Skip to content

Commit e8ddb17

Browse files
nordicjmjukkar
authored andcommitted
[nrf noup] boot: bootutil: Fix b0 checks
nrf-squash! [nrf noup] treewide: add NCS partition manager support Fixes invalid checks for b0 that would wrongly skip checking if partition sizes were valid for the non-b0 updates when b0 updates were generally enabled, and ports the check to swap using offset also Signed-off-by: Jamie McCrae <[email protected]>
1 parent 347a912 commit e8ddb17

File tree

3 files changed

+57
-17
lines changed

3 files changed

+57
-17
lines changed

boot/bootutil/src/swap_move.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
230230
int
231231
boot_slots_compatible(struct boot_loader_state *state)
232232
{
233+
size_t num_sectors_pri;
234+
size_t num_sectors_sec;
235+
size_t sector_sz_pri = 0;
236+
size_t sector_sz_sec = 0;
237+
size_t i;
238+
233239
#ifdef PM_S1_ADDRESS
234240
/* Patch needed for NCS. In this case, image 1 primary points to the other
235241
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
@@ -240,13 +246,17 @@ boot_slots_compatible(struct boot_loader_state *state)
240246
* partition manager is in use, and since we have the same sector size
241247
* in all of our flash.
242248
*/
249+
#if CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER != -1
250+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER) {
243251
return 1;
244-
#else
245-
size_t num_sectors_pri;
246-
size_t num_sectors_sec;
247-
size_t sector_sz_pri = 0;
248-
size_t sector_sz_sec = 0;
249-
size_t i;
252+
}
253+
#endif
254+
#if CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1
255+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER) {
256+
return 1;
257+
}
258+
#endif
259+
#endif
250260

251261
num_sectors_pri = boot_img_num_sectors(state, BOOT_SLOT_PRIMARY);
252262
num_sectors_sec = boot_img_num_sectors(state, BOOT_SLOT_SECONDARY);
@@ -307,7 +317,6 @@ boot_slots_compatible(struct boot_loader_state *state)
307317
}
308318

309319
return 1;
310-
#endif /* PM_S1_ADDRESS */
311320
}
312321

313322
#define BOOT_LOG_SWAP_STATE(area, state) \

boot/bootutil/src/swap_offset.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,28 @@ int boot_slots_compatible(struct boot_loader_state *state)
310310
size_t sector_sz_sec = 0;
311311
size_t i;
312312

313+
#ifdef PM_S1_ADDRESS
314+
/* Patch needed for NCS. In this case, image 1 primary points to the other
315+
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
316+
* With this configuration, image 0 and image 1 share the secondary slot.
317+
* Hence, the primary slot of image 1 will be *smaller* than image 1's
318+
* secondary slot. This is not allowed in upstream mcuboot, so we need
319+
* this patch to allow it. Also, all of these checks are redundant when
320+
* partition manager is in use, and since we have the same sector size
321+
* in all of our flash.
322+
*/
323+
#if CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER != -1
324+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER) {
325+
return 1;
326+
}
327+
#endif
328+
#if CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1
329+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER) {
330+
return 1;
331+
}
332+
#endif
333+
#endif
334+
313335
num_sectors_pri = boot_img_num_sectors(state, BOOT_SLOT_PRIMARY);
314336
num_sectors_sec = boot_img_num_sectors(state, BOOT_SLOT_SECONDARY);
315337

boot/bootutil/src/swap_scratch.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,16 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
271271
int
272272
boot_slots_compatible(struct boot_loader_state *state)
273273
{
274+
size_t num_sectors_primary;
275+
size_t num_sectors_secondary;
276+
size_t sz0, sz1;
277+
size_t primary_slot_sz, secondary_slot_sz;
278+
#ifndef MCUBOOT_OVERWRITE_ONLY
279+
size_t scratch_sz;
280+
#endif
281+
size_t i, j;
282+
int8_t smaller;
283+
274284
#ifdef PM_S1_ADDRESS
275285
/* Patch needed for NCS. In this case, image 1 primary points to the other
276286
* B1 slot (ie S0 or S1), and image 0 primary points to the app.
@@ -281,17 +291,17 @@ boot_slots_compatible(struct boot_loader_state *state)
281291
* partition manager is in use, and since we have the same sector size
282292
* in all of our flash.
283293
*/
294+
#if CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER != -1
295+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_NETWORK_CORE_IMAGE_NUMBER) {
284296
return 1;
285-
#else
286-
size_t num_sectors_primary;
287-
size_t num_sectors_secondary;
288-
size_t sz0, sz1;
289-
size_t primary_slot_sz, secondary_slot_sz;
290-
#ifndef MCUBOOT_OVERWRITE_ONLY
291-
size_t scratch_sz;
297+
}
298+
#endif
299+
#if CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER != -1
300+
if (BOOT_CURR_IMG(state) == CONFIG_MCUBOOT_MCUBOOT_IMAGE_NUMBER) {
301+
return 1;
302+
}
303+
#endif
292304
#endif
293-
size_t i, j;
294-
int8_t smaller;
295305

296306
num_sectors_primary = boot_img_num_sectors(state, BOOT_SLOT_PRIMARY);
297307
num_sectors_secondary = boot_img_num_sectors(state, BOOT_SLOT_SECONDARY);
@@ -380,7 +390,6 @@ boot_slots_compatible(struct boot_loader_state *state)
380390
#endif
381391

382392
return 1;
383-
#endif /* PM_S1_ADDRESS */
384393
}
385394

386395
#define BOOT_LOG_SWAP_STATE(area, state) \

0 commit comments

Comments
 (0)