@@ -112,6 +112,7 @@ void elf_riscv_usage(void)
{
}
+
int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
struct kexec_info *info)
{
@@ -127,9 +128,7 @@ int elf_riscv_load(int argc, char **argv, const char *buf, off_t len,
int ret = 0;
if (info->file_mode) {
- fprintf(stderr, "kexec_file not supported on this "
- "architecture\n");
- return -EINVAL;
+ return prepare_kexec_file_options(info);
}
/* Parse the ELF file */
@@ -17,6 +17,12 @@
#include "kexec-riscv.h"
#include "iomem.h"
#include <stdbool.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#ifndef _O_BINARY
+#define _O_BINARY 0
+#endif
const struct arch_map_entry arches[] = {
{ "riscv32", KEXEC_ARCH_RISCV },
@@ -141,6 +147,39 @@ void arch_usage(void)
printf(riscv_opts_usage);
}
+int prepare_kexec_file_options(struct kexec_info *info)
+{
+ int fd;
+ ssize_t result;
+ struct stat stats;
+
+ if (arch_options.cmdline) {
+ info->command_line = (char *)arch_options.cmdline;
+ info->command_line_len = strlen(info->command_line) + 1;
+ }
+
+ if (!arch_options.initrd_path) {
+ info->initrd_fd = -1;
+ return 0;
+ }
+
+ fd = open(arch_options.initrd_path, O_RDONLY | _O_BINARY);
+ if (fd < 0) {
+ fprintf(stderr, "Cannot open `%s': %s\n", arch_options.initrd_path,
+ strerror(errno));
+ return -EINVAL;
+ }
+ result = fstat(fd, &stats);
+ if (result < 0) {
+ close(fd);
+ fprintf(stderr, "Cannot stat: %s: %s\n", arch_options.initrd_path,
+ strerror(errno));
+ return -EINVAL;
+ }
+ info->initrd_fd = fd;
+ return 0;
+}
+
int arch_process_options(int argc, char **argv)
{
static const struct option options[] = {
@@ -23,6 +23,7 @@ extern struct memory_range elfcorehdr_mem;
int load_elfcorehdr(struct kexec_info *info);
/* kexec-riscv.c */
+int prepare_kexec_file_options(struct kexec_info *info);
int load_extra_segments(struct kexec_info *info, uint64_t kernel_base,
uint64_t kernel_size, uint64_t max_addr);
@@ -80,6 +80,9 @@
#ifdef __hppa__
#define __NR_kexec_file_load 355
#endif
+#if defined(__riscv__) || defined(__riscv)
+#define __NR_kexec_file_load 294
+#endif
#ifndef __NR_kexec_file_load
/* system call not available for the arch */