top.mk 9.94 KB
Newer Older
1
2
3
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) Arm Limited, 2020
4
5
6
7
8
9
10
#
# Makefile Conventions:
# Variable names:
# *_PATH:   Full path to project source directories or other assets
# *_OUTPUT: Build directories for each of the sub projects
# *_EXTRA:  Extra parameters to the make call. Gets added to make targets, e.g.
#           "$(MAKE) -C ${PROJECT_PATH} ... ${PROJECT_EXTRA} ..."
11

Grant Likely's avatar
Grant Likely committed
12
13
SHELL := /bin/bash

14
# Set some defaults that can be overridden by the target  makefile include
15
16
DT_PATH    := $(CURDIR)/devicetree-rebasing
DT_OUTPUT  := $(DT_PATH)
Grant Likely's avatar
Grant Likely committed
17
18
19
EDK2_PATH  := $(CURDIR)/edk2
EDK2_PLATFORMS_PATH := $(CURDIR)/edk2-platforms
OPTEE_PATH := $(CURDIR)/optee_os
20
21
TFA_PATH   := $(CURDIR)/trusted-firmware-a
UBOOT_PATH := $(CURDIR)/u-boot
22
23

# Give the option of building in a separate directory
24
ifneq ($(BUILD_OUTPUT),)
25
  __BUILD := $(realpath $(BUILD_OUTPUT))
Grant Likely's avatar
Grant Likely committed
26
  EDK2_OUTPUT := $(__BUILD)/edk2
Grant Likely's avatar
Grant Likely committed
27
28
  OPTEE_OUTPUT := $(__BUILD)/optee_os
  OPTEE_EXTRA += O=$(OPTEE_OUTPUT)
29
30
31
32
  TFA_OUTPUT := $(__BUILD)/tfa
  TFA_EXTRA += BUILD_BASE=$(TFA_OUTPUT)
  UBOOT_OUTPUT := $(__BUILD)/u-boot
  UBOOT_EXTRA += KBUILD_OUTPUT=$(UBOOT_OUTPUT)
33
else
Grant Likely's avatar
Grant Likely committed
34
35
  EDK2_OUTPUT := $(EDK2_PATH)
  OPTEE_OUTPUT := $(OPTEE_PATH)/out
36
37
  TFA_OUTPUT := $(TFA_PATH)/build
  UBOOT_OUTPUT := $(UBOOT_PATH)
38
endif
39

Grant Likely's avatar
Grant Likely committed
40
41
42
# Default target when none provided on command line
all: flashimage

Grant Likely's avatar
Grant Likely committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
help:
	@echo  'Cleaning targets:'
	@echo  '  clean		  - Remove most generated files but keep the config'
	@echo  '  mrproper	  - Remove all generated files + config + various backup files'
	@echo  ''
	@echo  'Configuration targets:'
	@$(MAKE) -C $(UBOOT_PATH) -f $(UBOOT_PATH)/scripts/kconfig/Makefile --no-print-directory help
	@echo  ''
	@echo  '  Only a subset of U-Boot defconfigs will work with this tool. For this tool'
	@echo  '  to work, $$TFA_PLAT needs to be set. See scripts/*.mk for examples. Adding'
	@echo  '  support for a new platform requires inspecting the U-Boot configuration and'
	@echo  '  choosing the correct $$TFA_PLAT value.'
	@echo  ''
	@echo  'Project targets:'
	@echo  ''
	@echo  '  u-boot/<name>		  - Build U-Boot target <name>'
	@echo  '  tfa/<name>		  - Build Trusted Firmware target <name> *'
	@echo  '  devicetree/<name>	  - Build Devicetree target <name> *'
	@echo  '    * Can only be called if U-Boot is configured'
	@echo  ''
	@echo  'Other targets:'
	@echo  ''
	@echo  '  help		  - This help text'
	@echo  '  info		  - Display details about the build configuration'

68
69
# ===========================================================================
# Rules shared between *config targets and build targets
70

