1 From 03cd81fbca6b91317ec1a7b3b3c09fb8d08f83a6 Mon Sep 17 00:00:00 2001
2 From: Wu Zhangjin <wuzhangjin@gmail.com>
3 Date: Tue, 11 Jan 2011 18:42:08 +0000
4 Subject: MIPS: Kexec: Enhance the support
7 o Print more information in machine_kexec() for debugging
8 E.g. with this information, the kexec_start_address has been found
9 it was wrong with 64bit kernel / o32 kexec-tools. Which must be
11 o Link relocate_kernel.S to a section for future extension
12 This allows more functions can be added for the kexec relocation
13 part even written in C. to add code into that section, you just need
14 to mark your function or data with __kexec or
15 __attribute__((__section__(".__kexec.relocate")))
19 1. Make 64bit kernel / o32|n32|64 kexec-tools works
21 Fix the user-space kexec-tools, seems the tool only work for 32bit
22 machine. So, we need to add 64bit support for it. The address of the
23 entry point(kexec_start_address) is wrong and make the "kexec -e" fail.
24 the real entry point must be read from the new kernel image by the
25 user-space kexec-tools, otherwise, it will not work. The above 64bit
26 support tested is 64bit kernel with o32 user-space kexec-tools. The root
27 cause may be the different definition of virt_to_phys() and
28 phys_to_virt() in the kexec-tools and kernel space for 64bit system /
31 Ref: http://www.linux-mips.org/archives/linux-mips/2009-08/msg00149.html
33 2. Pass the arguments from kexec-tools to the new kernel image
35 Please refer to: "MIPS: Loongson: Kexec: Pass parameters to new kernel"
37 Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
39 --- a/arch/mips/include/asm/kexec.h
40 +++ b/arch/mips/include/asm/kexec.h
41 @@ -36,6 +36,16 @@ static inline void crash_setup_regs(stru
46 +#define __kexec __attribute__((__section__(".__kexec.relocate")))
48 +/* The linker tells us where the relocate_new_kernel part is. */
49 +extern const unsigned char __start___kexec_relocate;
50 +extern const unsigned char __end___kexec_relocate;
52 +extern unsigned long kexec_start_address;
53 +extern unsigned long kexec_indirection_page;
56 extern unsigned long kexec_args[4];
57 extern int (*_machine_kexec_prepare)(struct kimage *);
58 --- a/arch/mips/kernel/machine_kexec.c
59 +++ b/arch/mips/kernel/machine_kexec.c
61 #include <asm/cacheflush.h>
64 -extern const unsigned char relocate_new_kernel[];
65 -extern const size_t relocate_new_kernel_size;
67 -extern unsigned long kexec_start_address;
68 -extern unsigned long kexec_indirection_page;
70 int (*_machine_kexec_prepare)(struct kimage *) = NULL;
71 void (*_machine_kexec_shutdown)(void) = NULL;
72 void (*_machine_crash_shutdown)(struct pt_regs *regs) = NULL;
73 @@ -61,21 +55,34 @@ typedef void (*noretfun_t)(void) __attri
75 machine_kexec(struct kimage *image)
77 + unsigned long kexec_relocate_size;
78 unsigned long reboot_code_buffer;
82 + kexec_relocate_size = (unsigned long)(&__end___kexec_relocate) -
83 + (unsigned long)(&__start___kexec_relocate);
84 + pr_info("kexec_relocate_size = %lu\n", kexec_relocate_size);
87 (unsigned long)page_address(image->control_code_page);
88 + pr_info("reboot_code_buffer = %p\n", (void *)reboot_code_buffer);
91 (unsigned long) phys_to_virt(image->start);
92 + pr_info("kexec_start_address(entry point of new kernel) = %p\n",
93 + (void *)kexec_start_address);
95 kexec_indirection_page =
96 (unsigned long) phys_to_virt(image->head & PAGE_MASK);
97 + pr_info("kexec_indirection_page = %p\n",
98 + (void *)kexec_indirection_page);
100 - memcpy((void*)reboot_code_buffer, relocate_new_kernel,
101 - relocate_new_kernel_size);
102 + memcpy((void *)reboot_code_buffer, &__start___kexec_relocate,
103 + kexec_relocate_size);
105 + pr_info("Copy kexec_relocate section from %p to reboot_code_buffer: %p\n",
106 + &__start___kexec_relocate, (void *)reboot_code_buffer);
109 * The generic kexec code builds a page list with physical
110 @@ -96,8 +103,8 @@ machine_kexec(struct kimage *image)
114 - printk("Will call new kernel at %08lx\n", image->start);
115 - printk("Bye ...\n");
116 + pr_info("Will call new kernel at %p\n", (void *)kexec_start_address);
117 + pr_info("Bye ...\n");
120 /* All secondary cpus now may jump to kexec_wait cycle */
121 @@ -108,4 +115,3 @@ machine_kexec(struct kimage *image)
123 ((noretfun_t) reboot_code_buffer)();
126 --- a/arch/mips/kernel/relocate_kernel.S
127 +++ b/arch/mips/kernel/relocate_kernel.S
129 #include <asm/stackframe.h>
130 #include <asm/addrspace.h>
132 + .section .kexec.relocate, "ax"
134 LEAF(relocate_new_kernel)
137 @@ -155,9 +157,3 @@ EXPORT(kexec_start_address)
138 EXPORT(kexec_indirection_page)
140 .size kexec_indirection_page, PTRSIZE
142 -relocate_new_kernel_end:
144 -EXPORT(relocate_new_kernel_size)
145 - PTR relocate_new_kernel_end - relocate_new_kernel
146 - .size relocate_new_kernel_size, PTRSIZE
147 --- a/arch/mips/kernel/vmlinux.lds.S
148 +++ b/arch/mips/kernel/vmlinux.lds.S
149 @@ -50,6 +50,10 @@ SECTIONS
153 + __start___kexec_relocate = .;
154 + KEEP(*(.kexec.relocate))
155 + KEEP(*(.__kexec.relocate))
156 + __end___kexec_relocate = .;
158 _etext = .; /* End of text section */