Skip to content

Logical sectors #2352

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Conversation

de-nordic
Copy link
Collaborator

@de-nordic de-nordic commented Jun 23, 2025

So far tested on nrf52840 with internal memory only.
Normal build from main, with hardware pages/sectors

Memory region         Used Size  Region Size  %age Used
           FLASH:       32716 B        48 KB     66.56%
             RAM:       22464 B       256 KB      8.57%
        IDT_LIST:          0 GB        32 KB      0.00%

Logical sectors ( -DCONFIG_MCUBOOT_LOGICAL_SECTOR_SIZE=4096 -DCONFIG_FLASH_PAGE_LAYOUT=n)

Memory region         Used Size  Region Size  %age Used
           FLASH:       32188 B        48 KB     65.49%
             RAM:       20544 B       256 KB      7.84%
        IDT_LIST:          0 GB        32 KB      0.00%

Logical sectors validation build (-DCONFIG_MCUBOOT_LOGICAL_SECTOR_SIZE=4096 -DCONFIG_MCUBOOT_LOGICAL_SECTOR_VALIDATION=y)

Memory region         Used Size  Region Size  %age Used
           FLASH:       33452 B        48 KB     68.06%
             RAM:       20544 B       256 KB      7.84%
        IDT_LIST:          0 GB        32 KB      0.00%

@de-nordic de-nordic force-pushed the this-is-not-your-sector branch 7 times, most recently from 40981d5 to 2e41af6 Compare June 27, 2025 14:43
@de-nordic de-nordic force-pushed the this-is-not-your-sector branch from 2e41af6 to 549cffc Compare July 2, 2025 15:36
@de-nordic de-nordic requested a review from Copilot July 2, 2025 15:37
Copilot

This comment was marked as outdated.

@de-nordic de-nordic force-pushed the this-is-not-your-sector branch from 4b00235 to 31268f1 Compare July 2, 2025 16:03
@de-nordic de-nordic requested a review from Copilot July 2, 2025 16:03
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds support for using fixed-size “logical” flash sectors (and optional run-time validation) instead of querying hardware page layouts in MCUBoot on Zephyr.

  • Introduce MCUBOOT_LOGICAL_SECTOR_SIZE and validation macros in mcuboot_config.h and Kconfig
  • Update flash_map_extended.c, CMakeLists, and loader/private/util code to switch between hardware and logical sectors
  • Remove legacy flash_map_legacy.c fallback and adjust build logic for flash layout

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
boot/zephyr/include/mcuboot_config/mcuboot_config.h Define MCUBOOT_LOGICAL_SECTOR_SIZE and MCUBOOT_LOGICAL_SECTOR_VALIDATION
boot/zephyr/flash_map_legacy.c Removed obsolete legacy page-layout fallback
boot/zephyr/flash_map_extended.c Conditional logic for logical sectors and validation in flash APIs
boot/zephyr/Kconfig Add Kconfig options for logical sector size and validation
boot/zephyr/CMakeLists.txt Stop including legacy flash_map fallback unconditionally
boot/bootutil/src/loader.c Wrap split_image_check and context code to skip on logical sectors
boot/bootutil/src/bootutil_priv.h Conditional sector fields and inline functions for logical sectors
boot/bootutil/src/bootutil_misc.c Add boot_validate_logical_sectors and adjust area initialization
Comments suppressed due to low confidence (4)

boot/zephyr/CMakeLists.txt:89

  • Unconditionally removing the legacy flash_map_legacy.c include may break builds when neither FLASH_PAGE_LAYOUT nor logical sectors are enabled. Consider re-adding a conditional to include it when both are off.
      )

boot/zephyr/Kconfig:1104

  • [nitpick] The name MCUBOOT_LOGICAL_SECTOR_SIZE_SET is ambiguous; consider renaming to something like MCUBOOT_LOGICAL_SECTOR_ENABLED to clearly indicate it toggles logical-sector mode.
config MCUBOOT_LOGICAL_SECTOR_SIZE_SET

boot/zephyr/Kconfig:1124

  • If logical sectors are enabled but validation is disabled, FLASH_PAGE_LAYOUT will not be selected, which can break flash layout support. Ensure FLASH_PAGE_LAYOUT is selected whenever hardware page info is needed.
	select FLASH_PAGE_LAYOUT if FLASH_HAS_PAGE_LAYOUT && !MCUBOOT_LOGICAL_SECTOR_SIZE_SET

boot/bootutil/src/loader.c:654

  • [nitpick] Add a matching comment on the #endif (e.g. /* logical sectors disabled */) to clearly link the conditional guard to its closing directive.
#if !defined(MCUBOOT_LOGICAL_SECTOR_SIZE) || MCUBOOT_LOGICAL_SECTOR_SIZE == 0

@de-nordic de-nordic added area: core Affects core functionality area: zephyr Affects the Zephyr port labels Jul 8, 2025
The function has been provided to support Zephyr, but is not
needed anymore.
It does not even compile, actually.

Signed-off-by: Dominik Ermel <[email protected]>
The commit adds support for logical/software sectors. User can
select size of sector by which image will be moved using
configuration identifier MCUBOOT_LOGICAL_SECTOR_SIZE.
Non-0 value set to MCUBOOT_LOGICAL_SECTOR_SIZE will be used
as sector size for image swap algorithms. Note that the value provided
here should be aligned to hardware erase page of device(s) used
and may not be smaller than of such a device.
There is also additional option provided, MCUBOOT_LOGICAL_SECTOR_VALIDATE,
that allows to enable validation of selected logical sector against
true layout of a device.

Signed-off-by: Dominik Ermel <[email protected]>
Add Kconfigs:
 - CONFIG_MCUBOOT_LOGICAL_SECTOR_SIZE
 - CONFIG_MCUBOOT_LOGICAL_SECTOR_VALIDATION

Signed-off-by: Dominik Ermel <[email protected]>
@de-nordic de-nordic force-pushed the this-is-not-your-sector branch from c165e48 to a0e7f0f Compare July 11, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Affects core functionality area: zephyr Affects the Zephyr port
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant