Skip to content

Commit 776ee26

Browse files
nvlsianpuanangl
authored andcommitted
[nrf noup] boot/../loader: skip downgrade prevention for s1/s0
This patch introduces skip on checking downgrade for s1/s0 upgrade image (chain-loaded by NSIB). which is used for upgrade MCUboot instance itself. Reason is that sdk-mcuboot has not access to semantic version of its own image. I also shouldn't touch HW counter used for hardware downgrade prevention for the application image (which was the case). HW counters for s0/s1 image are owned by NSIB because its role is to prevnt dongrades of s0/s1 MCUboot. Signed-off-by: Andrzej Puzdrowski <[email protected]>
1 parent 6869a65 commit 776ee26

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

boot/bootutil/src/loader.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ int pcd_version_cmp_net(const struct flash_area *fap, struct image_header *hdr);
7070
BOOT_LOG_MODULE_DECLARE(mcuboot);
7171

7272
static struct boot_loader_state boot_data;
73+
#ifdef PM_S1_ADDRESS
74+
static bool owner_nsib[BOOT_IMAGE_NUMBER] = {false};
75+
#endif
7376

7477
#if (BOOT_IMAGE_NUMBER > 1)
7578
#define IMAGES_ITER(x) for ((x) = 0; (x) < BOOT_IMAGE_NUMBER; ++(x))
@@ -1286,6 +1289,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
12861289
int swap_type;
12871290
FIH_DECLARE(fih_rc, FIH_FAILURE);
12881291
bool upgrade_valid = false;
1292+
#if defined(PM_S1_ADDRESS)
1293+
owner_nsib[BOOT_CURR_IMG(state)] = false;
1294+
#endif
12891295

12901296
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
12911297
const struct flash_area *secondary_fa =
@@ -1342,6 +1348,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
13421348
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
13431349
/* Set primary to be NSIB upgrade slot */
13441350
BOOT_IMG_AREA(state, 0) = nsib_fa;
1351+
owner_nsib[BOOT_CURR_IMG(state)] = true;
13451352
}
13461353
#else
13471354
return BOOT_SWAP_TYPE_NONE;
@@ -1352,6 +1359,10 @@ boot_validated_swap_type(struct boot_loader_state *state,
13521359
/* The image in the secondary slot is not intended for any */
13531360
return BOOT_SWAP_TYPE_NONE;
13541361
}
1362+
1363+
if ((primary_fa->fa_off == PM_S0_ADDRESS) || (primary_fa->fa_off == PM_S1_ADDRESS)) {
1364+
owner_nsib[BOOT_CURR_IMG(state)] = true;
1365+
}
13551366
}
13561367
#endif /* PM_S1_ADDRESS */
13571368
sec_slot_mark_assigned(state);
@@ -2291,6 +2302,13 @@ check_downgrade_prevention(struct boot_loader_state *state)
22912302
uint32_t security_counter[2];
22922303
int rc;
22932304

2305+
#if defined(PM_S1_ADDRESS)
2306+
if (owner_nsib[BOOT_CURR_IMG(state)]) {
2307+
/* Downgrade prevention on S0/S1 image is managed by NSIB */
2308+
return 0;
2309+
}
2310+
#endif
2311+
22942312
if (MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER) {
22952313
/* If there was security no counter in slot 0, allow swap */
22962314
rc = bootutil_get_img_security_cnt(&(BOOT_IMG(state, 0).hdr),

0 commit comments

Comments
 (0)