Skip to content

Commit 7cdf01e

Browse files
committed
Regenerate DTB if QEMU_BIN changes
1 parent edf020b commit 7cdf01e

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

Makefile

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

406406
QEMU_BRANCH := stable-7.2
407407

408+
ifeq ($(TRUSTY),1)
409+
# Trusty needs to use its own build of QEMU which has some custom patches
410+
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
411+
endif
412+
408413
ATF_DIR := $(TRUSTY_OUT)/atf/qemu/debug
409414
ATF_BL1 := $(ATF_DIR)/bl1.bin
410415
ATF_BL33 := $(ATF_DIR)/bl33.bin
@@ -492,13 +497,21 @@ ANDROID_DTB := $(OUT_DIR)/android.dtb
492497
QEMU_DTB := $(OUT_DIR)/qemu.dtb
493498
QEMU_DTS := $(OUT_DIR)/qemu.dts
494499

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

501-
QEMU_EXTRA_ARGS="-M dumpdtb=$(QEMU_DTB)" $(MAKE) run
512+
# DUMPING_DTB=1 prevents infinite recursion. It must be set as a `make` argument,
513+
# not an environment variable
514+
QEMU_EXTRA_ARGS="-M dumpdtb=$(QEMU_DTB)" $(MAKE) run DUMPING_DTB=1
502515
$(DTC) -I dtb -O dts $(QEMU_DTB) > $(QEMU_DTS)
503516
cat $(QEMU_DTS) $(ATF_DIR)/firmware.android.dts > $(ANDROID_DTS)
504517
$(DTC) -I dts -O dtb $(ANDROID_DTS) > $(ANDROID_DTB)
@@ -560,7 +573,12 @@ ifeq ($(ANDROID_USERSPACE),1)
560573
-device virtio-blk,drive=vdc -drive file=$(USERDATA_IMG),index=2,if=none,id=vdc,format=raw \
561574
-device virtio-net,netdev=adbnet0 -netdev user,id=adbnet0,hostfwd=tcp::5554-:5554,hostfwd=tcp::5555-:5555
562575
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
576+
577+
# Don't add the DTB as an argument if we're in the process of dumping it
578+
ifneq ($(DUMPING_DTB),1)
563579
QEMU_ARGS += -dtb $(ANDROID_DTB)
580+
endif
581+
564582
else ifneq ($(INITRD),)
565583
ifeq ($(INITRD),1)
566584
INITRD := $(CPIO_FILE)
@@ -590,13 +608,7 @@ else ifeq ($(ARCH),i386)
590608
QEMU_BIN ?= qemu-system-i386
591609
QEMU_KERNEL_CMDLINE += console=ttyS0
592610
else
593-
ifeq ($(TRUSTY),1)
594-
# Trusty needs to use its own build of QEMU which has some custom patches
595-
QEMU_BIN ?= $(TRUSTY_OUT)/qemu-build/aarch64-softmmu/qemu-system-aarch64
596-
else
597-
QEMU_BIN ?= qemu-system-aarch64
598-
endif
599-
611+
QEMU_BIN ?= qemu-system-aarch64
600612
QEMU_KERNEL_CMDLINE += console=ttyAMA0
601613

602614
ifeq ($(TRUSTY),1)
@@ -631,22 +643,38 @@ ifeq ($(TRUSTY),1)
631643
endif
632644

633645
ifeq ($(ANDROID_USERSPACE),1)
634-
# We need this device tree blob to mount /vendor
635-
RUN_DEPS += $(ANDROID_DTB)
646+
# We need a device tree blob to mount /vendor. If DUMPING_DTB is set, that
647+
# means we're already in the process of dumping the DTB and shouldn't add it
648+
# as a run dependency, otherwise we'll run into infinite recursion
649+
ifneq ($(DUMPING_DTB),1)
650+
# Add `android-dtb` instead of ANDROID_DTB so that this target is forced to
651+
# be run every time (to prevent accidentally using a DTB generated from a
652+
# different QEMU binary)
653+
RUN_DEPS += android-dtb
654+
endif
636655
endif
637656

638657
.PHONY: run
639658
run: $(RUN_DEPS) | $(SHARED_DIR)
659+
660+
echo $(RUN_DEPS)
661+
ifneq ($(DUMPING_DTB), 1)
640662
@echo "$(GREEN)Running QEMU, press 'ctrl-a x' to quit $(NC)"
663+
endif
664+
641665
ifeq ($(GDB),1)
666+
667+
ifneq ($(DUMPING_DTB),1)
642668
@echo "$(ARCH) $(ACK) $(TRUSTY) $(TRUSTY_TARGET)" > $(OUT_DIR)/.gdb
643669
@echo "$(GREEN)Waiting for GDB, attach with \`scripts/gdb.sh\` $(NC)"
644670

645671
ifdef TERMINAL_CMD
646672
$(TERMINAL_CMD) $(SCRIPT_DIR)/gdb.sh
647673
endif
648674

649-
endif
675+
endif # DUMPING_DTB
676+
endif # GDB
677+
650678
@echo ''
651679
cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
652680

0 commit comments

Comments
 (0)