diff mbox series

[U-Boot,V2,1/2] spl: Fix redundant image of uboot

Message ID 20180706060844.GA17021@panicking
State Superseded
Delegated to: Tom Rini
Headers show
Series [U-Boot,V2,1/2] spl: Fix redundant image of uboot | expand

Commit Message

Michael Nazzareno Trimarchi July 6, 2018, 6:08 a.m. UTC
We need to address the redundat image case and undestand if the
image is corrupted or not. In error case we need to try the fallback copy.
The function used before was always return 0 without any evaluation of the
error. We try to make it work properly

Signed-off-by: Michael Trimarchi <michael@amarulasolutions.com>
---
Changes V1->V2:
	Address the comments on using the err variable
---
 common/spl/spl_nand.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index 9a52500..109dd6e 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -44,9 +44,7 @@  static int spl_nand_load_element(struct spl_image_info *spl_image,
 {
 	int err;
 
-	err = nand_spl_load_image(offset, sizeof(*header), (void *)header);
-	if (err)
-		return err;
+	nand_spl_load_image(offset, sizeof(*header), (void *)header);
 
 	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT) &&
 	    image_get_magic(header) == FDT_MAGIC) {
@@ -59,13 +57,31 @@  static int spl_nand_load_element(struct spl_image_info *spl_image,
 		load.bl_len = 1;
 		load.read = spl_nand_fit_read;
 		return spl_load_simple_fit(spl_image, &load, offset, header);
-	} else {
-		err = spl_parse_image_header(spl_image, header);
-		if (err)
-			return err;
-		return nand_spl_load_image(offset, spl_image->size,
-					   (void *)(ulong)spl_image->load_addr);
 	}
+	err = spl_parse_image_header(spl_image, header);
+	if (err)
+		return err;
+
+	nand_spl_load_image(offset, spl_image->size,
+			   (void *)(ulong)spl_image->load_addr);
+
+	/*
+	 * Verify the crc of the header
+	 */
+	if (!((const image_header_t *)spl_image->load_addr)) {
+		debug("Header checksum failed\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * Verify the crc of the data
+	 */
+	if (!image_check_dcrc((const image_header_t *)spl_image->load_addr)) {
+		debug("Image checksum failed\n");
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static int spl_nand_load_image(struct spl_image_info *spl_image,