@@ -398,9 +398,61 @@ boot_write_image_ok(const struct flash_area *fap)
398398 return boot_write_trailer_flag (fap , off , BOOT_FLAG_SET );
399399}
400400
401+ #if defined(SEND_BOOT_REQUEST ) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP ))
402+ static int flash_area_to_image_slot (const struct flash_area * fa , uint32_t * slot )
403+ {
404+ int id = flash_area_get_id (fa );
405+ #if BOOT_IMAGE_NUMBER > 1
406+ uint8_t i = 0 ;
407+
408+ while (i < BOOT_IMAGE_NUMBER ) {
409+ if (FLASH_AREA_IMAGE_PRIMARY (i ) == id ) {
410+ if (slot != NULL ) {
411+ * slot = 0 ;
412+ }
413+ return i ;
414+ } else if (FLASH_AREA_IMAGE_SECONDARY (i ) == id ) {
415+ if (slot != NULL ) {
416+ * slot = 1 ;
417+ }
418+ return i ;
419+ }
420+
421+ ++ i ;
422+ }
423+
424+ /* Image not found */
425+ * slot = UINT32_MAX ;
426+ #else
427+ (void )fa ;
428+ if (slot != NULL ) {
429+ if (FLASH_AREA_IMAGE_PRIMARY (0 ) == id ) {
430+ * slot = 0 ;
431+ } else if (FLASH_AREA_IMAGE_SECONDARY (0 ) == id ) {
432+ * slot = 1 ;
433+ } else {
434+ * slot = UINT32_MAX ;
435+ }
436+ }
437+ #endif
438+ return 0 ;
439+ }
440+ #endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */
441+
401442int
402443boot_read_image_ok (const struct flash_area * fap , uint8_t * image_ok )
403444{
445+ #ifdef SEND_BOOT_REQUEST
446+ enum boot_slot slot_id = BOOT_SLOT_NONE ;
447+ int image_id = flash_area_to_image_slot (fap , & slot_id );
448+ bool confirm_pending = boot_request_check_confirmed_slot (image_id , slot_id );
449+
450+ if (confirm_pending ) {
451+ BOOT_LOG_DBG ("Image confirmation pending for image %d slot %d" , image_id , slot_id );
452+ * image_ok = BOOT_FLAG_SET ;
453+ return 0 ;
454+ }
455+ #endif /* SEND_BOOT_REQUEST */
404456 return boot_read_flag (fap , image_ok , boot_image_ok_off (fap ));
405457}
406458
@@ -541,47 +593,6 @@ send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
541593}
542594#endif /* SEND_BOOT_REQUEST */
543595
544- #if defined(SEND_BOOT_REQUEST ) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP ))
545- static int flash_area_to_image_slot (const struct flash_area * fa , uint32_t * slot )
546- {
547- int id = flash_area_get_id (fa );
548- #if BOOT_IMAGE_NUMBER > 1
549- uint8_t i = 0 ;
550-
551- while (i < BOOT_IMAGE_NUMBER ) {
552- if (FLASH_AREA_IMAGE_PRIMARY (i ) == id ) {
553- if (slot != NULL ) {
554- * slot = 0 ;
555- }
556- return i ;
557- } else if (FLASH_AREA_IMAGE_SECONDARY (i ) == id ) {
558- if (slot != NULL ) {
559- * slot = 1 ;
560- }
561- return i ;
562- }
563-
564- ++ i ;
565- }
566-
567- /* Image not found */
568- * slot = UINT32_MAX ;
569- #else
570- (void )fa ;
571- if (slot != NULL ) {
572- if (FLASH_AREA_IMAGE_PRIMARY (0 ) == id ) {
573- * slot = 0 ;
574- } else if (FLASH_AREA_IMAGE_SECONDARY (0 ) == id ) {
575- * slot = 1 ;
576- } else {
577- * slot = UINT32_MAX ;
578- }
579- }
580- #endif
581- return 0 ;
582- }
583- #endif /* defined(SEND_BOOT_REQUEST) || (!defined(MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP)) */
584-
585596#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
586597int
587598boot_set_next (const struct flash_area * fa , bool active , bool confirm )
0 commit comments