Skip to content

Commit

Permalink
examples/virtio: make: add userlevel snippets
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Brown <[email protected]>
  • Loading branch information
alexandermbrown committed Jul 9, 2024
1 parent 0768f92 commit 30cbc41
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 11 deletions.
5 changes: 5 additions & 0 deletions examples/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ 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 MICROKIT_BOARD given)
endif
Expand All @@ -35,6 +39,7 @@ export VIRTIO_EXAMPLE:=$(abspath .)

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
Expand Down
2 changes: 1 addition & 1 deletion examples/virtio/include/blk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <sddf/util/string.h>
#include <sddf/blk/queue.h>

// #define BLK_NUM_CLIENTS 2
#define BLK_NUM_CLIENTS 2

#define BLK_NAME_CLI0 "CLIENT_VMM-1"
#define BLK_NAME_CLI1 "CLIENT_VMM-2"
Expand Down
41 changes: 31 additions & 10 deletions examples/virtio/virtio.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
QEMU := qemu-system-aarch64

VMM_TOOLS := $(LIBVMM)/tools
MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit
SDDF_INCLUDE := $(SDDF)/include/sddf
UTIL := $(SDDF)/util
Expand All @@ -9,21 +10,27 @@ SERIAL_COMPONENTS := $(SDDF)/serial/components
BLK_COMPONENTS := $(SDDF)/blk/components

SERIAL_NUM_CLIENTS := -DSERIAL_NUM_CLIENTS=3
BLK_NUM_CLIENTS := -DBLK_NUM_CLIENTS=2

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)

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 $(VMM_TOOLS)/linux/blk/blk_init.mk
include $(VMM_TOOLS)/linux/uio_drivers/blk/uio_blk.mk

IMAGES := client_vmm.elf blk_driver_vmm.elf \
$(SERIAL_IMAGES) $(BLK_IMAGES) uart_driver.elf
Expand All @@ -45,6 +52,15 @@ CFLAGS := \
-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

Expand All @@ -69,12 +85,19 @@ $(IMAGE_FILE) $(REPORT_FILE): $(IMAGES) $(SYSTEM_FILE)
%_vm:
mkdir -p $@

# TODO: sort out userlevel scripts & build userlevel processes
client_vm/rootfs.cpio.gz: client_vm $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz
client_vm/rootfs.cpio.gz: client_vm $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz $(CLIENT_VM_USERLEVEL) $(CLIENT_VM_USERLEVEL_INIT)
$(LIBVMM)/tools/packrootfs $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz client_vm/rootfs -o $@ \
--startup $(CLIENT_VM_USERLEVEL) \
--startup $(CLIENT_VM_USERLEVEL_INIT) \
--home $(CLIENT_VM_USERLEVEL)

blk_driver_vm/rootfs.cpio.gz: blk_driver_vm $(SYSTEM_DIR)/blk_driver_vm/rootfs.cpio.gz $(BLK_DRIVER_VM_USERLEVEL) $(BLK_DRIVER_VM_USERLEVEL_INIT)
$(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:
$(VMM_TOOLS)/mkvirtdisk $@ $(BLK_NUM_PART) $(BLK_SIZE) $(BLK_MEM)

# %_vm/rootfs.cpio.gz: %_vm $(SYSTEM_DIR)/%_vm/rootfs.cpio.gz
# $(LIBVMM)/tools/packrootfs $(SYSTEM_DIR)/$</rootfs.cpio.gz $</rootfs -o $@

Expand All @@ -99,17 +122,15 @@ client_vm/rootfs.cpio.gz: client_vm $(SYSTEM_DIR)/client_vm/rootfs.cpio.gz
client_vm_files:: client_vm client_vm/vm.dts client_vm/vm.dtb client_vm/rootfs.cpio.gz client_vm/images.o client_vm/vmm.o
blk_driver_vm_files:: 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

qemu: $(IMAGE_FILE)
$(QEMU) -machine virt,virtualization=on \
qemu: $(IMAGE_FILE) blk_storage
$(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 \
-device virtio-net-device,netdev=netdev0 \
-netdev user,id=netdev0,hostfwd=tcp::1236-:1236,hostfwd=udp::1235-:1235 \
-global virtio-mmio.force-legacy=false \
-d guest_errors
-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* $
Expand Down
21 changes: 21 additions & 0 deletions tools/linux/blk/blk_init.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright 2024, UNSW
#
# SPDX-License-Identifier: BSD-2-Clause
#

ifeq ($(strip $(LIBVMM)),)
$(error LIBVMM must be specified)
endif
ifeq ($(strip $(MICROKIT_BOARD)),)
$(error MICROKIT_BOARD must be specified)
endif

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
44 changes: 44 additions & 0 deletions tools/linux/uio_drivers/blk/uio_blk.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#
# Copyright 2024, UNSW
#
# SPDX-License-Identifier: BSD-2-Clause
#
# This Makefile snippet builds block UIO driver
#

ifeq ($(strip $(VMM_TOOLS)),)
$(error VMM_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$(VMM_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 $@


# This shouldn't have a -c but for some reason it only works with one
uio_blk_driver: uio_blk_driver.o
$(CC_USERLEVEL) $(CFLAGS_USERLEVEL) $(CFLAGS_uio_blk_driver) -o $@ -c $<

uio_blk_driver.o: $(CHECK_UIO_BLK_DRIVER_FLAGS_MD5)
uio_blk_driver.o: $(VMM_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

0 comments on commit 30cbc41

Please sign in to comment.