18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * uboot.c -- uboot arguments support
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
58c2ecf20Sopenharmony_ci * License.  See the file COPYING in the main directory of this archive
68c2ecf20Sopenharmony_ci * for more details.
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/sched.h>
118c2ecf20Sopenharmony_ci#include <linux/delay.h>
128c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
138c2ecf20Sopenharmony_ci#include <linux/fb.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/mm.h>
168c2ecf20Sopenharmony_ci#include <linux/console.h>
178c2ecf20Sopenharmony_ci#include <linux/errno.h>
188c2ecf20Sopenharmony_ci#include <linux/string.h>
198c2ecf20Sopenharmony_ci#include <linux/memblock.h>
208c2ecf20Sopenharmony_ci#include <linux/seq_file.h>
218c2ecf20Sopenharmony_ci#include <linux/init.h>
228c2ecf20Sopenharmony_ci#include <linux/initrd.h>
238c2ecf20Sopenharmony_ci#include <linux/root_dev.h>
248c2ecf20Sopenharmony_ci#include <linux/rtc.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <asm/setup.h>
278c2ecf20Sopenharmony_ci#include <asm/irq.h>
288c2ecf20Sopenharmony_ci#include <asm/machdep.h>
298c2ecf20Sopenharmony_ci#include <asm/sections.h>
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci/*
328c2ecf20Sopenharmony_ci * parse_uboot_commandline
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * Copies u-boot commandline arguments and store them in the proper linux
358c2ecf20Sopenharmony_ci * variables.
368c2ecf20Sopenharmony_ci *
378c2ecf20Sopenharmony_ci * Assumes:
388c2ecf20Sopenharmony_ci *	_init_sp global contains the address in the stack pointer when the
398c2ecf20Sopenharmony_ci *	kernel starts (see head.S::_start)
408c2ecf20Sopenharmony_ci *
418c2ecf20Sopenharmony_ci *	U-Boot calling convention:
428c2ecf20Sopenharmony_ci *	(*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci *	_init_sp can be parsed as such
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci *	_init_sp+00 = u-boot cmd after jsr into kernel (skip)
478c2ecf20Sopenharmony_ci *	_init_sp+04 = &kernel board_info (residual data)
488c2ecf20Sopenharmony_ci *	_init_sp+08 = &initrd_start
498c2ecf20Sopenharmony_ci *	_init_sp+12 = &initrd_end
508c2ecf20Sopenharmony_ci *	_init_sp+16 = &cmd_start
518c2ecf20Sopenharmony_ci *	_init_sp+20 = &cmd_end
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci *	This also assumes that the memory locations pointed to are still
548c2ecf20Sopenharmony_ci *	unmodified. U-boot places them near the end of external SDRAM.
558c2ecf20Sopenharmony_ci *
568c2ecf20Sopenharmony_ci * Argument(s):
578c2ecf20Sopenharmony_ci *	commandp = the linux commandline arg container to fill.
588c2ecf20Sopenharmony_ci *	size     = the sizeof commandp.
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * Returns:
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistatic void __init parse_uboot_commandline(char *commandp, int size)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	extern unsigned long _init_sp;
658c2ecf20Sopenharmony_ci	unsigned long *sp;
668c2ecf20Sopenharmony_ci	unsigned long uboot_kbd;
678c2ecf20Sopenharmony_ci	unsigned long uboot_initrd_start, uboot_initrd_end;
688c2ecf20Sopenharmony_ci	unsigned long uboot_cmd_start, uboot_cmd_end;
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	sp = (unsigned long *)_init_sp;
718c2ecf20Sopenharmony_ci	uboot_kbd = sp[1];
728c2ecf20Sopenharmony_ci	uboot_initrd_start = sp[2];
738c2ecf20Sopenharmony_ci	uboot_initrd_end = sp[3];
748c2ecf20Sopenharmony_ci	uboot_cmd_start = sp[4];
758c2ecf20Sopenharmony_ci	uboot_cmd_end = sp[5];
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	if (uboot_cmd_start && uboot_cmd_end)
788c2ecf20Sopenharmony_ci		strncpy(commandp, (const char *)uboot_cmd_start, size);
798c2ecf20Sopenharmony_ci#if defined(CONFIG_BLK_DEV_INITRD)
808c2ecf20Sopenharmony_ci	if (uboot_initrd_start && uboot_initrd_end &&
818c2ecf20Sopenharmony_ci	    (uboot_initrd_end > uboot_initrd_start)) {
828c2ecf20Sopenharmony_ci		initrd_start = uboot_initrd_start;
838c2ecf20Sopenharmony_ci		initrd_end = uboot_initrd_end;
848c2ecf20Sopenharmony_ci		ROOT_DEV = Root_RAM0;
858c2ecf20Sopenharmony_ci		pr_info("initrd at 0x%lx:0x%lx\n", initrd_start, initrd_end);
868c2ecf20Sopenharmony_ci	}
878c2ecf20Sopenharmony_ci#endif /* if defined(CONFIG_BLK_DEV_INITRD) */
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci__init void process_uboot_commandline(char *commandp, int size)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	int len, n;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	n = strnlen(commandp, size);
958c2ecf20Sopenharmony_ci	commandp += n;
968c2ecf20Sopenharmony_ci	len = size - n;
978c2ecf20Sopenharmony_ci	if (len) {
988c2ecf20Sopenharmony_ci		/* Add the whitespace separator */
998c2ecf20Sopenharmony_ci		*commandp++ = ' ';
1008c2ecf20Sopenharmony_ci		len--;
1018c2ecf20Sopenharmony_ci	}
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	parse_uboot_commandline(commandp, len);
1048c2ecf20Sopenharmony_ci	commandp[len - 1] = 0;
1058c2ecf20Sopenharmony_ci}
106