1 --- a/arch/mips/kernel/machine_kexec.c
2 +++ b/arch/mips/kernel/machine_kexec.c
3 @@ -23,67 +23,104 @@ void (*relocated_kexec_smp_wait) (void *
4 atomic_t kexec_ready_to_reboot = ATOMIC_INIT(0);
7 -static void machine_kexec_init_args(void)
8 +#define KEXEC_MIPS_ARGV_BUF_SIZE COMMAND_LINE_SIZE
9 +#define KEXEC_MIPS_ARGV_MAX_ARGS (COMMAND_LINE_SIZE / 15)
11 +char kexec_argv_buf[KEXEC_MIPS_ARGV_BUF_SIZE] __kexec;
12 +char *kexec_argv[KEXEC_MIPS_ARGV_MAX_ARGS] __kexec;
15 +machine_kexec_print_args(void)
17 - kexec_args[0] = fw_arg0;
18 - kexec_args[1] = fw_arg1;
19 - kexec_args[2] = fw_arg2;
20 - kexec_args[3] = fw_arg3;
23 pr_info("kexec_args[0] (argc): %lu\n", kexec_args[0]);
24 pr_info("kexec_args[1] (argv): %p\n", (void *)kexec_args[1]);
25 pr_info("kexec_args[2] (env ): %p\n", (void *)kexec_args[2]);
26 pr_info("kexec_args[3] (desc): %p\n", (void *)kexec_args[3]);
29 -#define ARGV_MAX_ARGS (COMMAND_LINE_SIZE / 15)
30 + for (i = 0; i < kexec_args[0]; i++)
31 + pr_info("kexec_argv[%d] = %p, %s\n", i,
32 + (char *)kexec_argv[i], (char *)kexec_argv[i]);
35 -int machine_kexec_pass_args(struct kimage *image)
37 +machine_kexec_init_argv(struct kimage *image)
40 - char *bootloader = "kexec";
41 - int *kexec_argv = (int *)kexec_args[1];
42 + void __user *buf = NULL;
48 for (i = 0; i < image->nr_segments; i++) {
49 - if (!strncmp(bootloader, (char *)image->segment[i].buf,
50 - strlen(bootloader))) {
52 - * convert command line string to array
53 - * of parameters (as bootloader does).
56 - * Note: we do treat the 1st string "kexec" as an
57 - * argument ;-) so, argc here is 1.
59 - char *str = (char *)image->segment[i].buf;
60 - char *ptr = strchr(str, ' ');
61 - char *kbuf = (char *)kexec_argv[0];
62 - /* Whenever --command-line or --append used, "kexec" is copied */
64 - /* Parse the offset */
65 - while (ptr && (ARGV_MAX_ARGS > argc)) {
67 - if (ptr[1] != ' ' && ptr[1] != '\0') {
68 - int offt = (int)(ptr - str + 1);
69 - kexec_argv[argc] = (int)kbuf + offt;
72 - ptr = strchr(ptr + 1, ' ');
75 - /* Copy to kernel space */
76 - copy_from_user(kbuf, (char *)image->segment[i].buf, image->segment[i].bufsz);
77 - fw_arg0 = kexec_args[0] = argc;
80 + struct kexec_segment *seg;
82 + seg = &image->segment[i];
86 + if (strncmp((char *) seg->buf, "kexec", 5))
89 + /* don't copy "kexec" */
91 + bufsz = seg->bufsz - 5;
98 + size = KEXEC_MIPS_ARGV_BUF_SIZE - 1;
99 + size = min(size, bufsz);
101 + pr_warn("kexec command line truncated to %zd bytes\n", size);
103 + /* Copy to kernel space */
104 + copy_from_user(kexec_argv_buf, buf, size);
108 +machine_kexec_parse_argv(struct kimage *image)
110 + char *reboot_code_buffer;
116 + ptr = kexec_argv_buf;
120 + * convert command line string to array of parameters
121 + * (as bootloader does).
123 + while (ptr && *ptr && (KEXEC_MIPS_ARGV_MAX_ARGS > argc)) {
129 + kexec_argv[argc++] = ptr;
130 + ptr = strchr(ptr, ' ');
133 - pr_info("argc = %lu\n", kexec_args[0]);
134 - for (i = 0; i < kexec_args[0]; i++)
135 - pr_info("argv[%d] = %p, %s\n", i, (char *)kexec_argv[i], (char *)kexec_argv[i]);
140 + kexec_args[0] = argc;
141 + kexec_args[1] = (unsigned long)kexec_argv;
145 + reboot_code_buffer = page_address(image->control_code_page);
146 + reloc_delta = reboot_code_buffer - (char *) &__start___kexec_relocate;
148 + kexec_args[1] += reloc_delta;
149 + for (i = 0; i < argc; i++)
150 + kexec_argv[i] += reloc_delta;
154 @@ -95,8 +132,14 @@ machine_kexec_prepare(struct kimage *kim
156 * This can be overrided by _machine_kexec_prepare().
158 - machine_kexec_init_args();
159 - machine_kexec_pass_args(kimage);
161 + kexec_args[0] = fw_arg0;
162 + kexec_args[1] = fw_arg1;
163 + kexec_args[2] = fw_arg2;
164 + kexec_args[3] = fw_arg3;
166 + machine_kexec_init_argv(kimage);
167 + machine_kexec_parse_argv(kimage);
169 if (_machine_kexec_prepare)
170 return _machine_kexec_prepare(kimage);
171 @@ -152,11 +195,13 @@ machine_kexec(struct kimage *image)
172 pr_info("kexec_indirection_page = %p\n",
173 (void *)kexec_indirection_page);
175 + pr_info("Copy kexec_relocate section from %p to reboot_code_buffer: %p\n",
176 + &__start___kexec_relocate, (void *)reboot_code_buffer);
178 memcpy((void *)reboot_code_buffer, &__start___kexec_relocate,
179 kexec_relocate_size);
181 - pr_info("Copy kexec_relocate section from %p to reboot_code_buffer: %p\n",
182 - &__start___kexec_relocate, (void *)reboot_code_buffer);
183 + machine_kexec_print_args();
186 * The generic kexec code builds a page list with physical