Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 1 | # |
Chris Kay | c7ea347 | 2024-01-15 18:45:07 +0000 | [diff] [blame] | 2 | # Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved. |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 3 | # |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | # SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 5 | # |
| 6 | |
Evan Lloyd | 870a18c | 2015-12-02 18:41:22 +0000 | [diff] [blame] | 7 | # Report an error if the eval make function is not available. |
| 8 | $(eval eval_available := T) |
| 9 | ifneq (${eval_available},T) |
| 10 | $(error This makefile only works with a Make program that supports $$(eval)) |
| 11 | endif |
| 12 | |
Evan Lloyd | f269714 | 2015-12-02 18:17:37 +0000 | [diff] [blame] | 13 | # A user defined function to recursively search for a filename below a directory |
| 14 | # $1 is the directory root of the recursive search (blank for current directory). |
| 15 | # $2 is the file name to search for. |
| 16 | define rwildcard |
| 17 | $(strip $(foreach d,$(wildcard ${1}*),$(call rwildcard,${d}/,${2}) $(filter $(subst *,%,%${2}),${d}))) |
| 18 | endef |
| 19 | |
Boyan Karatotev | b4f25db | 2022-11-17 12:01:29 +0000 | [diff] [blame] | 20 | # Convenience function for setting a variable to 0 if not previously set |
| 21 | # $(eval $(call default_zero,FOO)) |
| 22 | define default_zero |
| 23 | $(eval $(1) ?= 0) |
| 24 | endef |
| 25 | |
| 26 | # Convenience function for setting a list of variables to 0 if not previously set |
| 27 | # $(eval $(call default_zeros,FOO BAR)) |
| 28 | define default_zeros |
| 29 | $(foreach var,$1,$(eval $(call default_zero,$(var)))) |
| 30 | endef |
| 31 | |
Govindraj Raja | 7dc5f1b | 2024-01-23 14:20:52 -0600 | [diff] [blame] | 32 | # Convenience function for setting a variable to 1 if not previously set |
| 33 | # $(eval $(call default_one,FOO)) |
| 34 | define default_one |
| 35 | $(eval $(1) ?= 1) |
| 36 | endef |
| 37 | |
| 38 | # Convenience function for setting a list of variables to 1 if not previously set |
| 39 | # $(eval $(call default_ones,FOO BAR)) |
| 40 | define default_ones |
| 41 | $(foreach var,$1,$(eval $(call default_one,$(var)))) |
| 42 | endef |
| 43 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 44 | # Convenience function for adding build definitions |
| 45 | # $(eval $(call add_define,FOO)) will have: |
| 46 | # -DFOO if $(FOO) is empty; -DFOO=$(FOO) otherwise |
| 47 | define add_define |
| 48 | DEFINES += -D$(1)$(if $(value $(1)),=$(value $(1)),) |
| 49 | endef |
| 50 | |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 51 | # Convenience function for addding multiple build definitions |
| 52 | # $(eval $(call add_defines,FOO BOO)) |
| 53 | define add_defines |
| 54 | $(foreach def,$1,$(eval $(call add_define,$(def)))) |
| 55 | endef |
| 56 | |
Soren Brinkmann | 9efe657 | 2016-06-09 13:36:27 -0700 | [diff] [blame] | 57 | # Convenience function for adding build definitions |
| 58 | # $(eval $(call add_define_val,FOO,BAR)) will have: |
| 59 | # -DFOO=BAR |
| 60 | define add_define_val |
| 61 | DEFINES += -D$(1)=$(2) |
| 62 | endef |
| 63 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 64 | # Convenience function for verifying option has a boolean value |
| 65 | # $(eval $(call assert_boolean,FOO)) will assert FOO is 0 or 1 |
| 66 | define assert_boolean |
Yann Gautier | dbf0a16 | 2023-04-24 13:38:12 +0200 | [diff] [blame] | 67 | $(if $($(1)),,$(error $(1) must not be empty)) |
Masahiro Yamada | 1ab9e92 | 2017-05-23 23:45:01 +0900 | [diff] [blame] | 68 | $(if $(filter-out 0 1,$($1)),$(error $1 must be boolean)) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 69 | endef |
| 70 | |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 71 | # Convenience function for verifying options have boolean values |
| 72 | # $(eval $(call assert_booleans,FOO BOO)) will assert FOO and BOO for 0 or 1 values |
| 73 | define assert_booleans |
| 74 | $(foreach bool,$1,$(eval $(call assert_boolean,$(bool)))) |
| 75 | endef |
| 76 | |
Jeenu Viswambharan | fca7680 | 2017-01-16 16:52:35 +0000 | [diff] [blame] | 77 | 0-9 := 0 1 2 3 4 5 6 7 8 9 |
| 78 | |
| 79 | # Function to verify that a given option $(1) contains a numeric value |
| 80 | define assert_numeric |
| 81 | $(if $($(1)),,$(error $(1) must not be empty)) |
| 82 | $(eval __numeric := $($(1))) |
| 83 | $(foreach d,$(0-9),$(eval __numeric := $(subst $(d),,$(__numeric)))) |
| 84 | $(if $(__numeric),$(error $(1) must be numeric)) |
| 85 | endef |
| 86 | |
Leonardo Sandoval | 65fca7c | 2020-09-10 12:18:27 -0500 | [diff] [blame] | 87 | # Convenience function for verifying options have numeric values |
| 88 | # $(eval $(call assert_numerics,FOO BOO)) will assert FOO and BOO contain numeric values |
| 89 | define assert_numerics |
| 90 | $(foreach num,$1,$(eval $(call assert_numeric,$(num)))) |
| 91 | endef |
| 92 | |
Marco Felsch | df646b5 | 2022-11-24 11:02:05 +0100 | [diff] [blame] | 93 | # Convenience function to check for a given linker option. An call to |
| 94 | # $(call ld_option, --no-XYZ) will return --no-XYZ if supported by the linker |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 95 | ld_option = $(shell $($(ARCH)-ld) $(1) -Wl,--version >/dev/null 2>&1 || $($(ARCH)-ld) $(1) -v >/dev/null 2>&1 && echo $(1)) |
Marco Felsch | df646b5 | 2022-11-24 11:02:05 +0100 | [diff] [blame] | 96 | |
Govindraj Raja | aa8ef3f | 2023-05-05 09:09:36 -0500 | [diff] [blame] | 97 | # Convenience function to check for a given compiler option. A call to |
| 98 | # $(call cc_option, --no-XYZ) will return --no-XYZ if supported by the compiler |
| 99 | define cc_option |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 100 | $(shell if $($(ARCH)-cc) $(1) -c -x c /dev/null -o /dev/null >/dev/null 2>&1; then echo $(1); fi ) |
Govindraj Raja | aa8ef3f | 2023-05-05 09:09:36 -0500 | [diff] [blame] | 101 | endef |
| 102 | |
Vijayenthiran Subramaniam | 3414e3a | 2020-02-08 21:27:30 +0530 | [diff] [blame] | 103 | # CREATE_SEQ is a recursive function to create sequence of numbers from 1 to |
| 104 | # $(2) and assign the sequence to $(1) |
| 105 | define CREATE_SEQ |
| 106 | $(if $(word $(2), $($(1))),\ |
| 107 | $(eval $(1) += $(words $($(1))))\ |
| 108 | $(eval $(1) := $(filter-out 0,$($(1)))),\ |
| 109 | $(eval $(1) += $(words $($(1))))\ |
| 110 | $(call CREATE_SEQ,$(1),$(2))\ |
| 111 | ) |
| 112 | endef |
| 113 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 114 | # IMG_MAPFILE defines the output file describing the memory map corresponding |
| 115 | # to a BL stage |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 116 | # $(1) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 117 | define IMG_MAPFILE |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 118 | ${BUILD_DIR}/$(1).map |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 119 | endef |
| 120 | |
| 121 | # IMG_ELF defines the elf file corresponding to a BL stage |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 122 | # $(1) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 123 | define IMG_ELF |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 124 | ${BUILD_DIR}/$(1).elf |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 125 | endef |
| 126 | |
| 127 | # IMG_DUMP defines the symbols dump file corresponding to a BL stage |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 128 | # $(1) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 129 | define IMG_DUMP |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 130 | ${BUILD_DIR}/$(1).dump |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 131 | endef |
| 132 | |
| 133 | # IMG_BIN defines the default image file corresponding to a BL stage |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 134 | # $(1) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 135 | define IMG_BIN |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 136 | ${BUILD_PLAT}/$(1).bin |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 137 | endef |
| 138 | |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 139 | # IMG_ENC_BIN defines the default encrypted image file corresponding to a |
| 140 | # BL stage |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 141 | # $(1) = BL stage |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 142 | define IMG_ENC_BIN |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 143 | ${BUILD_PLAT}/$(1)_enc.bin |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 144 | endef |
| 145 | |
| 146 | # ENCRYPT_FW invokes enctool to encrypt firmware binary |
| 147 | # $(1) = input firmware binary |
| 148 | # $(2) = output encrypted firmware binary |
| 149 | define ENCRYPT_FW |
| 150 | $(2): $(1) enctool |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 151 | $$(s)echo " ENC $$<" |
| 152 | $$(q)$$(ENCTOOL) $$(ENC_ARGS) -i $$< -o $$@ |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 153 | endef |
| 154 | |
Masahiro Yamada | 6c2b459 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 155 | # TOOL_ADD_PAYLOAD appends the command line arguments required by fiptool to |
| 156 | # package a new payload and/or by cert_create to generate certificate. |
| 157 | # Optionally, it adds the dependency on this payload |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 158 | # $(1) = payload filename (i.e. bl31.bin) |
Masahiro Yamada | c85deee | 2017-12-23 23:56:18 +0900 | [diff] [blame] | 159 | # $(2) = command line option for the specified payload (i.e. --soc-fw) |
Masahiro Yamada | 5c3ae33 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 160 | # $(3) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) |
Masahiro Yamada | cd7711d | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 161 | # $(4) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 162 | # $(5) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) |
Masahiro Yamada | 6c2b459 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 163 | define TOOL_ADD_PAYLOAD |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 164 | ifneq ($(5),) |
| 165 | $(4)FIP_ARGS += $(2) $(5) |
| 166 | $(if $(3),$(4)CRT_DEPS += $(1)) |
| 167 | else |
Masahiro Yamada | 714a692 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 168 | $(4)FIP_ARGS += $(2) $(1) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 169 | $(if $(3),$(4)CRT_DEPS += $(3)) |
| 170 | endif |
Masahiro Yamada | 714a692 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 171 | $(if $(3),$(4)FIP_DEPS += $(3)) |
Masahiro Yamada | ec154ad | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 172 | $(4)CRT_ARGS += $(2) $(1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 173 | endef |
| 174 | |
Masahiro Yamada | bfb64ac | 2018-02-01 16:31:09 +0900 | [diff] [blame] | 175 | # TOOL_ADD_IMG_PAYLOAD works like TOOL_ADD_PAYLOAD, but applies image filters |
| 176 | # before passing them to host tools if BL*_PRE_TOOL_FILTER is defined. |
| 177 | # $(1) = image_type (scp_bl2, bl33, etc.) |
| 178 | # $(2) = payload filepath (ex. build/fvp/release/bl31.bin) |
| 179 | # $(3) = command line option for the specified payload (ex. --soc-fw) |
| 180 | # $(4) = tool target dependency (optional) (ex. build/fvp/release/bl31.bin) |
| 181 | # $(5) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 182 | # $(6) = encrypted payload (optional) (ex. build/fvp/release/bl31_enc.bin) |
Masahiro Yamada | bfb64ac | 2018-02-01 16:31:09 +0900 | [diff] [blame] | 183 | |
| 184 | define TOOL_ADD_IMG_PAYLOAD |
| 185 | |
| 186 | $(eval PRE_TOOL_FILTER := $($(call uppercase,$(1))_PRE_TOOL_FILTER)) |
| 187 | |
| 188 | ifneq ($(PRE_TOOL_FILTER),) |
| 189 | |
| 190 | $(eval PROCESSED_PATH := $(BUILD_PLAT)/$(1).bin$($(PRE_TOOL_FILTER)_SUFFIX)) |
| 191 | |
| 192 | $(call $(PRE_TOOL_FILTER)_RULE,$(PROCESSED_PATH),$(2)) |
| 193 | |
| 194 | $(PROCESSED_PATH): $(4) |
| 195 | |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 196 | $(call TOOL_ADD_PAYLOAD,$(PROCESSED_PATH),$(3),$(PROCESSED_PATH),$(5),$(6)) |
Masahiro Yamada | bfb64ac | 2018-02-01 16:31:09 +0900 | [diff] [blame] | 197 | |
| 198 | else |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 199 | $(call TOOL_ADD_PAYLOAD,$(2),$(3),$(4),$(5),$(6)) |
Masahiro Yamada | bfb64ac | 2018-02-01 16:31:09 +0900 | [diff] [blame] | 200 | endif |
| 201 | endef |
| 202 | |
Yatharth Kochar | d1a9343 | 2015-10-12 12:33:47 +0100 | [diff] [blame] | 203 | # CERT_ADD_CMD_OPT adds a new command line option to the cert_create invocation |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 204 | # $(1) = parameter filename |
| 205 | # $(2) = cert_create command line option for the specified parameter |
Masahiro Yamada | 5ebfda3 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 206 | # $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 207 | define CERT_ADD_CMD_OPT |
Masahiro Yamada | 5ebfda3 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 208 | $(3)CRT_ARGS += $(2) $(1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 209 | endef |
| 210 | |
Masahiro Yamada | 4d15680 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 211 | # TOOL_ADD_IMG allows the platform to specify an external image to be packed |
| 212 | # in the FIP and/or for which certificate is generated. It also adds a |
| 213 | # dependency on the image file, aborting the build if the file does not exist. |
Masahiro Yamada | 9c5ca52 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 214 | # $(1) = image_type (scp_bl2, bl33, etc.) |
Masahiro Yamada | c85deee | 2017-12-23 23:56:18 +0900 | [diff] [blame] | 215 | # $(2) = command line option for fiptool (--scp-fw, --nt-fw, etc) |
Masahiro Yamada | cd7711d | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 216 | # $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 217 | # $(4) = Image encryption flag (optional) (0, 1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 218 | # Example: |
Masahiro Yamada | 9c5ca52 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 219 | # $(eval $(call TOOL_ADD_IMG,bl33,--nt-fw)) |
Masahiro Yamada | 4d15680 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 220 | define TOOL_ADD_IMG |
Masahiro Yamada | 9c5ca52 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 221 | # Build option to specify the image filename (SCP_BL2, BL33, etc) |
| 222 | # This is the uppercase form of the first parameter |
| 223 | $(eval _V := $(call uppercase,$(1))) |
| 224 | |
Pali Rohár | a5416ab | 2020-11-24 16:53:04 +0100 | [diff] [blame] | 225 | # $(check_$(1)_cmd) variable is executed in the check_$(1) target and also |
| 226 | # is put into the ${CHECK_$(3)FIP_CMD} variable which is executed by the |
| 227 | # target ${BUILD_PLAT}/${$(3)FIP_NAME}. |
| 228 | $(eval check_$(1)_cmd := \ |
| 229 | $(if $(value $(_V)),,$$$$(error "Platform '${PLAT}' requires $(_V). Please set $(_V) to point to the right file")) \ |
| 230 | $(if $(wildcard $(value $(_V))),,$$$$(error '$(_V)=$(value $(_V))' was specified, but '$(value $(_V))' does not exist)) \ |
| 231 | ) |
| 232 | |
Masahiro Yamada | 714a692 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 233 | $(3)CRT_DEPS += check_$(1) |
Pali Rohár | a5416ab | 2020-11-24 16:53:04 +0100 | [diff] [blame] | 234 | CHECK_$(3)FIP_CMD += $$(check_$(1)_cmd) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 235 | ifeq ($(4),1) |
| 236 | $(eval ENC_BIN := ${BUILD_PLAT}/$(1)_enc.bin) |
| 237 | $(call ENCRYPT_FW,$(value $(_V)),$(ENC_BIN)) |
| 238 | $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(ENC_BIN),$(3), \ |
| 239 | $(ENC_BIN)) |
| 240 | else |
Pali Rohár | a5416ab | 2020-11-24 16:53:04 +0100 | [diff] [blame] | 241 | $(call TOOL_ADD_IMG_PAYLOAD,$(1),$(value $(_V)),$(2),$(if $(wildcard $(value $(_V))),$(value $(_V)),FORCE),$(3)) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 242 | endif |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 243 | |
Masahiro Yamada | 9dff156 | 2017-12-24 13:08:00 +0900 | [diff] [blame] | 244 | .PHONY: check_$(1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 245 | check_$(1): |
Pali Rohár | a5416ab | 2020-11-24 16:53:04 +0100 | [diff] [blame] | 246 | $(check_$(1)_cmd) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 247 | endef |
| 248 | |
Juan Pablo Conde | 3539c74 | 2022-10-25 19:41:02 -0400 | [diff] [blame] | 249 | # SELECT_OPENSSL_API_VERSION selects the OpenSSL API version to be used to |
| 250 | # build the host tools by checking the version of OpenSSL located under |
| 251 | # the path defined by the OPENSSL_DIR variable. It receives no parameters. |
| 252 | define SELECT_OPENSSL_API_VERSION |
| 253 | # Set default value for USING_OPENSSL3 macro to 0 |
| 254 | $(eval USING_OPENSSL3 = 0) |
| 255 | # Obtain the OpenSSL version for the build located under OPENSSL_DIR |
| 256 | $(eval OPENSSL_INFO := $(shell LD_LIBRARY_PATH=${OPENSSL_DIR}:${OPENSSL_DIR}/lib ${OPENSSL_BIN_PATH}/openssl version)) |
| 257 | $(eval OPENSSL_CURRENT_VER = $(word 2, ${OPENSSL_INFO})) |
| 258 | $(eval OPENSSL_CURRENT_VER_MAJOR = $(firstword $(subst ., ,$(OPENSSL_CURRENT_VER)))) |
| 259 | # If OpenSSL version is 3.x, then set USING_OPENSSL3 flag to 1 |
| 260 | $(if $(filter 3,$(OPENSSL_CURRENT_VER_MAJOR)), $(eval USING_OPENSSL3 = 1)) |
| 261 | endef |
| 262 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 263 | ################################################################################ |
Masahiro Yamada | eff36a9 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 264 | # Generic image processing filters |
| 265 | ################################################################################ |
| 266 | |
| 267 | # GZIP |
| 268 | define GZIP_RULE |
| 269 | $(1): $(2) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 270 | $(s)echo " GZIP $$@" |
| 271 | $(q)gzip -n -f -9 $$< --stdout > $$@ |
Masahiro Yamada | eff36a9 | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 272 | endef |
| 273 | |
| 274 | GZIP_SUFFIX := .gz |
| 275 | |
| 276 | ################################################################################ |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 277 | # Auxiliary macros to build TF images from sources |
| 278 | ################################################################################ |
| 279 | |
Masahiro Yamada | e487bb6 | 2016-12-22 15:23:05 +0900 | [diff] [blame] | 280 | MAKE_DEP = -Wp,-MD,$(DEP) -MT $$@ -MP |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 281 | |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 282 | |
| 283 | # MAKE_C_LIB builds a C source file and generates the dependency file |
| 284 | # $(1) = output directory |
| 285 | # $(2) = source file (%.c) |
| 286 | # $(3) = library name |
| 287 | define MAKE_C_LIB |
| 288 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
| 289 | $(eval DEP := $(patsubst %.o,%.d,$(OBJ))) |
Govindraj Raja | 98375d4 | 2023-01-27 10:08:54 +0000 | [diff] [blame] | 290 | $(eval LIB := $(call uppercase, $(notdir $(1)))) |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 291 | |
| 292 | $(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 293 | $$(s)echo " CC $$<" |
| 294 | $$(q)$($(ARCH)-cc) $$($(LIB)_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(MAKE_DEP) -c $$< -o $$@ |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 295 | |
| 296 | -include $(DEP) |
| 297 | |
| 298 | endef |
| 299 | |
Antonio Nino Diaz | a884dfb | 2019-02-08 13:20:37 +0000 | [diff] [blame] | 300 | # MAKE_S_LIB builds an assembly source file and generates the dependency file |
| 301 | # $(1) = output directory |
| 302 | # $(2) = source file (%.S) |
| 303 | # $(3) = library name |
| 304 | define MAKE_S_LIB |
| 305 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
| 306 | $(eval DEP := $(patsubst %.o,%.d,$(OBJ))) |
| 307 | |
| 308 | $(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | lib$(3)_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 309 | $$(s)echo " AS $$<" |
| 310 | $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ |
Antonio Nino Diaz | a884dfb | 2019-02-08 13:20:37 +0000 | [diff] [blame] | 311 | |
| 312 | -include $(DEP) |
| 313 | |
| 314 | endef |
| 315 | |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 316 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 317 | # MAKE_C builds a C source file and generates the dependency file |
| 318 | # $(1) = output directory |
| 319 | # $(2) = source file (%.c) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 320 | # $(3) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 321 | define MAKE_C |
| 322 | |
| 323 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 324 | $(eval DEP := $(patsubst %.o,%.d,$(OBJ))) |
Chris Kay | 2a8e424 | 2023-03-22 15:42:32 +0000 | [diff] [blame] | 325 | |
Chris Kay | f581825 | 2023-05-03 15:31:42 +0200 | [diff] [blame] | 326 | $(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) |
| 327 | $(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) |
| 328 | $(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) |
| 329 | $(eval BL_CFLAGS := $($(call uppercase,$(3))_CFLAGS) $(PLAT_BL_COMMON_CFLAGS)) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 330 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 331 | $(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 332 | $$(s)echo " CC $$<" |
| 333 | $$(q)$($(ARCH)-cc) $$(LTO_CFLAGS) $$(TF_CFLAGS) $$(CFLAGS) $(BL_CPPFLAGS) $(BL_CFLAGS) $(MAKE_DEP) -c $$< -o $$@ |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 334 | |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 335 | -include $(DEP) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 336 | |
| 337 | endef |
| 338 | |
| 339 | |
| 340 | # MAKE_S builds an assembly source file and generates the dependency file |
| 341 | # $(1) = output directory |
| 342 | # $(2) = assembly file (%.S) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 343 | # $(3) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 344 | define MAKE_S |
| 345 | |
| 346 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 347 | $(eval DEP := $(patsubst %.o,%.d,$(OBJ))) |
Chris Kay | 2a8e424 | 2023-03-22 15:42:32 +0000 | [diff] [blame] | 348 | |
Chris Kay | f581825 | 2023-05-03 15:31:42 +0200 | [diff] [blame] | 349 | $(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) |
| 350 | $(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) |
| 351 | $(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) |
| 352 | $(eval BL_ASFLAGS := $($(call uppercase,$(3))_ASFLAGS) $(PLAT_BL_COMMON_ASFLAGS)) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 353 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 354 | $(OBJ): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 355 | $$(s)echo " AS $$<" |
| 356 | $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(TF_CFLAGS_$(ARCH)) $$(ASFLAGS) $(BL_CPPFLAGS) $(BL_ASFLAGS) $(MAKE_DEP) -c $$< -o $$@ |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 357 | |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 358 | -include $(DEP) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 359 | |
| 360 | endef |
| 361 | |
| 362 | |
| 363 | # MAKE_LD generate the linker script using the C preprocessor |
| 364 | # $(1) = output linker script |
| 365 | # $(2) = input template |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 366 | # $(3) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 367 | define MAKE_LD |
| 368 | |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 369 | $(eval DEP := $(1).d) |
Chris Kay | 2a8e424 | 2023-03-22 15:42:32 +0000 | [diff] [blame] | 370 | |
Chris Kay | f581825 | 2023-05-03 15:31:42 +0200 | [diff] [blame] | 371 | $(eval BL_DEFINES := IMAGE_$(call uppercase,$(3)) $($(call uppercase,$(3))_DEFINES) $(PLAT_BL_COMMON_DEFINES)) |
| 372 | $(eval BL_INCLUDE_DIRS := $($(call uppercase,$(3))_INCLUDE_DIRS) $(PLAT_BL_COMMON_INCLUDE_DIRS)) |
| 373 | $(eval BL_CPPFLAGS := $($(call uppercase,$(3))_CPPFLAGS) $(addprefix -D,$(BL_DEFINES)) $(addprefix -I,$(BL_INCLUDE_DIRS)) $(PLAT_BL_COMMON_CPPFLAGS)) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 374 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 375 | $(1): $(2) $(filter-out %.d,$(MAKEFILE_LIST)) | $(3)_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 376 | $$(s)echo " PP $$<" |
| 377 | $$(q)$($(ARCH)-cpp) -E $$(CPPFLAGS) $(BL_CPPFLAGS) $(TF_CFLAGS_$(ARCH)) -P -x assembler-with-cpp -D__LINKER__ $(MAKE_DEP) -o $$@ $$< |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 378 | |
Masahiro Yamada | 56c53f6 | 2016-12-22 14:02:27 +0900 | [diff] [blame] | 379 | -include $(DEP) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 380 | |
| 381 | endef |
| 382 | |
Antonio Nino Diaz | a884dfb | 2019-02-08 13:20:37 +0000 | [diff] [blame] | 383 | # MAKE_LIB_OBJS builds both C and assembly source files |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 384 | # $(1) = output directory |
| 385 | # $(2) = list of source files |
| 386 | # $(3) = name of the library |
| 387 | define MAKE_LIB_OBJS |
| 388 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 389 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 390 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C_LIB,$(1),$(obj),$(3)))) |
| 391 | |
Antonio Nino Diaz | a884dfb | 2019-02-08 13:20:37 +0000 | [diff] [blame] | 392 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 393 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 394 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S_LIB,$(1),$(obj),$(3)))) |
| 395 | |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 396 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 397 | endef |
| 398 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 399 | |
| 400 | # MAKE_OBJS builds both C and assembly source files |
| 401 | # $(1) = output directory |
| 402 | # $(2) = list of source files (both C and assembly) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 403 | # $(3) = BL stage |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 404 | define MAKE_OBJS |
| 405 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 406 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 407 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) |
| 408 | |
| 409 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 410 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 411 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) |
| 412 | |
| 413 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 414 | endef |
| 415 | |
| 416 | |
| 417 | # NOTE: The line continuation '\' is required in the next define otherwise we |
| 418 | # end up with a line-feed characer at the end of the last c filename. |
Evan Lloyd | a71d259 | 2015-12-02 18:56:06 +0000 | [diff] [blame] | 419 | # Also bear this issue in mind if extending the list of supported filetypes. |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 420 | define SOURCES_TO_OBJS |
| 421 | $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ |
| 422 | $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) |
| 423 | endef |
| 424 | |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 425 | .PHONY: libraries |
| 426 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 427 | # MAKE_LIB_DIRS macro defines the target for the directory where |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 428 | # libraries are created |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 429 | define MAKE_LIB_DIRS |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 430 | $(eval LIB_DIR := ${BUILD_PLAT}/lib) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 431 | $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) |
| 432 | $(eval LIBWRAPPER_DIR := ${BUILD_PLAT}/libwrapper) |
| 433 | $(eval $(call MAKE_PREREQ_DIR,${LIB_DIR},${BUILD_PLAT})) |
| 434 | $(eval $(call MAKE_PREREQ_DIR,${ROMLIB_DIR},${BUILD_PLAT})) |
| 435 | $(eval $(call MAKE_PREREQ_DIR,${LIBWRAPPER_DIR},${BUILD_PLAT})) |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 436 | endef |
| 437 | |
| 438 | # MAKE_LIB macro defines the targets and options to build each BL image. |
| 439 | # Arguments: |
| 440 | # $(1) = Library name |
| 441 | define MAKE_LIB |
| 442 | $(eval BUILD_DIR := ${BUILD_PLAT}/lib$(1)) |
| 443 | $(eval LIB_DIR := ${BUILD_PLAT}/lib) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 444 | $(eval ROMLIB_DIR := ${BUILD_PLAT}/romlib) |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 445 | $(eval SOURCES := $(LIB$(call uppercase,$(1))_SRCS)) |
| 446 | $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) |
| 447 | |
| 448 | $(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) |
| 449 | $(eval $(call MAKE_LIB_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) |
| 450 | |
| 451 | .PHONY : lib${1}_dirs |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 452 | lib${1}_dirs: | ${BUILD_DIR} ${LIB_DIR} ${ROMLIB_DIR} ${LIBWRAPPER_DIR} |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 453 | libraries: ${LIB_DIR}/lib$(1).a |
Chris Kay | cfba645 | 2023-12-04 09:55:50 +0000 | [diff] [blame] | 454 | ifeq ($($(ARCH)-ld-id),arm-link) |
Varun Wadekar | 4d034c5 | 2019-01-11 14:47:48 -0800 | [diff] [blame] | 455 | LDPATHS = --userlibpath=${LIB_DIR} |
| 456 | LDLIBS += --library=$(1) |
| 457 | else |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 458 | LDPATHS = -L${LIB_DIR} |
| 459 | LDLIBS += -l$(1) |
Varun Wadekar | 4d034c5 | 2019-01-11 14:47:48 -0800 | [diff] [blame] | 460 | endif |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 461 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 462 | ifeq ($(USE_ROMLIB),1) |
Sathees Balya | f5ec500 | 2018-10-18 19:14:21 +0100 | [diff] [blame] | 463 | LIBWRAPPER = -lwrappers |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 464 | endif |
| 465 | |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 466 | all: ${LIB_DIR}/lib$(1).a |
| 467 | |
| 468 | ${LIB_DIR}/lib$(1).a: $(OBJS) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 469 | $$(s)echo " AR $$@" |
| 470 | $$(q)$($(ARCH)-ar) cr $$@ $$? |
Roberto Vargas | 21360f3 | 2018-05-08 10:27:10 +0100 | [diff] [blame] | 471 | endef |
| 472 | |
Chris Kay | 68d2836 | 2023-01-16 16:53:45 +0000 | [diff] [blame] | 473 | # Generate the path to one or more preprocessed linker scripts given the paths |
| 474 | # of their sources. |
| 475 | # |
| 476 | # Arguments: |
| 477 | # $(1) = path to one or more linker script sources |
| 478 | define linker_script_path |
| 479 | $(patsubst %.S,$(BUILD_DIR)/%,$(1)) |
| 480 | endef |
| 481 | |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 482 | # MAKE_BL macro defines the targets and options to build each BL image. |
| 483 | # Arguments: |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 484 | # $(1) = BL stage |
Juan Castillo | 8e04dec | 2016-01-05 11:55:36 +0000 | [diff] [blame] | 485 | # $(2) = FIP command line option (if empty, image will not be included in the FIP) |
Masahiro Yamada | cd7711d | 2018-01-26 11:42:01 +0900 | [diff] [blame] | 486 | # $(3) = FIP prefix (optional) (if FWU_, target is fwu_fip instead of fip) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 487 | # $(4) = BL encryption flag (optional) (0, 1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 488 | define MAKE_BL |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 489 | $(eval BUILD_DIR := ${BUILD_PLAT}/$(1)) |
| 490 | $(eval BL_SOURCES := $($(call uppercase,$(1))_SOURCES)) |
Chris Kay | a7492ee | 2023-05-05 12:33:23 +0200 | [diff] [blame] | 491 | $(eval SOURCES := $(sort $(BL_SOURCES) $(BL_COMMON_SOURCES) $(PLAT_BL_COMMON_SOURCES))) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 492 | $(eval OBJS := $(addprefix $(BUILD_DIR)/,$(call SOURCES_TO_OBJS,$(SOURCES)))) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 493 | $(eval MAPFILE := $(call IMG_MAPFILE,$(1))) |
| 494 | $(eval ELF := $(call IMG_ELF,$(1))) |
| 495 | $(eval DUMP := $(call IMG_DUMP,$(1))) |
| 496 | $(eval BIN := $(call IMG_BIN,$(1))) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 497 | $(eval ENC_BIN := $(call IMG_ENC_BIN,$(1))) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 498 | $(eval BL_LIBS := $($(call uppercase,$(1))_LIBS)) |
Chris Kay | 68d2836 | 2023-01-16 16:53:45 +0000 | [diff] [blame] | 499 | |
| 500 | $(eval DEFAULT_LINKER_SCRIPT_SOURCE := $($(call uppercase,$(1))_DEFAULT_LINKER_SCRIPT_SOURCE)) |
| 501 | $(eval DEFAULT_LINKER_SCRIPT := $(call linker_script_path,$(DEFAULT_LINKER_SCRIPT_SOURCE))) |
| 502 | |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 503 | $(eval LINKER_SCRIPT_SOURCES := $($(call uppercase,$(1))_LINKER_SCRIPT_SOURCES)) |
| 504 | $(eval LINKER_SCRIPTS := $(call linker_script_path,$(LINKER_SCRIPT_SOURCES))) |
| 505 | |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 506 | # We use sort only to get a list of unique object directory names. |
| 507 | # ordering is not relevant but sort removes duplicates. |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 508 | $(eval TEMP_OBJ_DIRS := $(sort $(dir ${OBJS} ${DEFAULT_LINKER_SCRIPT} ${LINKER_SCRIPTS}))) |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 509 | # The $(dir ) function leaves a trailing / on the directory names |
Masahiro Yamada | 823482b | 2017-01-19 19:31:00 +0900 | [diff] [blame] | 510 | # Rip off the / to match directory names with make rule targets. |
| 511 | $(eval OBJ_DIRS := $(patsubst %/,%,$(TEMP_OBJ_DIRS))) |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 512 | |
| 513 | # Create generators for object directory structure |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 514 | |
Masahiro Yamada | e2395b4 | 2017-11-04 03:12:28 +0900 | [diff] [blame] | 515 | $(eval $(call MAKE_PREREQ_DIR,${BUILD_DIR},${BUILD_PLAT})) |
Evan Lloyd | 4c3055f | 2017-04-07 16:58:57 +0100 | [diff] [blame] | 516 | |
Chris Kay | 68d2836 | 2023-01-16 16:53:45 +0000 | [diff] [blame] | 517 | $(eval $(foreach objd,${OBJ_DIRS}, |
| 518 | $(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 519 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 520 | .PHONY : ${1}_dirs |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 521 | |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 522 | # We use order-only prerequisites to ensure that directories are created, |
| 523 | # but do not cause re-builds every time a file is written. |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 524 | ${1}_dirs: | ${OBJ_DIRS} |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 525 | |
| 526 | $(eval $(call MAKE_OBJS,$(BUILD_DIR),$(SOURCES),$(1))) |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 527 | |
| 528 | # Generate targets to preprocess each required linker script |
| 529 | $(eval $(foreach source,$(DEFAULT_LINKER_SCRIPT_SOURCE) $(LINKER_SCRIPT_SOURCES), \ |
| 530 | $(call MAKE_LD,$(call linker_script_path,$(source)),$(source),$(1)))) |
| 531 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 532 | $(eval BL_LDFLAGS := $($(call uppercase,$(1))_LDFLAGS)) |
Evan Lloyd | 93d3b70 | 2015-12-03 12:19:30 +0000 | [diff] [blame] | 533 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 534 | ifeq ($(USE_ROMLIB),1) |
| 535 | $(ELF): romlib.bin |
| 536 | endif |
| 537 | |
developer | 09f3e98 | 2022-03-23 18:51:48 +0800 | [diff] [blame] | 538 | # MODULE_OBJS can be assigned by vendors with different compiled |
| 539 | # object file path, and prebuilt object file path. |
| 540 | $(eval OBJS += $(MODULE_OBJS)) |
| 541 | |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 542 | $(ELF): $(OBJS) $(DEFAULT_LINKER_SCRIPT) $(LINKER_SCRIPTS) | $(1)_dirs libraries $(BL_LIBS) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 543 | $$(s)echo " LD $$@" |
Chris Kay | cfba645 | 2023-12-04 09:55:50 +0000 | [diff] [blame] | 544 | ifeq ($($(ARCH)-ld-id),arm-link) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 545 | $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) --entry=${1}_entrypoint \ |
Chris Kay | 6e1c3fd | 2024-05-29 20:37:33 +0000 | [diff] [blame] | 546 | --predefine=$(call escape-shell,-D__LINKER__=$(__LINKER__)) \ |
| 547 | --predefine=$(call escape-shell,-DTF_CFLAGS=$(TF_CFLAGS)) \ |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 548 | --map --list="$(MAPFILE)" --scatter=${PLAT_DIR}/scat/${1}.scat \ |
Chris Kay | 99b5b2e | 2024-03-08 16:08:31 +0000 | [diff] [blame] | 549 | $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) $(OBJS) |
Chris Kay | cfba645 | 2023-12-04 09:55:50 +0000 | [diff] [blame] | 550 | else ifeq ($($(ARCH)-ld-id),gnu-gcc) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 551 | $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Wl,-Map=$(MAPFILE) \ |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 552 | $(addprefix -Wl$(comma)--script$(comma),$(LINKER_SCRIPTS)) -Wl,--script,$(DEFAULT_LINKER_SCRIPT) \ |
zelalem-aweke | d5f4527 | 2019-11-12 16:20:17 -0600 | [diff] [blame] | 553 | $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) |
Varun Wadekar | 4d034c5 | 2019-01-11 14:47:48 -0800 | [diff] [blame] | 554 | else |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 555 | $$(q)$($(ARCH)-ld) -o $$@ $$(TF_LDFLAGS) $$(LDFLAGS) $(BL_LDFLAGS) -Map=$(MAPFILE) \ |
Chris Kay | 0c0007b | 2023-01-16 18:57:26 +0000 | [diff] [blame] | 556 | $(addprefix -T ,$(LINKER_SCRIPTS)) --script $(DEFAULT_LINKER_SCRIPT) \ |
Sathees Balya | f5ec500 | 2018-10-18 19:14:21 +0100 | [diff] [blame] | 557 | $(OBJS) $(LDPATHS) $(LIBWRAPPER) $(LDLIBS) $(BL_LIBS) |
Varun Wadekar | 4d034c5 | 2019-01-11 14:47:48 -0800 | [diff] [blame] | 558 | endif |
Christoph Müllner | 4f088e4 | 2019-04-24 09:45:30 +0200 | [diff] [blame] | 559 | ifeq ($(DISABLE_BIN_GENERATION),1) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 560 | $(s)echo |
| 561 | $(s)echo "Built $$@ successfully" |
| 562 | $(s)echo |
Christoph Müllner | 4f088e4 | 2019-04-24 09:45:30 +0200 | [diff] [blame] | 563 | endif |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 564 | |
| 565 | $(DUMP): $(ELF) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 566 | $$(s)echo " OD $$@" |
| 567 | $$(q)$($(ARCH)-od) -dx $$< > $$@ |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 568 | |
| 569 | $(BIN): $(ELF) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 570 | $$(s)echo " BIN $$@" |
| 571 | $$(q)$($(ARCH)-oc) -O binary $$< $$@ |
| 572 | $(s)echo |
| 573 | $(s)echo "Built $$@ successfully" |
| 574 | $(s)echo |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 575 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 576 | .PHONY: $(1) |
Christoph Müllner | 4f088e4 | 2019-04-24 09:45:30 +0200 | [diff] [blame] | 577 | ifeq ($(DISABLE_BIN_GENERATION),1) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 578 | $(1): $(ELF) $(DUMP) |
Christoph Müllner | 4f088e4 | 2019-04-24 09:45:30 +0200 | [diff] [blame] | 579 | else |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 580 | $(1): $(BIN) $(DUMP) |
Christoph Müllner | 4f088e4 | 2019-04-24 09:45:30 +0200 | [diff] [blame] | 581 | endif |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 582 | |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 583 | all: $(1) |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 584 | |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 585 | ifeq ($(4),1) |
| 586 | $(call ENCRYPT_FW,$(BIN),$(ENC_BIN)) |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 587 | $(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(ENC_BIN),$(3), \ |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 588 | $(ENC_BIN))) |
| 589 | else |
Zelalem Aweke | b44dec1 | 2021-07-11 17:25:48 -0500 | [diff] [blame] | 590 | $(if $(2),$(call TOOL_ADD_IMG_PAYLOAD,$(1),$(BIN),--$(2),$(BIN),$(3))) |
Sumit Garg | eec5244 | 2019-11-14 16:33:45 +0530 | [diff] [blame] | 591 | endif |
Juan Castillo | a3487d1 | 2015-08-18 14:23:04 +0100 | [diff] [blame] | 592 | |
| 593 | endef |
| 594 | |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 595 | # Convert device tree source file names to matching blobs |
| 596 | # $(1) = input dts |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 597 | define SOURCES_TO_DTBS |
| 598 | $(notdir $(patsubst %.dts,%.dtb,$(filter %.dts,$(1)))) |
| 599 | endef |
| 600 | |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 601 | # MAKE_FDT_DIRS macro creates the prerequisite directories that host the |
| 602 | # FDT binaries |
| 603 | # $(1) = output directory |
| 604 | # $(2) = input dts |
| 605 | define MAKE_FDT_DIRS |
| 606 | $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 607 | $(eval TEMP_DTB_DIRS := $(sort $(dir ${DTBS}))) |
| 608 | # The $(dir ) function leaves a trailing / on the directory names |
| 609 | # Rip off the / to match directory names with make rule targets. |
| 610 | $(eval DTB_DIRS := $(patsubst %/,%,$(TEMP_DTB_DIRS))) |
| 611 | |
| 612 | $(eval $(foreach objd,${DTB_DIRS},$(call MAKE_PREREQ_DIR,${objd},${BUILD_DIR}))) |
| 613 | |
| 614 | fdt_dirs: ${DTB_DIRS} |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 615 | endef |
| 616 | |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 617 | # MAKE_DTB generate the Flattened device tree binary |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 618 | # $(1) = output directory |
| 619 | # $(2) = input dts |
| 620 | define MAKE_DTB |
| 621 | |
Yann Gautier | f383180 | 2018-09-04 10:44:00 +0200 | [diff] [blame] | 622 | # List of DTB file(s) to generate, based on DTS file basename list |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 623 | $(eval DOBJ := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) |
Yann Gautier | f383180 | 2018-09-04 10:44:00 +0200 | [diff] [blame] | 624 | # List of the pre-compiled DTS file(s) |
Yann Gautier | 2cf1dbc | 2018-06-18 16:00:23 +0200 | [diff] [blame] | 625 | $(eval DPRE := $(addprefix $(1)/,$(patsubst %.dts,%.pre.dts,$(notdir $(2))))) |
Yann Gautier | f383180 | 2018-09-04 10:44:00 +0200 | [diff] [blame] | 626 | # Dependencies of the pre-compiled DTS file(s) on its source and included files |
| 627 | $(eval DTSDEP := $(patsubst %.dtb,%.o.d,$(DOBJ))) |
| 628 | # Dependencies of the DT compilation on its pre-compiled DTS |
| 629 | $(eval DTBDEP := $(patsubst %.dtb,%.d,$(DOBJ))) |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 630 | |
Chris Kay | a6a8bc7 | 2024-03-08 16:26:53 +0000 | [diff] [blame] | 631 | $(DPRE): $(2) | fdt_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 632 | $$(s)echo " CPP $$<" |
Yann Gautier | f383180 | 2018-09-04 10:44:00 +0200 | [diff] [blame] | 633 | $(eval DTBS := $(addprefix $(1)/,$(call SOURCES_TO_DTBS,$(2)))) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 634 | $$(q)$($(ARCH)-cpp) -E $$(TF_CFLAGS_$(ARCH)) $$(DTC_CPPFLAGS) -MT $(DTBS) -MMD -MF $(DTSDEP) -o $(DPRE) $$< |
Chris Kay | a6a8bc7 | 2024-03-08 16:26:53 +0000 | [diff] [blame] | 635 | |
| 636 | $(DOBJ): $(DPRE) $(filter-out %.d,$(MAKEFILE_LIST)) | fdt_dirs |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame^] | 637 | $$(s)echo " DTC $$<" |
| 638 | $$(q)$($(ARCH)-dtc) $$(DTC_FLAGS) -d $(DTBDEP) -o $$@ $$< |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 639 | |
Yann Gautier | f383180 | 2018-09-04 10:44:00 +0200 | [diff] [blame] | 640 | -include $(DTBDEP) |
| 641 | -include $(DTSDEP) |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 642 | |
| 643 | endef |
| 644 | |
| 645 | # MAKE_DTBS builds flattened device tree sources |
| 646 | # $(1) = output directory |
| 647 | # $(2) = list of flattened device tree source files |
| 648 | define MAKE_DTBS |
| 649 | $(eval DOBJS := $(filter %.dts,$(2))) |
| 650 | $(eval REMAIN := $(filter-out %.dts,$(2))) |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 651 | $(and $(REMAIN),$(error FDT_SOURCES contain non-DTS files: $(REMAIN))) |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 652 | $(eval $(foreach obj,$(DOBJS),$(call MAKE_DTB,$(1),$(obj)))) |
| 653 | |
Soby Mathew | ab4181d | 2017-12-14 17:44:56 +0000 | [diff] [blame] | 654 | $(eval $(call MAKE_FDT_DIRS,$(1),$(2))) |
| 655 | |
| 656 | dtbs: $(DTBS) |
| 657 | all: dtbs |
Nishanth Menon | 4ac02ba | 2016-10-14 01:13:57 +0000 | [diff] [blame] | 658 | endef |