Skip to content

Commit d86bfb1

Browse files
Barry Songvapier
authored andcommitted
Blackfin: initial XIP support
Signed-off-by: Barry Song <barry.song@analog.com> Signed-off-by: Mike Frysinger <vapier@gentoo.org>
1 parent aad16f3 commit d86bfb1

13 files changed

Lines changed: 160 additions & 29 deletions

File tree

‎arch/blackfin/Kconfig‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ config BLACKFIN
2626
select HAVE_FUNCTION_GRAPH_TRACER
2727
select HAVE_FUNCTION_TRACER
2828
select HAVE_IDE
29-
select HAVE_KERNEL_GZIP
30-
select HAVE_KERNEL_BZIP2
31-
select HAVE_KERNEL_LZMA
29+
select HAVE_KERNEL_GZIP if RAMKERNEL
30+
select HAVE_KERNEL_BZIP2 if RAMKERNEL
31+
select HAVE_KERNEL_LZMA if RAMKERNEL
3232
select HAVE_OPROFILE
3333
select ARCH_WANT_OPTIONAL_GPIOLIB
3434

@@ -407,10 +407,18 @@ config BOOT_LOAD
407407
config ROM_BASE
408408
hex "Kernel ROM Base"
409409
depends on ROMKERNEL
410-
default "0x20040000"
410+
default "0x20040040"
411411
range 0x20000000 0x20400000 if !(BF54x || BF561)
412412
range 0x20000000 0x30000000 if (BF54x || BF561)
413413
help
414+
Make sure your ROM base does not include any file-header
415+
information that is prepended to the kernel.
416+
417+
For example, the bootable U-Boot format (created with
418+
mkimage) has a 64 byte header (0x40). So while the image
419+
you write to flash might start at say 0x20080000, you have
420+
to add 0x40 to get the kernel's ROM base as it will come
421+
after the header.
414422

415423
comment "Clock/PLL Setup"
416424

‎arch/blackfin/Makefile‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ OBJCOPYFLAGS := -O binary -R .note -R .comment -S
1414
GZFLAGS := -9
1515

1616
KBUILD_CFLAGS += $(call cc-option,-mno-fdpic)
17+
ifeq ($(CONFIG_ROMKERNEL),y)
18+
KBUILD_CFLAGS += -mlong-calls
19+
endif
1720
KBUILD_AFLAGS += $(call cc-option,-mno-fdpic)
1821
CFLAGS_MODULE += -mlong-calls
1922
LDFLAGS_MODULE += -m elf32bfin
@@ -138,7 +141,7 @@ archclean:
138141

139142
INSTALL_PATH ?= /tftpboot
140143
boot := arch/$(ARCH)/boot
141-
BOOT_TARGETS = vmImage vmImage.bin vmImage.bz2 vmImage.gz vmImage.lzma
144+
BOOT_TARGETS = vmImage vmImage.bin vmImage.bz2 vmImage.gz vmImage.lzma vmImage.xip
142145
PHONY += $(BOOT_TARGETS) install
143146
KBUILD_IMAGE := $(boot)/vmImage
144147

@@ -156,6 +159,7 @@ define archhelp
156159
echo ' vmImage.bz2 - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage.bz2)'
157160
echo '* vmImage.gz - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage.gz)'
158161
echo ' vmImage.lzma - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage.lzma)'
162+
echo ' vmImage.xip - XIP Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage.xip)'
159163
echo ' install - Install kernel using'
160164
echo ' (your) ~/bin/$(INSTALLKERNEL) or'
161165
echo ' (distribution) PATH: $(INSTALLKERNEL) or'

‎arch/blackfin/boot/Makefile‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
MKIMAGE := $(srctree)/scripts/mkuboot.sh
1010

11-
targets := vmImage vmImage.bin vmImage.bz2 vmImage.gz vmImage.lzma
12-
extra-y += vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma
11+
targets := vmImage vmImage.bin vmImage.bz2 vmImage.gz vmImage.lzma vmImage.xip
12+
extra-y += vmlinux.bin vmlinux.bin.gz vmlinux.bin.bz2 vmlinux.bin.lzma vmlinux.bin.xip
13+
14+
UIMAGE_OPTS-y :=
15+
UIMAGE_OPTS-$(CONFIG_RAMKERNEL) += -a $(CONFIG_BOOT_LOAD)
16+
UIMAGE_OPTS-$(CONFIG_ROMKERNEL) += -a $(CONFIG_ROM_BASE) -x
1317

