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

Allow larger primary slot in swap-move

When using swap in move mode, the current compatibility test only allows
for same size and layout between slots. This results in one sector that
can never be used in the secondary slot, which corresponds to the first
move up operation in the primary slot. This relaxes and checking a bit,
so both same size slots and a primary with one extra sector are valid.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent a333a457
Loading
Loading
Loading
Loading
+21 −8
Changes for boot/bootutil/src/swap_move.c: 21 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -212,23 +212,36 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
int
boot_slots_compatible(struct boot_loader_state *state)
{
    size_t num_sectors;
    size_t num_sectors_pri;
    size_t num_sectors_sec;
    size_t sector_sz_pri = 0;
    size_t sector_sz_sec = 0;
    size_t i;

    num_sectors = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
    if (num_sectors != boot_img_num_sectors(state, BOOT_SECONDARY_SLOT)) {
        BOOT_LOG_WRN("Cannot upgrade: slots don't have same amount of sectors");
    num_sectors_pri = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
    num_sectors_sec = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT);
    if ((num_sectors_pri != num_sectors_sec) &&
            (num_sectors_pri != (num_sectors_sec + 1))) {
        BOOT_LOG_WRN("Cannot upgrade: not a compatible amount of sectors");
        return 0;
    }

    if (num_sectors > BOOT_MAX_IMG_SECTORS) {
    if (num_sectors_pri > BOOT_MAX_IMG_SECTORS) {
        BOOT_LOG_WRN("Cannot upgrade: more sectors than allowed");
        return 0;
    }

    for (i = 0; i < num_sectors; i++) {
        if (boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i) !=
                boot_img_sector_size(state, BOOT_SECONDARY_SLOT, i)) {
    for (i = 0; i < num_sectors_sec; i++) {
        sector_sz_pri = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i);
        sector_sz_sec = boot_img_sector_size(state, BOOT_SECONDARY_SLOT, i);
        if (sector_sz_pri != sector_sz_sec) {
            BOOT_LOG_WRN("Cannot upgrade: not same sector layout");
            return 0;
        }
    }

    if (num_sectors_pri > num_sectors_sec) {
        if (sector_sz_pri != boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i)) {
            BOOT_LOG_WRN("Cannot upgrade: not same sector layout");
            return 0;
        }