[PATCH v3 12/21] filetype: detect RISC-V images

Ahmad Fatoum a.fatoum at pengutronix.de
Sun Mar 21 15:13:35 GMT 2021


We still have no boot support for RISC-V, take the first step by
enabling barebox to detect both a RISC-V Linux kernel and barebox image.
The header format is aligned with that of arm64, but they differ
in the signature magic.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/filetype.c  | 6 ++++++
 include/filetype.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/common/filetype.c b/common/filetype.c
index 539c96b74527..0cae00abaaa5 100644
--- a/common/filetype.c
+++ b/common/filetype.c
@@ -61,6 +61,8 @@ static const struct filetype_str filetype_str[] = {
 	[filetype_kwbimage_v1] = { "MVEBU kwbimage (v1)", "kwb1" },
 	[filetype_android_sparse] = { "Android sparse image", "sparse" },
 	[filetype_arm64_linux_image] = { "ARM aarch64 Linux image", "aarch64-linux" },
+	[filetype_riscv_linux_image] = { "RISC-V Linux image", "riscv-linux" },
+	[filetype_riscv_barebox_image] = { "RISC-V barebox image", "riscv-barebox" },
 	[filetype_elf] = { "ELF", "elf" },
 	[filetype_imx_image_v1] = { "i.MX image (v1)", "imx-image-v1" },
 	[filetype_imx_image_v2] = { "i.MX image (v2)", "imx-image-v2" },
@@ -303,6 +305,10 @@ enum filetype file_detect_type(const void *_buf, size_t bufsize)
 		return filetype_bpk;
 	if (le32_to_cpu(buf[14]) == 0x644d5241)
 		return filetype_arm64_linux_image;
+	if (le32_to_cpu(buf[14]) == 0x05435352)
+		return filetype_riscv_linux_image;
+	if (le32_to_cpu(buf[14]) == 0x56435352 && !memcmp(&buf[12], "barebox", 8))
+		return filetype_riscv_barebox_image;
 	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 &&
diff --git a/include/filetype.h b/include/filetype.h
index 3019dda6ed78..fd339f9564ef 100644
--- a/include/filetype.h
+++ b/include/filetype.h
@@ -43,6 +43,8 @@ enum filetype {
 	filetype_kwbimage_v1,
 	filetype_android_sparse,
 	filetype_arm64_linux_image,
+	filetype_riscv_linux_image,
+	filetype_riscv_barebox_image,
 	filetype_elf,
 	filetype_imx_image_v1,
 	filetype_imx_image_v2,
-- 
2.29.2




More information about the barebox mailing list