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