-
Notifications
You must be signed in to change notification settings - Fork 49
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
Open
Harshil2107
wants to merge
18
commits into
gem5:stable
Choose a base branch
from
Harshil2107:make-arm-kernel
base: stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
970f97c
resources: add scripts to make and extract arm kernel
Harshil2107 c85807e
resources: update scripts to build the kernel
Harshil2107 22d3fe2
resources: update disk size to 50gb
Harshil2107 d8d4d3c
resources: Update building kernel and modules on host
Harshil2107 d9573fb
resources: clean up post install script
Harshil2107 c4ace1d
resources: add docker files to make kernel for ubuntu 22.04 image
Harshil2107 b497d6f
resources: Update docker files to make and kerenl and modules on build
Harshil2107 9678f1a
resources: Update and clean up documentation to refer to the new dock…
Harshil2107 6f6a870
resources: Update documentation
Harshil2107 67d061b
resources: add link to new documentation to BUILDING.md
Harshil2107 606cb28
resoruces: update dockerfile to remove chmod
Harshil2107 327a0b4
resources: revert size changes
Harshil2107 78e7a39
resources: Update size of images
Harshil2107 0f63a99
resources: clean up comments
Harshil2107 4624ee3
resources: update documentation
Harshil2107 0bd904d
resources: Update documentation
Harshil2107 b2a721b
resources: update dockerfiles to copy artifact to host during build
Harshil2107 a1a2b99
resources: Add bash script to make dockerfile
Harshil2107 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 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 | ||
|
||
RUN cd /workspace/output/lib/modules/5.15.167 && \ | ||
rm -rf build source | ||
|
||
CMD ["/bin/bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# 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 | ||
|
||
|
||
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 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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed so the image won't be used interactively. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
src/ubuntu-generic-diskimages/make-kernel-and-gem5-bridge-driver.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
|
||
# 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 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 | ||
|
||
- [Ubuntu 24.04 Disk Image](#ubuntu-2404-disk-image) | ||
- [Ubuntu 22.04 Disk Image](#ubuntu-2204-disk-image) | ||
|
||
## **Ubuntu 24.04 Disk Image** | ||
|
||
### Build the Docker Image | ||
|
||
- Navigate to the `24.04-dockerfile` directory and build the Docker image: | ||
|
||
```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: | ||
|
||
```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 | ||
``` | ||
|
||
### Verify Output | ||
|
||
- Check the contents of `my-arm-6.8.12-kernel`: | ||
|
||
```bash | ||
ls my-arm-6.8.12-kernel/ | ||
``` | ||
|
||
You should see: | ||
- `vmlinux` — The built kernel image. | ||
- `6.8.12/` — 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. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Make sure that this provisioner is added before the shell provisioner as we will used these files in the `post-installation.sh`: | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```hcl | ||
provisioner "file" { | ||
destination = "/home/gem5" | ||
source = "my-arm-6.8.12-kernel/6.8.12" | ||
} | ||
``` | ||
|
||
- Update the post-install script to move the modules into the correct location and regenerate the initramfs. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```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 | ||
``` | ||
|
||
### Build the Disk Image | ||
|
||
- Build the disk image using your build script: | ||
|
||
```bash | ||
./build-arm.sh 24.04 | ||
``` | ||
|
||
### 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. | ||
|
||
## **Ubuntu 22.04 Disk Image** | ||
|
||
### 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 | ||
|
||
- Create a container from the built image: | ||
|
||
```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. | ||
|
||
### Add Kernel Modules to the Disk Image | ||
|
||
- Add a Packer file provisioner to copy the modules to the disk image. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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/5.15.167" | ||
} | ||
``` | ||
|
||
- Update the post-install script to move the modules into the correct location and regenerate the initramfs. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Make sure the modules are moved before using `gem5-bridge` or compiling benchmarks with `gem5-bridge`: | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```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 | ||
|
||
- Build the disk image using your build script: | ||
|
||
```bash | ||
./build-arm.sh 22.04 | ||
``` | ||
|
||
### 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. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- You can use the following code snipped to use the disk image and kernel you made. | ||
Harshil2107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```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"), | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,13 +18,6 @@ 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)" | ||
|
||
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" | ||
|
||
echo "Installing the gem5 init script in /sbin" | ||
mv /home/gem5/gem5_init.sh /sbin | ||
mv /sbin/init /sbin/init.old | ||
|
@@ -47,14 +40,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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be changed before merging