diff mbox

[U-Boot] spl_mmc.c: Detect missing kernel image in RAW MMC

Message ID 1372444981-21305-1-git-send-email-trini@ti.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Tom Rini June 28, 2013, 6:43 p.m. UTC
Currently, we assume that if we can read from MMC correctly, we have
found a valid image.  This is not the case as an empty area will read
just fine.  Add a check for a valid IH_MAGIC.

Signed-off-by: Tom Rini <trini@ti.com>
---
 common/spl/spl_mmc.c |    4 ++++
 1 file changed, 4 insertions(+)

Comments

Peter Korsgaard June 28, 2013, 6:53 p.m. UTC | #1
>>>>> "Tom" == Tom Rini <trini@ti.com> writes:

 Tom> Currently, we assume that if we can read from MMC correctly, we have
 Tom> found a valid image.  This is not the case as an empty area will read
 Tom> just fine.  Add a check for a valid IH_MAGIC.

 Tom> Signed-off-by: Tom Rini <trini@ti.com>

Reviewed-by: Peter Korsgaard <jacmet@sunsite.dk>



 Tom> ---
 Tom>  common/spl/spl_mmc.c |    4 ++++
 Tom>  1 file changed, 4 insertions(+)

 Tom> diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
 Tom> index 170fa38..d20f45d 100644
 Tom> --- a/common/spl/spl_mmc.c
 Tom> +++ b/common/spl/spl_mmc.c
 Tom> @@ -29,6 +29,7 @@
 Tom>  #include <mmc.h>
 Tom>  #include <fat.h>
 Tom>  #include <version.h>
 Tom> +#include <image.h>
 
 Tom>  DECLARE_GLOBAL_DATA_PTR;
 
 Tom> @@ -46,6 +47,9 @@ static int mmc_load_image_raw(struct mmc *mmc, unsigned long sector)
 Tom>  	if (err == 0)
 Tom>  		goto end;
 
 Tom> +	if (image_get_magic(header) != IH_MAGIC)
 Tom> +		return -1;
 Tom> +
 Tom>  	spl_parse_image_header(header);
 
 Tom>  	/* convert size to sectors - round up */
 Tom> -- 
 Tom> 1.7.9.5

 Tom> _______________________________________________
 Tom> U-Boot mailing list
 Tom> U-Boot@lists.denx.de
 Tom> http://lists.denx.de/mailman/listinfo/u-boot
Tom Rini July 30, 2013, 1:26 p.m. UTC | #2
On Fri, Jun 28, 2013 at 02:43:01PM -0400, Tom Rini wrote:

> Currently, we assume that if we can read from MMC correctly, we have
> found a valid image.  This is not the case as an empty area will read
> just fine.  Add a check for a valid IH_MAGIC.
> 
> Signed-off-by: Tom Rini <trini@ti.com>
> Reviewed-by: Peter Korsgaard <jacmet@sunsite.dk>

Applied to u-boot-ti/master, thanks!
diff mbox

Patch

diff --git a/common/spl/spl_mmc.c b/common/spl/spl_mmc.c
index 170fa38..d20f45d 100644
--- a/common/spl/spl_mmc.c
+++ b/common/spl/spl_mmc.c
@@ -29,6 +29,7 @@ 
 #include <mmc.h>
 #include <fat.h>
 #include <version.h>
+#include <image.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -46,6 +47,9 @@  static int mmc_load_image_raw(struct mmc *mmc, unsigned long sector)
 	if (err == 0)
 		goto end;
 
+	if (image_get_magic(header) != IH_MAGIC)
+		return -1;
+
 	spl_parse_image_header(header);
 
 	/* convert size to sectors - round up */