7
32
Fork
You've already forked blackmagic
23

Fix: skip NULL remote-ensure_idle when transport is not JTAG #2259

Merged
dragonmux merged 1 commit from ALTracer/blackmagic:fix/remote-ensure-idle into main 2026年05月22日 04:51:06 +02:00
Contributor
Copy link

Detailed description

  • This is (another) bugfix to #2072.
  • The existing problem is a possible firmware crash in remote protocol.
  • This PR solves it by adding a NULL check.

BMDA with ADIv5 acceleration always has the ensure_idle method present, regardless of JTAG or SWD or auto transport, and will send !JI# as implemented.
BMP will then invoke the remote_dp (structure present in SRAM) function pointer .ensure_idle() which for SWD-only is a NULL pointer, which for all STM32 platforms aliases to Initial_MSP of bootloader or firmware and crashes (as a forced HardFault, escalated from UsageFault). On STM32F4 it is also catchable by MPU as a MemManage fault.
If this BMP had done any remote JTAG scan (!JS# initialize), then the pointer is good and points to adiv5_jtag_ensure_idle(), which I'm not sure is valid to perform in consequent remote SWD operation on SWJ+BSCAN chips. Question: zero out the pointer during SWD !SS# initialize? (now that it is checked and it is safe to)

Stack backtrace spoiler
(gdb) bt
#0 systick_spinner () at ../src/platforms/common/syscalls.c:148
#1 0x08022640 in hard_fault_handler () at ../src/platforms/common/syscalls.c:164
#2 <signal handler called>
#3 0x00000000 in ?? ()
#4 0x08006758 in remote_packet_process_jtag (packet=0x20001198 <packet_buffer>) at ../src/remote.c:254
#5 remote_packet_process (packet=packet@entry=0x20001198 <packet_buffer>) at ../src/remote.c:941
#6 0x08005b34 in consume_remote_packet (packet=packet@entry=0x20001198 <packet_buffer>) at ../src/gdb_packet.c:148
#7 0x08005b80 in gdb_packet_receive () at ../src/gdb_packet.c:198
#8 0x08005fd4 in bmp_poll_loop () at ../src/main.c:57
#9 main () at ../src/main.c:76
(gdb) vecstate
HardFault: forced due to escalated or disabled configurable fault (see below)
UsageFault due to bad T or IT bits in EPSR

Your checklist for this pull request

Closing issues

## Detailed description * This is (another) bugfix to #2072. * The existing problem is a possible firmware crash in remote protocol. * This PR solves it by adding a NULL check. BMDA with ADIv5 acceleration always has the `ensure_idle` method present, regardless of JTAG or SWD or auto transport, and will send `!JI#` as implemented. BMP will then invoke the `remote_dp` (structure present in SRAM) function pointer `.ensure_idle()` which for SWD-only is a NULL pointer, which for all STM32 platforms aliases to Initial_MSP of bootloader or firmware and crashes (as a forced HardFault, escalated from UsageFault). On STM32F4 it is also catchable by MPU as a MemManage fault. If this BMP had done any remote JTAG scan (`!JS#` initialize), then the pointer is good and points to `adiv5_jtag_ensure_idle()`, which I'm not sure is valid to perform in consequent remote SWD operation on SWJ+BSCAN chips. Question: zero out the pointer during SWD `!SS#` initialize? (now that it is checked and it is safe to) <details> <summary>Stack backtrace spoiler</summary> ``` (gdb) bt #0 systick_spinner () at ../src/platforms/common/syscalls.c:148 #1 0x08022640 in hard_fault_handler () at ../src/platforms/common/syscalls.c:164 #2 <signal handler called> #3 0x00000000 in ?? () #4 0x08006758 in remote_packet_process_jtag (packet=0x20001198 <packet_buffer>) at ../src/remote.c:254 #5 remote_packet_process (packet=packet@entry=0x20001198 <packet_buffer>) at ../src/remote.c:941 #6 0x08005b34 in consume_remote_packet (packet=packet@entry=0x20001198 <packet_buffer>) at ../src/gdb_packet.c:148 #7 0x08005b80 in gdb_packet_receive () at ../src/gdb_packet.c:198 #8 0x08005fd4 in bmp_poll_loop () at ../src/main.c:57 #9 main () at ../src/main.c:76 (gdb) vecstate HardFault: forced due to escalated or disabled configurable fault (see below) UsageFault due to bad T or IT bits in EPSR ``` </details> ## Your checklist for this pull request * [x] I've read the [Code of Conduct](https://codeberg.org/blackmagic-debug/blackmagic/src/CODE_OF_CONDUCT.md) * [x] I've read the [guidelines for contributing](https://codeberg.org/blackmagic-debug/blackmagic/src/CONTRIBUTING.md) to this repository * [x] It builds for hardware native (see [Building the firmware](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-the-firmware)) * [x] It builds as BMDA (see [Building the BMDA](https://codeberg.org/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app)) * [x] I've tested it to the best of my ability * [x] My commit messages provide a useful short description of what the commits do ## Closing issues
remote: Skip NULL ensure_idle when transport is not JTAG
Some checks failed
ci/woodpecker/pr/build-linux/1 Pipeline was successful
ci/woodpecker/pr/build-linux/2 Pipeline was successful
ci/woodpecker/pr/build-firmware/18 Pipeline failed
ci/woodpecker/pr/build-firmware/20 Pipeline was successful
ci/woodpecker/pr/build-firmware/19 Pipeline was successful
ci/woodpecker/pr/build-windows Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/push/build-firmware/1 Pipeline was successful
ci/woodpecker/push/build-firmware/5 Pipeline was successful
ci/woodpecker/push/build-firmware/6 Pipeline was successful
ci/woodpecker/push/build-firmware/4 Pipeline was successful
ci/woodpecker/push/build-firmware/2 Pipeline was successful
ci/woodpecker/push/build-firmware/3 Pipeline was successful
ci/woodpecker/push/build-firmware/7 Pipeline was successful
ci/woodpecker/push/build-firmware/8 Pipeline failed
ci/woodpecker/push/build-firmware/9 Pipeline was successful
ci/woodpecker/push/build-firmware/13 Pipeline failed
ci/woodpecker/push/build-firmware/10 Pipeline was successful
ci/woodpecker/push/build-firmware/12 Pipeline was successful
ci/woodpecker/push/build-firmware/11 Pipeline was successful
ci/woodpecker/push/build-firmware/15 Pipeline was successful
ci/woodpecker/push/build-firmware/14 Pipeline was successful
ci/woodpecker/push/build-linux/1 Pipeline was successful
ci/woodpecker/push/build-linux/2 Pipeline was successful
ci/woodpecker/push/build-firmware/18 Pipeline failed
ci/woodpecker/push/build-firmware/16 Pipeline was successful
ci/woodpecker/push/build-firmware/19 Pipeline was successful
ci/woodpecker/push/build-firmware/17 Pipeline was successful
ci/woodpecker/push/build-firmware/20 Pipeline was successful
ci/woodpecker/push/build-windows Pipeline was successful
482ded75d9
dragonmux left a comment
Copy link

LGTM, merging once CI completes. Thank you for the contribution and this bug fix!

LGTM, merging once CI completes. Thank you for the contribution and this bug fix!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!2259
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "ALTracer/blackmagic:fix/remote-ensure-idle"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?