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 */
484487int
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 */
553562int
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