Commit 8af203ec authored by Andre Przywara's avatar Andre Przywara
Browse files

fel: Check for U-Boot image before considering checksum



Currently we check the U-Boot (legacy!) image header checksum very early
and bail out with an error message if it does not match.

Move that check later into the function, *after* we have established
that we are actually dealing with such an U-Boot image.

This avoids confusing error messages in case there is no U-Boot image
used at all.
Signed-off-by: default avatarAndre Przywara <osp@andrep.de>
parent 8347b645
...@@ -870,15 +870,6 @@ void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len) ...@@ -870,15 +870,6 @@ void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len)
image_header_t hdr = *(image_header_t *)buf; image_header_t hdr = *(image_header_t *)buf;
uint32_t hcrc = be32toh(hdr.ih_hcrc);
/* The CRC is calculated on the whole header but the CRC itself */
hdr.ih_hcrc = 0;
uint32_t computed_hcrc = crc32(0, (const uint8_t *) &hdr, HEADER_SIZE);
if (hcrc != computed_hcrc)
pr_fatal("U-Boot header CRC mismatch: expected %x, got %x\n",
hcrc, computed_hcrc);
/* Check for a valid mkimage header */ /* Check for a valid mkimage header */
int image_type = get_image_type(buf, len); int image_type = get_image_type(buf, len);
if (image_type <= IH_TYPE_INVALID) { if (image_type <= IH_TYPE_INVALID) {
...@@ -899,6 +890,14 @@ void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len) ...@@ -899,6 +890,14 @@ void aw_fel_write_uboot_image(feldev_handle *dev, uint8_t *buf, size_t len)
pr_fatal("U-Boot image type mismatch: " pr_fatal("U-Boot image type mismatch: "
"expected IH_TYPE_FIRMWARE, got %02X\n", image_type); "expected IH_TYPE_FIRMWARE, got %02X\n", image_type);
/* The CRC is calculated on the whole header but the CRC itself */
uint32_t hcrc = be32toh(hdr.ih_hcrc);
hdr.ih_hcrc = 0;
uint32_t computed_hcrc = crc32(0, (const uint8_t *) &hdr, HEADER_SIZE);
if (hcrc != computed_hcrc)
pr_fatal("U-Boot header CRC mismatch: expected %x, got %x\n",
hcrc, computed_hcrc);
uint32_t data_size = be32toh(hdr.ih_size); /* Image Data Size */ uint32_t data_size = be32toh(hdr.ih_size); /* Image Data Size */
uint32_t load_addr = be32toh(hdr.ih_load); /* Data Load Address */ uint32_t load_addr = be32toh(hdr.ih_load); /* Data Load Address */
if (data_size > len - HEADER_SIZE) if (data_size > len - HEADER_SIZE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment