@@ -324,7 +324,7 @@ boot_write_magic(const struct flash_area *fap)
324324 memset (& magic [0 ], erased_val , sizeof (magic ));
325325 memcpy (& magic [BOOT_MAGIC_ALIGN_SIZE - BOOT_MAGIC_SZ ], BOOT_IMG_MAGIC , BOOT_MAGIC_SZ );
326326
327- BOOT_LOG_DBG ("writing magic; fa_id=%d off=0x%lx (0x%lx)" ,
327+ BOOT_LOG_DBG ("boot_write_magic: fa_id=%d off=0x%lx (0x%lx)" ,
328328 flash_area_get_id (fap ), (unsigned long )off ,
329329 (unsigned long )(flash_area_get_off (fap ) + off ));
330330 rc = flash_area_write (fap , pad_off , & magic [0 ], BOOT_MAGIC_ALIGN_SIZE );
@@ -350,9 +350,14 @@ boot_write_trailer(const struct flash_area *fap, uint32_t off,
350350 uint32_t align ;
351351 int rc ;
352352
353+ BOOT_LOG_DBG ("boot_write_trailer: for %p at %d, size = %d" ,
354+ fap , off , inlen );
355+
353356 align = flash_area_align (fap );
354357 align = ALIGN_UP (inlen , align );
355358 if (align > BOOT_MAX_ALIGN ) {
359+ /* This should never happen */
360+ assert (0 );
356361 return -1 ;
357362 }
358363 erased_val = flash_area_erased_val (fap );
@@ -593,6 +598,9 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
593598 struct boot_swap_state slot_state ;
594599 int rc ;
595600
601+ BOOT_LOG_DBG ("boot_set_next: fa %p active == %d, confirm == %d" ,
602+ fa , (int )active , (int )confirm );
603+
596604 if (active ) {
597605 /* The only way to set active slot for next boot is to confirm it,
598606 * as DirectXIP will conclude that, since slot has not been confirmed
@@ -603,6 +611,7 @@ boot_set_next(const struct flash_area *fa, bool active, bool confirm)
603611
604612 rc = boot_read_swap_state (fa , & slot_state );
605613 if (rc != 0 ) {
614+ BOOT_LOG_DBG ("boot_set_next: error %d reading state" , rc );
606615 return rc ;
607616 }
608617
@@ -730,6 +739,8 @@ boot_set_confirmed_multi(int image_index)
730739
731740 rc = flash_area_open (FLASH_AREA_IMAGE_PRIMARY (image_index ), & fap );
732741 if (rc != 0 ) {
742+ BOOT_LOG_DBG ("boot_set_confirmed_multi: error %d opening image %d" ,
743+ rc , image_index );
733744 return BOOT_EFLASH ;
734745 }
735746
@@ -757,13 +768,14 @@ int
757768boot_image_load_header (const struct flash_area * fa_p ,
758769 struct image_header * hdr )
759770{
760- uint32_t size ;
771+ uint32_t size = 0 ;
761772 int rc = flash_area_read (fa_p , 0 , hdr , sizeof * hdr );
762773
774+ BOOT_LOG_DBG ("boot_image_load_header: from %p, result %d" , fa_p , rc );
775+
763776 if (rc != 0 ) {
764- rc = BOOT_EFLASH ;
765777 BOOT_LOG_ERR ("Failed reading image header" );
766- return BOOT_EFLASH ;
778+ return BOOT_EFLASH ;
767779 }
768780
769781 if (hdr -> ih_magic != IMAGE_MAGIC ) {
@@ -780,6 +792,8 @@ boot_image_load_header(const struct flash_area *fa_p,
780792
781793 if (!boot_u32_safe_add (& size , hdr -> ih_img_size , hdr -> ih_hdr_size ) ||
782794 size >= flash_area_get_size (fa_p )) {
795+ BOOT_LOG_ERR ("Image size bigger than designated area: %lu > %lu" ,
796+ (unsigned long )size , (unsigned long )flash_area_get_size (fa_p ));
783797 return BOOT_EBADIMAGE ;
784798 }
785799
0 commit comments