diff options
author | 2025-03-08 22:04:20 +0800 | |
---|---|---|
committer | 2025-03-08 22:04:20 +0800 | |
commit | a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a (patch) | |
tree | 84f21bd0bf7071bc5fc7dd989e77d7ceb5476682 /arch/mips/boot/compressed | |
download | ohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.tar.gz ohosKernel-a07bb8fd1299070229f0e8f3dcb57ffd5ef9870a.zip |
Initial commit: OpenHarmony-v4.0-ReleaseOpenHarmony-v4.0-Release
Diffstat (limited to 'arch/mips/boot/compressed')
-rw-r--r-- | arch/mips/boot/compressed/.gitignore | 3 | ||||
-rw-r--r-- | arch/mips/boot/compressed/Makefile | 155 | ||||
-rw-r--r-- | arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | 54 | ||||
-rw-r--r-- | arch/mips/boot/compressed/dbg.c | 37 | ||||
-rw-r--r-- | arch/mips/boot/compressed/decompress.c | 132 | ||||
-rw-r--r-- | arch/mips/boot/compressed/dummy.c | 4 | ||||
-rw-r--r-- | arch/mips/boot/compressed/head.S | 56 | ||||
-rw-r--r-- | arch/mips/boot/compressed/ld.script | 57 | ||||
-rw-r--r-- | arch/mips/boot/compressed/string.c | 46 | ||||
-rw-r--r-- | arch/mips/boot/compressed/uart-16550.c | 64 | ||||
-rw-r--r-- | arch/mips/boot/compressed/uart-alchemy.c | 7 | ||||
-rw-r--r-- | arch/mips/boot/compressed/uart-prom.c | 7 |
12 files changed, 622 insertions, 0 deletions
diff --git a/arch/mips/boot/compressed/.gitignore b/arch/mips/boot/compressed/.gitignore new file mode 100644 index 000000000..d35839561 --- /dev/null +++ b/arch/mips/boot/compressed/.gitignore | |||
@@ -0,0 +1,3 @@ | |||
1 | # SPDX-License-Identifier: GPL-2.0-only | ||
2 | ashldi3.c | ||
3 | bswapsi.c | ||
diff --git a/arch/mips/boot/compressed/Makefile b/arch/mips/boot/compressed/Makefile new file mode 100644 index 000000000..eae0fad30 --- /dev/null +++ b/arch/mips/boot/compressed/Makefile | |||
@@ -0,0 +1,155 @@ | |||
1 | # | ||
2 | # This file is subject to the terms and conditions of the GNU General Public | ||
3 | # License. | ||
4 | # | ||
5 | # Adapted for MIPS Pete Popov, Dan Malek | ||
6 | # | ||
7 | # Copyright (C) 1994 by Linus Torvalds | ||
8 | # Adapted for PowerPC by Gary Thomas | ||
9 | # modified by Cort (cort@cs.nmt.edu) | ||
10 | # | ||
11 | # Copyright (C) 2009 Lemote Inc. & DSLab, Lanzhou University | ||
12 | # Author: Wu Zhangjin <wuzhangjin@gmail.com> | ||
13 | # | ||
14 | |||
15 | include $(srctree)/arch/mips/Kbuild.platforms | ||
16 | |||
17 | # set the default size of the mallocing area for decompressing | ||
18 | BOOT_HEAP_SIZE := 0x400000 | ||
19 | |||
20 | # Disable Function Tracer | ||
21 | KBUILD_CFLAGS := $(filter-out -pg, $(KBUILD_CFLAGS)) | ||
22 | |||
23 | KBUILD_CFLAGS := $(filter-out -fstack-protector, $(KBUILD_CFLAGS)) | ||
24 | |||
25 | # Disable lq/sq in zboot | ||
26 | ifdef CONFIG_CPU_LOONGSON64 | ||
27 | KBUILD_CFLAGS := $(filter-out -march=loongson3a, $(KBUILD_CFLAGS)) -march=mips64r2 | ||
28 | endif | ||
29 | |||
30 | KBUILD_CFLAGS := $(KBUILD_CFLAGS) -D__KERNEL__ -D__DISABLE_EXPORTS \ | ||
31 | -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) -D"VMLINUX_LOAD_ADDRESS_ULL=$(VMLINUX_LOAD_ADDRESS)ull" | ||
32 | |||
33 | KBUILD_AFLAGS := $(KBUILD_AFLAGS) -D__ASSEMBLY__ \ | ||
34 | -DBOOT_HEAP_SIZE=$(BOOT_HEAP_SIZE) \ | ||
35 | -DKERNEL_ENTRY=$(VMLINUX_ENTRY_ADDRESS) | ||
36 | |||
37 | # Prevents link failures: __sanitizer_cov_trace_pc() is not linked in. | ||
38 | KCOV_INSTRUMENT := n | ||
39 | UBSAN_SANITIZE := n | ||
40 | |||
41 | # decompressor objects (linked with vmlinuz) | ||
42 | vmlinuzobjs-y := $(obj)/head.o $(obj)/decompress.o $(obj)/string.o $(obj)/bswapsi.o | ||
43 | |||
44 | ifdef CONFIG_DEBUG_ZBOOT | ||
45 | vmlinuzobjs-$(CONFIG_DEBUG_ZBOOT) += $(obj)/dbg.o | ||
46 | vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART16550) += $(obj)/uart-16550.o | ||
47 | vmlinuzobjs-$(CONFIG_SYS_SUPPORTS_ZBOOT_UART_PROM) += $(obj)/uart-prom.o | ||
48 | vmlinuzobjs-$(CONFIG_MIPS_ALCHEMY) += $(obj)/uart-alchemy.o | ||
49 | vmlinuzobjs-$(CONFIG_ATH79) += $(obj)/uart-ath79.o | ||
50 | endif | ||
51 | |||
52 | extra-y += uart-ath79.c | ||
53 | $(obj)/uart-ath79.c: $(srctree)/arch/mips/ath79/early_printk.c | ||
54 | $(call cmd,shipped) | ||
55 | |||
56 | vmlinuzobjs-$(CONFIG_KERNEL_XZ) += $(obj)/ashldi3.o | ||
57 | |||
58 | extra-y += ashldi3.c | ||
59 | $(obj)/ashldi3.c: $(obj)/%.c: $(srctree)/lib/%.c FORCE | ||
60 | $(call if_changed,shipped) | ||
61 | |||
62 | extra-y += bswapsi.c | ||
63 | $(obj)/bswapsi.c: $(obj)/%.c: $(srctree)/arch/mips/lib/%.c FORCE | ||
64 | $(call if_changed,shipped) | ||
65 | |||
66 | targets := $(notdir $(vmlinuzobjs-y)) | ||
67 | |||
68 | targets += vmlinux.bin | ||
69 | OBJCOPYFLAGS_vmlinux.bin := $(OBJCOPYFLAGS) -O binary -R .comment -S | ||
70 | $(obj)/vmlinux.bin: $(KBUILD_IMAGE) FORCE | ||
71 | $(call if_changed,objcopy) | ||
72 | |||
73 | tool_$(CONFIG_KERNEL_GZIP) = gzip | ||
74 | tool_$(CONFIG_KERNEL_BZIP2) = bzip2 | ||
75 | tool_$(CONFIG_KERNEL_LZ4) = lz4 | ||
76 | tool_$(CONFIG_KERNEL_LZMA) = lzma | ||
77 | tool_$(CONFIG_KERNEL_LZO) = lzo | ||
78 | tool_$(CONFIG_KERNEL_XZ) = xzkern | ||
79 | tool_$(CONFIG_KERNEL_ZSTD) = zstd22 | ||
80 | |||
81 | targets += vmlinux.bin.z | ||
82 | $(obj)/vmlinux.bin.z: $(obj)/vmlinux.bin FORCE | ||
83 | $(call if_changed,$(tool_y)) | ||
84 | |||
85 | targets += piggy.o dummy.o | ||
86 | OBJCOPYFLAGS_piggy.o := --add-section=.image=$(obj)/vmlinux.bin.z \ | ||
87 | --set-section-flags=.image=contents,alloc,load,readonly,data | ||
88 | $(obj)/piggy.o: $(obj)/dummy.o $(obj)/vmlinux.bin.z FORCE | ||
89 | $(call if_changed,objcopy) | ||
90 | |||
91 | HOSTCFLAGS_calc_vmlinuz_load_addr.o += $(LINUXINCLUDE) | ||
92 | |||
93 | # Calculate the load address of the compressed kernel image | ||
94 | hostprogs := calc_vmlinuz_load_addr | ||
95 | |||
96 | ifneq ($(zload-y),) | ||
97 | VMLINUZ_LOAD_ADDRESS := $(zload-y) | ||
98 | else | ||
99 | VMLINUZ_LOAD_ADDRESS = $(shell $(obj)/calc_vmlinuz_load_addr \ | ||
100 | $(obj)/vmlinux.bin $(LINKER_LOAD_ADDRESS)) | ||
101 | endif | ||
102 | UIMAGE_LOADADDR = $(VMLINUZ_LOAD_ADDRESS) | ||
103 | |||
104 | vmlinuzobjs-y += $(obj)/piggy.o | ||
105 | |||
106 | quiet_cmd_zld = LD $@ | ||
107 | cmd_zld = $(LD) $(KBUILD_LDFLAGS) -Ttext $(VMLINUZ_LOAD_ADDRESS) -T $< $(vmlinuzobjs-y) -o $@ | ||
108 | quiet_cmd_strip = STRIP $@ | ||
109 | cmd_strip = $(STRIP) -s $@ | ||
110 | vmlinuz: $(src)/ld.script $(vmlinuzobjs-y) $(obj)/calc_vmlinuz_load_addr | ||
111 | $(call cmd,zld) | ||
112 | $(call cmd,strip) | ||
113 | |||
114 | # | ||
115 | # Some DECstations need all possible sections of an ECOFF executable | ||
116 | # | ||
117 | ifdef CONFIG_MACH_DECSTATION | ||
118 | e2eflag := -a | ||
119 | endif | ||
120 | |||
121 | # elf2ecoff can only handle 32bit image | ||
122 | hostprogs += ../elf2ecoff | ||
123 | |||
124 | ifdef CONFIG_32BIT | ||
125 | VMLINUZ = vmlinuz | ||
126 | else | ||
127 | VMLINUZ = vmlinuz.32 | ||
128 | endif | ||
129 | |||
130 | quiet_cmd_32 = OBJCOPY $@ | ||
131 | cmd_32 = $(OBJCOPY) -O $(32bit-bfd) $(OBJCOPYFLAGS) $< $@ | ||
132 | vmlinuz.32: vmlinuz | ||
133 | $(call cmd,32) | ||
134 | |||
135 | quiet_cmd_ecoff = ECOFF $@ | ||
136 | cmd_ecoff = $< $(VMLINUZ) $@ $(e2eflag) | ||
137 | vmlinuz.ecoff: $(obj)/../elf2ecoff $(VMLINUZ) | ||
138 | $(call cmd,ecoff) | ||
139 | |||
140 | OBJCOPYFLAGS_vmlinuz.bin := $(OBJCOPYFLAGS) -O binary | ||
141 | vmlinuz.bin: vmlinuz | ||
142 | $(call cmd,objcopy) | ||
143 | |||
144 | OBJCOPYFLAGS_vmlinuz.srec := $(OBJCOPYFLAGS) -S -O srec | ||
145 | vmlinuz.srec: vmlinuz | ||
146 | $(call cmd,objcopy) | ||
147 | |||
148 | uzImage.bin: vmlinuz.bin FORCE | ||
149 | $(call if_changed,uimage,none) | ||
150 | |||
151 | clean-files += $(objtree)/vmlinuz | ||
152 | clean-files += $(objtree)/vmlinuz.32 | ||
153 | clean-files += $(objtree)/vmlinuz.ecoff | ||
154 | clean-files += $(objtree)/vmlinuz.bin | ||
155 | clean-files += $(objtree)/vmlinuz.srec | ||
diff --git a/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c new file mode 100644 index 000000000..080b926d2 --- /dev/null +++ b/arch/mips/boot/compressed/calc_vmlinuz_load_addr.c | |||
@@ -0,0 +1,54 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
2 | /* | ||
3 | * Copyright (C) 2010 "Wu Zhangjin" <wuzhangjin@gmail.com> | ||
4 | */ | ||
5 | |||
6 | #include <sys/types.h> | ||
7 | #include <sys/stat.h> | ||
8 | #include <errno.h> | ||
9 | #include <stdint.h> | ||
10 | #include <stdio.h> | ||
11 | #include <stdlib.h> | ||
12 | #include <linux/sizes.h> | ||
13 | |||
14 | int main(int argc, char *argv[]) | ||
15 | { | ||
16 | unsigned long long vmlinux_size, vmlinux_load_addr, vmlinuz_load_addr; | ||
17 | struct stat sb; | ||
18 | |||
19 | if (argc != 3) { | ||
20 | fprintf(stderr, "Usage: %s <pathname> <vmlinux_load_addr>\n", | ||
21 | argv[0]); | ||
22 | return EXIT_FAILURE; | ||
23 | } | ||
24 | |||
25 | if (stat(argv[1], &sb) == -1) { | ||
26 | perror("stat"); | ||
27 | return EXIT_FAILURE; | ||
28 | } | ||
29 | |||
30 | /* Convert hex characters to dec number */ | ||
31 | errno = 0; | ||
32 | if (sscanf(argv[2], "%llx", &vmlinux_load_addr) != 1) { | ||
33 | if (errno != 0) | ||
34 | perror("sscanf"); | ||
35 | else | ||
36 | fprintf(stderr, "No matching characters\n"); | ||
37 | |||
38 | return EXIT_FAILURE; | ||
39 | } | ||
40 | |||
41 | vmlinux_size = (uint64_t)sb.st_size; | ||
42 | vmlinuz_load_addr = vmlinux_load_addr + vmlinux_size; | ||
43 | |||
44 | /* | ||
45 | * Align with 64KB: KEXEC needs load sections to be aligned to PAGE_SIZE, | ||
46 | * which may be as large as 64KB depending on the kernel configuration. | ||
47 | */ | ||
48 | |||
49 | vmlinuz_load_addr += (SZ_64K - vmlinux_size % SZ_64K); | ||
50 | |||
51 | printf("0x%llx\n", vmlinuz_load_addr); | ||
52 | |||
53 | return EXIT_SUCCESS; | ||
54 | } | ||
diff --git a/arch/mips/boot/compressed/dbg.c b/arch/mips/boot/compressed/dbg.c new file mode 100644 index 000000000..f6728a8fd --- /dev/null +++ b/arch/mips/boot/compressed/dbg.c | |||
@@ -0,0 +1,37 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * MIPS-specific debug support for pre-boot environment | ||
4 | * | ||
5 | * NOTE: putc() is board specific, if your board have a 16550 compatible uart, | ||
6 | * please select SYS_SUPPORTS_ZBOOT_UART16550 for your machine. othewise, you | ||
7 | * need to implement your own putc(). | ||
8 | */ | ||
9 | #include <linux/compiler.h> | ||
10 | #include <linux/types.h> | ||
11 | |||
12 | void __weak putc(char c) | ||
13 | { | ||
14 | } | ||
15 | |||
16 | void puts(const char *s) | ||
17 | { | ||
18 | char c; | ||
19 | while ((c = *s++) != '\0') { | ||
20 | putc(c); | ||
21 | if (c == '\n') | ||
22 | putc('\r'); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | void puthex(unsigned long long val) | ||
27 | { | ||
28 | |||
29 | unsigned char buf[10]; | ||
30 | int i; | ||
31 | for (i = 7; i >= 0; i--) { | ||
32 | buf[i] = "0123456789ABCDEF"[val & 0x0F]; | ||
33 | val >>= 4; | ||
34 | } | ||
35 | buf[8] = '\0'; | ||
36 | puts(buf); | ||
37 | } | ||
diff --git a/arch/mips/boot/compressed/decompress.c b/arch/mips/boot/compressed/decompress.c new file mode 100644 index 000000000..1e91155be --- /dev/null +++ b/arch/mips/boot/compressed/decompress.c | |||
@@ -0,0 +1,132 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
2 | /* | ||
3 | * Copyright 2001 MontaVista Software Inc. | ||
4 | * Author: Matt Porter <mporter@mvista.com> | ||
5 | * | ||
6 | * Copyright (C) 2009 Lemote, Inc. | ||
7 | * Author: Wu Zhangjin <wuzhangjin@gmail.com> | ||
8 | */ | ||
9 | |||
10 | #define DISABLE_BRANCH_PROFILING | ||
11 | |||
12 | #include <linux/types.h> | ||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/string.h> | ||
15 | #include <linux/libfdt.h> | ||
16 | |||
17 | #include <asm/addrspace.h> | ||
18 | #include <asm/unaligned.h> | ||
19 | |||
20 | /* | ||
21 | * These two variables specify the free mem region | ||
22 | * that can be used for temporary malloc area | ||
23 | */ | ||
24 | unsigned long free_mem_ptr; | ||
25 | unsigned long free_mem_end_ptr; | ||
26 | |||
27 | /* The linker tells us where the image is. */ | ||
28 | extern unsigned char __image_begin, __image_end; | ||
29 | |||
30 | /* debug interfaces */ | ||
31 | #ifdef CONFIG_DEBUG_ZBOOT | ||
32 | extern void puts(const char *s); | ||
33 | extern void puthex(unsigned long long val); | ||
34 | #else | ||
35 | #define puts(s) do {} while (0) | ||
36 | #define puthex(val) do {} while (0) | ||
37 | #endif | ||
38 | |||
39 | extern char __appended_dtb[]; | ||
40 | |||
41 | void error(char *x) | ||
42 | { | ||
43 | puts("\n\n"); | ||
44 | puts(x); | ||
45 | puts("\n\n -- System halted"); | ||
46 | |||
47 | while (1) | ||
48 | ; /* Halt */ | ||
49 | } | ||
50 | |||
51 | /* activate the code for pre-boot environment */ | ||
52 | #define STATIC static | ||
53 | |||
54 | #ifdef CONFIG_KERNEL_GZIP | ||
55 | #include "../../../../lib/decompress_inflate.c" | ||
56 | #endif | ||
57 | |||
58 | #ifdef CONFIG_KERNEL_BZIP2 | ||
59 | #include "../../../../lib/decompress_bunzip2.c" | ||
60 | #endif | ||
61 | |||
62 | #ifdef CONFIG_KERNEL_LZ4 | ||
63 | #include "../../../../lib/decompress_unlz4.c" | ||
64 | #endif | ||
65 | |||
66 | #ifdef CONFIG_KERNEL_LZMA | ||
67 | #include "../../../../lib/decompress_unlzma.c" | ||
68 | #endif | ||
69 | |||
70 | #ifdef CONFIG_KERNEL_LZO | ||
71 | #include "../../../../lib/decompress_unlzo.c" | ||
72 | #endif | ||
73 | |||
74 | #ifdef CONFIG_KERNEL_XZ | ||
75 | #include "../../../../lib/decompress_unxz.c" | ||
76 | #endif | ||
77 | |||
78 | #ifdef CONFIG_KERNEL_ZSTD | ||
79 | #include "../../../../lib/decompress_unzstd.c" | ||
80 | #endif | ||
81 | |||
82 | const unsigned long __stack_chk_guard = 0x000a0dff; | ||
83 | |||
84 | void __stack_chk_fail(void) | ||
85 | { | ||
86 | error("stack-protector: Kernel stack is corrupted\n"); | ||
87 | } | ||
88 | |||
89 | void decompress_kernel(unsigned long boot_heap_start) | ||
90 | { | ||
91 | unsigned long zimage_start, zimage_size; | ||
92 | |||
93 | zimage_start = (unsigned long)(&__image_begin); | ||
94 | zimage_size = (unsigned long)(&__image_end) - | ||
95 | (unsigned long)(&__image_begin); | ||
96 | |||
97 | puts("zimage at: "); | ||
98 | puthex(zimage_start); | ||
99 | puts(" "); | ||
100 | puthex(zimage_size + zimage_start); | ||
101 | puts("\n"); | ||
102 | |||
103 | /* This area are prepared for mallocing when decompressing */ | ||
104 | free_mem_ptr = boot_heap_start; | ||
105 | free_mem_end_ptr = boot_heap_start + BOOT_HEAP_SIZE; | ||
106 | |||
107 | /* Display standard Linux/MIPS boot prompt */ | ||
108 | puts("Uncompressing Linux at load address "); | ||
109 | puthex(VMLINUX_LOAD_ADDRESS_ULL); | ||
110 | puts("\n"); | ||
111 | |||
112 | /* Decompress the kernel with according algorithm */ | ||
113 | __decompress((char *)zimage_start, zimage_size, 0, 0, | ||
114 | (void *)VMLINUX_LOAD_ADDRESS_ULL, 0, 0, error); | ||
115 | |||
116 | if (IS_ENABLED(CONFIG_MIPS_RAW_APPENDED_DTB) && | ||
117 | fdt_magic((void *)&__appended_dtb) == FDT_MAGIC) { | ||
118 | unsigned int image_size, dtb_size; | ||
119 | |||
120 | dtb_size = fdt_totalsize((void *)&__appended_dtb); | ||
121 | |||
122 | /* last four bytes is always image size in little endian */ | ||
123 | image_size = get_unaligned_le32((void *)&__image_end - 4); | ||
124 | |||
125 | /* copy dtb to where the booted kernel will expect it */ | ||
126 | memcpy((void *)VMLINUX_LOAD_ADDRESS_ULL + image_size, | ||
127 | __appended_dtb, dtb_size); | ||
128 | } | ||
129 | |||
130 | /* FIXME: should we flush cache here? */ | ||
131 | puts("Now, booting the kernel...\n"); | ||
132 | } | ||
diff --git a/arch/mips/boot/compressed/dummy.c b/arch/mips/boot/compressed/dummy.c new file mode 100644 index 000000000..31dbf45bf --- /dev/null +++ b/arch/mips/boot/compressed/dummy.c | |||
@@ -0,0 +1,4 @@ | |||
1 | int main(void) | ||
2 | { | ||
3 | return 0; | ||
4 | } | ||
diff --git a/arch/mips/boot/compressed/head.S b/arch/mips/boot/compressed/head.S new file mode 100644 index 000000000..409cb483a --- /dev/null +++ b/arch/mips/boot/compressed/head.S | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * This file is subject to the terms and conditions of the GNU General Public | ||
3 | * License. See the file "COPYING" in the main directory of this archive | ||
4 | * for more details. | ||
5 | * | ||
6 | * Copyright (C) 1994, 1995 Waldorf Electronics | ||
7 | * Written by Ralf Baechle and Andreas Busse | ||
8 | * Copyright (C) 1995 - 1999 Ralf Baechle | ||
9 | * Copyright (C) 1996 Paul M. Antoine | ||
10 | * Modified for DECStation and hence R3000 support by Paul M. Antoine | ||
11 | * Further modifications by David S. Miller and Harald Koerfgen | ||
12 | * Copyright (C) 1999 Silicon Graphics, Inc. | ||
13 | */ | ||
14 | |||
15 | #include <asm/asm.h> | ||
16 | #include <asm/regdef.h> | ||
17 | |||
18 | .set noreorder | ||
19 | .cprestore | ||
20 | LEAF(start) | ||
21 | start: | ||
22 | /* Save boot rom start args */ | ||
23 | move s0, a0 | ||
24 | move s1, a1 | ||
25 | move s2, a2 | ||
26 | move s3, a3 | ||
27 | |||
28 | /* Clear BSS */ | ||
29 | PTR_LA a0, _edata | ||
30 | PTR_LA a2, _end | ||
31 | 1: sw zero, 0(a0) | ||
32 | bne a2, a0, 1b | ||
33 | addiu a0, a0, 4 | ||
34 | |||
35 | PTR_LA a0, (.heap) /* heap address */ | ||
36 | PTR_LA sp, (.stack + 8192) /* stack address */ | ||
37 | |||
38 | PTR_LA ra, 2f | ||
39 | PTR_LA k0, decompress_kernel | ||
40 | jr k0 | ||
41 | nop | ||
42 | 2: | ||
43 | move a0, s0 | ||
44 | move a1, s1 | ||
45 | move a2, s2 | ||
46 | move a3, s3 | ||
47 | PTR_LI k0, KERNEL_ENTRY | ||
48 | jr k0 | ||
49 | nop | ||
50 | 3: | ||
51 | b 3b | ||
52 | nop | ||
53 | END(start) | ||
54 | |||
55 | .comm .heap,BOOT_HEAP_SIZE,4 | ||
56 | .comm .stack,4096*2,4 | ||
diff --git a/arch/mips/boot/compressed/ld.script b/arch/mips/boot/compressed/ld.script new file mode 100644 index 000000000..2ed08fbef --- /dev/null +++ b/arch/mips/boot/compressed/ld.script | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * ld.script for compressed kernel support of MIPS | ||
3 | * | ||
4 | * Copyright (C) 2009 Lemote Inc. | ||
5 | * Author: Wu Zhangjin <wuzhanjing@gmail.com> | ||
6 | * Copyright (C) 2010 "Wu Zhangjin" <wuzhanjing@gmail.com> | ||
7 | */ | ||
8 | |||
9 | OUTPUT_ARCH(mips) | ||
10 | ENTRY(start) | ||
11 | PHDRS { | ||
12 | text PT_LOAD FLAGS(7); /* RWX */ | ||
13 | } | ||
14 | SECTIONS | ||
15 | { | ||
16 | /* Text and read-only data */ | ||
17 | /* . = VMLINUZ_LOAD_ADDRESS; */ | ||
18 | .text : { | ||
19 | *(.text) | ||
20 | *(.rodata) | ||
21 | }: text | ||
22 | /* End of text section */ | ||
23 | |||
24 | /* Writable data */ | ||
25 | .data : { | ||
26 | *(.data) | ||
27 | /* Put the compressed image here */ | ||
28 | __image_begin = .; | ||
29 | *(.image) | ||
30 | __image_end = .; | ||
31 | CONSTRUCTORS | ||
32 | . = ALIGN(16); | ||
33 | } | ||
34 | __appended_dtb = .; | ||
35 | /* leave space for appended DTB */ | ||
36 | . += 0x100000; | ||
37 | |||
38 | _edata = .; | ||
39 | /* End of data section */ | ||
40 | |||
41 | /* BSS */ | ||
42 | .bss : { | ||
43 | *(.bss) | ||
44 | } | ||
45 | . = ALIGN(16); | ||
46 | _end = .; | ||
47 | |||
48 | /* Sections to be discarded */ | ||
49 | /DISCARD/ : { | ||
50 | *(.MIPS.options) | ||
51 | *(.options) | ||
52 | *(.pdr) | ||
53 | *(.reginfo) | ||
54 | *(.comment) | ||
55 | *(.note) | ||
56 | } | ||
57 | } | ||
diff --git a/arch/mips/boot/compressed/string.c b/arch/mips/boot/compressed/string.c new file mode 100644 index 000000000..0b593b709 --- /dev/null +++ b/arch/mips/boot/compressed/string.c | |||
@@ -0,0 +1,46 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * arch/mips/boot/compressed/string.c | ||
4 | * | ||
5 | * Very small subset of simple string routines | ||
6 | */ | ||
7 | |||
8 | #include <linux/compiler_attributes.h> | ||
9 | #include <linux/types.h> | ||
10 | |||
11 | void *memcpy(void *dest, const void *src, size_t n) | ||
12 | { | ||
13 | int i; | ||
14 | const char *s = src; | ||
15 | char *d = dest; | ||
16 | |||
17 | for (i = 0; i < n; i++) | ||
18 | d[i] = s[i]; | ||
19 | return dest; | ||
20 | } | ||
21 | |||
22 | void *memset(void *s, int c, size_t n) | ||
23 | { | ||
24 | int i; | ||
25 | char *ss = s; | ||
26 | |||
27 | for (i = 0; i < n; i++) | ||
28 | ss[i] = c; | ||
29 | return s; | ||
30 | } | ||
31 | |||
32 | void * __weak memmove(void *dest, const void *src, size_t n) | ||
33 | { | ||
34 | unsigned int i; | ||
35 | const char *s = src; | ||
36 | char *d = dest; | ||
37 | |||
38 | if ((uintptr_t)dest < (uintptr_t)src) { | ||
39 | for (i = 0; i < n; i++) | ||
40 | d[i] = s[i]; | ||
41 | } else { | ||
42 | for (i = n; i > 0; i--) | ||
43 | d[i - 1] = s[i - 1]; | ||
44 | } | ||
45 | return dest; | ||
46 | } | ||
diff --git a/arch/mips/boot/compressed/uart-16550.c b/arch/mips/boot/compressed/uart-16550.c new file mode 100644 index 000000000..aee8d7b8f --- /dev/null +++ b/arch/mips/boot/compressed/uart-16550.c | |||
@@ -0,0 +1,64 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | /* | ||
3 | * 16550 compatible uart based serial debug support for zboot | ||
4 | */ | ||
5 | |||
6 | #include <linux/types.h> | ||
7 | #include <linux/serial_reg.h> | ||
8 | |||
9 | #include <asm/addrspace.h> | ||
10 | |||
11 | #if defined(CONFIG_MACH_LOONGSON64) || defined(CONFIG_MIPS_MALTA) | ||
12 | #define UART_BASE 0x1fd003f8 | ||
13 | #define PORT(offset) (CKSEG1ADDR(UART_BASE) + (offset)) | ||
14 | #endif | ||
15 | |||
16 | #ifdef CONFIG_AR7 | ||
17 | #include <ar7.h> | ||
18 | #define PORT(offset) (CKSEG1ADDR(AR7_REGS_UART0) + (4 * offset)) | ||
19 | #endif | ||
20 | |||
21 | #ifdef CONFIG_MACH_INGENIC | ||
22 | #define INGENIC_UART0_BASE_ADDR 0x10030000 | ||
23 | #define PORT(offset) (CKSEG1ADDR(INGENIC_UART0_BASE_ADDR) + (4 * offset)) | ||
24 | #endif | ||
25 | |||
26 | #ifdef CONFIG_CPU_XLR | ||
27 | #define UART0_BASE 0x1EF14000 | ||
28 | #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset)) | ||
29 | #define IOTYPE unsigned int | ||
30 | #endif | ||
31 | |||
32 | #ifdef CONFIG_CPU_XLP | ||
33 | #define UART0_BASE 0x18030100 | ||
34 | #define PORT(offset) (CKSEG1ADDR(UART0_BASE) + (4 * offset)) | ||
35 | #define IOTYPE unsigned int | ||
36 | #endif | ||
37 | |||
38 | #ifndef IOTYPE | ||
39 | #define IOTYPE char | ||
40 | #endif | ||
41 | |||
42 | #ifndef PORT | ||
43 | #error please define the serial port address for your own machine | ||
44 | #endif | ||
45 | |||
46 | static inline unsigned int serial_in(int offset) | ||
47 | { | ||
48 | return *((volatile IOTYPE *)PORT(offset)) & 0xFF; | ||
49 | } | ||
50 | |||
51 | static inline void serial_out(int offset, int value) | ||
52 | { | ||
53 | *((volatile IOTYPE *)PORT(offset)) = value & 0xFF; | ||
54 | } | ||
55 | |||
56 | void putc(char c) | ||
57 | { | ||
58 | int timeout = 1000000; | ||
59 | |||
60 | while (((serial_in(UART_LSR) & UART_LSR_THRE) == 0) && (timeout-- > 0)) | ||
61 | ; | ||
62 | |||
63 | serial_out(UART_TX, c); | ||
64 | } | ||
diff --git a/arch/mips/boot/compressed/uart-alchemy.c b/arch/mips/boot/compressed/uart-alchemy.c new file mode 100644 index 000000000..8ec63011e --- /dev/null +++ b/arch/mips/boot/compressed/uart-alchemy.c | |||
@@ -0,0 +1,7 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #include <asm/mach-au1x00/au1000.h> | ||
3 | |||
4 | void putc(char c) | ||
5 | { | ||
6 | alchemy_uart_putchar(AU1000_UART0_PHYS_ADDR, c); | ||
7 | } | ||
diff --git a/arch/mips/boot/compressed/uart-prom.c b/arch/mips/boot/compressed/uart-prom.c new file mode 100644 index 000000000..a8a0a32e0 --- /dev/null +++ b/arch/mips/boot/compressed/uart-prom.c | |||
@@ -0,0 +1,7 @@ | |||
1 | // SPDX-License-Identifier: GPL-2.0 | ||
2 | #include <asm/setup.h> | ||
3 | |||
4 | void putc(char c) | ||
5 | { | ||
6 | prom_putchar(c); | ||
7 | } | ||