@@ -563,6 +563,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
563
563
if (req -> off == SIZE_MAX ) {
564
564
/* Request did not include an `off` field. */
565
565
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_hdr_malformed );
566
+ LOG_DBG ("Request did not include an `off` field" );
566
567
return IMG_MGMT_ERR_INVALID_OFFSET ;
567
568
}
568
569
@@ -588,12 +589,15 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
588
589
if (req -> img_data .len < sizeof (struct image_header )) {
589
590
/* Image header is the first thing in the image */
590
591
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_hdr_malformed );
592
+ LOG_DBG ("Image data too short: %u < %u" , req -> img_data .len ,
593
+ sizeof (struct image_header ));
591
594
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER ;
592
595
}
593
596
594
597
if (req -> size == SIZE_MAX ) {
595
598
/* Request did not include a `len` field. */
596
599
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_hdr_malformed );
600
+ LOG_DBG ("Request did not include a `len` field" );
597
601
return IMG_MGMT_ERR_INVALID_LENGTH ;
598
602
}
599
603
@@ -602,10 +606,12 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
602
606
hdr = (struct image_header * )req -> img_data .value ;
603
607
if (hdr -> ih_magic != IMAGE_MAGIC ) {
604
608
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_magic_mismatch );
609
+ LOG_DBG ("Magic mismatch: %08X != %08X" , hdr -> ih_magic , IMAGE_MAGIC );
605
610
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC ;
606
611
}
607
612
608
613
if (req -> data_sha .len > IMG_MGMT_DATA_SHA_LEN ) {
614
+ LOG_DBG ("Invalid hash length: %u" , req -> data_sha .len );
609
615
return IMG_MGMT_ERR_INVALID_HASH ;
610
616
}
611
617
@@ -625,8 +631,9 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
625
631
626
632
action -> area_id = img_mgmt_get_unused_slot_area_id (req -> image );
627
633
if (action -> area_id < 0 ) {
628
- /* No slot where to upload! */
634
+ /* No slot available to upload to */
629
635
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_no_slot );
636
+ LOG_DBG ("No slot available to upload to" );
630
637
return IMG_MGMT_ERR_NO_FREE_SLOT ;
631
638
}
632
639
@@ -643,7 +650,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
643
650
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action ,
644
651
img_mgmt_err_str_image_too_large );
645
652
flash_area_close (fa );
646
- LOG_ERR ("Upload too large for slot: %u > %u" , req -> size , fa -> fa_size );
653
+ LOG_DBG ("Upload too large for slot: %u > %u" , req -> size ,
654
+ fa -> fa_size );
647
655
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE ;
648
656
}
649
657
@@ -695,7 +703,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
695
703
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action ,
696
704
img_mgmt_err_str_image_too_large );
697
705
flash_area_close (fa );
698
- LOG_ERR ("Upload too large for slot (with end offset): %u > %u" , req -> size ,
706
+ LOG_DBG ("Upload too large for slot (with end offset): %u > %u" , req -> size ,
699
707
(fa -> fa_size - CONFIG_MCUBOOT_UPDATE_FOOTER_SIZE ));
700
708
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE ;
701
709
}
@@ -710,7 +718,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
710
718
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action ,
711
719
img_mgmt_err_str_image_too_large );
712
720
flash_area_close (fa );
713
- LOG_ERR ("Upload too large for slot (with max image size): %u > %u" ,
721
+ LOG_DBG ("Upload too large for slot (with max image size): %u > %u" ,
714
722
req -> size , max_image_size );
715
723
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE ;
716
724
}
@@ -722,6 +730,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
722
730
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action ,
723
731
img_mgmt_err_str_image_bad_flash_addr );
724
732
flash_area_close (fa );
733
+ LOG_DBG ("Invalid flash address: %08X, expected: %08X" ,
734
+ hdr -> ih_load_addr , (int )fa -> fa_off );
725
735
return IMG_MGMT_ERR_INVALID_FLASH_ADDRESS ;
726
736
}
727
737
}
@@ -735,19 +745,26 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
735
745
*/
736
746
rc = img_mgmt_my_version (& cur_ver );
737
747
if (rc != 0 ) {
748
+ LOG_DBG ("Version get failed: %d" , rc );
738
749
return IMG_MGMT_ERR_VERSION_GET_FAILED ;
739
750
}
740
751
741
752
if (img_mgmt_vercmp (& cur_ver , & hdr -> ih_ver ) >= 0 ) {
742
753
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action ,
743
754
img_mgmt_err_str_downgrade );
755
+ LOG_DBG ("Downgrade: %d.%d.%d.%d, expected: %d.%d.%d.%d" ,
756
+ cur_ver .iv_major , cur_ver .iv_minor , cur_ver .iv_revision ,
757
+ cur_ver .iv_build_num , hdr -> ih_ver .iv_major ,
758
+ hdr -> ih_ver .iv_minor , hdr -> ih_ver .iv_revision ,
759
+ hdr -> ih_ver .iv_build_num );
744
760
return IMG_MGMT_ERR_CURRENT_VERSION_IS_NEWER ;
745
761
}
746
762
}
747
763
748
764
#ifndef CONFIG_IMG_ERASE_PROGRESSIVELY
749
765
rc = img_mgmt_flash_check_empty (action -> area_id );
750
766
if (rc < 0 ) {
767
+ LOG_DBG ("Flash check empty failed: %d" , rc );
751
768
return rc ;
752
769
}
753
770
@@ -763,6 +780,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
763
780
* Invalid offset. Drop the data, and respond with the offset we're
764
781
* expecting data for.
765
782
*/
783
+ LOG_DBG ("Invalid offset: %08x, expected: %08x" , req -> off ,
784
+ g_img_mgmt_state .off );
766
785
return IMG_MGMT_ERR_OK ;
767
786
}
768
787
@@ -771,6 +790,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
771
790
* of the image that the client originally sent
772
791
*/
773
792
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN (action , img_mgmt_err_str_data_overrun );
793
+ LOG_DBG ("Data overrun: %u + %u > %llu" , req -> off , req -> img_data .len ,
794
+ action -> size );
774
795
return IMG_MGMT_ERR_INVALID_IMAGE_DATA_OVERRUN ;
775
796
}
776
797
}
@@ -789,6 +810,7 @@ int img_mgmt_erased_val(int slot, uint8_t *erased_val)
789
810
int area_id = img_mgmt_flash_area_id (slot );
790
811
791
812
if (area_id < 0 ) {
813
+ LOG_DBG ("Invalid slot: %d" , area_id );
792
814
return IMG_MGMT_ERR_INVALID_SLOT ;
793
815
}
794
816
0 commit comments