Skip to content

Build Linux from source code

Toolchain Installation for Out of FlexBuild Builds

To install the toolchain, follow the Debian FlexBuild Toolchain installation guide.

Set Up the Environment

Set up a working directory:

export WORKDIR=~/imx7-var-som-linux
mkdir -p ${WORKDIR}

Define the cross-compiler and the architecture:

export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm

Build Linux Out of the FlexBuild Tree

Fetch linux-imx Source Code

cd ${WORKDIR}
git clone https://github.com/varigit/linux-imx.git -b 6.6-2.2.x-imx_var01 linux-imx

Build Kernel, Modules, and DTBs

Clean and prepare the kernel:

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

Customize the kernel configuration, if required:

make menuconfig

Build the kernel image, modules, and device trees:

make -j$(nproc)

Build individual parts as needed:

make -j$(nproc) zImage
make -j$(nproc) modules
make -j$(nproc) dtbs

The following device trees are generated:

Device Tree Name Model
imx7d-var-som-emmc.dtb VAR-SOM-MX7 with eMMC
imx7d-var-som-emmc-wm8731.dtb VAR-SOM-MX7 with eMMC and WM8731 audio codec
imx7d-var-som-emmc-m4.dtb VAR-SOM-MX7 with eMMC and Cortex-M4 support
imx7d-var-som-emmc-m4-wm8731.dtb VAR-SOM-MX7 with eMMC, Cortex-M4 support, and WM8731 audio codec
imx7d-var-som-nand.dtb VAR-SOM-MX7 with NAND flash
imx7d-var-som-nand-wm8731.dtb VAR-SOM-MX7 with NAND flash and WM8731 audio codec
imx7d-var-som-nand-m4.dtb VAR-SOM-MX7 with NAND flash and Cortex-M4 support
imx7d-var-som-nand-m4-wm8731.dtb VAR-SOM-MX7 with NAND flash, Cortex-M4 support, and WM8731 audio codec

Install Kernel Modules to a Temporary Directory

Create a temporary directory to install the modules:

rm -rf ${WORKDIR}/rootfs
mkdir -p ${WORKDIR}/rootfs

Install the modules to the temporary rootfs:

cd ${WORKDIR}/linux-imx
make ARCH=arm \
  INSTALL_MOD_STRIP=1 \
  INSTALL_MOD_PATH=${WORKDIR}/rootfs \
  modules_install

If you replace the kernel image on your system, reinstall the matching kernel modules as well.

Install Built Kernel Artifacts on an SD Card

Copy the kernel image and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition. The examples below assume the boot partition is mounted on /media/user/BOOT and the rootfs partition is mounted on /media/user/rootfs.

cd ${WORKDIR}/linux-imx
sudo cp arch/arm/boot/zImage /media/user/BOOT/
sudo cp arch/arm/boot/dts/nxp/imx/imx7d-var-som*.dtb /media/user/BOOT/
sudo cp -a ${WORKDIR}/rootfs/* /media/user/rootfs/
sync

Notes:

  • If you are using the Debian Recovery SD card and you want the eMMC/NAND installation process to use the updated kernel artifacts, update /opt/images/Debian on the SD card as well.
  • Properly unmount the SD card before physically removing it.