0

I've heard that OpenOCD is supposed to daemonize after running some commands.

I try giving commands as CLI arguments. The commands are run, but OpenOCD does not background afterwards, so GDB is never run. I could add '&' to the end of the openocd command, but then I have a race condition with GDB.

How can I make OpenOCD daemonize after loading the flash?

13 # Launch OpenOCD
14   # specify our hardware debugger and mcu type
15   # reset target
16   # erase in bank 0 from 20k (0x5000) to end of flash
17   # load hex format because elf has extraneous section at 0x00000000
18   # NOTE: we don't use 'erase' so we can't blow away bootloader
19   # ??? daemonize when done so GDB can run 
20 openocd -f interface/olimex-arm-usb-tiny-h.cfg -f target/stm32f1x.cfg \
21   -l .openocd.log \
22   -c "init" -c "reset init" \
23   -c "flash erase_sector 0 20 last" \
24   -c "flash write_image $HEXFILE"
25
26 # run gdb
...
Chris Merck
  • 454
  • 3
  • 12

1 Answers1

2

Instead of writing the flash in OpenOCD, you can do that from GDB using monitor commands.

Change your OpenOCD to launch as follows:

20 openocd -f interface/olimex-arm-usb-tiny-h.cfg -f target/stm32f1x.cfg \
21   -l .openocd.log \
22   -c "init" &

Then use a .gdbinit similar to this:

target remote localhost:3333
monitor reset halt
monitor flash erase_sector 0 20 last
monitor flash write_image build/my_project.hex
set remote hardware-breakpoint-limit 6
set remote hardware-watchpoint-limit 4
break main
continue

You still have a race-condition because OpenOCD still takes time to start up, but this works OK for me without any delays.

Chris Merck
  • 454
  • 3
  • 12