]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
dumpimage: fix handling of StarFive SPL too long
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Tue, 4 Mar 2025 16:04:03 +0000 (17:04 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 18 Mar 2025 14:17:32 +0000 (08:17 -0600)
The header of the StarFive U-Boot SPL file u-boot-spl.normal.out has a
field indicating the payload size. When copying U-Boot SPL from a
partition the copied file might be too long.

Currently in this situation a misleading error message 'Incorrect CRC32' is
written.

We must use the payload size and not the file size when calculating the
CRC32.

Write a warning if the file is too long indicating the correct size. This
enables the user to truncate the file accordingly.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
tools/sfspl.c

index c76420ce21b63bf1c66b78eb068fc70effe1c2b5..516e96e8dd9e877cc6204fbc38d13af5a404b93e 100644 (file)
@@ -70,11 +70,14 @@ static int sfspl_verify_header(unsigned char *buf, int size,
                printf("Truncated file\n");
                return EXIT_FAILURE;
        }
+       if ((size_t)size > hdr_size + file_size)
+               printf("File too long, expected %u bytes\n",
+                      hdr_size + file_size);
        if (hdr->version != DEFAULT_VERSION) {
                printf("Unknown file format version\n");
                return EXIT_FAILURE;
        }
-       crc_check = crc32(0, &buf[hdr_size], size - hdr_size);
+       crc_check = crc32(0, &buf[hdr_size], file_size);
        if (crc_check != crc) {
                printf("Incorrect CRC32\n");
                return EXIT_FAILURE;