1418
quiet_cmd_uimage = UIMAGE $@
1519
cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(ARCH) -O linux -T kernel \
16-
-C $(2) -n '$(MACHINE)-$(KERNELRELEASE)' -a $(CONFIG_BOOT_LOAD) \
20+
-C $(2) -n '$(MACHINE)-$(KERNELRELEASE)' \
1721
-e $(shell $(NM) vmlinux | awk '$$NF == "__start" {print $$1}') \
18-
-d $< $@
22+
$(UIMAGE_OPTS-y) -d $< $@
1923

2024
$(obj)/vmlinux.bin: vmlinux FORCE
2125
$(call if_changed,objcopy)
@@ -29,6 +33,12 @@ $(obj)/vmlinux.bin.bz2: $(obj)/vmlinux.bin FORCE
2933
$(obj)/vmlinux.bin.lzma: $(obj)/vmlinux.bin FORCE
3034
$(call if_changed,lzma)
3135

36+
# The mkimage tool wants 64bytes prepended to the image
37+
quiet_cmd_mk_bin_xip = BIN $@
38+
cmd_mk_bin_xip = ( printf '%64s' | tr ' ' '\377' ; cat $< ) > $@
39+
$(obj)/vmlinux.bin.xip: $(obj)/vmlinux.bin FORCE
40+
$(call if_changed,mk_bin_xip)
41+
3242
$(obj)/vmImage.bin: $(obj)/vmlinux.bin
3343
$(call if_changed,uimage,none)
3444

@@ -41,10 +51,15 @@ $(obj)/vmImage.gz: $(obj)/vmlinux.bin.gz
4151
$(obj)/vmImage.lzma: $(obj)/vmlinux.bin.lzma
4252
$(call if_changed,uimage,lzma)
4353

54+
$(obj)/vmImage.xip: $(obj)/vmlinux.bin.xip
55+
$(call if_changed,uimage,none)
56+
4457
suffix-y := bin
4558
suffix-$(CONFIG_KERNEL_GZIP) := gz
4659
suffix-$(CONFIG_KERNEL_BZIP2) := bz2
4760
suffix-$(CONFIG_KERNEL_LZMA) := lzma
61+
suffix-$(CONFIG_ROMKERNEL) := xip
62+
4863
$(obj)/vmImage: $(obj)/vmImage.$(suffix-y)
4964
@ln -sf $(notdir $<) $@
5065

‎arch/blackfin/include/asm/context.S‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,13 @@
374374

375375
(R7:0, P5:0) = [SP++];
376376
.endm
377+
378+
.macro pseudo_long_call func:req, scratch:req
379+
#ifdef CONFIG_ROMKERNEL
380+
\scratch\().l = \func;
381+
\scratch\().h = \func;
382+
call (\scratch);
383+
#else
384+
call \func;
385+
#endif
386+
.endm

‎arch/blackfin/include/asm/sections.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ extern unsigned long memory_start, memory_end, physical_mem_end;
2121
extern char _stext_l1[], _etext_l1[], _text_l1_lma[], __weak _text_l1_len[];
2222
extern char _sdata_l1[], _edata_l1[], _sbss_l1[], _ebss_l1[],
2323
_data_l1_lma[], __weak _data_l1_len[];
24+
#ifdef CONFIG_ROMKERNEL
25+
extern char _data_lma[], _data_len[], _sinitdata[], _einitdata[], _init_data_lma[], _init_data_len[];
26+
#endif
2427
extern char _sdata_b_l1[], _edata_b_l1[], _sbss_b_l1[], _ebss_b_l1[],
2528
_data_b_l1_lma[], __weak _data_b_l1_len[];
2629
extern char _stext_l2[], _etext_l2[], _sdata_l2[], _edata_l2[],

‎arch/blackfin/kernel/cplb-mpu/cplbinit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ void __init generate_cplb_tables_cpu(unsigned int cpu)
6464
icplb_tbl[cpu][i_i++].data = i_data | (addr == 0 ? CPLB_USER_RD : 0);
6565
}
6666

