@@ -398,9 +398,59 @@ 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+ for (i = 0 ; i < BOOT_IMAGE_NUMBER ; i ++ ) {
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+
422+ /* Image not found */
423+ * slot = UINT32_MAX ;
424+ #else
425+ (void )fa ;
426+ if (slot != NULL ) {
427+ if (FLASH_AREA_IMAGE_PRIMARY (0 ) == id ) {
428+ * slot = 0 ;
429+ } else if (FLASH_AREA_IMAGE_SECONDARY (0 ) == id ) {
430+ * slot = 1 ;
431+ } else {
432+ * slot = UINT32_MAX ;
433+ }
434+ }
435+ #endif
436+ return 0 ;
437+ }
438+ #endif /* SEND_BOOT_REQUEST || !MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP */
439+
401440int
402441boot_read_image_ok (const struct flash_area * fap , uint8_t * image_ok )
403442{
443+ #ifdef SEND_BOOT_REQUEST
444+ enum boot_slot slot_id = BOOT_SLOT_NONE ;
445+ int image_id = flash_area_to_image_slot (fap , & slot_id );
446+ bool confirm_pending = boot_request_check_confirmed_slot (image_id , slot_id );
447+
448+ if (confirm_pending ) {
449+ BOOT_LOG_DBG ("Image confirmation pending for image %d slot %d" , image_id , slot_id );
450+ * image_ok = BOOT_FLAG_SET ;
451+ return 0 ;
452+ }
453+ #endif /* SEND_BOOT_REQUEST */
404454 return boot_read_flag (fap , image_ok , boot_image_ok_off (fap ));
405455}
406456
@@ -541,47 +591,6 @@ send_boot_request(uint8_t magic, uint8_t image_ok, bool confirm, int image_id,
541591}
542592#endif /* SEND_BOOT_REQUEST */
543593
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-
585594#ifndef MCUBOOT_BOOTUTIL_LIB_FOR_DIRECT_XIP
586595int
587596boot_set_next (const struct flash_area * fa , bool active , bool confirm )
0 commit comments