Skip to content

Commit 30b9064

Browse files
newt/builder: read BOOTUTIL_MAX_IMG_SECTORS from syscfg for boot trailer
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.
1 parent 1a2a075 commit 30b9064

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

newt/builder/targetbuild.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ func (t *TargetBuilder) InjectSetting(key string, value string) {
777777
// that must be reserved at the end of each image slot.
778778
func (t *TargetBuilder) bootTrailerSize() int {
779779
var minWriteSz int
780+
var maxImgSectors int
780781

781782
entry, ok := t.res.Cfg.Settings["MCU_FLASH_MIN_WRITE_SIZE"]
782783
if !ok {
@@ -797,6 +798,26 @@ func (t *TargetBuilder) bootTrailerSize() int {
797798
}
798799
}
799800

801+
sectors, ok := t.res.Cfg.Settings["BOOTUTIL_MAX_IMG_SECTORS"]
802+
if !ok {
803+
util.StatusMessage(util.VERBOSITY_DEFAULT,
804+
"* Warning: target does not define BOOTUTIL_MAX_IMG_SECTORS "+
805+
"setting; assuming a value of 128.\n")
806+
maxImgSectors = 128
807+
} else {
808+
val, err := util.AtoiNoOct(sectors.Value)
809+
if err != nil {
810+
util.StatusMessage(util.VERBOSITY_DEFAULT,
811+
"* Warning: target specifies invalid non-integer "+
812+
"BOOTUTIL_MAX_IMG_SECTORS setting; assuming a "+
813+
"value of 128.\n")
814+
maxImgSectors = 128
815+
} else {
816+
maxImgSectors = val
817+
}
818+
}
819+
820+
800821
/* Mynewt boot trailer format:
801822
*
802823
* 0 1 2 3
@@ -814,12 +835,13 @@ func (t *TargetBuilder) bootTrailerSize() int {
814835
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815836
*/
816837

838+
817839
tsize := 16 + // Magic.
818-
128*minWriteSz*3 + // Swap status.
840+
maxImgSectors*minWriteSz*3 + // Swap status.
819841
minWriteSz + // Copy done.
820842
minWriteSz // Image Ok.
821843

822-
log.Debugf("Min-write-size=%d; boot-trailer-size=%d", minWriteSz, tsize)
844+
log.Debugf("Min-write-size=%d; max-img-sectors=%d; boot-trailer-size=%d", minWriteSz, maxImgSectors, tsize)
823845

824846
return tsize
825847
}

0 commit comments

Comments
 (0)