Skip to content

Commit 70fac51

Browse files
committed
unicore32 additional architecture files: boot process
This patch implements booting process, including uncompression process. Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Reviewed-by: Arnd Bergmann <arnd@arndb.de>
1 parent 96cf518 commit 70fac51

7 files changed

Lines changed: 546 additions & 0 deletions

File tree

‎arch/unicore32/boot/Makefile‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# arch/unicore32/boot/Makefile
3+
#
4+
# This file is included by the global makefile so that you can add your own
5+
# architecture-specific flags and dependencies.
6+
#
7+
# This file is subject to the terms and conditions of the GNU General Public
8+
# License. See the file "COPYING" in the main directory of this archive
9+
# for more details.
10+
#
11+
# Copyright (C) 2001~2010 GUAN Xue-tao
12+
#
13+
14+
MKIMAGE := $(srctree)/scripts/mkuboot.sh
15+
16+
targets := Image zImage uImage
17+
18+
$(obj)/Image: vmlinux FORCE
19+
$(call if_changed,objcopy)
20+
@echo ' Kernel: $@ is ready'
21+
22+
$(obj)/compressed/vmlinux: $(obj)/Image FORCE
23+
$(Q)$(MAKE) $(build)=$(obj)/compressed $@
24+
25+
$(obj)/zImage: $(obj)/compressed/vmlinux FORCE
26+
$(call if_changed,objcopy)
27+
@echo ' Kernel: $@ is ready'
28+
29+
quiet_cmd_uimage = UIMAGE $@
30+
cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A unicore -O linux -T kernel \
31+
-C none -a $(LOADADDR) -e $(STARTADDR) \
32+
-n 'Linux-$(KERNELRELEASE)' -d $< $@
33+
34+
$(obj)/uImage: LOADADDR=0x0
35+
36+
$(obj)/uImage: STARTADDR=$(LOADADDR)
37+
38+
$(obj)/uImage: $(obj)/zImage FORCE
39+
$(call if_changed,uimage)
40+
@echo ' Image $@ is ready'
41+
42+
PHONY += initrd FORCE
43+
initrd:
44+
@test "$(INITRD)" != "" || \
45+
(echo You must specify INITRD; exit -1)
46+
47+
subdir- := compressed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# linux/arch/unicore32/boot/compressed/Makefile
3+
#
4+
# create a compressed vmlinuz image from the original vmlinux
5+
#
6+
# This file is subject to the terms and conditions of the GNU General Public
7+
# License. See the file "COPYING" in the main directory of this archive
8+
# for more details.
9+
#
10+
# Copyright (C) 2001~2010 GUAN Xue-tao
11+
#
12+
13+
EXTRA_CFLAGS := -fpic -fno-builtin
14+
EXTRA_AFLAGS := -Wa,-march=all
15+
16+
OBJS := misc.o
17+
18+
# font.c and font.o
19+
CFLAGS_font.o := -Dstatic=
20+
$(obj)/font.c: $(srctree)/drivers/video/console/font_8x8.c
21+
$(call cmd,shipped)
22+
23+
# piggy.S and piggy.o
24+
suffix_$(CONFIG_KERNEL_GZIP) := gzip
25+
suffix_$(CONFIG_KERNEL_BZIP2) := bz2
26+
suffix_$(CONFIG_KERNEL_LZO) := lzo
27+
suffix_$(CONFIG_KERNEL_LZMA) := lzma
28+
29+
$(obj)/piggy.$(suffix_y): $(obj)/../Image FORCE
30+
$(call if_changed,$(suffix_y))
31+
32+
SEDFLAGS_piggy = s/DECOMP_SUFFIX/$(suffix_y)/
33+
$(obj)/piggy.S: $(obj)/piggy.S.in
34+
@sed "$(SEDFLAGS_piggy)" < $< > $@
35+
36+
$(obj)/piggy.o: $(obj)/piggy.$(suffix_y) $(obj)/piggy.S FORCE
37+
38+
targets := vmlinux vmlinux.lds font.o font.c head.o misc.o \
39+
piggy.$(suffix_y) piggy.o piggy.S \
40+
41+
# Make sure files are removed during clean
42+
extra-y += piggy.gzip piggy.bz2 piggy.lzo piggy.lzma
43+
44+
# ?
45+
LDFLAGS_vmlinux += -p
46+
# Report unresolved symbol references
47+
LDFLAGS_vmlinux += --no-undefined
48+
# Delete all temporary local symbols
49+
LDFLAGS_vmlinux += -X
50+
# Next argument is a linker script
51+
LDFLAGS_vmlinux += -T
52+
53+
# For uidivmod
54+
$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/head.o $(obj)/piggy.o \
55+
$(obj)/misc.o FORCE
56+
$(call if_changed,ld)
57+
@:
58+
59+
# We now have a PIC decompressor implementation. Decompressors running
60+
# from RAM should not define ZTEXTADDR. Decompressors running directly
61+
# from ROM or Flash must define ZTEXTADDR (preferably via the config)
62+
ZTEXTADDR := 0
63+
ZBSSADDR := ALIGN(4)
64+
65+
SEDFLAGS_lds = s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
66+
$(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in arch/unicore32/boot/Makefile $(KCONFIG_CONFIG)
67+
@sed "$(SEDFLAGS_lds)" < $< > $@
68+
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
/*
2+
* linux/arch/unicore32/boot/compressed/head.S
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
#include <linux/linkage.h>
13+
#include <mach/memory.h>
14+
15+
#define csub cmpsub
16+
#define cand cmpand
17+
#define nop8 nop; nop; nop; nop; nop; nop; nop; nop
18+
19+
.section ".start", #alloc, #execinstr
20+
.text
21+
start:
22+
.type start,#function
23+
24+
/* Initialize ASR, PRIV mode and INTR off */
25+
mov r0, #0xD3
26+
mov.a asr, r0
27+
28+
adr r0, LC0
29+
ldm (r1, r2, r3, r5, r6, r7, r8), [r0]+
30+
ldw sp, [r0+], #28
31+
sub.a r0, r0, r1 @ calculate the delta offset
32+
33+
/*
34+
* if delta is zero, we are running at the address
35+
* we were linked at.
36+
*/
37+
beq not_relocated
38+
39+
/*
40+
* We're running at a different address. We need to fix
41+
* up various pointers:
42+
* r5 - zImage base address (_start)
43+
* r7 - GOT start
44+
* r8 - GOT end
45+
*/
46+
add r5, r5, r0
47+
add r7, r7, r0
48+
add r8, r8, r0
49+
50+
/*
51+
* we need to fix up pointers into the BSS region.
52+
* r2 - BSS start
53+
* r3 - BSS end
54+
* sp - stack pointer
55+
*/
56+
add r2, r2, r0
57+
add r3, r3, r0
58+
add sp, sp, r0
59+
60+
/*
61+
* Relocate all entries in the GOT table.
62+
* This fixes up the C references.
63+
* r7 - GOT start
64+
* r8 - GOT end
65+
*/
66+
1001: ldw r1, [r7+], #0
67+
add r1, r1, r0
68+
stw.w r1, [r7]+, #4
69+
csub.a r7, r8
70+
bub 1001b
71+
72+
not_relocated:
73+
/*
74+
* Clear BSS region.
75+
* r2 - BSS start
76+
* r3 - BSS end
77+
*/
78+
mov r0, #0
79+
1002: stw.w r0, [r2]+, #4
80+
csub.a r2, r3
81+
bub 1002b
82+
83+
/*
84+
* Turn on the cache.
85+
*/
86+
mov r0, #0
87+
movc p0.c5, r0, #28 @ cache invalidate all
88+
nop8
89+
movc p0.c6, r0, #6 @ tlb invalidate all
90+
nop8
91+
92+
mov r0, #0x1c @ en icache and wb dcache
93+
movc p0.c1, r0, #0
94+
nop8
95+
96+
/*
97+
* Set up some pointers, for starting decompressing.
98+
*/
99+
100+
mov r1, sp @ malloc space above stack
101+
add r2, sp, #0x10000 @ 64k max
102+
103+
/*
104+
* Check to see if we will overwrite ourselves.
105+
* r4 = final kernel address
106+
* r5 = start of this image
107+
* r6 = size of decompressed image
108+
* r2 = end of malloc space (and therefore this image)
109+
* We basically want:
110+
* r4 >= r2 -> OK
111+
* r4 + image length <= r5 -> OK
112+
*/
113+
ldw r4, =KERNEL_IMAGE_START
114+
csub.a r4, r2
115+
bea wont_overwrite
116+
add r0, r4, r6
117+
csub.a r0, r5
118+
beb wont_overwrite
119+
120+
/*
121+
* If overwrite, just print error message
122+
*/
123+
b __error_overwrite
124+
125+
/*
126+
* We're not in danger of overwriting ourselves.
127+
* Do this the simple way.
128+
*/
129+
wont_overwrite:
130+
/*
131+
* decompress_kernel:
132+
* r0: output_start
133+
* r1: free_mem_ptr_p
134+
* r2: free_mem_ptr_end_p
135+
*/
136+
mov r0, r4
137+
b.l decompress_kernel @ C functions
138+
139+
/*
140+
* Clean and flush the cache to maintain consistency.
141+
*/
142+
mov r0, #0
143+
movc p0.c5, r0, #14 @ flush dcache
144+
nop8
145+
movc p0.c5, r0, #20 @ icache invalidate all
146+
nop8
147+
148+
/*
149+
* Turn off the Cache and MMU.
150+
*/
151+
mov r0, #0 @ disable i/d cache and MMU
152+
movc p0.c1, r0, #0
153+
nop8
154+
155+
mov r0, #0 @ must be zero
156+
ldw r4, =KERNEL_IMAGE_START
157+
mov pc, r4 @ call kernel
158+
159+
160+
.align 2
161+
.type LC0, #object
162+
LC0: .word LC0 @ r1
163+
.word __bss_start @ r2
164+
.word _end @ r3
165+
.word _start @ r5
166+
.word _image_size @ r6
167+
.word _got_start @ r7
168+
.word _got_end @ r8
169+
.word decompress_stack_end @ sp
170+
.size LC0, . - LC0
171+
172+
print_string:
173+
#ifdef CONFIG_DEBUG_OCD
174+
2001: ldb.w r1, [r0]+, #1
175+
csub.a r1, #0
176+
bne 2002f
177+
mov pc, lr
178+
2002:
179+
movc r2, p1.c0, #0
180+
cand.a r2, #2
181+
bne 2002b
182+
movc p1.c1, r1, #1
183+
csub.a r1, #'\n'
184+
cmoveq r1, #'\r'
185+
beq 2002b
186+
b 2001b
187+
#else
188+
mov pc, lr
189+
#endif
190+
191+
__error_overwrite:
192+
adr r0, str_error
193+
b.l print_string
194+
2001: nop8
195+
b 2001b
196+
str_error: .asciz "\nError: Kernel address OVERWRITE\n"
197+
.align
198+
199+
.ltorg
200+
201+
.align 4
202+
.section ".stack", "aw", %nobits
203+
decompress_stack: .space 4096
204+
decompress_stack_end:

0 commit comments

Comments
 (0)