Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

statropy
Copy link

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

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

Release Notes

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
@ciarmcom ciarmcom requested a review from a team July 13, 2019 19:00
@ciarmcom
Copy link
Member

@statropy, thank you for your changes.
@ARMmbed/mbed-os-tools @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested a review from a team July 13, 2019 19:00
@bulislaw
Copy link
Member

@mark-edgeworth @madchutney please review

@mbed-ci
Copy link

mbed-ci commented Jul 17, 2019

Test run: FAILED

Summary: 1 of 11 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_exporter

@mbed-ci
Copy link

mbed-ci commented Jul 19, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 2
Build artifacts

@madchutney
Copy link
Contributor

madchutney commented Jul 24, 2019

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?

@statropy
Copy link
Author

statropy commented Jul 24, 2019

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

@SeppoTakalo
Copy link
Contributor

@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.

@madchutney
Copy link
Contributor

madchutney commented Jul 25, 2019

@statropy Thanks for the explanation and the contribution, I have been looking at the original cause of the issue which seems to be #8097 and I'm trying to determine if this fix will cause a problem with that requirement.

@madchutney
Copy link
Contributor

@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 pad_to_restrict_size variable as it seems to me at the moment the only correct behaviour is when it is set to True. I'd rather not introduce an unnecessary variable, although I completely understand why @statropy has done so in this PR.

@statropy
Copy link
Author

@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.

Copy link
Contributor

@madchutney madchutney left a 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
Copy link
Contributor

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

Suggested change
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
Copy link
Contributor

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

@statropy
Copy link
Author

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.

@madchutney
Copy link
Contributor

Thanks that will be great

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 20, 2019

@statropy any update for this PR? If any questions, ask.

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 26, 2019

@statropy It would be good to have this fixed. I would close this PR as it has not been updated for a month.

@0xc0170 0xc0170 closed this Sep 9, 2019
@pawelm87
Copy link

pawelm87 commented Oct 2, 2019

Ok I try build bootloader:

`PS C:\Users\p\Desktop\workspace> mbed import mbed-os-example-bootloader
[mbed] Working path "C:\Users\p\Desktop\workspace" (directory)
[mbed] Importing program "mbed-os-example-bootloader" from "https://github.com/ARMmbed/mbed-os-example-bootloader" at latest revision in the current branch
[mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at rev #0f959dbe4749
PS C:\Users\p\Desktop\workspace> cd mbed-os-example-bootloader
PS C:\Users\p\Desktop\workspace\mbed-os-example-bootloader> mbed toolchain GCC_ARM
[mbed] Working path "C:\Users\p\Desktop\workspace\mbed-os-example-bootloader" (program)
[mbed] GCC_ARM now set as default toolchain in program "mbed-os-example-bootloader"
PS C:\Users\p\Desktop\workspace\mbed-os-example-bootloader> mbed target NUCLEO_L476RG
[mbed] Working path "C:\Users\p\Desktop\workspace\mbed-os-example-bootloader" (program)
[mbed] NUCLEO_L476RG now set as default target in program "mbed-os-example-bootloader"
PS C:\Users\p\Desktop\workspace\mbed-os-example-bootloader> mbed compile
[mbed] Working path "C:\Users\p\Desktop\workspace\mbed-os-example-bootloader" (program)
Building project mbed-os-example-bootloader (NUCLEO_L476RG, GCC_ARM)
Scan: mbed-os-example-bootloader
Compile [  0.1%]: except.S
Compile [  0.2%]: mbed_tz_context.c
Compile [  0.4%]: mbed_fault_handler.c
Compile [  0.5%]: at24mac.cpp
Compile [  0.6%]: MCR20Drv.c
Compile [  0.7%]: NanostackRfPhyAtmel.cpp
Compile [  0.8%]: main.cpp
[Fatal Error] main.cpp@2,27: SDBlockDevice.h: No such file or directory
[ERROR] .\main.cpp:2:27: fatal error: SDBlockDevice.h: No such file or directory
 #include "SDBlockDevice.h"
                           ^
compilation terminated.

[mbed]** ERROR: "c:\python27\python.exe" returned error.
       Code: 1
       Path: "C:\Users\p\Desktop\workspace\mbed-os-example-bootloader"
       Command: "c:\python27\python.exe -u C:\Users\p\Desktop\workspace\mbed-os-example-bootloader\mbed-os\tools\make.py -t GCC_ARM -m NUCLEO_L476RG --source . --build .\BUILD\NUCLEO_L476RG\GCC_ARM"
       Tip: You could retry the last command with "-v" flag for verbose output
---
PS C:\Users\p\Desktop\workspace\mbed-os-example-bootloader>`

When I build program in Mbed Studio I got this same error

Building project mbed-os-example-bootloader (NUCLEO_L476RG, ARMC6)
Scan: mbed-os-example-bootloader
Compile [  5.8%]: CellularLog.cpp
Compile [  5.9%]: AT_ControlPlane_netif.cpp
Compile [  6.0%]: AT_CellularStack.cpp
Compile [  6.1%]: CellularUtil.cpp
Compile [  6.2%]: CellularContext.cpp
Compile [  6.3%]: CellularDevice.cpp
Compile [  6.5%]: CellularStateMachine.cpp
Compile [  6.6%]: GEMALTO_CINTERION_CellularInformation.cpp
Compile [  6.7%]: GEMALTO_CINTERION.cpp
Compile [  6.8%]: GEMALTO_CINTERION_CellularContext.cpp
Compile [  6.9%]: main.cpp
[ERROR] .\main.cpp:2:10: fatal error: 'SDBlockDevice.h' file not found
#include "SDBlockDevice.h"
^~~~~~~~~~~~~~~~~
1 error generated.

This is simple example program from github, I tryed on NUCLEO_476RG (my change in mbed_app.json) and NUCLEO_F429ZI.

@mark-edgeworth
Copy link
Contributor

I've been able to repeat this - looks like an issue with this specific target as it works ok with K64F

@mark-edgeworth mark-edgeworth reopened this Oct 2, 2019
@SeppoTakalo
Copy link
Contributor

https://github.com/ARMmbed/mbed-os-example-bootloader#required-hardware
There is list of boards that this example is meant to work.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2019

@mark-edgeworth mark-edgeworth reopened this 16 days ago

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?

@madchutney
Copy link
Contributor

@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.

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 21, 2019

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.
I would like to close this if there is no update in the next 2 weeks planned (this is documented in our workflow, we don't keep opened PRs without a progress for weeks. Closure should not be taken as "won't fix".).

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 28, 2019

The referenced issue is opened, still valid bug that needs fixing and this can be reopened once updated

@0xc0170 0xc0170 closed this Oct 28, 2019
@amq
Copy link
Contributor

amq commented Nov 10, 2019

Without this, the bootloader functionality is broken for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bootloader Merging Regions Error