-
Notifications
You must be signed in to change notification settings - Fork 3k
Add padding up to restrict_size #11043
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
Conversation
https://os.mbed.com/docs/mbed-os/v5.13/reference/bootloader-configuration.html section target.restrict_size states that: "The postbuild merge process pads the resulting bootloader binary to its end address." This padding is added for region merges that specify restrict_size. Additional pad_to_restrict_size boolean argument added to allow both full and 'update' outputs. Fixes: ARMmbed#9949
@statropy, thank you for your changes. |
@mark-edgeworth @madchutney please review |
Test run: FAILEDSummary: 1 of 11 test jobs failed Failed test jobs:
|
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Hi @statropy, I am trying understand the problem you are trying to solve with this change. Also I didn't understand the comment of 'full' vs 'update'. Could you please explain? |
As captured in issue #9949, somewhere between mbed-os 5.11.0 and 5.11.1, creating a bootloader section using restrict_size was broken. Using restrict_size, as stated by the documentation referenced above, will pad out the binary output of the build to the restrict_size value. This is so that the main application can bundle the bootloader section with its binary, and to determine the proper start address for that application (directly after the bootloader section). This change adds the padding to the binary output of a build that uses restrict_size. I probably used the wrong terminology for 'update' vs 'full'. The mbed-os build produces two binary outputs: [project].bin and [project]_application.bin. The [project].bin includes the restrict_size padding and is used as the "target.bootloader_img" value in the main application. The _application.bin does NOT include the padding. This binary is intended to be used to update just the bootloader section on a device where a previous version of the bootloader is already present, therefore the padding isn't needed. The value of this is for a smaller size binary for use with updates, such as an over-the-air update. This change makes the functionality match the referenced documentation. Edit: [project] was not visible |
@madchutney Are you happy with the explanation? This seems to pass tests, and is otherwise good to go in. I would however mark this as 5.14-rc1 as it might change the way how binaries are produced, so that would give us some time to run it in the CI and manual testing, before pushing it to public release. |
@SeppoTakalo The explanation was useful, I am checking that this won't cause a regression. I believe we will need a unit test for this code to ensure the functionality is not unexpectedly removed again. I am also concerned whether there is a need for the |
@madchutney Thanks for looking into it further. I am concerned that I wasn't able to find the original point of regression, and that this change would cause other regressions. As for the Nordic targets in particular, the default output is .hex not bin, so my fix would only work when the output format is changed to .bin. This may be required for a bootloader segment though, because I think "target.bootloader_img" will only accept a binary. A further complication with the Nordic targets is the bundling of a soft-device as 'bootloader' segment. I'm not using the soft-device in my Nordic build, but I don't want to break that functionality either. |
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.
Thanks a lot for the changes, I don't think this will break the previous fix and this should certainly resolve the defect. To ensure we don't get a similar regression again could you please add a unit test to mbed-os/tools/test/build_api/build_api_test.py
?
There is one failing test in the suite (test_always_complete_build
) so I don't think they are run in CI, which I will look into.
Many thanks,
Graham
@@ -168,6 +170,9 @@ def merge_region_list( | |||
pad_size = start - begin | |||
merged.puts(begin, padding * pad_size) | |||
begin = stop + 1 | |||
if restrict_size is not None and pad_to_restrict_size: | |||
pad_size = int(restrict_size, 0) - begin |
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.
This would restore the output to something similar to pre 11.1 behaviour
pad_size = int(restrict_size, 0) - begin | |
pad_size = int(restrict_size, 0) - begin | |
notify.info(" Padding region with 0x%x bytes" % pad_size) |
@@ -116,6 +117,7 @@ def merge_region_list( | |||
destination - file name to write all regions to | |||
padding - bytes to fill gaps with | |||
restrict_size - check to ensure a region fits within the given size | |||
pad_to_restrict_size - fill with padding up to restrict_size |
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.
I do not think we need pad_to_restrict_size
, I cannot see a situation where this would be needed and without it I think it fixes the regression that appeared in 11.1
OK you've convinced me on not needing pad_to_restrict_size. I can get the same effect when calling merge_region_list() and leaving restrict_size as None. Much better. That bool felt hacky. I'll look at adding a unit test. This is my first project using mbed and love it so far. Happy to help contribute. |
Thanks that will be great |
@statropy any update for this PR? If any questions, ask. |
@statropy It would be good to have this fixed. I would close this PR as it has not been updated for a month. |
Ok I try build bootloader:
When I build program in Mbed Studio I got this same error
This is simple example program from github, I tryed on NUCLEO_476RG (my change in mbed_app.json) and NUCLEO_F429ZI. |
I've been able to repeat this - looks like an issue with this specific target as it works ok with K64F |
https://github.com/ARMmbed/mbed-os-example-bootloader#required-hardware |
Reopening this without any update does not help here much. How can we progress with this fix, as it seems it is our turn to help here? |
@0xc0170 The fix seems valid to me but as per my review I believe there is some work outstanding. Since the originator hasn't updated as promised we should take this on ourselves and complete the fix. I do not think closing the issue was the correct action in this circumstance. |
The issue is still opened #9949 so should not be forgotten. Only PR was closed as it's stalled. It can be reopened any time or discussion ongoing. |
The referenced issue is opened, still valid bug that needs fixing and this can be reopened once updated |
Without this, the bootloader functionality is broken for me. |
Description
https://os.mbed.com/docs/mbed-os/v5.13/reference/bootloader-configuration.html section target.restrict_size states that:
"The postbuild merge process pads the resulting bootloader binary to its end address."
This padding is added for region merges that specify restrict_size. Additional pad_to_restrict_size boolean argument added to allow both full and 'update' outputs.
Fixes: #9949
Pull request type
Reviewers
Release Notes