From 37c4c57292a5fcdc81a8596d21be7e9aac33fa76 Mon Sep 17 00:00:00 2001 From: Alex Brown Date: Tue, 9 Jul 2024 09:10:40 +1000 Subject: [PATCH] examples/virtio: use Makefile snippets Signed-off-by: Alex Brown --- ci/examples.sh | 4 +- dep/sddf | 2 +- examples/virtio/Makefile | 363 +++--------------- .../dts/{ => overlays}/disable.dts | 0 .../blk_driver_vm/dts/{ => overlays}/init.dts | 0 .../blk_driver_vm/dts/{ => overlays}/io.dts | 0 .../client_vm/dts/{ => overlays}/disable.dts | 0 .../client_vm/dts/{ => overlays}/init.dts | 0 .../client_vm/dts/{ => overlays}/virtio.dts | 0 .../dts/{ => overlays}/disable.dts | 0 .../blk_driver_vm/dts/{ => overlays}/init.dts | 0 .../blk_driver_vm/dts/{ => overlays}/io.dts | 0 .../client_vm/dts/{ => overlays}/init.dts | 0 .../client_vm/dts/{ => overlays}/virtio.dts | 0 examples/virtio/include/blk_config.h | 10 +- examples/virtio/virtio.mk | 148 +++++++ tools/linux/blk/blk_init.mk | 23 ++ tools/linux/uio/uio.mk | 43 +++ tools/linux/uio_drivers/blk/uio_blk.mk | 42 ++ 19 files changed, 311 insertions(+), 324 deletions(-) rename examples/virtio/board/odroidc4/blk_driver_vm/dts/{ => overlays}/disable.dts (100%) rename examples/virtio/board/odroidc4/blk_driver_vm/dts/{ => overlays}/init.dts (100%) rename examples/virtio/board/odroidc4/blk_driver_vm/dts/{ => overlays}/io.dts (100%) rename examples/virtio/board/odroidc4/client_vm/dts/{ => overlays}/disable.dts (100%) rename examples/virtio/board/odroidc4/client_vm/dts/{ => overlays}/init.dts (100%) rename examples/virtio/board/odroidc4/client_vm/dts/{ => overlays}/virtio.dts (100%) rename examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/{ => overlays}/disable.dts (100%) rename examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/{ => overlays}/init.dts (100%) rename examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/{ => overlays}/io.dts (100%) rename examples/virtio/board/qemu_arm_virt/client_vm/dts/{ => overlays}/init.dts (100%) rename examples/virtio/board/qemu_arm_virt/client_vm/dts/{ => overlays}/virtio.dts (100%) create mode 100644 examples/virtio/virtio.mk create mode 100644 tools/linux/blk/blk_init.mk create mode 100644 tools/linux/uio/uio.mk create mode 100644 tools/linux/uio_drivers/blk/uio_blk.mk diff --git a/ci/examples.sh b/ci/examples.sh index 264785ed..dc35869e 100755 --- a/ci/examples.sh +++ b/ci/examples.sh @@ -92,8 +92,8 @@ build_virtio() { mkdir -p ${BUILD_DIR} make -C examples/virtio -B \ BUILD_DIR=${BUILD_DIR} \ - CONFIG=${CONFIG} \ - BOARD=${BOARD} \ + MICROKIT_CONFIG=${CONFIG} \ + MICROKIT_BOARD=${BOARD} \ MICROKIT_SDK=${SDK_PATH} } diff --git a/dep/sddf b/dep/sddf index 96f9d3ad..33cf47c0 160000 --- a/dep/sddf +++ b/dep/sddf @@ -1 +1 @@ -Subproject commit 96f9d3adb16639166637e293e5ee66bc0c54b547 +Subproject commit 33cf47c04c3533369322b920a9e9087f28cb6c67 diff --git a/examples/virtio/Makefile b/examples/virtio/Makefile index b1e42ea3..7f001cf9 100644 --- a/examples/virtio/Makefile +++ b/examples/virtio/Makefile @@ -1,335 +1,64 @@ # -# Copyright 2021, Breakaway Consulting Pty. Ltd. -# Copyright 2022, UNSW (ABN 57 195 873 179) +# Copyright 2024, UNSW # # SPDX-License-Identifier: BSD-2-Clause # -# Default build directory, pass BUILD_DIR= to override BUILD_DIR ?= build -# Default config is a debug build, pass CONFIG= to override -CONFIG ?= debug +export MICROKIT_CONFIG ?= debug ifeq ($(strip $(MICROKIT_SDK)),) - $(error MICROKIT_SDK must be specified) +$(error MICROKIT_SDK must be specified) endif - -ifndef BOARD - $(error BOARD must be specified) -endif - -ifeq ($(filter $(BOARD), odroidc4 qemu_arm_virt),) - $(error "Board $(BOARD) is not supported") -endif - -# @ivanv: check that all dependencies exist -# Specify that we use bash for all shell commands -SHELL=/bin/bash -# All dependencies needed to compile the VMM -QEMU := qemu-system-aarch64 -DTC := dtc - -CC := clang -CC_USERLEVEL := zig cc -LD := ld.lld -AR := llvm-ar -RANLIB := llvm-ranlib - -MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit - -# @ivanv: need to have a step for putting in the initrd node into the DTB, -# right now it is unfortunately hard-coded. - -# @ivanv: check that the path of SDK_PATH/BOARD exists -# @ivanv: Have a list of supported boards to check with, if it's not one of those -# have a helpful message that lists all the support boards. - -# @ivanv: incremental builds don't work with IMAGE_DIR changing -BOARD_DIR := $(MICROKIT_SDK)/board/$(BOARD)/$(CONFIG) -LIBVMM := $(abspath ../..) -LIBVMM_TOOLS := $(LIBVMM)/tools -LIBVMM_SRC_DIR := $(LIBVMM)/src -SYSTEM_DESCRIPTION := board/$(BOARD)/virtio.system - -CURRENT_DIR := $(shell pwd) - -LINUX_DIR := $(LIBVMM_TOOLS)/linux -LINUX_BLK_DIR := $(LINUX_DIR)/blk -LINUX_BLK_BOARD_DIR := $(LINUX_BLK_DIR)/board/$(BOARD) - -UIO_DIR := $(LINUX_DIR)/uio -UIO_DRIVER_BLK_DIR := $(LINUX_DIR)/uio_drivers/blk - -SDDF_DIR := $(abspath ../../dep/sddf) - -VMM_INCLUDE := include - -BLK_DRIVER_VM_DIR := board/$(BOARD)/blk_driver_vm -BLK_DRIVER_VM_DTS_DIR := $(BLK_DRIVER_VM_DIR)/dts -BLK_DRIVER_VM_ROOTFS_TMP_DIR := $(BUILD_DIR)/blk_driver_vm_rootfs - -CLIENT_VM_DIR := board/$(BOARD)/client_vm -CLIENT_VM_DTS_DIR := $(CLIENT_VM_DIR)/dts -CLIENT_VM_ROOTFS_TMP_DIR := $(BUILD_DIR)/client_vm_rootfs - - -BLK_DRIVER_VM_LINUX := $(BLK_DRIVER_VM_DIR)/linux -BLK_DRIVER_VM_INITRD := $(BLK_DRIVER_VM_DIR)/rootfs.cpio.gz -BLK_DRIVER_VM_INITRD_MODIFIED := $(BUILD_DIR)/blk_driver_vm_rootfs.cpio.gz -BLK_DRIVER_VM_BASE_DTS := $(BLK_DRIVER_VM_DTS_DIR)/linux.dts -BLK_DRIVER_VM_DTS_OVERLAYS_qemu_arm_virt := $(BLK_DRIVER_VM_DTS_DIR)/init.dts \ - $(BLK_DRIVER_VM_DTS_DIR)/io.dts \ - $(BLK_DRIVER_VM_DTS_DIR)/disable.dts -BLK_DRIVER_VM_DTS_OVERLAYS_odroidc4 := $(BLK_DRIVER_VM_DTS_DIR)/init.dts \ - $(BLK_DRIVER_VM_DTS_DIR)/io.dts \ - $(BLK_DRIVER_VM_DTS_DIR)/disable.dts -BLK_DRIVER_VM_DTS_OVERLAYS := ${BLK_DRIVER_VM_DTS_OVERLAYS_${BOARD}} -BLK_DRIVER_VM_DTB := $(BUILD_DIR)/blk_driver_vm.dtb - - -CLIENT_VM_LINUX := $(CLIENT_VM_DIR)/linux -CLIENT_VM_INITRD := $(CLIENT_VM_DIR)/rootfs.cpio.gz -CLIENT_VM_INITRD_MODIFIED := $(BUILD_DIR)/client_vm_rootfs.cpio.gz -CLIENT_VM_BASE_DTS := $(CLIENT_VM_DTS_DIR)/linux.dts -CLIENT_VM_DTS_OVERLAYS_qemu_arm_virt := $(CLIENT_VM_DTS_DIR)/init.dts \ - $(CLIENT_VM_DTS_DIR)/virtio.dts -CLIENT_VM_DTS_OVERLAYS_odroidc4 := $(CLIENT_VM_DTS_DIR)/init.dts \ - $(CLIENT_VM_DTS_DIR)/virtio.dts\ - $(CLIENT_VM_DTS_DIR)/disable.dts -CLIENT_VM_DTS_OVERLAYS := ${CLIENT_VM_DTS_OVERLAYS_${BOARD}} -CLIENT_VM_DTB := $(BUILD_DIR)/client_vm.dtb - -SDDF_BLK_COMPONENTS := $(SDDF_DIR)/blk/components -SDDF_BLK_UTIL := $(SDDF_DIR)/blk/util - -ifeq ($(strip $(BOARD)), odroidc4) - export UART_DRIVER_DIR := meson -else ifeq ($(strip $(BOARD)), qemu_arm_virt) - export UART_DRIVER_DIR := arm +export override MICROKIT_SDK:=$(abspath $(MICROKIT_SDK)) + +ifeq ($(strip $(MICROKIT_BOARD)), odroidc4) + export UART_DRIVER := meson + export CPU := cortex-a55 +else ifeq ($(strip $(MICROKIT_BOARD)), imx8mm_evk) + export UART_DRIVER := imx + export CPU := cortex-a53 +else ifeq ($(strip $(MICROKIT_BOARD)), maaxboard) + export UART_DRIVER := imx + export CPU := cortex-a53 +else ifeq ($(strip $(MICROKIT_BOARD)), qemu_arm_virt) + export UART_DRIVER := arm + export CPU := cortex-a53 + QEMU := qemu-system-aarch64 + + export BLK_NUM_PART = 2 + export BLK_SIZE = 512 + export BLK_MEM ?= 2101248 else -$(error Unsupported BOARD given) -endif -SDDF_SERIAL_DRIVER := $(SDDF_DIR)/drivers/serial/$(UART_DRIVER_DIR) - -ELFS := client_vmm.elf blk_driver_vmm.elf serial_virt_tx.elf serial_virt_rx.elf uart_driver.elf blk_virt.elf - -BLK_DRIVER_VM_USERLEVEL := uio_blk_driver -BLK_DRIVER_VM_USERLEVEL_INIT := blk_driver_init - -CLIENT_VM_USERLEVEL := -CLIENT_VM_USERLEVEL_INIT := blk_client_init - -IMAGE_FILE = $(BUILD_DIR)/loader.img -REPORT_FILE = $(BUILD_DIR)/report.txt - -# @ivanv: should only compile printf.o in debug -VMM_OBJS := printf.o \ - virq.o \ - linux.o \ - guest.o \ - psci.o \ - smc.o \ - fault.o \ - util.o \ - vgic.o \ - vgic_v2.o \ - tcb.o \ - vcpu.o - -CLIENT_VMM_OBJS := $(VMM_OBJS) \ - client_images.o \ - client_vmm.o \ - console.o \ - block.o \ - mmio.o \ - libsddf_util_debug.a - -BLK_DRIVER_VMM_OBJS := $(VMM_OBJS) \ - blk_driver_images.o \ - blk_driver_vmm.o \ - console.o \ - mmio.o - -BLK_VIRT_OBJS := sddf_blk_virt.o libsddf_util_debug.a -UIO_BLK_DRIVER_OBJS := blk.o libuio.o - -# Toolchain flags -# FIXME: For optimisation we should consider providing the flag -mcpu. -# FIXME: We should also consider whether -mgeneral-regs-only should be -# used to avoid the use of the FPU and therefore seL4 does not have to -# context switch the FPU. -# Note we only need -Wno-unused-command-line-argument because in Nix -# passes an extra `--gcc-toolchain` flag which we do not need. -CFLAGS := -mstrict-align \ - -g3 \ - -O3 \ - -ffreestanding \ - -nostdlib \ - -Wno-unused-command-line-argument \ - -Wall -Wno-unused-function -Werror \ - -I$(BOARD_DIR)/include \ - -I$(SDDF_DIR)/include \ - -I$(LIBVMM)/include \ - -I$(VMM_INCLUDE) \ - -DBOARD_$(BOARD) \ - -DCONFIG_$(CONFIG) \ - -target aarch64-none-elf - -CFLAGS_LINUX := -g3 \ - -O3 \ - -Wno-unused-command-line-argument \ - -Wall -Wno-unused-function -Werror \ - -D_GNU_SOURCE \ - -I$(SDDF_DIR)/include \ - -I$(LINUX_DIR)/include \ - -I$(VMM_INCLUDE) \ - -target aarch64-linux-gnu - -LDFLAGS := -L$(BOARD_DIR)/lib -LIBS := -lmicrokit -Tmicrokit.ld $(BUILD_DIR)/libsddf_util_debug.a - -ifeq ($(BOARD), qemu_arm_virt) - NUM_PART = 2 - BLK_SIZE = 512 - BLK_MEM ?= 2101248 +$(error Unsupported MICROKIT_BOARD given) endif -all: directories $(IMAGE_FILE) - -clean: - rm -rf $(BUILD_DIR) - -qemu: all $(BUILD_DIR)/storage - # @ivanv: check that the amount of RAM given to QEMU is at least the number of RAM that QEMU is setup with for seL4. - if ! command -v $(QEMU) &> /dev/null; then echo "Could not find dependency: qemu-system-aarch64"; exit 1; fi - $(QEMU) -machine virt,virtualization=on,secure=off \ - -cpu cortex-a53 \ - -serial mon:stdio \ - -device loader,file=$(IMAGE_FILE),addr=0x70000000,cpu-num=0 \ - -m size=2G \ - -nographic \ - -drive file=$(BUILD_DIR)/storage,format=raw,if=none,id=drive0 \ - -device virtio-blk-device,drive=drive0,id=virtblk0,num-queues=1 - -directories: - $(shell mkdir -p $(BUILD_DIR)) - $(shell mkdir -p $(BUILD_DIR)/util) - $(shell mkdir -p $(BUILD_DIR)/serial) - -SDDF_LIB_UTIL_DBG_OBJS := cache.o sddf_printf.o newlibc.o assert.o putchar_debug.o bitarray.o fsmalloc.o - -$(BUILD_DIR)/libsddf_util_debug.a: $(addprefix ${BUILD_DIR}/util/, ${SDDF_LIB_UTIL_DBG_OBJS}) - ${AR} rv $@ $^ - ${RANLIB} $@ - -$(BUILD_DIR)/util/sddf_printf.o: ${SDDF_DIR}/util/printf.c - ${CC} ${CFLAGS} -c -o $@ $< - -$(BUILD_DIR)/util/%.o: ${SDDF_DIR}/util/%.c - ${CC} ${CFLAGS} -c -o $@ $< - -$(BUILD_DIR)/uart_driver.elf: $(BUILD_DIR)/serial/uart_driver.o - $(LD) $(LDFLAGS) $< $(LIBS) -o $@ - -$(BUILD_DIR)/serial/uart_driver.o: ${SDDF_SERIAL_DRIVER}/uart.c - $(CC) -c $(CFLAGS) -I${SDDF_SERIAL_DRIVER}/include -o $@ $< - -$(BUILD_DIR)/serial_virt_%.elf: $(BUILD_DIR)/serial/virt_%.o - $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ - -$(BUILD_DIR)/serial/virt_%.o: ${SDDF_DIR}/serial/components/virt_%.c - ${CC} ${CFLAGS} -o $@ -c $< - -$(BUILD_DIR)/storage: - $(LIBVMM_TOOLS)/mkvirtdisk $@ $(NUM_PART) $(BLK_SIZE) $(BLK_MEM) - -# Unpack rootfs, put the userlevel in /root and userlevel_init in /etc/init.d/S99, repack rootfs -$(BLK_DRIVER_VM_INITRD_MODIFIED): $(addprefix $(BUILD_DIR)/, $(BLK_DRIVER_VM_USERLEVEL)) \ - $(addprefix $(BUILD_DIR)/, $(BLK_DRIVER_VM_USERLEVEL_INIT)) - $(LIBVMM_TOOLS)/packrootfs $(BLK_DRIVER_VM_INITRD) $(BLK_DRIVER_VM_ROOTFS_TMP_DIR) -o $(BLK_DRIVER_VM_INITRD_MODIFIED) \ - --startup $(addprefix $(BUILD_DIR)/, $(BLK_DRIVER_VM_USERLEVEL_INIT)) \ - --home $(addprefix $(BUILD_DIR)/, $(BLK_DRIVER_VM_USERLEVEL)) - -$(CLIENT_VM_INITRD_MODIFIED): $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL)) \ - $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL_INIT)) - $(LIBVMM_TOOLS)/packrootfs $(CLIENT_VM_INITRD) $(CLIENT_VM_ROOTFS_TMP_DIR) -o $(CLIENT_VM_INITRD_MODIFIED) \ - --startup $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL_INIT)) \ - --home $(addprefix $(BUILD_DIR)/, $(CLIENT_VM_USERLEVEL)) - -$(BLK_DRIVER_VM_DTB): $(BLK_DRIVER_VM_BASE_DTS) $(BLK_DRIVER_VM_DTS_OVERLAYS) - $(LIBVMM_TOOLS)/dtscat $^ > $(BUILD_DIR)/blk_driver_vm.dts - $(DTC) -q -I dts -O dtb $(BUILD_DIR)/blk_driver_vm.dts > $@ - -$(CLIENT_VM_DTB): $(CLIENT_VM_BASE_DTS) $(CLIENT_VM_DTS_OVERLAYS) - $(LIBVMM_TOOLS)/dtscat $^ > $(BUILD_DIR)/client_vm.dts - $(DTC) -q -I dts -O dtb $(BUILD_DIR)/client_vm.dts > $@ - -$(BUILD_DIR)/blk_driver_images.o: $(LIBVMM_TOOLS)/package_guest_images.S $(BLK_DRIVER_VM_LINUX) $(BLK_DRIVER_VM_DTB) $(BLK_DRIVER_VM_INITRD_MODIFIED) - $(CC) -c -g3 -x assembler-with-cpp \ - -DGUEST_KERNEL_IMAGE_PATH=\"$(BLK_DRIVER_VM_LINUX)\" \ - -DGUEST_DTB_IMAGE_PATH=\"$(BLK_DRIVER_VM_DTB)\" \ - -DGUEST_INITRD_IMAGE_PATH=\"$(BLK_DRIVER_VM_INITRD_MODIFIED)\" \ - -target aarch64-none-elf \ - $< -o $@ - -$(BUILD_DIR)/client_images.o: $(LIBVMM_TOOLS)/package_guest_images.S $(CLIENT_VM_LINUX) $(CLIENT_VM_DTB) $(CLIENT_VM_INITRD_MODIFIED) - $(CC) -c -g3 -x assembler-with-cpp \ - -DGUEST_KERNEL_IMAGE_PATH=\"$(CLIENT_VM_LINUX)\" \ - -DGUEST_DTB_IMAGE_PATH=\"$(CLIENT_VM_DTB)\" \ - -DGUEST_INITRD_IMAGE_PATH=\"$(CLIENT_VM_INITRD_MODIFIED)\" \ - -target aarch64-none-elf \ - $< -o $@ - -$(BUILD_DIR)/%.o: %.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o: $(LIBVMM_SRC_DIR)/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o: $(LIBVMM_SRC_DIR)/util/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o: $(LIBVMM_SRC_DIR)/arch/aarch64/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o: $(LIBVMM_SRC_DIR)/arch/aarch64/vgic/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/%.o: $(LIBVMM_SRC_DIR)/virtio/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/sddf_blk_%.o: $(SDDF_BLK_COMPONENTS)/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/sddf_blk_%.o: $(SDDF_BLK_UTIL)/%.c Makefile - $(CC) -c $(CFLAGS) $< -o $@ - -$(BUILD_DIR)/client_vmm.elf: $(addprefix $(BUILD_DIR)/, $(CLIENT_VMM_OBJS)) - $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ - -$(BUILD_DIR)/blk_driver_vmm.elf: $(addprefix $(BUILD_DIR)/, $(BLK_DRIVER_VMM_OBJS)) - $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ - -$(BUILD_DIR)/blk_virt.elf: $(addprefix $(BUILD_DIR)/, $(BLK_VIRT_OBJS)) - $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ - -$(BUILD_DIR)/postmark: $(LINUX_BLK_DIR)/postmark.c - $(CC_USERLEVEL) $(CFLAGS_LINUX) $< -o $@ +export BUILD_DIR:=$(abspath $(BUILD_DIR)) +export MICROKIT_SDK:=$(abspath $(MICROKIT_SDK)) +export VIRTIO_EXAMPLE:=$(abspath .) -$(BUILD_DIR)/blk_client_init: $(LINUX_BLK_DIR)/blk_client_init - cp $< $@ +export TARGET := aarch64-none-elf +export CC := clang +export CC_USERLEVEL := zig cc +export LD := ld.lld +export AS := llvm-as +export AR := llvm-ar +export DTC := dtc +export RANLIB := llvm-ranlib +export MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit +export SDDF=$(abspath ../../dep/sddf) +export LIBVMM=$(abspath ../../) -$(BUILD_DIR)/blk_driver_init: $(LINUX_BLK_BOARD_DIR)/blk_driver_init - cp $< $@ +IMAGE_FILE := $(BUILD_DIR)/loader.img +REPORT_FILE := $(BUILD_DIR)/report.txt -$(BUILD_DIR)/%.o: $(UIO_DIR)/%.c Makefile - $(CC_USERLEVEL) -c $(CFLAGS_LINUX) $< -o $@ +all: $(IMAGE_FILE) -$(BUILD_DIR)/%.o: $(UIO_DRIVER_BLK_DIR)/%.c Makefile - $(CC_USERLEVEL) -c $(CFLAGS_LINUX) $< -o $@ +qemu $(IMAGE_FILE) $(REPORT_FILE) clean clobber: $(BUILD_DIR)/Makefile FORCE + $(MAKE) -C $(BUILD_DIR) MICROKIT_SDK=$(MICROKIT_SDK) $(notdir $@) -$(BUILD_DIR)/uio_blk_driver: $(addprefix $(BUILD_DIR)/, $(UIO_BLK_DRIVER_OBJS)) - $(CC_USERLEVEL) $(CFLAGS_LINUX) $^ -o $@ +$(BUILD_DIR)/Makefile: virtio.mk + mkdir -p $(BUILD_DIR) + cp virtio.mk $@ -$(IMAGE_FILE) $(REPORT_FILE): $(addprefix $(BUILD_DIR)/, $(ELFS)) $(SYSTEM_DESCRIPTION) - $(MICROKIT_TOOL) $(SYSTEM_DESCRIPTION) --search-path $(BUILD_DIR) --board $(BOARD) --config $(CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) \ No newline at end of file +FORCE: diff --git a/examples/virtio/board/odroidc4/blk_driver_vm/dts/disable.dts b/examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/disable.dts similarity index 100% rename from examples/virtio/board/odroidc4/blk_driver_vm/dts/disable.dts rename to examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/disable.dts diff --git a/examples/virtio/board/odroidc4/blk_driver_vm/dts/init.dts b/examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/init.dts similarity index 100% rename from examples/virtio/board/odroidc4/blk_driver_vm/dts/init.dts rename to examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/init.dts diff --git a/examples/virtio/board/odroidc4/blk_driver_vm/dts/io.dts b/examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/io.dts similarity index 100% rename from examples/virtio/board/odroidc4/blk_driver_vm/dts/io.dts rename to examples/virtio/board/odroidc4/blk_driver_vm/dts/overlays/io.dts diff --git a/examples/virtio/board/odroidc4/client_vm/dts/disable.dts b/examples/virtio/board/odroidc4/client_vm/dts/overlays/disable.dts similarity index 100% rename from examples/virtio/board/odroidc4/client_vm/dts/disable.dts rename to examples/virtio/board/odroidc4/client_vm/dts/overlays/disable.dts diff --git a/examples/virtio/board/odroidc4/client_vm/dts/init.dts b/examples/virtio/board/odroidc4/client_vm/dts/overlays/init.dts similarity index 100% rename from examples/virtio/board/odroidc4/client_vm/dts/init.dts rename to examples/virtio/board/odroidc4/client_vm/dts/overlays/init.dts diff --git a/examples/virtio/board/odroidc4/client_vm/dts/virtio.dts b/examples/virtio/board/odroidc4/client_vm/dts/overlays/virtio.dts similarity index 100% rename from examples/virtio/board/odroidc4/client_vm/dts/virtio.dts rename to examples/virtio/board/odroidc4/client_vm/dts/overlays/virtio.dts diff --git a/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/disable.dts b/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/disable.dts similarity index 100% rename from examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/disable.dts rename to examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/disable.dts diff --git a/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/init.dts b/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/init.dts similarity index 100% rename from examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/init.dts rename to examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/init.dts diff --git a/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/io.dts b/examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/io.dts similarity index 100% rename from examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/io.dts rename to examples/virtio/board/qemu_arm_virt/blk_driver_vm/dts/overlays/io.dts diff --git a/examples/virtio/board/qemu_arm_virt/client_vm/dts/init.dts b/examples/virtio/board/qemu_arm_virt/client_vm/dts/overlays/init.dts similarity index 100% rename from examples/virtio/board/qemu_arm_virt/client_vm/dts/init.dts rename to examples/virtio/board/qemu_arm_virt/client_vm/dts/overlays/init.dts diff --git a/examples/virtio/board/qemu_arm_virt/client_vm/dts/virtio.dts b/examples/virtio/board/qemu_arm_virt/client_vm/dts/overlays/virtio.dts similarity index 100% rename from examples/virtio/board/qemu_arm_virt/client_vm/dts/virtio.dts rename to examples/virtio/board/qemu_arm_virt/client_vm/dts/overlays/virtio.dts diff --git a/examples/virtio/include/blk_config.h b/examples/virtio/include/blk_config.h index 47b6f294..f8c7acd9 100644 --- a/examples/virtio/include/blk_config.h +++ b/examples/virtio/include/blk_config.h @@ -24,13 +24,15 @@ #define BLK_QUEUE_REGION_SIZE_CLI1 BLK_REGION_SIZE #define BLK_QUEUE_REGION_SIZE_DRIV BLK_REGION_SIZE -_Static_assert(BLK_DATA_REGION_SIZE_CLI0 >= BLK_TRANSFER_SIZE && BLK_DATA_REGION_SIZE_CLI0 % BLK_TRANSFER_SIZE == 0, +_Static_assert(BLK_DATA_REGION_SIZE_CLI0 >= BLK_TRANSFER_SIZE &&BLK_DATA_REGION_SIZE_CLI0 % BLK_TRANSFER_SIZE == 0, "Client0 data region size must be a multiple of the transfer size"); -_Static_assert(BLK_DATA_REGION_SIZE_CLI1 >= BLK_TRANSFER_SIZE && BLK_DATA_REGION_SIZE_CLI1 % BLK_TRANSFER_SIZE == 0, +_Static_assert(BLK_DATA_REGION_SIZE_CLI1 >= BLK_TRANSFER_SIZE &&BLK_DATA_REGION_SIZE_CLI1 % BLK_TRANSFER_SIZE == 0, "Client1 data region size must be a multiple of the transfer size"); -_Static_assert(BLK_DATA_REGION_SIZE_DRIV >= BLK_TRANSFER_SIZE && BLK_DATA_REGION_SIZE_DRIV % BLK_TRANSFER_SIZE == 0, +_Static_assert(BLK_DATA_REGION_SIZE_DRIV >= BLK_TRANSFER_SIZE &&BLK_DATA_REGION_SIZE_DRIV % BLK_TRANSFER_SIZE == 0, "Driver data region size must be a multiple of the transfer size"); +static const int blk_partition_mapping[BLK_NUM_CLIENTS] = { 0, 1 }; + static inline blk_storage_info_t *blk_virt_cli_config_info(blk_storage_info_t *info, unsigned int id) { switch (id) { @@ -86,7 +88,7 @@ static inline blk_resp_queue_t *blk_virt_cli_resp_queue(blk_resp_queue_t *resp, return resp; case 1: return (blk_resp_queue_t *)((uintptr_t)resp + BLK_QUEUE_REGION_SIZE_CLI0); - default: + default: return NULL; } } diff --git a/examples/virtio/virtio.mk b/examples/virtio/virtio.mk new file mode 100644 index 00000000..4222fad5 --- /dev/null +++ b/examples/virtio/virtio.mk @@ -0,0 +1,148 @@ +QEMU := qemu-system-aarch64 + +LIBVMM_TOOLS := $(LIBVMM)/tools +MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit +SDDF_INCLUDE := $(SDDF)/include/sddf +UTIL := $(SDDF)/util + +UART_DRIVER := $(SDDF)/drivers/serial/$(UART_DRIVER) +SERIAL_COMPONENTS := $(SDDF)/serial/components +BLK_COMPONENTS := $(SDDF)/blk/components + +BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG) +SYSTEM_DIR := $(VIRTIO_EXAMPLE)/board/$(MICROKIT_BOARD) +SYSTEM_FILE := $(SYSTEM_DIR)/virtio.system +IMAGE_FILE := loader.img +REPORT_FILE := report.txt + +CLIENT_VM_USERLEVEL := +CLIENT_VM_USERLEVEL_INIT := blk_client_init +BLK_DRIVER_VM_USERLEVEL := uio_blk_driver +BLK_DRIVER_VM_USERLEVEL_INIT := blk_driver_init + +vpath %.c $(SDDF) $(LIBVMM) $(VIRTIO_EXAMPLE) $(NETWORK_COMPONENTS) + +CFLAGS := \ + -mstrict-align \ + -ffreestanding \ + -g3 -O3 -Wall \ + -Wno-unused-function \ + -DMICROKIT_CONFIG_$(MICROKIT_CONFIG) \ + -DBOARD_$(MICROKIT_BOARD) \ + -I$(BOARD_DIR)/include \ + -I$(SDDF)/include \ + -I$(LIBVMM)/include \ + -I$(VIRTIO_EXAMPLE)/include \ + -I$(SDDF)/$(LWIPDIR)/include \ + -I$(SDDF)/$(LWIPDIR)/include/ipv4 \ + -MD \ + -MP \ + -target $(TARGET) + +CFLAGS_USERLEVEL := \ + -g3 \ + -O3 \ + -Wno-unused-command-line-argument \ + -Wall -Wno-unused-function -Werror \ + -D_GNU_SOURCE \ + -I$(VIRTIO_EXAMPLE)/include \ + -target aarch64-linux-gnu + +LDFLAGS := -L$(BOARD_DIR)/lib +LIBS := --start-group -lmicrokit -Tmicrokit.ld libsddf_util_debug.a libvmm.a --end-group + +include $(SDDF)/util/util.mk +include $(UART_DRIVER)/uart_driver.mk +include $(SERIAL_COMPONENTS)/serial_components.mk +include $(BLK_COMPONENTS)/blk_components.mk +include $(LIBVMM)/vmm.mk +include $(LIBVMM_TOOLS)/linux/uio/uio.mk +include $(LIBVMM_TOOLS)/linux/blk/blk_init.mk +include $(LIBVMM_TOOLS)/linux/uio_drivers/blk/uio_blk.mk + +IMAGES := client_vmm.elf blk_driver_vmm.elf \ + $(SERIAL_IMAGES) $(BLK_IMAGES) uart_driver.elf + +CHECK_FLAGS_BOARD_MD5:=.board_cflags-$(shell echo -- $(CFLAGS) $(BOARD) $(MICROKIT_CONFIG) | shasum | sed 's/ *-//') + +$(CHECK_FLAGS_BOARD_MD5): + -rm -f .board_cflags-* + touch $@ + +%_vmm.elf: %_vm/vmm.o %_vm/images.o + $(LD) $(LDFLAGS) $^ $(LIBS) -o $@ + +all: loader.img + +-include vmm.d + +$(IMAGES): libsddf_util_debug.a libvmm.a + +$(IMAGE_FILE) $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE) + $(MICROKIT_TOOL) $(SYSTEM_FILE) --search-path $(BUILD_DIR) --board $(MICROKIT_BOARD) \ + --config $(MICROKIT_CONFIG) -o $(IMAGE_FILE) -r $(REPORT_FILE) + +%_vm: + mkdir -p $@ + +client_vm/rootfs.cpio.gz: $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz \ + $(CLIENT_VM_USERLEVEL) $(CLIENT_VM_USERLEVEL_INIT) |client_vm + $(LIBVMM)/tools/packrootfs $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz \ + client_vm/rootfs -o $@ \ + --startup $(CLIENT_VM_USERLEVEL_INIT) \ + --home $(CLIENT_VM_USERLEVEL) + +blk_driver_vm/rootfs.cpio.gz: $(SYSTEM_DIR)/blk_driver_vm/rootfs.cpio.gz \ + $(BLK_DRIVER_VM_USERLEVEL) $(BLK_DRIVER_VM_USERLEVEL_INIT) |blk_driver_vm + $(LIBVMM)/tools/packrootfs $(SYSTEM_DIR)/blk_driver_vm/rootfs.cpio.gz \ + blk_driver_vm/rootfs -o $@ \ + --startup $(BLK_DRIVER_VM_USERLEVEL_INIT) \ + --home $(BLK_DRIVER_VM_USERLEVEL) + +blk_storage: + $(LIBVMM_TOOLS)/mkvirtdisk $@ $(BLK_NUM_PART) $(BLK_SIZE) $(BLK_MEM) + +%_vm/vm.dts: $(SYSTEM_DIR)/%_vm/dts/linux.dts \ + $(SYSTEM_DIR)/%_vm/dts/overlays/*.dts $(CHECK_FLAGS_BOARD_MD5) |%_vm + $(LIBVMM)/tools/dtscat $^ > $@ + +%_vm/vm.dtb: %_vm/vm.dts |%_vm + $(DTC) -q -I dts -O dtb $< > $@ + +%_vm/vmm.o: $(VIRTIO_EXAMPLE)/%_vmm.c $(CHECK_FLAGS_BOARD_MD5) |%_vm + $(CC) $(CFLAGS) -c -o $@ $< + +%_vm/images.o: $(LIBVMM)/tools/package_guest_images.S $(CHECK_FLAGS_BOARD_MD5) \ + $(SYSTEM_DIR)/%_vm/linux %_vm/vm.dtb %_vm/rootfs.cpio.gz + $(CC) -c -g3 -x assembler-with-cpp \ + -DGUEST_KERNEL_IMAGE_PATH=\"$(SYSTEM_DIR)/$(@D)/linux\" \ + -DGUEST_DTB_IMAGE_PATH=\"$(@D)/vm.dtb\" \ + -DGUEST_INITRD_IMAGE_PATH=\"$(@D)/rootfs.cpio.gz\" \ + -target $(TARGET) \ + $(LIBVMM)/tools/package_guest_images.S -o $@ + +# Stop make from deleting intermediate files +.PRECIOUS: blk_driver_vm blk_driver_vm/vm.dts \ + blk_driver_vm/vm.dtb blk_driver_vm/rootfs.cpio.gz \ + blk_driver_vm/images.o blk_driver_vm/vmm.o \ + client_vm client_vm/vm.dts client_vm/vm.dtb \ + client_vm/rootfs.cpio.gz client_vm/images.o client_vm/vmm.o + +qemu: $(IMAGE_FILE) blk_storage + [ ${MICROKIT_BOARD} = qemu_arm_virt ] + $(QEMU) -machine virt,virtualization=on,secure=off \ + -cpu cortex-a53 \ + -serial mon:stdio \ + -device loader,file=$(IMAGE_FILE),addr=0x70000000,cpu-num=0 \ + -m size=2G \ + -nographic \ + -drive file=blk_storage,format=raw,if=none,id=drive0 \ + -device virtio-blk-device,drive=drive0,id=virtblk0,num-queues=1 + +clean:: + $(RM) -f *.elf .depend* $ + find . -name \*.[do] -type f |xargs --no-run-if-empty rm + +clobber:: clean + rm -f *.a + rm -f $(IMAGE_FILE) $(REPORT_FILE) diff --git a/tools/linux/blk/blk_init.mk b/tools/linux/blk/blk_init.mk new file mode 100644 index 00000000..0a54f38c --- /dev/null +++ b/tools/linux/blk/blk_init.mk @@ -0,0 +1,23 @@ +# +# Copyright 2024, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Generates blk_client_init and blk_driver_init scripts +# + +ifeq ($(strip $(MICROKIT_BOARD)),) +$(error MICROKIT_BOARD must be specified) +endif + +LINUX_BLK_DIR := $(abs $(dir $(last ${MAKEFILES_LIST}))) +LIBVMM ?= $(realpath ${LINUX_BLK_DIR}/../../../) + +blk_client_init: $(LIBVMM)/tools/linux/blk/blk_client_init + cp $^ $@ + +blk_driver_init: $(LIBVMM)/tools/linux/blk/board/$(MICROKIT_BOARD)/blk_driver_init + cp $^ $@ + +clobber:: + rm -f blk_client_init blk_driver_init diff --git a/tools/linux/uio/uio.mk b/tools/linux/uio/uio.mk new file mode 100644 index 00000000..c7efdd04 --- /dev/null +++ b/tools/linux/uio/uio.mk @@ -0,0 +1,43 @@ +# +# Copyright 2024, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Generates library libuio.a to be linked against userlevel drivers +# + +ifeq ($(strip $(SDDF)),) +$(error SDDF must be specified) +endif +ifeq ($(strip $(CC_USERLEVEL)),) +$(error CC_USERLEVEL must be specified) +endif + +LINUX_UIO_DIR := $(abs $(dir $(last ${MAKEFILES_LIST}))) +LIBVMM ?= $(realpath ${LINUX_UIO_DIR}/../../../) + +LIBUIO_IMAGES := libuio.a + +CFLAGS_libuio := -I$(SDDF)/include -I$(LIBVMM)/tools/linux/include + +CHECK_LIBUIO_FLAGS_MD5:=.libuio_cflags-$(shell echo -- $(CFLAGS_USERLEVEL) $(CFLAGS_libuio) | shasum | sed 's/ *-//') + +$(CHECK_LIBUIO_FLAGS_MD5): + -rm -f .libuio_cflags-* + touch $@ + + +libuio.a: libuio.o + ar rv $@ $^ + +libuio.o: $(CHECK_LIBUIO_FLAGS_MD5) +libuio.o: $(LIBVMM)/tools/linux/uio/libuio.c + $(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $(CFLAGS_libuio) -o $@ -c $< + +clean:: + rm -f libuio.[od] .libuio_cflags-* + +clobber:: + rm -f $(UIO_BLK_IMAGES) + +-include libuio.d diff --git a/tools/linux/uio_drivers/blk/uio_blk.mk b/tools/linux/uio_drivers/blk/uio_blk.mk new file mode 100644 index 00000000..7e067f12 --- /dev/null +++ b/tools/linux/uio_drivers/blk/uio_blk.mk @@ -0,0 +1,42 @@ +# +# Copyright 2024, UNSW +# +# SPDX-License-Identifier: BSD-2-Clause +# +# This Makefile snippet builds block UIO driver +# + +ifeq ($(strip $(LIBVMM_TOOLS)),) +$(error LIBVMM_TOOLS must be specified) +endif +ifeq ($(strip $(SDDF)),) +$(error SDDF must be specified) +endif +ifeq ($(strip $(CC_USERLEVEL)),) +$(error CC_USERLEVEL must be specified) +endif + +UIO_BLK_IMAGES := uio_blk_driver + +CFLAGS_uio_blk_driver := -I$(SDDF)/include -I$(LIBVMM_TOOLS)/linux/include + +CHECK_UIO_BLK_DRIVER_FLAGS_MD5:=.uio_blk_driver_cflags-$(shell echo -- $(CFLAGS_USERLEVEL) $(CFLAGS_uio_blk_driver) | shasum | sed 's/ *-//') + +$(CHECK_UIO_BLK_DRIVER_FLAGS_MD5): + -rm -f .uio_blk_driver_cflags-* + touch $@ + +uio_blk_driver: uio_blk_driver.o libuio.a + $(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $(CFLAGS_uio_blk_driver) $^ -o $@ + +uio_blk_driver.o: $(CHECK_UIO_BLK_DRIVER_FLAGS_MD5) +uio_blk_driver.o: $(LIBVMM_TOOLS)/linux/uio_drivers/blk/blk.c + $(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $(CFLAGS_uio_blk_driver) -o $@ -c $< + +clean:: + rm -f uio_blk_driver.[od] .uio_blk_driver_cflags-* + +clobber:: + rm -f $(UIO_BLK_IMAGES) + +-include uio_blk_driver.d