| 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 |
| 5 | |
| 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. |
| 11 | |
| 12 | Signed-off-by: Wu Zhangjin <wuzhangjin@gmail.com> |
| 13 | --- |
| 14 | --- a/arch/mips/kernel/machine_kexec.c |
| 15 | +++ b/arch/mips/kernel/machine_kexec.c |
| 16 | @@ -13,6 +13,7 @@ |
| 17 | #include <asm/bootinfo.h> |
| 18 | #include <asm/cacheflush.h> |
| 19 | #include <asm/page.h> |
| 20 | +#include <asm/uaccess.h> |
| 21 | |
| 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]); |
| 26 | } |
| 27 | |
| 28 | +#define ARGV_MAX_ARGS (COMMAND_LINE_SIZE / 15) |
| 29 | + |
| 30 | +int machine_kexec_pass_args(struct kimage *image) |
| 31 | +{ |
| 32 | + int i, argc = 0; |
| 33 | + char *bootloader = "kexec"; |
| 34 | + int *kexec_argv = (int *)kexec_args[1]; |
| 35 | + |
| 36 | + for (i = 0; i < image->nr_segments; i++) { |
| 37 | + if (!strncmp(bootloader, (char *)image->segment[i].buf, |
| 38 | + strlen(bootloader))) { |
| 39 | + /* |
| 40 | + * convert command line string to array |
| 41 | + * of parameters (as bootloader does). |
| 42 | + */ |
| 43 | + /* |
| 44 | + * Note: we do treat the 1st string "kexec" as an |
| 45 | + * argument ;-) so, argc here is 1. |
| 46 | + */ |
| 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 */ |
| 51 | + argc = 1; |
| 52 | + /* Parse the offset */ |
| 53 | + while (ptr && (ARGV_MAX_ARGS > argc)) { |
| 54 | + *ptr = '\0'; |
| 55 | + if (ptr[1] != ' ' && ptr[1] != '\0') { |
| 56 | + int offt = (int)(ptr - str + 1); |
| 57 | + kexec_argv[argc] = (int)kbuf + offt; |
| 58 | + argc++; |
| 59 | + } |
| 60 | + ptr = strchr(ptr + 1, ' '); |
| 61 | + } |
| 62 | + if (argc > 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; |
| 66 | + } |
| 67 | + break; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 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]); |
| 74 | + |
| 75 | + return 0; |
| 76 | +} |
| 77 | + |
| 78 | int |
| 79 | machine_kexec_prepare(struct kimage *kimage) |
| 80 | { |
| 81 | @@ -45,6 +96,7 @@ machine_kexec_prepare(struct kimage *kim |
| 82 | * This can be overrided by _machine_kexec_prepare(). |
| 83 | */ |
| 84 | machine_kexec_init_args(); |
| 85 | + machine_kexec_pass_args(kimage); |
| 86 | |
| 87 | if (_machine_kexec_prepare) |
| 88 | return _machine_kexec_prepare(kimage); |
| 89 | |