On 11/11/21 16:59, Marek Behún wrote:
From: Pali Rohár <p...@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 <p...@kernel.org>
Signed-off-by: Marek Behún <marek.be...@nic.cz>

Again, some minor comments below...

Other than this:

Reviewed-by: Stefan Roese <s...@denx.de>

---
  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");

Again it might be helpful for users to print the incorrect blockid in
these cases.

Thanks,
Stefan

                return -EINVAL;
        }
+#endif
spl_image->offset = mhdr->srcaddr;

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: s...@denx.de

Reply via email to