Skip to content

Commit 64a4660

Browse files
nvlsianpubjarki-andreasen
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 776ee26)
1 parent 00e5d49 commit 64a4660

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};
@@ -1338,6 +1341,9 @@ boot_validated_swap_type(struct boot_loader_state *state,
13381341
int swap_type;
13391342
FIH_DECLARE(fih_rc, FIH_FAILURE);
13401343
bool upgrade_valid = false;
1344+
#if defined(PM_S1_ADDRESS)
1345+
owner_nsib[BOOT_CURR_IMG(state)] = false;
1346+
#endif
13411347

13421348
#if defined(PM_S1_ADDRESS) || defined(CONFIG_SOC_NRF5340_CPUAPP)
13431349
const struct flash_area *secondary_fa =
@@ -1394,6 +1400,7 @@ boot_validated_swap_type(struct boot_loader_state *state,
13941400
&& reset_addr < (nsib_fa->fa_off + nsib_fa->fa_size)) {
13951401
/* Set primary to be NSIB upgrade slot */
13961402
BOOT_IMG_AREA(state, 0) = nsib_fa;
1403+
owner_nsib[BOOT_CURR_IMG(state)] = true;
13971404
}
13981405
#else
13991406
return BOOT_SWAP_TYPE_NONE;
@@ -1404,6 +1411,10 @@ boot_validated_swap_type(struct boot_loader_state *state,
14041411
/* The image in the secondary slot is not intended for any */
14051412
return BOOT_SWAP_TYPE_NONE;
14061413
}
1414+
1415+
if ((primary_fa->fa_off == PM_S0_ADDRESS) || (primary_fa->fa_off == PM_S1_ADDRESS)) {
1416+
owner_nsib[BOOT_CURR_IMG(state)] = true;
1417+
}
14071418
}
14081419
#endif /* PM_S1_ADDRESS */
14091420
sec_slot_mark_assigned(state);
@@ -2371,6 +2382,13 @@ check_downgrade_prevention(struct boot_loader_state *state)
23712382
uint32_t security_counter[2];
23722383
int rc;
23732384

2385+
#if defined(PM_S1_ADDRESS)
2386+
if (owner_nsib[BOOT_CURR_IMG(state)]) {
2387+
/* Downgrade prevention on S0/S1 image is managed by NSIB */
2388+
return 0;
2389+
}
2390+
#endif
2391+
23742392
if (MCUBOOT_DOWNGRADE_PREVENTION_SECURITY_COUNTER) {
23752393
/* If there was security no counter in slot 0, allow swap */
23762394
rc = bootutil_get_img_security_cnt(&(BOOT_IMG(state, 0).hdr),

0 commit comments

Comments
 (0)