Skip to content

Customizing the Linux kernel

Introduction

This guide demonstrates how to patch and rebuild Debian Linux images.

After customizing the kernel, you can either build the complete Debian image with var_build_image, or build the kernel alone:

bld -f sdk-var.yml -m imx7-var-som linux

See the Build Debian from source code page for the initial FlexBuild setup.

Requirements

Before modifying the kernel source code, follow the initial setup steps in the Build Linux from source code page.

Modifying the Kernel

Make the desired changes to the kernel source code. For example:

cd ${WORKDIR}/linux-imx
vim ./drivers/net/can/m_can/m_can.c
vim ./drivers/net/can/m_can/m_can.h

Configuring the Kernel

The default kernel configuration file used by FlexBuild is part of the kernel source tree and is located at:

arch/arm/configs/imx_v7_var_defconfig

Clean and prepare the kernel:

cd ${WORKDIR}/linux-imx
make mrproper
make imx_v7_var_defconfig

Customize the kernel configuration and save it back to the default defconfig:

make menuconfig
make savedefconfig
mv defconfig arch/arm/configs/imx_v7_var_defconfig

Generate a Patch

Commit the changes locally and generate a patch:

git add .
git commit -e
git format-patch -1

Build Modified Linux

Make sure the FlexBuild Docker environment is set up as described in Build Debian from source code.

FlexBuild retrieves the source code from the default Variscite repository and applies patches from the Linux patch folder before building it. Copy the patch to the FlexBuild Linux patch folder:

mkdir -p [...]/flexbuild/patch/linux/
cp 0001-my-changes.patch [...]/flexbuild/patch/linux/

Do not run git am or git apply manually. FlexBuild applies the patch during the Linux build.

Enter the Docker environment if needed:

cd [...]/flexbuild
. setup.env
bld docker
. setup.env

Build Linux individually:

bld -f sdk-var.yml -m imx7-var-som linux

If a rebuild is required, clean the Linux build first:

bld clean-linux
bld -f sdk-var.yml -m imx7-var-som linux