@@ -30,6 +30,14 @@ else ifeq ($(filter x86_64 arm64 i386,$(ARCH)),)
30
30
$(error Invalid architecture $(ARCH))
31
31
endif
32
32
33
+ ifneq ($(ARCH ) ,arm64)
34
+ # We currently only support Trusty with arm64, as we rely on ARM TF-A
35
+ ifneq ($(filter trusty,$(MAKECMDGOALS)),)
36
+ $(error Building Trusty is only supported on arm64)
37
+ endif
38
+ endif
39
+
40
+
33
41
.PHONY : default
34
42
default : linux linux_modules tools-vm
35
43
@@ -384,6 +392,39 @@ uboot $(UBOOT_BIN): $(UBOOT_CONFIG) | $(CLANG_DIR)
384
392
uboot_clean :
385
393
+ $(UBOOT_MAKE ) mrproper
386
394
395
+ # #
396
+ # # Trusty
397
+ # #
398
+
399
+ TRUSTY_SRC ?= $(ROOT_DIR ) /trusty
400
+ TRUSTY_TARGET ?= qemu-generic-arm64-test-debug
401
+ TRUSTY_BUILD_ROOT ?= $(OUT_DIR ) /trusty
402
+ TRUSTY_OUT := $(TRUSTY_BUILD_ROOT ) /build-$(TRUSTY_TARGET )
403
+
404
+ ATF_DIR := $(TRUSTY_OUT ) /atf/qemu/debug
405
+ ATF_BL1 := $(ATF_DIR ) /bl1.bin
406
+ ATF_BL33 := $(ATF_DIR ) /bl33.bin
407
+
408
+ .PHONY : trusty-init
409
+ trusty-init :
410
+ mkdir -p $(TRUSTY_SRC )
411
+ cd $(TRUSTY_SRC ) && repo init -u https://android.googlesource.com/trusty/manifest -b main
412
+ cd $(TRUSTY_SRC ) && repo sync -j` nproc` -c --no-tags
413
+
414
+ .PHONY : trusty
415
+ trusty $(ATF_BL1 ) : | $(TRUSTY_SRC )
416
+ $(TRUSTY_SRC ) /trusty/vendor/google/aosp/scripts/build.py --build-root $(TRUSTY_BUILD_ROOT ) --skip-tests $(TRUSTY_TARGET )
417
+ $(MAKE ) trusty_bl33
418
+
419
+ .PHONY : trusty_bl33
420
+ trusty_bl33 $(ATF_BL33 ) : $(UBOOT_BIN )
421
+ rm $(ATF_BL33 )
422
+ cp $(UBOOT_BIN ) $(ATF_BL33 )
423
+
424
+ .PHONY : trusty_clean
425
+ trusty_clean :
426
+ rm -rf $(TRUSTY_OUT )
427
+
387
428
# #
388
429
# # Run QEMU
389
430
# #
@@ -400,7 +441,9 @@ ECHR ?= 1
400
441
ROOT ?= /dev/vda
401
442
RW ?= rw
402
443
KASLR ?= 0
444
+
403
445
UBOOT ?= 0
446
+ TRUSTY ?= 0
404
447
405
448
QEMU_KERNEL_CMDLINE := selinux=0
406
449
@@ -410,16 +453,23 @@ QEMU_ARGS := \
410
453
-nographic \
411
454
-no-reboot \
412
455
-kernel $(QEMU_KERNEL_IMAGE ) \
413
- -netdev user,id=eth0,hostfwd=tcp::7777-:7777,hostfwd=tcp::2222-:22,hostfwd=tcp::2223-:23 -device virtio-net-pci,netdev=eth0 \
414
- -virtfs local,security_model=mapped-xattr,path=$(SHARED_DIR ) ,mount_tag=shared \
415
- -virtfs local,security_model=mapped-xattr,path=$(LINUX_MODULES_INSTALL_PATH ) /lib/modules,mount_tag=modules \
416
456
-echr $(ECHR ) \
417
457
$(QEMU_EXTRA_ARGS )
418
458
419
- ifeq ($(UBOOT ) ,1)
459
+ ifeq ($(TRUSTY ) ,1)
460
+ QEMU_ARGS += -bios $(ATF_BL1 )
461
+ else ifeq ($(UBOOT),1)
420
462
QEMU_ARGS += -bios $(UBOOT_BIN )
421
463
endif
422
464
465
+ ifneq ($(TRUSTY ) ,1)
466
+ # Trusty currently only works with a very old version of QEMU, these flags
467
+ # don't seem to work with it
468
+ QEMU_ARGS += -netdev user,id=eth0,hostfwd=tcp::7777-:7777,hostfwd=tcp::2222-:22,hostfwd=tcp::2223-:23 -device virtio-net-pci,netdev=eth0
469
+ QEMU_ARGS += -virtfs local,security_model=mapped-xattr,path=$(SHARED_DIR ) ,mount_tag=shared
470
+ QEMU_ARGS += -virtfs local,security_model=mapped-xattr,path=$(LINUX_MODULES_INSTALL_PATH ) /lib/modules,mount_tag=modules
471
+ endif
472
+
423
473
ifneq ($(INITRD ) ,)
424
474
ifeq ($(INITRD),1)
425
475
INITRD := $(CPIO_FILE )
@@ -436,7 +486,7 @@ ifeq ($(GDB),1)
436
486
endif
437
487
438
488
ifeq ($(ARCH ) ,x86_64)
439
- QEMU_BIN : = qemu-system-x86_64
489
+ QEMU_BIN ? = qemu-system-x86_64
440
490
441
491
# 8250.nr_uarts=1 is needed because some Android kernels set
442
492
# `CONFIG_SERIAL_8250_RUNTIME_UARTS` to zero
@@ -449,14 +499,26 @@ ifeq ($(ARCH),x86_64)
449
499
QEMU_ARGS += -accel kvm
450
500
endif
451
501
else ifeq ($(ARCH),i386)
452
- QEMU_BIN : = qemu-system-i386
502
+ QEMU_BIN ? = qemu-system-i386
453
503
QEMU_KERNEL_CMDLINE += console=ttyS0
454
504
else
455
- QEMU_BIN := qemu-system-aarch64
505
+ ifeq ($(TRUSTY),1)
506
+ # Trusty currently only runs with its patched build of QEMU
507
+ QEMU_BIN ?= $(TRUSTY_OUT ) /qemu-build/aarch64-softmmu/qemu-system-aarch64
508
+ else
509
+ QEMU_BIN ?= qemu-system-aarch64
510
+ endif
511
+
456
512
QEMU_KERNEL_CMDLINE += console=ttyAMA0
457
513
514
+ ifeq ($(TRUSTY),1)
515
+ MACHINE := -machine virt,secure=on,virtualization=on
516
+ else
517
+ MACHINE := -machine virt,virtualization=on
518
+ endif
519
+
458
520
QEMU_ARGS += \
459
- -M virt \
521
+ $( MACHINE ) \
460
522
-cpu cortex-a53 \
461
523
-semihosting-config enable=on,target=native
462
524
endif
@@ -474,10 +536,18 @@ endif
474
536
QEMU_ARGS += -append "$(QEMU_KERNEL_CMDLINE ) $(QEMU_EXTRA_KERNEL_CMDLINE ) "
475
537
476
538
RUN_DEPS := $(QEMU_KERNEL_IMAGE )
539
+ RUN_DIR := $(ROOT_DIR )
540
+
477
541
ifeq ($(UBOOT ) ,1)
478
542
RUN_DEPS += $(UBOOT_BIN )
479
543
endif
480
544
545
+ ifeq ($(TRUSTY ) ,1)
546
+ RUN_DEPS += $(ATF_BL1 )
547
+ # TODO: Is there a QEMU flag we can use to make this not necessary?
548
+ RUN_DIR := $(ATF_DIR )
549
+ endif
550
+
481
551
# Make sure the modules directory exists, even if it's empty. Otherwise mount
482
552
# will fail.
483
553
$(LINUX_MODULES_INSTALL_PATH ) /lib/modules :
@@ -496,7 +566,7 @@ endif
496
566
497
567
endif
498
568
@echo ''
499
- $(QEMU_BIN) $(QEMU_ARGS)
569
+ cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
500
570
501
571
.PHONY : run-ack
502
572
run-ack : run
0 commit comments