From bbed4f50fd6b19a581315371aea41ccf872548f6 Mon Sep 17 00:00:00 2001 From: Alex Mikhalevich <2990126+alexmikhalevich@users.noreply.github.com> Date: Fri, 19 Jan 2024 19:34:13 -0300 Subject: [PATCH] feat: add possibility to build hypervisor host & guest filesystems --- .gitignore | 1 + CHANGELOG.md | 1 + Makefile | 29 +++++++--- fs/rootfs-hv-guest.Dockerfile | 35 +++++++++++ fs/rootfs-hv-host.Dockerfile | 86 ++++++++++++++++++++++++++++ fs/{Dockerfile => rootfs.Dockerfile} | 0 6 files changed, 145 insertions(+), 7 deletions(-) create mode 100644 fs/rootfs-hv-guest.Dockerfile create mode 100644 fs/rootfs-hv-host.Dockerfile rename fs/{Dockerfile => rootfs.Dockerfile} (100%) diff --git a/.gitignore b/.gitignore index e5e72fef..9e8e537c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ control machine-emulator-tools-*.tar.gz machine-emulator-tools-*.deb rootfs.* +!rootfs.Dockerfile # Prerequisites *.d diff --git a/CHANGELOG.md b/CHANGELOG.md index 52817753..d4ed1f79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +- Add possibility to build hypervisor host and guest filesystems ## [0.14.1] - 2023-12-18 ### Fixed diff --git a/Makefile b/Makefile index 7b1ea40c..15a608c8 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,8 @@ VERSION := $(MAJOR).$(MINOR).$(PATCH)$(LABEL) TOOLS_DEB := machine-emulator-tools-v$(VERSION).deb TOOLS_IMAGE := cartesi/machine-emulator-tools:$(VERSION) TOOLS_ROOTFS := rootfs-tools-v$(VERSION).ext2 +TOOLS_HV_HOST_ROOTFS := rootfs-hv-host-tools-v$(VERSION).ext2 +TOOLS_HV_GUEST_ROOTFS := rootfs-hv-guest-tools-v$(VERSION).ext2 IMAGE_KERNEL_VERSION ?= v0.19.1 LINUX_VERSION ?= 6.5.9-ctsi-1 @@ -51,16 +53,29 @@ $(TOOLS_DEB) deb: build control: Makefile control.template @sed 's|ARG_VERSION|$(VERSION)|g' control.template > control +define get_dockerfile_name +$(firstword $(subst -tools-v$(VERSION), ,$(1))).Dockerfile +endef -$(TOOLS_ROOTFS) fs: $(TOOLS_DEB) +%.tar: $(TOOLS_DEB) @docker buildx build --platform=linux/riscv64 \ + --progress=plain \ + --no-cache \ --build-arg TOOLS_DEB=$(TOOLS_DEB) \ - --output type=tar,dest=rootfs.tar \ - --file fs/Dockerfile \ - . && \ - bsdtar -cf rootfs.gnutar --format=gnutar @rootfs.tar && \ - xgenext2fs -fzB 4096 -b 25600 -i 4096 -a rootfs.gnutar -L rootfs $(TOOLS_ROOTFS) && \ - rm -f rootfs.gnutar rootfs.tar + --output type=tar,dest=$@ \ + --file fs/$(call get_dockerfile_name,$*) . + +%.gnutar: %.tar + bsdtar -cf $@ --format=gnutar @$< + +%.ext2: %.gnutar + xgenext2fs -fzB 4096 -b 25600 -i 4096 -a $< -L $* $@ + +fs: $(TOOLS_ROOTFS) + +hv-guest-fs: $(TOOLS_HV_GUEST_ROOTFS) +hv-host-fs: $(TOOLS_HV_HOST_ROOTFS) +hv-fs: hv-guest-fs hv-host-fs env: @echo TOOLS_DEB=$(TOOLS_DEB) diff --git a/fs/rootfs-hv-guest.Dockerfile b/fs/rootfs-hv-guest.Dockerfile new file mode 100644 index 00000000..65cad8e5 --- /dev/null +++ b/fs/rootfs-hv-guest.Dockerfile @@ -0,0 +1,35 @@ +FROM --platform=linux/riscv64 riscv64/ubuntu:22.04 +ARG TOOLS_DEB=machine-emulator-tools-v0.14.0.deb + +RUN < /etc/hostname diff --git a/fs/rootfs-hv-host.Dockerfile b/fs/rootfs-hv-host.Dockerfile new file mode 100644 index 00000000..08b238f8 --- /dev/null +++ b/fs/rootfs-hv-host.Dockerfile @@ -0,0 +1,86 @@ +FROM --platform=$BUILDPLATFORM ubuntu:22.04 as cross-builder +ENV BUILD_BASE=/tmp/build-extra +ENV LIBFDT_DIR=${BUILD_BASE}/dtc +ENV LKVM_DIR=${BUILD_BASE}/kvmtool +ENV CROSS_COMPILE=/usr/bin/riscv64-linux-gnu- + +# Install dependencies +RUN DEBIAN_FRONTEND=noninteractive apt-get update && \ + apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + wget \ + crossbuild-essential-riscv64 \ + gcc-12-riscv64-linux-gnu \ + git \ + pkg-config \ + flex \ + bison \ + && \ + adduser developer -u 499 --gecos ",,," --disabled-password && \ + mkdir -p ${BUILD_BASE} && chown -R developer:developer ${BUILD_BASE} && \ + rm -rf /var/lib/apt/lists/* + +USER developer +WORKDIR ${BUILD_BASE} + +# Build benchmark binaries +COPY fs/dhrystone.patch ${BUILD_BASE}/ +COPY fs/shasumfile ${BUILD_BASE}/ +RUN mkdir benchmarks && cd benchmarks && \ + wget https://www.netlib.org/benchmark/whetstone.c https://www.netlib.org/benchmark/dhry-c && \ + shasum -ca 256 ../shasumfile &&\ + bash dhry-c && \ + patch -p1 < ../dhrystone.patch && \ + riscv64-linux-gnu-gcc-12 -O2 -o whetstone whetstone.c -lm && \ + riscv64-linux-gnu-gcc-12 -O2 -o dhrystone dhry_1.c dhry_2.c -lm + +# Build libfdt +RUN <