Building Linux Kernel

Document created by rogeriopimentel Employee on May 14, 2014Last modified by rogeriopimentel Employee on Oct 24, 2018
Version 29Show 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: https://community.nxp.com/docs/DOC-94849) 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

../sources/meta-fsl-arm/recipes-kernel/linux/linux-imx-3.0.35/mx6/defconfig

  

 

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.org) kernel:

 

For NXP kernel (more details on https://source.codeaurora.org/external/imx/linux-imx/ ) use:

$ git clone https://source.codeaurora.org/external/imx/linux-imx 

              

 

For Mainline kernel (more details on https://www.kernel.org/ ) use:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

              

 

 

2 - Choose which branch will you use

 

Once downloaded, check the available branches by using:

$ git branch -a

  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/imx_4.9.123_imx8mm_ga
  remotes/origin/imx_4.9.51_imx8_beta1
  remotes/origin/imx_4.9.51_imx8_beta2
  remotes/origin/imx_4.9.51_imx8m_beta
  remotes/origin/imx_4.9.51_imx8m_ga
  remotes/origin/imx_4.9.88_2.0.0_ga
  remotes/origin/imx_4.9.88_imx8mm_alpha
  remotes/origin/imx_4.9.88_imx8qxp_beta2
  remotes/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: https://community.nxp.com/docs/DOC-94849 ), 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       

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

           
16 people found this helpful

Attachments

    Outcomes