Skip to content

Conversation

@wiktorkwiatkowski
Copy link
Contributor

Boot trailer size was hardcoded to 128 sectors, ignoring the value set in syscfg. This caused mismatches between trailer size and the actual image size when BOOTUTIL_MAX_IMG_SECTORS was set to value other than 128, potentially making images not fit in the slot. Now the trailer size is calculated based on the syscfg value.

Comment on lines 801 to 818
sectors, ok := t.res.Cfg.Settings["BOOTUTIL_MAX_IMG_SECTORS"]
if !ok {
util.StatusMessage(util.VERBOSITY_DEFAULT,
"* Warning: target does not define BOOTUTIL_MAX_IMG_SECTORS "+
"setting; assuming a value of 128.\n")
maxImgSectors = 128
} else {
val, err := util.AtoiNoOct(sectors.Value)
if err != nil {
util.StatusMessage(util.VERBOSITY_DEFAULT,
"* Warning: target specifies invalid non-integer "+
"BOOTUTIL_MAX_IMG_SECTORS setting; assuming a "+
"value of 128.\n")
maxImgSectors = 128
} else {
maxImgSectors = val
}
}
Copy link
Contributor

@m-gorecki m-gorecki Oct 7, 2025

Choose a reason for hiding this comment

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

This does the same as previous block of code for MCU_FLASH_MIN_WRITE_SIZE. You could add private helper function which will validate the setting and return it's value (or default value if proper setting is not present). Helper would be used like this:

	minWriteSz := t.getSettingIntValue(t.res.Cfg.Settings, "MCU_FLASH_MIN_WRITE_SIZE", 1)
	maxImgSectors := t.getSettingIntValue(t.res.Cfg.Settings, "BOOTUTIL_MAX_IMG_SECTORS", 128)

where 1 and 128 are configurable default values returned in case of wrong/lack of syscfg.

@wiktorkwiatkowski wiktorkwiatkowski force-pushed the target_build branch 3 times, most recently from bc055e7 to 58ec2a8 Compare October 9, 2025 09:25
Boot trailer size was hardcoded to 128 sectors, ignoring the value
set in syscfg. This caused mismatches between trailer size and
the actual image size when BOOTUTIL_MAX_IMG_SECTORS was set to
value other than 128, potentially making images not fit
in the slot. Now the trailer size is calculated based on the syscfg
value.
Copy link
Contributor

@kasjer kasjer left a comment

Choose a reason for hiding this comment

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

Verified to work correctly on STM32L4. Previously if image was close to slot size MCUBOOT failed to swap. Now image is reported as too big.

@m-gorecki m-gorecki merged commit 1127fdc into apache:master Oct 13, 2025
70 checks passed
@wiktorkwiatkowski wiktorkwiatkowski deleted the target_build branch October 13, 2025 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants