From 32bb5b905b5cd0550f57478248914afc862236e5 Mon Sep 17 00:00:00 2001 From: rickytrevor Date: Mon, 25 Apr 2022 18:42:06 +0200 Subject: [PATCH 1/2] improved build process --- extras/cross-compile/Dockerfile | 4 ++-- extras/cross-compile/run.sh | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 extras/cross-compile/run.sh diff --git a/extras/cross-compile/Dockerfile b/extras/cross-compile/Dockerfile index 73c27daaa..fd1907542 100644 --- a/extras/cross-compile/Dockerfile +++ b/extras/cross-compile/Dockerfile @@ -15,7 +15,7 @@ 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"] +CMD cp /bin/run.sh . && bash run.sh \ No newline at end of file diff --git a/extras/cross-compile/run.sh b/extras/cross-compile/run.sh new file mode 100644 index 000000000..3f7a1882e --- /dev/null +++ b/extras/cross-compile/run.sh @@ -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 https://github.com/raspberrypi/linux + 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 \ No newline at end of file From 41f2b1f8b0ff2c349917e1c42d59411bafc81708 Mon Sep 17 00:00:00 2001 From: rickytrevor Date: Mon, 25 Apr 2022 18:55:29 +0200 Subject: [PATCH 2/2] update --- extras/cross-compile/Dockerfile | 1 + extras/cross-compile/README.md | 93 ++++++++++++++++++++------------- extras/cross-compile/run.sh | 2 +- 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/extras/cross-compile/Dockerfile b/extras/cross-compile/Dockerfile index fd1907542..455ad2485 100644 --- a/extras/cross-compile/Dockerfile +++ b/extras/cross-compile/Dockerfile @@ -18,4 +18,5 @@ RUN chmod +x /usr/local/bin/copykernel COPY run.sh /bin WORKDIR /build +ENV linkkernel=https://github.com/raspberrypi/linux CMD cp /bin/run.sh . && bash run.sh \ No newline at end of file diff --git a/extras/cross-compile/README.md b/extras/cross-compile/README.md index bb6e772d0..a501a5e9d 100644 --- a/extras/cross-compile/README.md +++ b/extras/cross-compile/README.md @@ -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). - ``` - 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. @@ -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: @@ -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 diff --git a/extras/cross-compile/run.sh b/extras/cross-compile/run.sh index 3f7a1882e..8a417b6ee 100644 --- a/extras/cross-compile/run.sh +++ b/extras/cross-compile/run.sh @@ -10,7 +10,7 @@ if [ "$debug" == "" ]; then elif [ "$arch" == "arm32" ]; then architecture=aarch32-linux-gnu- fi - git clone --depth=1 https://github.com/raspberrypi/linux + git clone --depth=1 $linkkernel cd linux make ARCH=$arch CROSS_COMPILE=$architecture bcm2711_defconfig make ARCH=$arch CROSS_COMPILE=$architecture menuconfig