SparkFun Forums 

Where electronics enthusiasts find answers.

Open source ARM Debugger
By jqpublick
#16773
I'm trying to use the target_script command to automatically run a script when OpenOCD is started, but it never appears to run. I know the script is OK, because I can call it from a telnet session.

This is with openocd-2006re80 build via mifi installer.

One debug issue I noticed after some experimenting is that openOCD will report an error if if the name of the script is missing, but it does not report an error if the script file specified does not exist. (That is, "target_script 0 reset" will generate an error in the debug log, but "target_script 0 reset no_such_file" will not generate an error.) So it is difficult to tell exactly what is going on.

I found the target_script command from Martin Thomas' pages, but found no "official" documentation on the syntax.

Here is my config:
Code: Select all
# openocd cfg file for automatic flash of AT91SAM7
# Copied from at91r40008_pp.cfg

# This .cfg requires  an openocd script to perform the flash once the daemon starts 

# For more information about the configuration files, take a look at:
# http://openfacts.berlios.de/index-en.phtml?title=Open+On-Chip+Debugger


#daemon configuration
telnet_port 4444
gdb_port 3333

# When daemon starts, you can "reset" target or simply "attach"
daemon_startup reset


#interface setup for wiggler
interface parport
parport_port 0x378
parport_cable wiggler
jtag_speed 0

#use combined on interfaces or targets that can't set TRST/SRST separately
#On AT91SAM7S64-EK ans AT91SAM7X256-EK, TRST is always pulled up.
reset_config srst_only

# Wait after reset in ms
# I just picked an arbitrary value to see if it makes any difference
jtag_nsrst_delay 100 


#jtag scan chain
#format L IRC IRCM IDCODE (Length, IR Capture, IR Capture Mask, IDCODE)
jtag_device 4 0x1 0xf 0xe


#target <type> <startup mode>
#target arm7tdmi <reset mode> <chainpos> <endianness> <variant>
#This works on SAM7S:
#target arm7tdmi little run_and_halt 0 arm7tdmi_r4
#run_and_halt_time 0 30

#Try this:
target arm7tdmi little reset_halt 0 arm7tdmi_r4


# For AT91SAM7, flash config values are looked up after reading the chip-id and type.
# Only need to specify target number.
flash bank at91sam7 0 0 0 0 0

# Script to call to runb the flash commands
# (syntax???)
# note: no error produced if filename is wrong
target_script 0 reset at91sam7_flash.txt

Here is the script:
Code: Select all
# AT91SAM7 flash command-"batch"
# adapted by Martin Thomas based on information from Dominic Rath - Thanks
sleep 500
halt
wait_halt
poll
flash probe 0
# Need method to alter file name programatically
flash write 0 c:\temp\rtosdemo.bin 0x0

#reset run
#sleep 500
#shutdown
Here is the log:
Code: Select all
Debug:   jtag.c:1180 jtag_init(): 
Debug:   parport.c:358 parport_init(): requesting privileges for parallel port 0x378...
Debug:   parport.c:368 parport_init(): ...privileges granted
Debug:   parport.c:203 parport_reset(): trst: 0, srst: 0
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   openocd.c:98 main(): jtag init complete
Debug:   arm7_9_common.c:651 arm7_9_assert_reset(): target->state: unknown
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 0
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 1
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 0
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   parport.c:203 parport_reset(): trst: 0, srst: 1
Debug:   parport.c:203 parport_reset(): trst: 0, srst: 1
Debug:   arm7_9_common.c:777 arm7_9_halt(): target->state: reset
Debug:   embeddedice.c:251 embeddedice_write_reg(): 9: 0xffffffff
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 3
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   embeddedice.c:251 embeddedice_write_reg(): 11: 0xffffffff
Debug:   embeddedice.c:251 embeddedice_write_reg(): 12: 0x00000100
Debug:   embeddedice.c:251 embeddedice_write_reg(): 13: 0x000000f7
Debug:   arm7_9_common.c:714 arm7_9_deassert_reset(): target->state: reset
Debug:   jtag.c:240 jtag_call_event_callbacks(): jtag event: 2
Debug:   jtag.c:1070 jtag_reset_callback(): 
Debug:   parport.c:203 parport_reset(): trst: 0, srst: 0
Debug:   openocd.c:102 main(): target init complete
Debug:   openocd.c:106 main(): flash init complete
Debug:   gdb_server.c:1093 gdb_init(): gdb service for target arm7tdmi at port 3333
Debug:   embeddedice.c:155 embeddedice_read_reg_w_check(): 1
Debug:   arm7_9_common.c:615 arm7_9_poll(): DBGACK set, dbg_state->value: 0x9
Debug:   embeddedice.c:251 embeddedice_write_reg(): 0: 0x00000005
Debug:   embeddedice.c:251 embeddedice_write_reg(): 12: 0x00000000
Debug:   arm7_9_common.c:915 arm7_9_debug_entry(): target entered debug from ARM state
Debug:   arm7_9_common.c:934 arm7_9_debug_entry(): target entered debug state in Supervisor mode
Debug:   arm7_9_common.c:975 arm7_9_debug_entry(): entered debug state at PC 0x8f10
Debug:   target.c:439 target_call_event_callbacks(): target event 0
[ at this point I telnetted in to shutdown... ]
Info:    server.c:67 add_connection(): accepted 'telnet' connection from 0
Info:    server.c:367 server_loop(): dropped 'telnet' connection
By Dominic
#16786
The target_script command specifies which script should be run upon an event. The only event currently implemented is "reset", though it should probably be renamed to "init".

That event is generated when the target entered debug state after a "reset init" or "reset run_and_init" command, respectively after daemon startup if the target was configured as "target ... reset_init" or "target ... run_and_init" and the daemon was configured as "daemon_startup reset".

The "reset halt" and "reset run_and_halt" reset types don't generate the reset event. The idea is to allow the user to choose between an initialized system (while the bootloader isn't executing) and an uninitialized system (when the bootloader is working).

The "run_and_xxx" are necessary for targets that can't be halted immediately out of reset, like the LPC2000 series.

Regards,

Dominic