Bookworm armhf cross compile kernel docker
For compiling the kernel for Debian 12 we recommend setting up the cross compile docker.
We can use a shell script to enter the docker, and compile the kernel into a tar that can be distributed to the board. For example:
mkdir ~/Projects/kernel-5.10/
git clone https://github.com/embeddedTS/linux-lts.git -b linux-5.10.y linux
Make a ~/Projects/kernel-5.10/build.sh with:
#!/bin/bash -e if [ ! -e "/.dockerenv" ]; then exec docker-debian-bookworm "$0 $@"; fi export ARCH=arm export CROSS_COMPILE="arm-linux-gnueabihf-" export LOADADDR=0x10008000 cd linux if [ "$#" != "0" ]; then "$@" exit 0; fi if [ ! -e .config ]; then make ts_defconfig fi ## Make any changes in "make menuconfig" or driver modifications, then compile make -j"$(nproc --all)" all uImage # Install to a temporary directory TEMPDIR=$(mktemp -d) export TEMPDIR mkdir "$TEMPDIR"/boot/ cp arch/arm/boot/uImage "$TEMPDIR"/boot/uImage cp arch/arm/boot/zImage "$TEMPDIR"/boot/zImage cp arch/arm/boot/dts/imx6*-ts*.dtb "$TEMPDIR"/boot/ INSTALL_MOD_PATH="${TEMPDIR}/usr/" make modules_install cd ../ fakeroot sh -c "chmod 755 $TEMPDIR; chown -R root:root $TEMPDIR; tar cjf kernel.tar.bz2 -C $TEMPDIR .; rm -rf $TEMPDIR";
Make this executable:
chmod a+x ~/Projects/kernel-5.10/build.sh
Running ./build.sh will generate a config file from our defconfig if it does not yet exist, and will compile, and generate a file "~/Projects/kernel-5.10/kernel.tar.bz2". Any arguments to this script will be executed in the linux path. For example:
# Customize the kernel config
./build.sh make menuconfig
# Get a shell prompt in the kernel sources to run commands manually:
./build.sh bash
The kernel.tar.bz2 from this build script can be extracted from a board, or over an image to install this kernel. For example, copy this to the SBC and run:
tar -xhf kernel.tar.bz2 -C /
From a workstation this can similarly be used to install over a mounted SD image:
sudo mount /dev/sdc1 /mnt/sd/
sudo tar -xhf kernel.tar.bz2 -C /mnt/sd/
sudo umount /mnt/sd/