mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Grzeschik <grzeschik@puzzle.ch>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Michael Grzeschik <grzeschik@puzzle.ch>
Subject: [PATCH 4/6] filetype: detect kwbimage v0 images for NAND boot
Date: Tue, 03 Nov 2026 22:31:10 +0100	[thread overview]
Message-ID: <20261103-orion_kw_mvebu-v1-4-86442c0d283e@puzzle.ch> (raw)
In-Reply-To: <20261103-orion_kw_mvebu-v1-0-86442c0d283e@puzzle.ch>

The kwbimage detection requires header bytes 0x1-0x3 to be zero before
it looks at the header version. That is right for v1 headers, where
they are reserved, but in v0 headers byte 0x1 is the NAND ECC mode and
bytes 0x2-0x3 are the NAND page size. Every v0 image for NAND boot, as
used on Kirkwood, was therefore reported as unknown, and the mvebu
barebox_update handler refused it:

  ERROR: /barebox-ram.img is not a valid kwbimage
  update failed

Check these bytes for v1 headers only. v0 detection still requires a
valid header checksum.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Michael Grzeschik <grzeschik@puzzle.ch>
---
 common/filetype.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/common/filetype.c b/common/filetype.c
index a25be6e2fc..c5bed9eca9 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -406,9 +406,13 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 
 	if ((buf8[0] == 0x5a || buf8[0] == 0x69 || buf8[0] == 0x78 ||
 	     buf8[0] == 0x8b || buf8[0] == 0x9c) &&
-	    buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
 	    buf8[0x18] == 0 && buf8[0x1b] == 0 && buf8[0x1c] == 0) {
 
+		/*
+		 * In v0 headers byte 0x1 is the NAND ECC mode and bytes
+		 * 0x2-0x3 the NAND page size, both non-zero for NAND images.
+		 * Only v1 headers have them reserved.
+		 */
 		if (buf8[0x8] == 0) {
 			unsigned char sum = 0;
 			int i;
@@ -420,7 +424,8 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 			    fuzz_insecure_checksum_accepted(sum, buf8[0x1f]))
 				return filetype_kwbimage_v0;
 		} else if (buf8[0x8] == 1) {
-			if (buf8[0x1d] == 0 &&
+			if (buf8[0x1] == 0 && buf8[0x2] == 0 && buf8[0x3] == 0 &&
+			    buf8[0x1d] == 0 &&
 			    (buf8[0x1e] == 0 || buf8[0x1e] == 1))
 				return filetype_kwbimage_v1;
 		}

-- 
2.53.0




  parent reply	other threads:[~2026-11-03 21:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 21:31 [PATCH 0/6] orion/kw/mvebu: stability/usability patches Michael Grzeschik
2026-11-03 21:31 ` [PATCH 1/6] images: mvebu: skip images whose binary header is missing Michael Grzeschik
2026-11-03 21:31 ` [PATCH 2/6] mtd: nand: orion: set Hamming ECC algorithm in ->attach_chip() Michael Grzeschik
2026-11-03 21:31 ` [PATCH 3/6] gpio: orion: do not let banks without alias collide Michael Grzeschik
2026-11-03 21:31 ` Michael Grzeschik [this message]
2026-11-03 21:31 ` [PATCH 5/6] mtd: nand: orion: register the NAND device as "nand" Michael Grzeschik
2026-11-03 21:31 ` [PATCH 6/6] gpio: orion: register at coredevice level Michael Grzeschik

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=20261103-orion_kw_mvebu-v1-4-86442c0d283e@puzzle.ch \
    --to=grzeschik@puzzle.ch \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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