Skip to content

Commit fbeef9b

Browse files
Sherryzhang2utzig
authored andcommitted
bootutil_public.c: add two user APIs
Add boot_set_pending_multi() and boot_set_confirmed_multi() APIs so that the user can set the image with given index as pending, confirmed. Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com> Change-Id: Ifca04d396b38c6c64581703794071f6b42e9dfbf
1 parent a80e7c6 commit fbeef9b

File tree

2 files changed

+95
-28
lines changed

2 files changed

+95
-28
lines changed

boot/bootutil/include/bootutil/bootutil_public.h

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2017-2019 Linaro LTD
55
* Copyright (c) 2016-2019 JUUL Labs
6-
* Copyright (c) 2019-2020 Arm Limited
6+
* Copyright (c) 2019-2021 Arm Limited
77
* Copyright (c) 2020 Nordic Semiconductor ASA
88
*
99
* Original license:
@@ -147,25 +147,54 @@ int boot_swap_type_multi(int image_index);
147147
int boot_swap_type(void);
148148

149149
/**
150-
* Marks the image in the secondary slot as pending. On the next reboot,
151-
* the system will perform a one-time boot of the the secondary slot image.
150+
* Marks the image with the given index in the secondary slot as pending. On the
151+
* next reboot, the system will perform a one-time boot of the the secondary
152+
* slot image.
152153
*
153-
* @param permanent Whether the image should be used permanently or
154-
* only tested once:
155-
* 0=run image once, then confirm or revert.
156-
* 1=run image forever.
154+
* @param image_index Image pair index.
157155
*
158-
* @return 0 on success; nonzero on failure.
156+
* @param permanent Whether the image should be used permanently or
157+
* only tested once:
158+
* 0=run image once, then confirm or revert.
159+
* 1=run image forever.
160+
*
161+
* @return 0 on success; nonzero on failure.
162+
*/
163+
int boot_set_pending_multi(int image_index, int permanent);
164+
165+
/**
166+
* Marks the image with index 0 in the secondary slot as pending. On the next
167+
* reboot, the system will perform a one-time boot of the the secondary slot
168+
* image. Note that this API is kept for compatibility. The
169+
* boot_set_pending_multi() API is recommended.
170+
*
171+
* @param permanent Whether the image should be used permanently or
172+
* only tested once:
173+
* 0=run image once, then confirm or revert.
174+
* 1=run image forever.
175+
*
176+
* @return 0 on success; nonzero on failure.
159177
*/
160178
int boot_set_pending(int permanent);
161179

162180
/**
163-
* @brief Marks the image in the primary slot as confirmed.
181+
* Marks the image with the given index in the primary slot as confirmed. The
182+
* system will continue booting into the image in the primary slot until told to
183+
* boot from a different slot.
164184
*
165-
* The system will continue booting into the image in the primary slot until
166-
* told to boot from a different slot.
185+
* @param image_index Image pair index.
167186
*
168-
* @return 0 on success; nonzero on failure.
187+
* @return 0 on success; nonzero on failure.
188+
*/
189+
int boot_set_confirmed_multi(int image_index);
190+
191+
/**
192+
* Marks the image with index 0 in the primary slot as confirmed. The system
193+
* will continue booting into the image in the primary slot until told to boot
194+
* from a different slot. Note that this API is kept for compatibility. The
195+
* boot_set_confirmed_multi() API is recommended.
196+
*
197+
* @return 0 on success; nonzero on failure.
169198
*/
170199
int boot_set_confirmed(void);
171200

boot/bootutil/src/bootutil_public.c

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2017-2019 Linaro LTD
55
* Copyright (c) 2016-2019 JUUL Labs
6-
* Copyright (c) 2019-2020 Arm Limited
6+
* Copyright (c) 2019-2021 Arm Limited
77
* Copyright (c) 2020 Nordic Semiconductor ASA
88
*
99
* Original license:
@@ -471,25 +471,28 @@ boot_swap_type(void)
471471
}
472472

473473
/**
474-
* Marks the image in the secondary slot as pending. On the next reboot,
475-
* the system will perform a one-time boot of the the secondary slot image.
474+
* Marks the image with the given index in the secondary slot as pending. On the
475+
* next reboot, the system will perform a one-time boot of the the secondary
476+
* slot image.
477+
*
478+
* @param image_index Image pair index.
476479
*
477480
* @param permanent Whether the image should be used permanently or
478-
* only tested once:
479-
* 0=run image once, then confirm or revert.
480-
* 1=run image forever.
481+
* only tested once:
482+
* 0=run image once, then confirm or revert.
483+
* 1=run image forever.
481484
*
482485
* @return 0 on success; nonzero on failure.
483486
*/
484487
int
485-
boot_set_pending(int permanent)
488+
boot_set_pending_multi(int image_index, int permanent)
486489
{
487490
const struct flash_area *fap;
488491
struct boot_swap_state state_secondary_slot;
489492
uint8_t swap_type;
490493
int rc;
491494

492-
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY(0),
495+
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SECONDARY(image_index),
493496
&state_secondary_slot);
494497
if (rc != 0) {
495498
return rc;
@@ -501,7 +504,7 @@ boot_set_pending(int permanent)
501504
return 0;
502505

503506
case BOOT_MAGIC_UNSET:
504-
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(0), &fap);
507+
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap);
505508
if (rc != 0) {
506509
rc = BOOT_EFLASH;
507510
} else {
@@ -528,7 +531,7 @@ boot_set_pending(int permanent)
528531
/* The image slot is corrupt. There is no way to recover, so erase the
529532
* slot to allow future upgrades.
530533
*/
531-
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(0), &fap);
534+
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap);
532535
if (rc != 0) {
533536
return BOOT_EFLASH;
534537
}
@@ -544,20 +547,41 @@ boot_set_pending(int permanent)
544547
}
545548

546549
/**
547-
* Marks the image in the primary slot as confirmed. The system will continue
548-
* booting into the image in the primary slot until told to boot from a
549-
* different slot.
550+
* Marks the image with index 0 in the secondary slot as pending. On the next
551+
* reboot, the system will perform a one-time boot of the the secondary slot
552+
* image. Note that this API is kept for compatibility. The
553+
* boot_set_pending_multi() API is recommended.
554+
*
555+
* @param permanent Whether the image should be used permanently or
556+
* only tested once:
557+
* 0=run image once, then confirm or revert.
558+
* 1=run image forever.
550559
*
551560
* @return 0 on success; nonzero on failure.
552561
*/
553562
int
554-
boot_set_confirmed(void)
563+
boot_set_pending(int permanent)
564+
{
565+
return boot_set_pending_multi(0, permanent);
566+
}
567+
568+
/**
569+
* Marks the image with the given index in the primary slot as confirmed. The
570+
* system will continue booting into the image in the primary slot until told to
571+
* boot from a different slot.
572+
*
573+
* @param image_index Image pair index.
574+
*
575+
* @return 0 on success; nonzero on failure.
576+
*/
577+
int
578+
boot_set_confirmed_multi(int image_index)
555579
{
556580
const struct flash_area *fap;
557581
struct boot_swap_state state_primary_slot;
558582
int rc;
559583

560-
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_PRIMARY(0),
584+
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_PRIMARY(image_index),
561585
&state_primary_slot);
562586
if (rc != 0) {
563587
return rc;
@@ -577,7 +601,7 @@ boot_set_confirmed(void)
577601
return BOOT_EBADVECT;
578602
}
579603

580-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(0), &fap);
604+
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index), &fap);
581605
if (rc) {
582606
rc = BOOT_EFLASH;
583607
goto done;
@@ -599,3 +623,17 @@ boot_set_confirmed(void)
599623
flash_area_close(fap);
600624
return rc;
601625
}
626+
627+
/**
628+
* Marks the image with index 0 in the primary slot as confirmed. The system
629+
* will continue booting into the image in the primary slot until told to boot
630+
* from a different slot. Note that this API is kept for compatibility. The
631+
* boot_set_confirmed_multi() API is recommended.
632+
*
633+
* @return 0 on success; nonzero on failure.
634+
*/
635+
int
636+
boot_set_confirmed(void)
637+
{
638+
return boot_set_confirmed_multi(0);
639+
}

0 commit comments

Comments
 (0)