Unverified Commit 3ba92957 authored by Dimitris Papastamos's avatar Dimitris Papastamos Committed by GitHub
Browse files

Merge pull request #1510 from robertovargas-arm/romlib

Add support for moving libraries to ROM
parents 0983b8b1 1eb735d7
#!/bin/sh
# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
set -e
output=jmpvar.s
for i
do
case $i in
-o)
output=$2
shift 2
;;
--)
shift
break
;;
-*)
echo usage: genvar.sh [-o output] file... >&2
;;
esac
done
tmp=`mktemp`
trap "rm -f $tmp" EXIT INT QUIT
nm -a "$@" |
awk -v OFS="\n" '
$3 == ".text" {print "\t.data",
"\t.globl\tjmptbl",
"\t.align\t4",
"jmptbl:\t.quad\t0x" $1}' > $tmp
mv $tmp $output
#!/bin/sh
# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
set -e
build=.
out=output.a
for i
do
case $i in
-o)
out=$2
shift 2
;;
-b)
build=$2
shift 2
;;
--)
shift
break
;;
-*)
echo usage: genwrappers.sh [-o output] [-b dir] file ... >&2
exit 1
;;
esac
done
awk '{sub(/[:blank:]*#.*/,"")}
!/^$/ {print $1*4, $2, $3}' "$@" |
while read idx lib sym
do
file=$build/${lib}_$sym
cat <<EOF > $file.s
.globl $sym
$sym:
ldr x17, =jmptbl
ldr x17, [x17]
mov x16, $idx
add x16, x16, x17
br x16
EOF
${CROSS_COMPILE}as -o $file.o $file.s
done
${CROSS_COMPILE}ar -rc $out $build/*.o
/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
.globl rom_lib_init
.extern __DATA_RAM_START__, __DATA_ROM_START__, __DATA_SIZE__
.extern memset, memcpy
rom_lib_init:
cmp w0, #1
mov w0, #0
b.le 1f
ret
1: stp x29, x30, [sp, #-16]!
adrp x0, __DATA_RAM_START__
ldr x1,= __DATA_ROM_START__
ldr x2, =__DATA_SIZE__
bl memcpy
ldr x0, =__BSS_START__
mov x1, #0
ldr x2, =__BSS_SIZE__
bl memset
ldp x29, x30, [sp], #16
mov w0, #1
ret
#
# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
0 rom rom_lib_init
1 fdt fdt_getprop_namelen
2 fdt fdt_setprop_inplace
3 fdt fdt_check_header
4 fdt fdt_node_offset_by_compatible
5 mbedtls mbedtls_asn1_get_alg
6 mbedtls mbedtls_asn1_get_alg_null
7 mbedtls mbedtls_asn1_get_bitstring_null
8 mbedtls mbedtls_asn1_get_bool
9 mbedtls mbedtls_asn1_get_int
10 mbedtls mbedtls_asn1_get_tag
11 mbedtls mbedtls_free
12 mbedtls mbedtls_md
13 mbedtls mbedtls_md_get_size
14 mbedtls mbedtls_memory_buffer_alloc_init
15 mbedtls mbedtls_oid_get_md_alg
16 mbedtls mbedtls_oid_get_numeric_string
17 mbedtls mbedtls_oid_get_pk_alg
18 mbedtls mbedtls_oid_get_sig_alg
19 mbedtls mbedtls_pk_free
20 mbedtls mbedtls_pk_init
21 mbedtls mbedtls_pk_parse_subpubkey
22 mbedtls mbedtls_pk_verify_ext
23 mbedtls mbedtls_platform_set_snprintf
24 mbedtls mbedtls_x509_get_rsassa_pss_params
25 mbedtls mbedtls_x509_get_sig_alg
26 mbedtls mbedtls_md_info_from_type
27 c exit
28 c atexit
/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <platform_def.h>
#include <xlat_tables_defs.h>
MEMORY {
ROM (rx): ORIGIN = ROMLIB_RO_BASE, LENGTH = ROMLIB_RO_LIMIT - ROMLIB_RO_BASE
RAM (rwx): ORIGIN = ROMLIB_RW_BASE, LENGTH = ROMLIB_RW_END - ROMLIB_RW_BASE
}
OUTPUT_FORMAT(PLATFORM_LINKER_FORMAT)
OUTPUT_ARCH(PLATFORM_LINKER_ARCH)
ENTRY(jmptbl)
SECTIONS
{
. = ROMLIB_RO_BASE;
.text : {
*jmptbl.o(.text)
*(.text*)
*(.rodata*)
} >ROM
__DATA_ROM_START__ = LOADADDR(.data);
.data : {
__DATA_RAM_START__ = .;
*(.data*)
__DATA_RAM_END__ = .;
} >RAM AT>ROM
__DATA_SIZE__ = SIZEOF(.data);
.bss : {
__BSS_START__ = .;
*(.bss*)
__BSS_END__ = .;
} >RAM
__BSS_SIZE__ = SIZEOF(.bss);
}
...@@ -189,6 +189,24 @@ GZIP_SUFFIX := .gz ...@@ -189,6 +189,24 @@ GZIP_SUFFIX := .gz
MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP
# MAKE_C_LIB builds a C source file and generates the dependency file
# $(1) = output directory
# $(2) = source file (%.c)
# $(3) = library name
define MAKE_C_LIB
$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
$(eval DEP := $(patsubst %.o,%.d,$(OBJ)))
$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs
@echo " CC $$<"
$$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@
-include $(DEP)
endef
# MAKE_C builds a C source file and generates the dependency file # MAKE_C builds a C source file and generates the dependency file
# $(1) = output directory # $(1) = output directory
# $(2) = source file (%.c) # $(2) = source file (%.c)
...@@ -243,6 +261,18 @@ $(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs ...@@ -243,6 +261,18 @@ $(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs
endef endef
# MAKE_LIB_OBJS builds both C source files
# $(1) = output directory
# $(2) = list of source files
# $(3) = name of the library
define MAKE_LIB_OBJS
$(eval C_OBJS := $(filter %.c,$(2)))
$(eval REMAIN := $(filter-out %.c,$(2)))
$(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3))))
$(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
endef
# MAKE_OBJS builds both C and assembly source files # MAKE_OBJS builds both C and assembly source files
# $(1) = output directory # $(1) = output directory
...@@ -274,6 +304,49 @@ endef ...@@ -274,6 +304,49 @@ endef
# This must be set to a C string (including quotes where applicable). # This must be set to a C string (including quotes where applicable).
BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__ BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__
.PHONY: libraries
# MAKE_LIB_DIRS macro defines the target for the directory where
# libraries are created
define MAKE_LIB_DIRS
$(eval LIB_DIR := ${BUILD_PLAT}/lib)
$(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
$(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper)
$(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT}))
$(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT}))
$(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT}))
endef
# MAKE_LIB macro defines the targets and options to build each BL image.
# Arguments:
# $(1) = Library name
define MAKE_LIB
$(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1))
$(eval LIB_DIR := ${BUILD_PLAT}/lib)
$(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib)
$(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS))
$(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES))))
$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT}))
$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
.PHONY : lib${1}_dirs
lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR}
libraries: ${LIB_DIR}/lib$(1).a
LDPATHS = -L${LIB_DIR}
LDLIBS += -l$(1)
ifeq ($(USE_ROMLIB),1)
LDLIBS := -lwrappers -lc
endif
all: ${LIB_DIR}/lib$(1).a
${LIB_DIR}/lib$(1).a: $(OBJS)
@echo " AR $$@"
$$(Q)$$(AR) cr $$@ $$?
endef
# MAKE_BL macro defines the targets and options to build each BL image. # MAKE_BL macro defines the targets and options to build each BL image.
# Arguments: # Arguments:
# $(1) = BL stage (2, 2u, 30, 31, 32, 33) # $(1) = BL stage (2, 2u, 30, 31, 32, 33)
...@@ -313,7 +386,11 @@ bl${1}_dirs: | ${OBJ_DIRS} ...@@ -313,7 +386,11 @@ bl${1}_dirs: | ${OBJ_DIRS}
$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1)))
$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1))) $(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1)))
$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs $(BL_LIBS) ifeq ($(USE_ROMLIB),1)
$(ELF): romlib.bin
endif
$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs libraries $(BL_LIBS)
@echo " LD $$@" @echo " LD $$@"
ifdef MAKE_BUILD_STRINGS ifdef MAKE_BUILD_STRINGS
$(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o)
...@@ -323,7 +400,8 @@ else ...@@ -323,7 +400,8 @@ else
$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o
endif endif
$$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \ $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \
--script $(LINKERFILE) $(BUILD_DIR)/build_message.o $(OBJS) $(LDLIBS) $(BL_LIBS) --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \
$(OBJS) $(LDPATHS) $(LDLIBS) $(BL_LIBS)
$(DUMP): $(ELF) $(DUMP): $(ELF)
@echo " OD $$@" @echo " OD $$@"
......
...@@ -166,6 +166,9 @@ TRUSTED_BOARD_BOOT := 0 ...@@ -166,6 +166,9 @@ TRUSTED_BOARD_BOOT := 0
# Build option to choose whether Trusted firmware uses Coherent memory or not. # Build option to choose whether Trusted firmware uses Coherent memory or not.
USE_COHERENT_MEM := 1 USE_COHERENT_MEM := 1
# Build option to choose wheter Trusted firmware uses library at ROM
USE_ROMLIB := 0
# Use tbbr_oid.h instead of platform_oid.h # Use tbbr_oid.h instead of platform_oid.h
USE_TBBR_DEFS = $(ERROR_DEPRECATED) USE_TBBR_DEFS = $(ERROR_DEPRECATED)
......
...@@ -67,6 +67,8 @@ ...@@ -67,6 +67,8 @@
* in debug mode. We can test TBB on Juno bypassing the ROM and using 128 KB of * in debug mode. We can test TBB on Juno bypassing the ROM and using 128 KB of
* flash * flash
*/ */
#define PLAT_ARM_MAX_ROMLIB_RO_SIZE 0
#if TRUSTED_BOARD_BOOT #if TRUSTED_BOARD_BOOT
#define PLAT_ARM_TRUSTED_ROM_SIZE 0x00020000 #define PLAT_ARM_TRUSTED_ROM_SIZE 0x00020000
#else #else
...@@ -122,6 +124,15 @@ ...@@ -122,6 +124,15 @@
# define PLAT_ARM_MAX_BL1_RW_SIZE 0x6000 # define PLAT_ARM_MAX_BL1_RW_SIZE 0x6000
#endif #endif
/*
* PLAT_ARM_MAX_ROMLIB_RW_SIZE is define to use a full page
*/
#if USE_ROMLIB
#define PLAT_ARM_MAX_ROMLIB_RW_SIZE 0x1000
#else
#define PLAT_ARM_MAX_ROMLIB_RW_SIZE 0
#endif
/* /*
* PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a
* little space for growth. * little space for growth.
......
...@@ -117,6 +117,10 @@ void arm_bl1_plat_arch_setup(void) ...@@ -117,6 +117,10 @@ void arm_bl1_plat_arch_setup(void)
const mmap_region_t bl_regions[] = { const mmap_region_t bl_regions[] = {
MAP_BL1_TOTAL, MAP_BL1_TOTAL,
MAP_BL1_RO, MAP_BL1_RO,
#if USE_ROMLIB
ARM_MAP_ROMLIB_CODE,
ARM_MAP_ROMLIB_DATA,
#endif
{0} {0}
}; };
...@@ -126,6 +130,8 @@ void arm_bl1_plat_arch_setup(void) ...@@ -126,6 +130,8 @@ void arm_bl1_plat_arch_setup(void)
#else #else
enable_mmu_el3(0); enable_mmu_el3(0);
#endif /* AARCH32 */ #endif /* AARCH32 */
arm_setup_romlib();
} }
void bl1_plat_arch_setup(void) void bl1_plat_arch_setup(void)
......
...@@ -246,6 +246,10 @@ void arm_bl2_plat_arch_setup(void) ...@@ -246,6 +246,10 @@ void arm_bl2_plat_arch_setup(void)
const mmap_region_t bl_regions[] = { const mmap_region_t bl_regions[] = {
MAP_BL2_TOTAL, MAP_BL2_TOTAL,
ARM_MAP_BL_RO, ARM_MAP_BL_RO,
#if USE_ROMLIB
ARM_MAP_ROMLIB_CODE,
ARM_MAP_ROMLIB_DATA,
#endif
{0} {0}
}; };
...@@ -256,6 +260,8 @@ void arm_bl2_plat_arch_setup(void) ...@@ -256,6 +260,8 @@ void arm_bl2_plat_arch_setup(void)
#else #else
enable_mmu_el1(0); enable_mmu_el1(0);
#endif #endif
arm_setup_romlib();
} }
void bl2_plat_arch_setup(void) void bl2_plat_arch_setup(void)
......
...@@ -73,6 +73,10 @@ void arm_bl2u_plat_arch_setup(void) ...@@ -73,6 +73,10 @@ void arm_bl2u_plat_arch_setup(void)
const mmap_region_t bl_regions[] = { const mmap_region_t bl_regions[] = {
MAP_BL2U_TOTAL, MAP_BL2U_TOTAL,
ARM_MAP_BL_RO, ARM_MAP_BL_RO,
#if USE_ROMLIB
ARM_MAP_ROMLIB_CODE,
ARM_MAP_ROMLIB_DATA,
#endif
{0} {0}
}; };
...@@ -83,6 +87,7 @@ void arm_bl2u_plat_arch_setup(void) ...@@ -83,6 +87,7 @@ void arm_bl2u_plat_arch_setup(void)
#else #else
enable_mmu_el1(0); enable_mmu_el1(0);
#endif #endif
arm_setup_romlib();
} }
void bl2u_plat_arch_setup(void) void bl2u_plat_arch_setup(void)
......
...@@ -285,9 +285,18 @@ void bl31_plat_runtime_setup(void) ...@@ -285,9 +285,18 @@ void bl31_plat_runtime_setup(void)
void arm_bl31_plat_arch_setup(void) void arm_bl31_plat_arch_setup(void)
{ {
#define ARM_MAP_BL_ROMLIB MAP_REGION_FLAT( \
BL31_BASE, \
BL31_END - BL31_BASE, \
MT_MEMORY | MT_RW | MT_SECURE)
const mmap_region_t bl_regions[] = { const mmap_region_t bl_regions[] = {
MAP_BL31_TOTAL, MAP_BL31_TOTAL,
ARM_MAP_BL_RO, ARM_MAP_BL_RO,
#if USE_ROMLIB
ARM_MAP_ROMLIB_CODE,
ARM_MAP_ROMLIB_DATA,
#endif
#if USE_COHERENT_MEM #if USE_COHERENT_MEM
ARM_MAP_BL_COHERENT_RAM, ARM_MAP_BL_COHERENT_RAM,
#endif #endif
...@@ -297,6 +306,8 @@ void arm_bl31_plat_arch_setup(void) ...@@ -297,6 +306,8 @@ void arm_bl31_plat_arch_setup(void)
arm_setup_page_tables(bl_regions, plat_arm_get_mmap()); arm_setup_page_tables(bl_regions, plat_arm_get_mmap());
enable_mmu_el3(0); enable_mmu_el3(0);
arm_setup_romlib();
} }
void bl31_plat_arch_setup(void) void bl31_plat_arch_setup(void)
......
...@@ -10,8 +10,9 @@ ...@@ -10,8 +10,9 @@
#include <debug.h> #include <debug.h>
#include <mmio.h> #include <mmio.h>
#include <plat_arm.h> #include <plat_arm.h>
#include <platform_def.h>
#include <platform.h> #include <platform.h>
#include <platform_def.h>
#include <romlib.h>
#include <secure_partition.h> #include <secure_partition.h>
/* Weak definitions may be overridden in specific ARM standard platform */ /* Weak definitions may be overridden in specific ARM standard platform */
...@@ -24,6 +25,15 @@ ...@@ -24,6 +25,15 @@
#pragma weak plat_get_syscnt_freq2 #pragma weak plat_get_syscnt_freq2
#endif #endif
void arm_setup_romlib(void)
{
#if USE_ROMLIB
if (!rom_lib_init(ROMLIB_VERSION))
panic();
#endif
}
/* /*
* Set up the page tables for the generic and platform-specific memory regions. * Set up the page tables for the generic and platform-specific memory regions.
* The size of the Trusted SRAM seen by the BL image must be specified as well * The size of the Trusted SRAM seen by the BL image must be specified as well
......
...@@ -185,8 +185,7 @@ include lib/libfdt/libfdt.mk ...@@ -185,8 +185,7 @@ include lib/libfdt/libfdt.mk
DYN_CFG_SOURCES += plat/arm/common/arm_dyn_cfg.c \ DYN_CFG_SOURCES += plat/arm/common/arm_dyn_cfg.c \
plat/arm/common/arm_dyn_cfg_helpers.c \ plat/arm/common/arm_dyn_cfg_helpers.c \
common/fdt_wrappers.c \ common/fdt_wrappers.c
${LIBFDT_SRCS}
BL1_SOURCES += ${DYN_CFG_SOURCES} BL1_SOURCES += ${DYN_CFG_SOURCES}
BL2_SOURCES += ${DYN_CFG_SOURCES} BL2_SOURCES += ${DYN_CFG_SOURCES}
......
...@@ -132,8 +132,7 @@ BL2_SOURCES += drivers/io/io_semihosting.c \ ...@@ -132,8 +132,7 @@ BL2_SOURCES += drivers/io/io_semihosting.c \
plat/qemu/qemu_io_storage.c \ plat/qemu/qemu_io_storage.c \
plat/qemu/${ARCH}/plat_helpers.S \ plat/qemu/${ARCH}/plat_helpers.S \
plat/qemu/qemu_bl2_setup.c \ plat/qemu/qemu_bl2_setup.c \
plat/qemu/dt.c \ plat/qemu/dt.c
$(LIBFDT_SRCS)
ifeq (${LOAD_IMAGE_V2},1) ifeq (${LOAD_IMAGE_V2},1)
BL2_SOURCES += plat/qemu/qemu_bl2_mem_params_desc.c \ BL2_SOURCES += plat/qemu/qemu_bl2_mem_params_desc.c \
plat/qemu/qemu_image_load.c \ plat/qemu/qemu_image_load.c \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment