1 From 240c76841b26f1b09aaced33414ee1d08b6454cf Mon Sep 17 00:00:00 2001
2 From: Wu Zhangjin <wuzhangjin@gmail.com>
3 Date: Sat, 15 Jan 2011 12:46:03 +0000
4 Subject: MIPS: Get kernel parameters from kexec-tools
6 Before, we simply use the command lines from the original bootloader,
7 but it is not convenient. Now, we accept the kernel parameters from the
8 --command-line or --append option of the kexec-tools. But If not
9 --command-line or --apend option indicated, will fall back to use the
10 ones from the original bootloader.
12 Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com>
14 --- a/arch/mips/kernel/machine_kexec.c
15 +++ b/arch/mips/kernel/machine_kexec.c
17 #include <asm/bootinfo.h>
18 #include <asm/cacheflush.h>
20 +#include <asm/uaccess.h>
22 int (*_machine_kexec_prepare)(struct kimage *) = NULL;
23 void (*_machine_kexec_shutdown)(void) = NULL;
24 @@ -35,6 +36,56 @@ static void machine_kexec_init_args(void
25 pr_info("kexec_args[3] (desc): %p\n", (void *)kexec_args[3]);
28 +#define ARGV_MAX_ARGS (COMMAND_LINE_SIZE / 15)
30 +int machine_kexec_pass_args(struct kimage *image)
33 + char *bootloader = "kexec";
34 + int *kexec_argv = (int *)kexec_args[1];
36 + for (i = 0; i < image->nr_segments; i++) {
37 + if (!strncmp(bootloader, (char *)image->segment[i].buf,
38 + strlen(bootloader))) {
40 + * convert command line string to array
41 + * of parameters (as bootloader does).
44 + * Note: we do treat the 1st string "kexec" as an
45 + * argument ;-) so, argc here is 1.
47 + char *str = (char *)image->segment[i].buf;
48 + char *ptr = strchr(str, ' ');
49 + char *kbuf = (char *)kexec_argv[0];
50 + /* Whenever --command-line or --append used, "kexec" is copied */
52 + /* Parse the offset */
53 + while (ptr && (ARGV_MAX_ARGS > argc)) {
55 + if (ptr[1] != ' ' && ptr[1] != '\0') {
56 + int offt = (int)(ptr - str + 1);
57 + kexec_argv[argc] = (int)kbuf + offt;
60 + ptr = strchr(ptr + 1, ' ');
63 + /* Copy to kernel space */
64 + copy_from_user(kbuf, (char *)image->segment[i].buf, image->segment[i].bufsz);
65 + fw_arg0 = kexec_args[0] = argc;
71 + pr_info("argc = %lu\n", kexec_args[0]);
72 + for (i = 0; i < kexec_args[0]; i++)
73 + pr_info("argv[%d] = %p, %s\n", i, (char *)kexec_argv[i], (char *)kexec_argv[i]);
79 machine_kexec_prepare(struct kimage *kimage)
81 @@ -45,6 +96,7 @@ machine_kexec_prepare(struct kimage *kim
82 * This can be overrided by _machine_kexec_prepare().
84 machine_kexec_init_args();
85 + machine_kexec_pass_args(kimage);
87 if (_machine_kexec_prepare)
88 return _machine_kexec_prepare(kimage);