Skip to content

Commit 1953d93

Browse files
nvlsianpurlubos
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]> (cherry picked from commit cc78118)
1 parent 8f74833 commit 1953d93

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 defined(MCUBOOT_SERIAL_IMG_GRP_SLOT_INFO) || defined(MCUBOOT_DATA_SHARING)
7578
static struct image_max_size image_max_sizes[BOOT_IMAGE_NUMBER] = {0};
@@ -1370,6 +1373,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
13701373
int swap_type;
13711374
FIH_DECLARE(fih_rc, FIH_FAILURE);
13721375
bool upgrade_valid = false;
1376+
#if defined(PM_S1_ADDRESS)
1377+
owner_nsib[BOOT_CURR_IMG(state)] = false;
1378+
#endif
13731379

13741380
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
13751381
const struct flash_area *secondary_fa =
@@ -1426,6 +1432,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
14261432
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
14271433
/* Set primary to be NSIB upgrade slot */
14281434
BOOT_IMG_AREA(state, 0) = nsib_fa;
1435+
owner_nsib[BOOT_CURR_IMG(state)] = true;
14291436
}
14301437
#else
14311438
return BOOT_SWAP_TYPE_NONE;
@@ -1436,6 +1443,10 @@ boot_validated_swap_type(struct boot_loader_state *state,
14361443
/* The image in the secondary slot is not intended for any */
14371444
return BOOT_SWAP_TYPE_NONE;
14381445
}
1446+
1447+
if ((primary_fa->fa_off == PM_S0_ADDRESS) || (primary_fa->fa_off == PM_S1_ADDRESS)) {
1448+
owner_nsib[BOOT_CURR_IMG(state)] = true;
1449+
}
14391450
}
14401451
#endif /* PM_S1_ADDRESS */
14411452
sec_slot_mark_assigned(state);
@@ -2409,6 +2420,13 @@ check_downgrade_prevention(struct boot_loader_state *state)
24092420
uint32_t security_counter[2];
24102421
int rc;
24112422

2423+
#if defined(PM_S1_ADDRESS)
2424+
if (owner_nsib[BOOT_CURR_IMG(state)]) {
2425+
/* Downgrade prevention on S0/S1 image is managed by NSIB */
2426+
return 0;
2427+
}
2428+
#endif
2429+
24122430
if (MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER) {
24132431
/* If there was security no counter in slot 0, allow swap */
24142432
rc = bootutil_get_img_security_cnt(&(BOOT_IMG(state, 0).hdr),

0 commit comments

Comments
 (0)