On 11/11/21 16:59, Marek Behún wrote:
From: Pali Rohár <[email protected]>

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 <[email protected]>
Signed-off-by: Marek Behún <[email protected]>
---
  arch/arm/mach-mvebu/spl.c | 28 ++++++++++++++++++++++++++++
  1 file changed, 28 insertions(+)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 662f430503..f0b84167b9 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -100,6 +100,34 @@ u32 spl_mmc_boot_mode(const u32 boot_device)
  }
  #endif
+static uint32_t checksum32(void *start, uint32_t len)
+{
+       uint32_t csum = 0;
+       uint32_t *p = start;

Just curious: Doesn't checkpatch complain about using uint32_t instead
of u32?

Other than this:

Reviewed-by: Stefan Roese <[email protected]>

Thanks,
Stefan

+
+       while (len > 0) {
+               csum += *p++;
+               len -= sizeof(uint32_t);
+       };
+
+       return csum;
+}
+
+int spl_check_board_image(struct spl_image_info *spl_image,
+                         const struct spl_boot_device *bootdev)
+{
+       uint32_t csum = *(uint32_t *)(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)


Viele Grüße,
Stefan Roese

--
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]

Reply via email to