[PATCH 4/6] filetype: detect kwbimage v0 images for NAND boot
Michael Grzeschik
grzeschik at puzzle.ch
Tue Nov 3 13:31:10 PST 2026
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 at 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
More information about the barebox
mailing list