From: "Pali Rohár" <pali@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de, "Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-marvell v4 5/9] arm: mvebu: Check for kwbimage data checksum
Date: Fri, 14 Jan 2022 14:31:41 +0100 [thread overview]
Message-ID: <20220114133145.32329-6-pali@kernel.org> (raw)
In-Reply-To: <20220114133145.32329-1-pali@kernel.org>
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 | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index 62e4fe12d65c..72cc2f92f698 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -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)
--
2.20.1
next prev parent reply other threads:[~2022-01-14 13:35 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-14 13:31 [PATCH u-boot-marvell v4 0/9] More verifications for kwbimage in SPL Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 1/9] arm: mvebu: Check that kwbimage offset and blocksize are valid Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 2/9] SPL: Add struct spl_boot_device parameter into spl_parse_board_header() Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 3/9] arm: mvebu: Check that kwbimage blockid matches boot mode Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 4/9] SPL: Add support for checking board / BootROM specific image types Pali Rohár
2022-01-14 13:31 ` Pali Rohár [this message]
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 6/9] arm: mvebu: spl: Print srcaddr in error message Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 7/9] arm: mvebu: spl: Use preferred types u8/u16/u32 instead of uintN_t Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 8/9] arm: mvebu: spl: Use IS_ENABLED() instead of #ifdef where possible Pali Rohár
2022-01-14 13:31 ` [PATCH u-boot-marvell v4 9/9] arm: mvebu: spl: Fix 100 column exceeds Pali Rohár
2022-01-20 16:21 ` [PATCH u-boot-marvell v4 0/9] More verifications for kwbimage in SPL Stefan Roese
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220114133145.32329-6-pali@kernel.org \
--to=pali@kernel.org \
--cc=marek.behun@nic.cz \
--cc=sr@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.