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
path: root/fel.c
diff options
context:
space:
mode:
authorMaxime Ripard <maxime.ripard@free-electrons.com>2017-11-06 13:39:53 +0300
committerMaxime Ripard <maxime.ripard@free-electrons.com>2017-11-06 13:43:55 +0300
commitef802e4952b2483ebc922bf243ea610962c14723 (patch)
treee2658a856a78d267058bb60dc508e46a5b7a143e /fel.c
parente753821ea0d4dc0cd57b72fa1d4cba56545b7d3a (diff)
fel: Check for the U-Boot header CRC
A U-Boot image has two CRCs, one to cover the data and that we already check, and one to cover the header. Since we're not checking the latter, let's make sure it's the case. Tested-by: Frank Kunz <mailinglists@kunz-im-inter.net> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
Diffstat (limited to 'fel.c')
-rw-r--r--fel.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/fel.c b/fel.c
index 0fdefad..148e558 100644
--- a/fel.c
+++ b/fel.c
@@ -764,6 +764,15 @@ 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) {