Skip to content

Commit 9977d70

Browse files
committed
Makefile: support optee.
Signed-off-by: guibing <guibing@nucleisys.com>
1 parent bc0f3ae commit 9977d70

2 files changed

Lines changed: 130 additions & 25 deletions

File tree

.gitmodules

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,23 @@
1717
[submodule "u-boot"]
1818
path = u-boot
1919
url = ../u-boot.git
20+
21+
[submodule "optee/optee_os"]
22+
path = optee/optee_os
23+
url = ../optee_os.git
24+
25+
[submodule "optee/optee_client"]
26+
path = optee/optee_client
27+
url = ../optee_client.git
28+
29+
[submodule "optee/optee_test"]
30+
path = optee/optee_test
31+
url = ../optee_test.git
32+
33+
[submodule "optee/optee_examples"]
34+
path = optee/optee_examples
35+
url = ../optee_examples.git
36+
37+
[submodule "optee/optee_benchmark"]
38+
path = optee/optee_benchmark
39+
url = ../optee_benchmark.git

Makefile

Lines changed: 110 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,34 @@ uboot_spl_its := $(confdir)/uboot_spl.its
127127
uboot_spl_itb := $(uboot_spl_wrkdir)/uboot_spl.itb
128128
uboot_spl_dtb := $(uboot_spl_wrkdir)/spl.dtb
129129

130+
# OPTEE gits compile config
131+
optee_os_srcdir := $(srcdir)/optee/optee_os
132+
optee_os_wrkdir := $(wrkdir)/optee/optee_os
133+
optee_os_platform := nuclei
134+
135+
optee_os_bin := $(optee_os_wrkdir)/core/tee-pager_v2.bin
136+
optee_os_export := $(optee_os_wrkdir)/export-ta_rv64/
137+
138+
optee_client_srcdir := $(srcdir)/optee/optee_client
139+
optee_client_wrkdir := $(wrkdir)/optee/optee_client
140+
optee_client_export := $(optee_client_wrkdir)/export/usr
141+
optee_client_supplicant := $(optee_client_wrkdir)/tee-supplicant/tee-supplicant
142+
143+
optee_test_srcdir := $(srcdir)/optee/optee_test
144+
optee_test_wrkdir := $(wrkdir)/optee/optee_test
145+
optee_test_xtest := $(optee_test_wrkdir)/xtest/xtest
146+
optee_test_tadir := $(optee_test_wrkdir)/ta
147+
optee_test_plugindir := $(optee_test_wrkdir)/supp_plugin
148+
149+
optee_example_srcdir := $(srcdir)/optee/optee_examples
150+
optee_example_wrkdir := $(wrkdir)/optee/optee_examples
151+
optee_example_cadir := $(optee_example_wrkdir)/out/ca
152+
optee_example_tadir := $(optee_example_wrkdir)/out/ta
153+
optee_example_plugindir := $(optee_example_wrkdir)/out/plugins
154+
155+
optee_benchmark_srcdir := $(srcdir)/optee/optee_benchmark
156+
optee_benchmark_wrkdir := $(wrkdir)/optee/optee_benchmark
157+
optee_benchmark_elf := $(optee_benchmark_wrkdir)/out/benchmark
130158
# Directory for boot images stored in sdcard
131159
boot_wrkdir := $(wrkdir)/boot
132160
boot_zip := $(wrkdir)/boot.zip
@@ -219,12 +247,14 @@ help:
219247
@echo "- linux : build linux image"
220248
@echo "- opensbi : build opensbi jump binary"
221249
@echo "- uboot : build uboot and generate uboot binary"
250+
@echo "- optee : build optee os/client/test/example and generate binary"
222251
@echo "- clean : clean this full workspace"
223252
@echo "- cleanboot : clean generated boot images"
224253
@echo "- cleanlinux : clean linux workspace"
225254
@echo "- cleanbuildroot : clean buildroot workspace"
226255
@echo "- cleansysroot : clean buildroot sysroot files"
227256
@echo "- cleanuboot : clean u-boot workspace"
257+
@echo "- cleanoptee : clean optee os/client/test/example output files"
228258
@echo "- cleanfreeloader : clean freeloader generated objects"
229259
@echo "- cleanopensbi : clean opensbi workspace"
230260
@echo "- backup : backup generated prebuilt images into $(backupdir) folder, you need to input backup message when this target is triggered"
@@ -238,8 +268,9 @@ help:
238268
@echo "Deprecated: If you want to run linux in simulation using xlspike, please run presim, sim targets"
239269
@echo "Deprecated: The xl-spike support will be deprecated in future release"
240270

