blackmagic-debug / blackmagic

In application debugger for ARM Cortex microcontrollers.
GNU General Public License v3.0
3.22k stars 768 forks source link

[RFC] OpenOCD HLA interface driver for Blackmagic #570

Open walmis opened 4 years ago

walmis commented 4 years ago

I've created initial implementation for Blackmagic firmware and implemented a basic OpenOCD HLA interface driver for blackmagic probe. On the probe itself, I've extended the remote.c interface with a new class REMOTE_HL_PACKET. It's currently in experimental stage, but seems to pass functional tests: eg. single stepping, flashing, RTOS threads support, openocd built in memory transfer tests. Speed and performance feel similar to that of st-link. Transfer rate is about 30 KB/s. Half of that of direct gdb connection, but for RTOS support of OpenOCD I think it's a reasonable tradeoff.

It enables this workflow:

[Target SWD]
  ↑↓
[Blackmagic on st-link ] 
  ↑↓
[REMOTE_HL commands over /dev/ttyACM0]
  ↑↓
[OpenOCD GDB server] ← OpenOCD features (RTOS threads, OpenOCD commands, etc.)
  ↑ ↓
GDB extended-remote

TODO:

You can find the code on my github: https://github.com/walmis/openocd-blackmagic/blob/master/src/jtag/drivers/blackmagic.c https://github.com/walmis/openocd-blackmagic https://github.com/walmis/blackmagic

UweBonnes commented 4 years ago

Can you try https://github.com/UweBonnes/blackmagic/tree/cmsis_dap against yout firmware?

walmis commented 4 years ago

Hi, I'm not really sure what to try on that branch as I don't have a CMSIS-DAP adapter.

UweBonnes commented 4 years ago

There are( too?) many debugger variants. With your first post, I thought that you implemented a firmware for (Stlink)BMP to behave as a OpenOCD HLA adapter. I also thought that " OpenOCD HLA" is the same as a CMSIS-DAP adapter. I have to have a look at the code to understand more.

walmis commented 4 years ago

No, the BMP firmware core functionality is as-is, nothing changed. On the BMP side, the only addition are the remote api calls for target read mem/write mem/read reg(s)/write reg(s). This is the core functionality required for OpenOCD HLA(High level adapter layer). The magic happens inside OpenOCD as it has access to target registers and memory over BMP. BMP in this case works like a bridge. To clarify:

hiviah commented 4 years ago

This looks interesting. BMP has extra features, but I sometimes need the OpenOCD commands.

Note that when cloning recursively with submodules, you are missing autoreconf in openocd-blackmagic/src/jtag/drivers/libjaylink (thus no configure script and exit)

You could add this to README for running it for clarity (STM32F4x sample chip):

openocd-blackmagic/bin/openocd -f share/openocd/scripts/interface/blackmagic.cfg -f share/openocd/scripts/target/stm32f4x.cfg

However flashing doesn't seem to work (maybe it wasn't part of this code):

/home/ondro/local/openocd-blackmagic/bin/openocd -f /home/ondro/local/openocd-blackmagic/share/openocd/scripts/interface/blackmagic.cfg -f /home/ondro/local/openocd-blackmagic/share/openocd/scripts/target/stm32f4x.cfg -c "init; reset halt; flash write_image erase build/firmware/firmware.bin.p1 0x08040000; flash write_image erase build/firmware/firmware.bin.p2 0x08120000; exit"

/home/ondro/local/openocd-blackmagic/bin/openocd -f /home/ondro/local/openocd-blackmagic/share/openocd/scripts/interface/blackmagic.cfg -f /home/ondro/local/openocd-blackmagic/share/openocd/scripts/target/stm32f4x.cfg -c "init; reset; exit"

UweBonnes commented 4 years ago

@hiviah: For target devices supported, your openocd commands now collapse to "blackmagic_stlinkv2 -a 0x08040000 build/firmware/firmware.bin.p1" "blackmagic_stlinkv2 -a 0x08120000 build/firmware/firmware.bin.p2" "blackmagic_stlinkv2 -R"

