[PATCH 3/6] arm64: kdump: set up kernel image segment
AKASHI Takahiro
takahiro.akashi at linaro.org
Tue Jul 26 01:05:22 PDT 2016
On arm64, we can use the same kernel image as 1st kernel, but
we have to modify the entry point as well as segments' addresses
in the kernel's elf header in order to load them into correct places.
Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
---
kexec/arch/arm64/crashdump-arm64.c | 23 +++++++++++++++++++++++
kexec/arch/arm64/crashdump-arm64.h | 1 +
kexec/arch/arm64/kexec-elf-arm64.c | 7 +++++++
3 files changed, 31 insertions(+)
diff --git a/kexec/arch/arm64/crashdump-arm64.c b/kexec/arch/arm64/crashdump-arm64.c
index 3af01a3..e8e0489 100644
--- a/kexec/arch/arm64/crashdump-arm64.c
+++ b/kexec/arch/arm64/crashdump-arm64.c
@@ -182,3 +182,26 @@ int load_crashdump_segments(struct kexec_info *info)
return 0;
}
+
+/*
+ * e_entry and p_paddr are actually in virtual address space.
+ * Those values will be translated to physcal addresses by
+ * using virt_to_phys().
+ * So let's get ready for later use so the memory base (phys_offset)
+ * will be correctly replaced with crash_reserved_mem.start.
+ */
+void modify_ehdr_for_crashdump(struct mem_ehdr *ehdr)
+{
+ struct mem_phdr *phdr;
+ int i;
+
+ ehdr->e_entry += - arm64_mem.phys_offset + crash_reserved_mem.start;
+
+ for (i = 0; i < ehdr->e_phnum; i++) {
+ phdr = &ehdr->e_phdr[i];
+ if (phdr->p_type != PT_LOAD)
+ continue;
+ phdr->p_paddr +=
+ (-arm64_mem.phys_offset + crash_reserved_mem.start);
+ }
+}
diff --git a/kexec/arch/arm64/crashdump-arm64.h b/kexec/arch/arm64/crashdump-arm64.h
index da75a2d..382f571 100644
--- a/kexec/arch/arm64/crashdump-arm64.h
+++ b/kexec/arch/arm64/crashdump-arm64.h
@@ -21,5 +21,6 @@ extern struct memory_range crash_reserved_mem;
extern struct memory_range elfcorehdr_mem;
extern int load_crashdump_segments(struct kexec_info *info);
+extern void modify_ehdr_for_crashdump(struct mem_ehdr *ehdr);
#endif /* CRASHDUMP_ARM64_H */
diff --git a/kexec/arch/arm64/kexec-elf-arm64.c b/kexec/arch/arm64/kexec-elf-arm64.c
index 029d3e2..1e5deb4 100644
--- a/kexec/arch/arm64/kexec-elf-arm64.c
+++ b/kexec/arch/arm64/kexec-elf-arm64.c
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <linux/elf.h>
+#include "crashdump-arm64.h"
#include "kexec-arm64.h"
#include "kexec-elf.h"
#include "kexec-syscall.h"
@@ -109,6 +110,12 @@ int elf_arm64_load(int argc, char **argv, const char *kernel_buf,
"kexec: creating eflcorehdr failed.\n");
goto exit;
}
+
+ /*
+ * offset addresses in order to fit vmlinux
+ * (elf_exec) into crash kernel's memory
+ */
+ modify_ehdr_for_crashdump(&ehdr);
}
result = elf_exec_load(&ehdr, info);
--
2.9.0
More information about the kexec
mailing list