Skip to content
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

zephyr: Add support for automatically calculcating max sectors #2019

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

nordicjm
Copy link
Collaborator

No description provided.

@nordicjm
Copy link
Collaborator Author

How it looks on a device with large (different) sector sizes (stm32f411e_disco):

CMake Warning at CMakeLists.txt:392 (message):
  Unable to determine erase size of slot0 partition, cannot calculate minimum
  sector usage


CMake Warning at CMakeLists.txt:407 (message):
  Unable to determine erase size of slot1 partition, cannot calculate minimum
  sector usage


CMake Warning at CMakeLists.txt:421 (message):
  Unable to calculate minimum number of sector sizes, falling back to 128
  sector default.  Please disable CONFIG_BOOT_MAX_IMG_SECTORS_AUTO and set
  CONFIG_BOOT_MAX_IMG_SECTORS to the required value

It builds and default remains at 128

@nordicjm
Copy link
Collaborator Author

nordicjm commented Jul 25, 2024

@butok interestingly it looks like the nxp ones were a bit optimistic...
boards/mimxrt595_evk_mimxrt595s_cm33.conf:CONFIG_BOOT_MAX_IMG_SECTORS=8192
cmake -GNinja -DBOARD=mimxrt595_evk/mimxrt595s/cm33 ..:

Calculated maximum number of sectors: 866

This means 0xc000 is needed to store the update data but you have actually reserved 0x62000...

Adds a feature that will calculate the maximum number of sectors
that are needed for a build. Can be disabled to revert back to
the old behaviour by disabling CONFIG_BOOT_MAX_IMG_SECTORS_AUTO

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Adds a note about the new feature that has been added

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
@butok
Copy link
Contributor

butok commented Jul 25, 2024

@butok interestingly it looks like the nxp ones were a bit optimistic... boards/mimxrt595_evk_mimxrt595s_cm33.conf:CONFIG_BOOT_MAX_IMG_SECTORS=8192 cmake -GNinja -DBOARD=mimxrt595_evk/mimxrt595s/cm33 ..:

Calculated maximum number of sectors: 866

Is it bad or good?

@nordicjm
Copy link
Collaborator Author

@butok interestingly it looks like the nxp ones were a bit optimistic... boards/mimxrt595_evk_mimxrt595s_cm33.conf:CONFIG_BOOT_MAX_IMG_SECTORS=8192 cmake -GNinja -DBOARD=mimxrt595_evk/mimxrt595s/cm33 ..:

Calculated maximum number of sectors: 866

Is it bad or good?

Updated the comment just as you posted:

This means 0xc000 is needed to store the update data but you have actually reserved 0x62000...

That's 344KiB of wasted space

@butok
Copy link
Contributor

butok commented Jul 25, 2024

@butok interestingly it looks like the nxp ones were a bit optimistic... boards/mimxrt595_evk_mimxrt595s_cm33.conf:CONFIG_BOOT_MAX_IMG_SECTORS=8192 cmake -GNinja -DBOARD=mimxrt595_evk/mimxrt595s/cm33 ..:

Calculated maximum number of sectors: 866

Is it bad or good?

Updated the comment just as you posted:

This means 0xc000 is needed to store the update data but you have actually reserved 0x62000...

That's 344KiB of wasted space

The board has 64MB, so the configuration value was set to have a bigger coverage.
BUT when you will add this automatic calculation, we can remove all CONFIG_BOOT_MAX_IMG_SECTORS from board configs.

dt_prop(slot0_size PATH "${slot0_flash}" PROPERTY "reg" INDEX 1)
dt_get_parent(slot0_flash)
dt_get_parent(slot0_flash)
dt_prop(erase_size_slot0 PATH "${slot0_flash}" PROPERTY "erase-block-size")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda do not like that we get to the Flash device layer to get this information as I think that we start to pick information that we should not access directly from scripts, but unless the DTS parsing script does not start definitions for info like number of pages per partitions this is the only way. Still this makes changes to dts harder in the future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other problem is that I don't believe the code cares what this property is even set to. The flash api directly asks the driver about the erase block size. And that API is needlessly complicated to allow for devices with variable sized sectors, even though the only reasonable thing to do with them in mcuboot is treat the device as if all of the sectors were the size of the largest one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this means is that if this property is at a mismatch with the underlying device, the calculation will be wrong. For example, people have reported trying to increase the erase size in the DT, to discover it didn't work, as the code still asked the device what the real sector size is.

I think we should look into changing things so that mcuboot uses this property only to determine the erase-block-size. This will make it easier to support multiple devices by just setting the value to the largest size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For variably sized sectors, like some stm32 parts, that property is not set and this will give the warning then use the existing default of 128 instead, I did give it a try

@nordicjm nordicjm merged commit 4baa6d3 into mcu-tools:main Aug 13, 2024
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: zephyr Affects the Zephyr port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants