Building Linux Kernel

Document created by rogeriopimentel Employee on May 14, 2014Last modified by Renato Nogueira Frias on Nov 4, 2019
Version 30Show Document
  • View in full screen mode

Building using Yocto


1 - Baking (building) the kernel


When an image is built using Yocto (for more details about how to build an image, check the Yocto training home: the kernel is automatically built and the kernel image is located at /fsl-community-bsp/build/tmp/deploy/images/<your_target>/uImage


If you want to build only the kernel, the following command can be used:

$ bitbake linux-imx




2 - Configuring the kernel


To call the kernel menuconfig, run the command:

$ bitbake -c menuconfig linux-imx



A new terminal window will open with the kernel menuconfig. Make changes if needed, exit the configmenu and copy the .config generated file to defconfig as following:

$ cp tmp/work/imx6qsabresd-poky-linux-gnueabi/linux-imx/3.0.35-r33.10/git/.config




Note that the kernel version, in this case "3.0.35-r33.10" may change.



3 - Cleaning and building again with the new configuration

With the new defconfig saved on the correct folder (step 2), it's time to clear all previous kernel and build it again:

$ bitbake -c cleansstate linux-imx

$ bitbake <your_image>       or         $ bitbake linux-imx



The uImage will be under tmp/deploy/image



Building without a BSP



1- Downloading the kernel source code


Choose what kernel you will build. Usually, the NXP kernel or mainline ( kernel:


For NXP kernel (more details on ) use:

$ git clone 



For Mainline kernel (more details on ) use:

$ git clone git://




2 - Choose which branch will you use


Once downloaded, check the available branches by using:

$ git branch -a

  remotes/origin/HEAD -> origin/master

Make a local branch, based on a branch you choose from the list:

$ git checkout -b local_branch origin/imx_4.9.88_2.0.0_ga

*NOTES:      On command above my local branch name is "local_branch". You can choose this name as you prefer

                    The chosen branch was origin/imx_4.9.88_2.0.0_ga. You can choose another one, always starting by origin/.......


3 - Setting the environment variables


3.1 - Using Yocto Toolchain


If you're using the Yocto SDK (Check the Yocto training at NXP community: ), just execute the script to export the needed environment variables, e.g.:

$ source /opt/poky/1.6+snapshot/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi 

unset LDFLAGS     

If you're using another toolchain, the common environment variables to set are the following:

$ export PATH=$PATH:/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/
$ export TOOLCHAIN=/opt/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/
$ export CROSS_COMPILE=arm-none-linux-gnueabi-

$ export ARCH=arm

IMPORTANT: Change the variables above according your installed toolchain.


3.2 - Using Ubuntu Toolchain


For 64-bits processors (i.MX8 family)


Install the GCC toolchain for 64 bits:


sudo apt-get install gcc-aarch64-linux-gnu

Export the environment variables:


$ export ARCH=arm64
$ export CROSS_COMPILE=/usr/bin/aarch64-linux-gnu-

For 32-bits processors (i.MX2, i.MX3, i.MX5 and i.MX6 families)


Install the GCC toolchain for 32 bits:


sudo apt-get install gcc-arm-linux-gnueabi

Export the environment variables:


export ARCH=arm
export CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-


4 - Configuring the kernel


If you're building for i.MX6 and i.MX5, configure the kernel options based on file imx_v7_defconfig:

$ cp arch/arm/configs/imx_v7_defconfig .config

$ make menuconfig 

$ make


If you're building for i.MX8 family, configure the kernel options based on file arm64/defconfig:


      $ cp arch/arm64/configs/defconfig .config


      $ make menuconfig


      $ make


5 - Building the modules


After step 4, only the kernel (uImage file) was generated. The kernel modules must be built and installed in a known path. First, build the modules:

$ make modules


And install them:

$ make modules_install INSTALL_MOD_PATH=/path_where_you_want_to_install

20 people found this helpful