From f8ddc899f7d5da3c32cad6e4ab720534a509ff47 Mon Sep 17 00:00:00 2001 From: Kaloyan Nikolov Date: Thu, 9 May 2024 13:20:20 +0300 Subject: [PATCH 1/2] Update Dockerfile Added python3-venv as per QEMU requirements, add parameters for CPU count and memory amount as environment variables. --- Dockerfile | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7b78d62..fd2b4c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ EXPOSE 2222 # Install all needed packages RUN apt-get update && \ -apt-get install -y --no-install-recommends ca-certificates git wget build-essential ninja-build libglib2.0-dev libpixman-1-dev u-boot-qemu unzip libslirp-dev && \ +apt-get install -y --no-install-recommends ca-certificates git wget build-essential ninja-build libglib2.0-dev libpixman-1-dev u-boot-qemu unzip libslirp-dev python3-venv && \ # clean up the temp files apt-get autoremove -y && \ apt-get clean && \ @@ -18,9 +18,16 @@ mkdir /root/qemu/build && cd /root/qemu/build && \ # clean up the git repo and build artifacts after installed rm /root/qemu -r +#Add QEMU CPU and Memory params as env variables to allow a bit more customisation +ARG QM_RAM +ENV QM_RAM=2G + +ARG QM_CPU +ENV QM_CPU=2 + # Get RISC-V Debian image WORKDIR "/root" RUN wget https://gitlab.com/api/v4/projects/giomasce%2Fdqib/jobs/artifacts/master/download?job=convert_riscv64-virt -O artifacts.zip && \ unzip artifacts.zip && rm artifacts.zip -CMD qemu-system-riscv64 -smp 2 -m 2G -cpu rv64 -nographic -machine virt -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-blk-device,drive=hd -drive file=dqib_riscv64-virt/image.qcow2,if=none,id=hd -device virtio-net-device,netdev=net -netdev user,id=net,hostfwd=tcp::2222-:22 -object rng-random,filename=/dev/urandom,id=rng -device virtio-rng-device,rng=rng -append "root=LABEL=rootfs console=ttyS0" +CMD qemu-system-riscv64 -smp ${QM_CPU} -m ${QM_RAM} -cpu rv64 -nographic -machine virt -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-blk-device,drive=hd -drive file=dqib_riscv64-virt/image.qcow2,if=none,id=hd -device virtio-net-device,netdev=net -netdev user,id=net,hostfwd=tcp::2222-:22 -object rng-random,filename=/dev/urandom,id=rng -device virtio-rng-device,rng=rng -append "root=LABEL=rootfs console=ttyS0" From 5c98ba761812a32458756be8a5ac4b283c89a724 Mon Sep 17 00:00:00 2001 From: Kaloyan Nikolov Date: Thu, 9 May 2024 13:27:30 +0300 Subject: [PATCH 2/2] Update README.md Add the new environment variables to the Readme file. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 310a96d..1fef847 100644 --- a/README.md +++ b/README.md @@ -43,10 +43,10 @@ ssh root@localhost -p 2222 ```bash # 2. Alternative: Allocate more CPU / RAM to QEMU guest -# Start the container, and manually start QEMU with the required specs. -# replace AAAA with desired cpus (e.g. 2 or 4) -# replace BBBB with desired RAM (e.g. 2G or 4G) -docker run -d --publish 127.0.0.1:2222:2222/tcp davidburela/riscv-emulator qemu-system-riscv64 -smp AAAA -m BBBB -cpu rv64 -nographic -machine virt -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-blk-device,drive=hd -drive file=dqib_riscv64-virt/image.qcow2,if=none,id=hd -device virtio-net-device,netdev=net -netdev user,id=net,hostfwd=tcp::2222-:22 -object rng-random,filename=/dev/urandom,id=rng -device virtio-rng-device,rng=rng -append "root=LABEL=rootfs console=ttyS0" +# Amount of memory and CPU count are available as docker variables. +# QM_CPU=X where X is the number of CPUs to be added. +# QM_RAM=Y where Y is the amount of memory, i.e. 4G means 4 gigabytes of RAM. +docker run -d --publish 127.0.0.1:2222:2222/tcp -e QM_CPU=4 -e QM_RAM=4G davidburela/riscv-emulator ``` ### Podman