Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/linux-sunxi/sunxi-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Przywara <osp@andrep.de>2020-12-21 19:11:23 +0300
committerAndre Przywara <osp@andrep.de>2020-12-29 03:06:41 +0300
commit8af203ec454c5d8490018afdc82aa15359fb7a9e (patch)
treeb4b2d848383130bc91573187644d74975b0da871
parent8347b645387f25594c7349a5c6075ed5c95a7b80 (diff)
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: Andre Przywara <osp@andrep.de>
-rw-r--r--fel.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/fel.c b/fel.c
index 9cb8923..1555184 100644
--- a/fel.c
+++ b/fel.c
@@ -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;
- 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 */
int image_type = get_image_type(buf, len);
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)
pr_fatal("U-Boot image type mismatch: "
"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 load_addr = be32toh(hdr.ih_load); /* Data Load Address */
if (data_size > len - HEADER_SIZE)