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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/
docs/book/
.DS_Store

TAGS
examples/vmm/vmm/initrd.img
examples/vmm/vmm/linux
Comment on lines +5 to +6

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be necessary.

1 change: 1 addition & 0 deletions ci/examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ MICROKIT_SDK=$2
$LIONSOS/ci/kitty.sh $LIONSOS $MICROKIT_SDK
$LIONSOS/ci/webserver.sh $LIONSOS $MICROKIT_SDK
$LIONSOS/ci/vmm.sh $LIONSOS $MICROKIT_SDK
$LIONSOS/ci/vmm-virtio.sh $LIONSOS $MICROKIT_SDK
24 changes: 24 additions & 0 deletions ci/vmm-virtio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
#
# This script aims to build an already checked out version of LionsOS.
#

set -e

if [ "$#" -ne 2 ]; then
echo "usage: vmm.sh /path/to/lionsos /path/to/microkit/sdk"
exit 1
fi

LIONSOS=$1
MICROKIT_SDK=$2

BUILD_DIR=$LIONSOS/ci_build/vmm-virtio
rm -rf $BUILD_DIR

export BUILD_DIR=$BUILD_DIR
export MICROKIT_SDK=$MICROKIT_SDK
export LIONSOS=$LIONSOS

cd $LIONSOS/examples/vmm
make VARIANT=virtio
47 changes: 27 additions & 20 deletions examples/vmm/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ Simple VM with passthrough
================================

This directory contains what's needed to run a complete VM with
passthrough of all components on an Odroid C4.

The ethernetsddf branch uses LionsOS console drivers.
passthrough of all components (including the GPU) on an Odroid C4.

Such a VM can be used to develop new LionsOS components, and is fairly
easy to adapt to other systems.

What you need
================
=================

Build and Source dependencies
-----------------------------
Expand All @@ -31,11 +29,14 @@ target system. The simplest way to get them is to extract them from

For Armbian-based systems, the files you need are `/boot/Image`
`/boot/initrd.img` and `/boot/dtb/amlogic/meson-sm1-odroid-c4.dtb`.
Use `scp` to transfer these files to your build machine.
Boot your board into Linux, then use `scp` to transfer these files to
your build machine, and put them into the `vmm` subdirectory.

There are versions in the Git repo, but these might not match your
root filesystem --- they were taken from an [Armbian](https://github.com/armbian/community/releases/download/24.5.0-trunk.168/Armbian_community_24.5.0-trunk.168_Odroidc4_jammy_current_6.6.21_gnome_desktop.img.xz) 'Jammy' Ubuntu
system.
The Makefile will fetch some from our website if they are missing from
`vmm`, but there's no guarantee they'll match what's on your root
filesystem --- they were taken from an
[Armbian](https://github.com/armbian/community/releases/download/24.5.0-trunk.168/Armbian_community_24.5.0-trunk.168_Odroidc4_jammy_current_6.6.21_gnome_desktop.img.xz)
'Jammy' Ubuntu system.

You will also need to update the commandline in `vmm/overlay.dts`,
especially if you are not running Ubuntu Jammy Armbian.
Expand All @@ -44,33 +45,39 @@ The Microkit
------------

You can use the prebuilt microkit from
[Prebuilt](https://trustworthy.systems/Downloads/microkit/microkit-sdk-dev-7c679ea-linux-x86-64.tar.gz)

If you choose to build your own. At the moment,
the microkit from [Ivan Velickovic's
repository](https://github.com/Ivan-Velickovic/microkit) on the dev
branch is the one to use.
[Prebuilt](https://github.com/seL4/microkit/releases/download/1.4.1/microkit-sdk-1.4.1-linux-x86-64.tar.gz)

You can build it by following
If you choose to build your own,
you can build it by following
the instructions in the
[ReadMe](https://github.com/Ivan-Velickovic/microkit)
[ReadMe](https://github.com/seL4/microkit)

You need version 1.4.1

Building
--------

You need to have `aarch64-none-elf-gcc` etc in your PATH; plus you
need to set the LionsOS and MICROKIT_SDK environment variables.
You need to have `aarch64-none-elf-gcc` etc., in your PATH; plus you
need to set the LIONSOS and MICROKIT_SDK environment variables.

If the vmm-example repository is checked out at the same level in your
directory tree as LionsOS the default will work.

Otherwise do:
```
cd vmm-examples
MICROKIT_SDK=.../path-to/microkit-sdk-1.2.6 LionsOS=.../path-to/LionsOS make
MICROKIT_SDK=.../path-to/microkit-sdk-1.4.1 LionsOS=.../path-to/LionsOS make
```


If all goes well, a directory called `build`,and a
bootable image `boot/vmdev.img`, will be created.

There are two variants you can build. The standard variant passes
through _everything_; the `virtio_console` variant uses the sDDF's
UART driver and a virtio console.

To select, do
```
make VARIANT=virtio_console MICROKIT_SDK=... ...
```

5 changes: 5 additions & 0 deletions examples/vmm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VMM Examples
================

See https://lionsos.org/docs/examples/vmm/ for documentation and build
instructions.
103 changes: 103 additions & 0 deletions examples/vmm/include/serial_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright 2024, UNSW
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#pragma once

#include <microkit.h>
#include <sddf/util/string.h>
#include <sddf/serial/queue.h>
#include <stdint.h>

/* Number of clients */
#define SERIAL_NUM_CLIENTS 1

/* Only support transmission and not receive. */
#define SERIAL_TX_ONLY 0

/* Associate a colour with each client's output. */
#define SERIAL_WITH_COLOUR 0

/*
* Control character to switch input stream - ctrl \.
* To input character input twice.
*/
#define SERIAL_SWITCH_CHAR 28

/* Control character to terminate client number input. */
#define SERIAL_TERMINATE_NUM '\r'

/* Default baud rate of the uart device */
#define UART_DEFAULT_BAUD 115200

/* String to be printed to start console input */
#define SERIAL_CONSOLE_BEGIN_STRING "Begin input\n"
#define SERIAL_CONSOLE_BEGIN_STRING_LEN 13

#define SERIAL_CLI0_NAME "CLIENT_VM"
#define SERIAL_VIRT_RX_NAME "serial_virt_rx"
#define SERIAL_VIRT_TX_NAME "serial_virt_tx"
#define SERIAL_DRIVER_NAME "uart_driver"

#define SERIAL_QUEUE_SIZE 0x1000
#define SERIAL_DATA_REGION_SIZE 0x2000

#define SERIAL_TX_DATA_REGION_SIZE_DRIV SERIAL_DATA_REGION_SIZE
#define SERIAL_TX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE

#define SERIAL_RX_DATA_REGION_SIZE_DRIV SERIAL_DATA_REGION_SIZE
#define SERIAL_RX_DATA_REGION_SIZE_CLI0 SERIAL_DATA_REGION_SIZE

#define SERIAL_MAX_TX_DATA_SIZE MAX( \
SERIAL_TX_DATA_REGION_SIZE_DRIV, \
SERIAL_TX_DATA_REGION_SIZE_CLI0 \
)
#define SERIAL_MAX_RX_DATA_SIZE MAX( \
SERIAL_RX_DATA_REGION_SIZE_DRIV, \
SERIAL_RX_DATA_REGION_SIZE_CLI0 \
)
#define SERIAL_MAX_DATA_SIZE MAX( \
SERIAL_MAX_TX_DATA_SIZE, \
SERIAL_MAX_RX_DATA_SIZE \
)
_Static_assert(SERIAL_MAX_DATA_SIZE < UINT32_MAX,
"Data regions must be smaller than UINT32 max"
" to use the queue data structure correctly.");

static inline void serial_cli_queue_init_sys(
char *pd_name, serial_queue_handle_t *rx_queue_handle,
serial_queue_t *rx_queue, char *rx_data,
serial_queue_handle_t *tx_queue_handle,
serial_queue_t *tx_queue, char *tx_data)
{
if (!sddf_strcmp(pd_name, SERIAL_CLI0_NAME)) {
serial_queue_init(rx_queue_handle, rx_queue, SERIAL_RX_DATA_REGION_SIZE_CLI0, rx_data);
serial_queue_init(tx_queue_handle, tx_queue, SERIAL_TX_DATA_REGION_SIZE_CLI0, tx_data);
}
}

static inline void serial_virt_queue_init_sys(
char *pd_name, serial_queue_handle_t *cli_queue_handle,
serial_queue_t *cli_queue, char *cli_data)
{
if (!sddf_strcmp(pd_name, SERIAL_VIRT_RX_NAME)) {
serial_queue_init(cli_queue_handle,
cli_queue,
SERIAL_RX_DATA_REGION_SIZE_CLI0,
cli_data);
} else if (!sddf_strcmp(pd_name, SERIAL_VIRT_TX_NAME)) {
serial_queue_init(cli_queue_handle,
cli_queue,
SERIAL_TX_DATA_REGION_SIZE_CLI0,
cli_data);
}
}

#if SERIAL_WITH_COLOUR
static inline void serial_channel_names_init(char **client_names)
{
client_names[0] = SERIAL_CLI0_NAME;
}
#endif
12 changes: 8 additions & 4 deletions examples/vmm/vmm-dev.mk
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG)
LIBVMM ?= ${LIONSOS}/dep/libvmm

VMM_IMAGE_DIR := ${EXAMPLE_DIR}/vmm
LINUX := 1e6f245cabe25aabf179448e41dea5fe5550c98d-linux
INITRD := 1ef035ae59438f6df6c596a6de7cc36d6a3368ac-initrd.img
LINUX := ${VMM_IMAGE_DIR}/linux
INITRD :=${VMM_IMAGE_DIR}/initrd.img
SAMPLE_LINUX := 1e6f245cabe25aabf179448e41dea5fe5550c98d-linux
SAMPLE_INITRD := 1ef035ae59438f6df6c596a6de7cc36d6a3368ac-initrd.img

IMAGES := vmm.elf
CFLAGS := \
Expand Down Expand Up @@ -85,8 +87,10 @@ all: $(IMAGE_FILE)
${notdir $(ORIGINAL_DTB:.dtb=.dts)}: ${ORIGINAL_DTB} ${MAKEFILE}
$(DTC) -q -I dtb -O dts $< > $@ || rm -f $@

$(INITRD) $(LINUX):
curl -L https://lionsos.org/downloads/examples/vmm/$@ -o $@
$(INITRD):
curl -L https://lionsos.org/downloads/examples/vmm/${SAMPLE_INITRD} -o $@
$(LINUX):
curl -L https://lionsos.org/downloads/examples/vmm/${SAMPLE_LINUX} -o $@

dtb.dts: ${notdir $(ORIGINAL_DTB:.dtb=.dts)} ${DT_OVERLAYS} vmm_ram.h ${CHECK_VARIANT}
${LIBVMM}/tools/dtscat ${notdir $(ORIGINAL_DTB:.dtb=.dts)} ${DT_OVERLAYS} | cpp -nostdinc -undef -x assembler-with-cpp -P - > $@ || rm -f $@
Expand Down
35 changes: 25 additions & 10 deletions examples/vmm/vmm-virtio-console.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ifeq ($(strip $(LIBGCC)),)
LIBGCC := $(shell dirname $$(aarch64-none-elf-gcc --print-file-name libgcc.a))
endif

ifeq ($(strip $(LionsOS)),)
$(error LionsOS should point to the root of the LionOS source tree)
ifeq ($(strip $(LIONSOS)),)
$(error LIONSOS should point to the root of the LionOS source tree)
endif

ifeq ($(strip $(SDDF)),)
Expand All @@ -33,6 +33,8 @@ CPU := cortex-a55
TOOLCHAIN := clang
CC := clang
LD := ld.lld
RANLIB := llvm-ranlib

TARGET := aarch64-none-elf

CHECK_VARIANT:=.variant.$(shell md5sum ${SYSTEM})
Expand All @@ -48,14 +50,19 @@ MICROKIT_TOOL ?= $(MICROKIT_SDK)/bin/microkit
DTC := dtc

BOARD_DIR := $(MICROKIT_SDK)/board/$(MICROKIT_BOARD)/$(MICROKIT_CONFIG)
LIBVMM_DIR ?= ${LionsOS}/dep/libvmm
LIBVMM_DIR ?= ${LIONSOS}/dep/libvmm

VMM_IMAGE_DIR := ${EXAMPLE_DIR}/vmm
LINUX := $(VMM_IMAGE_DIR)/Linux
LINUX := ${VMM_IMAGE_DIR}/linux
INITRD :=${VMM_IMAGE_DIR}/initrd.img

SAMPLE_LINUX := 1e6f245cabe25aabf179448e41dea5fe5550c98d-linux
SAMPLE_INITRD := 1ef035ae59438f6df6c596a6de7cc36d6a3368ac-initrd.img

INITRD := $(VMM_IMAGE_DIR)/initrd.img
DT_OVERLAYS := ${VMM_IMAGE_DIR}/overlay-virtcon.dts

IMAGES := vmm.elf uart_driver.elf serial_rx_virt.elf serial_tx_virt.elf
IMAGES := vmm.elf uart_driver.elf serial_virt_rx.elf serial_virt_tx.elf
CFLAGS := \
-mtune=$(CPU) \
-mstrict-align \
Expand All @@ -64,13 +71,12 @@ CFLAGS := \
-O0 \
-Wall \
-Wno-unused-function \
-DBOARD_$(MICROKIT_BOARD) \
-I. \
-I$(BOARD_DIR)/include \
-target $(TARGET) \
-I$(LIBVMM_DIR)/src/arch/aarch64 \
-I$(LIBVMM_DIR)/src \
-I$(LIBVMM_DIR)/src/util \
-DBOARD_$(MICROKIT_BOARD) \
-I$(LIBVMM_DIR)/include \
-I${EXAMPLE_DIR}/include \
-I$(SDDF)/include \
-MD \
-DMAC_BASE_ADDRESS=$(MAC_BASE_ADDRESS)
Expand Down Expand Up @@ -99,6 +105,13 @@ ${notdir $(ORIGINAL_DTB:.dtb=.dts)}: ${ORIGINAL_DTB} ${MAKEFILE}
dtb.dts: ${notdir $(ORIGINAL_DTB:.dtb=.dts)} ${DT_OVERLAYS} vmm_ram.h
${LIBVMM_DIR}/tools/dtscat ${notdir $(ORIGINAL_DTB:.dtb=.dts)} ${DT_OVERLAYS} | cpp -nostdinc -undef -x assembler-with-cpp -P - > $@ || rm -f $@

$(INITRD):
curl -L https://lionsos.org/downloads/examples/vmm/${SAMPLE_INITRD} -o $@
$(LINUX):
curl -L https://lionsos.org/downloads/examples/vmm/${SAMPLE_LINUX} -o $@

vmm-virtio-console.o: vmm_ram.h

package_guest_images.o: $(LIBVMM_DIR)/tools/package_guest_images.S $(LINUX) $(INITRD) dtb.dtb
$(CC) -c -g3 -x assembler-with-cpp \
-DGUEST_KERNEL_IMAGE_PATH=\"$(LINUX)\" \
Expand Down Expand Up @@ -136,6 +149,8 @@ clobber:: clean
# How to build libvmm.a
include ${LIBVMM_DIR}/vmm.mk
# the UART driver
include ${SDDF}/drivers/serial/meson/uart.mk
include ${SDDF}/drivers/serial/meson/uart_driver.mk
# the multiplexers
include ${SDDF}/serial/components/serial_components.mk
# and the util library needed by the uart driver and serial components
include ${SDDF}/util/util.mk
Loading