]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: mvebu: Check for kwbimage data checksum
authorPali Rohár <pali@kernel.org>
Fri, 14 Jan 2022 13:31:41 +0000 (14:31 +0100)
committerStefan Roese <sr@denx.de>
Thu, 20 Jan 2022 10:35:29 +0000 (11:35 +0100)
Last 4 bytes of kwbimage boot image is checksum. Verify it via the new
spl_check_board_image() function which is called by U-Boot SPL after
loading kwbimage.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
arch/arm/mach-mvebu/spl.c

index 62e4fe12d65c2cc77d833843d149f401a2ae03b0..72cc2f92f6986a80bd79dfe2374e8eba1fb7efaa 100644 (file)
@@ -99,6 +99,33 @@ u32 spl_mmc_boot_mode(const u32 boot_device)
 }
 #endif
 
+static u32 checksum32(void *start, u32 len)
+{
+       u32 csum = 0;
+       u32 *p = start;
+
+       while (len > 0) {
+               csum += *p++;
+               len -= sizeof(u32);
+       };
+
+       return csum;
+}
+
+int spl_check_board_image(struct spl_image_info *spl_image,
+                         const struct spl_boot_device *bootdev)
+{
+       u32 csum = *(u32 *)(spl_image->load_addr + spl_image->size - 4);
+
+       if (checksum32((void *)spl_image->load_addr,
+                      spl_image->size - 4) != csum) {
+               printf("ERROR: Invalid data checksum in kwbimage\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 int spl_parse_board_header(struct spl_image_info *spl_image,
                           const struct spl_boot_device *bootdev,
                           const void *image_header, size_t size)