From 970f97cba2d5f2eb04e8baabba4826782e7a4887 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 29 Oct 2024 15:18:58 -0700 Subject: [PATCH 01/18] resources: add scripts to make and extract arm kernel --- .../files/arm/gem5_init.sh | 17 +++++++++ .../http/arm-24-04/user-data | 2 +- .../packer-scripts/arm-ubuntu.pkr.hcl | 7 +++- .../scripts/post-installation.sh | 38 +++++++++++++++---- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh index 0c13e97ad..65c041190 100755 --- a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh @@ -15,6 +15,23 @@ mount -t sysfs /sys /sys cmdline=$(cat /proc/cmdline) no_systemd=false +# Load gem5_bridge driver +## Default parameters (ARM64) +gem5_bridge_baseaddr=0x10010000 +gem5_bridge_rangesize=0x10000 +## Try to read overloads from kernel arguments +if [[ $cmdline =~ gem5_bridge_baseaddr=([[:alnum:]]+) ]]; then + gem5_bridge_baseaddr=${BASH_REMATCH[1]} +fi +if [[ $cmdline =~ gem5_bridge_rangesize=([[:alnum:]]+) ]]; then + gem5_bridge_rangesize=${BASH_REMATCH[1]} +fi +## Insert driver +modprobe gem5_bridge \ + gem5_bridge_baseaddr=$gem5_bridge_baseaddr \ + gem5_bridge_rangesize=$gem5_bridge_rangesize + + # gem5-bridge exit signifying that kernel is booted # This will cause the simulation to exit. Note that this will # cause qemu to fail. diff --git a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data index 895062bbb..64b02c3c2 100644 --- a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data +++ b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data @@ -62,7 +62,7 @@ autoinstall: type: format id: format-0 - device: disk-vda - size: 4257218560 + size: 40726691840 wipe: superblock flag: '' number: 2 diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 6e81dd5e6..7b89c6308 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -92,7 +92,7 @@ source "qemu" "initialize" { "" ] cpus = "4" - disk_size = "4600" + disk_size = "42000" format = "raw" headless = "true" http_directory = local.iso_data[var.ubuntu_version].http_directory @@ -139,4 +139,9 @@ build { environment_vars = ["ISA=arm64"] expect_disconnect = true } + provisioner "file" { + source = "/home/gem5/my-arm-kernel/linux-6.8.0/vmlinux" + destination = "./arm-disk-image-24-04/vmlinux" + direction = "download" + } } diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 7d29bc153..7aef48a60 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -18,12 +18,26 @@ apt-get install -y build-essential echo "Installing serial service for autologin after systemd" mv /home/gem5/serial-getty@.service /lib/systemd/system/ -# Make sure the headers are installed to extract the kernel that DKMS -# packages will be built against. -sudo apt -y install "linux-headers-$(uname -r)" "linux-modules-extra-$(uname -r)" - -echo "Extracting linux kernel $(uname -r) to /home/gem5/vmlinux-x86-ubuntu" -sudo bash -c "/usr/src/linux-headers-$(uname -r)/scripts/extract-vmlinux /boot/vmlinuz-$(uname -r) > /home/gem5/vmlinux-x86-ubuntu" +apt-get update +apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge +# Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list +sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources + +apt update + +apt-get -y build-dep linux +apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev +apt-get -y install libssl-dev +apt -y install flex bison +apt -y install zstd + +mkdir my-arm-kernel +cd my-arm-kernel +apt source linux-image-unsigned-$(uname -r) +cd linux-6.8.0 +cp /boot/config-$(uname -r) .config +make olddefconfig +make -j$(nproc) echo "Installing the gem5 init script in /sbin" mv /home/gem5/gem5_init.sh /sbin @@ -47,14 +61,15 @@ if [ -z "$ISA" ]; then fi # Just get the files we need -git clone https://github.com/gem5/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=stable +git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge pushd gem5 # Checkout just the files we need git sparse-checkout add util/m5 +git sparse-checkout add util/gem5_bridge git sparse-checkout add include git checkout # Install the headers globally so that other benchmarks can use them -cp -r include/gem5 /usr/local/include/\ +cp -r include/gem5 /usr/local/include/ # Build the library and binary pushd util/m5 @@ -62,6 +77,13 @@ scons build/${ISA}/out/m5 cp build/${ISA}/out/m5 /usr/local/bin/ cp build/${ISA}/out/libm5.a /usr/local/lib/ popd # util/m5 + +# Build and insert the gem5-bridge driver +pushd util/gem5_bridge +make build install +depmod --quick +popd + popd # gem5 # rename the m5 binary to gem5-bridge From c85807ebac4cf39b8f25d6f2f671660e10b068a9 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 4 Nov 2024 15:56:39 -0800 Subject: [PATCH 02/18] resources: update scripts to build the kernel --- src/ubuntu-generic-diskimages/files/arm/gem5_init.sh | 2 ++ .../scripts/post-installation.sh | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh index 65c041190..cf05f64c7 100755 --- a/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh +++ b/src/ubuntu-generic-diskimages/files/arm/gem5_init.sh @@ -31,6 +31,8 @@ modprobe gem5_bridge \ gem5_bridge_baseaddr=$gem5_bridge_baseaddr \ gem5_bridge_rangesize=$gem5_bridge_rangesize +# see if this modprode fails or not +# print warning if it fails, gem5-bridge module is not going to work, you will need sudo for running exit events # gem5-bridge exit signifying that kernel is booted # This will cause the simulation to exit. Note that this will diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 7aef48a60..41e379b5f 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -36,8 +36,13 @@ cd my-arm-kernel apt source linux-image-unsigned-$(uname -r) cd linux-6.8.0 cp /boot/config-$(uname -r) .config -make olddefconfig -make -j$(nproc) +make -j$(nproc) vmlinux + +chmod +x ./debian/scripts/sign-module +make -j$(nproc) modules +make -j modules_install + +update-initramfs -u -k 6.8.12 echo "Installing the gem5 init script in /sbin" mv /home/gem5/gem5_init.sh /sbin From 22d3fe27a0a44a6fefb20144d2068b6d5b77a124 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 4 Nov 2024 16:00:38 -0800 Subject: [PATCH 03/18] resources: update disk size to 50gb --- src/ubuntu-generic-diskimages/http/arm-24-04/user-data | 2 +- src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data index 64b02c3c2..b368a4724 100644 --- a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data +++ b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data @@ -62,7 +62,7 @@ autoinstall: type: format id: format-0 - device: disk-vda - size: 40726691840 + size: 50726691840 wipe: superblock flag: '' number: 2 diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 7b89c6308..4cd639023 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -92,7 +92,7 @@ source "qemu" "initialize" { "" ] cpus = "4" - disk_size = "42000" + disk_size = "52000" format = "raw" headless = "true" http_directory = local.iso_data[var.ubuntu_version].http_directory From d8d4d3cd1fa74dfcc509f56a0def96baa550ca12 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 20 Nov 2024 15:21:44 -0800 Subject: [PATCH 04/18] resources: Update building kernel and modules on host --- .../24.04-dockerfile/Dockerfile | 21 ++++ .../make-kernel-and-gem5-bridge-driver.md | 108 ++++++++++++++++++ .../packer-scripts/arm-ubuntu.pkr.hcl | 11 +- .../scripts/post-installation.sh | 53 +++++---- 4 files changed, 165 insertions(+), 28 deletions(-) create mode 100644 src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile create mode 100644 src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md diff --git a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile new file mode 100644 index 000000000..23dbb7765 --- /dev/null +++ b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile @@ -0,0 +1,21 @@ +# Start from Ubuntu 24.04 base image +FROM ubuntu:24.04 + +# Install necessary packages for kernel and module build +RUN apt update && apt install -y \ + build-essential \ + libncurses-dev \ + bison \ + flex \ + libssl-dev \ + libelf-dev \ + bc \ + wget \ + git \ + kmod + +# Set the default working directory +WORKDIR /workspace + +# Use bash as the default shell +CMD ["/bin/bash"] diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md new file mode 100644 index 000000000..7dfce3b29 --- /dev/null +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -0,0 +1,108 @@ +# Make kernel and the gem5 bridge driver + +This document will highlight the steps needed to make a kernel and its modules with the gem5-bridge driver. + +## Ubuntu 24.04 disk image + +Assuming you are in the `src/ubuntu-generic-diskiamges` directory. +`cd` to the `24.04-dockerfile` directory and build the docker image. + +```bash +cd 24.04-dockerfile +docker build -t ubuntu-kernel-build . +cd .. +``` + +Then lets make a new directory called `my-arm-6.8.12-kernel`. +This directory will have the kernel source and the modules of our built kernel. + +```bash +mkdir my-arm-6.8.12-kernel +``` + +lets get the kernel source from `apt source`, we will be making the `6.8.12 96.8.0-47-generic)` kernel. + +```bash +cd my-arm-6.8.12-kernel +apt source linux-image-unsigned-6.8.0-47-generic +``` + +You might need to update ubuntu source list to use the above command. +Checkout this post if you need to update: + +Lets make an output directory that will have our built modules + +```bash +mkdir output +``` + +Lets run the docker image from the `my-arm-6.8.12-kernel` directory. + +```bash +docker run --rm -it -u $UID:$GID -v ./linux-6.8.0:/workspace/source -v ./output:/workspace/output --name kernel-builder ubuntu-kernel-build +``` + +Now in the docker terminal, lets build the kernel + +```bash +cd source +make defconfig +make -j$nproc +``` + +The above commands will make the kernel and the modules. +lets install the modules to the output directory + +```bash +make INSTALL_MOD_PATH=/workspace/output modules_install +``` + +After the modules are installed, lets install our gem5-bridge driver. + +in the `/workspace/source`, lets get the driver files + +```bash +git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge +cd gem5 +git sparse-checkout add util/m5 +git sparse-checkout add util/gem5_bridge +git sparse-checkout add include +git checkout +``` +Now lets make our driver + +```bash +cd util/gem5_bridge +make KMAKEDIR=/workspace/source INSTALL_MOD_PATH=/workspace/output build install +``` + +The above command specifies the kernel source path and the output path. +You can find the kernel at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/linux-6.8.0/vmlinux` +and the modules at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12`. + +Now lets move the modules to our disk image. + +First you will need to delete the `build` file in `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12` as that is a symlink to the `/workspace` directory in source + +```bash +rm output/lib/modules/6.8.12/build +``` + +now add the following file provisioner to move the files from host to the disk + +```hcl + provisioner "file" { + destination= "/home/gem5" + source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" + } +``` + +also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs` + +```bash +mv /home/gem5/6.8.12 /lib/modules/6.8.12 +depmod --quick -a 6.8.12 +update-initramfs -u -k 6.8.12 +``` + +Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver. diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 4cd639023..28e201dbc 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -133,15 +133,16 @@ build { source = "files/serial-getty@.service" } + provisioner "file" { + destination= "/home/gem5" + source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" + } + provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/post-installation.sh"] environment_vars = ["ISA=arm64"] expect_disconnect = true } - provisioner "file" { - source = "/home/gem5/my-arm-kernel/linux-6.8.0/vmlinux" - destination = "./arm-disk-image-24-04/vmlinux" - direction = "download" - } + } diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 41e379b5f..91f2db1c8 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -18,29 +18,33 @@ apt-get install -y build-essential echo "Installing serial service for autologin after systemd" mv /home/gem5/serial-getty@.service /lib/systemd/system/ -apt-get update -apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge -# Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list -sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources +# apt-get update +# apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge +# # Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list +# sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources + +# apt update + +# apt-get -y build-dep linux +# apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev +# apt-get -y install libssl-dev +# apt -y install flex bison +# apt -y install zstd -apt update +# mkdir my-arm-kernel +# cd my-arm-kernel +# apt source linux-image-unsigned-6.8.0-47-generic +# cd linux-6.8.0 +# cp /boot/config-$(uname -r) .config +# make -j$(nproc) vmlinux -apt-get -y build-dep linux -apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev -apt-get -y install libssl-dev -apt -y install flex bison -apt -y install zstd +# chmod +x ./debian/scripts/sign-module +# make -j$(nproc) modules +# make -j modules_install -mkdir my-arm-kernel -cd my-arm-kernel -apt source linux-image-unsigned-$(uname -r) -cd linux-6.8.0 -cp /boot/config-$(uname -r) .config -make -j$(nproc) vmlinux +mv /home/gem5/6.8.12 /lib/modules/6.8.12 -chmod +x ./debian/scripts/sign-module -make -j$(nproc) modules -make -j modules_install +depmod --quick -a 6.8.12 update-initramfs -u -k 6.8.12 @@ -84,10 +88,11 @@ cp build/${ISA}/out/libm5.a /usr/local/lib/ popd # util/m5 # Build and insert the gem5-bridge driver -pushd util/gem5_bridge -make build install -depmod --quick -popd +# pushd util/gem5_bridge +# make build install + + +# popd popd # gem5 @@ -121,3 +126,5 @@ systemctl disable systemd-networkd-wait-online.service systemctl mask systemd-networkd-wait-online.service echo "Post Installation Done" + +sleep 10m \ No newline at end of file From d9573fb6a4a83ed6c8549432a5fd20e9096020b2 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 20 Nov 2024 15:42:12 -0800 Subject: [PATCH 05/18] resources: clean up post install script --- .../scripts/post-installation.sh | 32 ------------------- 1 file changed, 32 deletions(-) diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 91f2db1c8..2f57c704e 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -18,30 +18,6 @@ apt-get install -y build-essential echo "Installing serial service for autologin after systemd" mv /home/gem5/serial-getty@.service /lib/systemd/system/ -# apt-get update -# apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge -# # Fixing the sources.list file to include deb-src: https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list -# sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources - -# apt update - -# apt-get -y build-dep linux -# apt-get -y install git-core libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev -# apt-get -y install libssl-dev -# apt -y install flex bison -# apt -y install zstd - -# mkdir my-arm-kernel -# cd my-arm-kernel -# apt source linux-image-unsigned-6.8.0-47-generic -# cd linux-6.8.0 -# cp /boot/config-$(uname -r) .config -# make -j$(nproc) vmlinux - -# chmod +x ./debian/scripts/sign-module -# make -j$(nproc) modules -# make -j modules_install - mv /home/gem5/6.8.12 /lib/modules/6.8.12 depmod --quick -a 6.8.12 @@ -86,14 +62,6 @@ scons build/${ISA}/out/m5 cp build/${ISA}/out/m5 /usr/local/bin/ cp build/${ISA}/out/libm5.a /usr/local/lib/ popd # util/m5 - -# Build and insert the gem5-bridge driver -# pushd util/gem5_bridge -# make build install - - -# popd - popd # gem5 # rename the m5 binary to gem5-bridge From c4ace1d0631ed1c18b6dac786547818be5911845 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Fri, 22 Nov 2024 14:02:49 -0800 Subject: [PATCH 06/18] resources: add docker files to make kernel for ubuntu 22.04 image --- .../22.04-dockerfile/Dockerfile | 48 ++++++++++++ .../make-kernel-and-gem5-bridge-driver.md | 76 +++++++++++++++++++ .../packer-scripts/arm-ubuntu.pkr.hcl | 10 ++- .../scripts/post-installation.sh | 11 ++- 4 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile diff --git a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile new file mode 100644 index 000000000..1e2f6eb8a --- /dev/null +++ b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile @@ -0,0 +1,48 @@ +FROM ubuntu:22.04 + +# Install necessary packages for kernel build +RUN apt update && apt install -y \ + build-essential \ + libncurses-dev \ + bison \ + flex \ + libssl-dev \ + libelf-dev \ + bc \ + wget \ + git \ + kmod \ + apt-src \ + vim \ + curl \ + file + +RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list +RUN apt update +RUN mkdir /workspace +RUN cd /workspace && apt source linux-image-unsigned-5.15.0-25-generic +RUN chmod -R u+rwx /workspace/linux-5.15.0 +RUN cd /workspace/linux-5.15.0 && \ + chmod a+x debian/rules && \ + chmod a+x debian/scripts/* && \ + chmod a+x debian/scripts/misc/* && \ + chmod -R +x scripts/ + +RUN cd /workspace/linux-5.15.0 && \ + make defconfig && \ + make -j 32 && \ + make INSTALL_MOD_PATH=/workspace/output modules_install + +RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ + cd gem5 && \ + git sparse-checkout add util/m5 && \ + git sparse-checkout add util/gem5_bridge && \ + git sparse-checkout add include && \ + git checkout + +RUN cd gem5/util/gem5_bridge && \ + make KMAKEDIR=/workspace/linux-5.15.0 INSTALL_MOD_PATH=/workspace/output build install + # Set working directory +WORKDIR /workspace + +CMD ["/bin/bash"] diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index 7dfce3b29..66f5e534b 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -46,6 +46,9 @@ Now in the docker terminal, lets build the kernel ```bash cd source +chmod a+x debian/rules +chmod a+x debian/scripts/* +chmod a+x debian/scripts/misc/* make defconfig make -j$nproc ``` @@ -106,3 +109,76 @@ update-initramfs -u -k 6.8.12 ``` Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver. + +## Unutu 22.04 disk image + +Assuming you are in the `src/ubuntu-generic-diskiamges` directory. +`cd` to the `22.04-dockerfile` directory and build the docker image. + +```bash +cd 22.04-dockerfile +docker build -t ubuntu-22.04-kernel-build . +cd .. +``` + +Then lets make a new directory called `my-arm-5.15.167-kernel`. +This directory will have the kernel source and the modules of our built kernel. + +```bash +mkdir my-arm-5.15.167-kernel +``` + +Now lets give permissions to this diretory so that we can copy the modules and the kerenl from the docker image. + +```bash + chmod 777 my-arm-5.15.167-kernel +``` + +Lets run the docker image. + +```bash +docker run --rm -it -v ./my-arm-5.15.167-kernel:/workspace/my-arm-5.15.167-kernel --name kernel-builder ubuntu-22.04-kernel-build +``` + +Now in the docker image terminal we can copy the modules and the kernel + +```bash +cp linux-5.15.0/vmlinux my-arm-5.15.167-kernel/ +``` + +Now, before copying the modules lets remove the symlinks to `/workspace` directory of our docker image + +```bash +cd output/lib/modules/5.15.167/ +rm build +rm source +cd /workspace +cp -r ./output/lib/modules/5.15.167/ my-arm-5.15.167-kernel/ +``` + +Now we have the kernel and the modules. + +now add the following file provisioner to move the files from host to the disk + +```hcl + provisioner "file" { + destination= "/home/gem5" + source = "my-arm-5.15.167-kernel/5.15.167" + } +``` + +also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs` + +```bash +mv /home/gem5/5.15.167 /lib/modules/5.15.167 +depmod --quick -a 5.15.167 +update-initramfs -u -k 5.15.167 +``` + +Now you can build the disk image with + +```bash +./build-arm.sh 22.04 +``` + +Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver. diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 28e201dbc..2bd5de79d 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -92,7 +92,7 @@ source "qemu" "initialize" { "" ] cpus = "4" - disk_size = "52000" + disk_size = "5000" format = "raw" headless = "true" http_directory = local.iso_data[var.ubuntu_version].http_directory @@ -133,9 +133,13 @@ build { source = "files/serial-getty@.service" } + # provisioner "file" { + # destination= "/home/gem5" + # source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" + # } provisioner "file" { - destination= "/home/gem5" - source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" + source = "arm-5.15.30-kernel-modules/5.15.167" + destination = "/home/gem5" } provisioner "shell" { diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 2f57c704e..621343604 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -18,11 +18,15 @@ apt-get install -y build-essential echo "Installing serial service for autologin after systemd" mv /home/gem5/serial-getty@.service /lib/systemd/system/ -mv /home/gem5/6.8.12 /lib/modules/6.8.12 +# mv /home/gem5/6.8.12 /lib/modules/6.8.12 -depmod --quick -a 6.8.12 +# depmod --quick -a 6.8.12 -update-initramfs -u -k 6.8.12 +# update-initramfs -u -k 6.8.12 + +mv /home/gem5/5.15.167 /lib/modules/5.15.167 +depmod --quick -a 5.15.167 +update-initramfs -u -k 5.15.167 echo "Installing the gem5 init script in /sbin" mv /home/gem5/gem5_init.sh /sbin @@ -95,4 +99,3 @@ systemctl mask systemd-networkd-wait-online.service echo "Post Installation Done" -sleep 10m \ No newline at end of file From b497d6f5eff775bdcd1ae2cdc0e6d507a1b4cd98 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 25 Nov 2024 14:32:15 -0800 Subject: [PATCH 07/18] resources: Update docker files to make and kerenl and modules on build --- .../22.04-dockerfile/Dockerfile | 7 +++-- .../24.04-dockerfile/Dockerfile | 31 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile index 1e2f6eb8a..c377c789f 100644 --- a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile @@ -15,7 +15,7 @@ RUN apt update && apt install -y \ apt-src \ vim \ curl \ - file + file RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list RUN apt update @@ -42,7 +42,8 @@ RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --n RUN cd gem5/util/gem5_bridge && \ make KMAKEDIR=/workspace/linux-5.15.0 INSTALL_MOD_PATH=/workspace/output build install - # Set working directory -WORKDIR /workspace + +RUN cd /workspace/output/lib/modules/5.15.167 && \ + rm -rf build source CMD ["/bin/bash"] diff --git a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile index 23dbb7765..3fcde8f00 100644 --- a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile @@ -14,8 +14,35 @@ RUN apt update && apt install -y \ git \ kmod -# Set the default working directory -WORKDIR /workspace + +RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources +RUN apt update +RUN mkdir /workspace +RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic +RUN chmod -R u+rwx /workspace/linux-6.8.0 +RUN cd /workspace/linux-6.8.0 && \ + chmod a+x debian/rules && \ + chmod a+x debian/scripts/* && \ + chmod a+x debian/scripts/misc/* && \ + chmod -R +x scripts/ + +RUN cd /workspace/linux-6.8.0 && \ + make defconfig && \ + make -j 32 && \ + make INSTALL_MOD_PATH=/workspace/output modules_install + +RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge && \ + cd gem5 && \ + git sparse-checkout add util/m5 && \ + git sparse-checkout add util/gem5_bridge && \ + git sparse-checkout add include && \ + git checkout + +RUN cd gem5/util/gem5_bridge && \ + make KMAKEDIR=/workspace/linux-6.8.0 INSTALL_MOD_PATH=/workspace/output build install + +RUN cd /workspace/output/lib/modules/6.8.12 && \ + rm -rf build # Use bash as the default shell CMD ["/bin/bash"] From 9678f1a1983f8906364d506c00018ac68db96df0 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 25 Nov 2024 14:32:48 -0800 Subject: [PATCH 08/18] resources: Update and clean up documentation to refer to the new dockerfiles --- .../make-kernel-and-gem5-bridge-driver.md | 254 +++++++++--------- 1 file changed, 123 insertions(+), 131 deletions(-) diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index 66f5e534b..ea2e84633 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -1,184 +1,176 @@ -# Make kernel and the gem5 bridge driver -This document will highlight the steps needed to make a kernel and its modules with the gem5-bridge driver. +# Make Kernel and the gem5 Bridge Driver -## Ubuntu 24.04 disk image +This document outlines the steps to build a Linux kernel and its modules with the gem5-bridge driver for Ubuntu disk images. Below are separate instructions for Ubuntu 24.04 and Ubuntu 22.04. -Assuming you are in the `src/ubuntu-generic-diskiamges` directory. -`cd` to the `24.04-dockerfile` directory and build the docker image. +## Table of Contents -```bash -cd 24.04-dockerfile -docker build -t ubuntu-kernel-build . -cd .. -``` +- [Ubuntu 24.04 Disk Image](#ubuntu-2404-disk-image) +- [Ubuntu 22.04 Disk Image](#ubuntu-2204-disk-image) -Then lets make a new directory called `my-arm-6.8.12-kernel`. -This directory will have the kernel source and the modules of our built kernel. +## **Ubuntu 24.04 Disk Image** -```bash -mkdir my-arm-6.8.12-kernel -``` +### Build the Docker Image -lets get the kernel source from `apt source`, we will be making the `6.8.12 96.8.0-47-generic)` kernel. +- Navigate to the `24.04-dockerfile` directory and build the Docker image: -```bash -cd my-arm-6.8.12-kernel -apt source linux-image-unsigned-6.8.0-47-generic -``` + ```bash + cd src/ubuntu-generic-diskiamges/24.04-dockerfile + docker build -t ubuntu-kernel-build . + cd .. + ``` -You might need to update ubuntu source list to use the above command. -Checkout this post if you need to update: +### Build the Kernel and Modules -Lets make an output directory that will have our built modules +- Create a container from the built image: -```bash -mkdir output -``` + ```bash + docker create --name kernel-builder ubuntu-kernel-build + ``` -Lets run the docker image from the `my-arm-6.8.12-kernel` directory. +- Start the container to build the kernel: -```bash -docker run --rm -it -u $UID:$GID -v ./linux-6.8.0:/workspace/source -v ./output:/workspace/output --name kernel-builder ubuntu-kernel-build -``` + ```bash + docker start -a kernel-builder + ``` -Now in the docker terminal, lets build the kernel +- Copy the kernel and modules to the host: -```bash -cd source -chmod a+x debian/rules -chmod a+x debian/scripts/* -chmod a+x debian/scripts/misc/* -make defconfig -make -j$nproc -``` + ```bash + mkdir my-arm-6.8.12-kernel + docker cp kernel-builder:/workspace/linux-6.8.0/vmlinux my-arm-6.8.12-kernel/ + docker cp kernel-builder:/workspace/output/lib/modules/6.8.12 my-arm-6.8.12-kernel/ + ``` -The above commands will make the kernel and the modules. -lets install the modules to the output directory +- Clean up the container: -```bash -make INSTALL_MOD_PATH=/workspace/output modules_install -``` + ```bash + docker rm kernel-builder + ``` -After the modules are installed, lets install our gem5-bridge driver. +### Verify Output -in the `/workspace/source`, lets get the driver files +- Check the contents of `my-arm-6.8.12-kernel`: -```bash -git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge -cd gem5 -git sparse-checkout add util/m5 -git sparse-checkout add util/gem5_bridge -git sparse-checkout add include -git checkout -``` -Now lets make our driver + ```bash + ls my-arm-6.8.12-kernel/ + ``` -```bash -cd util/gem5_bridge -make KMAKEDIR=/workspace/source INSTALL_MOD_PATH=/workspace/output build install -``` + You should see: + - `vmlinux` — The built kernel image. + - `6.8.12/` — Directory containing the kernel modules. -The above command specifies the kernel source path and the output path. -You can find the kernel at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/linux-6.8.0/vmlinux` -and the modules at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12`. +### Add Kernel Modules to the Disk Image -Now lets move the modules to our disk image. +- Add a Packer file provisioner to copy the modules to the disk image: -First you will need to delete the `build` file in `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12` as that is a symlink to the `/workspace` directory in source + ```hcl + provisioner "file" { + destination = "/home/gem5" + source = "my-arm-6.8.12-kernel/6.8.12" + } + ``` -```bash -rm output/lib/modules/6.8.12/build -``` +- Update the post-install script to move the modules into the correct location and regenerate the initramfs: -now add the following file provisioner to move the files from host to the disk + ```bash + mv /home/gem5/6.8.12 /lib/modules/6.8.12 + depmod --quick -a 6.8.12 + update-initramfs -u -k 6.8.12 + ``` -```hcl - provisioner "file" { - destination= "/home/gem5" - source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" - } -``` +### Build the Disk Image + +- Build the disk image using your build script: + + ```bash + ./build-arm.sh 24.04 + ``` -also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs` +### Test with gem5 -```bash -mv /home/gem5/6.8.12 /lib/modules/6.8.12 -depmod --quick -a 6.8.12 -update-initramfs -u -k 6.8.12 -``` +- Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. -Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver. -## Unutu 22.04 disk image +## **Ubuntu 22.04 Disk Image** -Assuming you are in the `src/ubuntu-generic-diskiamges` directory. -`cd` to the `22.04-dockerfile` directory and build the docker image. +### Build the Docker Image -```bash -cd 22.04-dockerfile -docker build -t ubuntu-22.04-kernel-build . -cd .. -``` +- Navigate to the `22.04-dockerfile` directory and build the Docker image: -Then lets make a new directory called `my-arm-5.15.167-kernel`. -This directory will have the kernel source and the modules of our built kernel. + ```bash + cd src/ubuntu-generic-diskiamges/22.04-dockerfile + docker build -t ubuntu-22.04-kernel-build . + cd .. + ``` -```bash -mkdir my-arm-5.15.167-kernel -``` +### Build the Kernel and Modules -Now lets give permissions to this diretory so that we can copy the modules and the kerenl from the docker image. +- Create a container from the built image: -```bash - chmod 777 my-arm-5.15.167-kernel -``` + ```bash + docker create --name kernel-builder ubuntu-22.04-kernel-build + ``` -Lets run the docker image. +- Start the container to build the kernel: -```bash -docker run --rm -it -v ./my-arm-5.15.167-kernel:/workspace/my-arm-5.15.167-kernel --name kernel-builder ubuntu-22.04-kernel-build -``` + ```bash + docker start -a kernel-builder + ``` -Now in the docker image terminal we can copy the modules and the kernel +- Copy the kernel and modules to the host: -```bash -cp linux-5.15.0/vmlinux my-arm-5.15.167-kernel/ -``` + ```bash + mkdir my-arm-5.15.167-kernel + docker cp kernel-builder:/workspace/linux-5.15.0/vmlinux my-arm-5.15.167-kernel/ + docker cp kernel-builder:/workspace/output/lib/modules/5.15.167 my-arm-5.15.167-kernel/ + ``` -Now, before copying the modules lets remove the symlinks to `/workspace` directory of our docker image +- Clean up the container: -```bash -cd output/lib/modules/5.15.167/ -rm build -rm source -cd /workspace -cp -r ./output/lib/modules/5.15.167/ my-arm-5.15.167-kernel/ -``` + ```bash + docker rm kernel-builder + ``` -Now we have the kernel and the modules. +### Verify Output -now add the following file provisioner to move the files from host to the disk +- Check the contents of `my-arm-5.15.167-kernel`: -```hcl + ```bash + ls my-arm-5.15.167-kernel/ + ``` + + You should see: + - `vmlinux` — The built kernel image. + - `5.15.167/` — Directory containing the kernel modules. + +### Add Kernel Modules to the Disk Image + +- Add a Packer file provisioner to copy the modules to the disk image: + + ```hcl provisioner "file" { - destination= "/home/gem5" - source = "my-arm-5.15.167-kernel/5.15.167" + destination = "/home/gem5" + source = "my-arm-5.15.167-kernel" } -``` + ``` + +- Update the post-install script to move the modules into the correct location and regenerate the initramfs: + + ```bash + mv /home/gem5/5.15.167 /lib/modules/5.15.167 + depmod --quick -a 5.15.167 + update-initramfs -u -k 5.15.167 + ``` -also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs` +### Build the Disk Image -```bash -mv /home/gem5/5.15.167 /lib/modules/5.15.167 -depmod --quick -a 5.15.167 -update-initramfs -u -k 5.15.167 -``` +- Build the disk image using your build script: -Now you can build the disk image with + ```bash + ./build-arm.sh 22.04 + ``` -```bash -./build-arm.sh 22.04 -``` +### Test with gem5 -Now you can run a gem5 fs simulation with this disk and the kernel we just made to use the new gem 5-bridge driver. +- Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. From 6f6a870eb3e36a79540276ea70a7f5993ea64ef0 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 25 Nov 2024 14:36:50 -0800 Subject: [PATCH 09/18] resources: Update documentation --- .../make-kernel-and-gem5-bridge-driver.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index ea2e84633..fe76821e7 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -1,7 +1,9 @@ # Make Kernel and the gem5 Bridge Driver -This document outlines the steps to build a Linux kernel and its modules with the gem5-bridge driver for Ubuntu disk images. Below are separate instructions for Ubuntu 24.04 and Ubuntu 22.04. +This document outlines the steps to build a Linux kernel and its modules with the gem5-bridge driver for the ARM Ubuntu disk images. Below are separate instructions for Ubuntu 24.04 and Ubuntu 22.04. + +**Note**: These dockerfiles assume that you are running on arm host to build them. If you are not on ARM host then you would need to use a cross compiler to make the kernel and the modules. ## Table of Contents From 67d061b0dafdf8512ec713923d46045718e71cbc Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 25 Nov 2024 15:25:27 -0800 Subject: [PATCH 10/18] resources: add link to new documentation to BUILDING.md --- src/ubuntu-generic-diskimages/BUILDING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ubuntu-generic-diskimages/BUILDING.md b/src/ubuntu-generic-diskimages/BUILDING.md index 48b49352d..722095adb 100644 --- a/src/ubuntu-generic-diskimages/BUILDING.md +++ b/src/ubuntu-generic-diskimages/BUILDING.md @@ -39,6 +39,8 @@ dd if=/dev/zero of=flash0.img bs=1M count=64 dd if=/usr/share/qemu-efi-aarch64/QEMU_EFI.fd of=flash0.img conv=notrunc ``` +If you want to get the `gem5-bridge` driver and the kernel locally, please refer to the documentation [here](make-kernel-and-gem5-bridge-driver.md). + **Note**: The `build-arm.sh` will make this file for you. Note: Building the image can take a while to run. From 606cb289f0a19730efdb6119d50bc90d1685a21f Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 26 Nov 2024 11:14:51 -0800 Subject: [PATCH 11/18] resoruces: update dockerfile to remove chmod --- src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile | 6 ------ src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile | 6 ------ 2 files changed, 12 deletions(-) diff --git a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile index c377c789f..bc0d24ca5 100644 --- a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile @@ -21,12 +21,6 @@ RUN sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list RUN apt update RUN mkdir /workspace RUN cd /workspace && apt source linux-image-unsigned-5.15.0-25-generic -RUN chmod -R u+rwx /workspace/linux-5.15.0 -RUN cd /workspace/linux-5.15.0 && \ - chmod a+x debian/rules && \ - chmod a+x debian/scripts/* && \ - chmod a+x debian/scripts/misc/* && \ - chmod -R +x scripts/ RUN cd /workspace/linux-5.15.0 && \ make defconfig && \ diff --git a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile index 3fcde8f00..3793f9e95 100644 --- a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile @@ -19,12 +19,6 @@ RUN sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.s RUN apt update RUN mkdir /workspace RUN cd /workspace && apt source linux-image-unsigned-6.8.0-47-generic -RUN chmod -R u+rwx /workspace/linux-6.8.0 -RUN cd /workspace/linux-6.8.0 && \ - chmod a+x debian/rules && \ - chmod a+x debian/scripts/* && \ - chmod a+x debian/scripts/misc/* && \ - chmod -R +x scripts/ RUN cd /workspace/linux-6.8.0 && \ make defconfig && \ From 327a0b45cfad6e45f0649105263fa042b1bcb9ea Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 26 Nov 2024 11:29:45 -0800 Subject: [PATCH 12/18] resources: revert size changes --- src/ubuntu-generic-diskimages/http/arm-24-04/user-data | 2 +- src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data index b368a4724..895062bbb 100644 --- a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data +++ b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data @@ -62,7 +62,7 @@ autoinstall: type: format id: format-0 - device: disk-vda - size: 50726691840 + size: 4257218560 wipe: superblock flag: '' number: 2 diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 2bd5de79d..16c21b389 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -92,7 +92,7 @@ source "qemu" "initialize" { "" ] cpus = "4" - disk_size = "5000" + disk_size = "4600" format = "raw" headless = "true" http_directory = local.iso_data[var.ubuntu_version].http_directory From 78e7a39fe4c39b21cd2d78fab45590001b4d37ef Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 2 Dec 2024 15:46:56 -0800 Subject: [PATCH 13/18] resources: Update size of images --- .../http/arm-22-04/user-data | 2 +- .../http/arm-24-04/user-data | 2 +- .../packer-scripts/arm-ubuntu.pkr.hcl | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ubuntu-generic-diskimages/http/arm-22-04/user-data b/src/ubuntu-generic-diskimages/http/arm-22-04/user-data index b82387329..387209290 100644 --- a/src/ubuntu-generic-diskimages/http/arm-22-04/user-data +++ b/src/ubuntu-generic-diskimages/http/arm-22-04/user-data @@ -70,7 +70,7 @@ autoinstall: type: format id: format-0 - device: disk-vda - size: 4257218560 + size: 4557218560 wipe: superblock flag: '' number: 2 diff --git a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data index 895062bbb..ec9ada114 100644 --- a/src/ubuntu-generic-diskimages/http/arm-24-04/user-data +++ b/src/ubuntu-generic-diskimages/http/arm-24-04/user-data @@ -62,7 +62,7 @@ autoinstall: type: format id: format-0 - device: disk-vda - size: 4257218560 + size: 4557218560 wipe: superblock flag: '' number: 2 diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 16c21b389..45391310c 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -92,7 +92,7 @@ source "qemu" "initialize" { "" ] cpus = "4" - disk_size = "4600" + disk_size = "5000" format = "raw" headless = "true" http_directory = local.iso_data[var.ubuntu_version].http_directory @@ -133,14 +133,14 @@ build { source = "files/serial-getty@.service" } - # provisioner "file" { - # destination= "/home/gem5" - # source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" - # } - provisioner "file" { - source = "arm-5.15.30-kernel-modules/5.15.167" - destination = "/home/gem5" - } + provisioner "file" { + destination= "/home/gem5" + source = "my-arm-6.8.12-kernel/6.8.12" + } + # provisioner "file" { + # source = "arm-5.15.30-kernel-modules/5.15.167" + # destination = "/home/gem5" + # } provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" From 0f63a998e2afdda9efc349442e72a33606e9dad1 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Mon, 2 Dec 2024 15:47:42 -0800 Subject: [PATCH 14/18] resources: clean up comments --- .../packer-scripts/arm-ubuntu.pkr.hcl | 9 --------- .../scripts/post-installation.sh | 11 ----------- 2 files changed, 20 deletions(-) diff --git a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl index 45391310c..02fdea798 100644 --- a/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl +++ b/src/ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl @@ -133,15 +133,6 @@ build { source = "files/serial-getty@.service" } - provisioner "file" { - destination= "/home/gem5" - source = "my-arm-6.8.12-kernel/6.8.12" - } - # provisioner "file" { - # source = "arm-5.15.30-kernel-modules/5.15.167" - # destination = "/home/gem5" - # } - provisioner "shell" { execute_command = "echo '${var.ssh_password}' | {{ .Vars }} sudo -E -S bash '{{ .Path }}'" scripts = ["scripts/post-installation.sh"] diff --git a/src/ubuntu-generic-diskimages/scripts/post-installation.sh b/src/ubuntu-generic-diskimages/scripts/post-installation.sh index 621343604..24a0f889c 100755 --- a/src/ubuntu-generic-diskimages/scripts/post-installation.sh +++ b/src/ubuntu-generic-diskimages/scripts/post-installation.sh @@ -18,16 +18,6 @@ apt-get install -y build-essential echo "Installing serial service for autologin after systemd" mv /home/gem5/serial-getty@.service /lib/systemd/system/ -# mv /home/gem5/6.8.12 /lib/modules/6.8.12 - -# depmod --quick -a 6.8.12 - -# update-initramfs -u -k 6.8.12 - -mv /home/gem5/5.15.167 /lib/modules/5.15.167 -depmod --quick -a 5.15.167 -update-initramfs -u -k 5.15.167 - echo "Installing the gem5 init script in /sbin" mv /home/gem5/gem5_init.sh /sbin mv /sbin/init /sbin/init.old @@ -98,4 +88,3 @@ systemctl disable systemd-networkd-wait-online.service systemctl mask systemd-networkd-wait-online.service echo "Post Installation Done" - From 4624ee3c07860989e6579d490768b988169dcd79 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Wed, 4 Dec 2024 09:43:23 -0800 Subject: [PATCH 15/18] resources: update documentation --- .../make-kernel-and-gem5-bridge-driver.md | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index fe76821e7..7e9228110 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -17,7 +17,7 @@ This document outlines the steps to build a Linux kernel and its modules with th - Navigate to the `24.04-dockerfile` directory and build the Docker image: ```bash - cd src/ubuntu-generic-diskiamges/24.04-dockerfile + cd src/ubuntu-generic-diskimages/24.04-dockerfile docker build -t ubuntu-kernel-build . cd .. ``` @@ -64,7 +64,8 @@ This document outlines the steps to build a Linux kernel and its modules with th ### Add Kernel Modules to the Disk Image -- Add a Packer file provisioner to copy the modules to the disk image: +- Add a Packer file provisioner to copy the modules to the disk image. +Make sure that this provisioner is added before the shell provisioner as we will used these files in the `post-installation.sh`: ```hcl provisioner "file" { @@ -73,7 +74,8 @@ This document outlines the steps to build a Linux kernel and its modules with th } ``` -- Update the post-install script to move the modules into the correct location and regenerate the initramfs: +- Update the post-install script to move the modules into the correct location and regenerate the initramfs. +Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: ```bash mv /home/gem5/6.8.12 /lib/modules/6.8.12 @@ -93,7 +95,6 @@ This document outlines the steps to build a Linux kernel and its modules with th - Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. - ## **Ubuntu 22.04 Disk Image** ### Build the Docker Image @@ -101,7 +102,7 @@ This document outlines the steps to build a Linux kernel and its modules with th - Navigate to the `22.04-dockerfile` directory and build the Docker image: ```bash - cd src/ubuntu-generic-diskiamges/22.04-dockerfile + cd src/ubuntu-generic-diskimages/22.04-dockerfile docker build -t ubuntu-22.04-kernel-build . cd .. ``` @@ -148,16 +149,18 @@ This document outlines the steps to build a Linux kernel and its modules with th ### Add Kernel Modules to the Disk Image -- Add a Packer file provisioner to copy the modules to the disk image: +- Add a Packer file provisioner to copy the modules to the disk image. +Make sure that this provisioner is added before the shell provisioner as we will used these files in the `post-installation.sh`: ```hcl provisioner "file" { destination = "/home/gem5" - source = "my-arm-5.15.167-kernel" + source = "my-arm-5.15.167-kernel/5.15.167" } ``` -- Update the post-install script to move the modules into the correct location and regenerate the initramfs: +- Update the post-install script to move the modules into the correct location and regenerate the initramfs. +Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: ```bash mv /home/gem5/5.15.167 /lib/modules/5.15.167 @@ -176,3 +179,16 @@ This document outlines the steps to build a Linux kernel and its modules with th ### Test with gem5 - Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. + +- You can use the following code snipped to use the disk image and kernel you made. + +```python +image = DiskImageResource("/path/to/gem5-resources/src/ubuntu-generic-diskimages/arm-disk-image-22-04/arm-ubuntu") +image._root_partition = "2" + +board.set_kernel_disk_workload( + kernel=KernelResource("/path/to/gem5-resources/src/ubuntu-generic-diskimages/my-arm-5.15.167-kernel/vmlinux"), + disk_image=image, + bootloader=obtain_resource("arm64-bootloader-foundation"), +) +``` From 0bd904da99a7efbefa97cddfeea7d6e2f2002ace Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 16 Jan 2025 13:12:38 -0800 Subject: [PATCH 16/18] resources: Update documentation --- .../make-kernel-and-gem5-bridge-driver.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index 7e9228110..83e0c744b 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -64,8 +64,8 @@ This document outlines the steps to build a Linux kernel and its modules with th ### Add Kernel Modules to the Disk Image -- Add a Packer file provisioner to copy the modules to the disk image. -Make sure that this provisioner is added before the shell provisioner as we will used these files in the `post-installation.sh`: +- Add a Packer file provisioner to copy the modules to the disk image. The Packer script is located at `ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl`. +Make sure that this provisioner is added before the shell provisioner, as these files are used when the shell provisioner runs`post-installation.sh`: ```hcl provisioner "file" { @@ -74,8 +74,8 @@ Make sure that this provisioner is added before the shell provisioner as we will } ``` -- Update the post-install script to move the modules into the correct location and regenerate the initramfs. -Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: +- Add the following code snippet to the post-install script to move the modules into the correct location and regenerate the initramfs. The post-install script is located at `ubuntu-generic-diskimages/scripts/post-installation.sh`. +Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`, i.e. add the snippet before the line `echo "Building and installing gem5-bridge (m5) and libm5"`: ```bash mv /home/gem5/6.8.12 /lib/modules/6.8.12 @@ -149,7 +149,7 @@ Make sure the modules are moved before using `gem5-bridge` or compiling benchmar ### Add Kernel Modules to the Disk Image -- Add a Packer file provisioner to copy the modules to the disk image. +- Add a Packer file provisioner to copy the modules to the disk image. The Packer script is located at `ubuntu-generic-diskimages/packer-scripts/arm-ubuntu.pkr.hcl`. Make sure that this provisioner is added before the shell provisioner as we will used these files in the `post-installation.sh`: ```hcl @@ -159,8 +159,8 @@ Make sure that this provisioner is added before the shell provisioner as we will } ``` -- Update the post-install script to move the modules into the correct location and regenerate the initramfs. -Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: +- Add the following code snippet to the post-install script to move the modules into the correct location and regenerate the initramfs. The post-install script is located at `ubuntu-generic-diskimages/scripts/post-installation.sh`. +Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`, i.e. add the snippet before the line `echo "Building and installing gem5-bridge (m5) and libm5"`: ```bash mv /home/gem5/5.15.167 /lib/modules/5.15.167 @@ -178,9 +178,9 @@ Make sure the modules are moved before using `gem5-bridge` or compiling benchmar ### Test with gem5 -- Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. +- Use the disk image and the kernel to run a gem5 filesystem simulation, ensuring the new kernel and modules are correctly set up. See the bottom of this file for an example. -- You can use the following code snipped to use the disk image and kernel you made. +- You can use the following code snippet to use the disk image and kernel you made. ```python image = DiskImageResource("/path/to/gem5-resources/src/ubuntu-generic-diskimages/arm-disk-image-22-04/arm-ubuntu") From b2a721b7036727d9752896d18f565ea8902063e8 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Thu, 16 Jan 2025 13:57:32 -0800 Subject: [PATCH 17/18] resources: update dockerfiles to copy artifact to host during build --- .../22.04-dockerfile/Dockerfile | 8 +- .../24.04-dockerfile/Dockerfile | 7 +- .../make-kernel-and-gem5-bridge-driver.md | 90 +++---------------- 3 files changed, 21 insertions(+), 84 deletions(-) diff --git a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile index bc0d24ca5..18ba9548f 100644 --- a/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/22.04-dockerfile/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:22.04 +FROM ubuntu:22.04 AS stage1 # Install necessary packages for kernel build RUN apt update && apt install -y \ @@ -37,7 +37,9 @@ RUN git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --n RUN cd gem5/util/gem5_bridge && \ make KMAKEDIR=/workspace/linux-5.15.0 INSTALL_MOD_PATH=/workspace/output build install -RUN cd /workspace/output/lib/modules/5.15.167 && \ +RUN cd /workspace/output/lib/modules/5.15.* && \ rm -rf build source -CMD ["/bin/bash"] +FROM scratch AS export-stage +COPY --from=stage1 /workspace/output/lib/modules . +COPY --from=stage1 workspace/linux-5.15.0/vmlinux . diff --git a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile index 3793f9e95..1112719cd 100644 --- a/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile +++ b/src/ubuntu-generic-diskimages/24.04-dockerfile/Dockerfile @@ -1,5 +1,5 @@ # Start from Ubuntu 24.04 base image -FROM ubuntu:24.04 +FROM ubuntu:24.04 AS stage1 # Install necessary packages for kernel and module build RUN apt update && apt install -y \ @@ -38,5 +38,6 @@ RUN cd gem5/util/gem5_bridge && \ RUN cd /workspace/output/lib/modules/6.8.12 && \ rm -rf build -# Use bash as the default shell -CMD ["/bin/bash"] +FROM scratch AS export-stage +COPY --from=stage1 /workspace/output/lib/modules . +COPY --from=stage1 /workspace/linux-6.8.0/vmlinux . diff --git a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md index 83e0c744b..cc4609fb0 100644 --- a/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md +++ b/src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md @@ -14,41 +14,14 @@ This document outlines the steps to build a Linux kernel and its modules with th ### Build the Docker Image -- Navigate to the `24.04-dockerfile` directory and build the Docker image: +The Docker image build process will copy the built kernel and modules to your host system, making them readily available for further use. - ```bash - cd src/ubuntu-generic-diskimages/24.04-dockerfile - docker build -t ubuntu-kernel-build . - cd .. - ``` - -### Build the Kernel and Modules - -- Create a container from the built image: - - ```bash - docker create --name kernel-builder ubuntu-kernel-build - ``` - -- Start the container to build the kernel: - - ```bash - docker start -a kernel-builder - ``` - -- Copy the kernel and modules to the host: + Run the `make-arm-kernel.sh` script located in the directory `src/ubuntu-generic-diskimages`. + Since we are building the kernel that is included by default in Ubuntu 24.04, you need to use the `24.04` argument with the script: - ```bash - mkdir my-arm-6.8.12-kernel - docker cp kernel-builder:/workspace/linux-6.8.0/vmlinux my-arm-6.8.12-kernel/ - docker cp kernel-builder:/workspace/output/lib/modules/6.8.12 my-arm-6.8.12-kernel/ - ``` - -- Clean up the container: - - ```bash - docker rm kernel-builder - ``` +```bash +./make-arm-kernel.sh 24.04 +``` ### Verify Output @@ -99,53 +72,14 @@ Make sure the modules are moved before using `gem5-bridge` or compiling benchmar ### Build the Docker Image -- Navigate to the `22.04-dockerfile` directory and build the Docker image: - - ```bash - cd src/ubuntu-generic-diskimages/22.04-dockerfile - docker build -t ubuntu-22.04-kernel-build . - cd .. - ``` - -### Build the Kernel and Modules +The Docker image build process will copy the built kernel and modules to your host system, making them readily available for further use. -- Create a container from the built image: + Run the `make-arm-kernel.sh` script located in the directory `src/ubuntu-generic-diskimages`. + Since we are building the kernel that is included by default in Ubuntu 22.04, you need to use the `22.04` argument with the script: - ```bash - docker create --name kernel-builder ubuntu-22.04-kernel-build - ``` - -- Start the container to build the kernel: - - ```bash - docker start -a kernel-builder - ``` - -- Copy the kernel and modules to the host: - - ```bash - mkdir my-arm-5.15.167-kernel - docker cp kernel-builder:/workspace/linux-5.15.0/vmlinux my-arm-5.15.167-kernel/ - docker cp kernel-builder:/workspace/output/lib/modules/5.15.167 my-arm-5.15.167-kernel/ - ``` - -- Clean up the container: - - ```bash - docker rm kernel-builder - ``` - -### Verify Output - -- Check the contents of `my-arm-5.15.167-kernel`: - - ```bash - ls my-arm-5.15.167-kernel/ - ``` - - You should see: - - `vmlinux` — The built kernel image. - - `5.15.167/` — Directory containing the kernel modules. +```bash +./make-arm-kernel.sh 22.04 +``` ### Add Kernel Modules to the Disk Image From a1a2b99a0ca08c72b38808d25e754fe9ecb08634 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Fri, 17 Jan 2025 14:28:44 -0800 Subject: [PATCH 18/18] resources: Add bash script to make dockerfile --- .../make-arm-kernel.sh | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 src/ubuntu-generic-diskimages/make-arm-kernel.sh diff --git a/src/ubuntu-generic-diskimages/make-arm-kernel.sh b/src/ubuntu-generic-diskimages/make-arm-kernel.sh new file mode 100755 index 000000000..57b05e060 --- /dev/null +++ b/src/ubuntu-generic-diskimages/make-arm-kernel.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Ensure an argument is provided +if [ -z "$1" ]; then + echo "Usage: $0 " + echo "Example: $0 24.04" + echo " $0 22.04" + exit 1 +fi + +# Set variables based on the argument +if [ "$1" == "24.04" ]; then + DOCKERFILE="./24.04-dockerfile/Dockerfile" + OUTPUT="my-arm-6.8.12-kernel" +elif [ "$1" == "22.04" ]; then + DOCKERFILE="./22.04-dockerfile/Dockerfile" + OUTPUT="my-arm-5.15.167-kernel" +else + echo "Invalid version: $1" + echo "Supported versions: 24.04, 22.04" + exit 1 +fi + +# Build the Docker image +DOCKER_BUILDKIT=1 docker build --no-cache \ + --file "$DOCKERFILE" \ + --output "$OUTPUT" . + +echo "Build completed for $1: Output directory is $OUTPUT"