Skip to content

Commit 51b9112

Browse files
Nick BrookChromeos LUCI
authored andcommitted
mgmt/mcumgr: Add error logs for all error cases
Errors were logged for some cases in zephyr_img_mgmt.c, but not all. This commit adds error logs for all error cases. (cherry picked from commit d0d3dd4) Original-Signed-off-by: Nick Brook <[email protected]> GitOrigin-RevId: d0d3dd4 Cr-Build-Id: 8722485936012132001 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8722485936012132001 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I136e20520d870f774dd3894f09c985b337dc46c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6281750 Tested-by: ChromeOS Prod (Robot) <[email protected]> Commit-Queue: ChromeOS Prod (Robot) <[email protected]> Bot-Commit: ChromeOS Prod (Robot) <[email protected]>
1 parent a65ffb1 commit 51b9112

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

subsys/mgmt/mcumgr/grp/img_mgmt/src/zephyr_img_mgmt.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
563563
if (req->off == SIZE_MAX) {
564564
/* Request did not include an `off` field. */
565565
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_hdr_malformed);
566+
LOG_DBG("Request did not include an `off` field");
566567
return IMG_MGMT_ERR_INVALID_OFFSET;
567568
}
568569

@@ -588,12 +589,15 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
588589
if (req->img_data.len < sizeof(struct image_header)) {
589590
/* Image header is the first thing in the image */
590591
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));
591594
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER;
592595
}
593596

594597
if (req->size == SIZE_MAX) {
595598
/* Request did not include a `len` field. */
596599
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_hdr_malformed);
600+
LOG_DBG("Request did not include a `len` field");
597601
return IMG_MGMT_ERR_INVALID_LENGTH;
598602
}
599603

@@ -602,10 +606,12 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
602606
hdr = (struct image_header *)req->img_data.value;
603607
if (hdr->ih_magic != IMAGE_MAGIC) {
604608
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);
605610
return IMG_MGMT_ERR_INVALID_IMAGE_HEADER_MAGIC;
606611
}
607612

608613
if (req->data_sha.len > IMG_MGMT_DATA_SHA_LEN) {
614+
LOG_DBG("Invalid hash length: %u", req->data_sha.len);
609615
return IMG_MGMT_ERR_INVALID_HASH;
610616
}
611617

@@ -625,8 +631,9 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
625631

626632
action->area_id = img_mgmt_get_unused_slot_area_id(req->image);
627633
if (action->area_id < 0) {
628-
/* No slot where to upload! */
634+
/* No slot available to upload to */
629635
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action, img_mgmt_err_str_no_slot);
636+
LOG_DBG("No slot available to upload to");
630637
return IMG_MGMT_ERR_NO_FREE_SLOT;
631638
}
632639

@@ -643,7 +650,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
643650
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
644651
img_mgmt_err_str_image_too_large);
645652
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);
647655
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE;
648656
}
649657

@@ -695,7 +703,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
695703
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
696704
img_mgmt_err_str_image_too_large);
697705
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,
699707
(fa->fa_size - CONFIG_MCUBOOT_UPDATE_FOOTER_SIZE));
700708
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE;
701709
}
@@ -710,7 +718,7 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
710718
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
711719
img_mgmt_err_str_image_too_large);
712720
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",
714722
req->size, max_image_size);
715723
return IMG_MGMT_ERR_INVALID_IMAGE_TOO_LARGE;
716724
}
@@ -722,6 +730,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
722730
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
723731
img_mgmt_err_str_image_bad_flash_addr);
724732
flash_area_close(fa);
733+
LOG_DBG("Invalid flash address: %08X, expected: %08X",
734+
hdr->ih_load_addr, (int)fa->fa_off);
725735
return IMG_MGMT_ERR_INVALID_FLASH_ADDRESS;
726736
}
727737
}
@@ -735,19 +745,26 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
735745
*/
736746
rc = img_mgmt_my_version(&cur_ver);
737747
if (rc != 0) {
748+
LOG_DBG("Version get failed: %d", rc);
738749
return IMG_MGMT_ERR_VERSION_GET_FAILED;
739750
}
740751

741752
if (img_mgmt_vercmp(&cur_ver, &hdr->ih_ver) >= 0) {
742753
IMG_MGMT_UPLOAD_ACTION_SET_RC_RSN(action,
743754
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);
744760
return IMG_MGMT_ERR_CURRENT_VERSION_IS_NEWER;
745761
}
746762
}
747763

748764
#ifndef CONFIG_IMG_ERASE_PROGRESSIVELY
749765
rc = img_mgmt_flash_check_empty(action->area_id);
750766
if (rc < 0) {
767+
LOG_DBG("Flash check empty failed: %d", rc);
751768
return rc;
752769
}
753770

@@ -763,6 +780,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
763780
* Invalid offset. Drop the data, and respond with the offset we're
764781
* expecting data for.
765782
*/
783+
LOG_DBG("Invalid offset: %08x, expected: %08x", req->off,
784+
g_img_mgmt_state.off);
766785
return IMG_MGMT_ERR_OK;
767786
}
768787

@@ -771,6 +790,8 @@ int img_mgmt_upload_inspect(const struct img_mgmt_upload_req *req,
771790
* of the image that the client originally sent
772791
*/
773792
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);
774795
return IMG_MGMT_ERR_INVALID_IMAGE_DATA_OVERRUN;
775796
}
776797
}
@@ -789,6 +810,7 @@ int img_mgmt_erased_val(int slot, uint8_t *erased_val)
789810
int area_id = img_mgmt_flash_area_id(slot);
790811

791812
if (area_id < 0) {
813+
LOG_DBG("Invalid slot: %d", area_id);
792814
return IMG_MGMT_ERR_INVALID_SLOT;
793815
}
794816

0 commit comments

Comments
 (0)