Skip to content

Commit ce24fe6

Browse files
committed
bootutil: Make boot_get_first_trailer_sector available for swap-move
This routine will now also be useful for the swap-move strategy. The trailer size is removed from the list of parameters as it can be easily obtained using the 'state' parameter and it will be more convenient, for the swap-move strategy, not to have to compute it manually before calling 'boot_get_first_trailer_sector'. Signed-off-by: Thomas Altenbach <thomas.altenbach@legrand.com>
1 parent 88294be commit ce24fe6

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

boot/bootutil/src/bootutil_misc.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ boot_write_enc_key(const struct flash_area *fap, uint8_t slot,
397397
}
398398
#endif
399399

400-
#ifdef MCUBOOT_SWAP_USING_SCRATCH
400+
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE)
401401
size_t
402-
boot_get_first_trailer_sector(struct boot_loader_state *state, size_t slot, size_t trailer_sz)
402+
boot_get_first_trailer_sector(struct boot_loader_state *state, size_t slot)
403403
{
404404
size_t first_trailer_sector = boot_img_num_sectors(state, slot) - 1;
405405
size_t sector_sz = boot_img_sector_size(state, slot, first_trailer_sector);
406+
size_t trailer_sz = boot_trailer_sz(BOOT_WRITE_SZ(state));
406407
size_t trailer_sector_sz = sector_sz;
407408

408409
while (trailer_sector_sz < trailer_sz) {
@@ -415,20 +416,21 @@ boot_get_first_trailer_sector(struct boot_loader_state *state, size_t slot, size
415416

416417
return first_trailer_sector;
417418
}
419+
#endif /* MCUBOOT_SWAP_USING_SCRATCH || MCUBOOT_SWAP_USING_MOVE */
418420

421+
#ifdef MCUBOOT_SWAP_USING_SCRATCH
419422
/**
420423
* Returns the offset to the end of the first sector of a given slot that holds image trailer data.
421424
*
422425
* @param state Current bootloader's state.
423426
* @param slot The index of the slot to consider.
424-
* @param trailer_sz The size of the trailer, in bytes.
425427
*
426428
* @return The offset to the end of the first sector of the slot that holds image trailer data.
427429
*/
428430
static uint32_t
429-
get_first_trailer_sector_end_off(struct boot_loader_state *state, size_t slot, size_t trailer_sz)
431+
get_first_trailer_sector_end_off(struct boot_loader_state *state, size_t slot)
430432
{
431-
size_t first_trailer_sector = boot_get_first_trailer_sector(state, slot, trailer_sz);
433+
size_t first_trailer_sector = boot_get_first_trailer_sector(state, slot);
432434

433435
return boot_img_sector_off(state, slot, first_trailer_sector) +
434436
boot_img_sector_size(state, slot, first_trailer_sector);
@@ -455,9 +457,9 @@ uint32_t bootutil_max_image_size(struct boot_loader_state *state, const struct f
455457
* trailer containing part of the trailer in the primary and secondary slot.
456458
*/
457459
size_t trailer_sector_primary_end_off =
458-
get_first_trailer_sector_end_off(state, BOOT_PRIMARY_SLOT, slot_trailer_sz);
460+
get_first_trailer_sector_end_off(state, BOOT_PRIMARY_SLOT);
459461
size_t trailer_sector_secondary_end_off =
460-
get_first_trailer_sector_end_off(state, BOOT_SECONDARY_SLOT, slot_trailer_sz);
462+
get_first_trailer_sector_end_off(state, BOOT_SECONDARY_SLOT);
461463

462464
size_t trailer_sz_in_first_sector;
463465

boot/bootutil/src/bootutil_priv.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,19 +365,18 @@ int boot_read_enc_key(const struct flash_area *fap, uint8_t slot,
365365
struct boot_status *bs);
366366
#endif
367367

368-
#ifdef MCUBOOT_SWAP_USING_SCRATCH
368+
#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE)
369369
/**
370370
* Finds the first sector of a given slot that holds image trailer data.
371371
*
372372
* @param state Current bootloader's state.
373373
* @param slot The index of the slot to consider.
374-
* @param trailer_sz The size of the trailer, in bytes.
375374
*
376375
* @return The index of the first sector of the slot that holds image trailer data.
377376
*/
378377
size_t
379-
boot_get_first_trailer_sector(struct boot_loader_state *state, size_t slot, size_t trailer_sz);
380-
#endif
378+
boot_get_first_trailer_sector(struct boot_loader_state *state, size_t slot);
379+
#endif /* MCUBOOT_SWAP_USING_SCRATCH || MCUBOOT_SWAP_USING_MOVE */
381380

382381
/**
383382
* Checks that a buffer is erased according to what the erase value for the

boot/bootutil/src/swap_scratch.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
592592
* NOTE: `use_scratch` is a temporary flag (never written to flash) which
593593
* controls if special handling is needed (swapping the first trailer sector).
594594
*/
595-
first_trailer_sector_primary =
596-
boot_get_first_trailer_sector(state, BOOT_PRIMARY_SLOT, trailer_sz);
595+
first_trailer_sector_primary = boot_get_first_trailer_sector(state, BOOT_PRIMARY_SLOT);
597596

598597
/* Check if the currently swapped sector(s) contain the trailer or part of it */
599598
if ((img_off + sz) >
@@ -673,7 +672,7 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
673672
* sector(s) containing the beginning of the trailer won't be erased again.
674673
*/
675674
size_t trailer_sector_secondary =
676-
boot_get_first_trailer_sector(state, BOOT_SECONDARY_SLOT, trailer_sz);
675+
boot_get_first_trailer_sector(state, BOOT_SECONDARY_SLOT);
677676

678677
uint32_t trailer_sector_offset =
679678
boot_img_sector_off(state, BOOT_SECONDARY_SLOT, trailer_sector_secondary);

0 commit comments

Comments
 (0)