Skip to content

Instantly share code, notes, and snippets.

@projectgus
Last active August 29, 2015 14:06
Show Gist options
  • Save projectgus/8dab3f891c9bd694fc5f to your computer and use it in GitHub Desktop.
Save projectgus/8dab3f891c9bd694fc5f to your computer and use it in GitHub Desktop.
Looking for a nice way to have openocd upload via an existing instance if it exists, or run standalone if not
install: $(APP).elf
# try to upload via a running openocd instance first, if that
# fails then fail over to running openocd program
( echo "halt; flash write_image erase $(APP).elf; reset" | nc localhost 4444 ) || \
$(OPENOCD) --command "program $(APP).elf; reset"
@projectgus
Copy link
Author

For future reference, the answer is:

netcat-traditional on Debian has undesirable behaviour with this snippet (you have to Ctrl-C out of netcat manually if openocd is running, because EOF from the input pipe doesn't close the TCP connection and exit netcat.)

netcat-openbsd on Debian has desirable behaviour (EOF from the input pipe does close the connection and exit netcat.)

So run netcat-openbsd or similar and life is good...

(Thanks Nattgris on #openocd for providing the key "this works for me" clue.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment