From 970f97cba2d5f2eb04e8baabba4826782e7a4887 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Tue, 29 Oct 2024 15:18:58 -0700 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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