Skip to content

Build Linux from source code

It is recommended to build the kernel image using Yocto (see the Customizing the Linux kernel page) instead of using the direct method described in this page.
This is because some of the Yocto packages may depend on the kernel, like the WiFi module that is built from outside of the kernel source tree on some of the Yocto releases.

Toolchain installation for out of Yocto builds

To install the toolchain, follow the Yocto Toolchain installation guide.

Setup the environment:

Setup a working directory

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

Build Linux out of Yocto tree

Fetch linux-imx source code:

cd $WORKDIR
git clone https://github.com/varigit/linux-imx.git -b lf-6.6.y_6.6.52-2.2.0_var01

Build Kernel, Modules, and DTBs:

Setup the environment:

source /opt/fsl-imx-x11/6.6-scarthgap/environment-setup-cortexa7t2hf-neon-poky-linux-gnueabi

Clean and prepare the kernel:

cd ${WORKDIR}/linux-imx
make mrproper
make imx_v7_var_defconfig
Customize the kernel configuration (optional step):
make menuconfig

Build kernel parts:

Build everything:
make -j$(nproc)

Build zImage only:
make -j$(nproc)  zImage

Build modules only:
make -j$(nproc)  modules

Build device trees only:

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-nand.dtb VAR-SOM-MX7 with NAND flash
imx7d-var-som-emmc-m4.dtb VAR-SOM-MX7 with eMMC and M4 support
imx7d-var-som-nand-m4.dtb VAR-SOM-MX7 with NAND flash and M4 support

Install kernel modules to temporary directory

Create a temporary directory to install the modules:

Optional: delete any old installation from previous builds:
rm -rf $WORKDIR/rootfs

Create new directory:
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

Notes:

If you replace the kernel image (zImage) on your system, you also need to reinstall the kernel modules, and vice versa.

If you just want to make a change in the device tree, you can compile and replace it without replacing the kernel image and modules.

Install the built kernel images, modules, and device trees on an SD card

Copy the zImage and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition.
Assuming the boot partition is mounted on /media/user/BOOT-VARMX7 and the rootfs partition is mounted on /media/user/root:

Install the kernel image and modules:
cd ${WORKDIR}/linux-imx
cp arch/arm/boot/zImage /media/user/BOOT-VARMX7
sudo cp $WORKDIR/rootfs/* /media/user/rootfs

Install the device trees:
sudo cp arch/arm/boot/dts/nxp/imx/imx7*var*.dtb /media/user/BOOT-VARMX7

Notes:

  • If you are using our Yocto Recovery SD card, and you want the NAND flash/eMMC installation process to be updated as well as the SD card boot itself, you need to also update the /opt/images/Yocto directory.
  • You should always properly unmount your SD card before physically removing it.