From 6baf85b3e01a6c8295a53798bd92e26d517a4196 Mon Sep 17 00:00:00 2001 From: Sathees Balya Date: Thu, 18 Oct 2018 19:14:21 +0100 Subject: [PATCH 1/3] romlib: Allow patching of romlib functions This change allows patching of functions in the romlib. This can be done by adding "patch" at the end of the jump table entry for the function that needs to be patched in the file jmptbl.i. Functions patched in the jump table list will be built as part of the BL image and the romlib version will not be used Change-Id: Iefb200cb86e2a4b61ad3ee6180d3ecc39bad537f Signed-off-by: Sathees Balya --- lib/romlib/genwrappers.sh | 2 +- lib/romlib/jmptbl.i | 6 +++++- make_helpers/build_macros.mk | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/romlib/genwrappers.sh b/lib/romlib/genwrappers.sh index bcf670b98..48ee5a43b 100755 --- a/lib/romlib/genwrappers.sh +++ b/lib/romlib/genwrappers.sh @@ -31,7 +31,7 @@ do done awk '{sub(/[:blank:]*#.*/,"")} -!/^$/ {print $1*4, $2, $3}' "$@" | +!/^$/ && !/\\tpatch$/ {print $1*4, $2, $3}' "$@" | while read idx lib sym do file=$build/${lib}_$sym diff --git a/lib/romlib/jmptbl.i b/lib/romlib/jmptbl.i index 338cd8a71..5e33e0e1b 100644 --- a/lib/romlib/jmptbl.i +++ b/lib/romlib/jmptbl.i @@ -3,6 +3,10 @@ # # SPDX-License-Identifier: BSD-3-Clause # +# Format: +# index lib function [patch] +# Add "patch" at the end of the line to patch a function. For example: +# 14 mbedtls mbedtls_memory_buffer_alloc_init patch 0 rom rom_lib_init 1 fdt fdt_getprop_namelen @@ -32,4 +36,4 @@ 25 mbedtls mbedtls_x509_get_sig_alg 26 mbedtls mbedtls_md_info_from_type 27 c exit -28 c atexit +28 c atexit \ No newline at end of file diff --git a/make_helpers/build_macros.mk b/make_helpers/build_macros.mk index e186fc100..d60a5bf0e 100644 --- a/make_helpers/build_macros.mk +++ b/make_helpers/build_macros.mk @@ -338,7 +338,7 @@ LDPATHS = -L${LIB_DIR} LDLIBS += -l$(1) ifeq ($(USE_ROMLIB),1) -LDLIBS := -lwrappers -lc +LIBWRAPPER = -lwrappers endif all: ${LIB_DIR}/lib$(1).a @@ -402,7 +402,7 @@ else endif $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \ --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \ - $(OBJS) $(LDPATHS) $(LDLIBS) $(BL_LIBS) + $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(DUMP): $(ELF) $${ECHO} " OD $$@" From 032e3a6cd7f866da6a7ef9f6e05dc64649def528 Mon Sep 17 00:00:00 2001 From: Sathees Balya Date: Wed, 14 Nov 2018 11:57:10 +0000 Subject: [PATCH 2/3] romlib: Add calloc_free register function Register functions have to be added to the jump table to allow patching in the future Change-Id: I57a885f7fc6290ea74a6096aea5b1867b2098eb7 Signed-off-by: Sathees Balya --- lib/romlib/jmptbl.i | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/romlib/jmptbl.i b/lib/romlib/jmptbl.i index 5e33e0e1b..5eca5aab3 100644 --- a/lib/romlib/jmptbl.i +++ b/lib/romlib/jmptbl.i @@ -31,9 +31,10 @@ 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 \ No newline at end of file +23 mbedtls mbedtls_platform_set_calloc_free +24 mbedtls mbedtls_platform_set_snprintf +25 mbedtls mbedtls_x509_get_rsassa_pss_params +26 mbedtls mbedtls_x509_get_sig_alg +27 mbedtls mbedtls_md_info_from_type +28 c exit +29 c atexit \ No newline at end of file From 582133a8075b4795e6886c4b711626095f5a80f3 Mon Sep 17 00:00:00 2001 From: Sathees Balya Date: Wed, 14 Nov 2018 11:59:12 +0000 Subject: [PATCH 3/3] romlib: Add map file generation Change-Id: I1f377d2d94c0fe8d2d9e62614f4a8e2dfcd9e745 Signed-off-by: Sathees Balya --- lib/romlib/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/romlib/Makefile b/lib/romlib/Makefile index 46b920682..00dde31cd 100644 --- a/lib/romlib/Makefile +++ b/lib/romlib/Makefile @@ -15,6 +15,7 @@ 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 +MAPFILE = ../../$(BUILD_PLAT)/romlib/romlib.map V ?= 0 ifeq ($(V),0) @@ -25,7 +26,7 @@ endif ifeq ($(DEBUG),1) CFLAGS := -g - LDFLAGS := -g + LDFLAGS := -g --gc-sections -O1 -Map=$(MAPFILE) endif