67+
#ifdef CONFIG_ROMKERNEL
68+
/* Cover kernel XIP flash area */
69+
addr = CONFIG_ROM_BASE & ~(4 * 1024 * 1024 - 1);
70+
dcplb_tbl[cpu][i_d].addr = addr;
71+
dcplb_tbl[cpu][i_d++].data = d_data | CPLB_USER_RD;
72+
icplb_tbl[cpu][i_i].addr = addr;
73+
icplb_tbl[cpu][i_i++].data = i_data | CPLB_USER_RD;
74+
#endif
75+
6776
/* Cover L1 memory. One 4M area for code and data each is enough. */
6877
#if L1_DATA_A_LENGTH > 0 || L1_DATA_B_LENGTH > 0
6978
dcplb_tbl[cpu][i_d].addr = get_l1_data_a_start_cpu(cpu);

‎arch/blackfin/kernel/cplb-nompu/cplbinit.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ void __init generate_cplb_tables_cpu(unsigned int cpu)
5656
i_tbl[i_i++].data = SDRAM_IGENERIC | PAGE_SIZE_4MB;
5757
}
5858

59+
#ifdef CONFIG_ROMKERNEL
60+
/* Cover kernel XIP flash area */
61+
addr = CONFIG_ROM_BASE & ~(4 * 1024 * 1024 - 1);
62+
d_tbl[i_d].addr = addr;
63+
d_tbl[i_d++].data = SDRAM_DGENERIC | PAGE_SIZE_4MB;
64+
i_tbl[i_i].addr = addr;
65+
i_tbl[i_i++].data = SDRAM_IGENERIC | PAGE_SIZE_4MB;
66+
#endif
67+
5968
/* Cover L1 memory. One 4M area for code and data each is enough. */
6069
if (cpu == 0) {
6170
if (L1_DATA_A_LENGTH || L1_DATA_B_LENGTH) {

‎arch/blackfin/kernel/entry.S‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ENTRY(_ret_from_fork)
4444
sti r4;
4545
#endif /* CONFIG_IPIPE */
4646
SP += -12;
47-
call _schedule_tail;
47+
pseudo_long_call _schedule_tail, p5;
4848
SP += 12;
4949
r0 = [sp + PT_IPEND];
5050
cc = bittst(r0,1);
@@ -79,7 +79,7 @@ ENTRY(_sys_vfork)
7979
r0 += 24;
8080
[--sp] = rets;
8181
SP += -12;
82-
call _bfin_vfork;
82+
pseudo_long_call _bfin_vfork, p2;
8383
SP += 12;
8484
rets = [sp++];
8585
rts;
@@ -90,7 +90,7 @@ ENTRY(_sys_clone)
9090
r0 += 24;
9191
[--sp] = rets;
9292
SP += -12;
93-
call _bfin_clone;
93+
pseudo_long_call _bfin_clone, p2;
9494
SP += 12;
9595
rets = [sp++];
9696
rts;
@@ -101,7 +101,7 @@ ENTRY(_sys_rt_sigreturn)
101101
r0 += 24;
102102
[--sp] = rets;
103103
SP += -12;
104-
call _do_rt_sigreturn;
104+
pseudo_long_call _do_rt_sigreturn, p2;
105105
SP += 12;
106106
rets = [sp++];
107107
rts;

‎arch/blackfin/kernel/setup.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ void __init bfin_relocate_l1_mem(void)
220220
memcpy(_stext_l2, _l2_lma, l2_len);
221221
}
222222

223+
#ifdef CONFIG_ROMKERNEL
224+
void __init bfin_relocate_xip_data(void)
225+
{
226+
early_shadow_stamp();
227+
228+
memcpy(_sdata, _data_lma, (unsigned long)_data_len - THREAD_SIZE + sizeof(struct thread_info));
229+
memcpy(_sinitdata, _init_data_lma, (unsigned long)_init_data_len);
230+
}
231+
#endif
232+
223233
/* add_memory_region to memmap */
224234
static void __init add_memory_region(unsigned long long start,
225235
unsigned long long size, int type)
@@ -504,7 +514,7 @@ static __init void memory_setup(void)
504514
#endif
505515
unsigned long max_mem;
506516

507-
_rambase = (unsigned long)_stext;
517+
_rambase = CONFIG_BOOT_LOAD;
508518
_ramstart = (unsigned long)_end;
509519

510520
if (DMA_UNCACHED_REGION > (_ramend - _ramstart)) {
@@ -1261,8 +1271,8 @@ static int show_cpuinfo(struct seq_file *m, void *v)
12611271
seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
12621272
physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
12631273
seq_printf(m, "kernel memory\t: %d kB (0x%p -> 0x%p)\n",
1264-
((int)memory_end - (int)_stext) >> 10,
1265-
_stext,
1274+
((int)memory_end - (int)_rambase) >> 10,
1275+
(void *)_rambase,
12661276
(void *)memory_end);
12671277
seq_printf(m, "\n");
12681278

‎arch/blackfin/kernel/vmlinux.lds.S‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ _jiffies = _jiffies_64;
1515

1616
SECTIONS
1717
{
18+
#ifdef CONFIG_RAMKERNEL
1819
. = CONFIG_BOOT_LOAD;
20+
#else
21+
. = CONFIG_ROM_BASE;
22+
#endif
23+
1924
/* Neither the text, ro_data or bss section need to be aligned
2025
* So pack them back to back
2126
*/
@@ -31,6 +36,12 @@ SECTIONS
3136
LOCK_TEXT
3237
IRQENTRY_TEXT
3338
KPROBES_TEXT
39+
#ifdef CONFIG_ROMKERNEL
40+
__sinittext = .;
41+
INIT_TEXT
42+
__einittext = .;
43+
EXIT_TEXT
44+
#endif
3445
*(.text.*)
3546
*(.fixup)
3647

@@ -50,8 +61,14 @@ SECTIONS
5061

5162
/* Just in case the first read only is a 32-bit access */
5263
RO_DATA(4)
64+
__rodata_end = .;
5365

66+
#ifdef CONFIG_ROMKERNEL
67+
. = CONFIG_BOOT_LOAD;
68+
.bss : AT(__rodata_end)
69+
#else
5470
.bss :
71+
#endif
5572
{
5673
. = ALIGN(4);
5774
___bss_start = .;
@@ -67,7 +84,11 @@ SECTIONS
6784
___bss_stop = .;
6885
}
6986

87+
#if defined(CONFIG_ROMKERNEL)
88+
.data : AT(LOADADDR(.bss) + SIZEOF(.bss))
89+
#else
7090
.data :
91+
#endif
7192
{
7293
__sdata = .;
7394
/* This gets done first, so the glob doesn't suck it in */
@@ -94,6 +115,8 @@ SECTIONS
94115

95116
__edata = .;
96117
}
118+
__data_lma = LOADADDR(.data);
119+
__data_len = SIZEOF(.data);
97120

98121
/* The init section should be last, so when we free it, it goes into
99122
* the general memory pool, and (hopefully) will decrease fragmentation
@@ -103,6 +126,7 @@ SECTIONS
103126
. = ALIGN(PAGE_SIZE);
104127
___init_begin = .;
105128

129+
#ifdef CONFIG_RAMKERNEL
106130
INIT_TEXT_SECTION(PAGE_SIZE)
107131

108132
/* We have to discard exit text and such at runtime, not link time, to
@@ -125,6 +149,35 @@ SECTIONS
125149
}
126150

127151
.text_l1 L1_CODE_START : AT(LOADADDR(.exit.data) + SIZEOF(.exit.data))
152+
#else
153+
.init.data : AT(__data_lma + __data_len)
154+
{
155+
__sinitdata = .;
156+
INIT_DATA
157+
INIT_SETUP(16)
158+
INIT_CALLS
159+
CON_INITCALL
160+
SECURITY_INITCALL
161+
INIT_RAM_FS
162+
163+
. = ALIGN(4);
164+
___per_cpu_load = .;
165+
___per_cpu_start = .;
166+
*(.data.percpu.first)
167+
*(.data.percpu.page_aligned)
168+
*(.data.percpu)
169+
*(.data.percpu.shared_aligned)
170+
___per_cpu_end = .;
171+
172+
EXIT_DATA
173+
__einitdata = .;
174+
}
175+
__init_data_lma = LOADADDR(.init.data);
176+
__init_data_len = SIZEOF(.init.data);
177+
__init_data_end = .;
178+
179+
.text_l1 L1_CODE_START : AT(__init_data_lma + __init_data_len)
180+
#endif
128181
{
129182
. = ALIGN(4);
130183
__stext_l1 = .;
@@ -205,7 +258,11 @@ SECTIONS
205258
/* Force trailing alignment of our init section so that when we
206259
* free our init memory, we don't leave behind a partial page.
207260
*/
261+
#ifdef CONFIG_RAMKERNEL
208262
. = __l2_lma + __l2_len;
263+
#else
264+
. = __init_data_end;
265+
#endif
209266
. = ALIGN(PAGE_SIZE);
210267
___init_end = .;
211268

0 commit comments

Comments
 (0)