RISC-V: Add support for kexec on kexec-tools
Subsystems (3)
PATCH 1/1 RISC-V: Add support for kexec on kexec-tools
This patch adds kexec support for RISC-V on kexec-tools. For now this only includes support for the kexec call, no kexec_file or kdump / crashkernel. The only supported image type is an ELF image such as vmlinux. When the new kernel starts a0 will contain the current hart id and a1 the pointer to the dtb (PA).
Note: Until we have CPU suspend support on RISC-V we can't fully recover on an SMP system, the kernel side will call smp_send_stop(), so at this point we pass "nosmp" to the next kernel as a temporary workaround.
I tested this on riscv64 QEMU on both smp and non-smp setups and works as expected.
--- configure.ac | 3 + include/elf.h | 3 +- kexec/Makefile | 1 + kexec/arch/riscv/Makefile | 34 ++ kexec/arch/riscv/include/arch/options.h | 43 ++ kexec/arch/riscv/kexec-elf-riscv.c | 281 ++++++++++++ kexec/arch/riscv/kexec-riscv.c | 545 ++++++++++++++++++++++++ kexec/arch/riscv/kexec-riscv.h | 24 ++ kexec/kexec-syscall.h | 4 + purgatory/Makefile | 1 + purgatory/arch/riscv/Makefile | 7 + 12 files changed, 947 insertions(+), 3 deletions(-) create mode 100644 kexec/arch/riscv/Makefile create mode 100644 kexec/arch/riscv/include/arch/options.h create mode 100644 kexec/arch/riscv/kexec-elf-riscv.c create mode 100644 kexec/arch/riscv/kexec-riscv.c create mode 100644 kexec/arch/riscv/kexec-riscv.h create mode 100644 purgatory/arch/riscv/Makefile
configure.ac +3 -0
@@ -55,6 +55,9 @@ case $target_cpu in ia64|x86_64|alpha|m68k ) ARCH="$target_cpu" ;; + riscv32|riscv64 ) + ARCH="riscv" + ;; * ) AC_MSG_ERROR([unsupported architecture $target_cpu]) ;;
include/elf.h +2 -1
@@ -259,7 +259,8 @@ typedef struct#define EM_ARC_A5 93/* ARC Cores Tangent-A5 */ #define EM_XTENSA 94/* Tensilica Xtensa Architecture */ #define EM_AARCH64 183/* ARM AARCH64 */ -#define EM_NUM 184 +#define EM_RISCV 243/* RISC-V */ +#define EM_NUM 244/* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
kexec/Makefile +1 -0
@@ -89,6 +89,7 @@ include $(srcdir)/kexec/arch/mips/Makefile include $(srcdir)/kexec/arch/cris/Makefile include $(srcdir)/kexec/arch/ppc/Makefile include $(srcdir)/kexec/arch/ppc64/Makefile +include $(srcdir)/kexec/arch/riscv/Makefile include $(srcdir)/kexec/arch/s390/Makefile include $(srcdir)/kexec/arch/sh/Makefile include $(srcdir)/kexec/arch/x86_64/Makefile
kexec/arch/riscv/Makefile new file +34 -0
@@ -0,0 +1,34 @@ +# +# kexec riscv +# +riscv_KEXEC_SRCS = kexec/arch/riscv/kexec-riscv.c +riscv_KEXEC_SRCS += kexec/arch/riscv/kexec-elf-riscv.c + +riscv_MEM_REGIONS = kexec/mem_regions.c + +riscv_DT_OPS += kexec/dt-ops.c + +riscv_ARCH_REUSE_INITRD = + +riscv_CPPFLAGS += -I $(srcdir)/kexec/ + +dist += kexec/arch/riscv/Makefile $(riscv_KEXEC_SRCS) \ + kexec/arch/riscv/kexec-riscv.h \ + kexec/arch/riscv/include/arch/options.h + +ifdef HAVE_LIBFDT + +LIBS += -lfdt + +else + +include $(srcdir)/kexec/libfdt/Makefile.libfdt + +libfdt_SRCS += $(LIBFDT_SRCS:%=kexec/libfdt/%) + +riscv_CPPFLAGS += -I$(srcdir)/kexec/libfdt + +riscv_KEXEC_SRCS += $(libfdt_SRCS) + +endif +
kexec/arch/riscv/include/arch/options.h new file +43 -0
43 lines not on this page · raw message
kexec/arch/riscv/kexec-elf-riscv.c new file +281 -0
281 lines not on this page · raw message
kexec/arch/riscv/kexec-riscv.c new file +545 -0
545 lines not on this page · raw message
kexec/arch/riscv/kexec-riscv.h new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (C) 2019 FORTH-ICS/CARV +* Nick Kossifidis <[email protected]> +*/ + +struct fdt_image { +char *buf; +off_t size; +}; + +struct riscv_opts { +char *cmdline; +char *fdt_path; +char *initrd_path; +uint64_t initrd_start; +uint64_t initrd_end; +struct fdt_image *fdt; +}; + +int elf_riscv_probe (const char *buf,off_t len); +void elf_riscv_usage (void ); +int elf_riscv_load (int argc,char **argv,const char *buf,off_t len, +struct kexec_info *info);
kexec/kexec-syscall.h +4 -0
@@ -126,6 +126,7 @@ static inline long kexec_file_load(int kernel_fd, int initrd_fd,#define KEXEC_ARCH_MIPS_LE (10 << 16)#define KEXEC_ARCH_MIPS ( 8 << 16)#define KEXEC_ARCH_CRIS (76 << 16) +#define KEXEC_ARCH_RISCV (243 << 16)#define KEXEC_MAX_SEGMENTS 16
@@ -169,5 +170,8 @@ static inline long kexec_file_load(int kernel_fd, int initrd_fd,#if defined(__arm64__)#define KEXEC_ARCH_NATIVE KEXEC_ARCH_ARM64#endif +#if defined(__riscv__) || defined(__riscv) +#define KEXEC_ARCH_NATIVE KEXEC_ARCH_RISCV +#endif #endif /* KEXEC_SYSCALL_H */
purgatory/Makefile +1 -0
@@ -25,6 +25,7 @@ include $(srcdir)/purgatory/arch/ia64/Makefile include $(srcdir)/purgatory/arch/mips/Makefile include $(srcdir)/purgatory/arch/ppc/Makefile include $(srcdir)/purgatory/arch/ppc64/Makefile +include $(srcdir)/purgatory/arch/riscv/Makefile include $(srcdir)/purgatory/arch/s390/Makefile include $(srcdir)/purgatory/arch/sh/Makefile include $(srcdir)/purgatory/arch/x86_64/Makefile
purgatory/arch/riscv/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Purgatory riscv +# + +riscv_PURGATORY_SRCS = + +dist += purgatory/arch/sh/Makefile $(riscv_PURGATORY_SRCS)
Signature · 7 lines
2.21.0 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec