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
Build Linux out of Yocto tree¶
Fetch linux-imx source code:¶
Build Kernel, Modules, and DTBs:¶
Setup the environment:
Clean and prepare the kernel:
Build kernel parts:
Build everything:
$ make -j$(nproc)
Build Image.gz only:
$ make -j$(nproc) Image.gz
Build modules only:
$ make -j$(nproc) modules
Build device trees only:
$ make -j$(nproc) dtbs
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard-m7.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS and Basler VCAM-AR1335B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard-basler-isi0.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS, Basler VCAM-AR1335B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard-basler-isi0-m7.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS and Basler VCAM-AR0821B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard-basler-isp0.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with LVDS, Basler VCAM-AR0821B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-dt8mcustomboard-basler-isp0-m7.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE and LVDS support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE, LVDS and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard-m7.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE, LVDS and Basler VCAM-AR1335B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard-basler-isi0.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE, LVDS, Basler VCAM-AR1335B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard-basler-isi0-m7.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE, LVDS and Basler VCAM-AR0821B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard-basler-isp0.dtb
Build only the device tree for DART-MX8M-PLUS V2.x with WBE, LVDS, Basler VCAM-AR0821B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-wbe-dt8mcustomboard-basler-isp0-m7.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard-m7.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS and Basler VCAM-AR1335B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard-basler-isi0.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS, Basler VCAM-AR1335B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard-basler-isi0-m7.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS and Basler VCAM-AR0821B camera support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard-basler-isp0.dtb
Build only the device tree for DART-MX8M-PLUS V1.x with LVDS, Basler VCAM-AR0821B camera and Cortex-M7 support on DT8MCustomBoard 2.x and above:
$ make -j4 freescale/imx8mp-var-dart-1.x-dt8mcustomboard-basler-isp0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.X with LVDS support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.X with LVDS and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with LVDS and 2nd OV5640 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-2nd-ov5640.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with LVDS, 2nd OV5640 and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-2nd-ov5640-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with LVDS and Basler VCAM-AR1335B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-basler-isi0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS v2.X with LVDS, Basler VCAM-AR1335B camera and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-basler-isi0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with LVDS and Basler VCAM-AR0821B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-basler-isp0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with LVDS, Basler VCAM-AR0821B camera and Cortex-M7 supporton Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-symphony-basler-isp0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE and LVDS support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS and 2nd OV5640 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-2nd-ov5640.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.X with WBE, LVDS, 2nd OV5640 and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-2nd-ov5640-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS and Basler VCAM-AR1335B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-basler-isi0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS, Basler VCAM-AR1335B camera and M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-basler-isi0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS and Basler VCAM-AR0821B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-basler-isp0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V2.x with WBE, LVDS, Basler VCAM-AR0821B camera and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-wbe-symphony-basler-isp0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS and 2nd OV5640 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-2nd-ov5640.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS, 2nd OV5640 and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-2nd-ov5640-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS and Basler VCAM-AR1335B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-basler-isi0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS, Basler VCAM-AR1335B camera and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-basler-isi0-m7.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS and Basler VCAM-AR0821B camera support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-basler-isp0.dtb
Build only the device tree for VAR-SOM-MX8M-PLUS V1.x with LVDS, Basler VCAM-AR0821B camera and Cortex-M7 support on Symphony-Board:
$ make -j4 freescale/imx8mp-var-som-1.x-symphony-basler-isp0-m7.dtb
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=arm64 \
INSTALL_MOD_STRIP=1 \
INSTALL_MOD_PATH=$WORKDIR/rootfs \
modules_install
Notes:
If you replace the kernel image (Image.gz) 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 Image.gz and device trees to the SD card boot partition, and install the modules in the SD card rootfs partition.
Assuming the rootfs partition is mounted on /media/user/root:
Install the kernel image and modules:
$ cd ${WORKDIR}/linux-imx
$ kver=$(strings arch/arm64/boot/Image | grep -i "Linux version" | awk 'NR==1 {print $3}')
$ sudo cp arch/arm64/boot/Image.gz /media/user/root/boot/Image.gz-${kver}
$ sudo ln -fs Image.gz-${kver} /media/user/root/boot/Image.gz
$ sudo rsync -Kra $WORKDIR/rootfs/* /media/user/root
Install the device trees:
$ sudo cp arch/arm64/boot/dts/freescale/*imx*var*.dtb /media/user/root/boot/
Install the built kernel images, modules, and device trees using SSH on a running target¶
The example below uses ssh to install the kernel on a running device.
First, export a variable with the ip address of your target device:
Then, copy the kernel image and device trees to the temporary directory, send them to the target using ssh, and install them with the correct user permissions:
$ mkdir -p $WORKDIR/rootfs/boot && \
cp ${WORKDIR}/linux-imx/arch/arm64/boot/dts/freescale/*imx*var*.dtb $WORKDIR/rootfs/boot && \
cp ${WORKDIR}/linux-imx/arch/arm64/boot/Image.gz $WORKDIR/rootfs/boot/ && \
ssh root@${TARGET_IP} 'mkdir /tmp/rootfs' && \
tar czf - -C $WORKDIR/rootfs . | ssh root@${TARGET_IP} 'tar xzf - -C /tmp/rootfs && \
chown -R root:root /tmp/rootfs && cp -a /tmp/rootfs/boot/* /boot/ && cp -a /tmp/rootfs/lib/* /lib/ && \
rm -r /tmp/rootfs'