71
72
73
74
75
76
77
78
# To make sure we do not include .config for any of the *config targets
# catch them early
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'.
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).

Grant Likely's avatar
Grant Likely committed
79
no-dot-config-targets := clean mrproper distclean u-boot/% tfa/%clean devicetree/clean help
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

config-targets := 0
mixed-targets  := 0
dot-config     := 1

ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
		dot-config := 0
	endif
endif

ifneq ($(filter %config,$(MAKECMDGOALS)),)
        config-targets := 1
        ifneq ($(words $(MAKECMDGOALS)),1)
                mixed-targets := 1
        endif
endif

ifeq ($(mixed-targets),1)
# ===========================================================================
# We're called with mixed targets (*config and build targets).
# Handle them one by one.
PHONY += $(MAKECMDGOALS) __build_one_by_one

$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
	@:
106

107
108
109
110
111
112
113
114
115
116
117
118
119
__build_one_by_one:
	$(Q)set -e; \
	for i in $(MAKECMDGOALS); do \
		$(MAKE) $$i; \
	done

else
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
# in scripts/kconfig to make the *config target

%config: u-boot/%config
120
	$(UBOOT_PATH)/scripts/kconfig/merge_config.sh -m -O $(UBOOT_OUTPUT) $(UBOOT_OUTPUT)/.config scripts/ebbr.config
121
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) olddefconfig
122

123
PHONY += defconfig
124
defconfig: rockpro64-rk3399_defconfig ;
125
126
127
128
129
130
131
132

else
# ===========================================================================
# Build targets only
# In general all targets that make use of the selected configuration

ifeq ($(dot-config),1)
# Read in config
Grant Likely's avatar
Grant Likely committed
133
-include $(UBOOT_OUTPUT)/.config
134
135
136

# ===================================
# Platform/SOC specific configuration
137
138
139
140
#
# Try including platform specific configs
# Platform specific config could be SOC, Vendor, or config

