-
-
Notifications
You must be signed in to change notification settings - Fork 968
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
Fix linker script to prevent using not available flash memory #1472
Fix linker script to prevent using not available flash memory #1472
Conversation
@AlexXZero Thank you very much for your in-depth analysis in #1463 and for this PR! I had a look at the changes, and I can see that I did a few mistakes when I designed the memory map for the bootloader and the firmware! The image header and trailer were not taken into account! Also, the last 12KB that are left unused are a bit intriguing... To be honest, I can't remember what was my intent : I either made a calculus error, and I intended to use them as scratch area, but forgot to extend the area size to 16KB... Have you already had the opportunity to check that those changes in the linker script work correctly, and that it prevents from generating a faulty (too big) firmware? EDIT : it would also be nice to update the memory map in the documentation of the bootloader. Would you like to do it? |
I did a few additional checks : generate the biggest possible firmware file, and then the corresponding image. The goal is to check that everything work fine when flashing the biggest size allowed. So, according to @AlexXZero's calculation, we should be allowed to build a firmware that is 474672 (0x73e30) bytes of size.
In this case, the firmware size is 473728B of code and 940B of data which is 474668B total. It's 4B less than the maximum, but I couldn't reach the exact number of 474672. Notice that There are 2 issues here :
I do not have the answer to the 1st question. The 2nd question can be explained by
Yep, trailer sizes match, but not the image size. So, in theory, we should change the imgtool CLI to use an align value of 1, but I would like to understand why there's a difference in the image size between the build and the call to imgtool first. (*) And I think they are right. Still in the bootloader, the external spi flash is configured this way : (repos/apache-mynewt-core/hw/drivers/flash/spiflash/src/spiflash.c) Since both memories are configured with an align value of 1, mcu boot should use a min-write-size equal to 1. |
Ok, I found where do those 40bytes come from : See https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/tools/mcuboot/imgtool/image.py#L374. I added a few So I guess we'll probably take that into account in the linker script by removing 40 bytes to the max size of the firmware. |
Co-authored-by: JF <[email protected]>
Co-authored-by: JF <[email protected]>
@JF002 It seems we also need to change the imgtool arguments, I will review how to do it soon and also will test building and running an image with maximum possible size. I tired to draw the memory map diagram which we can add into documentation: |
@AlexXZero The new memory map looks good! Waiting for your test results :) |
…pected alignment
I have built and tested image with maximum possible size (actually I also couldn't reach the rest 4 bytes, but I guess it is caused by alignment between .text and .data sections) Test firmware is based on cfc86d7 commit + the following changes: diff --git a/gcc_nrf52-mcuboot.ld b/gcc_nrf52-mcuboot.ld
index 6c3a769b..0fb3e9e9 100644
--- a/gcc_nrf52-mcuboot.ld
+++ b/gcc_nrf52-mcuboot.ld
@@ -166,6 +166,12 @@ SECTIONS
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
+ .test_dummy :
+ {
+ . = ALIGN(4);
+ . += 56212;
+ } > FLASH
+
} INSERT AFTER .text Tested actions:
All test results are match expected behavior. |
@AlexXZero Thanks for your test results, it looks good to me! I'm OK to create a new PR for the documentation. Just one minor detail : I think we should also update |
…/InfiniTime#1472) and add more information about the sections in the internal memory.
I added the changes in gcc_nrf52-mcuboot.ld and also updated the documentation in the bootloader readme file (InfiniTimeOrg/pinetime-mcuboot-bootloader@2bd9ead) so that we can merge this branch. Thanks for you work, @AlexXZero ! |
…/InfiniTime#1472) and add more information about the sections in the internal memory.
There is a fix for the issue found in the ticket #1463
It replace magic numbers with named constants in the linker script for mcuboot application.