redox/mk/qemu.mk

285 lines
6.8 KiB
Makefile
Raw Permalink Normal View History

# Configuration file for QEMU
2022-08-30 19:09:49 +02:00
QEMU=SDL_VIDEO_X11_DGAMOUSE=0 qemu-system-$(QEMU_ARCH)
QEMUFLAGS=-d guest_errors -name "Redox OS $(ARCH)"
2022-08-30 19:09:49 +02:00
2022-07-29 18:11:32 +02:00
ifeq ($(ARCH),i686)
2022-11-16 20:34:48 +01:00
audio?=ac97
uefi=no
2022-07-29 20:13:32 +02:00
QEMU_ARCH=i386
QEMU_MACHINE?=pc
QEMU_CPU?=pentium2
QEMU_SMP?=1
QEMU_MEM?=1024
# Default to using kvm when arch is i686 and host is x86_64
ifeq ($(HOST_ARCH),x86_64)
kvm?=yes
endif
2022-07-29 18:15:18 +02:00
else ifeq ($(ARCH),x86_64)
2022-07-29 20:13:32 +02:00
QEMU_ARCH=x86_64
QEMU_MACHINE?=q35
QEMU_CPU?=core2duo
QEMU_SMP?=4
QEMU_MEM?=2048
ifeq ($(uefi),yes)
FIRMWARE=/usr/share/OVMF/OVMF_CODE.fd
endif
2024-03-25 21:29:10 +01:00
ifneq ($(usb),no)
QEMUFLAGS+=-device nec-usb-xhci,id=xhci
endif
2022-07-29 18:15:18 +02:00
else ifeq ($(ARCH),aarch64)
# Default to UEFI as U-Boot doesn't set up a framebuffer for us and we don't yet support
# setting up a framebuffer ourself.
uefi?=yes
2024-11-14 04:54:10 +01:00
live?=yes
2022-07-29 20:13:32 +02:00
QEMU_ARCH=aarch64
QEMU_MACHINE?=virt
2022-07-29 20:13:32 +02:00
QEMU_CPU=max
QEMU_SMP?=1
QEMU_MEM?=2048
ifeq ($(BOARD),raspi3bp)
2024-11-14 04:54:10 +01:00
QEMU_KERNEL=$(BUILD)/raspi3bp_uboot.rom
disk?=sdcard
2024-11-14 04:54:10 +01:00
QEMU_MACHINE:=raspi3b
QEMU_SMP:=4
QEMU_MEM:=1024
net:=usb-net
audio:=no
ifneq ($(usb),no)
QEMUFLAGS+=-usb -device usb-kbd -device usb-tablet
endif
else
2024-11-14 04:54:10 +01:00
ifeq ($(uefi),yes)
FIRMWARE=/usr/share/AAVMF/AAVMF_CODE.fd
else
FIRMWARE=$(BUILD)/qemu_uboot.rom
endif
ifneq ($(gpu),no)
QEMUFLAGS+=-device ramfb
endif
ifneq ($(usb),no)
QEMUFLAGS+=-device qemu-xhci -device usb-kbd -device usb-tablet
endif
2022-08-24 14:22:40 +02:00
endif
else ifeq ($(ARCH),riscv64gc)
live=no
efi=yes
audio=no
vga=no # virtio-gpu-pci
net=bridge
QEMU_ARCH=riscv64
# QEMU_MACHINE=virt for ACPI mode instead of DTB
QEMU_MACHINE=virt,acpi=off
# QEMU_MACHINE:=${QEMU_MACHINE},aclint=on
# QEMU_MACHINE:=${QEMU_MACHINE},aia=aplic
# QEMU_MACHINE:=${QEMU_MACHINE},aia=aplic-imsic
QEMU_SMP?=4
QEMU_MEM?=2048
QEMU_CPU=max
disk?=nvme
PFLASH0=/usr/share/qemu-efi-riscv64/RISCV_VIRT_CODE.fd
PFLASH1=/usr/share/qemu-efi-riscv64/RISCV_VIRT_VARS.fd
ifneq ($(vga),no)
QEMUFLAGS+=-device ramfb
endif
ifneq ($(usb),no)
QEMUFLAGS+=-device qemu-xhci -device usb-kbd -device usb-tablet
endif
2022-07-29 18:11:32 +02:00
else
2022-07-29 20:13:32 +02:00
$(error Unsupported ARCH for QEMU "$(ARCH)"))
2022-07-29 18:11:32 +02:00
endif
2022-07-29 18:15:18 +02:00
QEMUFLAGS+=-smp $(QEMU_SMP) -m $(QEMU_MEM)
# If host and target arch do not match, disable kvm
# (unless overridden above or by environment)
ifneq ($(ARCH),$(HOST_ARCH))
kvm?=no
endif
ifneq ($(FIRMWARE),)
QEMUFLAGS+=-bios $(FIRMWARE)
endif
2024-11-14 04:54:10 +01:00
ifneq ($(QEMU_KERNEL),)
QEMUFLAGS+=-kernel $(QEMU_KERNEL)
endif
ifeq ($(live),yes)
DISK=$(BUILD)/livedisk.iso
else
DISK=$(BUILD)/harddrive.img
2022-08-24 14:22:40 +02:00
endif
2019-03-12 02:55:10 +01:00
ifeq ($(serial),no)
QEMUFLAGS+=-chardev stdio,id=debug -device isa-debugcon,iobase=0x402,chardev=debug
else
QEMUFLAGS+=-chardev stdio,id=debug,signal=off,mux=on,"$(if $(qemu_serial_logfile),logfile=$(qemu_serial_logfile))"
QEMUFLAGS+=-serial chardev:debug -mon chardev=debug
2019-03-12 02:55:10 +01:00
endif
2022-08-30 19:09:49 +02:00
2017-01-05 22:07:20 +01:00
ifeq ($(iommu),yes)
2022-07-29 18:11:32 +02:00
QEMUFLAGS+=-machine $(QEMU_MACHINE),iommu=on
2017-01-05 22:07:20 +01:00
else
2022-07-29 18:11:32 +02:00
QEMUFLAGS+=-machine $(QEMU_MACHINE)
2017-01-05 22:07:20 +01:00
endif
2022-08-30 19:09:49 +02:00
2022-11-15 23:11:38 +01:00
ifeq ($(audio),no)
# No audio
else ifeq ($(audio),ac97)
# AC'97
QEMUFLAGS+=-device AC97
else
# Intel High Definition Audio
QEMUFLAGS+=-device ich9-intel-hda -device hda-output
2017-06-18 00:59:01 +02:00
endif
2022-08-30 19:09:49 +02:00
2017-01-05 22:07:20 +01:00
ifeq ($(net),no)
QEMUFLAGS+=-net none
else
2024-11-14 04:54:10 +01:00
ifeq ($(net),rtl8139) # RTL8139
QEMUFLAGS+=-device rtl8139,netdev=net0
else ifeq ($(net),virtio) # virtio-net
QEMUFLAGS+=-device virtio-net,netdev=net0
else ifeq ($(net),usb-net)
QEMUFLAGS+=-device usb-net,netdev=net0
else
QEMUFLAGS+=-device e1000,netdev=net0,id=nic0
endif
ifneq ($(bridge),)
2024-11-14 04:54:10 +01:00
QEMUFLAGS+=-netdev bridge,br=$(bridge),id=net0
else ifeq ($(net),redir)
# port 8080 and 8083 - webservers
# port 64126 - our gdbserver implementation
QEMUFLAGS+=-netdev user,id=net0,hostfwd=tcp::8080-:8080,hostfwd=tcp::8083-:8083,hostfwd=tcp::64126-:64126
else
2024-11-14 04:54:10 +01:00
QEMUFLAGS+=-netdev user,id=net0 -object filter-dump,id=f1,netdev=net0,file=$(BUILD)/network.pcap
2017-01-05 22:07:20 +01:00
endif
endif
2022-08-30 19:09:49 +02:00
ifeq ($(gpu),no)
2017-01-05 22:07:20 +01:00
QEMUFLAGS+=-nographic -vga none
else ifeq ($(gpu),multi)
2023-01-20 19:53:29 +01:00
QEMUFLAGS+=-display sdl -vga std -device secondary-vga
else ifeq ($(gpu),virtio)
2023-07-07 16:47:44 +02:00
QEMUFLAGS+=-vga virtio
else ifeq ($(vga),virtio-gpu-pci)
QEMUFLAGS+= -vga virtio-gpu-pci
2017-01-05 22:07:20 +01:00
endif
2022-08-30 19:09:49 +02:00
EXTRA_DISK=$(BUILD)/extra.img
2024-06-14 16:59:39 +02:00
disk?=ata
ifeq ($(disk),ata)
# For i386, ata will use ided
# For aarch64 and x86_64, ata will use ahcid
QEMUFLAGS+= \
-drive file=$(DISK),format=raw \
-drive file=$(EXTRA_DISK),format=raw
else ifeq ($(disk),nvme)
QEMUFLAGS+= \
-drive file=$(DISK),format=raw,if=none,id=drv0 -device nvme,drive=drv0,serial=NVME_SERIAL \
-drive file=$(EXTRA_DISK),format=raw,if=none,id=drv1 -device nvme,drive=drv1,serial=NVME_EXTRA
else ifeq ($(disk),usb)
QEMUFLAGS+= \
-drive if=none,id=usbstick,format=raw,file=$(DISK) \
-device usb-storage,drive=usbstick
else ifeq ($(disk),virtio)
QEMUFLAGS+= \
-drive file=$(DISK),format=raw,if=virtio \
-drive file=$(EXTRA_DISK),format=raw,if=virtio
else ifeq ($(disk),cdrom)
QEMUFLAGS+= \
-boot d -cdrom $(DISK) \
-drive file=$(EXTRA_DISK),format=raw
else ifeq ($(disk),sdcard)
QEMUFLAGS+=-drive file=$(DISK),if=sd,format=raw
endif
2019-09-08 04:01:03 +02:00
ifeq ($(gdb),yes)
QEMUFLAGS+=-d cpu_reset -s -S
endif
2022-08-30 19:09:49 +02:00
2017-01-05 22:07:20 +01:00
ifeq ($(UNAME),Linux)
ifneq ($(kvm),no)
QEMUFLAGS+=-enable-kvm -cpu host
else
2022-07-29 18:11:32 +02:00
QEMUFLAGS+=-cpu $(QEMU_CPU)
2017-01-05 22:07:20 +01:00
endif
endif
2023-04-29 16:27:20 +02:00
ifeq ($(UNAME),Darwin)
QEMUFLAGS+=-cpu $(QEMU_CPU)
endif
ifneq ($(PFLASH0),)
QEMUFLAGS+=-drive if=pflash,format=raw,unit=0,file=$(PFLASH0),readonly=on
endif
ifneq ($(PFLASH1),)
QEMUFLAGS+=-drive if=pflash,format=raw,unit=1,file=$(BUILD)/fw_vars.bin
endif
.PHONY: qemu-deps
qemu-deps: $(DISK)
ifeq ($(disk),usb)
else ifeq ($(disk),sdcard)
else
qemu-deps: $(EXTRA_DISK)
endif
qemu-deps:$(FIRMWARE)
2024-11-14 04:54:10 +01:00
qemu-deps:$(QEMU_KERNEL)
qemu-deps: $(PFLASH0)
ifneq ($(PFLASH1),)
qemu-deps: $(BUILD)/fw_vars.bin
.PRECIOUS: $(BUILD)/fw_vars.bin
$(BUILD)/fw_vars.bin: $(PFLASH1)
cp "$<" "$@"
endif
$(EXTRA_DISK):
truncate -s 1g $@
2017-01-05 22:07:20 +01:00
$(BUILD)/raspi3bp_uboot.rom:
wget -O $@ https://gitlab.redox-os.org/Ivan/redox_firmware/-/raw/main/platform/raspberry_pi/rpi3/u-boot-rpi-3-b-plus.bin
$(BUILD)/qemu_uboot.rom:
wget -O $@ https://gitlab.redox-os.org/Ivan/redox_firmware/-/raw/main/platform/qemu/qemu_arm64/u-boot-qemu-arm64.bin
/usr/share/AAVMF/AAVMF_CODE.fd:
echo "\n\n\nMissing /usr/share/AAVMF/AAVMF_CODE.fd UEFI firmware file.\n\
Please install the qemu-efi-aarch64 package or use efi=no to download U-Boot instead.\n" \
&& exit 1
2022-07-29 20:13:32 +02:00
/usr/share/qemu-efi-riscv64/RISCV_VIRT_CODE.fd /usr/share/qemu-efi-riscv64/RISCV_VIRT_VARS.fd:
echo "\n\n\nMissing $@ UEFI firmware file.\n\
Please install the qemu-efi-riscv64 package.\n"
&& exit 1
qemu: qemu-deps
$(QEMU) $(QEMUFLAGS)
2019-09-15 21:41:21 +02:00
# You probably want to use disk=no when using the *_extra targets
qemu_extra: qemu-deps
2019-09-15 21:41:21 +02:00
$(QEMU) $(QEMUFLAGS) \
-drive file=$(EXTRA_DISK),format=raw
2022-09-07 16:28:12 +02:00
qemu_nvme_extra: qemu-deps
2022-09-07 16:28:12 +02:00
$(QEMU) $(QEMUFLAGS) \
-drive file=$(EXTRA_DISK),format=raw,if=none,id=drv1 -device nvme,drive=drv1,serial=NVME_EXTRA
#additional steps for $(DISK) are required!!!
qemu_raspi: qemu-deps
$(QEMU) -M raspi3b -smp 4,cores=1 \
-kernel $(FIRMWARE) \
-serial stdio -display none