From 5fee02873ba0f2ac32aba319f750ad69242fe603 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 8 May 2018 10:27:10 +0100 Subject: [PATCH 1/8] Add make macros to build library archives This patch adds all the make macros needed to create a library archive and to use it in the link stage. Change-Id: I26597bfd6543649d0b68a9b1e06aec1ba353e6de Signed-off-by: Roberto Vargas --- Makefile | 2 ++ make_helpers/build_macros.mk | 70 ++++++++++++++++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 533cb8ab1..260986412 100644 --- a/Makefile +++ b/Makefile @@ -670,6 +670,8 @@ ifeq (${ERROR_DEPRECATED},0) CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp endif +$(eval $(call MAKE_LIB_DIR)) + # Expand build macros for the different images ifeq (${NEED_BL1},yes) $(eval $(call MAKE_BL,1)) diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index 1184b7af8..ca826941a 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -189,6 +189,24 @@ GZIP_SUFFIX := .gz 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 # $(1) = output directory # $(2) = source file (%.c) @@ -243,6 +261,18 @@ $(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs 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 # $(1) = output directory @@ -274,6 +304,41 @@ endef # This must be set to a C string (including quotes where applicable). BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__ +.PHONY: libraries + + +# MAKE_LIB_DIR macro defines the target for the directory where +# libraries are created +define MAKE_LIB_DIR + $(eval LIB_DIR := ${BUILD_PLAT}/lib) + $(eval $(call MAKE_PREREQ_DIR,${LIB_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 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} +libraries: ${LIB_DIR}/lib$(1).a +LDPATHS = -L${LIB_DIR} +LDLIBS += -l$(1) + +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. # Arguments: # $(1) = BL stage (2, 2u, 30, 31, 32, 33) @@ -313,7 +378,7 @@ bl${1}_dirs: | ${OBJ_DIRS} $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) $(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1))) -$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs $(BL_LIBS) +$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs libraries $(BL_LIBS) @echo " LD $$@" ifdef MAKE_BUILD_STRINGS $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) @@ -323,7 +388,8 @@ else $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o endif $$(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) @echo " OD $$@" From fec364847861e5a04dfd44a8d77cb25bf64820c7 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 8 May 2018 10:27:10 +0100 Subject: [PATCH 2/8] Create a library file for libfdt TF Makefile was linking all the objects files generated for the fdt library instead of creating a static library that could be used in the linking stage. Change-Id: If3705bba188ec39e1fbf2322a7f2a9a941e1b90d Signed-off-by: Roberto Vargas --- lib/libfdt/libfdt.mk | 2 ++ plat/arm/common/arm_common.mk | 3 +-- plat/qemu/platform.mk | 3 +-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libfdt/libfdt.mk b/lib/libfdt/libfdt.mk index d03dde204..1cbbd7852 100644 --- a/lib/libfdt/libfdt.mk +++ b/lib/libfdt/libfdt.mk @@ -15,3 +15,5 @@ LIBFDT_SRCS := $(addprefix lib/libfdt/, \ fdt_wip.c) \ INCLUDES += -Iinclude/lib/libfdt + +$(eval $(call MAKE_LIB,fdt)) diff --git a/plat/arm/common/arm_common.mk b/plat/arm/common/arm_common.mk index 67b574de6..d8eda35b6 100644 --- a/plat/arm/common/arm_common.mk +++ b/plat/arm/common/arm_common.mk @@ -185,8 +185,7 @@ include lib/libfdt/libfdt.mk DYN_CFG_SOURCES += plat/arm/common/arm_dyn_cfg.c \ plat/arm/common/arm_dyn_cfg_helpers.c \ - common/fdt_wrappers.c \ - ${LIBFDT_SRCS} + common/fdt_wrappers.c BL1_SOURCES += ${DYN_CFG_SOURCES} BL2_SOURCES += ${DYN_CFG_SOURCES} diff --git a/plat/qemu/platform.mk b/plat/qemu/platform.mk index 379ab3dca..1d46eeccd 100644 --- a/plat/qemu/platform.mk +++ b/plat/qemu/platform.mk @@ -132,8 +132,7 @@ BL2_SOURCES += drivers/io/io_semihosting.c \ plat/qemu/qemu_io_storage.c \ plat/qemu/${ARCH}/plat_helpers.S \ plat/qemu/qemu_bl2_setup.c \ - plat/qemu/dt.c \ - $(LIBFDT_SRCS) + plat/qemu/dt.c ifeq (${LOAD_IMAGE_V2},1) BL2_SOURCES += plat/qemu/qemu_bl2_mem_params_desc.c \ plat/qemu/qemu_image_load.c \ From 61f72a34250d063da67f4fc2b0eb8c3fda3376be Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 8 May 2018 10:27:10 +0100 Subject: [PATCH 3/8] Create a library file for libc TF Makefile was linking all the objects files generated for the c library instead of creating a static library that could be used in the linking stage. Change-Id: I721daea097e9b13cbb42c9f8eaa2af8fea0799cf Signed-off-by: Roberto Vargas --- Makefile | 14 +++++++------- include/lib/{stdlib => libc}/assert.h | 0 include/lib/{stdlib => libc}/inttypes.h | 0 include/lib/{stdlib => libc}/machine/_inttypes.h | 0 include/lib/{stdlib => libc}/machine/_limits.h | 0 include/lib/{stdlib => libc}/machine/_stdint.h | 0 include/lib/{stdlib => libc}/machine/_types.h | 0 include/lib/{stdlib => libc}/machine/endian.h | 0 include/lib/{stdlib => libc}/stdbool.h | 0 include/lib/{stdlib => libc}/stddef.h | 0 include/lib/{stdlib => libc}/stdio.h | 0 include/lib/{stdlib => libc}/stdlib.h | 0 include/lib/{stdlib => libc}/string.h | 0 include/lib/{stdlib => libc}/strings.h | 0 include/lib/{stdlib => libc}/sys/_null.h | 0 include/lib/{stdlib => libc}/sys/_stdint.h | 0 include/lib/{stdlib => libc}/sys/_timespec.h | 0 include/lib/{stdlib => libc}/sys/_types.h | 0 include/lib/{stdlib => libc}/sys/cdefs.h | 0 include/lib/{stdlib => libc}/sys/ctype.h | 0 include/lib/{stdlib => libc}/sys/endian.h | 0 include/lib/{stdlib => libc}/sys/errno.h | 0 include/lib/{stdlib => libc}/sys/limits.h | 0 include/lib/{stdlib => libc}/sys/stdarg.h | 0 include/lib/{stdlib => libc}/sys/stdint.h | 0 include/lib/{stdlib => libc}/sys/timespec.h | 0 include/lib/{stdlib => libc}/sys/types.h | 0 include/lib/{stdlib => libc}/time.h | 0 include/lib/{stdlib => libc}/xlocale/_strings.h | 0 include/lib/{stdlib => libc}/xlocale/_time.h | 0 lib/{stdlib => libc}/abort.c | 0 lib/{stdlib => libc}/assert.c | 0 lib/{stdlib => libc}/exit.c | 0 lib/{stdlib/stdlib.mk => libc/libc.mk} | 6 +++--- lib/{stdlib => libc}/mem.c | 0 lib/{stdlib => libc}/printf.c | 0 lib/{stdlib => libc}/putchar.c | 0 lib/{stdlib => libc}/puts.c | 0 lib/{stdlib => libc}/sscanf.c | 0 lib/{stdlib => libc}/strchr.c | 0 lib/{stdlib => libc}/strcmp.c | 0 lib/{stdlib => libc}/strlen.c | 0 lib/{stdlib => libc}/strncmp.c | 0 lib/{stdlib => libc}/strnlen.c | 0 lib/{stdlib => libc}/subr_prf.c | 0 lib/{stdlib => libc}/timingsafe_bcmp.c | 0 46 files changed, 10 insertions(+), 10 deletions(-) rename include/lib/{stdlib => libc}/assert.h (100%) rename include/lib/{stdlib => libc}/inttypes.h (100%) rename include/lib/{stdlib => libc}/machine/_inttypes.h (100%) rename include/lib/{stdlib => libc}/machine/_limits.h (100%) rename include/lib/{stdlib => libc}/machine/_stdint.h (100%) rename include/lib/{stdlib => libc}/machine/_types.h (100%) rename include/lib/{stdlib => libc}/machine/endian.h (100%) rename include/lib/{stdlib => libc}/stdbool.h (100%) rename include/lib/{stdlib => libc}/stddef.h (100%) rename include/lib/{stdlib => libc}/stdio.h (100%) rename include/lib/{stdlib => libc}/stdlib.h (100%) rename include/lib/{stdlib => libc}/string.h (100%) rename include/lib/{stdlib => libc}/strings.h (100%) rename include/lib/{stdlib => libc}/sys/_null.h (100%) rename include/lib/{stdlib => libc}/sys/_stdint.h (100%) rename include/lib/{stdlib => libc}/sys/_timespec.h (100%) rename include/lib/{stdlib => libc}/sys/_types.h (100%) rename include/lib/{stdlib => libc}/sys/cdefs.h (100%) rename include/lib/{stdlib => libc}/sys/ctype.h (100%) rename include/lib/{stdlib => libc}/sys/endian.h (100%) rename include/lib/{stdlib => libc}/sys/errno.h (100%) rename include/lib/{stdlib => libc}/sys/limits.h (100%) rename include/lib/{stdlib => libc}/sys/stdarg.h (100%) rename include/lib/{stdlib => libc}/sys/stdint.h (100%) rename include/lib/{stdlib => libc}/sys/timespec.h (100%) rename include/lib/{stdlib => libc}/sys/types.h (100%) rename include/lib/{stdlib => libc}/time.h (100%) rename include/lib/{stdlib => libc}/xlocale/_strings.h (100%) rename include/lib/{stdlib => libc}/xlocale/_time.h (100%) rename lib/{stdlib => libc}/abort.c (100%) rename lib/{stdlib => libc}/assert.c (100%) rename lib/{stdlib => libc}/exit.c (100%) rename lib/{stdlib/stdlib.mk => libc/libc.mk} (77%) rename lib/{stdlib => libc}/mem.c (100%) rename lib/{stdlib => libc}/printf.c (100%) rename lib/{stdlib => libc}/putchar.c (100%) rename lib/{stdlib => libc}/puts.c (100%) rename lib/{stdlib => libc}/sscanf.c (100%) rename lib/{stdlib => libc}/strchr.c (100%) rename lib/{stdlib => libc}/strcmp.c (100%) rename lib/{stdlib => libc}/strlen.c (100%) rename lib/{stdlib => libc}/strncmp.c (100%) rename lib/{stdlib => libc}/strnlen.c (100%) rename lib/{stdlib => libc}/subr_prf.c (100%) rename lib/{stdlib => libc}/timingsafe_bcmp.c (100%) diff --git a/Makefile b/Makefile index 260986412..9c0ab722e 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ CHECKCODE_ARGS := --no-patch # Do not check the coding style on imported library files or documentation files INC_LIB_DIRS_TO_CHECK := $(sort $(filter-out \ include/lib/libfdt \ - include/lib/stdlib, \ + include/lib/libc, \ $(wildcard include/lib/*))) INC_DIRS_TO_CHECK := $(sort $(filter-out \ include/lib, \ @@ -53,7 +53,7 @@ INC_DIRS_TO_CHECK := $(sort $(filter-out \ LIB_DIRS_TO_CHECK := $(sort $(filter-out \ lib/compiler-rt \ lib/libfdt% \ - lib/stdlib, \ + lib/libc, \ $(wildcard lib/*))) ROOT_DIRS_TO_CHECK := $(sort $(filter-out \ lib \ @@ -198,7 +198,7 @@ DTC_FLAGS += -I dts -O dtb # Common sources and include directories ################################################################################ include lib/compiler-rt/compiler-rt.mk -include lib/stdlib/stdlib.mk +include lib/libc/libc.mk BL_COMMON_SOURCES += common/bl_common.c \ common/tf_log.c \ @@ -211,8 +211,7 @@ BL_COMMON_SOURCES += common/bl_common.c \ plat/common/plat_log_common.c \ plat/common/${ARCH}/plat_common.c \ plat/common/${ARCH}/platform_helpers.S \ - ${COMPILER_RT_SRCS} \ - ${STDLIB_SRCS} + ${COMPILER_RT_SRCS} INCLUDES += -Iinclude \ -Iinclude/bl1 \ @@ -671,6 +670,7 @@ ifeq (${ERROR_DEPRECATED},0) endif $(eval $(call MAKE_LIB_DIR)) +$(eval $(call MAKE_LIB,c)) # Expand build macros for the different images ifeq (${NEED_BL1},yes) @@ -747,7 +747,7 @@ realclean distclean: checkcodebase: locate-checkpatch @echo " CHECKING STYLE" @if test -d .git ; then \ - git ls-files | grep -E -v 'libfdt|stdlib|docs|\.md' | \ + git ls-files | grep -E -v 'libfdt|libc|docs|\.md' | \ while read GIT_FILE ; \ do ${CHECKPATCH} ${CHECKCODE_ARGS} -f $$GIT_FILE ; \ done ; \ @@ -755,7 +755,7 @@ checkcodebase: locate-checkpatch find . -type f -not -iwholename "*.git*" \ -not -iwholename "*build*" \ -not -iwholename "*libfdt*" \ - -not -iwholename "*stdlib*" \ + -not -iwholename "*libc*" \ -not -iwholename "*docs*" \ -not -iwholename "*.md" \ -exec ${CHECKPATCH} ${CHECKCODE_ARGS} -f {} \; ; \ diff --git a/include/lib/stdlib/assert.h b/include/lib/libc/assert.h similarity index 100% rename from include/lib/stdlib/assert.h rename to include/lib/libc/assert.h diff --git a/include/lib/stdlib/inttypes.h b/include/lib/libc/inttypes.h similarity index 100% rename from include/lib/stdlib/inttypes.h rename to include/lib/libc/inttypes.h diff --git a/include/lib/stdlib/machine/_inttypes.h b/include/lib/libc/machine/_inttypes.h similarity index 100% rename from include/lib/stdlib/machine/_inttypes.h rename to include/lib/libc/machine/_inttypes.h diff --git a/include/lib/stdlib/machine/_limits.h b/include/lib/libc/machine/_limits.h similarity index 100% rename from include/lib/stdlib/machine/_limits.h rename to include/lib/libc/machine/_limits.h diff --git a/include/lib/stdlib/machine/_stdint.h b/include/lib/libc/machine/_stdint.h similarity index 100% rename from include/lib/stdlib/machine/_stdint.h rename to include/lib/libc/machine/_stdint.h diff --git a/include/lib/stdlib/machine/_types.h b/include/lib/libc/machine/_types.h similarity index 100% rename from include/lib/stdlib/machine/_types.h rename to include/lib/libc/machine/_types.h diff --git a/include/lib/stdlib/machine/endian.h b/include/lib/libc/machine/endian.h similarity index 100% rename from include/lib/stdlib/machine/endian.h rename to include/lib/libc/machine/endian.h diff --git a/include/lib/stdlib/stdbool.h b/include/lib/libc/stdbool.h similarity index 100% rename from include/lib/stdlib/stdbool.h rename to include/lib/libc/stdbool.h diff --git a/include/lib/stdlib/stddef.h b/include/lib/libc/stddef.h similarity index 100% rename from include/lib/stdlib/stddef.h rename to include/lib/libc/stddef.h diff --git a/include/lib/stdlib/stdio.h b/include/lib/libc/stdio.h similarity index 100% rename from include/lib/stdlib/stdio.h rename to include/lib/libc/stdio.h diff --git a/include/lib/stdlib/stdlib.h b/include/lib/libc/stdlib.h similarity index 100% rename from include/lib/stdlib/stdlib.h rename to include/lib/libc/stdlib.h diff --git a/include/lib/stdlib/string.h b/include/lib/libc/string.h similarity index 100% rename from include/lib/stdlib/string.h rename to include/lib/libc/string.h diff --git a/include/lib/stdlib/strings.h b/include/lib/libc/strings.h similarity index 100% rename from include/lib/stdlib/strings.h rename to include/lib/libc/strings.h diff --git a/include/lib/stdlib/sys/_null.h b/include/lib/libc/sys/_null.h similarity index 100% rename from include/lib/stdlib/sys/_null.h rename to include/lib/libc/sys/_null.h diff --git a/include/lib/stdlib/sys/_stdint.h b/include/lib/libc/sys/_stdint.h similarity index 100% rename from include/lib/stdlib/sys/_stdint.h rename to include/lib/libc/sys/_stdint.h diff --git a/include/lib/stdlib/sys/_timespec.h b/include/lib/libc/sys/_timespec.h similarity index 100% rename from include/lib/stdlib/sys/_timespec.h rename to include/lib/libc/sys/_timespec.h diff --git a/include/lib/stdlib/sys/_types.h b/include/lib/libc/sys/_types.h similarity index 100% rename from include/lib/stdlib/sys/_types.h rename to include/lib/libc/sys/_types.h diff --git a/include/lib/stdlib/sys/cdefs.h b/include/lib/libc/sys/cdefs.h similarity index 100% rename from include/lib/stdlib/sys/cdefs.h rename to include/lib/libc/sys/cdefs.h diff --git a/include/lib/stdlib/sys/ctype.h b/include/lib/libc/sys/ctype.h similarity index 100% rename from include/lib/stdlib/sys/ctype.h rename to include/lib/libc/sys/ctype.h diff --git a/include/lib/stdlib/sys/endian.h b/include/lib/libc/sys/endian.h similarity index 100% rename from include/lib/stdlib/sys/endian.h rename to include/lib/libc/sys/endian.h diff --git a/include/lib/stdlib/sys/errno.h b/include/lib/libc/sys/errno.h similarity index 100% rename from include/lib/stdlib/sys/errno.h rename to include/lib/libc/sys/errno.h diff --git a/include/lib/stdlib/sys/limits.h b/include/lib/libc/sys/limits.h similarity index 100% rename from include/lib/stdlib/sys/limits.h rename to include/lib/libc/sys/limits.h diff --git a/include/lib/stdlib/sys/stdarg.h b/include/lib/libc/sys/stdarg.h similarity index 100% rename from include/lib/stdlib/sys/stdarg.h rename to include/lib/libc/sys/stdarg.h diff --git a/include/lib/stdlib/sys/stdint.h b/include/lib/libc/sys/stdint.h similarity index 100% rename from include/lib/stdlib/sys/stdint.h rename to include/lib/libc/sys/stdint.h diff --git a/include/lib/stdlib/sys/timespec.h b/include/lib/libc/sys/timespec.h similarity index 100% rename from include/lib/stdlib/sys/timespec.h rename to include/lib/libc/sys/timespec.h diff --git a/include/lib/stdlib/sys/types.h b/include/lib/libc/sys/types.h similarity index 100% rename from include/lib/stdlib/sys/types.h rename to include/lib/libc/sys/types.h diff --git a/include/lib/stdlib/time.h b/include/lib/libc/time.h similarity index 100% rename from include/lib/stdlib/time.h rename to include/lib/libc/time.h diff --git a/include/lib/stdlib/xlocale/_strings.h b/include/lib/libc/xlocale/_strings.h similarity index 100% rename from include/lib/stdlib/xlocale/_strings.h rename to include/lib/libc/xlocale/_strings.h diff --git a/include/lib/stdlib/xlocale/_time.h b/include/lib/libc/xlocale/_time.h similarity index 100% rename from include/lib/stdlib/xlocale/_time.h rename to include/lib/libc/xlocale/_time.h diff --git a/lib/stdlib/abort.c b/lib/libc/abort.c similarity index 100% rename from lib/stdlib/abort.c rename to lib/libc/abort.c diff --git a/lib/stdlib/assert.c b/lib/libc/assert.c similarity index 100% rename from lib/stdlib/assert.c rename to lib/libc/assert.c diff --git a/lib/stdlib/exit.c b/lib/libc/exit.c similarity index 100% rename from lib/stdlib/exit.c rename to lib/libc/exit.c diff --git a/lib/stdlib/stdlib.mk b/lib/libc/libc.mk similarity index 77% rename from lib/stdlib/stdlib.mk rename to lib/libc/libc.mk index 821162354..ded3d7459 100644 --- a/lib/stdlib/stdlib.mk +++ b/lib/libc/libc.mk @@ -4,7 +4,7 @@ # SPDX-License-Identifier: BSD-3-Clause # -STDLIB_SRCS := $(addprefix lib/stdlib/, \ +LIBC_SRCS := $(addprefix lib/libc/, \ abort.c \ assert.c \ exit.c \ @@ -21,5 +21,5 @@ STDLIB_SRCS := $(addprefix lib/stdlib/, \ subr_prf.c \ timingsafe_bcmp.c) -INCLUDES += -Iinclude/lib/stdlib \ - -Iinclude/lib/stdlib/sys +INCLUDES += -Iinclude/lib/libc \ + -Iinclude/lib/libc/sys diff --git a/lib/stdlib/mem.c b/lib/libc/mem.c similarity index 100% rename from lib/stdlib/mem.c rename to lib/libc/mem.c diff --git a/lib/stdlib/printf.c b/lib/libc/printf.c similarity index 100% rename from lib/stdlib/printf.c rename to lib/libc/printf.c diff --git a/lib/stdlib/putchar.c b/lib/libc/putchar.c similarity index 100% rename from lib/stdlib/putchar.c rename to lib/libc/putchar.c diff --git a/lib/stdlib/puts.c b/lib/libc/puts.c similarity index 100% rename from lib/stdlib/puts.c rename to lib/libc/puts.c diff --git a/lib/stdlib/sscanf.c b/lib/libc/sscanf.c similarity index 100% rename from lib/stdlib/sscanf.c rename to lib/libc/sscanf.c diff --git a/lib/stdlib/strchr.c b/lib/libc/strchr.c similarity index 100% rename from lib/stdlib/strchr.c rename to lib/libc/strchr.c diff --git a/lib/stdlib/strcmp.c b/lib/libc/strcmp.c similarity index 100% rename from lib/stdlib/strcmp.c rename to lib/libc/strcmp.c diff --git a/lib/stdlib/strlen.c b/lib/libc/strlen.c similarity index 100% rename from lib/stdlib/strlen.c rename to lib/libc/strlen.c diff --git a/lib/stdlib/strncmp.c b/lib/libc/strncmp.c similarity index 100% rename from lib/stdlib/strncmp.c rename to lib/libc/strncmp.c diff --git a/lib/stdlib/strnlen.c b/lib/libc/strnlen.c similarity index 100% rename from lib/stdlib/strnlen.c rename to lib/libc/strnlen.c diff --git a/lib/stdlib/subr_prf.c b/lib/libc/subr_prf.c similarity index 100% rename from lib/stdlib/subr_prf.c rename to lib/libc/subr_prf.c diff --git a/lib/stdlib/timingsafe_bcmp.c b/lib/libc/timingsafe_bcmp.c similarity index 100% rename from lib/stdlib/timingsafe_bcmp.c rename to lib/libc/timingsafe_bcmp.c From 180c4bc2c04f1fa58c9e4355cb2b204efdf29f52 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 8 May 2018 10:27:10 +0100 Subject: [PATCH 4/8] Create a library file for libmbedtls TF Makefile was linking all the objects files generated for the Mbed TLS library instead of creating a static library that could be used in the linking stage. Change-Id: I8e4cd843ef56033c9d3faeee71601d110b7e4c12 Signed-off-by: Roberto Vargas --- bl1/bl1.mk | 4 +- bl2/bl2.mk | 4 +- drivers/auth/mbedtls/mbedtls_common.mk | 84 +++++++++++++++++++++++--- drivers/auth/mbedtls/mbedtls_crypto.mk | 82 +------------------------ drivers/auth/mbedtls/mbedtls_x509.mk | 6 +- 5 files changed, 78 insertions(+), 102 deletions(-) diff --git a/bl1/bl1.mk b/bl1/bl1.mk index 41ee1a736..9a46a3483 100644 --- a/bl1/bl1.mk +++ b/bl1/bl1.mk @@ -14,9 +14,7 @@ BL1_SOURCES += bl1/bl1_main.c \ lib/el3_runtime/${ARCH}/context_mgmt.c \ plat/common/plat_bl1_common.c \ plat/common/${ARCH}/platform_up_stack.S \ - ${MBEDTLS_COMMON_SOURCES} \ - ${MBEDTLS_CRYPTO_SOURCES} \ - ${MBEDTLS_X509_SOURCES} + ${MBEDTLS_SOURCES} ifeq (${ARCH},aarch64) BL1_SOURCES += lib/el3_runtime/aarch64/context.S diff --git a/bl2/bl2.mk b/bl2/bl2.mk index a856fb738..7e337030f 100644 --- a/bl2/bl2.mk +++ b/bl2/bl2.mk @@ -8,9 +8,7 @@ BL2_SOURCES += bl2/bl2_main.c \ bl2/${ARCH}/bl2_arch_setup.c \ lib/locks/exclusive/${ARCH}/spinlock.S \ plat/common/${ARCH}/platform_up_stack.S \ - ${MBEDTLS_COMMON_SOURCES} \ - ${MBEDTLS_CRYPTO_SOURCES} \ - ${MBEDTLS_X509_SOURCES} + ${MBEDTLS_SOURCES} ifeq (${ARCH},aarch64) BL2_SOURCES += common/aarch64/early_exceptions.S diff --git a/drivers/auth/mbedtls/mbedtls_common.mk b/drivers/auth/mbedtls/mbedtls_common.mk index a5d19e6a9..67a5da2b1 100644 --- a/drivers/auth/mbedtls/mbedtls_common.mk +++ b/drivers/auth/mbedtls/mbedtls_common.mk @@ -20,15 +20,79 @@ INCLUDES += -I${MBEDTLS_DIR}/include \ MBEDTLS_CONFIG_FILE := "" $(eval $(call add_define,MBEDTLS_CONFIG_FILE)) -MBEDTLS_COMMON_SOURCES := drivers/auth/mbedtls/mbedtls_common.c \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - asn1parse.c \ - asn1write.c \ - memory_buffer_alloc.c \ - oid.c \ - platform.c \ - platform_util.c \ - rsa_internal.c \ - ) +MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_common.c + + +LIBMBEDTLS_SRCS := $(addprefix ${MBEDTLS_DIR}/library/, \ + asn1parse.c \ + asn1write.c \ + memory_buffer_alloc.c \ + oid.c \ + platform.c \ + platform_util.c \ + bignum.c \ + md.c \ + md_wrap.c \ + pk.c \ + pk_wrap.c \ + pkparse.c \ + pkwrite.c \ + sha256.c \ + sha512.c \ + ecdsa.c \ + ecp_curves.c \ + ecp.c \ + rsa.c \ + rsa_internal.c \ + x509.c \ + x509_crt.c \ + ) + +# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key +# algorithm to use. If the variable is not defined, select it based on algorithm +# used for key generation `KEY_ALG`. If `KEY_ALG` is not defined or is +# defined to `rsa`/`rsa_1_5`, then set the variable to `rsa`. +ifeq (${TF_MBEDTLS_KEY_ALG},) + ifeq (${KEY_ALG}, ecdsa) + TF_MBEDTLS_KEY_ALG := ecdsa + else + TF_MBEDTLS_KEY_ALG := rsa + endif +endif + +# If MBEDTLS_KEY_ALG build flag is defined use it to set TF_MBEDTLS_KEY_ALG for +# backward compatibility +ifdef MBEDTLS_KEY_ALG + ifeq (${ERROR_DEPRECATED},1) + $(error "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") + endif + $(warning "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") + TF_MBEDTLS_KEY_ALG := ${MBEDTLS_KEY_ALG} +endif + +ifeq (${HASH_ALG}, sha384) + TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 +else ifeq (${HASH_ALG}, sha512) + TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 +else + TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 +endif + +ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) + TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA +else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) + TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA +else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) + TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA +else + $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") +endif + +# Needs to be set to drive mbed TLS configuration correctly +$(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID)) +$(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID)) + + +$(eval $(call MAKE_LIB,mbedtls)) endif diff --git a/drivers/auth/mbedtls/mbedtls_crypto.mk b/drivers/auth/mbedtls/mbedtls_crypto.mk index 6b15e717d..2a9fbbf99 100644 --- a/drivers/auth/mbedtls/mbedtls_crypto.mk +++ b/drivers/auth/mbedtls/mbedtls_crypto.mk @@ -6,86 +6,6 @@ include drivers/auth/mbedtls/mbedtls_common.mk -# The platform may define the variable 'TF_MBEDTLS_KEY_ALG' to select the key -# algorithm to use. If the variable is not defined, select it based on algorithm -# used for key generation `KEY_ALG`. If `KEY_ALG` is not defined or is -# defined to `rsa`/`rsa_1_5`, then set the variable to `rsa`. -ifeq (${TF_MBEDTLS_KEY_ALG},) - ifeq (${KEY_ALG}, ecdsa) - TF_MBEDTLS_KEY_ALG := ecdsa - else - TF_MBEDTLS_KEY_ALG := rsa - endif -endif +MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_crypto.c -# If MBEDTLS_KEY_ALG build flag is defined use it to set TF_MBEDTLS_KEY_ALG for -# backward compatibility -ifdef MBEDTLS_KEY_ALG - ifeq (${ERROR_DEPRECATED},1) - $(error "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") - endif - $(warning "MBEDTLS_KEY_ALG is deprecated. Please use the new build flag TF_MBEDTLS_KEY_ALG") - TF_MBEDTLS_KEY_ALG := ${MBEDTLS_KEY_ALG} -endif -MBEDTLS_CRYPTO_SOURCES := drivers/auth/mbedtls/mbedtls_crypto.c \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - bignum.c \ - md.c \ - md_wrap.c \ - pk.c \ - pk_wrap.c \ - pkparse.c \ - pkwrite.c \ - ) - -ifeq (${HASH_ALG}, sha384) - MBEDTLS_CRYPTO_SOURCES += \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - sha256.c \ - sha512.c \ - ) - TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA384 -else ifeq (${HASH_ALG}, sha512) - MBEDTLS_CRYPTO_SOURCES += \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - sha256.c \ - sha512.c \ - ) - TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA512 -else - MBEDTLS_CRYPTO_SOURCES += \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - sha256.c \ - ) - TF_MBEDTLS_HASH_ALG_ID := TF_MBEDTLS_SHA256 -endif - -# Key algorithm specific files -MBEDTLS_ECDSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ - ecdsa.c \ - ecp_curves.c \ - ecp.c \ - ) - -MBEDTLS_RSA_CRYPTO_SOURCES += $(addprefix ${MBEDTLS_DIR}/library/, \ - rsa.c \ - ) - -ifeq (${TF_MBEDTLS_KEY_ALG},ecdsa) - MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) - TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_ECDSA -else ifeq (${TF_MBEDTLS_KEY_ALG},rsa) - MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) - TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA -else ifeq (${TF_MBEDTLS_KEY_ALG},rsa+ecdsa) - MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_ECDSA_CRYPTO_SOURCES) - MBEDTLS_CRYPTO_SOURCES += $(MBEDTLS_RSA_CRYPTO_SOURCES) - TF_MBEDTLS_KEY_ALG_ID := TF_MBEDTLS_RSA_AND_ECDSA -else - $(error "TF_MBEDTLS_KEY_ALG=${TF_MBEDTLS_KEY_ALG} not supported on mbed TLS") -endif - -# Needs to be set to drive mbed TLS configuration correctly -$(eval $(call add_define,TF_MBEDTLS_KEY_ALG_ID)) -$(eval $(call add_define,TF_MBEDTLS_HASH_ALG_ID)) diff --git a/drivers/auth/mbedtls/mbedtls_x509.mk b/drivers/auth/mbedtls/mbedtls_x509.mk index a6f72e678..a0557e20a 100644 --- a/drivers/auth/mbedtls/mbedtls_x509.mk +++ b/drivers/auth/mbedtls/mbedtls_x509.mk @@ -6,8 +6,4 @@ include drivers/auth/mbedtls/mbedtls_common.mk -MBEDTLS_X509_SOURCES := drivers/auth/mbedtls/mbedtls_x509_parser.c \ - $(addprefix ${MBEDTLS_DIR}/library/, \ - x509.c \ - x509_crt.c \ - ) +MBEDTLS_SOURCES += drivers/auth/mbedtls/mbedtls_x509_parser.c From ea7a57a3a5963a5c8a67bfd42b4f6ad1472b46f3 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Mon, 4 Jun 2018 15:15:04 +0100 Subject: [PATCH 5/8] Don't include mbebtls include paths in INCLUDES Mbebtls include paths are controlled by the user using the variable MBEDTLS_DIR and they are out of the TF source tree. Since these includes have a different origin it is better to move them to a different variable. This change makes easier for the romlib Makefile to parse the include paths. Change-Id: I3e4c99300f1012bc7f88c6b9f5bc0ec1f7b5aa8d Signed-off-by: Roberto Vargas --- Makefile | 2 +- drivers/auth/mbedtls/mbedtls_common.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9c0ab722e..8a1ff9441 100644 --- a/Makefile +++ b/Makefile @@ -172,7 +172,7 @@ TF_CFLAGS_aarch64 += -mgeneral-regs-only -mstrict-align ASFLAGS_aarch32 = $(march32-directive) ASFLAGS_aarch64 = -march=armv8-a -CPPFLAGS = ${DEFINES} ${INCLUDES} -nostdinc \ +CPPFLAGS = ${DEFINES} ${INCLUDES} ${MBEDTLS_INC} -nostdinc \ -Wmissing-include-dirs -Werror ASFLAGS += $(CPPFLAGS) $(ASFLAGS_$(ARCH)) \ -D__ASSEMBLY__ -ffreestanding \ diff --git a/drivers/auth/mbedtls/mbedtls_common.mk b/drivers/auth/mbedtls/mbedtls_common.mk index 67a5da2b1..71c496eda 100644 --- a/drivers/auth/mbedtls/mbedtls_common.mk +++ b/drivers/auth/mbedtls/mbedtls_common.mk @@ -13,8 +13,8 @@ ifeq (${MBEDTLS_DIR},) $(error Error: MBEDTLS_DIR not set) endif -INCLUDES += -I${MBEDTLS_DIR}/include \ - -Iinclude/drivers/auth/mbedtls +MBEDTLS_INC = -I${MBEDTLS_DIR}/include +INCLUDES += -Iinclude/drivers/auth/mbedtls # Specify mbed TLS configuration file MBEDTLS_CONFIG_FILE := "" From 6c3733456706809d5c9fb78a9746bf2fa484fb91 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Thu, 24 May 2018 13:34:53 +0100 Subject: [PATCH 6/8] Add atexit function to libc We had exit but we didn't have atexit, and we were calling panic and tf_printf from exit, which generated a dependency from exit to them. Having atexit allows to set a different function pointer in every image. Change-Id: I95b9556d680d96249ed3b14da159b6f417da7661 Signed-off-by: Roberto Vargas --- bl2u/bl2u_main.c | 1 + drivers/auth/mbedtls/mbedtls_common.c | 10 ++++++++++ lib/libc/exit.c | 20 ++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/bl2u/bl2u_main.c b/bl2u/bl2u_main.c index a7e3fb916..b29d57e9d 100644 --- a/bl2u/bl2u_main.c +++ b/bl2u/bl2u_main.c @@ -17,6 +17,7 @@ #include #include + /******************************************************************************* * This function is responsible to: * Load SCP_BL2U if platform has defined SCP_BL2U_BASE diff --git a/drivers/auth/mbedtls/mbedtls_common.c b/drivers/auth/mbedtls/mbedtls_common.c index c048d005a..64dc1967d 100644 --- a/drivers/auth/mbedtls/mbedtls_common.c +++ b/drivers/auth/mbedtls/mbedtls_common.c @@ -5,6 +5,7 @@ */ #include +#include /* mbed TLS headers */ #include @@ -23,6 +24,12 @@ #endif static unsigned char heap[MBEDTLS_HEAP_SIZE]; +static void cleanup(void) +{ + ERROR("EXIT from BL2\n"); + panic(); +} + /* * mbed TLS initialization function */ @@ -31,6 +38,9 @@ void mbedtls_init(void) static int ready; if (!ready) { + if (atexit(cleanup)) + panic(); + /* Initialize the mbed TLS heap */ mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE); diff --git a/lib/libc/exit.c b/lib/libc/exit.c index afc3f9343..b2fde9ca2 100644 --- a/lib/libc/exit.c +++ b/lib/libc/exit.c @@ -4,11 +4,23 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include #include -void exit(int v) +static void (*exitfun)(void); + +void exit(int status) { - ERROR("EXIT\n"); - panic(); + if (exitfun) + (*exitfun)(); + for (;;) + ; +} + +int atexit(void (*fun)(void)) +{ + if (exitfun) + return -1; + exitfun = fun; + + return 0; } From 5accce5bcc211c08e80c638acbd01099af81cc37 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Tue, 22 May 2018 16:05:42 +0100 Subject: [PATCH 7/8] Add support for romlib in the build system Romlib is a new image that is stored in ROM and contains the code of several libraries that can be shared between different images. All the functions within in the library are accessed using a jump table which allows to update the romlib image whithout changing the binary compatibility. This jump table can be also stored in RAM and it can allow to patch a romlib with potential bugs fixes.. Change-Id: If980ccdaca24b7aaca900e32acc68baf6f94ab35 Signed-off-by: Roberto Vargas --- Makefile | 13 ++++++- include/common/romlib.h | 15 ++++++++ lib/romlib/Makefile | 71 ++++++++++++++++++++++++++++++++++++ lib/romlib/gentbl.sh | 40 ++++++++++++++++++++ lib/romlib/genvar.sh | 36 ++++++++++++++++++ lib/romlib/genwrappers.sh | 52 ++++++++++++++++++++++++++ lib/romlib/init.s | 30 +++++++++++++++ lib/romlib/jmptbl.i | 35 ++++++++++++++++++ lib/romlib/romlib.ld.S | 44 ++++++++++++++++++++++ make_helpers/build_macros.mk | 22 ++++++++--- make_helpers/defaults.mk | 3 ++ 11 files changed, 355 insertions(+), 6 deletions(-) create mode 100644 include/common/romlib.h create mode 100644 lib/romlib/Makefile create mode 100755 lib/romlib/gentbl.sh create mode 100755 lib/romlib/genvar.sh create mode 100755 lib/romlib/genwrappers.sh create mode 100644 lib/romlib/init.s create mode 100644 lib/romlib/jmptbl.i create mode 100644 lib/romlib/romlib.ld.S diff --git a/Makefile b/Makefile index 8a1ff9441..18c487342 100644 --- a/Makefile +++ b/Makefile @@ -505,6 +505,9 @@ CRTTOOL ?= ${CRTTOOLPATH}/cert_create${BIN_EXT} FIPTOOLPATH ?= tools/fiptool FIPTOOL ?= ${FIPTOOLPATH}/fiptool${BIN_EXT} +# Variables for use with ROMLIB +ROMLIBPATH ?= lib/romlib + ################################################################################ # Include BL specific makefiles ################################################################################ @@ -573,6 +576,7 @@ $(eval $(call assert_boolean,SEPARATE_CODE_AND_RODATA)) $(eval $(call assert_boolean,SPIN_ON_BL1_EXIT)) $(eval $(call assert_boolean,TRUSTED_BOARD_BOOT)) $(eval $(call assert_boolean,USE_COHERENT_MEM)) +$(eval $(call assert_boolean,USE_ROMLIB)) $(eval $(call assert_boolean,USE_TBBR_DEFS)) $(eval $(call assert_boolean,WARMBOOT_ENABLE_DCACHE_EARLY)) $(eval $(call assert_boolean,BL2_AT_EL3)) @@ -625,6 +629,7 @@ $(eval $(call add_define,SPD_${SPD})) $(eval $(call add_define,SPIN_ON_BL1_EXIT)) $(eval $(call add_define,TRUSTED_BOARD_BOOT)) $(eval $(call add_define,USE_COHERENT_MEM)) +$(eval $(call add_define,USE_ROMLIB)) $(eval $(call add_define,USE_TBBR_DEFS)) $(eval $(call add_define,WARMBOOT_ENABLE_DCACHE_EARLY)) $(eval $(call add_define,BL2_AT_EL3)) @@ -669,7 +674,7 @@ ifeq (${ERROR_DEPRECATED},0) CPPFLAGS += -Wno-error=deprecated-declarations -Wno-error=cpp endif -$(eval $(call MAKE_LIB_DIR)) +$(eval $(call MAKE_LIB_DIRS)) $(eval $(call MAKE_LIB,c)) # Expand build macros for the different images @@ -736,6 +741,7 @@ clean: $(call SHELL_REMOVE_DIR,${BUILD_PLAT}) ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean + ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean realclean distclean: @echo " REALCLEAN" @@ -743,6 +749,7 @@ realclean distclean: $(call SHELL_DELETE_ALL, ${CURDIR}/cscope.*) ${Q}${MAKE} --no-print-directory -C ${FIPTOOLPATH} clean ${Q}${MAKE} PLAT=${PLAT} --no-print-directory -C ${CRTTOOLPATH} clean + ${Q}${MAKE} --no-print-directory -C ${ROMLIBPATH} clean checkcodebase: locate-checkpatch @echo " CHECKING STYLE" @@ -821,6 +828,10 @@ fwu_fip: ${BUILD_PLAT}/${FWU_FIP_NAME} ${FIPTOOL}: ${Q}${MAKE} CPPFLAGS="-DVERSION='\"${VERSION_STRING}\"'" --no-print-directory -C ${FIPTOOLPATH} +.PHONY: libraries +romlib.bin: libraries + ${Q}${MAKE} BUILD_PLAT=${BUILD_PLAT} INCLUDES='${INCLUDES}' DEFINES='${DEFINES}' --no-print-directory -C ${ROMLIBPATH} all + cscope: @echo " CSCOPE" ${Q}find ${CURDIR} -name "*.[chsS]" > cscope.files diff --git a/include/common/romlib.h b/include/common/romlib.h new file mode 100644 index 000000000..81a6f5c1e --- /dev/null +++ b/include/common/romlib.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ROMLIB_H_ + +#define ROMLIB_MAJOR 0 +#define ROMLIB_MINOR 1 +#define ROMLIB_VERSION ((ROMLIB_MAJOR << 8) | ROMLIB_MINOR) + +int rom_lib_init(int version); + +#endif diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile new file mode 100644 index 000000000..46b920682 --- /dev/null +++ b/lib/romlib/Makefile @@ -0,0 +1,71 @@ +# +# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +AS = $(CROSS_COMPILE)as +LD = $(CROSS_COMPILE)ld +OC = $(CROSS_COMPILE)objcopy +CPP = $(CROSS_COMPILE)cpp +BUILD_DIR = ../../$(BUILD_PLAT)/romlib +LIB_DIR = ../../$(BUILD_PLAT)/lib +WRAPPER_DIR = ../../$(BUILD_PLAT)/libwrapper +LIBS = -lmbedtls -lfdt -lc +INC = $(INCLUDES:-I%=-I../../%) +PPFLAGS = $(INC) $(DEFINES) -P -D__ASSEMBLY__ -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld +OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o + +V ?= 0 +ifeq ($(V),0) + Q := @ +else + Q := +endif + +ifeq ($(DEBUG),1) + CFLAGS := -g + LDFLAGS := -g +endif + + +.PHONY: all clean distclean + +all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a + +%.o: %.s + @echo " AS $@" + $(Q)$(AS) $(ASFLAGS) -o $@ $< + +$(BUILD_DIR)/%.o: %.s + @echo " AS $@" + $(Q)$(AS) $(ASFLAGS) -o $@ $< + +$(BUILD_DIR)/romlib.ld: romlib.ld.S + @echo " PP $@" + $(Q)$(CPP) $(PPFLAGS) -o $@ romlib.ld.S + +$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld + @echo " LD $@" + $(Q)$(LD) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) + +$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf + @echo " BIN $@" + $(Q)$(OC) -O binary $(BUILD_DIR)/romlib.elf $@ + +$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf + @echo " VAR $@" + $(Q)./genvar.sh -o $@ $(BUILD_DIR)/romlib.elf + +$(LIB_DIR)/libwrappers.a: jmptbl.i $(WRAPPER_DIR)/jmpvar.o + @echo " AR $@" + $(Q)./genwrappers.sh -b $(WRAPPER_DIR) -o $@ jmptbl.i + +$(BUILD_DIR)/jmptbl.s: jmptbl.i + @echo " TBL $@" + $(Q)./gentbl.sh -o $@ jmptbl.i + +clean: + @rm -f $(BUILD_DIR)/* + +-include $(BUILD_DIR)/romlib.d diff --git a/lib/romlib/gentbl.sh b/lib/romlib/gentbl.sh new file mode 100755 index 000000000..0695f6e4f --- /dev/null +++ b/lib/romlib/gentbl.sh @@ -0,0 +1,40 @@ +#!/bin/sh +# Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause + +set -e + +output=jmptbl.s + +for i +do + case $i in + -o) + output=$2 + shift 2 + ;; + --) + shift + break + ;; + -*) + echo usage: gentbl.sh [-o output] file ... >&2 + exit 1 + ;; + esac +done + +tmp=`mktemp` +trap "rm -f $tmp" EXIT INT QUIT + +rm -f $output + +awk -v OFS="\n" ' +BEGIN {print "\t.text", + "\t.globl\tjmptbl", + "jmptbl:"} + {sub(/[:blank:]*#.*/,"")} +!/^$/ {print "\tb\t" $3}' "$@" > $tmp + +mv $tmp $output diff --git a/lib/romlib/genvar.sh b/lib/romlib/genvar.sh new file mode 100755 index 000000000..a3e2cdf69 --- /dev/null +++ b/lib/romlib/genvar.sh @@ -0,0 +1,36 @@ +#!/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 diff --git a/lib/romlib/genwrappers.sh b/lib/romlib/genwrappers.sh new file mode 100755 index 000000000..bcf670b98 --- /dev/null +++ b/lib/romlib/genwrappers.sh @@ -0,0 +1,52 @@ +#!/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 < $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 diff --git a/lib/romlib/init.s b/lib/romlib/init.s new file mode 100644 index 000000000..5cf2aca04 --- /dev/null +++ b/lib/romlib/init.s @@ -0,0 +1,30 @@ +/* + * 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 diff --git a/lib/romlib/jmptbl.i b/lib/romlib/jmptbl.i new file mode 100644 index 000000000..338cd8a71 --- /dev/null +++ b/lib/romlib/jmptbl.i @@ -0,0 +1,35 @@ +# +# 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 diff --git a/lib/romlib/romlib.ld.S b/lib/romlib/romlib.ld.S new file mode 100644 index 000000000..8f0bc62bc --- /dev/null +++ b/lib/romlib/romlib.ld.S @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include + +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); +} diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index ca826941a..92a0f6e86 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -306,12 +306,15 @@ BUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__ .PHONY: libraries - -# MAKE_LIB_DIR macro defines the target for the directory where +# MAKE_LIB_DIRS macro defines the target for the directory where # libraries are created -define MAKE_LIB_DIR +define MAKE_LIB_DIRS $(eval LIB_DIR := ${BUILD_PLAT}/lib) - $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) + $(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. @@ -320,6 +323,7 @@ endef 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)))) @@ -327,11 +331,15 @@ $(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} +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) @@ -378,6 +386,10 @@ bl${1}_dirs: | ${OBJ_DIRS} $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) $(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1))) +ifeq ($(USE_ROMLIB),1) +$(ELF): romlib.bin +endif + $(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs libraries $(BL_LIBS) @echo " LD $$@" ifdef MAKE_BUILD_STRINGS diff --git a/make_helpers/defaults.mk b/make_helpers/defaults.mk index cea853381..e4b5bdc92 100644 --- a/make_helpers/defaults.mk +++ b/make_helpers/defaults.mk @@ -166,6 +166,9 @@ TRUSTED_BOARD_BOOT := 0 # Build option to choose whether Trusted firmware uses Coherent memory or not. 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_DEFS = $(ERROR_DEPRECATED) From 1eb735d75366526c0fdc1acee6a1a78ef6617975 Mon Sep 17 00:00:00 2001 From: Roberto Vargas Date: Wed, 23 May 2018 09:27:06 +0100 Subject: [PATCH 8/8] Add librom support in FVP Change-Id: Idb9ba3864d6de3053260724f07172fd32c1523e0 Signed-off-by: Roberto Vargas --- include/plat/arm/board/common/board_arm_def.h | 17 +++++++++++- include/plat/arm/common/arm_def.h | 26 ++++++++++++++++--- include/plat/arm/common/plat_arm.h | 2 ++ plat/arm/board/juno/include/platform_def.h | 11 ++++++++ plat/arm/common/arm_bl1_setup.c | 6 +++++ plat/arm/common/arm_bl2_setup.c | 6 +++++ plat/arm/common/arm_bl2u_setup.c | 5 ++++ plat/arm/common/arm_bl31_setup.c | 11 ++++++++ plat/arm/common/arm_common.c | 12 ++++++++- 9 files changed, 91 insertions(+), 5 deletions(-) diff --git a/include/plat/arm/board/common/board_arm_def.h b/include/plat/arm/board/common/board_arm_def.h index c3ae5643b..a388ed9ac 100644 --- a/include/plat/arm/board/common/board_arm_def.h +++ b/include/plat/arm/board/common/board_arm_def.h @@ -71,9 +71,12 @@ #elif defined(IMAGE_BL32) # define PLAT_ARM_MMAP_ENTRIES 8 # define MAX_XLAT_TABLES 5 -#else +#elif !USE_ROMLIB # define PLAT_ARM_MMAP_ENTRIES 11 # define MAX_XLAT_TABLES 5 +#else +# define PLAT_ARM_MMAP_ENTRIES 12 +# define MAX_XLAT_TABLES 6 #endif /* @@ -82,6 +85,18 @@ */ #define PLAT_ARM_MAX_BL1_RW_SIZE 0xB000 +/* + * PLAT_ARM_MAX_ROMLIB_RW_SIZE is define to use a full page + */ + +#if USE_ROMLIB +#define PLAT_ARM_MAX_ROMLIB_RW_SIZE 0x1000 +#define PLAT_ARM_MAX_ROMLIB_RO_SIZE 0xe000 +#else +#define PLAT_ARM_MAX_ROMLIB_RW_SIZE 0 +#define PLAT_ARM_MAX_ROMLIB_RO_SIZE 0 +#endif + /* * PLAT_ARM_MAX_BL2_SIZE is calculated using the current BL2 debug size plus a * little space for growth. diff --git a/include/plat/arm/common/arm_def.h b/include/plat/arm/common/arm_def.h index 47f2ac210..5da8cdb4a 100644 --- a/include/plat/arm/common/arm_def.h +++ b/include/plat/arm/common/arm_def.h @@ -268,6 +268,17 @@ - BL_COHERENT_RAM_BASE, \ MT_DEVICE | MT_RW | MT_SECURE) #endif +#if USE_ROMLIB +#define ARM_MAP_ROMLIB_CODE MAP_REGION_FLAT( \ + ROMLIB_RO_BASE, \ + ROMLIB_RO_LIMIT - ROMLIB_RO_BASE,\ + MT_CODE | MT_SECURE) + +#define ARM_MAP_ROMLIB_DATA MAP_REGION_FLAT( \ + ROMLIB_RW_BASE, \ + ROMLIB_RW_END - ROMLIB_RW_BASE,\ + MT_MEMORY | MT_RW | MT_SECURE) +#endif /* * The max number of regions like RO(code), coherent and data required by @@ -346,14 +357,23 @@ ******************************************************************************/ #define BL1_RO_BASE PLAT_ARM_TRUSTED_ROM_BASE #define BL1_RO_LIMIT (PLAT_ARM_TRUSTED_ROM_BASE \ - + PLAT_ARM_TRUSTED_ROM_SIZE) + + (PLAT_ARM_TRUSTED_ROM_SIZE - \ + PLAT_ARM_MAX_ROMLIB_RO_SIZE)) /* * Put BL1 RW at the top of the Trusted SRAM. */ #define BL1_RW_BASE (ARM_BL_RAM_BASE + \ ARM_BL_RAM_SIZE - \ - PLAT_ARM_MAX_BL1_RW_SIZE) -#define BL1_RW_LIMIT (ARM_BL_RAM_BASE + ARM_BL_RAM_SIZE) + (PLAT_ARM_MAX_BL1_RW_SIZE +\ + PLAT_ARM_MAX_ROMLIB_RW_SIZE)) +#define BL1_RW_LIMIT (ARM_BL_RAM_BASE + \ + (ARM_BL_RAM_SIZE - PLAT_ARM_MAX_ROMLIB_RW_SIZE)) + +#define ROMLIB_RO_BASE BL1_RO_LIMIT +#define ROMLIB_RO_LIMIT (PLAT_ARM_TRUSTED_ROM_BASE + PLAT_ARM_TRUSTED_ROM_SIZE) + +#define ROMLIB_RW_BASE (BL1_RW_BASE + PLAT_ARM_MAX_BL1_RW_SIZE) +#define ROMLIB_RW_END (ROMLIB_RW_BASE + PLAT_ARM_MAX_ROMLIB_RW_SIZE) /******************************************************************************* * BL2 specific defines. diff --git a/include/plat/arm/common/plat_arm.h b/include/plat/arm/common/plat_arm.h index 506bed348..1af4dd1ac 100644 --- a/include/plat/arm/common/plat_arm.h +++ b/include/plat/arm/common/plat_arm.h @@ -72,6 +72,8 @@ typedef struct arm_tzc_regions_info { void arm_setup_page_tables(const mmap_region_t bl_regions[], const mmap_region_t plat_regions[]); +void arm_setup_romlib(void); + #if defined(IMAGE_BL31) || (defined(AARCH32) && defined(IMAGE_BL32)) /* * Use this macro to instantiate lock before it is used in below diff --git a/plat/arm/board/juno/include/platform_def.h b/plat/arm/board/juno/include/platform_def.h index a781c4f09..3f71d7355 100644 --- a/plat/arm/board/juno/include/platform_def.h +++ b/plat/arm/board/juno/include/platform_def.h @@ -67,6 +67,8 @@ * in debug mode. We can test TBB on Juno bypassing the ROM and using 128 KB of * flash */ +#define PLAT_ARM_MAX_ROMLIB_RO_SIZE 0 + #if TRUSTED_BOARD_BOOT #define PLAT_ARM_TRUSTED_ROM_SIZE 0x00020000 #else @@ -122,6 +124,15 @@ # define PLAT_ARM_MAX_BL1_RW_SIZE 0x6000 #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 * little space for growth. diff --git a/plat/arm/common/arm_bl1_setup.c b/plat/arm/common/arm_bl1_setup.c index a192a0635..d442ac2e6 100644 --- a/plat/arm/common/arm_bl1_setup.c +++ b/plat/arm/common/arm_bl1_setup.c @@ -117,6 +117,10 @@ void arm_bl1_plat_arch_setup(void) const mmap_region_t bl_regions[] = { MAP_BL1_TOTAL, MAP_BL1_RO, +#if USE_ROMLIB + ARM_MAP_ROMLIB_CODE, + ARM_MAP_ROMLIB_DATA, + #endif {0} }; @@ -126,6 +130,8 @@ void arm_bl1_plat_arch_setup(void) #else enable_mmu_el3(0); #endif /* AARCH32 */ + + arm_setup_romlib(); } void bl1_plat_arch_setup(void) diff --git a/plat/arm/common/arm_bl2_setup.c b/plat/arm/common/arm_bl2_setup.c index 39aceb3b9..2dd363f74 100644 --- a/plat/arm/common/arm_bl2_setup.c +++ b/plat/arm/common/arm_bl2_setup.c @@ -246,6 +246,10 @@ void arm_bl2_plat_arch_setup(void) const mmap_region_t bl_regions[] = { MAP_BL2_TOTAL, ARM_MAP_BL_RO, +#if USE_ROMLIB + ARM_MAP_ROMLIB_CODE, + ARM_MAP_ROMLIB_DATA, +#endif {0} }; @@ -256,6 +260,8 @@ void arm_bl2_plat_arch_setup(void) #else enable_mmu_el1(0); #endif + + arm_setup_romlib(); } void bl2_plat_arch_setup(void) diff --git a/plat/arm/common/arm_bl2u_setup.c b/plat/arm/common/arm_bl2u_setup.c index a62683023..c475b12ca 100644 --- a/plat/arm/common/arm_bl2u_setup.c +++ b/plat/arm/common/arm_bl2u_setup.c @@ -73,6 +73,10 @@ void arm_bl2u_plat_arch_setup(void) const mmap_region_t bl_regions[] = { MAP_BL2U_TOTAL, ARM_MAP_BL_RO, +#if USE_ROMLIB + ARM_MAP_ROMLIB_CODE, + ARM_MAP_ROMLIB_DATA, +#endif {0} }; @@ -83,6 +87,7 @@ void arm_bl2u_plat_arch_setup(void) #else enable_mmu_el1(0); #endif + arm_setup_romlib(); } void bl2u_plat_arch_setup(void) diff --git a/plat/arm/common/arm_bl31_setup.c b/plat/arm/common/arm_bl31_setup.c index 0b648049f..c7c45b0d7 100644 --- a/plat/arm/common/arm_bl31_setup.c +++ b/plat/arm/common/arm_bl31_setup.c @@ -285,9 +285,18 @@ void bl31_plat_runtime_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[] = { MAP_BL31_TOTAL, ARM_MAP_BL_RO, +#if USE_ROMLIB + ARM_MAP_ROMLIB_CODE, + ARM_MAP_ROMLIB_DATA, +#endif #if USE_COHERENT_MEM ARM_MAP_BL_COHERENT_RAM, #endif @@ -297,6 +306,8 @@ void arm_bl31_plat_arch_setup(void) arm_setup_page_tables(bl_regions, plat_arm_get_mmap()); enable_mmu_el3(0); + + arm_setup_romlib(); } void bl31_plat_arch_setup(void) diff --git a/plat/arm/common/arm_common.c b/plat/arm/common/arm_common.c index f83005f64..ed43c379d 100644 --- a/plat/arm/common/arm_common.c +++ b/plat/arm/common/arm_common.c @@ -10,8 +10,9 @@ #include #include #include -#include #include +#include +#include #include /* Weak definitions may be overridden in specific ARM standard platform */ @@ -24,6 +25,15 @@ #pragma weak plat_get_syscnt_freq2 #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. * The size of the Trusted SRAM seen by the BL image must be specified as well