-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
CARTESI_MACHINE=lua ../cartesi-machine.lua | ||
|
||
all: host-rootfs.ext2 guest-rootfs.ext2 | ||
|
||
%.ext2: %.gnutar | ||
genext2fs --faketime --block-size 4096 --readjustment +0 --tarball $< $@ | ||
|
||
%.gnutar: %.tar | ||
bsdtar -cf $@ --format=gnutar @$< | ||
|
||
host-rootfs.tar: host-rootfs.Dockerfile guest-linux.bin lkvm-test.sh | ||
%.tar: %.Dockerfile | ||
docker build --platform=linux/riscv64 --file $< --output type=tar,dest=$@ --progress plain . | ||
|
||
clean: | ||
rm -f *.ext2 *.tar *.gnutar | ||
|
||
shell: | ||
$(CARTESI_MACHINE) \ | ||
--ram-image=host-linux.bin \ | ||
--flash-drive=label:root,filename:host-rootfs.ext2 \ | ||
--flash-drive=label:guest-root,filename:guest-rootfs.ext2 \ | ||
--ram-length=1024Mi \ | ||
-i bash | ||
|
||
test: | ||
$(CARTESI_MACHINE) \ | ||
--ram-image=host-linux.bin \ | ||
--flash-drive=label:root,filename:host-rootfs.ext2 \ | ||
--flash-drive=label:guest-root,filename:guest-rootfs.ext2 \ | ||
--ram-length=1024Mi \ | ||
/root/lkvm-test.sh | ||
|
||
.PHONY: clean shell test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# syntax=docker.io/docker/dockerfile:1.4 | ||
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 | ||
|
||
# Update system | ||
RUN <<EOF | ||
apt-get update | ||
apt-get upgrade -y | ||
EOF | ||
|
||
# Install busybox | ||
RUN <<EOF | ||
apt-get install -y busybox-static | ||
EOF | ||
|
||
# Install emulator tools | ||
RUN <<EOF | ||
apt-get install -y wget | ||
wget -O machine-emulator-tools.deb https://github.com/cartesi/machine-emulator-tools/releases/download/v0.12.0/machine-emulator-tools-v0.12.0.deb | ||
dpkg -i machine-emulator-tools.deb | ||
rm -f machine-emulator-tools.deb | ||
EOF | ||
|
||
# Make build more or less reproducible | ||
RUN <<EOF | ||
rm -rf /var/lib/apt/lists/* | ||
rm -rf /var/log/* | ||
EOF | ||
|
||
# Hack to disable auto mounting | ||
RUN rm -rf /mnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# syntax=docker.io/docker/dockerfile:1.4 | ||
FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 | ||
|
||
# Update system | ||
RUN <<EOF | ||
apt-get update | ||
apt-get upgrade -y | ||
EOF | ||
|
||
# Install busybox | ||
RUN <<EOF | ||
apt-get install -y busybox-static | ||
EOF | ||
|
||
# Install emulator tools | ||
RUN <<EOF | ||
apt-get install -y wget | ||
wget -O machine-emulator-tools.deb https://github.com/cartesi/machine-emulator-tools/releases/download/v0.12.0/machine-emulator-tools-v0.12.0.deb | ||
dpkg -i machine-emulator-tools.deb | ||
rm -f machine-emulator-tools.deb | ||
EOF | ||
|
||
# Install build tools | ||
RUN <<EOF | ||
apt-get install -y build-essential git | ||
EOF | ||
|
||
# Install debugging utilities | ||
RUN <<EOF | ||
apt-get install -y gdb strace | ||
EOF | ||
|
||
WORKDIR /root | ||
|
||
# Install kvmtool | ||
RUN <<EOF | ||
apt-get install -y libfdt-dev kmod | ||
git clone https://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git | ||
EOF | ||
COPY kvmtool-net-exit.patch . | ||
RUN <<EOF | ||
cd kvmtool | ||
patch -Np1 < ../kvmtool-net-exit.patch | ||
make lkvm-static | ||
install lkvm-static /usr/bin/lkvm | ||
EOF | ||
|
||
# Make build more or less reproducible | ||
RUN <<EOF | ||
rm -rf /var/lib/apt/lists/* | ||
rm -rf /var/log/* | ||
EOF | ||
|
||
# Hack to disable auto mounting | ||
RUN rm -rf /mnt | ||
|
||
# Copy guest linux and rootfs | ||
COPY guest-linux.bin /root | ||
|
||
COPY kvm.ko /root | ||
COPY --chmod=755 lkvm-test.sh /root | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
diff --git a/virtio/net.c b/virtio/net.c | ||
index f09dd0a..4e559cc 100644 | ||
--- a/virtio/net.c | ||
+++ b/virtio/net.c | ||
@@ -971,6 +971,7 @@ int virtio_net__exit(struct kvm *kvm) | ||
virtio_net_exec_script(params->downscript, ndev->tap_name); | ||
|
||
list_del(&ndev->list); | ||
+ ndev->vdev.ops->exit(kvm, &ndev->vdev); | ||
free(ndev); | ||
} | ||
return 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
set -e | ||
insmod kvm.ko | ||
|
||
while true; do | ||
lkvm run \ | ||
--network virtio \ | ||
--disk /dev/mtdblock1 \ | ||
--kernel guest-linux.bin \ | ||
--virtio-transport mmio \ | ||
--params "\ | ||
init=/opt/cartesi/bin/init loglevel=5 splash=no single=yes \ | ||
-- \ | ||
busybox ip link set dev eth0 up && | ||
echo booted" | ||
done |