173c99d4eSJuan Castillo# 2802d2dd2SMasahiro Yamada# Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. 373c99d4eSJuan Castillo# 482cb2c1aSdp-arm# SPDX-License-Identifier: BSD-3-Clause 573c99d4eSJuan Castillo# 673c99d4eSJuan Castillo 71670d9dfSEvan Lloyd# Report an error if the eval make function is not available. 81670d9dfSEvan Lloyd$(eval eval_available := T) 91670d9dfSEvan Lloydifneq (${eval_available},T) 101670d9dfSEvan Lloyd $(error This makefile only works with a Make program that supports $$(eval)) 111670d9dfSEvan Lloydendif 121670d9dfSEvan Lloyd 13231c1470SEvan Lloyd# Some utility macros for manipulating awkward (whitespace) characters. 14231c1470SEvan Lloydblank := 15231c1470SEvan Lloydspace :=${blank} ${blank} 16231c1470SEvan Lloyd 17231c1470SEvan Lloyd# A user defined function to recursively search for a filename below a directory 18231c1470SEvan Lloyd# $1 is the directory root of the recursive search (blank for current directory). 19231c1470SEvan Lloyd# $2 is the file name to search for. 20231c1470SEvan Lloyddefine rwildcard 21231c1470SEvan Lloyd$(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d}))) 22231c1470SEvan Lloydendef 23231c1470SEvan Lloyd 245ba8f669SYatharth Kochar# This table is used in converting lower case to upper case. 255ba8f669SYatharth Kocharuppercase_table:=a,A b,B c,C d,D e,E f,F g,G h,H i,I j,J k,K l,L m,M n,N o,O p,P q,Q r,R s,S t,T u,U v,V w,W x,X y,Y z,Z 265ba8f669SYatharth Kochar 275ba8f669SYatharth Kochar# Internal macro used for converting lower case to upper case. 285ba8f669SYatharth Kochar# $(1) = upper case table 295ba8f669SYatharth Kochar# $(2) = String to convert 305ba8f669SYatharth Kochardefine uppercase_internal 315ba8f669SYatharth Kochar$(if $(1),$$(subst $(firstword $(1)),$(call uppercase_internal,$(wordlist 2,$(words $(1)),$(1)),$(2))),$(2)) 325ba8f669SYatharth Kocharendef 335ba8f669SYatharth Kochar 345ba8f669SYatharth Kochar# A macro for converting a string to upper case 355ba8f669SYatharth Kochar# $(1) = String to convert 365ba8f669SYatharth Kochardefine uppercase 375ba8f669SYatharth Kochar$(eval uppercase_result:=$(call uppercase_internal,$(uppercase_table),$(1)))$(uppercase_result) 385ba8f669SYatharth Kocharendef 395ba8f669SYatharth Kochar 4073c99d4eSJuan Castillo# Convenience function for adding build definitions 4173c99d4eSJuan Castillo# $(eval $(call add_define,FOO)) will have: 4273c99d4eSJuan Castillo# -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise 4373c99d4eSJuan Castillodefine add_define 4473c99d4eSJuan Castillo DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) 4573c99d4eSJuan Castilloendef 4673c99d4eSJuan Castillo 478eadeb4aSSoren Brinkmann# Convenience function for adding build definitions 488eadeb4aSSoren Brinkmann# $(eval $(call add_define_val,FOO,BAR)) will have: 498eadeb4aSSoren Brinkmann# -DFOO=BAR 508eadeb4aSSoren Brinkmanndefine add_define_val 518eadeb4aSSoren Brinkmann DEFINES += -D$(1)=$(2) 528eadeb4aSSoren Brinkmannendef 538eadeb4aSSoren Brinkmann 5473c99d4eSJuan Castillo# Convenience function for verifying option has a boolean value 5573c99d4eSJuan Castillo# $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 5673c99d4eSJuan Castillodefine assert_boolean 57be4cd40eSMasahiro Yamada $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) 5873c99d4eSJuan Castilloendef 5973c99d4eSJuan Castillo 60c877b414SJeenu Viswambharan0-9 := 0 1 2 3 4 5 6 7 8 9 61c877b414SJeenu Viswambharan 62c877b414SJeenu Viswambharan# Function to verify that a given option $(1) contains a numeric value 63c877b414SJeenu Viswambharandefine assert_numeric 64c877b414SJeenu Viswambharan$(if $($(1)),,$(error $(1) must not be empty)) 65c877b414SJeenu Viswambharan$(eval __numeric := $($(1))) 66c877b414SJeenu Viswambharan$(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) 67c877b414SJeenu Viswambharan$(if $(__numeric),$(error $(1) must be numeric)) 68c877b414SJeenu Viswambharanendef 69c877b414SJeenu Viswambharan 7073c99d4eSJuan Castillo# IMG_LINKERFILE defines the linker script corresponding to a BL stage 7173c99d4eSJuan Castillo# $(1) = BL stage (2, 30, 31, 32, 33) 7273c99d4eSJuan Castillodefine IMG_LINKERFILE 7373c99d4eSJuan Castillo ${BUILD_DIR}/bl$(1).ld 7473c99d4eSJuan Castilloendef 7573c99d4eSJuan Castillo 7673c99d4eSJuan Castillo# IMG_MAPFILE defines the output file describing the memory map corresponding 7773c99d4eSJuan Castillo# to a BL stage 7873c99d4eSJuan Castillo# $(1) = BL stage (2, 30, 31, 32, 33) 7973c99d4eSJuan Castillodefine IMG_MAPFILE 8073c99d4eSJuan Castillo ${BUILD_DIR}/bl$(1).map 8173c99d4eSJuan Castilloendef 8273c99d4eSJuan Castillo 8373c99d4eSJuan Castillo# IMG_ELF defines the elf file corresponding to a BL stage 8473c99d4eSJuan Castillo# $(1) = BL stage (2, 30, 31, 32, 33) 8573c99d4eSJuan Castillodefine IMG_ELF 8673c99d4eSJuan Castillo ${BUILD_DIR}/bl$(1).elf 8773c99d4eSJuan Castilloendef 8873c99d4eSJuan Castillo 8973c99d4eSJuan Castillo# IMG_DUMP defines the symbols dump file corresponding to a BL stage 9073c99d4eSJuan Castillo# $(1) = BL stage (2, 30, 31, 32, 33) 9173c99d4eSJuan Castillodefine IMG_DUMP 9273c99d4eSJuan Castillo ${BUILD_DIR}/bl$(1).dump 9373c99d4eSJuan Castilloendef 9473c99d4eSJuan Castillo 9573c99d4eSJuan Castillo# IMG_BIN defines the default image file corresponding to a BL stage 9673c99d4eSJuan Castillo# $(1) = BL stage (2, 30, 31, 32, 33) 9773c99d4eSJuan Castillodefine IMG_BIN 9873c99d4eSJuan Castillo ${BUILD_PLAT}/bl$(1).bin 9973c99d4eSJuan Castilloendef 10073c99d4eSJuan Castillo 10110cea934SMasahiro Yamada# TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to 10210cea934SMasahiro Yamada# package a new payload and/or by cert_create to generate certificate. 10310cea934SMasahiro Yamada# Optionally, it adds the dependency on this payload 10473c99d4eSJuan Castillo# $(1) = payload filename (i.e. bl31.bin) 1051e0c0784SMasahiro Yamada# $(2) = command line option for the specified payload (i.e. --soc-fw) 10636af3455SMasahiro Yamada# $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1071dc0714fSMasahiro Yamada# $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 10810cea934SMasahiro Yamadadefine TOOL_ADD_PAYLOAD 109945b316fSMasahiro Yamada $(4)FIP_ARGS += $(2) $(1) 110945b316fSMasahiro Yamada $(if $(3),$(4)FIP_DEPS += $(3)) 111f30ee0b9SMasahiro Yamada $(4)CRT_ARGS += $(2) $(1) 112f30ee0b9SMasahiro Yamada $(if $(3),$(4)CRT_DEPS += $(3)) 11373c99d4eSJuan Castilloendef 11473c99d4eSJuan Castillo 1152da522bbSMasahiro Yamada# TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters 1162da522bbSMasahiro Yamada# before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. 1172da522bbSMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 1182da522bbSMasahiro Yamada# $(2) = payload filepath (ex. build/fvp/release/bl31.bin) 1192da522bbSMasahiro Yamada# $(3) = command line option for the specified payload (ex. --soc-fw) 1202da522bbSMasahiro Yamada# $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) 1212da522bbSMasahiro Yamada# $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 1222da522bbSMasahiro Yamada 1232da522bbSMasahiro Yamadadefine TOOL_ADD_IMG_PAYLOAD 1242da522bbSMasahiro Yamada 1252da522bbSMasahiro Yamada$(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER)) 1262da522bbSMasahiro Yamada 1272da522bbSMasahiro Yamadaifneq ($(PRE_TOOL_FILTER),) 1282da522bbSMasahiro Yamada 1292da522bbSMasahiro Yamada$(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) 1302da522bbSMasahiro Yamada 1312da522bbSMasahiro Yamada$(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) 1322da522bbSMasahiro Yamada 1332da522bbSMasahiro Yamada$(PROCESSED_PATH): $(4) 1342da522bbSMasahiro Yamada 1352da522bbSMasahiro Yamada$(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5)) 1362da522bbSMasahiro Yamada 1372da522bbSMasahiro Yamadaelse 1382da522bbSMasahiro Yamada$(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5)) 1392da522bbSMasahiro Yamadaendif 1402da522bbSMasahiro Yamadaendef 1412da522bbSMasahiro Yamada 1420191262dSYatharth Kochar# CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation 14373c99d4eSJuan Castillo# $(1) = parameter filename 14473c99d4eSJuan Castillo# $(2) = cert_create command line option for the specified parameter 14591704d9dSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 14673c99d4eSJuan Castillodefine CERT_ADD_CMD_OPT 14791704d9dSMasahiro Yamada $(3)CRT_ARGS += $(2) $(1) 14873c99d4eSJuan Castilloendef 14973c99d4eSJuan Castillo 150c939d13aSMasahiro Yamada# TOOL_ADD_IMG allows the platform to specify an external image to be packed 151c939d13aSMasahiro Yamada# in the FIP and/or for which certificate is generated. It also adds a 152c939d13aSMasahiro Yamada# dependency on the image file, aborting the build if the file does not exist. 15333950dd8SMasahiro Yamada# $(1) = image_type (scp_bl2, bl33, etc.) 1541e0c0784SMasahiro Yamada# $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) 1551dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 15673c99d4eSJuan Castillo# Example: 15733950dd8SMasahiro Yamada# $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) 158c939d13aSMasahiro Yamadadefine TOOL_ADD_IMG 15933950dd8SMasahiro Yamada # Build option to specify the image filename (SCP_BL2, BL33, etc) 16033950dd8SMasahiro Yamada # This is the uppercase form of the first parameter 16133950dd8SMasahiro Yamada $(eval _V := $(call uppercase,$(1))) 16233950dd8SMasahiro Yamada 163945b316fSMasahiro Yamada $(3)CRT_DEPS += check_$(1) 164945b316fSMasahiro Yamada $(3)FIP_DEPS += check_$(1) 1652da522bbSMasahiro Yamada $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),,$(3)) 1660191262dSYatharth Kochar 16787ebd20dSMasahiro Yamada.PHONY: check_$(1) 1680191262dSYatharth Kocharcheck_$(1): 16933950dd8SMasahiro Yamada $$(if $(value $(_V)),,$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) 17033950dd8SMasahiro Yamada $$(if $(wildcard $(value $(_V))),,$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) 1710191262dSYatharth Kocharendef 17273c99d4eSJuan Castillo 17373c99d4eSJuan Castillo################################################################################ 17414db8908SMasahiro Yamada# Generic image processing filters 17514db8908SMasahiro Yamada################################################################################ 17614db8908SMasahiro Yamada 17714db8908SMasahiro Yamada# GZIP 17814db8908SMasahiro Yamadadefine GZIP_RULE 17914db8908SMasahiro Yamada$(1): $(2) 18014db8908SMasahiro Yamada @echo " GZIP $$@" 18114db8908SMasahiro Yamada $(Q)gzip -n -f -9 $$< --stdout > $$@ 18214db8908SMasahiro Yamadaendef 18314db8908SMasahiro Yamada 18414db8908SMasahiro YamadaGZIP_SUFFIX := .gz 18514db8908SMasahiro Yamada 18614db8908SMasahiro Yamada################################################################################ 18773c99d4eSJuan Castillo# Auxiliary macros to build TF images from sources 18873c99d4eSJuan Castillo################################################################################ 18973c99d4eSJuan Castillo 1901d274ab0SMasahiro YamadaMAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP 19173c99d4eSJuan Castillo 1925fee0287SRoberto Vargas 1935fee0287SRoberto Vargas# MAKE_C_LIB builds a C source file and generates the dependency file 1945fee0287SRoberto Vargas# $(1) = output directory 1955fee0287SRoberto Vargas# $(2) = source file (%.c) 1965fee0287SRoberto Vargas# $(3) = library name 1975fee0287SRoberto Vargasdefine MAKE_C_LIB 1985fee0287SRoberto Vargas$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 1995fee0287SRoberto Vargas$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 2005fee0287SRoberto Vargas 2015fee0287SRoberto Vargas$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs 2025fee0287SRoberto Vargas @echo " CC $$<" 2035fee0287SRoberto Vargas $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@ 2045fee0287SRoberto Vargas 2055fee0287SRoberto Vargas-include $(DEP) 2065fee0287SRoberto Vargas 2075fee0287SRoberto Vargasendef 2085fee0287SRoberto Vargas 2095fee0287SRoberto Vargas 21073c99d4eSJuan Castillo# MAKE_C builds a C source file and generates the dependency file 21173c99d4eSJuan Castillo# $(1) = output directory 21273c99d4eSJuan Castillo# $(2) = source file (%.c) 2135ba8f669SYatharth Kochar# $(3) = BL stage (2, 2u, 30, 31, 32, 33) 21473c99d4eSJuan Castillodefine MAKE_C 21573c99d4eSJuan Castillo 21673c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) 217710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 2185ba8f669SYatharth Kochar$(eval IMAGE := IMAGE_BL$(call uppercase,$(3))) 21973c99d4eSJuan Castillo 2206bc1a30cSStephen Warren$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs 22173c99d4eSJuan Castillo @echo " CC $$<" 222710ea1d0SMasahiro Yamada $$(Q)$$(CC) $$(TF_CFLAGS) $$(CFLAGS) -D$(IMAGE) $(MAKE_DEP) -c $$< -o $$@ 22373c99d4eSJuan Castillo 224710ea1d0SMasahiro Yamada-include $(DEP) 22573c99d4eSJuan Castillo 22673c99d4eSJuan Castilloendef 22773c99d4eSJuan Castillo 22873c99d4eSJuan Castillo 22973c99d4eSJuan Castillo# MAKE_S builds an assembly source file and generates the dependency file 23073c99d4eSJuan Castillo# $(1) = output directory 23173c99d4eSJuan Castillo# $(2) = assembly file (%.S) 2325ba8f669SYatharth Kochar# $(3) = BL stage (2, 2u, 30, 31, 32, 33) 23373c99d4eSJuan Castillodefine MAKE_S 23473c99d4eSJuan Castillo 23573c99d4eSJuan Castillo$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) 236710ea1d0SMasahiro Yamada$(eval DEP := $(patsubst %.o,%.d,$(OBJ))) 2375ba8f669SYatharth Kochar$(eval IMAGE := IMAGE_BL$(call uppercase,$(3))) 23873c99d4eSJuan Castillo 2396bc1a30cSStephen Warren$(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs 24073c99d4eSJuan Castillo @echo " AS $$<" 241710ea1d0SMasahiro Yamada $$(Q)$$(AS) $$(ASFLAGS) -D$(IMAGE) $(MAKE_DEP) -c $$< -o $$@ 24273c99d4eSJuan Castillo 243710ea1d0SMasahiro Yamada-include $(DEP) 24473c99d4eSJuan Castillo 24573c99d4eSJuan Castilloendef 24673c99d4eSJuan Castillo 24773c99d4eSJuan Castillo 24873c99d4eSJuan Castillo# MAKE_LD generate the linker script using the C preprocessor 24973c99d4eSJuan Castillo# $(1) = output linker script 25073c99d4eSJuan Castillo# $(2) = input template 251a6ca7888SMasahiro Yamada# $(3) = BL stage (2, 2u, 30, 31, 32, 33) 25273c99d4eSJuan Castillodefine MAKE_LD 25373c99d4eSJuan Castillo 254710ea1d0SMasahiro Yamada$(eval DEP := $(1).d) 25573c99d4eSJuan Castillo 2566bc1a30cSStephen Warren$(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | bl$(3)_dirs 25773c99d4eSJuan Castillo @echo " PP $$<" 258710ea1d0SMasahiro Yamada $$(Q)$$(CPP) $$(CPPFLAGS) -P -D__ASSEMBLY__ -D__LINKER__ $(MAKE_DEP) -o $$@ $$< 25973c99d4eSJuan Castillo 260710ea1d0SMasahiro Yamada-include $(DEP) 26173c99d4eSJuan Castillo 26273c99d4eSJuan Castilloendef 26373c99d4eSJuan Castillo 2645fee0287SRoberto Vargas# MAKE_LIB_OBJS builds both C source files 2655fee0287SRoberto Vargas# $(1) = output directory 2665fee0287SRoberto Vargas# $(2) = list of source files 2675fee0287SRoberto Vargas# $(3) = name of the library 2685fee0287SRoberto Vargasdefine MAKE_LIB_OBJS 2695fee0287SRoberto Vargas $(eval C_OBJS := $(filter %.c,$(2))) 2705fee0287SRoberto Vargas $(eval REMAIN := $(filter-out %.c,$(2))) 2715fee0287SRoberto Vargas $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3)))) 2725fee0287SRoberto Vargas 2735fee0287SRoberto Vargas $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 2745fee0287SRoberto Vargasendef 2755fee0287SRoberto Vargas 27673c99d4eSJuan Castillo 27773c99d4eSJuan Castillo# MAKE_OBJS builds both C and assembly source files 27873c99d4eSJuan Castillo# $(1) = output directory 27973c99d4eSJuan Castillo# $(2) = list of source files (both C and assembly) 28073c99d4eSJuan Castillo# $(3) = BL stage (2, 30, 31, 32, 33) 28173c99d4eSJuan Castillodefine MAKE_OBJS 28273c99d4eSJuan Castillo $(eval C_OBJS := $(filter %.c,$(2))) 28373c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.c,$(2))) 28473c99d4eSJuan Castillo $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) 28573c99d4eSJuan Castillo 28673c99d4eSJuan Castillo $(eval S_OBJS := $(filter %.S,$(REMAIN))) 28773c99d4eSJuan Castillo $(eval REMAIN := $(filter-out %.S,$(REMAIN))) 28873c99d4eSJuan Castillo $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) 28973c99d4eSJuan Castillo 29073c99d4eSJuan Castillo $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) 29173c99d4eSJuan Castilloendef 29273c99d4eSJuan Castillo 29373c99d4eSJuan Castillo 29473c99d4eSJuan Castillo# NOTE: The line continuation '\' is required in the next define otherwise we 29573c99d4eSJuan Castillo# end up with a line-feed characer at the end of the last c filename. 296e7f54dbdSEvan Lloyd# Also bear this issue in mind if extending the list of supported filetypes. 29773c99d4eSJuan Castillodefine SOURCES_TO_OBJS 29873c99d4eSJuan Castillo $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ 29973c99d4eSJuan Castillo $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) 30073c99d4eSJuan Castilloendef 30173c99d4eSJuan Castillo 3022f5d4a48SPatrick Georgi# Allow overriding the timestamp, for example for reproducible builds, or to 3032f5d4a48SPatrick Georgi# synchronize timestamps across multiple projects. 3042f5d4a48SPatrick Georgi# This must be set to a C string (including quotes where applicable). 3052f5d4a48SPatrick GeorgiBUILD_MESSAGE_TIMESTAMP ?= __TIME__", "__DATE__ 30673c99d4eSJuan Castillo 3075fee0287SRoberto Vargas.PHONY: libraries 3085fee0287SRoberto Vargas 3095accce5bSRoberto Vargas# MAKE_LIB_DIRS macro defines the target for the directory where 3105fee0287SRoberto Vargas# libraries are created 3115accce5bSRoberto Vargasdefine MAKE_LIB_DIRS 3125fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 3135accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 3145accce5bSRoberto Vargas $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper) 3155fee0287SRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) 3165accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT})) 3175accce5bSRoberto Vargas $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT})) 3185fee0287SRoberto Vargasendef 3195fee0287SRoberto Vargas 3205fee0287SRoberto Vargas# MAKE_LIB macro defines the targets and options to build each BL image. 3215fee0287SRoberto Vargas# Arguments: 3225fee0287SRoberto Vargas# $(1) = Library name 3235fee0287SRoberto Vargasdefine MAKE_LIB 3245fee0287SRoberto Vargas $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) 3255fee0287SRoberto Vargas $(eval LIB_DIR := ${BUILD_PLAT}/lib) 3265accce5bSRoberto Vargas $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) 3275fee0287SRoberto Vargas $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS)) 3285fee0287SRoberto Vargas $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 3295fee0287SRoberto Vargas 3305fee0287SRoberto Vargas$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 3315fee0287SRoberto Vargas$(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 3325fee0287SRoberto Vargas 3335fee0287SRoberto Vargas.PHONY : lib${1}_dirs 3345accce5bSRoberto Vargaslib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR} 3355fee0287SRoberto Vargaslibraries: ${LIB_DIR}/lib$(1).a 3365fee0287SRoberto VargasLDPATHS = -L${LIB_DIR} 3375fee0287SRoberto VargasLDLIBS += -l$(1) 3385fee0287SRoberto Vargas 3395accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 3405accce5bSRoberto VargasLDLIBS := -lwrappers -lc 3415accce5bSRoberto Vargasendif 3425accce5bSRoberto Vargas 3435fee0287SRoberto Vargasall: ${LIB_DIR}/lib$(1).a 3445fee0287SRoberto Vargas 3455fee0287SRoberto Vargas${LIB_DIR}/lib$(1).a: $(OBJS) 3465fee0287SRoberto Vargas @echo " AR $$@" 3475fee0287SRoberto Vargas $$(Q)$$(AR) cr $$@ $$? 3485fee0287SRoberto Vargasendef 3495fee0287SRoberto Vargas 35073c99d4eSJuan Castillo# MAKE_BL macro defines the targets and options to build each BL image. 35173c99d4eSJuan Castillo# Arguments: 3525ba8f669SYatharth Kochar# $(1) = BL stage (2, 2u, 30, 31, 32, 33) 3538f0617efSJuan Castillo# $(2) = FIP command line option (if empty, image will not be included in the FIP) 3541dc0714fSMasahiro Yamada# $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) 35573c99d4eSJuan Castillodefine MAKE_BL 35673c99d4eSJuan Castillo $(eval BUILD_DIR := ${BUILD_PLAT}/bl$(1)) 3575ba8f669SYatharth Kochar $(eval BL_SOURCES := $(BL$(call uppercase,$(1))_SOURCES)) 3585ba8f669SYatharth Kochar $(eval SOURCES := $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES)) 35973c99d4eSJuan Castillo $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) 36073c99d4eSJuan Castillo $(eval LINKERFILE := $(call IMG_LINKERFILE,$(1))) 36173c99d4eSJuan Castillo $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) 36273c99d4eSJuan Castillo $(eval ELF := $(call IMG_ELF,$(1))) 36373c99d4eSJuan Castillo $(eval DUMP := $(call IMG_DUMP,$(1))) 36473c99d4eSJuan Castillo $(eval BIN := $(call IMG_BIN,$(1))) 3655ba8f669SYatharth Kochar $(eval BL_LINKERFILE := $(BL$(call uppercase,$(1))_LINKERFILE)) 36623e0fe52SKonstantin Porotchkin $(eval BL_LIBS := $(BL$(call uppercase,$(1))_LIBS)) 36751b27702SEvan Lloyd # We use sort only to get a list of unique object directory names. 36851b27702SEvan Lloyd # ordering is not relevant but sort removes duplicates. 3696ba7d274SEvan Lloyd $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${LINKERFILE}))) 37051b27702SEvan Lloyd # The $(dir ) function leaves a trailing / on the directory names 371d014ea6cSMasahiro Yamada # Rip off the / to match directory names with make rule targets. 372d014ea6cSMasahiro Yamada $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) 37351b27702SEvan Lloyd 37451b27702SEvan Lloyd# Create generators for object directory structure 37551b27702SEvan Lloyd 3768012cc5cSMasahiro Yamada$(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) 3776ba7d274SEvan Lloyd 3786ba7d274SEvan Lloyd$(eval $(foreach objd,${OBJ_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 37951b27702SEvan Lloyd 38051b27702SEvan Lloyd.PHONY : bl${1}_dirs 38151b27702SEvan Lloyd 38251b27702SEvan Lloyd# We use order-only prerequisites to ensure that directories are created, 38351b27702SEvan Lloyd# but do not cause re-builds every time a file is written. 38451b27702SEvan Lloydbl${1}_dirs: | ${OBJ_DIRS} 38573c99d4eSJuan Castillo 38673c99d4eSJuan Castillo$(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) 387a6ca7888SMasahiro Yamada$(eval $(call MAKE_LD,$(LINKERFILE),$(BL_LINKERFILE),$(1))) 38873c99d4eSJuan Castillo 3895accce5bSRoberto Vargasifeq ($(USE_ROMLIB),1) 3905accce5bSRoberto Vargas$(ELF): romlib.bin 3915accce5bSRoberto Vargasendif 3925accce5bSRoberto Vargas 3935fee0287SRoberto Vargas$(ELF): $(OBJS) $(LINKERFILE) | bl$(1)_dirs libraries $(BL_LIBS) 39473c99d4eSJuan Castillo @echo " LD $$@" 395414ab853SEvan Lloydifdef MAKE_BUILD_STRINGS 396414ab853SEvan Lloyd $(call MAKE_BUILD_STRINGS, $(BUILD_DIR)/build_message.o) 397414ab853SEvan Lloydelse 3982f5d4a48SPatrick Georgi @echo 'const char build_message[] = "Built : "$(BUILD_MESSAGE_TIMESTAMP); \ 39973c99d4eSJuan Castillo const char version_string[] = "${VERSION_STRING}";' | \ 400f2e1d57eSMasahiro Yamada $$(CC) $$(TF_CFLAGS) $$(CFLAGS) -xc -c - -o $(BUILD_DIR)/build_message.o 401414ab853SEvan Lloydendif 402c2b8806fSDouglas Raillard $$(Q)$$(LD) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) -Map=$(MAPFILE) \ 4035fee0287SRoberto Vargas --script $(LINKERFILE) $(BUILD_DIR)/build_message.o \ 4045fee0287SRoberto Vargas $(OBJS) $(LDPATHS) $(LDLIBS) $(BL_LIBS) 40573c99d4eSJuan Castillo 40673c99d4eSJuan Castillo$(DUMP): $(ELF) 40773c99d4eSJuan Castillo @echo " OD $$@" 40873c99d4eSJuan Castillo $${Q}$${OD} -dx $$< > $$@ 40973c99d4eSJuan Castillo 41073c99d4eSJuan Castillo$(BIN): $(ELF) 41173c99d4eSJuan Castillo @echo " BIN $$@" 41273c99d4eSJuan Castillo $$(Q)$$(OC) -O binary $$< $$@ 413052ab529SEvan Lloyd @${ECHO_BLANK_LINE} 41473c99d4eSJuan Castillo @echo "Built $$@ successfully" 415052ab529SEvan Lloyd @${ECHO_BLANK_LINE} 41673c99d4eSJuan Castillo 41773c99d4eSJuan Castillo.PHONY: bl$(1) 41851b27702SEvan Lloydbl$(1): $(BIN) $(DUMP) 41973c99d4eSJuan Castillo 42073c99d4eSJuan Castilloall: bl$(1) 42173c99d4eSJuan Castillo 4222da522bbSMasahiro Yamada$(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,bl$(1),$(BIN),--$(2),$(BIN),$(3))) 42373c99d4eSJuan Castillo 42473c99d4eSJuan Castilloendef 42573c99d4eSJuan Castillo 42638c14d88SSoby Mathew# Convert device tree source file names to matching blobs 42738c14d88SSoby Mathew# $(1) = input dts 42803b397a8SNishanth Menondefine SOURCES_TO_DTBS 42903b397a8SNishanth Menon $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) 43003b397a8SNishanth Menonendef 43103b397a8SNishanth Menon 43238c14d88SSoby Mathew# MAKE_FDT_DIRS macro creates the prerequisite directories that host the 43338c14d88SSoby Mathew# FDT binaries 43438c14d88SSoby Mathew# $(1) = output directory 43538c14d88SSoby Mathew# $(2) = input dts 43638c14d88SSoby Mathewdefine MAKE_FDT_DIRS 43738c14d88SSoby Mathew $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 43803b397a8SNishanth Menon $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS}))) 43903b397a8SNishanth Menon # The $(dir ) function leaves a trailing / on the directory names 44003b397a8SNishanth Menon # Rip off the / to match directory names with make rule targets. 44103b397a8SNishanth Menon $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS))) 44203b397a8SNishanth Menon 44303b397a8SNishanth Menon$(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) 44403b397a8SNishanth Menon 44503b397a8SNishanth Menonfdt_dirs: ${DTB_DIRS} 44603b397a8SNishanth Menonendef 44703b397a8SNishanth Menon 44838c14d88SSoby Mathew# MAKE_DTB generate the Flattened device tree binary 44903b397a8SNishanth Menon# $(1) = output directory 45003b397a8SNishanth Menon# $(2) = input dts 45103b397a8SNishanth Menondefine MAKE_DTB 45203b397a8SNishanth Menon 453*077b3e9aSYann Gautier# List of DTB file(s) to generate, based on DTS file basename list 45438c14d88SSoby Mathew$(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 455*077b3e9aSYann Gautier# List of the pre-compiled DTS file(s) 45601d237cbSYann Gautier$(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) 457*077b3e9aSYann Gautier# Dependencies of the pre-compiled DTS file(s) on its source and included files 458*077b3e9aSYann Gautier$(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) 459*077b3e9aSYann Gautier# Dependencies of the DT compilation on its pre-compiled DTS 460*077b3e9aSYann Gautier$(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) 46103b397a8SNishanth Menon 4626bc1a30cSStephen Warren$(DOBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs 46301d237cbSYann Gautier @echo " CPP $$<" 464*077b3e9aSYann Gautier $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) 465*077b3e9aSYann Gautier $$(Q)$$(CPP) $$(CPPFLAGS) -x assembler-with-cpp -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< 46603b397a8SNishanth Menon @echo " DTC $$<" 467*077b3e9aSYann Gautier $$(Q)$$(DTC) $$(DTC_FLAGS) -i fdts -d $(DTBDEP) -o $$@ $(DPRE) 46803b397a8SNishanth Menon 469*077b3e9aSYann Gautier-include $(DTBDEP) 470*077b3e9aSYann Gautier-include $(DTSDEP) 47103b397a8SNishanth Menon 47203b397a8SNishanth Menonendef 47303b397a8SNishanth Menon 47403b397a8SNishanth Menon# MAKE_DTBS builds flattened device tree sources 47503b397a8SNishanth Menon# $(1) = output directory 47603b397a8SNishanth Menon# $(2) = list of flattened device tree source files 47703b397a8SNishanth Menondefine MAKE_DTBS 47803b397a8SNishanth Menon $(eval DOBJS := $(filter %.dts,$(2))) 47903b397a8SNishanth Menon $(eval REMAIN := $(filter-out %.dts,$(2))) 48038c14d88SSoby Mathew $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) 48103b397a8SNishanth Menon $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) 48203b397a8SNishanth Menon 48338c14d88SSoby Mathew $(eval $(call MAKE_FDT_DIRS,$(1),$(2))) 48438c14d88SSoby Mathew 48538c14d88SSoby Mathewdtbs: $(DTBS) 48638c14d88SSoby Mathewall: dtbs 48703b397a8SNishanth Menonendef 488