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