@@ -405,6 +405,11 @@ TRUSTY_KERNEL_IMAGE := $(TRUSTY_OUT)/linux-build/arch/arm64/boot/Image
405
405
406
406
QEMU_BRANCH := stable-7.2
407
407
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
+
408
413
ATF_DIR := $(TRUSTY_OUT ) /atf/qemu/debug
409
414
ATF_BL1 := $(ATF_DIR ) /bl1.bin
410
415
ATF_BL33 := $(ATF_DIR ) /bl33.bin
@@ -492,13 +497,21 @@ ANDROID_DTB := $(OUT_DIR)/android.dtb
492
497
QEMU_DTB := $(OUT_DIR ) /qemu.dtb
493
498
QEMU_DTS := $(OUT_DIR ) /qemu.dts
494
499
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)
495
506
.PHONY : android-dtb
496
507
android-dtb $(ANDROID_DTB ) :
497
508
ifneq ($(ARCH ) ,arm64)
498
509
$(error android-dtb is only supported from arm64)
499
510
endif
500
511
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
502
515
$(DTC) -I dtb -O dts $(QEMU_DTB) > $(QEMU_DTS)
503
516
cat $(QEMU_DTS) $(ATF_DIR)/firmware.android.dts > $(ANDROID_DTS)
504
517
$(DTC) -I dts -O dtb $(ANDROID_DTS) > $(ANDROID_DTB)
@@ -560,7 +573,12 @@ ifeq ($(ANDROID_USERSPACE),1)
560
573
-device virtio-blk,drive=vdc -drive file=$(USERDATA_IMG ) ,index=2,if=none,id=vdc,format=raw \
561
574
-device virtio-net,netdev=adbnet0 -netdev user,id=adbnet0,hostfwd=tcp::5554-:5554,hostfwd=tcp::5555-:5555
562
575
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)
563
579
QEMU_ARGS += -dtb $(ANDROID_DTB )
580
+ endif
581
+
564
582
else ifneq ($(INITRD),)
565
583
ifeq ($(INITRD),1)
566
584
INITRD := $(CPIO_FILE )
@@ -590,13 +608,7 @@ else ifeq ($(ARCH),i386)
590
608
QEMU_BIN ?= qemu-system-i386
591
609
QEMU_KERNEL_CMDLINE += console=ttyS0
592
610
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
600
612
QEMU_KERNEL_CMDLINE += console=ttyAMA0
601
613
602
614
ifeq ($(TRUSTY),1)
@@ -631,22 +643,38 @@ ifeq ($(TRUSTY),1)
631
643
endif
632
644
633
645
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
636
655
endif
637
656
638
657
.PHONY : run
639
658
run : $(RUN_DEPS ) | $(SHARED_DIR )
659
+
660
+ echo $(RUN_DEPS)
661
+ ifneq ($(DUMPING_DTB ) , 1)
640
662
@echo "$(GREEN)Running QEMU, press 'ctrl-a x' to quit $(NC)"
663
+ endif
664
+
641
665
ifeq ($(GDB ) ,1)
666
+
667
+ ifneq ($(DUMPING_DTB ) ,1)
642
668
@echo "$(ARCH) $(ACK) $(TRUSTY) $(TRUSTY_TARGET)" > $(OUT_DIR)/.gdb
643
669
@echo "$(GREEN)Waiting for GDB, attach with \`scripts/gdb.sh\` $(NC)"
644
670
645
671
ifdef TERMINAL_CMD
646
672
$(TERMINAL_CMD) $(SCRIPT_DIR)/gdb.sh
647
673
endif
648
674
649
- endif
675
+ endif # DUMPING_DTB
676
+ endif # GDB
677
+
650
678
@echo ''
651
679
cd $(RUN_DIR) && $(QEMU_BIN) $(QEMU_ARGS)
652
680
0 commit comments