-
-
Notifications
You must be signed in to change notification settings - Fork 782
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix: BMDA ST-Link v3 crashes #1605
Conversation
…ture, per the advice of clang-tidy
…and added protocol-level debug information to the function
…) and proper handling for faulting accesses
…tions into one spot
…they start to make more sense
…nt multi-drop targets
… stlink_ap_{read,write}()
in stlink_send_recv_retry()
in stlink_read_retry()
in stlink_write_retry()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Use the ST specific AP setup +++ b/src/platforms/hosted/stlinkv2.c
@@ -514,7 +514,7 @@ uint32_t stlink_adiv5_clear_error(adiv5_debug_port_s *const dp, const bool proto
*/
stlink_reset_adaptor();
if (dp->version >= 2)
- adiv5_dp_write(dp, ADIV5_DP_TARGETSEL, dp->targetsel);
+ stlink_ap_setup(dp->targetsel);
adiv5_dp_read(dp, ADIV5_DP_DPIDR);
}
const uint32_t err = adiv5_dp_read(dp, ADIV5_DP_CTRLSTAT) &
|
That doesn't help here - TARGETSEL is about selecting which DP we're talking to, not the AP.. unless you're telling us that STLINK_DEBUG_APIV2_INIT_AP is now overloaded for this purpose somehow. Not that this is documented anywhere that we've found. Also note that we've been unable, other than by exiting and re-entering debug mode, to generate the requisite line reset event needed to precede this for it to function correctly. How too would this interact with older ST-Link firmware? |
@UweBonnes I tried your change locally, and with a TARGETID @dragonmux Please copy/move the "remaining crash that is not addressed" detailed description of this PR1605 there as well. Even if it's actually last commit of PR1464 that breaks stuff for me. I failed to port over |
As mentioned in the code, STLink only can access AP0..8. With
the failing code is not longer executed |
Right, and this part of BMD has absolutely nothing to do with that.. this code is making a DP selection on a DPv2+ SWD chain, after (trying to) do a line reset.. passing a TARGETSEL value to the ST-Link AP machinery is demonstrably wrong and only hides a fundamental flaw with more bad code that does the wrong thing but silently. The AP setup code is an entirely different mechanism once a DP has been selected on the chain.. BMD will still try and attempt to select through 8 non-existent DPs for DPv2+ devices and translating those into AP selections is outright wrong. |
Detailed description
In this PR we partially address a series of crashes and error reporting issues discovered while prodding ST-Link v3's with BMDA. There is still an issue left to figure out regarding multi-drop SWD devices which results in a fail-safe crash against multi-drop parts, detailed after the main description.
With this we have sought to improve the error reporting done by the backend, improve correctness and reliability, and sort out its JTAG support which was completely broken (complete with segfaults). These changes also better harmonise the backend with the rest of the naming conventions being established in BMDA and the Black Magic Debug project in general.
Most notably, these changes include the removal of the
ap_setup()
andap_cleanup()
callbacks from the ADIv5 control structures by moving this logic properly into the backend where it belongs, simplifying logic in adiv5.c and enabling proper and reliable support for multi-AP parts.Finally, the remaining crash that is not addressed manifests against multi-drop SWD parts as:
which when expanded on, is caused by this interaction:
This is because in the current implementation, TARGETSEL writes (and therefore multi-drop support) are broken due to invoking the wrong packet kind on the ST-Link v3. This doesn't show up on a v2, only v3. In part this is because we do not correctly implement line reset right now, or know of any specific method ST has provisioned for switching which DP we're talking to. This will be addressed in a follow-up PR at a later date once the necessary research has been completed.
Your checklist for this pull request
make PROBE_HOST=native
)make PROBE_HOST=hosted
)Closing issues