Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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