333-mips-kexec-get-kernel-parameters-from-kexec-tools.patch 2.7 KB

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