kexec-tools: Don't create hardcoded PT_LOAD header on old kernels (x86_64)
This patch improves the kexec binary to avoid creating a PT_LOAD program header
for the kernel if enough information cannot be gathered through /proc/kcore.
This to avoid avoid hardcoded values and the limitation of only supporting 2MB
physical start address (kernel config option CONFIG_PHYSICAL_START).
The patch also solves the kexec-tools-testing regression introduced by commit
103c946e39eb9dd57ccbda20ac12ccb01f883c17 - with this patch it is now possible
to copy /proc/vmcore on 2.6.18.
Signed-off-by: Magnus Damm <[EMAIL PROTECTED]>
---
kexec/arch/x86_64/crashdump-x86_64.c | 47 +++++++++++-----------------------
1 file changed, 16 insertions(+), 31 deletions(-)
--- 0001/kexec/arch/x86_64/crashdump-x86_64.c
+++ work/kexec/arch/x86_64/crashdump-x86_64.c 2006-11-15 19:07:11.000000000
+0900
@@ -84,24 +84,6 @@ static int get_kernel_paddr(struct kexec
return -1;
}
-/* Hardcoding kernel virtual address and size. While writting
- * this patch vanilla kernel is compiled for addr 2MB. Anybody
- * using kernel older than that which was compiled for 1MB
- * physical addr, use older version of kexec-tools. This function
- * is there just for backward compatibility reasons and we should
- * get rid of it at some point of time.
- */
-
-static int hardcode_kernel_vaddr_size(struct kexec_info *info)
-{
- fprintf(stderr, "Warning: Hardcoding kernel virtual addr and size\n");
- info->kern_vaddr_start = __START_KERNEL_map + 0x200000;
- info->kern_size = KERNEL_TEXT_SIZE - 0x200000;
- fprintf(stderr, "Warning: virtual addr = 0x%lx size = 0x%lx\n",
- info->kern_vaddr_start, info->kern_size);
- return 0;
-}
-
/* Retrieve info regarding virtual address kernel has been compiled for and
* size of the kernel from /proc/kcore. Current /proc/kcore parsing from
* from kexec-tools fails because of malformed elf notes. A kernel patch has
@@ -120,6 +102,8 @@ static int get_kernel_vaddr_and_size(str
unsigned long size;
uint32_t elf_flags = 0;
+ info->kern_size = 0; /* only create PT_LOAD header for new kernels */
+
align = getpagesize();
size = KCORE_ELF_HEADERS_SIZE;
buf = slurp_file_len(kcore, size);
@@ -137,7 +121,6 @@ static int get_kernel_vaddr_and_size(str
result = build_elf_core_info(buf, size, &ehdr, elf_flags);
if (result < 0) {
fprintf(stderr, "ELF core (kcore) parse failed\n");
- hardcode_kernel_vaddr_size(info);
return 0;
}
@@ -664,18 +647,19 @@ static int prepare_crash_memory_elf64_he
#endif
}
- /* Setup an PT_LOAD type program header for the region where
- * Kernel is mapped.
- */
- phdr = (Elf64_Phdr *) bufp;
- bufp += sizeof(Elf64_Phdr);
- phdr->p_type = PT_LOAD;
- phdr->p_flags = PF_R|PF_W|PF_X;
- phdr->p_offset = phdr->p_paddr = info->kern_paddr_start;
- phdr->p_vaddr = info->kern_vaddr_start;
- phdr->p_filesz = phdr->p_memsz = info->kern_size;
- phdr->p_align = 0;
- (elf->e_phnum)++;
+ if (info->kern_size) {
+ /* Setup an PT_LOAD type program header for the region where
+ * Kernel is mapped.
+ */
+ phdr = (Elf64_Phdr *) bufp;
+ bufp += sizeof(Elf64_Phdr);
+ phdr->p_type = PT_LOAD;
+ phdr->p_flags = PF_R|PF_W|PF_X;
+ phdr->p_offset = phdr->p_paddr = info->kern_paddr_start;
+ phdr->p_vaddr = info->kern_vaddr_start;
+ phdr->p_filesz = phdr->p_memsz = info->kern_size;
+ phdr->p_align = 0;
+ (elf->e_phnum)++;
#ifdef DEBUG
printf("Kernel text Elf header: p_type = %d, p_offset = 0x%lx "
"p_paddr = 0x%lx p_vaddr = 0x%lx "
@@ -683,6 +667,7 @@ static int prepare_crash_memory_elf64_he
phdr->p_type, phdr->p_offset, phdr->p_paddr,
phdr->p_vaddr, phdr->p_filesz, phdr->p_memsz);
#endif
+ }
/* Setup PT_LOAD type program header for every system RAM chunk.
* A seprate program header for Backup Region*/
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot