-
Notifications
You must be signed in to change notification settings - Fork 178
Add skip-data-init feature to disable .data section initialization #613
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
Add skip-data-init feature to disable .data section initialization #613
Conversation
Stubbing out the copy loop seems fine but what is the purpose of the example? It has no observable output and no mechanism to run it with the kind of bootloader that it must be used with to avoid UB. Was it LLM generated? |
Hey @jonathanpallant the purpose of that example is to demonstrate how a Cortex-M program behaves when the usual Either way my PR isn't LLM generated, through that example I was indeed trying to show something reasonable :) Thanks! |
Ok so how do I run the example and what will I observe when the feature is set? |
|
||
use cortex_m_rt::entry; | ||
|
||
static mut COUNTER: u32 = 42; |
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.
can this be put into local scope or replaced by an atomic to avoid unsafe code?
unsafe { | ||
COUNTER += 1; | ||
} | ||
|
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.
can you just print the counter using semihosting printout?
Also, what about panicking if the output is not the expected value?
I think you might be able to just use a non-zero constant here to show that the data section was initialized? No need to use mutable statics then.. EDIT: the constant might be optimized away.. |
@KushalMeghani1644 have you actually tried if this solves the issue #609 is reporting, in actual RP2040 hardware, with the |
6fc7a46
to
cfc1ee0
Compare
I'm closing this PR on the grounds it's taking far more effort to review than the change is worth. I'm happy to look at this again when we have a working example (in another repo) with clear steps to reproduce the issue and clear evidence that the PR resolves the issue. |
A note on this - while the actual change is correct, the documentation and examples are not. The In my opinion the documentation was very clearly generated by an LLM and needs to be rewritten completely, at the very least. |
This PR adds an optional feature to skip .data initialization during startup.
Introduces:
the skip-data-init feature that disables the .data copy loop in the reset handler, for boot flows that already initialize RAM (e.g. RP2040 boot2 that copies to RAM and unmaps flash).
Adds a compile-time guard preventing skip-data-init from being used with zero-init-ram.
Includes a minimal example at skip-data-init.rs.
Default behavior is unchanged; .data is still copied when the feature is not enabled.
This PR tries to address issue #609