Commit a1fae67d authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Add config for BOOT_MAX_IMG_SECTORS

This still defaults to 128 for compatibility, but allows users to
specify less elements to save space, or more elements for devices that
have massive flash size and/or too small sectors.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent e09e2084
Loading
Loading
Loading
Loading
+26 −7
Changes for boot/bootutil/src/bootutil_priv.h: 26 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -90,8 +90,33 @@ struct boot_swap_state {
    uint8_t image_ok;
};

#if defined(__BOOTSIM__)
#define BOOT_MAX_IMG_SECTORS       128
#elif defined(__ZEPHYR__)
#define BOOT_MAX_IMG_SECTORS       CONFIG_BOOT_MAX_IMG_SECTORS
#elif defined(MCUBOOT_MYNEWT)
#define BOOT_MAX_IMG_SECTORS       MYNEWT_VAL(BOOTUTIL_MAX_IMG_SECTORS)
#else
#error "Invalid target OS"
#endif

/*
 * The current flashmap API does not check the amount of space allocated when
 * loading sector data from the flash device, allowing for smaller counts here
 * would most surely incur in overruns.
 *
 * TODO: make flashmap API receive the current sector array size.
 */
#if BOOT_MAX_IMG_SECTORS < 32
#error "Too few sectors, please increase BOOT_MAX_IMG_SECTORS to at least 32"
#endif

/** Number of image slots in flash; currently limited to two. */
#define BOOT_NUM_SLOTS             2

/** Maximum number of image sectors supported by the bootloader. */
#define BOOT_STATUS_STATE_COUNT    3
#define BOOT_STATUS_MAX_ENTRIES 128
#define BOOT_STATUS_MAX_ENTRIES    BOOT_MAX_IMG_SECTORS

#define BOOT_STATUS_SOURCE_NONE    0
#define BOOT_STATUS_SOURCE_SCRATCH 1
@@ -105,12 +130,6 @@ struct boot_swap_state {

extern const uint32_t BOOT_MAGIC_SZ;

/** Number of image slots in flash; currently limited to two. */
#define BOOT_NUM_SLOTS              2

/** Maximum number of image sectors supported by the bootloader. */
#define BOOT_MAX_IMG_SECTORS        120

/**
 * Compatibility shim for flash sector type.
 *
+10
Changes for boot/bootutil/src/loader.c: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -337,14 +337,22 @@ boot_slots_compatible(void)
    size_t size_0, size_1;
    size_t i;

    if (num_sectors_0 > BOOT_MAX_IMG_SECTORS || num_sectors_1 > BOOT_MAX_IMG_SECTORS) {
        BOOT_LOG_WRN("Cannot upgrade: more sectors than allowed");
        return 0;
    }

    /* Ensure both image slots have identical sector layouts. */
    if (num_sectors_0 != num_sectors_1) {
        BOOT_LOG_WRN("Cannot upgrade: number of sectors differ between slots");
        return 0;
    }

    for (i = 0; i < num_sectors_0; i++) {
        size_0 = boot_img_sector_size(&boot_data, 0, i);
        size_1 = boot_img_sector_size(&boot_data, 1, i);
        if (size_0 != size_1) {
            BOOT_LOG_WRN("Cannot upgrade: an incompatible sector was found");
            return 0;
        }
    }
@@ -1336,6 +1344,8 @@ boot_go(struct boot_rsp *rsp)
    /* Determine the sector layout of the image slots and scratch area. */
    rc = boot_read_sectors();
    if (rc != 0) {
        BOOT_LOG_WRN("Failed reading sectors; BOOT_MAX_IMG_SECTORS=%d - too small?",
                BOOT_MAX_IMG_SECTORS);
        goto out;
    }

+4 −1
Changes for boot/mynewt/mcuboot_config/syscfg.yml: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -44,5 +44,8 @@ syscfg.defs:
        description: 'Use faster copy only upgrade.'
        value: 1
    BOOTUTIL_IMAGE_FORMAT_V2:
        description: 'Indicates that system is using v2 of image format'
        description: 'Indicates that system is using v2 of image format.'
        value: 1
    BOOTUTIL_MAX_IMG_SECTORS:
        description: 'Maximum number of sectors that are swapped.'
        value: 128
+6
Changes for boot/zephyr/Kconfig: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -38,6 +38,12 @@ menuconfig MCUBOOT_SERIAL
	help
	  Enable serial recovery feature in mcuboot.

config BOOT_MAX_IMG_SECTORS
	int "max number of sectors per image slot"
	default 128
	help
	  Maximum number of sectors that a swap upgrade can handle

config BOOT_MAX_LINE_INPUT_LEN
	int "cmd line max length"
	default 512