241-
242-
$(target_gcc): buildroot_initramfs_sysroot
271+
# First level toolchain build
272+
$(target_gcc): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(buildroot_initramfs_config)
273+
$(MAKE) -C $(buildroot_srcdir) RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir) toolchain
243274

244275
$(wrkdir):
245276
mkdir -p $@
@@ -251,7 +282,7 @@ $(buildroot_initramfs_wrkdir)/.config:
251282
$(MAKE) -C ${buildroot_srcdir} RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir) olddefconfig
252283

253284
# buildroot_initramfs provides gcc
254-
$(buildroot_initramfs_tar): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(buildroot_initramfs_config)
285+
$(buildroot_initramfs_tar): $(buildroot_srcdir) $(buildroot_initramfs_wrkdir)/.config $(buildroot_initramfs_config) $(target_gcc)
255286
$(MAKE) -C $< RISCV=$(RISCV) O=$(buildroot_initramfs_wrkdir)
256287

257288
.PHONY: buildroot_initramfs-menuconfig
@@ -264,11 +295,14 @@ buildroot_initramfs-menuconfig: $(buildroot_initramfs_wrkdir)/.config $(buildroo
264295
buildroot_busybox-menuconfig: $(buildroot_initramfs_wrkdir)/.config $(buildroot_srcdir) $(target_gcc)
265296
$(MAKE) -C $(dir $<) O=$(buildroot_initramfs_wrkdir) busybox-menuconfig
266297

298+
# 2th level buildroot build
267299
$(buildroot_initramfs_sysroot_stamp): $(buildroot_initramfs_tar)
268300
mkdir -p $(buildroot_initramfs_sysroot)
269301
tar -xpf $< -C $(buildroot_initramfs_sysroot) --exclude ./dev --exclude ./usr/share/locale
302+
if [ -f $(confdir)/S30optee ]; then cp -af $(confdir)/S30optee $(buildroot_initramfs_sysroot)/etc/init.d/; fi
270303
touch $@
271304

305+
# 2th level vmlinux build
272306
.PHONY: initrd linux
273307

274308
$(linux_wrkdir)/.config: $(linux_defconfig) $(target_gcc)
@@ -284,7 +318,7 @@ $(linux_image): linux
284318
initrd: $(initramfs)
285319
@echo "initramfs cpio file is generated into $<"
286320

287-
linux: $(linux_wrkdir)/.config
321+
linux: $(linux_wrkdir)/.config $(target_gcc)
288322
$(MAKE) -C $(linux_srcdir) O=$(linux_wrkdir) \
289323
CONFIG_INITRAMFS_ROOT_UID=$(shell id -u) \
290324
CONFIG_INITRAMFS_ROOT_GID=$(shell id -g) \
@@ -293,7 +327,8 @@ linux: $(linux_wrkdir)/.config
293327
PATH=$(RVPATH) \
294328
vmlinux Image
295329

296-
$(initramfs): $(buildroot_initramfs_sysroot) $(linux_image)
330+
# 4th level initramfs build
331+
$(initramfs): $(buildroot_initramfs_sysroot) $(linux_image) optee_test optee_client optee_example
297332
$(INITRAMFS_PRECMD)
298333
cd $(linux_wrkdir) && \
299334
$(linux_gen_initramfs) \
@@ -339,12 +374,14 @@ $(platform_preproc_sim_dts): gen-simdts
339374
gen-simdts: $(platform_sim_dts) $(target_gcc)
340375
$(target_gcc) -E -nostdinc -undef -x assembler-with-cpp $(DTS_DEFINES) -DSIMULATION=2 $(platform_sim_dts) -o $(platform_preproc_sim_dts)
341376

377+
# 2th level dtb build
342378
$(platform_dtb) : $(platform_preproc_dts) $(target_gcc)
343379
dtc -O dtb -o $(platform_dtb) $(platform_preproc_dts)
344380

345381
$(platform_sim_dtb) : $(platform_preproc_sim_dts) $(target_gcc)
346382
dtc -O dtb -o $(platform_sim_dtb) $(platform_preproc_sim_dts)
347383

384+
# 2th level opensbi build
348385
.PHONY: opensbi opensbi_cp_plat
349386

350387
$(opensbi_jumpbin): opensbi
@@ -354,7 +391,9 @@ opensbi: $(target_gcc) $(opensbi_plat_deps)
354391
cp -u $(opensbi_plat_confdir)/* $(opensbi_plat_srcdir)
355392
$(MAKE) -C $(opensbi_srcdir) O=$(opensbi_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) BUILD_INFO=y \
356393
PLATFORM_RISCV_ABI=$(ABI) PLATFORM_RISCV_ISA=$(ISA) PLATFORM_RISCV_XLEN=$(XLEN) \
357-
PLATFORM=generic FW_TEXT_START=$(FW_TEXT_START)
394+
PLATFORM=generic FW_TEXT_START=$(FW_TEXT_START) FW_OPTEE_SHMEM_BASE=$(OPTEE_OS_SHMEM_START) \
395+
FW_OPTEE_SHMEM_SIZE=$(OPTEE_OS_SHMEM_SIZE) FW_OPTEE_TZDRAM_BASE=$(OPTEE_OS_TZDRAM_START) \
396+
FW_OPTEE_TZDRAM_SIZE=$(OPTEE_OS_TZDRAM_SIZE) FW_OPTEE_PLIC_BASE=$(OPTEE_PLIC_BASE)
358397

359398
# internal usage for xlspike, deprecated
360399
$(opensbi_payload): $(opensbi_srcdir) $(vmlinux_sim_bin) $(platform_sim_dtb) $(opensbi_plat_deps)
@@ -369,7 +408,7 @@ $(opensbi_payload): $(opensbi_srcdir) $(vmlinux_sim_bin) $(platform_sim_dtb) $(o
369408

370409
$(buildroot_initramfs_sysroot): $(buildroot_initramfs_sysroot_stamp)
371410

372-
.PHONY: buildroot_initramfs_sysroot vmlinux
411+
#.PHONY: buildroot_initramfs_sysroot vmlinux
373412
buildroot_initramfs_sysroot: $(buildroot_initramfs_sysroot)
374413
vmlinux: $(vmlinux)
375414

@@ -394,20 +433,59 @@ $(boot_kernel_dtb): $(platform_preproc_dts)
394433

395434
$(boot_zip): $(boot_wrkdir) $(boot_image) $(boot_initrd) $(boot_kernel_dtb) $(uboot_mkimage)
396435
rm -f $(boot_zip)
397-
mkdir -p $(wrkdir)/keys
398-
399-
# generate uboot rsa key and x509 crt
400-
if [ ! -f $(wrkdir)/keys/uboot.crt ]; then cd $(wrkdir) && openssl genpkey -algorithm RSA -out keys/uboot.key -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 ; fi;
401-
cd $(wrkdir) && openssl req -batch -new -x509 -key keys/uboot.key -out keys/uboot.crt
402-
403-
if [ ! -f $(wrkdir)/keys/aes256key_uboot.bin ]; then dd if=/dev/urandom of=$(wrkdir)/keys/aes256key_uboot.bin bs=1 count=32; fi
404436

405437
cp -f $(confdir)/uboot.its $(boot_wrkdir)/uboot.its
406-
# store uboot pubkey to boot_kernel_dtb
407-
cd $(boot_wrkdir) && $(uboot_mkimage) -f uboot.its -K $(boot_kernel_dtb) -k $(wrkdir)/keys -r kernel.itb
438+
cp -f $(boot_kernel_dtb) $(boot_kernel_dtb).tmp
439+
# kernel/rootfs use the same key as uboot/opensbi/optee, here .tmp file is only to let mkimage generate aes iv.
440+
cd $(boot_wrkdir) && $(uboot_mkimage) -f uboot.its -K $(boot_kernel_dtb).tmp -k $(wrkdir)/keys -r kernel.itb
408441
cd $(boot_wrkdir) && zip -q -r $(boot_zip) .
409-
rm -f $(boot_image) $(boot_initrd) $(boot_wrkdir)/uboot.its
410-
442+
rm -f $(boot_image) $(boot_initrd) $(boot_wrkdir)/uboot.its $(boot_kernel_dtb).tmp
443+
444+
.PHONY: optee optee_os optee_client optee_example optee_test
445+
446+
optee: optee_os optee_client optee_test optee_example
447+
448+
# 2th level optee_os build
449+
optee_os: $(target_gcc) $(optee_os_srcdir)
450+
$(MAKE) -C $(optee_os_srcdir) O=$(optee_os_wrkdir) CROSS_COMPILE64=$(CROSS_COMPILE) ARCH=riscv CFG_RV64_core=y \
451+
CFG_TZDRAM_START=$(OPTEE_OS_TZDRAM_START) CFG_TZDRAM_SIZE=$(OPTEE_OS_TZDRAM_SIZE) CFG_SHMEM_START=$(OPTEE_OS_SHMEM_START) \
452+
CFG_SHMEM_SIZE=$(OPTEE_OS_SHMEM_SIZE) PLATFORM=$(optee_os_platform) ta-targets=ta_rv64 MARCH=$(ISA) MABI=$(ABI)
453+
454+
# 2th level optee_client build
455+
optee_client: $(target_gcc) $(optee_client_srcdir) $(buildroot_initramfs_sysroot)
456+
$(MAKE) -C $(optee_client_srcdir) O=$(optee_client_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) MARCH=$(ISA) MABI=$(ABI)
457+
# copy optee client tee-supplicant, libteec to rootfs
458+
if [ -f $(optee_client_supplicant) ];then cp -af $(optee_client_supplicant) $(buildroot_initramfs_sysroot)/usr/sbin/; fi
459+
if ls $(optee_client_export)/lib/lib*so* >/dev/null 2>&1 ;then cp -af $(optee_client_export)/lib/lib*so* $(buildroot_initramfs_sysroot)/lib/; fi
460+
461+
# 3th level optee_test build
462+
optee_test: $(target_gcc) optee_client optee_os $(buildroot_initramfs_sysroot)
463+
$(MAKE) -C $(optee_test_srcdir) O=$(optee_test_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) OPTEE_CLIENT_EXPORT=$(optee_client_export) \
464+
--no-builtin-variables TA_DEV_KIT_DIR=$(optee_os_export) MARCH=$(ISA) MABI=$(ABI) OPENSSL_INSTALL_PATH=$(buildroot_initramfs_sysroot)/usr
465+
#copy optee test ca,ta,plugin
466+
mkdir -p $(buildroot_initramfs_sysroot)/lib/optee_armtz && mkdir -p $(buildroot_initramfs_sysroot)/usr/lib/tee-supplicant/plugins && if ls $(optee_test_tadir)/*/*.ta >/dev/null 2>&1 ;then cp -af $(optee_test_tadir)/*/*.ta $(buildroot_initramfs_sysroot)/lib/optee_armtz/; fi && if [ -f $(optee_test_xtest) ];then cp -af $(optee_test_xtest) $(buildroot_initramfs_sysroot)/usr/bin/; fi && if ls $(optee_test_plugindir)/*.plugin >/dev/null 2>&1 ;then cp -af $(optee_test_plugindir)/*.plugin $(buildroot_initramfs_sysroot)/usr/lib/tee-supplicant/plugins/; fi
467+
468+
# 3th level optee_example build
469+
optee_example: $(target_gcc) $(optee_example_srcdir) optee_client optee_os
470+
mkdir -p $(buildroot_initramfs_sysroot)/lib/optee_armtz
471+
cp -af $(optee_example_srcdir) $(wrkdir)/optee/
472+
$(MAKE) -C $(optee_example_wrkdir) HOST_CROSS_COMPILE=$(CROSS_COMPILE) TEEC_EXPORT=$(optee_client_export) --no-builtin-variables TA_DEV_KIT_DIR=$(optee_os_export) MARCH=$(ISA) MABI=$(ABI)
473+
#copy optee example ca,ta,plugin
474+
if ls $(optee_example_cadir)/* >/dev/null 2>&1 ;then cp -af $(optee_example_cadir)/* $(buildroot_initramfs_sysroot)/usr/bin; fi
475+
if ls $(optee_example_tadir)/* >/dev/null 2>&1 ;then cp -af $(optee_example_tadir)/* $(buildroot_initramfs_sysroot)/lib/optee_armtz/; fi
476+
if ls $(optee_example_plugindir)/*.plugin >/dev/null 2>&1 ;then cp -af $(optee_example_plugindir)/*.plugin $(buildroot_initramfs_sysroot)/usr/lib/tee-supplicant/plugins/; fi
477+
478+
# 3th level optee_benchmark build
479+
optee_benchmark: $(target_gcc) $(optee_benchmark_srcdir) optee_client optee_os
480+
cp -af $(optee_benchmark_srcdir) $(wrkdir)/optee/
481+
$(MAKE) -C $(optee_benchmark_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) TEEC_EXPORT=$(optee_client_export) TEEC_INTERNAL_INCLUDES=$(optee_client_srcdir)/libteec MULTIARCH=riscv-nuclei-linux-gnu
482+
#copy optee benchmark
483+
if [ -f $(optee_benchmark_elf) ];then \
484+
cp -af $(optee_benchmark_elf) $(buildroot_initramfs_sysroot)/usr/bin; \
485+
cp -af $(optee_benchmark_wrkdir)/out/libyaml/out/lib/libyaml*.so* $(buildroot_initramfs_sysroot)/lib/; \
486+
fi
487+
488+
# 2th level uboot build
411489
.PHONY: uboot uboot-menuconfig
412490
uboot: $(uboot_wrkdir)/.config $(platform_dtb)
413491
# use external device tree binary for uboot
@@ -423,27 +501,30 @@ $(uboot_wrkdir)/.config: $(target_gcc) $(uboot_config)
423501
cp $(uboot_config) $@
424502
$(MAKE) -C $(uboot_srcdir) O=$(uboot_wrkdir) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig
425503

426-
$(uboot_spl_itb): $(target_gcc) $(uboot_spl_its) $(platform_dtb) opensbi uboot $(boot_zip)
504+
# 3th level spl.itb build
505+
$(uboot_spl_itb): $(target_gcc) $(uboot_spl_its) $(platform_dtb) opensbi optee_os uboot
427506
mkdir -p $(uboot_spl_wrkdir)
507+
mkdir -p $(wrkdir)/keys
428508
rm -f $(uboot_spl_wrkdir)/*.*
429509
cp -f $(opensbi_jumpbin) $(uboot_spl_wrkdir)/opensbi.bin
430510
cp -f $(uboot_bin) $(uboot_spl_wrkdir)/u-boot.bin
431-
cp -f $(boot_kernel_dtb) $(uboot_spl_wrkdir)/fdt.dtb
432-
rm -f $(boot_kernel_dtb)
511+
512+
cp -f $(optee_os_bin) $(uboot_spl_wrkdir)/optee.bin
433513
cp -f $(platform_dtb) $(uboot_spl_dtb)
434514
cp -f $(uboot_spl_its) $(uboot_spl_wrkdir)/spl.its
435515
# generate spl rsa key and x509 crt
436-
if [ ! -f $(wrkdir)/keys/spl.crt ]; then cd $(wrkdir) && openssl genpkey -algorithm RSA -out keys/spl.key -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 ; fi;
437-
cd $(wrkdir) && openssl req -batch -new -x509 -key keys/spl.key -out keys/spl.crt
516+
if [ ! -f $(wrkdir)/keys/rsa_spl.crt ]; then cd $(wrkdir) && openssl genpkey -algorithm RSA -out keys/rsa_spl.key -pkeyopt rsa_keygen_bits:2048 -pkeyopt rsa_keygen_pubexp:65537 ; fi;
517+
cd $(wrkdir) && openssl req -batch -new -x509 -key keys/rsa_spl.key -out keys/rsa_spl.crt -sha256
438518
# generate aes256 cipher key
439-
if [ ! -f $(wrkdir)/keys/aes256key_spl.bin ]; then dd if=/dev/urandom of=$(wrkdir)/keys/aes256key_spl.bin bs=1 count=32; fi
519+
if [ ! -f $(wrkdir)/keys/aes_spl.bin ]; then dd if=/dev/urandom of=$(wrkdir)/keys/aes_spl.bin bs=1 count=32; fi
440520

441521
# store spl pubkey to spl.dtb
442522
cd $(uboot_spl_wrkdir) && $(uboot_mkimage) -f spl.its -K $(uboot_spl_dtb) -k $(wrkdir)/keys -r $@
443523

444524
$(uboot_mkimage) $(uboot_bin) $(uboot_spl_bin): uboot
445525
@echo "Uboot binary is generated into $<"
446526

527+
447528
.PHONY: freeloader upload_freeloader debug_freeloader run_openocd
448529

449530
freeloader: $(freeloader_elf)
@@ -476,8 +557,9 @@ freeloader4m: prepare4m $(freeloader_elf)
476557
ls -lh $(freeloader_elf)
477558
endif
478559

560+
# 4th level freeloader build
479561
ifeq ($(BOOT_MODE),sd)
480-
$(freeloader_elf): $(freeloader_srcdir) $(uboot_spl_bin) $(uboot_spl_itb) $(platform_dtb) $(amp_bins)
562+
$(freeloader_elf): $(freeloader_srcdir) $(uboot_spl_bin) $(uboot_spl_itb) $(platform_dtb) $(amp_bins) $(boot_zip)
481563
else
482564
$(freeloader_elf): $(freeloader_srcdir) $(uboot_spl_bin) $(uboot_spl_itb) $(platform_dtb) $(boot_zip) $(amp_bins)
483565
endif
@@ -553,6 +635,9 @@ cleanfreeloader:
553635
cleanopensbi:
554636
rm -rf $(opensbi_wrkdir)
555637

638+
cleanoptee:
639+
rm -rf $(wrkdir)/optee
640+
556641
# If you change your make target from sim to bootimages, you need to run preboot first
557642
preboot: prepare
558643

0 commit comments

Comments
 (0)