uboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * uboot.c -- uboot arguments support
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file COPYING in the main directory of this archive
  6. * for more details.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/delay.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/fb.h>
  13. #include <linux/module.h>
  14. #include <linux/mm.h>
  15. #include <linux/console.h>
  16. #include <linux/errno.h>
  17. #include <linux/string.h>
  18. #include <linux/bootmem.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/init.h>
  21. #include <linux/initrd.h>
  22. #include <linux/root_dev.h>
  23. #include <linux/rtc.h>
  24. #include <asm/setup.h>
  25. #include <asm/irq.h>
  26. #include <asm/machdep.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/sections.h>
  29. /*
  30. * parse_uboot_commandline
  31. *
  32. * Copies u-boot commandline arguments and store them in the proper linux
  33. * variables.
  34. *
  35. * Assumes:
  36. * _init_sp global contains the address in the stack pointer when the
  37. * kernel starts (see head.S::_start)
  38. *
  39. * U-Boot calling convention:
  40. * (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
  41. *
  42. * _init_sp can be parsed as such
  43. *
  44. * _init_sp+00 = u-boot cmd after jsr into kernel (skip)
  45. * _init_sp+04 = &kernel board_info (residual data)
  46. * _init_sp+08 = &initrd_start
  47. * _init_sp+12 = &initrd_end
  48. * _init_sp+16 = &cmd_start
  49. * _init_sp+20 = &cmd_end
  50. *
  51. * This also assumes that the memory locations pointed to are still
  52. * unmodified. U-boot places them near the end of external SDRAM.
  53. *
  54. * Argument(s):
  55. * commandp = the linux commandline arg container to fill.
  56. * size = the sizeof commandp.
  57. *
  58. * Returns:
  59. */
  60. static void __init parse_uboot_commandline(char *commandp, int size)
  61. {
  62. extern unsigned long _init_sp;
  63. unsigned long *sp;
  64. unsigned long uboot_kbd;
  65. unsigned long uboot_initrd_start, uboot_initrd_end;
  66. unsigned long uboot_cmd_start, uboot_cmd_end;
  67. sp = (unsigned long *)_init_sp;
  68. uboot_kbd = sp[1];
  69. uboot_initrd_start = sp[2];
  70. uboot_initrd_end = sp[3];
  71. uboot_cmd_start = sp[4];
  72. uboot_cmd_end = sp[5];
  73. if (uboot_cmd_start && uboot_cmd_end)
  74. strncpy(commandp, (const char *)uboot_cmd_start, size);
  75. #if defined(CONFIG_BLK_DEV_INITRD)
  76. if (uboot_initrd_start && uboot_initrd_end &&
  77. (uboot_initrd_end > uboot_initrd_start)) {
  78. initrd_start = uboot_initrd_start;
  79. initrd_end = uboot_initrd_end;
  80. ROOT_DEV = Root_RAM0;
  81. printk(KERN_INFO "initrd at 0x%lx:0x%lx\n",
  82. initrd_start, initrd_end);
  83. }
  84. #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
  85. }
  86. __init void process_uboot_commandline(char *commandp, int size)
  87. {
  88. int len, n;
  89. n = strnlen(commandp, size);
  90. commandp += n;
  91. len = size - n;
  92. if (len) {
  93. /* Add the whitespace separator */
  94. *commandp++ = ' ';
  95. len--;
  96. }
  97. parse_uboot_commandline(commandp, len);
  98. commandp[size - 1] = 0;
  99. }