top.mk 10.7 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/Build
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
  EDK2_OUTPUT := $(CURDIR)/Build
Grant Likely's avatar
Grant Likely committed
35
  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
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  ''
63
64
65
66
67
68
69
70
71
72
73
	@echo  'Emulation targets (if available for given u-boot configuration:'
	@echo  ''
	@echo  '  qemu-fip:		  - Boot in QEMU using FIP image as -bios'
	@echo  '  qemu-semihosting:	  - Boot in QEMU with semihosting'
	@echo  ''
	@echo  '  QEMU configuration can be manipulated with environmental variables:'
	@echo  '  VIRTDISK	Path to a raw disk image. Could be an ISO, or a GPT or MBR'
	@echo  '		partitioned disk image. The image will be passed to QEMU as a'
	@echo  '		virtio block device'
	@echo  '  QEMU_EXTRA	List of extra command line options passed to QEMU'
	@echo  ''
Grant Likely's avatar
Grant Likely committed
74
75
76
77
78
	@echo  'Other targets:'
	@echo  ''
	@echo  '  help		  - This help text'
	@echo  '  info		  - Display details about the build configuration'

79
80
# ===========================================================================
# Rules shared between *config targets and build targets
81

82
83
84
85
86
87
88
89
# 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
90
no-dot-config-targets := clean mrproper distclean u-boot/% tfa/%clean devicetree/clean help
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

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
	@:
117

118
119
120
121
122
123
124
125
126
127
128
129
__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

130
131
132
133
addstmmconfig:
	$(UBOOT_PATH)/scripts/kconfig/merge_config.sh -m -O $(UBOOT_OUTPUT) $(UBOOT_OUTPUT)/.config scripts/stmm.config
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) olddefconfig

134
%config: u-boot/%config
135
	$(UBOOT_PATH)/scripts/kconfig/merge_config.sh -m -O $(UBOOT_OUTPUT) $(UBOOT_OUTPUT)/.config scripts/ebbr.config
136
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) olddefconfig
137

138
PHONY += defconfig
139
defconfig: rockpro64-rk3399_defconfig ;
140
141
142
143
144
145
146
147

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
148
-include $(UBOOT_OUTPUT)/.config
149
150
151

# ===================================
# Platform/SOC specific configuration
152
153
154
155
#
# Try including platform specific configs
# Platform specific config could be SOC, Vendor, or config

Grant Likely's avatar
Grant Likely committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
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))'
171
172
	@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
173
174
175
176
177
178
	@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
179
ifeq ($(TFA_PLAT),)
Grant Likely's avatar
Grant Likely committed
180
181
182
183
184
185
  $(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
186
ifeq ($(CONFIG_OPTEE)$(OPTEE_PLATFORM),y)
Grant Likely's avatar
Grant Likely committed
187
188
189
190
191
192
  $(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
193
194
endif

195
ifeq ($(CONFIG_OPTEE),y)
Grant Likely's avatar
Grant Likely committed
196
197
# ----------------------------------------------------------------------
# Standalone-MM build configuration
198
ifeq ($(CONFIG_EFI_MM_COMM_TEE),y)
Grant Likely's avatar
Grant Likely committed
199
200

# EDK2 Environmental variables; easiest to export these
Grant Likely's avatar
Grant Likely committed
201
export WORKSPACE=$(CURDIR)
Grant Likely's avatar
Grant Likely committed
202
203
export PACKAGES_PATH=$(EDK2_PATH):$(EDK2_PLATFORMS_PATH)
export GCC5_AARCH64_PREFIX=$(CROSS_COMPILE)
Grant Likely's avatar
Grant Likely committed
204
export ACTIVE_PLATFORM=Platform/StMMRpmb/PlatformStandaloneMm.dsc
Grant Likely's avatar
Grant Likely committed
205

206
STMM_FD := $(EDK2_OUTPUT)/MmStandaloneRpmb/DEBUG_GCC5/FV/BL32_AP_MM.fd
Grant Likely's avatar
Grant Likely committed
207

208
209
# Tell optee where to find StMM
OPTEE_EXTRA += CFG_STMM_PATH=$(STMM_FD)
Grant Likely's avatar
Grant Likely committed
210

211
optee_os/all: stmm/all $(STMM_FD)
212
213
edk2/BaseTools:
	source $(EDK2_PATH)/edksetup.sh && $(MAKE) -C $(EDK2_PATH)/BaseTools
Grant Likely's avatar
Grant Likely committed
214

215
216
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
217

218
endif # ifeq($(CONFIG_EFI_MM_COMM_TEE),y)
Grant Likely's avatar
Grant Likely committed
219
220
221
222
223
224
225

# ----------------------------------------------------------------------
# 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
226
227
228
229
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
230
231
232
233
234
235
236
237
#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
238
239
240
TFA_EXTRA += BL32_RAM_LOCATION=tdram
TFA_EXTRA += SPD=opteed

241
tfa/all tfa/fip: optee_os/all
Grant Likely's avatar
Grant Likely committed
242
243
244

# ================================================
# Delegate optee targets to optee Makefile
245
optee_os/%:
Grant Likely's avatar
Grant Likely committed
246
247
	${MAKE} -C ${OPTEE_PATH} ${OPTEE_EXTRA} $*

248
endif # ifeq($(CONFIG_OPTEE),y)
Grant Likely's avatar
Grant Likely committed
249
250

# Default Trusted Firmware configuration settings
251
252
253
254
255
256
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
257
SD_IMAGE := $(subst ",,$(CONFIG_SYS_CONFIG_NAME))-sdcard.img
258
259
260
261
262
ESP_SIZE ?= $$((64*1024*1024))
ESP_OFFSET ?= $$((4*1024*1024))

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

263
ifneq ($(DTB_TARGET),)
264
265
266
267
268
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`
269
endif
270
271
272
273
274
275
276

PHONY += flashimage sdimage

flashimage ${FLASH_IMAGE}: ${FLASH_IMAGE_DEPS}

sdimage: flashimage

277
PHONY += clean mrproper distclean
278
clean: u-boot/clean tfa/distclean devicetree/clean optee_os/clean
279
280
281
282
283
284
	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
285
286
287
288
289
290
291
292
293
	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
294
295
296
#
devicetree/%:
	${MAKE} -C ${DT_PATH} $*
297

Grant Likely's avatar
Grant Likely committed
298
# ================================================
Grant Likely's avatar
Grant Likely committed
299
# Delegate to op-tee clean target
300
optee_os/clean:
Grant Likely's avatar
Grant Likely committed
301
	${MAKE} -C ${OPTEE_PATH} clean
Grant Likely's avatar
Grant Likely committed
302

303
304
305
306
307
# ================================================
# Delegate to trusted-firmware-a build
tfa/%:
	${MAKE} -C ${TFA_PATH} ${TFA_EXTRA} $*

308
tfa/all tfa/fip: u-boot/all
309
310
311
312
313
314
315

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

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