Grant Likely's avatar
Grant Likely committed
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
INCLUDE_MK := scripts/cpu-$(subst ",,$(CONFIG_SYS_CPU)).mk
INCLUDE_MK += scripts/vendor-$(subst ",,$(CONFIG_SYS_VENDOR)).mk
INCLUDE_MK += scripts/soc-$(subst ",,$(CONFIG_SYS_SOC)).mk
INCLUDE_MK += scripts/board-$(subst ",,$(CONFIG_SYS_BOARD)).mk
INCLUDE_MK += scripts/config-$(subst ",,$(CONFIG_SYS_CONFIG_NAME)).mk
include $(wildcard $(INCLUDE_MK))

ifeq ($(MAKECMDGOALS),info)
info:
	@echo 'U-Boot Config:'
	@echo '  CONFIG_SYS_CPU=$(subst ",,$(CONFIG_SYS_CPU))'
	@echo '  CONFIG_SYS_VENDOR=$(subst ",,$(CONFIG_SYS_VENDOR))'
	@echo '  CONFIG_SYS_SOC=$(subst ",,$(CONFIG_SYS_SOC))'
	@echo '  CONFIG_SYS_BOARD=$(subst ",,$(CONFIG_SYS_BOARD))'
	@echo '  CONFIG_SYS_CONFIG_NAME=$(subst ",,$(CONFIG_SYS_CONFIG_NAME))'
156
157
	@echo '  CONFIG_OPTEE=$(subst ",,$(CONFIG_OPTEE))'
	@echo '  CONFIG_EFI_MM_COMM_TEE=$(subst ",,$(CONFIG_EFI_MM_COMM_TEE))'
Grant Likely's avatar
Grant Likely committed
158
159
160
161
162
163
	@echo 'Derived Config:'
	@echo '  TFA_PLAT=$(TFA_PLAT)'
	@echo '  FLASH_IMAGE=$(FLASH_IMAGE)'
	@echo 'Included platform configuration files:'
	@$(foreach inc, $(wildcard $(INCLUDE_MK)), echo '  $(inc)';)
else
164
ifeq ($(TFA_PLAT),)
Grant Likely's avatar
Grant Likely committed
165
166
167
168
169
170
  $(info $$TFA_PLAT is not set. Either U-Boot is not configured, the platform is not)
  $(info yet supported, or there is a bug. Use \'make info\' to see the current)
  $(info configuration)
  $(info )
  $(error Invalid configuration)
endif
171
ifeq ($(CONFIG_OPTEE)$(OPTEE_PLATFORM),y)
Grant Likely's avatar
Grant Likely committed
172
173
174
175
176
177
  $(info OPTEE is enabled, but $$OPTEE_PLATFORM is not set. Either the platform is not)
  $(info yet supported, or there is a bug. Use \'make info\' to see the current)
  $(info configuration)
  $(info )
  $(error Invalid configuration)
endif
178
179
endif

180
ifeq ($(CONFIG_OPTEE),y)
Grant Likely's avatar
Grant Likely committed
181
182
# ----------------------------------------------------------------------
# Standalone-MM build configuration
183
ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
Grant Likely's avatar
Grant Likely committed
184
185

# EDK2 Environmental variables; easiest to export these
Grant Likely's avatar
Grant Likely committed
186
export WORKSPACE=$(CURDIR)
Grant Likely's avatar
Grant Likely committed
187
188
export PACKAGES_PATH=$(EDK2_PATH):$(EDK2_PLATFORMS_PATH)
export GCC5_AARCH64_PREFIX=$(CROSS_COMPILE)
Grant Likely's avatar
Grant Likely committed
189
export ACTIVE_PLATFORM=Platform/StMMRpmb/PlatformStandaloneMm.dsc
Grant Likely's avatar
Grant Likely committed
190

Grant Likely's avatar
Grant Likely committed
191
# Tell optee where to find StMM
Grant Likely's avatar
Grant Likely committed
192
OPTEE_EXTRA += CFG_STMM_PATH=$(EDK2_OUTPUT)/QemuVirtMmStandalone/DEBUG_GCC5/FV/BL32_AP-MM.fd
Grant Likely's avatar
Grant Likely committed
193
194
195

optee/all: stmm/all

196
197
edk2/BaseTools:
	source $(EDK2_PATH)/edksetup.sh && $(MAKE) -C $(EDK2_PATH)/BaseTools
Grant Likely's avatar
Grant Likely committed
198

199
200
stmm/all: edk2/BaseTools
	source $(EDK2_PATH)/edksetup.sh && build -p $(ACTIVE_PLATFORM) -b DEBUG -a AARCH64 -t GCC5 -D DO_X86EMU=TRUE
Grant Likely's avatar
Grant Likely committed
201

202
endif # ifeq($(CONFIG_EFI_MM_COMM_TEE),y)
Grant Likely's avatar
Grant Likely committed
203
204
205
206
207
208
209

# ----------------------------------------------------------------------
# OP-TEE build configuration
OPTEE_EXTRA += ARCH=arm
OPTEE_EXTRA += CROSS_COMPILE32=arm-linux-gnueabihf-
OPTEE_EXTRA += PLATFORM=$(OPTEE_PLATFORM)
OPTEE_EXTRA += CFG_ARM64_core=y
Grant Likely's avatar
Grant Likely committed
210
211
212
213
OPTEE_EXTRA += CFG_RPMB_FS=y
OPTEE_EXTRA += CFG_RPMB_FS_DEV_ID=1
OPTEE_EXTRA += CFG_RPMB_WRITE_KEY=1
OPTEE_EXTRA += CFG_CORE_HEAP_SIZE=524288
Grant Likely's avatar
Grant Likely committed
214
215
216
217
218
219
220
221
#OPTEE_EXTRA += CFG_TEE_CORE_LOG_LEVEL=3
#OPTEE_EXTRA += CFG_CORE_ASLR=n
#OPTEE_EXTRA += CFG_TA_ASLR=n

# Tell TFA where to find the OP-TEE binaries
TFA_EXTRA += BL32=$(OPTEE_OUTPUT)/arm-plat-vexpress/core/tee-header_v2.bin
TFA_EXTRA += BL32_EXTRA1=$(OPTEE_OUTPUT)/arm-plat-vexpress/core/tee-pager_v2.bin
TFA_EXTRA += BL32_EXTRA2=$(OPTEE_OUTPUT)/arm-plat-vexpress/core/tee-pageable_v2.bin
Grant Likely's avatar
Grant Likely committed
222
223
224
225
TFA_EXTRA += BL32_RAM_LOCATION=tdram
TFA_EXTRA += SPD=opteed

tfa/all tfa/fip: optee/all
Grant Likely's avatar
Grant Likely committed
226
227
228
229
230
231

# ================================================
# Delegate optee targets to optee Makefile
optee/%:
	${MAKE} -C ${OPTEE_PATH} ${OPTEE_EXTRA} $*

232
endif # ifeq($(CONFIG_OPTEE),y)
Grant Likely's avatar
Grant Likely committed
233
234

# Default Trusted Firmware configuration settings
235
236
237
238
239
240
TFA_EXTRA += PLAT=$(TFA_PLAT)
TFA_EXTRA += LOG_LEVEL=20
TFA_EXTRA += BL33=$(UBOOT_OUTPUT)/u-boot.bin

FLASH_IMAGE ?= $(TFA_OUTPUT)/$(TFA_PLAT)/release/flash-image.bin
FLASH_IMAGE_DEPS ?= tfa/all tfa/fip
241
SD_IMAGE := $(subst ",,$(CONFIG_SYS_CONFIG_NAME))-sdcard.img
242
243
244
245
246
ESP_SIZE ?= $$((64*1024*1024))
ESP_OFFSET ?= $$((4*1024*1024))

endif # ifeq ($(dot-config),1)

247
ifneq ($(DTB_TARGET),)
248
249
250
251
252
PHONY += dtb
dtb: ${DTB_TARGET}
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / u-boot-ver `cd ${UBOOT_PATH} && git describe`
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / tfa-ver `cd ${TFA_PATH} && git describe`
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / dt-ver `cd ${DT_PATH} && git describe`
253
endif
254
255
256
257
258
259
260

PHONY += flashimage sdimage

flashimage ${FLASH_IMAGE}: ${FLASH_IMAGE_DEPS}

sdimage: flashimage

261
262
263
264
265
266
267
268
PHONY += clean mrproper distclean
clean: u-boot/clean tfa/clean devicetree/clean
	cd $(CURDIR)/mv-ddr && git clean -fdx

mrproper: u-boot/mrproper tfa/distclean devicetree/clean
	cd $(CURDIR)/mv-ddr && git clean -fdx

distclean: u-boot/distclean tfa/distclean devicetree/clean
269
270
271
272
273
274
275
276
277
	cd $(CURDIR)/mv-ddr && git clean -fdx

endif #ifeq ($(config-targets),1)

# ===========================================================================
# Common targets - Mostly delegates to the individual project build systems

# ================================================
# Delegate to devicetree-rebasing build
278
279
280
#
devicetree/%:
	${MAKE} -C ${DT_PATH} $*
281

Grant Likely's avatar
Grant Likely committed
282
# ================================================
Grant Likely's avatar
Grant Likely committed
283
284
285
# Delegate to op-tee clean target
optee/clean:
	${MAKE} -C ${OPTEE_PATH} clean
Grant Likely's avatar
Grant Likely committed
286

287
288
289
290
291
# ================================================
# Delegate to trusted-firmware-a build
tfa/%:
	${MAKE} -C ${TFA_PATH} ${TFA_EXTRA} $*

292
tfa/all tfa/fip: u-boot/all
293
294
295
296
297
298
299

# ================================================
# Delegate to u-boot build
u-boot/%:
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) $*

endif #ifeq ($(mixed-targets),1)
300