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

Improved build process #434

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions extras/cross-compile/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN mkdir /build

COPY copykernel.sh /usr/local/bin/copykernel
RUN chmod +x /usr/local/bin/copykernel
COPY run.sh /bin

WORKDIR /build

CMD ["bash"]
ENV linkkernel=https://github.com/raspberrypi/linux
CMD cp /bin/run.sh . && bash run.sh
93 changes: 58 additions & 35 deletions extras/cross-compile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,74 @@ This build configuration has only been tested with the Raspberry Pi 4, CM4, and

## Bringing up the build environment

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

Choose a reason for hiding this comment

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

Try to leave all numbered lists with 1. for all bullet points as the lists automatically increment. In practice, this reduces changelogs


```
docker-compose up -d
```
2. Bring up the cross-compile environment:

```
docker-compose up -d
```

1. Log into the running container:

```
docker attach cross-compile
```
3. Log into the running container:
```
docker attach cross-compile
```

You will be dropped into a shell inside the container's `/build` directory. From here you can work on compiling the kernel.

> After you `exit` out of that shell, the Docker container will stop, but will not be removed. If you want to jump back into it, you can run `docker start cross-compile` and `docker attach cross-compile`.
>
>

## Compiling the Kernel

1. Clone the linux repo (or clone a fork or a different branch):
## Compiling the Kenrel

```
git clone --depth=1 https://github.com/raspberrypi/linux
```
1. build the docker container image

```
docker build -t crosscompile .
```

1. Run the following commands to make the .config file:
2. run the image with the appropriate environment variables

example

```
docker run -ti -e arch=arm64 -v /directory/for/the/build:/build crosscompile
```

```
cd linux
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
```
with the -e arch= you specify the arch that you want to build for, if you want to build for arm32 you just need to write arch=arm32.

1. (Optionally) Either edit the .config file by hand or use menuconfig:
I've also introduced a debug option usable by inserting -e debug=true in the docker run command, that option is going to throw you into a bash prompt where you can test out pretty much whatever you want

```
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
```
## Compiling the Kernel (old version)

1. Compile the Kernel:
1. Clone the linux repo (or clone a fork or a different branch):

```
make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
git clone --depth=1 https://github.com/raspberrypi/linux
```

> For 32-bit Pi OS, use `ARCH=arm`, `CROSS_COMPILE=arm-linux-gnueabihf-`, and `zImage` instead of `Image`.
1. Run the following commands to make the .config file:

```
cd linux
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
```

2. (Optionally) Either edit the .config file by hand or use menuconfig:

```
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- menuconfig
```

3. Compile the Kernel:

```
make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- Image modules dtbs
```

~~

> 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.

Expand All @@ -62,8 +85,8 @@ For the benefit of silly Mac users like me, I have a 'reverse NFS' mount availab

This is helpful because:

- Most macOS installs don't have case-sensitive filesystems, so Linux codebase checkouts (which have files with duplicate filenames) will break.
- Docker for Mac is funny and runs in a VM, so if you mount a local (host) directory into the container, performance goes down the drain.
- Most macOS installs don't have case-sensitive filesystems, so Linux codebase checkouts (which have files with duplicate filenames) will break.
- Docker for Mac is funny and runs in a VM, so if you mount a local (host) directory into the container, performance goes down the drain.

To connect to the NFS share, create a folder like `nfs-share` on your Mac and run the command:

Expand All @@ -79,14 +102,14 @@ One prerequisite for this particular method is to make sure you can mount the re

The easiest way is to run the `setup.yml` playbook:

1. Install Ansible.
2. Make sure the `inventory.ini` points at your Raspberry Pi and you can SSH into it.
3. Run `ansible-playbook setup.yml`.
1. Install Ansible.
2. Make sure the `inventory.ini` points at your Raspberry Pi and you can SSH into it.
3. Run `ansible-playbook setup.yml`.

If you want to set it up manually instead, do this:

1. On the Pi: edit `/etc/ssh/sshd_config` and uncomment `PermitRootLogin`, then restart `sshd`.
2. Create an SSH key in the container, and copy the public key to the Pi's root user `authorized_keys`.
1. On the Pi: edit `/etc/ssh/sshd_config` and uncomment `PermitRootLogin`, then restart `sshd`.
2. Create an SSH key in the container, and copy the public key to the Pi's root user `authorized_keys`.

### Install kernel modules and DTBs via SSHFS

Expand Down
21 changes: 21 additions & 0 deletions extras/cross-compile/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

if [ "$debug" == "" ]; then

if [ "$arch" == "" ]; then
echo "Please set the arch variable to either arm64 or arm32"
exit 1
fi
if [ "$arch" == "arm64" ]; then
architecture=aarch64-linux-gnu-
elif [ "$arch" == "arm32" ]; then
architecture=aarch32-linux-gnu-
fi
git clone --depth=1 $linkkernel
cd linux
make ARCH=$arch CROSS_COMPILE=$architecture bcm2711_defconfig
make ARCH=$arch CROSS_COMPILE=$architecture menuconfig
make -j$(nproc) ARCH=$arch CROSS_COMPILE=$architecture Image modules dtbs
fi
if [ "$debug" == "true" ]; then
bash
fi