UweBonnes commented 4 years ago

Your patch is usefull, even without using BMP with OpenOCD, as it will greatly improve command line programming speed when used like "blackmagic_hosted -d /dev/ttyACMx >. However it defeats another use of pc-hosted: Develop device algorithms without having to reflash the BMP. Can you think about adding a command line option to disable the high level access and in that case do only low level access?

The patch also misses the integration in platforms/pc-hosted, if I do not overlook something. Or maybe even another platform, branched from pc-hosted.

UweBonnes commented 4 years ago

Are you still listening?

REMOTE_INIT_SWDP hard codes target one an provides a duplicate way to swdptap_init. I think remotePacketProcessHL/REMOTE_INIT_SWDP should be removed and replaces by a pure call to target_attach_n

UweBonnes commented 4 years ago

https://github.com/UweBonnes/blackmagic/tree/multi implements remote high level interface in a way it is usable for BMP pc-hosted. Comments welcome.

brainstorm commented 4 years ago

@UweBonnes Adding an example session on https://github.com/UweBonnes/blackmagic/commit/d0cc2df00753d0806a8ad529c3826d94f905c971 (with both server/client involved) would help users getting started, IMHO.

UweBonnes commented 4 years ago

@brainstorm:

Please have a look at platforms/hosted/Readme.md and tell me what is missing.

brainstorm commented 4 years ago

@UweBonnes Just an example shell session with any hardware of your choice, as a guiding example. That way users can see the actual text outputs from GDB/shell from a real session.

UweBonnes commented 4 years ago

For running with gdb, you need two shells:

For help, type "help". Type "apropos word" to search for commands related to "word". (gdb) tar ext :2000 Remote debugging using :2000 (gdb) mon s Target voltage: 3.22V Available Targets: No. Att Driver 1 STM32F74x M7 (gdb)

The gdb windows is the same as with running firmware BMP but you must connect to :2000 instead of /dev/ttyACM0

Is this the example you need?

brainstorm commented 4 years ago

It's not about what I need ;) I was just reviewing the docs from a technical/UX perspective for (other) people that might approach this project without having had contact with it before.

Yes, that looks better, I would perhaps remove all the GDB license banner in the interest of brevity but the interaction and outputs can help as a guide. Cheers!

UweBonnes commented 4 years ago

Can you please proof-read https://github.com/UweBonnes/blackmagic/tree/hosted? Thanks!

brainstorm commented 4 years ago

Sure! This paragraph is a bit too dense?:

This builds the same GDB server, that is running on the Black Magic Probe. While connection to the Black Magic Probe GDB server is via serial line, connection to the PC-Hosted GDB server is via TCP port 2000 for the first GDB server and higher for more invokations. Use "tar(get) ext(ented) :2000" to connect. PC-hosted BMP GDB server can talk to the Black Magic Probe itself, ST-LinkV2 and V3, CMSIS-DAP, JLINK and FTDI MPSSE based debuggers.

The last part I would break it down into a list, typo on "invocations". I would remove the target explanation bit since it's already shown in the example.

The rest LGTM 👍

esden commented 2 years ago

@UweBonnes Just to clarify. Is this branch referring to your OpenOCD support branch? What is the status of that project? What are the todo items that need to be done here?

ankostis commented 2 years ago

~Any hope of pushing your changes to BOTH upstream projects?~

Q about confirming what has been suggested and/or is sufficiently accepted to make both projects work together?

ikcalB commented 7 months ago

hi guys,

is there any progress on this? using the BMP as a transport in openOCD could really push the spread of BMP. (allowing to support more different targets - as is my current use case)

dragonmux commented 7 months ago

This is not something which is in the project roadmap to go fix/implement as we just don't have the people power to go after OpenOCD's contribution process while also trying to evolve BMD itself.

If it's a feature you want to see happen and you feel you have the skills and time to write an OpenOCD backend for BMD (using BMDA's remote protocol implementation as a template) then that would be very welcome by us - can't speak for OpenOCD there though. As noted in the post above yours, BMD itself is fully capable already, there's no code changes required our side to make something like that happen.