|
| 1 | +# Make kernel and the gem5 bridge driver |
| 2 | + |
| 3 | +This document will highlight the steps needed to make a kernel and its modules with the gem5-bridge driver. |
| 4 | + |
| 5 | +## Ubuntu 24.04 disk image |
| 6 | + |
| 7 | +Assuming you are in the `src/ubuntu-generic-diskiamges` directory. |
| 8 | +`cd` to the `24.04-dockerfile` directory and build the docker image. |
| 9 | + |
| 10 | +```bash |
| 11 | +cd 24.04-dockerfile |
| 12 | +docker build -t ubuntu-kernel-build . |
| 13 | +cd .. |
| 14 | +``` |
| 15 | + |
| 16 | +Then lets make a new directory called `my-arm-6.8.12-kernel`. |
| 17 | +This directory will have the kernel source and the modules of our built kernel. |
| 18 | + |
| 19 | +```bash |
| 20 | +mkdir my-arm-6.8.12-kernel |
| 21 | +``` |
| 22 | + |
| 23 | +lets get the kernel source from `apt source`, we will be making the `6.8.12 96.8.0-47-generic)` kernel. |
| 24 | + |
| 25 | +```bash |
| 26 | +cd my-arm-6.8.12-kernel |
| 27 | +apt source linux-image-unsigned-6.8.0-47-generic |
| 28 | +``` |
| 29 | + |
| 30 | +You might need to update ubuntu source list to use the above command. |
| 31 | +Checkout this post if you need to update: <https://askubuntu.com/questions/1512042/ubuntu-24-04-getting-error-you-must-put-some-deb-src-uris-in-your-sources-list> |
| 32 | + |
| 33 | +Lets make an output directory that will have our built modules |
| 34 | + |
| 35 | +```bash |
| 36 | +mkdir output |
| 37 | +``` |
| 38 | + |
| 39 | +Lets run the docker image from the `my-arm-6.8.12-kernel` directory. |
| 40 | + |
| 41 | +```bash |
| 42 | +docker run --rm -it -u $UID:$GID -v ./linux-6.8.0:/workspace/source -v ./output:/workspace/output --name kernel-builder ubuntu-kernel-build |
| 43 | +``` |
| 44 | + |
| 45 | +Now in the docker terminal, lets build the kernel |
| 46 | + |
| 47 | +```bash |
| 48 | +cd source |
| 49 | +make defconfig |
| 50 | +make -j$nproc |
| 51 | +``` |
| 52 | + |
| 53 | +The above commands will make the kernel and the modules. |
| 54 | +lets install the modules to the output directory |
| 55 | + |
| 56 | +```bash |
| 57 | +make INSTALL_MOD_PATH=/workspace/output modules_install |
| 58 | +``` |
| 59 | + |
| 60 | +After the modules are installed, lets install our gem5-bridge driver. |
| 61 | + |
| 62 | +in the `/workspace/source`, lets get the driver files |
| 63 | + |
| 64 | +```bash |
| 65 | +git clone https://github.com/nkrim/gem5.git --depth=1 --filter=blob:none --no-checkout --sparse --single-branch --branch=gem5-bridge |
| 66 | +cd gem5 |
| 67 | +git sparse-checkout add util/m5 |
| 68 | +git sparse-checkout add util/gem5_bridge |
| 69 | +git sparse-checkout add include |
| 70 | +git checkout |
| 71 | +``` |
| 72 | +Now lets make our driver |
| 73 | + |
| 74 | +```bash |
| 75 | +cd util/gem5_bridge |
| 76 | +make KMAKEDIR=/workspace/source INSTALL_MOD_PATH=/workspace/output build install |
| 77 | +``` |
| 78 | + |
| 79 | +The above command specifies the kernel source path and the output path. |
| 80 | +You can find the kernel at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/linux-6.8.0/vmlinux` |
| 81 | +and the modules at `src/ubuntu-generic-diskimages/my-arm-6.8.12-kernel/output/lib/modules/6.8.12`. |
| 82 | + |
| 83 | +Now lets move the modules to our disk image. |
| 84 | + |
| 85 | +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 |
| 86 | + |
| 87 | +```bash |
| 88 | +rm output/lib/modules/6.8.12/build |
| 89 | +``` |
| 90 | + |
| 91 | +now add the following file provisioner to move the files from host to the disk |
| 92 | + |
| 93 | +```hcl |
| 94 | + provisioner "file" { |
| 95 | + destination= "/home/gem5" |
| 96 | + source = "my-arm-6.8.12-kernel/output/lib/modules/6.8.12" |
| 97 | + } |
| 98 | +``` |
| 99 | + |
| 100 | +also add the following lines in the post install script to move the modules to `/lib/modules` and run `depmode` and `initramfs` |
| 101 | + |
| 102 | +```bash |
| 103 | +mv /home/gem5/6.8.12 /lib/modules/6.8.12 |
| 104 | +depmod --quick -a 6.8.12 |
| 105 | +update-initramfs -u -k 6.8.12 |
| 106 | +``` |
| 107 | + |
| 108 | +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. |
0 commit comments