Skip to content

Commit 852f22a

Browse files
committed
Update cross-compile setup to also include easy instructions for on-Pi compile.
1 parent 9861f8f commit 852f22a

File tree

6 files changed

+27
-277
lines changed

6 files changed

+27
-277
lines changed

extras/cross-compile/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:buster
1+
FROM debian:trixie
22

33
ENV DEBIAN_FRONTEND=noninteractive
44

extras/cross-compile/README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# Raspberry Pi Linux Cross-compilation Environment
22

3-
> **NOTE**: The old Vagrant and VirtualBox-based build environment is now stored in the [`legacy-vagrant`](legacy-vagrant/) directory.
4-
53
This environment can be used to [cross-compile the Raspberry Pi OS kernel](https://www.raspberrypi.org/documentation/linux/kernel/building.md) from a Linux, Windows, or Mac workstation using Docker.
64

7-
This build configuration has only been tested with the Raspberry Pi 4, CM4, and Pi 400, and run on macOS.
5+
You can also skip the 'Bringing up the build environment' section and just compile the kernel directly on the Pi itself.
6+
7+
This build configuration currently targets Raspberry Pi 5, CM5, and Pi 500/500+, and on macOS using Docker Desktop, using the Pi OS 64-bit build.
88

99
## Bringing up the build environment
1010

1111
1. Install Docker (and Docker Compose if not using Docker Desktop).
1212
1. Bring up the cross-compile environment:
1313

1414
```
15-
docker-compose up -d
15+
docker compose up -d
1616
```
1717
1818
1. Log into the running container:
@@ -27,17 +27,19 @@ You will be dropped into a shell inside the container's `/build` directory. From
2727
2828
## Compiling the Kernel
2929
30+
If compiling on the Raspberry Pi directly, omit the `ARCH` and `CROSS_COMPILE` options.
31+
3032
1. Clone the linux repo (or clone a fork or a different branch):
3133
3234
```
3335
git clone --depth=1 https://github.com/raspberrypi/linux
3436
```
3537
36-
1. Run the following commands to make the .config file:
38+
1. Run the following commands to make the .config file (change the `bcm2712` to `bcm2711` if compiling for Pi 4/400/CM4):
3739
3840
```
3941
cd linux
40-
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
42+
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2712_defconfig
4143
```
4244
4345
1. (Optionally) Either edit the .config file by hand or use menuconfig:
@@ -49,12 +51,23 @@ You will be dropped into a shell inside the container's `/build` directory. From
4951
1. Compile the Kernel:
5052
5153
```
52-
make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
54+
make -j6 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
5355
```
5456
55-
> For 32-bit Pi OS, use `ARCH=arm`, `CROSS_COMPILE=arm-linux-gnueabihf-`, and `zImage` instead of `Image`.
57+
> I set the jobs argument (`-j6`) conservatively. If you have more processor cores, you may be able to speed up compilation with a higher number, like `-j8` or `-j10`.
5658
57-
> I set the jobs argument (`-j8`) based on a bit of benchmarking on my Mac's processor. For different types of processors you may want to use more (or fewer) jobs depending on architecture and how many cores you have.
59+
**If you're cross-compiling the kernel**: proceed to the next sections.
60+
61+
**If you're compiling the kernel on a Raspberry Pi**: install the new kernel and kernel modules directly, then reboot the Pi:
62+
63+
```
64+
sudo make -j6 modules_install
65+
sudo cp /boot/firmware/$KERNEL.img /boot/firmware/$KERNEL-backup.img
66+
sudo cp arch/arm64/boot/Image.gz /boot/firmware/$KERNEL.img
67+
sudo cp arch/arm64/boot/dts/broadcom/*.dtb /boot/firmware/
68+
sudo cp arch/arm64/boot/dts/overlays/*.dtb* /boot/firmware/overlays/
69+
sudo cp arch/arm64/boot/dts/overlays/README /boot/firmware/overlays/
70+
```
5871
5972
## Editing the kernel source inside /build/linux
6073
@@ -120,7 +133,7 @@ env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH
120133
Copy the kernel and DTBs onto the drive:
121134
122135
```
123-
cp arch/arm64/boot/Image /mnt/pi-fat32/kernel8.img
136+
cp arch/arm64/boot/Image /mnt/pi-fat32/kernel_2712.img
124137
cp arch/arm64/boot/dts/broadcom/*.dtb /mnt/pi-fat32/
125138
cp arch/arm64/boot/dts/overlays/*.dtb* /mnt/pi-fat32/overlays/
126139
cp arch/arm64/boot/dts/overlays/README /mnt/pi-fat32/overlays/
@@ -135,8 +148,6 @@ umount /mnt/pi-fat32
135148
136149
Reboot the Pi and _voila!_, you're done!
137150
138-
> For 32-bit Pi OS, use `ARCH=arm`, `CROSS_COMPILE=arm-linux-gnueabihf-`, `zImage` instead of `Image`, `kernel7l` instead of `kernel8`, and `arm` instead of `arm64`.
139-
140151
### Hard Reset on the CM4 IO Board
141152
142153
If you get a fatal kernel panic that doesn't get caught cleanly (which I do, quite often, when debugging PCI Express devices), you can quickly reset the CM4 IO Board by jumping pins 12 and 14 on J2 (`GLOBAL_EN` to `GND`).
@@ -182,7 +193,7 @@ sudo mount /dev/sdb2 mnt/ext4
182193
Copy the kernel and DTBs onto the drive:
183194
184195
```
185-
sudo cp arch/arm64/boot/Image mnt/fat32/kernel8.img
196+
sudo cp arch/arm64/boot/Image mnt/fat32/kernel_2712.img
186197
sudo cp arch/arm64/boot/dts/broadcom/*.dtb mnt/fat32/
187198
sudo cp arch/arm64/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
188199
sudo cp arch/arm64/boot/dts/overlays/README mnt/fat32/overlays/
@@ -201,14 +212,12 @@ sudo env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD
201212
Copy the kernel and DTBs onto the drive:
202213
203214
```
204-
sudo cp arch/arm64/boot/Image mnt/fat32/kernel8.img
215+
sudo cp arch/arm64/boot/Image mnt/fat32/kernel_2712.img
205216
sudo cp arch/arm64/boot/dts/broadcom/*.dtb mnt/fat32/
206217
sudo cp arch/arm64/boot/dts/overlays/*.dtb* mnt/fat32/overlays/
207218
sudo cp arch/arm64/boot/dts/overlays/README mnt/fat32/overlays/
208219
```
209220
210-
> For 32-bit Pi OS, use `kernel7l` instead of `kernel8`.
211-
212221
### Unmounting the drive
213222
214223
Unmount the disk before you remove it from the card reader or unplug it.

extras/cross-compile/copykernel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env PATH=$PATH make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- INSTALL_MOD_PATH
2727

2828
# Copy kernel and DTBs to Pi.
2929
printf "Copying kernel and DTBs\n"
30-
cp arch/arm64/boot/Image /mnt/pi-fat32/kernel8.img
30+
cp arch/arm64/boot/Image /mnt/pi-fat32/kernel_2712.img
3131
cp arch/arm64/boot/dts/broadcom/*.dtb /mnt/pi-fat32/
3232
cp arch/arm64/boot/dts/overlays/*.dtb* /mnt/pi-fat32/overlays/
3333
cp arch/arm64/boot/dts/overlays/README /mnt/pi-fat32/overlays/

extras/cross-compile/legacy-vagrant/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

extras/cross-compile/legacy-vagrant/README.md

Lines changed: 0 additions & 213 deletions
This file was deleted.

extras/cross-compile/legacy-vagrant/Vagrantfile

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)