zephyrproject-rtos / openocd

OpenOCD with Zephyr patches for building Zephyr SDK
Other
28 stars 45 forks source link

jlink: Support choosing a jlink serial number through west #39

Closed yonsch closed 3 years ago

yonsch commented 3 years ago

When multiple devices using a jlink interface are connected to the same host, trying to flash or debug them with west fails, as openocd can't infer which of the devices to act on. This PR enables west to explicitly choose a device using it's serial number, e.g. west flash --serial 123456789

Signed-off-by: Yonatan Schachter yonatan.schachter@gmail.com

galak commented 3 years ago

Can this not be done where jlink.cfg gets included? I'd prefer a solution that didn't have to touch this file, or at least one that the upstream openocd community is accepting of.

yonsch commented 3 years ago

Thanks for the quick reply. jlink.cfg is currently being included by every jlink enabled board, so doing it where jlink.cfg is included means copying that change to quite a few files (and requiring that it is re-added for every new board with a jlink). This can probably be solved by adding a jlink_common.cfg file to Zephyr, and make all jlink boards include that file. The only problem I can see with this solution is that it might require changing quite a few files, some of which make it not so trivial (for example: source [find interface/$INTERFACE.cfg]). I'm not sure that the openocd community would welcome a PR that is so specific to zephyr, and changing the variable name from _ZEPHYR_BOARD_SERIAL to something more generic will render west's --serial flag useless. Tell me what you think would be the best solution and I'll fix it.

galak commented 3 years ago

@mbolivar-nordic any thoughts on how we might handle this w/o modifying the official openocd. Can we modify the west runner to inject a -c jlink serial $_ZEPHYR_BOARD_SERIAL?

mbolivar-nordic commented 3 years ago

There are several options for hooking the flash command.

$ west flash -H -r openocd 
WARNING: no --build-dir given or found; output will be limited
openocd capabilities:
  RunnerCaps(commands={'debug', 'flash', 'attach', 'debugserver'}, flash_addr=False, erase=False)
openocd options:
  --config CONFIG       if given, override default config file
[...]
  --cmd-pre-init CMD_PRE_INIT
                        Command to run before calling init; may be given multiple times
  --cmd-pre-load CMD_PRE_LOAD
                        Command to run before flashing; may be given multiple times
  --cmd-load CMD_LOAD   Command to load/flash binary (required when flashing)
  --cmd-verify CMD_VERIFY
                        Command to verify flashed binary
  --cmd-post-verify CMD_POST_VERIFY
                        Command to run after verification; may be given multiple times
[...]

Are none of them really applicable to this?

yonsch commented 3 years ago

Yes, west flash --cmd-pre-init "jlink serial 123456789" works fine. I suppose this is a good enough solution for most use cases. I thought it would be nice to use the existing --serial flag, making it common to both FTDI and jlink devices, but if you're trying to avoid modifying openocd's files, it's probably better to just hook a command. Thanks!

galak commented 3 years ago

Yes, west flash --cmd-pre-init "jlink serial 123456789" works fine. I suppose this is a good enough solution for most use cases. I thought it would be nice to use the existing --serial flag, making it common to both FTDI and jlink devices, but if you're trying to avoid modifying openocd's files, it's probably better to just hook a command. Thanks!

Based on that, is there a reason we can't have the west runner add in jlink serial ... for the user?

mbolivar-nordic commented 3 years ago

Based on that, is there a reason we can't have the west runner add in jlink serial ... for the user?

Something like that sounds workable

galak commented 3 years ago

Closing this as there is some direction on how to handle in west or elsewhere.