Customizing the Linux kernel: Difference between revisions
From SomLabs Wiki
No edit summary |
No edit summary |
||
Line 42: | Line 42: | ||
<pre>git apply <KERNEL_PATCH_PATH>/linux-imx-somlabs.patch</pre> | <pre>git apply <KERNEL_PATCH_PATH>/linux-imx-somlabs.patch</pre> | ||
The Linux kernel version 4. | The Linux kernel version 4.9 in the SoMLabs Debian versions older the 02-2020 can be patched using the ''kernel_4.9'' tag of the mentioned repository. | ||
== Customizing the Linux kernel == | == Customizing the Linux kernel == |
Revision as of 17:55, 9 March 2020
Customizing the Linux kernel
This tutorial shows how to download, patch, modify and update the Linux kernel in the existing system on VisionSOM module. It was tested on the PC with Ubuntu 18.04 host system.
Downloading toolchain
For the kernel compilation we need an appropriate compiler that will generate kernel image for the ARM architecture. We will use the ready toolchain from Linaro. It can be download from the Linaro website using wget command:
wget https://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/arm-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
and extracted using tar:
tar -xf gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.tar.xz
Now the toolchain is ready to use.
Downloading the Linux kernel
The iMX6ULL processor is fully supported by the Linux kernel version maintained by the NXP company. We will use the kernel released under version 4.19.35. The sources can be downloaded from the NXP repositories using git:
https://source.codeaurora.org/external/imx/linux-imx
This command will download the entire kernel source, so we need to switch to the appropriate branch:
cd linux-imx git checkout imx_4.19.35_1.1.0
In the SoMLabs Debian versions older than 02-2020 the older Linux kernel version 4.9 is used. It can be obtained from the repository:
git clone git://git.freescale.com/imx/linux-imx.git
cd linux-imx git checkout rel_imx_4.9.x_1.0.0_ga
Patching the Linux kernel
The base kernel from NXP supports the processor, however we need to apply the patch with VisionSOM-6ULL hardware configuration. The newest patch is located in the SoMLabs git repository and can be cloned using command:
git clone https://github.com/SoMLabs/linux-imx-somlabs-patch.git
Now is time to apply the patch to the kernel sources by calling the following command from the kernel directory (linux-imx):
git apply <KERNEL_PATCH_PATH>/linux-imx-somlabs.patch
The Linux kernel version 4.9 in the SoMLabs Debian versions older the 02-2020 can be patched using the kernel_4.9 tag of the mentioned repository.
Customizing the Linux kernel
The kernel configuration tools require two environmental variables describing the chosen architecture and toolchain. We can set them in the current terminal with the following commands:
export ARCH=arm export CROSS_COMPILE=<LINARO_TOOLCHAIN_PATH>/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
Now we can create the default configuration from the SoMLabs kernel patch:
make somlabs-visionsom_defconfig
This configuration may be used as a base for further customization. Alternatively one of the configuration files provided by NXP may also be used - they can be found in the arch/arm/configs/ directory.
To modify the kernel we can use some graphical tools. The examples are:
- make menuconfig - based on ncurses library
- make nconfig - based on ncurses library
- make xconfig - based on qt library
Each of these tools displays all of the possible configuration options of the kernel.
For example, in order to add the support for a luminosity sensor using the menuconfig tool we need to go to Device Drivers > Industrial I/O support > Light sensors section and select one of the supported devices (pressing Y adds the driver to kernel, M configures it as a kernel module, N removes the driver):
After all changes the we need to save them and the selected tool will generate a new configuration file (.config in the kernel source directory).
Building the Linux kernel
When the configuration is ready, the kernel can be built using the command:
make
called from the base kernel directory. It is important to remember also about the ARCH and CROSS_COMPILE variables:
export ARCH=arm export CROSS_COMPILE=<LINARO_TOOLCHAIN_PATH>/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
In order to compile the kernel in multi-core environment, the -j option can be added to define the number of cores for the compilation, for example:
make -j6
This command will build the entire kernel, modules and the device tree. it is also possible to build selected parts by choosing one or more targets:
make zImage modules dtbs
- zImage - kernel image
- modules - kernel modules
- dtbs - device tree
The new kernel image is located in the arch/arm/boot/zImage file and the device tree blobs can be found in the arch/arm/boot/dts/ directory. For the VisionSOM-6ULL there are three hardware configurations available:
- somlabs-visionsom-6ull.dtb - for SD card version
- somlabs-visionsom-6ull-emmc.dtb - for eMMC version
- somlabs-visionsom-6ull-nand.dtb - for NAND version
Finally the modules can be installed using the following command:
make modules_install INSTALL_MOD_PATH=<MODULES_INSTALL_PATH>
We need to specify the installation path of the modules in place of MODULES_INSTALL_PATH. It can be any local directory - all modules will be collected from the kernel source directory and copied there.
If we need the kernel headers we can collect them in a similar way:
make headers_install INSTALL_HDR_PATH=<HEADERS_INSTALL_PATH>
Installing new Linux kernel
Now, when we have all kernel components we can install the to our VisionSOM system. The original kernel (zImage) and the device tree files (*.dtb) are located in the /boot directory on SD card or eMMC memory, so we can just backup the old versions and replace them. The kernel modules needs to be copied to the /lib/modules directory and the headers to /usr/include.