forked from OP-TEE/build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qemu_v8.mk
239 lines (198 loc) · 7.55 KB
/
qemu_v8.mk
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
################################################################################
# Following variables defines how the NS_USER (Non Secure User - Client
# Application), NS_KERNEL (Non Secure Kernel), S_KERNEL (Secure Kernel) and
# S_USER (Secure User - TA) are compiled
################################################################################
COMPILE_NS_USER ?= 64
override COMPILE_NS_KERNEL := 64
COMPILE_S_USER ?= 64
COMPILE_S_KERNEL ?= 64
################################################################################
# If you change this, you MUST run `make arm-tf-clean` first before rebuilding
################################################################################
TF_A_TRUSTED_BOARD_BOOT ?= n
BR2_ROOTFS_OVERLAY = $(ROOT)/build/br-ext/board/qemu/overlay
BR2_ROOTFS_POST_BUILD_SCRIPT = $(ROOT)/build/br-ext/board/qemu/post-build.sh
BR2_ROOTFS_POST_SCRIPT_ARGS = "$(QEMU_VIRTFS_AUTOMOUNT) $(QEMU_VIRTFS_MOUNTPOINT) $(QEMU_PSS_AUTOMOUNT)"
OPTEE_OS_PLATFORM = vexpress-qemu_armv8a
include common.mk
DEBUG ?= 1
################################################################################
# Paths to git projects and various binaries
################################################################################
TF_A_PATH ?= $(ROOT)/trusted-firmware-a
BINARIES_PATH ?= $(ROOT)/out/bin
EDK2_PATH ?= $(ROOT)/edk2
EDK2_TOOLCHAIN ?= GCC49
EDK2_ARCH ?= AARCH64
ifeq ($(DEBUG),1)
EDK2_BUILD ?= DEBUG
else
EDK2_BUILD ?= RELEASE
endif
EDK2_BIN ?= $(EDK2_PATH)/Build/ArmVirtQemuKernel-$(EDK2_ARCH)/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/FV/QEMU_EFI.fd
QEMU_PATH ?= $(ROOT)/qemu
SOC_TERM_PATH ?= $(ROOT)/soc_term
################################################################################
# Targets
################################################################################
all: arm-tf buildroot edk2 linux optee-os qemu soc-term
clean: arm-tf-clean buildroot-clean edk2-clean linux-clean optee-os-clean \
qemu-clean soc-term-clean check-clean
include toolchain.mk
################################################################################
# ARM Trusted Firmware
################################################################################
TF_A_EXPORTS ?= \
CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
TF_A_DEBUG ?= $(DEBUG)
ifeq ($(TF_A_DEBUG),0)
TF_A_LOGLVL ?= 30
TF_A_OUT = $(TF_A_PATH)/build/qemu/release
else
TF_A_LOGLVL ?= 50
TF_A_OUT = $(TF_A_PATH)/build/qemu/debug
endif
TF_A_FLAGS ?= \
BL32=$(OPTEE_OS_HEADER_V2_BIN) \
BL32_EXTRA1=$(OPTEE_OS_PAGER_V2_BIN) \
BL32_EXTRA2=$(OPTEE_OS_PAGEABLE_V2_BIN) \
BL33=$(EDK2_BIN) \
PLAT=qemu \
ARM_TSP_RAM_LOCATION=tdram \
BL32_RAM_LOCATION=tdram \
SPD=opteed \
DEBUG=$(TF_A_DEBUG) \
LOG_LEVEL=$(TF_A_LOGLVL)
ifeq ($(TF_A_TRUSTED_BOARD_BOOT),y)
TF_A_FLAGS += \
MBEDTLS_DIR=$(ROOT)/mbedtls \
TRUSTED_BOARD_BOOT=1 \
GENERATE_COT=1
endif
arm-tf: optee-os edk2
$(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) all fip
mkdir -p $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/bl1.bin $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/bl2.bin $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/bl31.bin $(BINARIES_PATH)
ifeq ($(TF_A_TRUSTED_BOARD_BOOT),y)
ln -sf $(TF_A_OUT)/trusted_key.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/tos_fw_key.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/tos_fw_content.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/tb_fw.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/soc_fw_key.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/soc_fw_content.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/nt_fw_key.crt $(BINARIES_PATH)
ln -sf $(TF_A_OUT)/nt_fw_content.crt $(BINARIES_PATH)
endif
ln -sf $(OPTEE_OS_HEADER_V2_BIN) $(BINARIES_PATH)/bl32.bin
ln -sf $(OPTEE_OS_PAGER_V2_BIN) $(BINARIES_PATH)/bl32_extra1.bin
ln -sf $(OPTEE_OS_PAGEABLE_V2_BIN) $(BINARIES_PATH)/bl32_extra2.bin
ln -sf $(EDK2_BIN) $(BINARIES_PATH)/bl33.bin
arm-tf-clean:
$(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) clean
################################################################################
# QEMU
################################################################################
qemu:
cd $(QEMU_PATH); ./configure --target-list=aarch64-softmmu\
$(QEMU_CONFIGURE_PARAMS_COMMON)
$(MAKE) -C $(QEMU_PATH)
qemu-clean:
$(MAKE) -C $(QEMU_PATH) distclean
################################################################################
# EDK2 / Tianocore
################################################################################
define edk2-env
export WORKSPACE=$(EDK2_PATH)
endef
define edk2-call
$(EDK2_TOOLCHAIN)_$(EDK2_ARCH)_PREFIX=$(AARCH64_CROSS_COMPILE) \
build -n `getconf _NPROCESSORS_ONLN` -a $(EDK2_ARCH) \
-t $(EDK2_TOOLCHAIN) -p ArmVirtPkg/ArmVirtQemuKernel.dsc \
-b $(EDK2_BUILD)
endef
edk2: edk2-common
edk2-clean: edk2-clean-common
################################################################################
# Linux kernel
################################################################################
LINUX_DEFCONFIG_COMMON_ARCH := arm64
LINUX_DEFCONFIG_COMMON_FILES := \
$(LINUX_PATH)/arch/arm64/configs/defconfig \
$(CURDIR)/kconfigs/qemu.conf
linux-defconfig: $(LINUX_PATH)/.config
LINUX_COMMON_FLAGS += ARCH=arm64 Image
linux: linux-common
mkdir -p $(BINARIES_PATH)
ln -sf $(LINUX_PATH)/arch/arm64/boot/Image $(BINARIES_PATH)
linux-defconfig-clean: linux-defconfig-clean-common
LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
linux-clean: linux-clean-common
LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
linux-cleaner: linux-cleaner-common
################################################################################
# OP-TEE
################################################################################
OPTEE_OS_COMMON_FLAGS += DEBUG=$(DEBUG)
optee-os: optee-os-common
optee-os-clean: optee-os-clean-common
################################################################################
# Soc-term
################################################################################
soc-term:
$(MAKE) -C $(SOC_TERM_PATH)
soc-term-clean:
$(MAKE) -C $(SOC_TERM_PATH) clean
################################################################################
# Run targets
################################################################################
.PHONY: run
# This target enforces updating root fs etc
run: all
$(MAKE) run-only
QEMU_SMP ?= 2
.PHONY: run-only
run-only:
ln -sf $(ROOT)/out-br/images/rootfs.cpio.gz $(BINARIES_PATH)/
$(call check-terminal)
$(call run-help)
$(call launch-terminal,54320,"Normal World")
$(call launch-terminal,54321,"Secure World")
$(call wait-for-ports,54320,54321)
cd $(BINARIES_PATH) && $(QEMU_PATH)/aarch64-softmmu/qemu-system-aarch64 \
-nographic \
-serial tcp:localhost:54320 -serial tcp:localhost:54321 \
-smp $(QEMU_SMP) \
-s -S -machine virt,secure=on -cpu cortex-a57 \
-d unimp -semihosting-config enable,target=native \
-m 1057 \
-bios bl1.bin \
-initrd rootfs.cpio.gz \
-kernel Image -no-acpi \
-append 'console=ttyAMA0,38400 keep_bootcon root=/dev/vda2' \
$(QEMU_EXTRA_ARGS)
ifneq ($(filter check,$(MAKECMDGOALS)),)
CHECK_DEPS := all
endif
ifneq ($(TIMEOUT),)
check-args := --timeout $(TIMEOUT)
endif
check: $(CHECK_DEPS)
ln -sf $(ROOT)/out-br/images/rootfs.cpio.gz $(BINARIES_PATH)/
cd $(BINARIES_PATH) && \
export QEMU=$(QEMU_PATH)/aarch64-softmmu/qemu-system-aarch64 && \
export QEMU_SMP=$(QEMU_SMP) && \
expect $(ROOT)/build/qemu-check.exp -- $(check-args) || \
(if [ "$(DUMP_LOGS_ON_ERROR)" ]; then \
echo "== $$PWD/serial0.log:"; \
cat serial0.log; \
echo "== end of $$PWD/serial0.log:"; \
echo "== $$PWD/serial1.log:"; \
cat serial1.log; \
echo "== end of $$PWD/serial1.log:"; \
fi; false)
check-only: check
check-clean:
rm -f serial0.log serial1.log