diff --git a/subsys/dfu/boot/mcuboot.c b/subsys/dfu/boot/mcuboot.c index 90fe60870dd..a905331e1ee 100644 --- a/subsys/dfu/boot/mcuboot.c +++ b/subsys/dfu/boot/mcuboot.c @@ -71,12 +71,12 @@ struct mcuboot_v1_raw_header { /* DT_FLASH_AREA_IMAGE_XX_YY values used below are auto-generated by DT */ #ifdef CONFIG_TRUSTED_EXECUTION_NONSECURE -#define FLASH_BANK0_ID DT_FLASH_AREA_IMAGE_0_NONSECURE_ID -#define FLASH_BANK1_ID DT_FLASH_AREA_IMAGE_1_NONSECURE_ID +#define FLASH_AREA_IMAGE_PRIMARY DT_FLASH_AREA_IMAGE_0_NONSECURE_ID +#define FLASH_AREA_IMAGE_SECONDARY DT_FLASH_AREA_IMAGE_1_NONSECURE_ID #define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID #else -#define FLASH_BANK0_ID DT_FLASH_AREA_IMAGE_0_ID -#define FLASH_BANK1_ID DT_FLASH_AREA_IMAGE_1_ID +#define FLASH_AREA_IMAGE_PRIMARY DT_FLASH_AREA_IMAGE_0_ID +#define FLASH_AREA_IMAGE_SECONDARY DT_FLASH_AREA_IMAGE_1_ID #define FLASH_AREA_IMAGE_SCRATCH DT_FLASH_AREA_IMAGE_SCRATCH_ID #endif /* CONFIG_TRUSTED_EXECUTION_NONSECURE */ @@ -96,11 +96,11 @@ static const u32_t boot_img_magic[4] = { struct boot_swap_table { /** For each field, a value of 0 means "any". */ - u8_t magic_slot0; - u8_t magic_slot1; - u8_t image_ok_slot0; - u8_t image_ok_slot1; - u8_t copy_done_slot0; + u8_t magic_primary_slot; + u8_t magic_secondary_slot; + u8_t image_ok_primary_slot; + u8_t image_ok_secondary_slot; + u8_t copy_done_primary_slot; u8_t swap_type; }; @@ -126,12 +126,12 @@ static const struct boot_swap_table boot_swap_tables[] = { * swap: test | * -----------------------------------' */ - .magic_slot0 = 0, - .magic_slot1 = BOOT_MAGIC_GOOD, - .image_ok_slot0 = 0, - .image_ok_slot1 = 0xff, - .copy_done_slot0 = 0, - .swap_type = BOOT_SWAP_TYPE_TEST, + .magic_primary_slot = 0, + .magic_secondary_slot = BOOT_MAGIC_GOOD, + .image_ok_primary_slot = 0, + .image_ok_secondary_slot = 0xff, + .copy_done_primary_slot = 0, + .swap_type = BOOT_SWAP_TYPE_TEST, }, { /* | slot-0 | slot-1 | @@ -142,12 +142,12 @@ static const struct boot_swap_table boot_swap_tables[] = { * swap: permanent | * -----------------------------------' */ - .magic_slot0 = 0, - .magic_slot1 = BOOT_MAGIC_GOOD, - .image_ok_slot0 = 0, - .image_ok_slot1 = 0x01, - .copy_done_slot0 = 0, - .swap_type = BOOT_SWAP_TYPE_PERM, + .magic_primary_slot = 0, + .magic_secondary_slot = BOOT_MAGIC_GOOD, + .image_ok_primary_slot = 0, + .image_ok_secondary_slot = 0x01, + .copy_done_primary_slot = 0, + .swap_type = BOOT_SWAP_TYPE_PERM, }, { /* | slot-0 | slot-1 | @@ -158,12 +158,12 @@ static const struct boot_swap_table boot_swap_tables[] = { * swap: revert (test image running) | * -----------------------------------' */ - .magic_slot0 = BOOT_MAGIC_GOOD, - .magic_slot1 = BOOT_MAGIC_UNSET, - .image_ok_slot0 = 0xff, - .image_ok_slot1 = 0, - .copy_done_slot0 = 0x01, - .swap_type = BOOT_SWAP_TYPE_REVERT, + .magic_primary_slot = BOOT_MAGIC_GOOD, + .magic_secondary_slot = BOOT_MAGIC_UNSET, + .image_ok_primary_slot = 0xff, + .image_ok_secondary_slot = 0, + .copy_done_primary_slot = 0x01, + .swap_type = BOOT_SWAP_TYPE_REVERT, }, }; #define BOOT_SWAP_TABLES_COUNT (ARRAY_SIZE(boot_swap_tables)) @@ -426,17 +426,19 @@ static int boot_read_swap_state(u8_t bank_id, struct boot_swap_state *state) int mcuboot_swap_type(void) { const struct boot_swap_table *table; - struct boot_swap_state state_slot0; - struct boot_swap_state state_slot1; + struct boot_swap_state state_primary_slot; + struct boot_swap_state state_secondary_slot; int rc; int i; - rc = boot_read_swap_state(FLASH_BANK0_ID, &state_slot0); + rc = boot_read_swap_state(FLASH_AREA_IMAGE_PRIMARY, + &state_primary_slot); if (rc != 0) { return rc; } - rc = boot_read_swap_state(FLASH_BANK1_ID, &state_slot1); + rc = boot_read_swap_state(FLASH_AREA_IMAGE_SECONDARY, + &state_secondary_slot); if (rc != 0) { return rc; } @@ -444,16 +446,23 @@ int mcuboot_swap_type(void) for (i = 0; i < BOOT_SWAP_TABLES_COUNT; i++) { table = boot_swap_tables + i; - if ((table->magic_slot0 == 0U || - table->magic_slot0 == state_slot0.magic) && - (table->magic_slot1 == 0U || - table->magic_slot1 == state_slot1.magic) && - (table->image_ok_slot0 == 0U || - table->image_ok_slot0 == state_slot0.image_ok) && - (table->image_ok_slot1 == 0U || - table->image_ok_slot1 == state_slot1.image_ok) && - (table->copy_done_slot0 == 0U || - table->copy_done_slot0 == state_slot0.copy_done)) { + if ((table->magic_primary_slot == 0U || + table->magic_primary_slot == state_primary_slot.magic) + && + (table->magic_secondary_slot == 0U || + table->magic_secondary_slot == state_secondary_slot.magic) + && + (table->image_ok_primary_slot == 0U || + table->image_ok_primary_slot == + state_primary_slot.image_ok) + && + (table->image_ok_secondary_slot == 0U || + table->image_ok_secondary_slot == + state_secondary_slot.image_ok) + && + (table->copy_done_primary_slot == 0U || + table->copy_done_primary_slot == + state_primary_slot.copy_done)) { assert(table->swap_type == BOOT_SWAP_TYPE_TEST || table->swap_type == BOOT_SWAP_TYPE_PERM || @@ -469,9 +478,9 @@ int boot_request_upgrade(int permanent) { int rc; - rc = boot_magic_write(FLASH_BANK1_ID); + rc = boot_magic_write(FLASH_AREA_IMAGE_SECONDARY); if (rc == 0 && permanent) { - rc = boot_image_ok_write(FLASH_BANK1_ID); + rc = boot_image_ok_write(FLASH_AREA_IMAGE_SECONDARY); } return rc; @@ -479,19 +488,19 @@ int boot_request_upgrade(int permanent) bool boot_is_img_confirmed(void) { - return boot_image_ok_read(FLASH_BANK0_ID) == BOOT_FLAG_SET; + return boot_image_ok_read(FLASH_AREA_IMAGE_PRIMARY) == BOOT_FLAG_SET; } int boot_write_img_confirmed(void) { int rc; - if (boot_image_ok_read(FLASH_BANK0_ID) != BOOT_FLAG_UNSET) { + if (boot_image_ok_read(FLASH_AREA_IMAGE_PRIMARY) != BOOT_FLAG_UNSET) { /* Already confirmed. */ return 0; } - rc = boot_image_ok_write(FLASH_BANK0_ID); + rc = boot_image_ok_write(FLASH_AREA_IMAGE_PRIMARY); return rc; }