Bookworm armhf cross compile kernel docker: Difference between revisions

From embeddedTS Manuals
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 25: Line 25:
         "$@"
         "$@"
         exit 0;
         exit 0;
fi
if [ ! -e .config ]; then
make ts_defconfig
fi
fi


Line 55: Line 51:
</source>
</source>


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:
The kernel can be compiled by running these two commands:
<source lang=bash>
./build.sh make ts_defconfig
./build.sh # No arguments runs the build and packages the kernel
 
# This will output the build in the current directory as kernel.tar.bz2
</source>
 
Any arguments to this script will be executed in the linux path.  For example:
<source lang=bash>
<source lang=bash>
./build.sh make ts_defconfig
# Customize the kernel config
# Customize the kernel config
./build.sh make menuconfig
./build.sh make menuconfig
# Test a compile (does not package the install)
./build.sh make
# Get a shell prompt in the kernel sources to run commands manually:
# Get a shell prompt in the kernel sources to run commands manually:
./build.sh bash
./build.sh bash

Latest revision as of 10:44, 10 January 2023

To compile the kernel you should use the Debian cross compile docker from a linux workstation.

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/
cd ~/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

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

The kernel can be compiled by running these two commands:

./build.sh make ts_defconfig
./build.sh # No arguments runs the build and packages the kernel

# This will output the build in the current directory as kernel.tar.bz2

Any arguments to this script will be executed in the linux path. For example:

./build.sh make ts_defconfig
# Customize the kernel config
./build.sh make menuconfig
# Test a compile (does not package the install)
./build.sh make
# 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/