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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * misc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This is a collection of several routines from gzip-1.0.3 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * adapted for Linux.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * malloc by Hannu Savolainen 1993 and Matthias Urlichs 1994
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * Modified for ARM Linux by Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * Nicolas Pitre <nico@visuaide.com>  1999/04/14 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  For this code to run directly from Flash, all constant variables must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  be marked with 'const' and all other variables initialized at run-time 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  only.  This way all non constant variables will end up in the bss segment,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *  which should point to addresses in RAM and cleared to 0 on start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  This allows for a much quicker boot time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) unsigned int __machine_arch_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/compiler.h>	/* for inline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include "misc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) static void putstr(const char *ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include CONFIG_UNCOMPRESS_INCLUDE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #ifdef CONFIG_DEBUG_ICEDCC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_V6K) || defined(CONFIG_CPU_V7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static void icedcc_putc(int ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int status, i = 0x4000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		if (--i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		asm volatile ("mrc p14, 0, %0, c0, c1, 0" : "=r" (status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	} while (status & (1 << 29));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	asm("mcr p14, 0, %0, c0, c5, 0" : : "r" (ch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #elif defined(CONFIG_CPU_XSCALE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static void icedcc_putc(int ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	int status, i = 0x4000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		if (--i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		asm volatile ("mrc p14, 0, %0, c14, c0, 0" : "=r" (status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	} while (status & (1 << 28));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	asm("mcr p14, 0, %0, c8, c0, 0" : : "r" (ch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static void icedcc_putc(int ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	int status, i = 0x4000000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		if (--i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		asm volatile ("mrc p14, 0, %0, c0, c0, 0" : "=r" (status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	} while (status & 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	asm("mcr p14, 0, %0, c1, c0, 0" : : "r" (ch));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #define putc(ch)	icedcc_putc(ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static void putstr(const char *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	char c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	while ((c = *ptr++) != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (c == '\n')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			putc('\r');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		putc(c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	flush();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * gzip declarations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) extern char input_data[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) extern char input_data_end[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) unsigned char *output_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned long free_mem_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned long free_mem_end_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifndef arch_error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define arch_error(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) void error(char *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	arch_error(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	putstr("\n\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	putstr(x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	putstr("\n\n -- System halted");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	while(1);	/* Halt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) asmlinkage void __div0(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	error("Attempting division by 0!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) const unsigned long __stack_chk_guard = 0x000a0dff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) void __stack_chk_fail(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	error("stack-protector: Kernel stack is corrupted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) extern int do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		unsigned long free_mem_ptr_end_p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		int arch_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	output_data		= (unsigned char *)output_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	free_mem_ptr		= free_mem_ptr_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	free_mem_end_ptr	= free_mem_ptr_end_p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	__machine_arch_type	= arch_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	arch_decomp_setup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	putstr("Uncompressing Linux...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	ret = do_decompress(input_data, input_data_end - input_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			    output_data, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		error("decompressor returned an error");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		putstr(" done, booting the kernel.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) void fortify_panic(const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	error("detected buffer overflow");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }