Skip to content

Commit

Permalink
support odroidc4 on virtio example
Browse files Browse the repository at this point in the history
  • Loading branch information
erichchan999 committed Feb 21, 2024
1 parent 901d68f commit 6f42997
Show file tree
Hide file tree
Showing 35 changed files with 55,728 additions and 73 deletions.
42 changes: 30 additions & 12 deletions examples/virtio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,50 @@ BLK_DRIVER_VM_LINUX := $(BLK_DRIVER_VM_DIR)/linux
BLK_DRIVER_VM_INITRD := $(BLK_DRIVER_VM_DIR)/rootfs.cpio.gz
BLK_DRIVER_VM_INITRD_OVERLAYED := $(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 := $(BLK_DRIVER_VM_DTS_DIR)/init.dts \
$(BLK_DRIVER_VM_DTS_DIR)/uio.dts

CLIENT_VM_1_LINUX := $(CLIENT_VM_1_DIR)/linux
CLIENT_VM_1_INITRD := $(CLIENT_VM_1_DIR)/rootfs.cpio.gz
CLIENT_VM_1_INITRD_OVERLAYED := $(BUILD_DIR)/client_vm_1_rootfs.cpio.gz
CLIENT_VM_1_BASE_DTS := $(CLIENT_VM_1_DTS_DIR)/linux.dts
CLIENT_VM_1_DTS_OVERLAYS := $(CLIENT_VM_1_DTS_DIR)/init.dts \
$(CLIENT_VM_1_DTS_DIR)/virtio.dts

CLIENT_VM_2_LINUX := $(CLIENT_VM_2_DIR)/linux
CLIENT_VM_2_INITRD := $(CLIENT_VM_2_DIR)/rootfs.cpio.gz
CLIENT_VM_2_INITRD_OVERLAYED := $(BUILD_DIR)/client_vm_2_rootfs.cpio.gz
CLIENT_VM_2_BASE_DTS := $(CLIENT_VM_2_DTS_DIR)/linux.dts
CLIENT_VM_2_DTS_OVERLAYS := $(CLIENT_VM_2_DTS_DIR)/init.dts \
$(CLIENT_VM_2_DTS_DIR)/virtio.dts

BLK_DRIVER_VM_DTB := $(BUILD_DIR)/blk_driver_vm.dtb
CLIENT_VM_1_DTB := $(BUILD_DIR)/client_vm_1.dtb
CLIENT_VM_2_DTB := $(BUILD_DIR)/client_vm_2.dtb

SDDF := sddf

SDDF_BLK_SHAREDQUEUE := $(SDDF)/blk/libblksharedqueue
SDDF_SERIAL_RINGBUFFER := $(SDDF)/serial/libserialsharedringbuffer
SDDF_SERIAL_COMPONENTS := $(SDDF)/serial/components
SDDF_SERIAL_DRIVER := $(SDDF)/drivers/serial/arm

SDDF_BLK_SHAREDQUEUE := $(SDDF)/blk/libblksharedqueue
ifeq ($(BOARD),qemu_arm_virt)
SDDF_SERIAL_DRIVER := $(SDDF)/drivers/serial/arm
BLK_DRIVER_VM_DTS_OVERLAYS := $(BLK_DRIVER_VM_DTS_DIR)/init.dts \
$(BLK_DRIVER_VM_DTS_DIR)/uio.dts
CLIENT_VM_1_DTS_OVERLAYS := $(CLIENT_VM_1_DTS_DIR)/init.dts \
$(CLIENT_VM_1_DTS_DIR)/virtio.dts
CLIENT_VM_2_DTS_OVERLAYS := $(CLIENT_VM_2_DTS_DIR)/init.dts \
$(CLIENT_VM_2_DTS_DIR)/virtio.dts
BLK_DRIVER_VM_USERLEVEL_INIT := qemu_blk_driver_init
else ifeq ($(BOARD),odroidc4)
SDDF_SERIAL_DRIVER := $(SDDF)/drivers/serial/meson
BLK_DRIVER_VM_DTS_OVERLAYS := $(BLK_DRIVER_VM_DTS_DIR)/init.dts \
$(BLK_DRIVER_VM_DTS_DIR)/uio.dts \
$(BLK_DRIVER_VM_DTS_DIR)/disable.dts
CLIENT_VM_1_DTS_OVERLAYS := $(CLIENT_VM_1_DTS_DIR)/init.dts \
$(CLIENT_VM_1_DTS_DIR)/virtio.dts\
$(CLIENT_VM_1_DTS_DIR)/disable.dts
CLIENT_VM_2_DTS_OVERLAYS := $(CLIENT_VM_2_DTS_DIR)/init.dts \
$(CLIENT_VM_2_DTS_DIR)/virtio.dts \
$(CLIENT_VM_2_DTS_DIR)/disable.dts
BLK_DRIVER_VM_USERLEVEL_INIT := blk_driver_init
else
$(error "Board $(BOARD) is not supported")
endif

ELFS := client_vmm_1.elf client_vmm_2.elf blk_driver_vmm.elf serial_mux_tx.elf serial_mux_rx.elf uart_driver.elf

Expand All @@ -116,7 +132,6 @@ CLIENT_VM_1_USERLEVEL_INIT := blk_client_init
CLIENT_VM_2_USERLEVEL := postmark
CLIENT_VM_2_USERLEVEL_INIT := blk_client_init
BLK_DRIVER_VM_USERLEVEL := uio_blk_driver storage_0 storage_1
BLK_DRIVER_VM_USERLEVEL_INIT := blk_driver_init

IMAGE_FILE = $(BUILD_DIR)/loader.img
REPORT_FILE = $(BUILD_DIR)/report.txt
Expand All @@ -136,7 +151,7 @@ VMM_OBJS := printf.o \
tcb.o \
vcpu.o \

CLIENT_VMM_1_OBJS := $(VMM_OBJS) \
CLIENT_VMM_1_OBJS := $(VMM_OBJS) \
client_images_1.o \
client_vmm_1.o \
virtio.o \
Expand All @@ -156,7 +171,7 @@ CLIENT_VMM_2_OBJS := $(VMM_OBJS) \
sddf_serial_sharedringbuffer.o \
sddf_blk_shared_queue.o \

BLK_DRIVER_VMM_OBJS := $(VMM_OBJS) \
BLK_DRIVER_VMM_OBJS := $(VMM_OBJS) \
blk_driver_images.o \
blk_driver_vmm.o \
virtio.o \
Expand Down Expand Up @@ -371,6 +386,9 @@ $(BUILD_DIR)/blk_client_init: $(LINUX_DIR)/blk_client_init Makefile
$(BUILD_DIR)/blk_driver_init: $(LINUX_DIR)/blk_driver_init Makefile
cp $< $@

$(BUILD_DIR)/qemu_blk_driver_init: $(LINUX_DIR)/qemu_blk_driver_init Makefile
cp $< $@

$(BUILD_DIR)/uio_blk_driver: $(addprefix $(BUILD_DIR)/, $(UIO_BLK_DRIVER_OBJS))
$(TOOLCHAIN)-gcc $(CFLAGS_LINUX) $^ -o $@

Expand Down
5 changes: 4 additions & 1 deletion examples/virtio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ make BOARD=<BOARD> MICROKIT_SDK=/path/to/sdk

Where `<BOARD>` is one of:
* `qemu_arm_virt`
* `odroidc4`

Other configuration options can be passed to the Makefile such as `CONFIG`
and `BUILD_DIR`, see the Makefile for details.
Expand Down Expand Up @@ -72,4 +73,6 @@ After the client VMs boot, they will attempt to mount the first partition of the
[ 22.793574] EXT4-fs (vda): mounted filesystem without journal. Quota mode: none.
```

We can further test the virtIO block implementation by using block benchmark programs like `postmark`, which has been included in `/root`, by running it in the `/mnt` directory.
We can further test the virtIO block implementation by using block benchmark programs like `postmark`, which has been included in `/root`, by running it in the `/mnt` directory.

When running on the odroidc4, the system expects to read and write from the SD card, not the eMMC. When running on QEMU, read and writes go to ramdisk instead of a persistent storage device.
40 changes: 34 additions & 6 deletions examples/virtio/blk_driver_vmm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
* guest's "RAM" the same for all platforms. For just booting Linux with a
* simple user-space, 0x10000000 bytes (256MB) is plenty.
*/
#define GUEST_RAM_SIZE 0x8000000
#define GUEST_RAM_SIZE 0x6000000

#if defined(BOARD_qemu_arm_virt)
#define GUEST_DTB_VADDR 0x47f00000
#define GUEST_INIT_RAM_DISK_VADDR 0x47000000
#elif defined(BOARD_odroidc4)
#define GUEST_DTB_VADDR 0x25f10000
#define GUEST_INIT_RAM_DISK_VADDR 0x24000000
#else
#error Need to define guest kernel image address and DTB address
#endif
Expand All @@ -43,7 +46,7 @@ extern char _guest_initrd_image_end[];
/* Microkit will set this variable to the start of the guest RAM memory region. */
uintptr_t guest_ram_vaddr;

#define MAX_IRQ_CH 63
#define MAX_IRQ_CH 64
int passthrough_irq_map[MAX_IRQ_CH];

static void dummy_ack(size_t vcpu_id, int irq, void *cookie) {
Expand All @@ -67,6 +70,13 @@ static void register_passthrough_irq(int irq, microkit_channel irq_ch) {
}
}

static int get_passthrough_irq(microkit_channel irq_ch) {
if (passthrough_irq_map[irq_ch] != -1) {
return passthrough_irq_map[irq_ch];
}
return -1;
}

/* sDDF block */
typedef struct {
int irq;
Expand Down Expand Up @@ -133,27 +143,45 @@ void init(void) {
return;
}

/* Initialise passthrough IRQ map */
for (int i = 0; i < MAX_IRQ_CH; i++) {
passthrough_irq_map[i] = -1;
}

/* Register UIO irq */
for (int i = 0; i < NUM_UIO_DEVICE; i++) {
virq_register(GUEST_VCPU_ID, uio_devices[i].irq, &uio_ack, NULL);
}

#if defined(BOARD_odroidc4)
// SD
register_passthrough_irq(222, 1);
// // eMMC
// register_passthrough_irq(223, 2);
#endif

/* Finally start the guest */
guest_start(GUEST_VCPU_ID, kernel_pc, GUEST_DTB_VADDR, GUEST_INIT_RAM_DISK_VADDR);
}

void notified(microkit_channel ch) {
int irq;

/* Handle notifications from clients of block device */
int irq = get_uio_irq_from_ch(ch);
irq = get_uio_irq_from_ch(ch);
if (irq != -1) {
virq_inject(GUEST_VCPU_ID, irq);
return;
}

switch (ch) {
default:
LOG_VMM_ERR("Unexpected channel, ch: 0x%lx\n", ch);
/* Handle passthrough IRQs */
irq = get_passthrough_irq(ch);
if (irq != -1) {
virq_inject(GUEST_VCPU_ID, irq);
return;
}

LOG_VMM_ERR("Unexpected channel, ch: 0x%lx\n", ch);
}

/*
Expand Down
42 changes: 42 additions & 0 deletions examples/virtio/board/odroidc4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# QEMU ARM virt images

## Linux kernel

### Details
* Image name: `linux`
* Config name: `linux_config`
* Git remote: https://github.com/torvalds/linux.git
* Tag: v5.18 (commit hash: `4b0986a3613c92f4ec1bdc7f60ec66fea135991f`)
* Toolchain: `aarch64-none-elf`
* Version: GNU Toolchain for the A-profile Architecture 10.2-2020.11 (arm-10.16)) 10.2.1 20201103

You can also get the Linux config used after booting by running the following
command in userspace: `zcat /proc/config.gz`.

### Instructions for reproducing
```
git clone --depth 1 --branch v5.18 https://github.com/torvalds/linux.git
cp linux_config linux/.config
make -C linux ARCH=arm64 CROSS_COMPILE=aarch64-none-elf- all -j$(nproc)
```

The path to the image is: `linux/arch/arm64/boot/Image`.

## Buildroot RootFS image

### Details
* Image name: `rootfs.cpio.gz`
* Config name: `buildroot_config`
* Version: 2022.08-rc2

### Instructions for reproducing

```
wget https://buildroot.org/downloads/buildroot-2022.08-rc2.tar.xz
tar xvf buildroot-2022.08-rc2.tar.xz
cp buildroot_config buildroot-2022.08-rc2/.config
make -C buildroot-2022.08-rc2
```

The root filesystem will be located at: `buildroot-2022.08-rc2/output/images/rootfs.cpio.gz` along
with the other buildroot artefacts.
Loading

0 comments on commit 6f42997

Please sign in to comment.