mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] filetype: mvebu: Fix kwbimage v1 detection
@ 2019-11-15 10:38 Sascha Hauer
  2019-11-15 10:58 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2019-11-15 10:38 UTC (permalink / raw)
  To: Barebox List; +Cc: ukl

The kwbimage detection calculates a checksum over the first 31 bytes of
the image. This is correct for the v0 image format, but for the v1 image
format the checksum in the image also covers the extenstion headers.
These might not be completely present in the initial buffer provided to
file_detect_type(), so just drop the checksum calculation for v1 images.

Fixes: bf8b6d46db ("kwbimage_v0: add support to detect and boot a mvebu v0 image")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/filetype.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index 4966c5e068..ad7f301d71 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -316,19 +316,21 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
 	    buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
 	    buf8[0x18] == 0 && buf8[0x1b] == 0 && buf8[0x1c] == 0) {
-		unsigned char sum = 0;
-		int i;
 
-		for (i = 0; i <= 0x1e; ++i)
-			sum += buf8[i];
+		if (buf8[0x8] == 0) {
+			unsigned char sum = 0;
+			int i;
 
-		if (sum == buf8[0x1f] && buf8[0x8] == 0)
-			return filetype_kwbimage_v0;
+			for (i = 0; i <= 0x1e; ++i)
+				sum += buf8[i];
 
-		if (sum == buf8[0x1f] &&
-		    buf8[0x8] == 1 && buf8[0x1d] == 0 &&
-		    (buf8[0x1e] == 0 || buf8[0x1e] == 1))
-			return filetype_kwbimage_v1;
+			if (sum == buf8[0x1f])
+				return filetype_kwbimage_v0;
+		} else if (buf8[0x8] == 1) {
+			if (sum == buf8[0x1f] && buf8[0x1d] == 0 &&
+			    (buf8[0x1e] == 0 || buf8[0x1e] == 1))
+				return filetype_kwbimage_v1;
+		}
 	}
 
 	if (is_sparse_image(_buf))
-- 
2.24.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] filetype: mvebu: Fix kwbimage v1 detection
  2019-11-15 10:38 [PATCH] filetype: mvebu: Fix kwbimage v1 detection Sascha Hauer
@ 2019-11-15 10:58 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-11-15 10:58 UTC (permalink / raw)
  To: Barebox List; +Cc: ukl

On Fri, Nov 15, 2019 at 11:38:00AM +0100, Sascha Hauer wrote:
> The kwbimage detection calculates a checksum over the first 31 bytes of
> the image. This is correct for the v0 image format, but for the v1 image
> format the checksum in the image also covers the extenstion headers.
> These might not be completely present in the initial buffer provided to
> file_detect_type(), so just drop the checksum calculation for v1 images.
> 
> Fixes: bf8b6d46db ("kwbimage_v0: add support to detect and boot a mvebu v0 image")
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  common/filetype.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)
> 
> diff --git a/common/filetype.c b/common/filetype.c
> index 4966c5e068..ad7f301d71 100644
> --- a/common/filetype.c
> +++ b/common/filetype.c
> @@ -316,19 +316,21 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
>  	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
>  	    buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
>  	    buf8[0x18] == 0 && buf8[0x1b] == 0 && buf8[0x1c] == 0) {
> -		unsigned char sum = 0;
> -		int i;
>  
> -		for (i = 0; i <= 0x1e; ++i)
> -			sum += buf8[i];
> +		if (buf8[0x8] == 0) {
> +			unsigned char sum = 0;
> +			int i;
>  
> -		if (sum == buf8[0x1f] && buf8[0x8] == 0)
> -			return filetype_kwbimage_v0;
> +			for (i = 0; i <= 0x1e; ++i)
> +				sum += buf8[i];
>  
> -		if (sum == buf8[0x1f] &&
> -		    buf8[0x8] == 1 && buf8[0x1d] == 0 &&
> -		    (buf8[0x1e] == 0 || buf8[0x1e] == 1))
> -			return filetype_kwbimage_v1;
> +			if (sum == buf8[0x1f])
> +				return filetype_kwbimage_v0;
> +		} else if (buf8[0x8] == 1) {
> +			if (sum == buf8[0x1f] && buf8[0x1d] == 0 &&

sum == buf8[0x1f] must be dropped here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-15 10:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-15 10:38 [PATCH] filetype: mvebu: Fix kwbimage v1 detection Sascha Hauer
2019-11-15 10:58 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox