Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 175 additions & 2 deletions versal2.mk
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ OPTEE_OS_COMMON_EXTRA_FLAGS ?= CFG_PKCS11_TA=y CFG_USER_TA_TARGET_pkcs11=ta_arm6
TF_A_PATH ?= $(ROOT)/arm-trusted-firmware
U-BOOT_PATH ?= $(ROOT)/u-boot-xlnx
LINUX_PATH ?= $(ROOT)/linux-xlnx
BOOTGEN_PATH ?= $(ROOT)/bootgen
QEMU_PATH ?= $(ROOT)/qemu
QEMU_BUILD ?= $(QEMU_PATH)/build
QEMU_DEVICETREES_PATH ?= $(ROOT)/qemu-devicetrees

include common.mk

Expand All @@ -59,8 +63,14 @@ ROOTFS_SIGN ?= $(BINARIES_PATH)/rootfs.cpio.gz.u-boot
# Targets
################################################################################

all: tfa optee-os u-boot linux dtbo buildroot buildroot_mkimg
clean: tfa-clean optee-os-clean u-boot-clean linux-clean dtbo-clean buildroot-clean
all: tfa optee-os u-boot linux dtbo buildroot buildroot_mkimg bootgen \
qemu qemu-devicetrees bootimage
run: all
$(MAKE) run-only
run-only: bootimage run-qemu-direct

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other run-only target in fvp.mk, qemu.mk, and qemu_v8.mk, doesn't depend on anything.
Since this run-only target doesn't even do anything, only depend on stuff, how about removing it to avoid confusion?
By the way, if run-only is executed with -j<something>, run-qemu-direct might execute before bootimage is done.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll keep run-only as a standalone target rather than removing it, similar to how it's done upstream. Instead of listing bootimage run-qemu-direct as prerequisites, run-only would do an explicit existence check for each required artifact (TF-A, OP-TEE, U-Boot, DTBs, bootgen, QEMU binaries, kernel Image, rootfs) before invoking the run step directly.
Let us know if this approach works, or if you'd prefer something different — will send the updated patch once confirmed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works.

clean: tfa-clean optee-os-clean u-boot-clean linux-clean dtbo-clean \
buildroot-clean bootimage-clean bootgen-clean run-qemu-clean \
qemu-clean qemu-devicetrees-clean

$(BINARIES_PATH):
mkdir -p $@
Expand Down Expand Up @@ -180,3 +190,166 @@ buildroot_mkimg: buildroot
-T ramdisk \
-C gzip \
-d $(ROOTFS_GZ) $(ROOTFS_SIGN)

################################################################################
# Boot Image with Bootgen
################################################################################

bootimage: bootgen tfa optee-os u-boot dtbo
mkdir -p $(BINARIES_PATH)
cp $(BUILD_PATH)/versal2/bootgen.bif $(BINARIES_PATH)
cp $(BUILD_PATH)/versal2/platconfig.pdi $(BINARIES_PATH)
cp $(BUILD_PATH)/versal2/platconfig.elf $(BINARIES_PATH)
cd $(BINARIES_PATH) && $(BOOTGEN_BIN) -arch versal_2ve_2vm \
-padimageheader=0 -log info \
-image bootgen.bif -w -o $(BINARIES_PATH)/BOOT.BIN
cp $(BINARIES_PATH)/BOOT.BIN \
$(BINARIES_PATH)/qemu-ospi.bin
truncate -s 256M \
$(BINARIES_PATH)/qemu-ospi.bin
cd $(BINARIES_PATH) && $(BOOTGEN_BIN) -arch versal_2ve_2vm \
-dump $(BINARIES_PATH)/BOOT.BIN boot_files

bootimage-clean:
rm -f $(BINARIES_PATH)/bootgen.bif $(BINARIES_PATH)/platconfig.pdi \
$(BINARIES_PATH)/platconfig.elf $(BINARIES_PATH)/BOOT.BIN \
$(BINARIES_PATH)/BOOT_bh.BIN $(BINARIES_PATH)/plm.bin \
$(BINARIES_PATH)/pmc_cdo.bin $(BINARIES_PATH)/Hashblock0.bin \
$(BINARIES_PATH)/qemu-ospi.bin

################################################################################
# Bootgen
################################################################################

bootgen:
$(MAKE) -C $(BOOTGEN_PATH)
mkdir -p $(BINARIES_PATH)
cp $(BOOTGEN_PATH)/build/bin/bootgen $(BINARIES_PATH)

bootgen-clean:
$(MAKE) -C $(BOOTGEN_PATH) clean
rm -f $(BINARIES_PATH)/bootgen

qemu-devicetrees:
$(MAKE) -C $(QEMU_DEVICETREES_PATH)

qemu-devicetrees-clean:
$(MAKE) -C $(QEMU_DEVICETREES_PATH) clean

################################################################################
# QEMU Build
################################################################################

$(QEMU_BUILD)/config-host.mak:
mkdir -p $(QEMU_BUILD)
cd $(QEMU_BUILD) && $(QEMU_PATH)/configure \
--target-list="aarch64-softmmu,microblazeel-softmmu,riscv32-softmmu" \
--enable-fdt --disable-kvm --disable-xen --enable-gcrypt --enable-slirp

qemu: $(QEMU_BUILD)/.stamp_qemu

$(QEMU_BUILD)/.stamp_qemu: $(QEMU_BUILD)/config-host.mak
$(MAKE) -C $(QEMU_BUILD)
touch $@

qemu-clean:
rm -f $(QEMU_BUILD)/.stamp_qemu
test -d $(QEMU_BUILD) && $(MAKE) -C $(QEMU_BUILD) distclean || true

################################################################################
# QEMU Run-Only Recipe
################################################################################
#
# The targets below assume 'make all' (or 'make run'/'make run-only')
# has already been run at least once, so all required binaries and
# device trees are already present in $(BINARIES_PATH). They do not
# declare Make prerequisites or perform existence checks.
#

# Path definitions for QEMU
QEMU_BINARIES_PATH := $(QEMU_BUILD)
DEVICE_TREE_PATH := $(QEMU_DEVICETREES_PATH)/LATEST/MULTI_ARCH
BOOT_IMAGES_PATH := $(BINARIES_PATH)
BOOTGEN_BIN := $(BINARIES_PATH)/bootgen

# QEMU binaries (similar to how qemu_v8.mk defines QEMU_BIN)
QEMU_MICROBLAZE_BIN = $(QEMU_BINARIES_PATH)/qemu-system-microblazeel
QEMU_RISCV_BIN = $(QEMU_BINARIES_PATH)/qemu-system-riscv32
QEMU_AARCH64_BIN = $(QEMU_BINARIES_PATH)/qemu-system-aarch64

# QEMU run recipes
.PHONY: run run-only all clean tfa optee-os u-boot linux \
qemu qemu-devicetrees bootgen bootimage bootimage-clean \
bootgen-clean run-qemu-clean

# Individual QEMU target recipes
.PHONY: run-qemu-microblaze
run-qemu-microblaze:
@echo "=== Starting MicroBlaze PMC QEMU ==="
@echo "Working directory: $(BOOT_IMAGES_PATH)"
@echo "Device tree: $(DEVICE_TREE_PATH)/board-versal2-pmxc-virt.dtb"
@mkdir -p $(BOOT_IMAGES_PATH)/temp/qemu_temp
@echo "==================================="
cd $(BOOT_IMAGES_PATH) && $(QEMU_MICROBLAZE_BIN) -M microblaze-fdt \
-display none \
-device loader,addr=0xf0000000,data=0xba020004,data-len=4 \
-device loader,addr=0xf0000004,data=0xb800fffc,data-len=4 \
-device loader,addr=0xF1110624,data=0x0,data-len=4 \
-device loader,addr=0xF1110620,data=0x1,data-len=4 \
-hw-dtb $(DEVICE_TREE_PATH)/board-versal2-pmxc-virt.dtb \
-device loader,file=$(BOOT_IMAGES_PATH)/BOOT_bh.bin,addr=0xf201eec0,force-raw=on \
-device loader,file=$(BOOT_IMAGES_PATH)/HashBlock0.bin,addr=0xf201ecc0 \
-device loader,file=$(BOOT_IMAGES_PATH)/pmc_cdo.bin,addr=0xf2000000,force-raw=on \
-device loader,file=$(BOOT_IMAGES_PATH)/plm.bin,addr=0xf0200000,force-raw=on \
-device loader,addr=0xf0200000,cpu-num=1 \
-machine-path $(BOOT_IMAGES_PATH)/temp/qemu_temp/

.PHONY: run-qemu-riscv
run-qemu-riscv:
@echo "=== Starting RISC-V ASU QEMU ==="
@echo "Working directory: $(BOOT_IMAGES_PATH)"
@echo "Device tree: $(DEVICE_TREE_PATH)/board-versal2-asu-virt.dtb"
@mkdir -p $(BOOT_IMAGES_PATH)/temp/qemu_temp
@echo "================================"
cd $(BOOT_IMAGES_PATH) && $(QEMU_RISCV_BIN) -M riscv-fdt \
-hw-dtb $(DEVICE_TREE_PATH)/board-versal2-asu-virt.dtb \
-display none \
-machine-path $(BOOT_IMAGES_PATH)/temp/qemu_temp/

.PHONY: run-qemu-aarch64
run-qemu-aarch64:
@echo "=== Starting AArch64 PSXC QEMU ==="
@echo "Working directory: $(BOOT_IMAGES_PATH)"
@echo "Device tree: $(DEVICE_TREE_PATH)/board-versal2-psxc-vek385.dtb"
@mkdir -p $(BOOT_IMAGES_PATH)/temp/qemu_temp
@echo "===================================="
cd $(BOOT_IMAGES_PATH) && $(QEMU_AARCH64_BIN) -machine arm-generic-fdt -m 8G \
-nographic \
-serial null -serial null -serial null -serial mon:stdio -nodefaults \
-boot mode=8 \
-drive file=$(BOOT_IMAGES_PATH)/qemu-ospi.bin,if=mtd,format=raw,index=0 \
-hw-dtb $(DEVICE_TREE_PATH)/board-versal2-psxc-vek385.dtb \
-device loader,addr=0x21000000,file=$(BOOT_IMAGES_PATH)/Image \
-device loader,force-raw=on,addr=0x30000000,file=$(BOOT_IMAGES_PATH)/rootfs.cpio.gz.u-boot \
-machine-path $(BOOT_IMAGES_PATH)/temp/qemu_temp/

# Clean QEMU temporary files
run-qemu-clean:
@echo "Cleaning QEMU temporary files..."
@rm -rf $(BINARIES_PATH)/temp/qemu_temp
@echo "QEMU temporary files cleaned."

# Run all three QEMU instances — MicroBlaze and RISC-V in background,
# AArch64 interactive
.PHONY: run-qemu-direct
run-qemu-direct: bootimage qemu qemu-devicetrees linux buildroot_mkimg
@mkdir -p $(BOOT_IMAGES_PATH)/temp/qemu_temp
@echo "Launching MicroBlaze PMC in background (log: $(BOOT_IMAGES_PATH)/mb-pmc.log)..."
@$(MAKE) run-qemu-microblaze > $(BOOT_IMAGES_PATH)/mb-pmc.log 2>&1 & MB_PID=$$!; \
echo "Launching RISC-V ASU in background (log: $(BOOT_IMAGES_PATH)/riscv-asu.log)..."; \
$(MAKE) run-qemu-riscv > $(BOOT_IMAGES_PATH)/riscv-asu.log 2>&1 & RV_PID=$$!; \
echo "Launching AArch64 PSXC (interactive - Ctrl+a x to exit)..."; \
$(MAKE) run-qemu-aarch64; \
echo "AArch64 exited. Stopping background QEMU instances..."; \
kill $$MB_PID $$RV_PID 2>/dev/null || true; \
echo "All QEMU instances stopped."
14 changes: 14 additions & 0 deletions versal2/bootgen.bif
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
the_ROM_image:
{
image {
{ type=bootimage, file=platconfig.pdi }
{ type=bootloader, file=platconfig.elf }
}
image {
id = 0x1c000000, name=apu_ss
{ type=raw, load=0x1000000, file=versal2-vek385-revA.dtb }
{ core=a78-0, cluster=0, exception_level = el-3, trustzone, file=bl31.elf }
{ core=a78-0, cluster=0, exception_level = el-1, trustzone, load=0x1800000, file=tee-raw.bin }
{ core=a78-0, cluster=0, exception_level = el-2, file=u-boot.elf }
}
}
Binary file added versal2/platconfig.elf
Binary file not shown.
Binary file added versal2/platconfig.pdi
Binary file not shown.