Skip to content

Commit 20ab084

Browse files
committed
WIP
1 parent 5b7be18 commit 20ab084

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ compile_commands.json
1313
/external/*
1414
!/external/external.mk
1515
!/external/README.md
16+
17+
/trusty

Makefile

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ else ifeq ($(filter x86_64 arm64 i386,$(ARCH)),)
3030
$(error Invalid architecture $(ARCH))
3131
endif
3232

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+
3341
.PHONY: default
3442
default: linux linux_modules tools-vm
3543

@@ -384,6 +392,39 @@ uboot $(UBOOT_BIN): $(UBOOT_CONFIG) | $(CLANG_DIR)
384392
uboot_clean:
385393
+ $(UBOOT_MAKE) mrproper
386394

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+
387428
##
388429
## Run QEMU
389430
##
@@ -400,7 +441,9 @@ ECHR ?= 1
400441
ROOT ?= /dev/vda
401442
RW ?= rw
402443
KASLR ?= 0
444+
403445
UBOOT ?= 0
446+
TRUSTY ?= 0
404447

405448
QEMU_KERNEL_CMDLINE := selinux=0
406449

@@ -410,16 +453,23 @@ QEMU_ARGS := \
410453
-nographic \
411454
-no-reboot \
412455
-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 \
416456
-echr $(ECHR) \
417457
$(QEMU_EXTRA_ARGS)
418458

419-
ifeq ($(UBOOT),1)
459+
ifeq ($(TRUSTY),1)
460+
QEMU_ARGS += -bios $(ATF_BL1)
461+
else ifeq ($(UBOOT),1)
420462
QEMU_ARGS += -bios $(UBOOT_BIN)
421463
endif
422464

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+
423473
ifneq ($(INITRD),)
424474
ifeq ($(INITRD),1)
425475
INITRD := $(CPIO_FILE)
@@ -436,7 +486,7 @@ ifeq ($(GDB),1)
436486
endif
437487

438488
ifeq ($(ARCH),x86_64)
439-
QEMU_BIN := qemu-system-x86_64
489+
QEMU_BIN ?= qemu-system-x86_64
440490

441491
# 8250.nr_uarts=1 is needed because some Android kernels set
442492
# `CONFIG_SERIAL_8250_RUNTIME_UARTS` to zero
@@ -449,14 +499,26 @@ ifeq ($(ARCH),x86_64)
449499
QEMU_ARGS += -accel kvm
450500
endif
451501
else ifeq ($(ARCH),i386)
452-
QEMU_BIN := qemu-system-i386
502+
QEMU_BIN ?= qemu-system-i386
453503
QEMU_KERNEL_CMDLINE += console=ttyS0
454504
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+
456512
QEMU_KERNEL_CMDLINE += console=ttyAMA0
457513

514+
ifeq ($(TRUSTY),1)
515+
MACHINE := -machine virt,secure=on,virtualization=on
516+
else
517+
MACHINE := -machine virt,virtualization=on
518+
endif
519+
458520
QEMU_ARGS += \
459-
-M virt \
521+
$(MACHINE) \
460522
-cpu cortex-a53 \
461523
-semihosting-config enable=on,target=native
462524
endif
@@ -474,10 +536,18 @@ endif
474536
QEMU_ARGS += -append "$(QEMU_KERNEL_CMDLINE) $(QEMU_EXTRA_KERNEL_CMDLINE)"
475537

476538
RUN_DEPS := $(QEMU_KERNEL_IMAGE)
539+
RUN_DIR := $(ROOT_DIR)
540+
477541
ifeq ($(UBOOT),1)
478542
RUN_DEPS += $(UBOOT_BIN)
479543
endif
480544

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+
481551
# Make sure the modules directory exists, even if it's empty. Otherwise mount
482552
# will fail.
483553
$(LINUX_MODULES_INSTALL_PATH)/lib/modules:
@@ -496,7 +566,7 @@ endif
496566

497567
endif
498568
@echo ''
499-
$(QEMU_BIN) $(QEMU_ARGS)
569+
cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
500570

501571
.PHONY: run-ack
502572
run-ack: run

0 commit comments

Comments
 (0)