Skip to contentSkip to conversation

RISC-V: add kexec_load support for vmlinuz

PATCH Applied Tao Liu 2 participants 4 messages May 26 – May 27

Subsystems (3)
lore
Share & tools
lore

Tao Liu

author
#0 lore raw

PATCH 1/1 RISC-V: add kexec_load support for vmlinuz

Copy arm64 code and change for riscv so that the kexec -c can load a vmlinuz image.

---
 kexec/arch/riscv/Makefile              |   1 +
 kexec/arch/riscv/image-header.h        |  12 +++
 kexec/arch/riscv/kexec-riscv.c         |   1 +
 kexec/arch/riscv/kexec-riscv.h         |   6 ++
 kexec/arch/riscv/kexec-vmlinuz-riscv.c | 112 +++++++++++++++++++++++++
 5 files changed, 132 insertions(+)
 create mode 100644 kexec/arch/riscv/kexec-vmlinuz-riscv.c
kexec/arch/riscv/Makefile +1 -0
index 18a997b..6ba8976 100644
@@ -4,6 +4,7 @@
 riscv_KEXEC_SRCS = kexec/arch/riscv/crashdump-riscv.c
 riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-elf-riscv.c
 riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-image-riscv.c
+riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-vmlinuz-riscv.c
 riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-riscv.c
 
 riscv_DT_OPS += kexec/dt-ops.c
kexec/arch/riscv/image-header.h +12 -0
index a677546..7e950ee 100644
@@ -85,4 +85,16 @@ static inline uint64_t riscv_header_image_size(const struct riscv_image_header *
 	return le64toh(h->image_size);
 }
 
+static const uint8_t riscv_image_pe_sig[2] = {'M', 'Z'};
+static const uint8_t riscv_pe_machtype[6] = {'P','E', 0x0, 0x0, 0x64, 0x50};
+
+static inline int riscv_header_check_pe_sig(const struct riscv_image_header *h)
+{
+	if (!h)
+		return 0;
+
+	return (*((char *)&(h->code0)) == riscv_image_pe_sig[0] &&
+		*((char *)&(h->code0) + 1) == riscv_image_pe_sig[1]);
+}
+
 #endif
kexec/arch/riscv/kexec-riscv.c +1 -0
index a5a12a0..a7188ac 100644
@@ -34,6 +34,7 @@ const struct arch_map_entry arches[] = {
 struct file_type file_type[] = {
 	{"elf-riscv", elf_riscv_probe, elf_riscv_load, elf_riscv_usage},
 	{"image-riscv", image_riscv_probe, image_riscv_load, image_riscv_usage},
+	{"vmlinuz-riscv", pez_riscv_probe, pez_riscv_load, pez_riscv_usage},
 };
 int file_types = sizeof(file_type) / sizeof(file_type[0]);
 
kexec/arch/riscv/kexec-riscv.h +6 -0
index cfb0377..f487b27 100644
@@ -51,3 +51,9 @@ int image_riscv_probe(const char *buf, off_t len);
 void image_riscv_usage(void);
 int image_riscv_load(int argc, char **argv, const char *buf, off_t len,
 		   struct kexec_info *info);
+
+/* kexec-vmlinuz-riscv.c */
+int pez_riscv_probe(const char *buf, off_t len);
+void pez_riscv_usage(void);
+int pez_riscv_load(int argc, char **argv, const char *buf, off_t len,
+		   struct kexec_info *info);
kexec/arch/riscv/kexec-vmlinuz-riscv.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.47.0
author
#3 lore raw

Hi Simon,

Quoted 6 lines · Simon Horman
Quoted 4 lines · Simon Horman
Quoted 3 lines · Tao Liu

Copy arm64 code and change for riscv so that the kexec -c can load a vmlinuz image.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Thanks, applied.

... here:

- RISC-V: add kexec_load support for vmlinuz
https://git.kernel.org/pub/scm/utils/kernel/kexec/kexec-tools.git/commit/?id=771e89dc104e

Thanks a lot for that! :)

Thanks,
Tao Liu

Quoted 1 line