Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resources: add scripts to make and extract arm kernel #60

Draft
wants to merge 3 commits into
base: stable
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/ubuntu-generic-diskimages/files/arm/gem5_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ 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

# 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
# cause qemu to fail.
Expand Down
2 changes: 1 addition & 1 deletion src/ubuntu-generic-diskimages/http/arm-24-04/user-data
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ autoinstall:
type: format
id: format-0
- device: disk-vda
size: 4257218560
size: 50726691840
wipe: superblock
flag: ''
number: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ source "qemu" "initialize" {
"<wait>"
]
cpus = "4"
disk_size = "4600"
disk_size = "52000"
format = "raw"
headless = "true"
http_directory = local.iso_data[var.ubuntu_version].http_directory
Expand Down Expand Up @@ -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"
}
}
41 changes: 34 additions & 7 deletions src/ubuntu-generic-diskimages/scripts/post-installation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,31 @@ apt-get install -y build-essential
echo "Installing serial service for autologin after systemd"
mv /home/gem5/[email protected] /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)"
apt-get update
apt-get install -y fakeroot build-essential crash kexec-tools makedumpfile kernel-wedge
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt you need these packages

# 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
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you are not applying the ubuntu patches to the kernel. You should add something like patch < linux_6.8.0-47.47. You'll have to figure out the right directory and the exact command. You may also have to unzip the diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to apply the patch but it looks like it is aldready applied. I also looked at the make file of the diff and the source and it looks like the changes from the diff are already in the source.

make -j$(nproc) vmlinux

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"
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
Expand All @@ -47,21 +66,29 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is just a placeholder, but don't forget to fix this.

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
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
Expand Down