From 15fc6ffd0274f72282761ed0e6ae4b097be23f97 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 22 Mar 2021 14:39:10 +0100 Subject: filetype: detect RISC-V images 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 Signed-off-by: Sascha Hauer --- common/filetype.c | 6 ++++++ include/filetype.h | 2 ++ 2 files changed, 8 insertions(+) diff --git a/common/filetype.c b/common/filetype.c index 539c96b745..0cae00abaa 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 3019dda6ed..fd339f9564 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, -- cgit v1.2.3