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 
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/delay.h>
12 #include <linux/interrupt.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/memblock.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 
25 #include <asm/setup.h>
26 #include <asm/irq.h>
27 #include <asm/machdep.h>
28 #include <asm/sections.h>
29 #include <asm/bootinfo.h>
30 
31 /*
32  * parse_uboot_commandline
33  *
34  * Copies u-boot commandline arguments and store them in the proper linux
35  * variables.
36  *
37  * Assumes:
38  *	_init_sp global contains the address in the stack pointer when the
39  *	kernel starts (see head.S::_start)
40  *
41  *	U-Boot calling convention:
42  *	(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
43  *
44  *	_init_sp can be parsed as such
45  *
46  *	_init_sp+00 = u-boot cmd after jsr into kernel (skip)
47  *	_init_sp+04 = &kernel board_info (residual data)
48  *	_init_sp+08 = &initrd_start
49  *	_init_sp+12 = &initrd_end
50  *	_init_sp+16 = &cmd_start
51  *	_init_sp+20 = &cmd_end
52  *
53  *	This also assumes that the memory locations pointed to are still
54  *	unmodified. U-boot places them near the end of external SDRAM.
55  *
56  * Argument(s):
57  *	commandp = the linux commandline arg container to fill.
58  *	size     = the sizeof commandp.
59  *
60  * Returns:
61  */
62 static void __init parse_uboot_commandline(char *commandp, int size)
63 {
64 	extern unsigned long _init_sp;
65 	unsigned long *sp;
66 	unsigned long uboot_cmd_start, uboot_cmd_end;
67 #if defined(CONFIG_BLK_DEV_INITRD)
68 	unsigned long uboot_initrd_start, uboot_initrd_end;
69 #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
70 
71 	sp = (unsigned long *)_init_sp;
72 	uboot_cmd_start = sp[4];
73 	uboot_cmd_end = sp[5];
74 
75 	if (uboot_cmd_start && uboot_cmd_end)
76 		strscpy(commandp, (const char *)uboot_cmd_start, size);
77 
78 #if defined(CONFIG_BLK_DEV_INITRD)
79 	uboot_initrd_start = sp[2];
80 	uboot_initrd_end = sp[3];
81 
82 	if (uboot_initrd_start && uboot_initrd_end &&
83 	    (uboot_initrd_end > uboot_initrd_start)) {
84 		initrd_start = uboot_initrd_start;
85 		initrd_end = uboot_initrd_end;
86 		ROOT_DEV = Root_RAM0;
87 		pr_info("initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
88 	}
89 #endif /* if defined(CONFIG_BLK_DEV_INITRD) */
90 }
91 
92 __init void process_uboot_commandline(char *commandp, int size)
93 {
94 	int len, n;
95 
96 	n = strnlen(commandp, size);
97 	commandp += n;
98 	len = size - n;
99 	if (len) {
100 		/* Add the whitespace separator */
101 		*commandp++ = ' ';
102 		len--;
103 	}
104 
105 	parse_uboot_commandline(commandp, len);
106 	commandp[len - 1] = 0;
107 }
108