-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
449 lines (364 loc) · 13.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
68
69
70
71
72
73
74
75
76
77
78
79
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# Main Makefile for the secure video demo
#
# See README.md for typical usage and documentation.
#
# make
# Build everything, or re-build what's necessary if some file changed in any
# subproject
#
# make build-<something>
# Make sure <something> is up-to-date, but do not consider cross-project
# dependencies. For instance, "make build-atf-fip" will make sure the
# Firmware Image Package file is up-to date wrt. all source files in the
# arm-trusted-firmware directory and the other required files (output
# of the optee-os and edk2 (UEFI) subdirectories). But it will not make sure
# that optee-os and edk2 are themselves up-to-date, unless explicitely
# asked to do so like this: "make build-atf-fip built-optee-os build-uefi"
#
# make clean
# Remove most files generated by make, except the downloaded tarballs and
# the directories they were extracted to.
#
# make cleaner
# Like clean, but also remove the directories for downloaded stuff
# (compilers, busybox...). Does not delete the downloaded tarballs.
#
# make distclean
# Remove all generated or downloaded files.
filename = $(lastword $(subst /, ,$(1)))
EDK2_URL = https://github.com/tianocore/edk2/archive/8c83d0c0b9bd102cd905c83b2644a543e9711815.tar.gz
EDK2_TARBALL = $(call filename,$(EDK2_URL))
EDK2_DIR = edk2-$(EDK2_TARBALL:.tar.gz=)
BUSYBOX_URL = http://busybox.net/downloads/busybox-1.23.0.tar.bz2
BUSYBOX_TARBALL = $(call filename,$(BUSYBOX_URL))
BUSYBOX_DIR = $(BUSYBOX_TARBALL:.tar.bz2=)
AARCH64_GCC_URL = http://releases.linaro.org/14.08/components/toolchain/binaries/gcc-linaro-aarch64-linux-gnu-4.9-2014.08_linux.tar.xz
AARCH64_GCC_TARBALL = $(call filename,$(AARCH64_GCC_URL))
AARCH64_GCC_DIR = $(AARCH64_GCC_TARBALL:.tar.xz=)
aarch64-linux-gnu-gcc := toolchains/$(AARCH64_GCC_DIR)
AARCH64_NONE_GCC_URL = http://releases.linaro.org/14.07/components/toolchain/binaries/gcc-linaro-aarch64-none-elf-4.9-2014.07_linux.tar.xz
AARCH64_NONE_GCC_TARBALL = $(call filename,$(AARCH64_NONE_GCC_URL))
AARCH64_NONE_GCC_DIR = $(AARCH64_NONE_GCC_TARBALL:.tar.xz=)
aarch64-none-elf-gcc := toolchains/$(AARCH64_NONE_GCC_DIR)
SHELL = /bin/bash
CURL = curl -L
_NPROCESSORS_ONLN = $(shell getconf _NPROCESSORS_ONLN)
ifneq (,$(shell which ccache))
CCACHE = ccache #
endif
export PATH := $(PATH):$(PWD)/toolchains/$(AARCH64_NONE_GCC_DIR)/bin:$(PWD)/toolchains/$(AARCH64_GCC_DIR)/bin:$(PWD)/linux/usr
# Read stdin, expand ${VAR} environment variables, output to stdout
# http://superuser.com/a/302847
define expand-env-var
awk '{while(match($$0,"[$$]{[^}]*}")) {var=substr($$0,RSTART+2,RLENGTH -3);gsub("[$$]{"var"}",ENVIRON[var])}}1'
endef
ifeq ($(V),1)
Q :=
ECHO := @:
else
Q := @
ECHO := @echo
endif
.PHONY: _all
_all:
$(Q)$(MAKE) all $(filter-out _all,$(MAKECMDGOALS))
all: build-linux build-arm-tf build-rootfs build-dtb
#
# Download rules
#
edk2: downloads/$(EDK2_TARBALL)
$(ECHO) ' TAR $@'
$(Q)rm -rf $(EDK2_DIR)
$(Q)tar xf downloads/$(EDK2_TARBALL)
$(Q)rm -rf $@
$(Q)mv $(EDK2_DIR) $@
$(Q)touch $@
downloads/$(EDK2_TARBALL):
$(ECHO) ' CURL $@'
$(Q)$(CURL) $(EDK2_URL) -o $@
.busybox: downloads/$(BUSYBOX_TARBALL)
$(ECHO) ' TAR gen_rootfs/busybox'
$(Q)rm -rf gen_rootfs/$(BUSYBOX_DIR) gen_rootfs/busybox
$(Q)cd gen_rootfs && tar xf ../downloads/$(BUSYBOX_TARBALL)
$(Q)mv gen_rootfs/$(BUSYBOX_DIR) gen_rootfs/busybox
$(Q)touch $@
downloads/$(BUSYBOX_TARBALL):
$(ECHO) ' CURL $@'
$(Q)$(CURL) $(BUSYBOX_URL) -o $@
toolchains/$(AARCH64_GCC_DIR): downloads/$(AARCH64_GCC_TARBALL)
$(ECHO) ' TAR $@'
$(Q)rm -rf toolchains/$(AARCH64_GCC_DIR)
$(Q)cd toolchains && tar xf ../downloads/$(AARCH64_GCC_TARBALL)
$(Q)touch $@
downloads/$(AARCH64_GCC_TARBALL):
$(ECHO) ' CURL $@'
$(Q)$(CURL) $(AARCH64_GCC_URL) -o $@
toolchains/$(AARCH64_NONE_GCC_DIR): downloads/$(AARCH64_NONE_GCC_TARBALL)
$(ECHO) ' TAR $@'
$(Q)rm -rf toolchains/$(AARCH64_NONE_GCC_DIR)
$(Q)cd toolchains && tar xf ../downloads/$(AARCH64_NONE_GCC_TARBALL)
$(Q)touch $@
downloads/$(AARCH64_NONE_GCC_TARBALL):
$(ECHO) ' CURL $@'
$(Q)$(CURL) $(AARCH64_NONE_GCC_URL) -o $@
#
# Clean rules
#
clean: clean-linux clean-dtb clean-optee-os clean-optee-client clean-optee-linuxdriver clean-secfb-driver clean-uefi clean-arm-tf clean-rootfs clean-app
$(ECHO) ' CLEAN .'
cleaner: clean
$(ECHO) ' CLEANER .'
$(Q)rm -rf $(EDK2_DIR) edk2
$(Q)rm -rf gen_rootfs/$(BUSYBOX_DIR) .busybox
$(Q)rm -rf toolchains/$(AARCH64_GCC_DIR)
$(Q)rm -rf toolchains/$(AARCH64_NONE_GCC_DIR)
# Also remove downloaded files
distclean: cleaner
$(ECHO) ' DISTCL .'
$(Q)rm -f downloads/$(EDK2_TARBALL)
$(Q)rm -f downloads/$(BUSYBOX_TARBALL)
$(Q)rm -f downloads/$(AARCH64_GCC_TARBALL)
$(Q)rm -f downloads/$(AARCH64_NONE_GCC_DIR)
$(MAKE) -C app distclean
#
# Linux
#
.PHONY: build-linux
build-linux linux/arch/arm64/boot/Image: linux/.config $(aarch64-none-elf-gcc)
$(Q)$(MAKE) -C linux \
-j$(_NPROCESSORS_ONLN) \
ARCH=arm64 \
CROSS_COMPILE="$(CCACHE)aarch64-none-elf-" \
LOCALVERSION=
linux/.config: $(aarch64-none-elf-gcc)
$(Q)$(MAKE) -C linux ARCH=arm64 CROSS_COMPILE=aarch64-none-elf- defconfig
linux/usr/gen_init_cpio: linux/.config
$(Q)$(MAKE) -C linux ARCH=arm64 usr/gen_init_cpio
linux/scripts/dtc/dtc: linux/.config $(aarch64-none-elf-gcc)
$(Q)$(MAKE) -C linux ARCH=arm64 CROSS_COMPILE=aarch64-none-elf- scripts
clean-linux:
$(ECHO) ' CLEAN linux'
$(Q)-[ -d linux ] && $(MAKE) -C linux ARCH=arm64 CROSS_COMPILE=aarch64-none-elf- clean
#
# Dummy "secure framebuffer" driver
#
.PHONY: build-secfb-driver
build-secfb-driver secfb_driver/secfb.ko: linux/arch/arm64/boot/Image $(aarch64-linux-gnu-gcc)
$(ECHO) ' BUILD optee_linuxdriver'
$(Q)$(MAKE) -C linux \
-j$(_NPROCESSORS_ONLN) \
ARCH=arm64 \
CROSS_COMPILE="$(CCACHE)aarch64-linux-gnu-" \
LOCALVERSION= \
M=../secfb_driver \
modules
clean-secfb-driver:
$(ECHO) ' CLEAN secfb_driver'
$(Q)-[ -d linux ] && $(MAKE) -C linux \
-j$(_NPROCESSORS_ONLN) \
ARCH=arm64 \
CROSS_COMPILE="$(CCACHE)aarch64-linux-gnu-" \
LOCALVERSION= \
M=../secfb_driver \
clean
#
# OP-TEE
#
optee-os-files := optee_os/out/arm32-plat-vexpress/core/tee.bin
.PHONY: build-optee-os
build-optee-os $(optee-os-files):
$(ECHO) ' BUILD optee_os'
$(Q)$(MAKE) -C optee_os \
-j$(_NPROCESSORS_ONLN) \
CROSS_COMPILE="$(CCACHE)arm-linux-gnueabihf-" \
PLATFORM=vexpress-fvp \
CFG_TEE_CORE_LOG_LEVEL=3
clean-optee-os:
$(ECHO) ' CLEAN optee_os'
$(Q)$(MAKE) -C optee_os \
-j$(_NPROCESSORS_ONLN) \
CROSS_COMPILE="$(CCACHE)arm-linux-gnueabihf-" \
PLATFORM=vexpress-fvp \
clean
#
# OP-TEE client
#
optee-client-files := optee_client/out/export/lib/libteec.so.1.0 \
optee_client/out/export/bin/tee-supplicant
.PHONY: build-optee-client
build-optee-client $(optee-client-files): $(aarch64-linux-gnu-gcc)
$(ECHO) ' BUILD optee_client'
$(Q)$(MAKE) -C optee_client \
-j$(_NPROCESSORS_ONLN) \
CROSS_COMPILE="$(CCACHE)aarch64-linux-gnu-"
clean-optee-client:
$(ECHO) ' CLEAN optee_client'
$(Q)$(MAKE) -C optee_client \
-j$(_NPROCESSORS_ONLN) \
CROSS_COMPILE="$(CCACHE)arm-linux-gnueabihf-" \
clean
#
# OP-TEE Linux driver
#
optee-linuxdriver-files := optee_linuxdriver/optee.ko \
optee_linuxdriver/optee_armtz.ko
.PHONY: build-optee-linuxdriver
build-optee-linuxdriver $(optee-linuxdriver-files): linux/arch/arm64/boot/Image $(aarch64-linux-gnu-gcc)
$(ECHO) ' BUILD optee_linuxdriver'
$(Q)$(MAKE) -C linux \
-j$(_NPROCESSORS_ONLN) \
ARCH=arm64 \
CROSS_COMPILE="$(CCACHE)aarch64-linux-gnu-" \
LOCALVERSION= \
M=../optee_linuxdriver \
modules
clean-optee-linuxdriver: clean-dtb
$(ECHO) ' CLEAN optee_linuxdriver'
$(Q)-[ -d linux ] && $(MAKE) -C linux \
-j$(_NPROCESSORS_ONLN) \
ARCH=arm64 \
CROSS_COMPILE="$(CCACHE)aarch64-linux-gnu-" \
LOCALVERSION= \
M=../optee_linuxdriver \
clean
.PHONY: build-dtb
build-dtb: arm-trusted-firmware/fdts/fvp-foundation-gicv2-psci.dtb
arm-trusted-firmware/fdts/fvp-foundation-gicv2-psci.dtb: arm-trusted-firmware/fdts/fvp-foundation-gicv2-psci.dts linux/scripts/dtc/dtc
$(ECHO) ' GEN $@'
$(Q)cd arm-trusted-firmware/fdts && \
../../linux/scripts/dtc/dtc -O dtb -o fvp-foundation-gicv2-psci.dtb \
-b 0 -i . fvp-foundation-gicv2-psci.dts
clean-dtb:
$(ECHO) ' RM arm-trusted-firmware/fdts/fvp-foundation-gicv2-psci.dtb'
$(Q)rm -f arm-trusted-firmware/fdts/fvp-foundation-gicv2-psci.dtb
#
# UEFI
#
.PHONY: build-uefi
build-uefi edk2/Build/ArmVExpress-FVP-AArch64/RELEASE_GCC49/FV/FVP_AARCH64_EFI.fd: $(aarch64-none-elf-gcc) edk2/.BaseTools
$(ECHO) ' BUILD edk2'
$(Q)set -e ; cd edk2 ; export GCC49_AARCH64_PREFIX='"$(CCACHE)aarch64-none-elf-"' ; \
. edksetup.sh ; \
$(MAKE) -f ArmPlatformPkg/Scripts/Makefile \
EDK2_ARCH=AARCH64 \
EDK2_DSC=ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc \
EDK2_TOOLCHAIN=GCC49 EDK2_BUILD=RELEASE \
EDK2_MACROS="-n 6 -D ARM_FOUNDATION_FVP=1"
$(Q)touch edk2/Build/ArmVExpress-FVP-AArch64/RELEASE_GCC49/FV/FVP_AARCH64_EFI.fd
edk2/.BaseTools: edk2
$(ECHO) ' BUILD edk2/BaseTools'
$(Q)set -e ; cd edk2 ; export GCC49_AARCH64_PREFIX='"$(CCACHE)aarch64-none-elf-"' ; \
. edksetup.sh ; \
$(MAKE) -C BaseTools CC="$(CCACHE)gcc" CXX="$(CCACHE)g++" ; \
touch .BaseTools
clean-uefi: clean-uefi-basetools
$(ECHO) ' CLEAN edk2'
$(Q)-[ -d edk2 ] && ( set -e ; cd edk2 ; \
. edksetup.sh ; \
$(MAKE) -f ArmPlatformPkg/Scripts/Makefile \
EDK2_ARCH=AARCH64 \
EDK2_DSC=ArmPlatformPkg/ArmVExpressPkg/ArmVExpress-FVP-AArch64.dsc \
EDK2_TOOLCHAIN=GCC49 EDK2_BUILD=RELEASE \
EDK2_MACROS="-n 6 -D ARM_FOUNDATION_FVP=1" \
clean )
clean-uefi-basetools:
$(ECHO) ' CLEAN edk2/BaseTools'
$(Q)-[ -d edk2 ] && ( set -e ; cd edk2 ; \
. edksetup.sh ; \
$(MAKE) -C BaseTools clean ; \
rm -f .BaseTools)
#
# ARM Trusted Firmware
#
.PHONY: build-arm-tf
build-arm-tf: build-arm-tf-bl1 build-arm-tf-fip
ATF = arm-trusted-firmware/build/fvp/debug
define arm-tf-make
$(ECHO) ' BUILD $@'
$(Q)export CFLAGS="-O0 -gdwarf-2" ; \
export BL32=$(PWD)/optee_os/out/arm32-plat-vexpress/core/tee.bin ; \
export BL33=$(PWD)/edk2/Build/ArmVExpress-FVP-AArch64/RELEASE_GCC49/FV/FVP_AARCH64_EFI.fd ; \
$(MAKE) -C arm-trusted-firmware \
CROSS_COMPILE="$(CCACHE)aarch64-none-elf-" \
DEBUG=1 \
FVP_TSP_RAM_LOCATION=tdram \
FVP_SHARED_DATA_LOCATION=tdram \
PLAT=fvp \
SPD=opteed \
$(1)
endef
.PHONY: build-arm-tf-bl2-bl31
build-arm-tf-bl2-bl31 $(ATF)/bl2.bin $(ATF)/bl31.bin: $(aarch64-none-elf-gcc)
$(call arm-tf-make, bl2 bl31)
# "$(MAKE) -C arm-trusted-firmware fip" always updates fip.bin, even if it is
# up-to-date, so we can't add just add build-arm-tf-fip and fip.bin to the
# left side of the above rule and add 'fip' to the $(MAKE) command. This would
# result in "$(MAKE) build-arm-tf-fip" always touching fip.bin.
# The double-colon rules below are processed in order, which solves the issue.
ifneq ($(filter all build-optee-os,$(MAKECMDGOALS)),)
tf-other-projects-deps += build-optee-os
endif
ifneq ($(filter all build-uefi,$(MAKECMDGOALS)),)
tf-other-projects-deps += build-uefi
endif
.PHONY: build-arm-tf-fip
build-arm-tf-fip:: build-arm-tf-bl2-bl31 $(tf-other-projects-deps)
build-arm-tf-fip:: $(ATF)/fip.bin
$(ATF)/fip.bin: $(ATF)/bl2.bin $(ATF)/bl31.bin optee_os/out/arm32-plat-vexpress/core/tee.bin edk2/Build/ArmVExpress-FVP-AArch64/RELEASE_GCC49/FV/FVP_AARCH64_EFI.fd $(aarch64-none-elf-gcc)
$(call arm-tf-make, fip)
.PHONY: build-arm-tf-bl1
build-arm-tf-bl1 arm-trusted-firmware/build/fvp/debug/bl1.bin: $(aarch64-none-elf-gcc)
$(call arm-tf-make, bl1)
clean-arm-tf:
$(ECHO) ' CLEAN arm-trusted-firmware'
$(Q)$(MAKE) -C arm-trusted-firmware PLAT=fvp DEBUG=1 clean
#
# Application (normal world + trusted app)
#
app-files := app/host/secvideo_demo app/ta/ffa39702-9ce0-47e0-a1cb4048cfdb847d.ta
ifneq ($(filter all build-optee-os,$(MAKECMDGOALS)),)
app-other-projects-deps += build-optee-os
endif
ifneq ($(filter all build-optee-client,$(MAKECMDGOALS)),)
app-other-projects-deps += build-optee-client
endif
build-app:: $(app-other-projects-deps)
build-app:: $(app-files)
build-app:: do-build-app
.PHONY: do-build-app
do-build-app $(app-files): $(optee-client-files) $(optee-os-files)
$(MAKE) -C app
.PHONY: clean-app
clean-app:
$(MAKE) -C app clean
#
# Root fs
#
ifneq ($(filter all build-app,$(MAKECMDGOALS)),)
rootfs-other-projects-deps += build-app
endif
ifneq ($(filter all build-optee-linuxdriver,$(MAKECMDGOALS)),)
rootfs-other-projects-deps += build-optee-linuxdriver
endif
.PHONY: build-rootfs
build-rootfs:: build-filelist $(rootfs-other-projects-deps)
build-rootfs:: rootfs-cpio
rootfs-cpio run/filesystem.cpio.gz: gen_rootfs/filelist-tee.txt linux/usr/gen_init_cpio $(optee-client-files) $(optee-linuxdriver-files) secfb_driver/secfb.ko
$(ECHO) " GEN run/filesystem.cpio.gz"
$(Q)(cd gen_rootfs && gen_init_cpio filelist-tee.txt) | gzip >run/filesystem.cpio.gz
gen_rootfs/filelist-tee.txt: gen_rootfs/filelist-final.txt tee-files.txt
$(ECHO) ' GEN $@'
$(Q)cat gen_rootfs/filelist-final.txt | sed '/fbtest/d' >$@
$(Q)export KERNEL_VERSION=`cd linux ; $(MAKE) --no-print-directory -s kernelversion` ;\
export TOP=$(PWD) ; \
$(expand-env-var) <tee-files.txt >>$@
.PHONY: build-filelist
build-filelist gen_rootfs/filelist-final.txt: .busybox $(aarch64-linux-gnu-gcc)
$(ECHO) ' GEN gen_rootfs/filelist-final.txt'
$(Q)cd gen_rootfs ; \
export CC_DIR=$(PWD)/toolchains/$(AARCH64_GCC_DIR) ; \
./generate-cpio-rootfs.sh fvp-aarch64 nocpio
clean-rootfs:
$(ECHO) " CLEAN gen_rootfs"
$(Q)cd gen_rootfs ; ./generate-cpio-rootfs.sh fvp-aarch64 clean
$(Q)rm -f run/filesystem.cpio.gz gen_rootfs/filelist-tee.txt