@@ -409,6 +409,11 @@ TRUSTY_KERNEL_IMAGE := $(TRUSTY_OUT)/linux-build/arch/arm64/boot/Image
409
409
410
410
QEMU_BRANCH := stable-7.2
411
411
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
+
412
417
ATF_DIR := $(TRUSTY_OUT ) /atf/qemu/debug
413
418
ATF_BL1 := $(ATF_DIR ) /bl1.bin
414
419
ATF_BL33 := $(ATF_DIR ) /bl33.bin
@@ -496,13 +501,21 @@ ANDROID_DTB := $(OUT_DIR)/android.dtb
496
501
QEMU_DTB := $(OUT_DIR ) /qemu.dtb
497
502
QEMU_DTS := $(OUT_DIR ) /qemu.dts
498
503
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)
499
510
.PHONY : android-dtb
500
511
android-dtb $(ANDROID_DTB ) :
501
512
ifneq ($(ARCH ) ,arm64)
502
513
$(error android-dtb is only supported from arm64)
503
514
endif
504
515
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
506
519
$(DTC) -I dtb -O dts $(QEMU_DTB) > $(QEMU_DTS)
507
520
cat $(QEMU_DTS) $(ATF_DIR)/firmware.android.dts > $(ANDROID_DTS)
508
521
$(DTC) -I dts -O dtb $(ANDROID_DTS) > $(ANDROID_DTB)
@@ -572,7 +585,12 @@ ifeq ($(ANDROID_USERSPACE),1)
572
585
-device virtio-blk,drive=vdc -drive file=$(USERDATA_IMG ) ,index=2,if=none,id=vdc,format=raw \
573
586
-device virtio-net,netdev=adbnet0 -netdev user,id=adbnet0,hostfwd=tcp::5554-:5554,hostfwd=tcp::5555-:5555
574
587
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)
575
591
QEMU_ARGS += -dtb $(ANDROID_DTB )
592
+ endif
593
+
576
594
else ifneq ($(INITRD),)
577
595
ifeq ($(INITRD),1)
578
596
INITRD := $(CPIO_FILE )
@@ -605,13 +623,7 @@ else ifeq ($(ARCH),i386)
605
623
QEMU_BIN ?= qemu-system-i386
606
624
QEMU_KERNEL_CMDLINE += console=ttyS0
607
625
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
615
627
QEMU_KERNEL_CMDLINE += console=ttyAMA0
616
628
617
629
ifeq ($(TRUSTY),1)
@@ -652,8 +664,15 @@ ifeq ($(TRUSTY),1)
652
664
endif
653
665
654
666
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
657
676
endif
658
677
659
678
# Make sure the modules directory exists, even if it's empty. Otherwise mount
@@ -663,16 +682,23 @@ $(LINUX_MODULES_INSTALL_PATH)/lib/modules:
663
682
664
683
.PHONY : run
665
684
run : $(RUN_DEPS ) | $(SHARED_DIR ) $(LINUX_MODULES_INSTALL_PATH ) /lib/modules
685
+ ifneq ($(DUMPING_DTB ) , 1)
666
686
@echo "$(GREEN)Running QEMU, press 'ctrl-a x' to quit $(NC)"
687
+ endif
688
+
667
689
ifeq ($(GDB ) ,1)
690
+
691
+ ifneq ($(DUMPING_DTB ) ,1)
668
692
@echo "$(ARCH) $(ACK) $(TRUSTY) $(TRUSTY_TARGET)" > $(OUT_DIR)/.gdb
669
693
@echo "$(GREEN)Waiting for GDB, attach with \`scripts/gdb.sh\` $(NC)"
670
694
671
695
ifdef TERMINAL_CMD
672
696
$(TERMINAL_CMD) $(SCRIPT_DIR)/gdb.sh
673
697
endif
674
698
675
- endif
699
+ endif # DUMPING_DTB
700
+ endif # GDB
701
+
676
702
@echo ''
677
703
cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
678
704
0 commit comments