diff options
author | Jens Wiklander <jens.wiklander@linaro.org> | 2014-12-04 08:04:01 +0100 |
---|---|---|
committer | Jens Wiklander <jens.wiklander@linaro.org> | 2014-12-16 07:52:30 +0100 |
commit | 8f7de3fc92dbdfdc217b83403c64abc0bafb5d31 (patch) | |
tree | 24bb0f98461c23d1449a99d349470f87f1dc5b1f /core/arch/arm32 | |
parent | 467cf45c9e7e5c5d651837ca10f219fe7f008217 (diff) |
plat-vexpress: linking supports pagable tee.bin
* Adds scripts to create a pagable tee.bin
* Updates link script and link.mk to support pagable tee.bin
* Binary format of tee.bin is changed from a raw format to a header
followed by the binary data as described by the header. This requires
updates in ARM-TF OP-TEE Dispatcher and QEMU virt bios.
fvp:
* Changes OP-TEE load address to start of TZDRAM_BASE
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Diffstat (limited to 'core/arch/arm32')
-rw-r--r-- | core/arch/arm32/plat-vexpress/kern.ld.S | 145 | ||||
-rw-r--r-- | core/arch/arm32/plat-vexpress/link.mk | 135 | ||||
-rw-r--r-- | core/arch/arm32/plat-vexpress/platform_config.h | 2 |
3 files changed, 231 insertions, 51 deletions
diff --git a/core/arch/arm32/plat-vexpress/kern.ld.S b/core/arch/arm32/plat-vexpress/kern.ld.S index ee1449e..e1714ae 100644 --- a/core/arch/arm32/plat-vexpress/kern.ld.S +++ b/core/arch/arm32/plat-vexpress/kern.ld.S @@ -64,7 +64,15 @@ SECTIONS KEEP(*(.text.boot.vectab1)) KEEP(*(.text.boot.vectab2)) KEEP(*(.text.boot)) - *(.text* .sram.text.glue_7* .gnu.linkonce.t.*) + +#ifdef CFG_WITH_PAGER + *(.text) +/* Include list of sections needed for paging */ +#include <text_unpaged.ld.S> +#else + *(.text .text.*) +#endif + *(.sram.text.glue_7* .gnu.linkonce.t.*) __text_end = .; } @@ -96,19 +104,26 @@ SECTIONS .plt : { *(.plt) } /* .ARM.exidx is sorted, so has to go in its own output section. */ - __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } - __exidx_end = .; + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + __exidx_end = .; + } .rodata : ALIGN(4) { __rodata_start = .; - *(.rodata .rodata.* .gnu.linkonce.r.*) - . = ALIGN(4); + *(.gnu.linkonce.r.*) +#ifdef CFG_WITH_PAGER + *(.rodata) +#include <rodata_unpaged.ld.S> +#else + *(.rodata .rodata.*) + . = ALIGN(4); __start_ta_head_section = . ; - *(ta_head_section) + KEEP(*(ta_head_section)) __stop_ta_head_section = . ; - +#endif . = ALIGN(4); __rodata_end = .; } @@ -120,6 +135,7 @@ SECTIONS /* in one segment binaries, the rom data address is on top of the ram data address */ __data_start = .; *(.data .data.* .gnu.linkonce.d.*) + . = ALIGN(4); } .ctors : ALIGN(4) { @@ -145,13 +161,20 @@ SECTIONS . = ALIGN(4); __bss_end = .; } - __heap2_start = .; - /* - * We're keeping track of the padding added before the .nozi - * section so we can do something useful with this otherwise wasted - * memory. - */ + .heap1 (NOLOAD) : { + /* + * We're keeping track of the padding added before the + * .nozi section so we can do something useful with + * this otherwise wasted memory. + */ + __heap1_start = .; +#ifndef CFG_WITH_PAGER + . += HEAP_SIZE; +#endif + . = ALIGN(16 * 1024); + __heap1_end = .; + } /* * Uninitialized data that shouldn't be zero initialized at @@ -159,43 +182,89 @@ SECTIONS * * L1 mmu table requires 16 KiB alignment */ - .nozi : ALIGN(16 * 1024) { - __heap2_end = .; + .nozi (NOLOAD) : ALIGN(16 * 1024) { KEEP(*(.nozi .nozi.*)) } - -#if PLATFORM_FLAVOR_IS(fvp) - /* - * The base address of the coherent memory section must be - * page-aligned (4K) to guarantee that the coherent data are stored - * on their own pages and are not mixed with normal data. This is - * required to set up the correct memory attributes for the - * coherent data page tables. - */ - coherent_ram (NOLOAD) : ALIGN(4096) { - __COHERENT_RAM_START__ = .; - *(tzfw_coherent_mem) - __COHERENT_RAM_END_UNALIGNED__ = .; +#ifdef CFG_WITH_PAGER + .heap2 (NOLOAD) : { + __heap2_start = .; /* - * Memory page(s) mapped to this section will be marked as - * device memory. No other unexpected data must creep in. - * Ensure the rest of the current memory page is unused. + * Reserve additional memory for heap, the total should + * be at least HEAP_SIZE, but count what has already been + * reserved in .heap1 */ - . = NEXT(4096); - __COHERENT_RAM_END__ = .; + . += HEAP_SIZE - (__heap1_end - __heap1_start); + . = ALIGN(4 * 1024); + __heap2_end = .; } -#endif - __heap1_start = .; - . += 0x40000 /*256KiB*/; - __heap1_end = .; + .text_init : ALIGN(4 * 1024) { + __text_init_start = .; +/* + * Include list of sections needed for boot initialization, this list + * overlaps with unpaged.ld.S but since unpaged.ld.S is first all those + * sections will go into the unpaged area. + */ +#include <text_init.ld.S> + . = ALIGN(4); + __text_init_end = .; + } + + .rodata_init : ALIGN(4) { + __rodata_init_start = .; +#include <rodata_init.ld.S> + . = ALIGN(4); + __rodata_init_end = .; + } + __init_start = __text_init_start; + __init_end = .; + __init_size = __init_end - __text_init_start; + __init_mem_usage = __init_end - CFG_TEE_LOAD_ADDR; + + .text_pagable : ALIGN(4) { + __text_pagable_start = .; + *(.text*) + . = ALIGN(4); + __text_pagable_end = .; + } + + .rodata_pagable : ALIGN(4) { + __rodata_pagable_start = .; + *(.rodata*) + . = ALIGN(4); + __start_ta_head_section = . ; + KEEP(*(ta_head_section)) + __stop_ta_head_section = . ; + . = ALIGN(4 * 1024); + __rodata_pagable_end = .; + } + + __pagable_part_start = __rodata_init_end; + __pagable_part_end = __rodata_pagable_end; + __pagable_start = __text_init_start; + __pagable_end = __pagable_part_end; + + ASSERT(CFG_TEE_LOAD_ADDR >= CFG_TEE_RAM_START, + "Load address before start of physical memory") + ASSERT(CFG_TEE_LOAD_ADDR < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), + "Load address after end of physical memory") + ASSERT(__init_end < (CFG_TEE_RAM_START + CFG_TEE_RAM_PH_SIZE), + "OP-TEE can't fit init part into available physical memory") + + +#endif /*CFG_WITH_PAGER*/ _end = .; +#ifndef CFG_WITH_PAGER + __init_size = __data_end - CFG_TEE_LOAD_ADDR; + __init_mem_usage = _end - CFG_TEE_LOAD_ADDR; +#endif . = CFG_TEE_RAM_START + CFG_TEE_RAM_VA_SIZE; _end_of_ram = .; /* Strip unnecessary stuff */ /DISCARD/ : { *(.comment .note .eh_frame) } + } diff --git a/core/arch/arm32/plat-vexpress/link.mk b/core/arch/arm32/plat-vexpress/link.mk index 9f90e44..e17948c 100644 --- a/core/arch/arm32/plat-vexpress/link.mk +++ b/core/arch/arm32/plat-vexpress/link.mk @@ -6,16 +6,12 @@ link-script-dep = $(link-out-dir)/.kern.ld.d AWK = awk -all: $(link-out-dir)/tee.elf $(link-out-dir)/tee.dmp $(link-out-dir)/tee.bin -all: $(link-out-dir)/tee.symb_sizes -cleanfiles += $(link-out-dir)/tee.elf $(link-out-dir)/tee.dmp $(link-out-dir)/tee.map -cleanfiles += $(link-out-dir)/tee.bin -cleanfiles += $(link-out-dir)/tee.symb_sizes -cleanfiles += $(link-script-pp) $(link-script-dep) link-ldflags = $(LDFLAGS) link-ldflags += -T $(link-script-pp) -Map=$(link-out-dir)/tee.map link-ldflags += --sort-section=alignment +link-ldflags += --fatal-warnings +link-ldflags += --print-gc-sections link-ldadd = $(LDADD) link-ldadd += $(addprefix -L,$(libdirs)) @@ -25,30 +21,147 @@ ldargs-tee.elf := $(link-ldflags) $(objs) $(link-ldadd) $(libgcc) link-script-cppflags := -DASM=1 \ $(filter-out $(CPPFLAGS_REMOVE) $(cppflags-remove), \ $(nostdinc) $(CPPFLAGS) \ - $(addprefix -I,$(incdirs$(sm))) $(cppflags$(sm))) + $(addprefix -I,$(incdirs$(sm)) $(link-out-dir)) \ + $(cppflags$(sm))) + +entries-unpaged += tee_pager_abort_handler +entries-unpaged += pager_load_rodata +entries-unpaged += thread_init_vbar +entries-unpaged += sm_init +entries-unpaged += core_init_mmu_regs +entries-unpaged += main_cpu_on_handler +entries-unpaged += main_init_secondary +entries-unpaged += stack_tmp_top +objs-unpaged := \ + $(filter-out $(addprefix $(out-dir)/, $(objs-unpaged-rem)), $(objs)) +ldargs-unpaged := -i --gc-sections \ + $(addprefix -u, $(entries-unpaged)) \ + $(objs-unpaged) $(link-ldadd) $(libgcc) +cleanfiles += $(link-out-dir)/unpaged.o +$(link-out-dir)/unpaged.o: $(objs-unpaged) $(libdeps) $(MAKEFILE_LIST) + @echo ' LD $@' + $(q)$(LD) $(ldargs-unpaged) -o $@ +cleanfiles += $(link-out-dir)/text_unpaged.ld.S: +$(link-out-dir)/text_unpaged.ld.S: $(link-out-dir)/unpaged.o + @echo ' GEN $@' + $(q)$(READELF) -a -W $< | ${AWK} -f ./scripts/gen_ld_text_sects.awk > $@ + +cleanfiles += $(link-out-dir)/rodata_unpaged.ld.S: +$(link-out-dir)/rodata_unpaged.ld.S: $(link-out-dir)/unpaged.o + @echo ' GEN $@' + $(q)$(READELF) -a -W $< | \ + ${AWK} -f ./scripts/gen_ld_rodata_sects.awk > $@ + +objs-init-rem += core/arch/arm32/tee/arch_svc.o +objs-init-rem += core/arch/arm32/tee/arch_svc_asm.o +objs-init-rem += core/arch/arm32/plat-vexpress/plat_tee_func.o +objs-init-rem += core/arch/arm32/tee/init.o +entries-init += _start +objs-init := \ + $(filter-out $(addprefix $(out-dir)/, $(objs-init-rem)), $(objs)) +ldargs-init := -i --gc-sections \ + $(addprefix -u, $(entries-init)) \ + $(objs-init) $(link-ldadd) $(libgcc) +cleanfiles += $(link-out-dir)/init.o +$(link-out-dir)/init.o: $(objs-init) $(libdeps) $(MAKEFILE_LIST) + @echo ' LD $@' + $(q)$(LD) $(ldargs-init) -o $@ + +cleanfiles += $(link-out-dir)/text_init.ld.S: +$(link-out-dir)/text_init.ld.S: $(link-out-dir)/init.o + @echo ' GEN $@' + $(q)$(READELF) -a -W $< | ${AWK} -f ./scripts/gen_ld_text_sects.awk > $@ + +cleanfiles += $(link-out-dir)/rodata_init.ld.S: +$(link-out-dir)/rodata_init.ld.S: $(link-out-dir)/init.o + @echo ' GEN $@' + $(q)$(READELF) -a -W $< | \ + ${AWK} -f ./scripts/gen_ld_rodata_sects.awk > $@ -include $(link-script-dep) -$(link-script-pp): $(link-script) +link-script-extra-deps += $(link-out-dir)/text_unpaged.ld.S +link-script-extra-deps += $(link-out-dir)/rodata_unpaged.ld.S +link-script-extra-deps += $(link-out-dir)/text_init.ld.S +link-script-extra-deps += $(link-out-dir)/rodata_init.ld.S +cleanfiles += $(link-script-pp) $(link-script-dep) +$(link-script-pp): $(link-script) $(link-script-extra-deps) @echo ' CPP $@' @mkdir -p $(dir $@) $(q)$(CPP) -Wp,-P,-MT,$@,-MD,$(link-script-dep) \ $(link-script-cppflags) $< > $@ - +all: $(link-out-dir)/tee.elf +cleanfiles += $(link-out-dir)/tee.elf $(link-out-dir)/tee.map $(link-out-dir)/tee.elf: $(objs) $(libdeps) $(link-script-pp) @echo ' LD $@' $(q)$(LD) $(ldargs-tee.elf) -o $@ +all: $(link-out-dir)/tee.dmp +cleanfiles += $(link-out-dir)/tee.dmp $(link-out-dir)/tee.dmp: $(link-out-dir)/tee.elf @echo ' OBJDUMP $@' $(q)$(OBJDUMP) -l -x -d $< > $@ -$(link-out-dir)/tee.bin: $(link-out-dir)/tee.elf +pagable_sections := .*_pagable +init_sections := .*_init +cleanfiles += $(link-out-dir)/tee-pager.bin +$(link-out-dir)/tee-pager.bin: $(link-out-dir)/tee.elf @echo ' OBJCOPY $@' - $(q)$(OBJCOPY) -O binary $< $@ + $(q)$(OBJCOPY) -O binary \ + --remove-section="$(pagable_sections)" \ + --remove-section="$(init_sections)" \ + $< $@ +cleanfiles += $(link-out-dir)/tee-pagable.bin +$(link-out-dir)/tee-pagable.bin: $(link-out-dir)/tee.elf + @echo ' OBJCOPY $@' + $(q)$(OBJCOPY) -O binary \ + --only-section="$(init_sections)" \ + --only-section="$(pagable_sections)" \ + $< $@ + +cleanfiles += $(link-out-dir)/tee-init_size.txt +$(link-out-dir)/tee-init_size.txt: $(link-out-dir)/tee.elf + @echo ' GEN $@' + @echo -n 0x > $@ + $(q)$(NM) $< | grep __init_size | sed 's/ .*$$//' >> $@ + +cleanfiles += $(link-out-dir)/tee-init_load_addr.txt +$(link-out-dir)/tee-init_load_addr.txt: $(link-out-dir)/tee.elf + @echo ' GEN $@' + @echo -n 0x > $@ + $(q)$(NM) $< | grep ' _start' | sed 's/ .*$$//' >> $@ + +cleanfiles += $(link-out-dir)/tee-init_mem_usage.txt +$(link-out-dir)/tee-init_mem_usage.txt: $(link-out-dir)/tee.elf + @echo ' GEN $@' + @echo -n 0x > $@ + $(q)$(NM) $< | grep ' __init_mem_usage' | sed 's/ .*$$//' >> $@ + +all: $(link-out-dir)/tee.bin +cleanfiles += $(link-out-dir)/tee.bin +$(link-out-dir)/tee.bin: $(link-out-dir)/tee-pager.bin \ + $(link-out-dir)/tee-pagable.bin \ + $(link-out-dir)/tee-init_size.txt \ + $(link-out-dir)/tee-init_load_addr.txt \ + $(link-out-dir)/tee-init_mem_usage.txt \ + ./scripts/gen_hashed_bin.py + @echo ' GEN $@' + $(q)./scripts/gen_hashed_bin.py \ + --arch 0 \ + --init_size `cat $(link-out-dir)/tee-init_size.txt` \ + --init_load_addr_lo \ + `cat $(link-out-dir)/tee-init_load_addr.txt` \ + --init_mem_usage `cat $(link-out-dir)/tee-init_mem_usage.txt` \ + --tee_pager_bin $(link-out-dir)/tee-pager.bin \ + --tee_pagable_bin $(link-out-dir)/tee-pagable.bin \ + --out $@ + + +all: $(link-out-dir)/tee.symb_sizes +cleanfiles += $(link-out-dir)/tee.symb_sizes $(link-out-dir)/tee.symb_sizes: $(link-out-dir)/tee.elf @echo ' GEN $@' $(q)$(NM) --print-size --reverse-sort --size-sort $< > $@ diff --git a/core/arch/arm32/plat-vexpress/platform_config.h b/core/arch/arm32/plat-vexpress/platform_config.h index d34e9af..bdab66d 100644 --- a/core/arch/arm32/plat-vexpress/platform_config.h +++ b/core/arch/arm32/plat-vexpress/platform_config.h @@ -119,8 +119,6 @@ #define CFG_TEE_CORE_NB_CORE 8 -#define CFG_TEE_LOAD_ADDR (TZDRAM_BASE + 0x1000) - #define CFG_SHMEM_START (DRAM0_BASE + 0x1000000) #define CFG_SHMEM_SIZE 0x100000 |