public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Marek Behún" <kabel@kernel.org>
To: Stefan Roese <sr@denx.de>
Cc: u-boot@lists.denx.de, "Pali Rohár" <pali@kernel.org>,
	"Marek Behún" <marek.behun@nic.cz>
Subject: [PATCH u-boot-marvell 3/5] arm: mvebu: Check that kwbimage blockid matches boot mode
Date: Thu, 11 Nov 2021 16:59:51 +0100	[thread overview]
Message-ID: <20211111155953.31526-4-kabel@kernel.org> (raw)
In-Reply-To: <20211111155953.31526-1-kabel@kernel.org>

From: Pali Rohár <pali@kernel.org>

Each boot mode has its own kwbimage specified by blockid. So check that
kwbimage is valid by blockid.

Signed-off-by: Pali Rohár <pali@kernel.org>
Signed-off-by: Marek Behún <marek.behun@nic.cz>
---
 arch/arm/mach-mvebu/spl.c | 32 +++++++++++++++++++++++---------
 1 file changed, 23 insertions(+), 9 deletions(-)

diff --git a/arch/arm/mach-mvebu/spl.c b/arch/arm/mach-mvebu/spl.c
index deef6e76f3..662f430503 100644
--- a/arch/arm/mach-mvebu/spl.c
+++ b/arch/arm/mach-mvebu/spl.c
@@ -118,22 +118,36 @@ int spl_parse_board_header(struct spl_image_info *spl_image,
 	 * (including SPL content) which is not included in U-Boot image_header.
 	 */
 	if (mhdr->version != 1 ||
-	    ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr) ||
-	    (
+	    ((mhdr->headersz_msb << 16) | mhdr->headersz_lsb) < sizeof(*mhdr)) {
+		printf("ERROR: Invalid kwbimage v1\n");
+		return -EINVAL;
+	}
+
 #ifdef CONFIG_SPL_SPI_FLASH_SUPPORT
-	     mhdr->blockid != IBR_HDR_SPI_ID &&
+	if (bootdev->boot_device == BOOT_DEVICE_SPI &&
+	    mhdr->blockid != IBR_HDR_SPI_ID) {
+		printf("ERROR: Wrong blockid in SPI kwbimage\n");
+		return -EINVAL;
+	}
 #endif
+
 #ifdef CONFIG_SPL_SATA
-	     mhdr->blockid != IBR_HDR_SATA_ID &&
+	if (bootdev->boot_device == BOOT_DEVICE_SATA &&
+	    mhdr->blockid != IBR_HDR_SATA_ID) {
+		printf("ERROR: Wrong blockid in SATA kwbimage\n");
+		return -EINVAL;
+	}
 #endif
+
 #ifdef CONFIG_SPL_MMC
-	     mhdr->blockid != IBR_HDR_SDIO_ID &&
-#endif
-	     1
-	    )) {
-		printf("ERROR: Not valid SPI/NAND/SATA/SDIO kwbimage v1\n");
+	if ((bootdev->boot_device == BOOT_DEVICE_MMC1 ||
+	     bootdev->boot_device == BOOT_DEVICE_MMC2 ||
+	     bootdev->boot_device == BOOT_DEVICE_MMC2_2) &&
+	    mhdr->blockid != IBR_HDR_SDIO_ID) {
+		printf("ERROR: Wrong blockid in SDIO kwbimage\n");
 		return -EINVAL;
 	}
+#endif
 
 	spl_image->offset = mhdr->srcaddr;
 
-- 
2.32.0


  parent reply	other threads:[~2021-11-11 16:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 15:59 [PATCH u-boot-marvell 0/5] More verifications for kwbimage in SPL Marek Behún
2021-11-11 15:59 ` [PATCH u-boot-marvell 1/5] arm: mvebu: Check that kwbimage offset and blocksize are valid Marek Behún
2021-11-15  8:52   ` Stefan Roese
2021-11-11 15:59 ` [PATCH u-boot-marvell 2/5] SPL: Add struct spl_boot_device parameter into spl_parse_board_header() Marek Behún
2021-11-15  8:58   ` Stefan Roese
2021-11-11 15:59 ` Marek Behún [this message]
2021-11-15  8:59   ` [PATCH u-boot-marvell 3/5] arm: mvebu: Check that kwbimage blockid matches boot mode Stefan Roese
2021-11-11 15:59 ` [PATCH u-boot-marvell 4/5] SPL: Add support for checking board / BootROM specific image types Marek Behún
2021-11-15  9:09   ` Stefan Roese
2021-11-11 15:59 ` [PATCH u-boot-marvell 5/5] arm: mvebu: Check for kwbimage data checksum Marek Behún
2021-11-15  9:10   ` 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=20211111155953.31526-4-kabel@kernel.org \
    --to=kabel@kernel.org \
    --cc=marek.behun@nic.cz \
    --cc=pali@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox