generic: fix build failure in MIPS kexec code if SMP is enabled
[openwrt.git] / target / linux / generic / patches-3.6 / 331-mips-kexec-enhanche-the-support.patch
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
5
6 Changes:
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
10     fixed later.
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")))
16
17 TODO:
18
19 1. Make 64bit kernel / o32|n32|64 kexec-tools works
20
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 /
29 o32 kernel.
30
31 Ref: http://www.linux-mips.org/archives/linux-mips/2009-08/msg00149.html
32
33 2. Pass the arguments from kexec-tools to the new kernel image
34
35 Please refer to: "MIPS: Loongson: Kexec: Pass parameters to new kernel"
36
37 Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
38 ---
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
42  }
43  
44  #ifdef CONFIG_KEXEC
45 +
46 +#define __kexec __attribute__((__section__(".__kexec.relocate")))
47 +
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;
51 +
52 +extern unsigned long kexec_start_address;
53 +extern unsigned long kexec_indirection_page;
54 +
55  struct kimage;
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
60 @@ -14,10 +14,6 @@
61  #include <asm/page.h>
62  
63  extern const unsigned char relocate_new_kernel[];
64 -extern const size_t relocate_new_kernel_size;
65 -
66 -extern unsigned long kexec_start_address;
67 -extern unsigned long kexec_indirection_page;
68  
69  int (*_machine_kexec_prepare)(struct kimage *) = NULL;
70  void (*_machine_kexec_shutdown)(void) = NULL;
71 @@ -61,21 +57,34 @@ typedef void (*noretfun_t)(void) __attri
72  void
73  machine_kexec(struct kimage *image)
74  {
75 +       unsigned long kexec_relocate_size;
76         unsigned long reboot_code_buffer;
77         unsigned long entry;
78         unsigned long *ptr;
79  
80 +       kexec_relocate_size = (unsigned long)(&__end___kexec_relocate) -
81 +               (unsigned long)(&__start___kexec_relocate);
82 +       pr_info("kexec_relocate_size = %lu\n", kexec_relocate_size);
83 +
84         reboot_code_buffer =
85           (unsigned long)page_address(image->control_code_page);
86 +       pr_info("reboot_code_buffer = %p\n", (void *)reboot_code_buffer);
87  
88         kexec_start_address =
89           (unsigned long) phys_to_virt(image->start);
90 +       pr_info("kexec_start_address(entry point of new kernel) = %p\n",
91 +                       (void *)kexec_start_address);
92  
93         kexec_indirection_page =
94                 (unsigned long) phys_to_virt(image->head & PAGE_MASK);
95 +       pr_info("kexec_indirection_page = %p\n",
96 +                       (void *)kexec_indirection_page);
97  
98 -       memcpy((void*)reboot_code_buffer, relocate_new_kernel,
99 -              relocate_new_kernel_size);
100 +       memcpy((void *)reboot_code_buffer, &__start___kexec_relocate,
101 +              kexec_relocate_size);
102 +
103 +       pr_info("Copy kexec_relocate section from %p to reboot_code_buffer: %p\n",
104 +                       &__start___kexec_relocate, (void *)reboot_code_buffer);
105  
106         /*
107          * The generic kexec code builds a page list with physical
108 @@ -96,8 +105,8 @@ machine_kexec(struct kimage *image)
109          */
110         local_irq_disable();
111  
112 -       printk("Will call new kernel at %08lx\n", image->start);
113 -       printk("Bye ...\n");
114 +       pr_info("Will call new kernel at %p\n", (void *)kexec_start_address);
115 +       pr_info("Bye ...\n");
116         __flush_cache_all();
117  #ifdef CONFIG_SMP
118         /* All secondary cpus now may jump to kexec_wait cycle */
119 @@ -108,4 +117,3 @@ machine_kexec(struct kimage *image)
120  #endif
121         ((noretfun_t) reboot_code_buffer)();
122  }
123 -
124 --- a/arch/mips/kernel/relocate_kernel.S
125 +++ b/arch/mips/kernel/relocate_kernel.S
126 @@ -14,6 +14,8 @@
127  #include <asm/stackframe.h>
128  #include <asm/addrspace.h>
129  
130 +       .section        .kexec.relocate, "ax"
131 +
132  LEAF(relocate_new_kernel)
133         PTR_L a0,       arg0
134         PTR_L a1,       arg1
135 @@ -155,9 +157,3 @@ EXPORT(kexec_start_address)
136  EXPORT(kexec_indirection_page)
137         PTR             0
138         .size           kexec_indirection_page, PTRSIZE
139 -
140 -relocate_new_kernel_end:
141 -
142 -EXPORT(relocate_new_kernel_size)
143 -       PTR             relocate_new_kernel_end - relocate_new_kernel
144 -       .size           relocate_new_kernel_size, PTRSIZE
145 --- a/arch/mips/kernel/vmlinux.lds.S
146 +++ b/arch/mips/kernel/vmlinux.lds.S
147 @@ -51,6 +51,10 @@ SECTIONS
148                 *(.text.*)
149                 *(.fixup)
150                 *(.gnu.warning)
151 +               __start___kexec_relocate = .;
152 +               KEEP(*(.kexec.relocate))
153 +               KEEP(*(.__kexec.relocate))
154 +               __end___kexec_relocate = .;
155         } :text = 0
156         _etext = .;     /* End of text section */
157