8000 segger_rtt: mark allocated struct as `_SEGGER_RTT` in ELF by alevy · Pull Request #4124 · tock/tock · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

segger_rtt: mark allocated struct as _SEGGER_RTT in ELF #4124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 2, 2024

Conversation

alevy
Copy link
Member
@alevy alevy commented Aug 1, 2024

Pull Request Overview

This PR adds an ELF section name to the statically allocated Segger RTT struct to marking for tools on the host where to find that memory. This is a de-facto standard for tools that interact with Segger RTT that allows them to find the shared memory buffer in the ELF. For example, probe-rs uses this.

Testing Strategy

Running probe-rs run --chip nRF52840_xxAA target/thumbv7em-none-eabi/release/sma_q3 with an sma_q3 connected and watch for the Segger RTT output.

TODO or Help Wanted

N/A

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

@alevy alevy added the P-Upkeep This a relatively minor change, or one that is limited in scope, and requires less scrutiny. label Aug 1, 2024
@github-actions github-actions bot added kernel component and removed P-Upkeep This a relatively minor change, or one that is limited in scope, and requires less scrutiny. labels Aug 1, 2024
lschuermann
lschuermann previously approved these changes Aug 2, 2024
Copy link
Member
@lschuermann lschuermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I don't like the code duplication in the static_buf macro, but it'd probably be even more confusing if we tried to split this out in another macro or recursively invoke itself to generate the second half of the expression.

@lschuermann lschuermann added the last-call Final review period for a pull request. label Aug 2, 2024
// initialized.
&mut BUF.0
}};
($T:ty, $N:expr) => {{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
($T:ty, $N:expr) => {{
($T:ty, $N:expr $(,)?) => {{

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes!

@bradjc bradjc removed the last-call Final review period for a pull request. label Aug 2, 2024
Copy link
Contributor
@bradjc bradjc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a new macro that can be documented as to what the second parameter is and when it should be used. Macros are hard to document as it is, and the static_X infrastructure is fairly confusing already. This seems like a very niche use case and since we are already copying the macro I think it makes sense to not change the existing static_buf macro.

@bradjc
Copy link
Contributor
bradjc commented Aug 2, 2024

For posterity, if you like me were wondering how this worked already, the standard way that host-side tools find the RTT buffer is by looking for a sentinel in RAM.

However, it does seem that Segger does suggest using the symbol _SEGGER_RTT if the scan doesn't work or isn't an option.

@lschuermann
Copy link
Member
lschuermann commented Aug 2, 2024

Come to think of it, in concept this is somewhat similar to storage_volume! (

macro_rules! storage_volume {
), so @bradjc's argument makes sense to me -- this should probably be a dedicated macro.

I don't know whether it could be combined with storage_volume! as that's a non-mutable buffer. And also storage_volume! is probably unsound anyways, as we're writing to an immutable static.

@bradjc
Copy link
Contributor
bradjc commented Aug 2, 2024

Come to think of it, in concept this is somewhat similar to storage_volume! (

I will note that storage_volume!() comes from what might be considered a different era of Tock that was more exploratory. It can definitely inform our thinking, but we might want to avoid using it as precedent.

This is a de-facto standard for tools that interact with Segger RTT
that allows them to find the shared memory buffer in the ELF
@alevy
Copy link
Member Author
alevy commented Aug 2, 2024

@bradjc @alexandruradovici @lschuermann revised to be a separate macro (that also fixes the syntax parsing error @alexandruradovici noticed).

Suggestions on the documentation for the macro are welcome, I'm not sure how or what to say about how to use this beyond "it adds an export name".

lschuermann
lschuermann previously approved these changes Aug 2, 2024
bradjc
bradjc previously approved these changes Aug 2, 2024
@lschuermann lschuermann dismissed stale reviews from bradjc and themself via d0997be August 2, 2024 18:46
< 8000 div class="AvatarStack flex-self-start AvatarStack--two " >
…y of `static_named_buf`

Co-authored-by: Brad Campbell <bradjc5@gmail.com>
@alevy alevy added the last-call Final review period for a pull request. label Aug 2, 2024
@alevy alevy added this pull request to the merge queue Aug 2, 2024
Merged via the queue into tock:master with commit 93af4ff Aug 2, 2024
12 checks passed
@alevy alevy deleted the segger_rtt branch August 2, 2024 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component kernel last-call Final review period for a pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0