Skip to content

Commit 234dfce

Browse files
committed
Regenerate DTB if QEMU_BIN changes
1 parent d7965e2 commit 234dfce

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

Makefile

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ TRUSTY_KERNEL_IMAGE := $(TRUSTY_OUT)/linux-build/arch/arm64/boot/Image
409409

410410
QEMU_BRANCH := stable-7.2
411411

412+
ifeq ($(TRUSTY),1)
413+
# Trusty needs to use its own build of QEMU which has some custom patches
414+
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
415+
endif
416+
412417
ATF_DIR := $(TRUSTY_OUT)/atf/qemu/debug
413418
ATF_BL1 := $(ATF_DIR)/bl1.bin
414419
ATF_BL33 := $(ATF_DIR)/bl33.bin
@@ -496,13 +501,21 @@ ANDROID_DTB := $(OUT_DIR)/android.dtb
496501
QEMU_DTB := $(OUT_DIR)/qemu.dtb
497502
QEMU_DTS := $(OUT_DIR)/qemu.dts
498503

504+
# We use DUMPING_DTB to avoid infinite recursion
505+
DUMPING_DTB := 0
506+
507+
# We depend on QEMU_BIN because it's best if we generate this every time (as it
508+
# the DTB can change if run with a different version QEMU and we want to make
509+
# sure it exactly matches the DTB for the current QEMU binary being used)
499510
.PHONY: android-dtb
500511
android-dtb $(ANDROID_DTB):
501512
ifneq ($(ARCH),arm64)
502513
$(error android-dtb is only supported from arm64)
503514
endif
504515

505-
QEMU_EXTRA_ARGS="-M dumpdtb=$(QEMU_DTB)" $(MAKE) run
516+
# DUMPING_DTB=1 prevents infinite recursion. It must be set as a `make` argument,
517+
# not an environment variable
518+
QEMU_EXTRA_ARGS="-M dumpdtb=$(QEMU_DTB)" $(MAKE) run DUMPING_DTB=1
506519
$(DTC) -I dtb -O dts $(QEMU_DTB) > $(QEMU_DTS)
507520
cat $(QEMU_DTS) $(ATF_DIR)/firmware.android.dts > $(ANDROID_DTS)
508521
$(DTC) -I dts -O dtb $(ANDROID_DTS) > $(ANDROID_DTB)
@@ -572,7 +585,12 @@ ifeq ($(ANDROID_USERSPACE),1)
572585
-device virtio-blk,drive=vdc -drive file=$(USERDATA_IMG),index=2,if=none,id=vdc,format=raw \
573586
-device virtio-net,netdev=adbnet0 -netdev user,id=adbnet0,hostfwd=tcp::5554-:5554,hostfwd=tcp::5555-:5555
574587
QEMU_KERNEL_CMDLINE += root=$(ROOT) $(RW) kvm-arm.mode=protected earlyprintk androidboot.hardware=qemu_trusty trusty-log.log_ratelimit_interval=0 trusty-log.log_to_dmesg=always
588+
589+
# Don't add the DTB as an argument if we're in the process of dumping it
590+
ifneq ($(DUMPING_DTB),1)
575591
QEMU_ARGS += -dtb $(ANDROID_DTB)
592+
endif
593+
576594
else ifneq ($(INITRD),)
577595
ifeq ($(INITRD),1)
578596
INITRD := $(CPIO_FILE)
@@ -605,13 +623,7 @@ else ifeq ($(ARCH),i386)
605623
QEMU_BIN ?= qemu-system-i386
606624
QEMU_KERNEL_CMDLINE += console=ttyS0
607625
else
608-
ifeq ($(TRUSTY),1)
609-
# Trusty needs to use its own build of QEMU which has some custom patches
610-
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
611-
else
612-
QEMU_BIN ?= qemu-system-aarch64
613-
endif
614-
626+
QEMU_BIN ?= qemu-system-aarch64
615627
QEMU_KERNEL_CMDLINE += console=ttyAMA0
616628

617629
ifeq ($(TRUSTY),1)
@@ -652,8 +664,15 @@ ifeq ($(TRUSTY),1)
652664
endif
653665

654666
ifeq ($(ANDROID_USERSPACE),1)
655-
# We need this device tree blob to mount /vendor
656-
RUN_DEPS += $(ANDROID_DTB)
667+
# We need a device tree blob to mount /vendor. If DUMPING_DTB is set, that
668+
# means we're already in the process of dumping the DTB and shouldn't add it
669+
# as a run dependency, otherwise we'll run into infinite recursion
670+
ifneq ($(DUMPING_DTB),1)
671+
# Add `android-dtb` instead of ANDROID_DTB so that this target is forced to
672+
# be run every time (to prevent accidentally using a DTB generated from a
673+
# different QEMU binary)
674+
RUN_DEPS += android-dtb
675+
endif
657676
endif
658677

659678
# Make sure the modules directory exists, even if it's empty. Otherwise mount
@@ -663,16 +682,23 @@ $(LINUX_MODULES_INSTALL_PATH)/lib/modules:
663682

664683
.PHONY: run
665684
run: $(RUN_DEPS) | $(SHARED_DIR) $(LINUX_MODULES_INSTALL_PATH)/lib/modules
685+
ifneq ($(DUMPING_DTB), 1)
666686
@echo "$(GREEN)Running QEMU, press 'ctrl-a x' to quit $(NC)"
687+
endif
688+
667689
ifeq ($(GDB),1)
690+
691+
ifneq ($(DUMPING_DTB),1)
668692
@echo "$(ARCH) $(ACK) $(TRUSTY) $(TRUSTY_TARGET)" > $(OUT_DIR)/.gdb
669693
@echo "$(GREEN)Waiting for GDB, attach with \`scripts/gdb.sh\` $(NC)"
670694

671695
ifdef TERMINAL_CMD
672696
$(TERMINAL_CMD) $(SCRIPT_DIR)/gdb.sh
673697
endif
674698

675-
endif
699+
endif # DUMPING_DTB
700+
endif # GDB
701+
676702
@echo ''
677703
cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
678704

0 commit comments

Comments
 (0)