Cross compilation of Linux Kernel is a widely used technique for optimizing and configuring the kernel. It allows developers to develop and deploy the kernel on multiple types of hosts or platforms. This article will help you understand the basic steps involved in cross compiling Linux kernel on Linux system.
First of all, clone the linux repository from github and compile the source on your system. On GitHub, you can find various versions of the linux source code, such as the mainline, stable, or the latest development version. We will clone the mainline version in this tutorial. To do so, clone the repository with the following command:
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
After cloning the repository, move to the new directory and run the configuration script. During the configuration process, you will be asked about the target platform for which you are planning to compile the kernel. After the configuration process is finished, the .config file is created in the root directory. This file contains the information of the selected target platform and kernel components.
After that, you can build the linux kernel. To do so, run the following command in the root directory of the linux repository:
make ARCH= CROSS_COMPILE= -j
For instance, if you are cross compiling the kernel on a x86 platform, then you should use the following command:
make ARCH=i386 CROSS_COMPILE=i686-pc-linux-gnu- -j 8
This command will cross-compile the kernel on your system. After the compilation is finished, the kernel image will be generated in the arch//boot directory.
To summarize, cross compiling a Linux kernel on Linux system is relatively easy. First of all, you have to clone the linux source repository from Github or elsewhere. After that, you have to configure the target platform for which the kernel is to be compiled. Finally, the build process is initiated using Makefile. After the compilation is finished, the kernel image will be generated under the arch directory.