-
Notifications
You must be signed in to change notification settings - Fork 7.7k
zephyr_code_relocate() now supports the NOCOPY_DATA flag to inhibit data relocation #86628
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
base: main
Are you sure you want to change the base?
Conversation
Hello @rhaberkorn, and thank you very much for your first pull request to the Zephyr project! |
c2c7015
to
1118aa3
Compare
1118aa3
to
d44630f
Compare
d44630f
to
6413369
Compare
Force-pushed a new version with the changes requested by @JarmouniA. |
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.
We should add NOCOPY_DATA here, no?
zephyr_code_relocate(FILES src/ext_code.c LOCATION EXTFLASH_TEXT NOCOPY) |
for the sample to keep its current behavior.
No, the patch should not break any existing code. In particular, as far as I understand, this example is for typical execute-inplace-from-flash scenarios, i.e. modern MCU case where you can execute from the builtin flash. But you cannot write individual words in that flash, nor do you want to for most global variables, as it would wear out the flash. So on those devices, you do need to copy the .data segment from flash into SRAM. Another question/bug might be that Zephyr does not seem to actually copy .data into SRAM if you relocate all segments (e.g. without the _TEXT suffix and without the new NOCOPY_DATA). This is how I actually noticed that something is missing. I wanted to relocate everything into SRAM. In my particular use case you don't actually have to copy .data, but it could still be broken on devices with real XIP flash. |
This is activated by passing NOCOPY_DATA to zephyr_code_relocate(). It helps when building firmwares for coprocessors, where the image is loaded completely into SRAM from Linux-land using the remoteproc framework. Fixes: zephyrproject-rtos#86530 Signed-off-by: Robin Haberkorn <haberkorn@metratec.com>
6413369
to
176d993
Compare
As I was musing in a previous comment, perhaps we should simply apply diff --git a/scripts/build/gen_relocate_app.py b/scripts/build/gen_relocate_app.py
index 48ef8a4bf95..7778fd663bb 100755
--- a/scripts/build/gen_relocate_app.py
+++ b/scripts/build/gen_relocate_app.py
@@ -404,10 +404,10 @@ def generate_linker_script(linker_file, sram_data_linker_file, sram_bss_linker_f
gen_string += MPU_RO_REGION_END.format(memory_type.lower())
if region_is_default_ram(memory_type):
- gen_string_sram_data += string_create_helper(SectionKind.DATA, memory_type, full_list_of_sections, 1, 1, phdrs)
+ gen_string_sram_data += string_create_helper(SectionKind.DATA, memory_type, full_list_of_sections, 1, is_copy, phdrs)
gen_string_sram_bss += string_create_helper(SectionKind.BSS, memory_type, full_list_of_sections, 0, 1, phdrs)
else:
- gen_string += string_create_helper(SectionKind.DATA, memory_type, full_list_of_sections, 1, 1, phdrs)
+ gen_string += string_create_helper(SectionKind.DATA, memory_type, full_list_of_sections, 1, is_copy, phdrs)
gen_string += string_create_helper(SectionKind.BSS, memory_type, full_list_of_sections, 0, 1, phdrs)
# finally writing to the linker file That's it, that will also do the trick even without adding any new zephyr_code_relocate() flags. .bss is already mapped properly ( |
@carlocaione you authored the original NOCOPY feature here: d3203dc / PR##42859. @rhaberkorn please take a look at the referenced commit / PR, as this provides details on the original use-case. |
The original use case was for XIP flash, so @carlocaione didn't want to apply |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
@carlocaione - please comment if you have some time. It would be good to investigate the nocopy option highlighted above as well. @rhaberkorn - can you make an alternate PR to explore that so we can compare the two? |
@cfriedt You mean a new PR with this patch? |
This helps when building firmwares for coprocessors, where the image is loaded completely into SRAM in Linux-land using the remoteproc framework.
For a motivation of this change, see #86530.