-
Notifications
You must be signed in to change notification settings - Fork 7.3k
arch: common: Make nocache region optionally loadable #87826
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
arch: common: Make nocache region optionally loadable #87826
Conversation
To add a bit more background: I created #52637 when I was working on a project where we modified the modbus stack to use DMA. The solution then existed as a patch in said project and never was cleaned up for a PR. Wrote a clean one now. The question, however, is if anyone needs it. I.e. no one commented on #52637 so we could also close the issue and this PR. But if not than here is a solution ;) One further note: |
288ab2f
to
7c5e337
Compare
@jachatzi - thanks for following up with this - a 2yo feature request. Personally, I don't see why nocache regions should be excluded from loading. I wonder if we can just enable that behaviour by default without being opt-in. |
@cfriedt Normally I'd say so too. The only thing which made me disable it by default is that it would slightly increase the boot time of existing products, when they update to a newer zephyr version. Maybe a bit over cautious... |
@peter-mitsis Yes indeed, it would fix #85236 |
@jachatzi - it fixes a bug. I say make it the default. Technically speaking, if there are no initialized objects in a no-cache region, they won't get loaded. I wonder if maybe the no-load was a bit of a hack to preserve the contents of memory across soft-resets, but IIRC, there are other ways of doing that. |
The NOCACHE region has been initially designed to hold data for DMA operations where cache operations can't not be used (e.g. due to alignment issues). Support for loading it on boot was not implemented as it was not needed for that usage. |
@jachatzi - IIUC you can assume that the Kconfig option you have added is always true, so I think it makes sense to remove it and hard-code the resulting bits. This would only affect initialized objects in nocache regions, which would typically be what one wants anyway with a C runtime. There is a separate option / attribute to skip zero-initializing bss, but I don't think that's in play here because we are specifically looking at data regions / initialized objects. |
7c5e337
to
438739b
Compare
@cfriedt - Removed the KConfig symbol and made it always loadable. |
438739b
to
650ea4f
Compare
@aurel32 - Thanks for clarifying. Wanted to make sure that there isn't some weird edge case which speaks against making it loadable. As this is not the case we could go on with this PR. |
@jachatzi - this might need a rebase on the latest from |
The `nocache` is not loadable, thus data stored therein cannot be initialized by the startup code. This might be needed in special cases. E.g. One might have a buffer which one wants to DMA into, and which is a member of a struct. Other members of the struct one may want to have initialized by the startup code. The buffer thus should be placed in the `nocache` region, but for the other members of the buffer to be initialized by the startup code, the `nocache` region needs to be loadable. Fix it by making the `nocache` region loadable. Adding a KConfig symbol to do this optionally was considered, but deemed unnecessary during the PR. Signed-off-by: Julian Achatzi <[email protected]>
650ea4f
to
2aa9ca9
Compare
The
nocache
region is not loadable, thus data stored therein cannot be initialized by the startup code. This might be needed in special cases. E.g. One might have a buffer which one wants to DMA into, and which is a member of a struct. Other members of the struct one may want to have initialized by the startup code.The buffer thus should be placed in the
nocache
region, but for the other members of the struct to be initialized by the startup code, thenocache
region needs to be loadable.Fix it by adding a KConfig symbol
NOCACHE_REGION_IS_LOADABLE
, which if set toy
makes thenocache
region loadable. It defaults ton
so that existing code does not get affected by it.Fixes #52637, #85236