Build linux kernel source

Build Linux Kernel from Source Code

Use version 9.2 of the Arm releases binary toolchains to cross-compile software for Toradex modules:

  • For 32 bit Arm: gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz
  • For 64 bit Arm: gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz

You have to choose to download either the 32 bit or 64 bit Arm cross-toolchain, according to the architecture of your Computer on Module SoC. Select the correct one from the tabs below:

To install the toolchain on your host machine, download and unpack the tar.xz file. From the command-line:

$ cd ~ $ wget -O gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" $ tar xvf gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz $ ln -s gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf gcc-linaro 

Or you can download the toolchain from Arm website.

The U-Boot and Linux makefiles use the environment variables ARCH/CROSS_COMPILE to configure and call the compiler correctly. Therefore, these environment variables must be exported in any shell instance that will run configure/compile commands to build U-Boot or Linux for the target module.

$ export ARCH=arm $ export DTC_FLAGS="-@" $ export PATH=~/gcc-linaro/bin/:$PATH $ export CROSS_COMPILE=arm-none-linux-gnueabihf- 

You can put those commands into a file and source that file to export it more easily, e.g.:

$ echo "export ARCH=arm" >> ~/export_compiler $ echo "export DTC_FLAGS='-@'" >> ~/export_compiler $ echo "export PATH=~/gcc-linaro/bin/:$PATH" >> ~/export_compiler $ echo "export CROSS_COMPILE=arm-none-linux-gnueabihf-" >> ~/export_compiler $ source ~/export_compiler 

To install the toolchain on your host machine, download and unpack the tar.xz file. From the command-line:

$ cd ~ $ wget -O gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz "https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766&la=en&hash=0A37024B42028A9616F56A51C2D20755C5EBBCD7" $ tar xvf gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz $ ln -s gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu gcc-linaro 

Or you can download the toolchain from Arm website.

The U-Boot and Linux makefiles use the environment variables ARCH/CROSS_COMPILE to configure and call the compiler correctly. Therefore, these environment variables must be exported in any shell instance that will run configure/compile commands to build U-Boot or Linux for the target module.

$ export ARCH=arm64 $ export DTC_FLAGS="-@" $ export PATH=~/gcc-linaro/bin/:$PATH $ export CROSS_COMPILE=aarch64-none-linux-gnu- 

You can put those commands into a file and source that file to export it more easily, E.g.:

$ echo "export ARCH=arm64" >> ~/export_compiler $ echo "export DTC_FLAGS='-@'" >> ~/export_compiler $ echo "export PATH=~/gcc-linaro/bin/:$PATH" >> ~/export_compiler $ echo "export CROSS_COMPILE=aarch64-none-linux-gnu-" >> ~/export_compiler $ source ~/export_compiler 

Install Tools and Dependencies​

Build Host​

You need some essential build tools to compile the Kernel or DTC. Most are likely part of your distro’s standard install.

$ sudo dnf install bc gcc git ncurses-devel lzop make perl openssl-devel bison flex diffutils 
$ sudo apt-get install bc build-essential git libncurses5-dev lzop perl libssl-dev bison flex 

U-Boot Tools​

The uImage target of the Linux kernel compilation needs a recent mkimage tool.

One can install the Fedora package uboot-tools :

$ sudo dnf install uboot-tools 

Or with the corresponding Debian/Ubuntu package u-boot-tools :

$ sudo apt-get install u-boot-tools 

Alternatively, mkimage tool is also built during the U-Boot compilation. You can follow the U-Boot building instructions as explained further in this article, and after that, include it in PATH.

Kernel Version Information​

The required git branch and Linux binaries to be used depend on module type and BSP version, as we will explain in this article.

For a high-level overview of the BSP Versions, check out our Embedded Linux Release Matrix. There you will find the version information of the Linux kernel, U-Boot, Yocto/OpenEmbedded, the Toradex BSP, and Linux images, along with release dates.

Upstream-based Kernel​

SoC Kernel Git Branch Kernel Configuration Kernel Binary
i.MX 8MM/8MP v6.1 defconfig arch/arm64/boot/Image.gz
i.MX 7 v6.1 imx_v6_v7_defconfig arch/arm/boot/zImage
i.MX 6 v6.1 imx_v6_v7_defconfig arch/arm/boot/zImage
i.MX 6ULL v6.1 imx_v6_v7_defconfig arch/arm/boot/zImage

Downstream-based Kernel​

SoC Kernel Git Branch Kernel Configuration Kernel Binary
i.MX 8MM/8MP toradex_5.15-2.0.x-imx toradex_defconfig arch/arm64/boot/Image.gz
SoC Kernel Git Branch Kernel Configuration Kernel Binary
i.MX 8/8MM/8MP toradex_5.15-2.1.x-imx toradex_defconfig arch/arm64/boot/Image.gz

Device Tree Binaries Information​

SoC Device Tree
i.MX 8/8MM/8MP imx8qm-apalis-eval.dtb
imx8qm-apalis-ixora-v1.1.dtb
imx8qm-apalis-v1.1-eval.dtb
imx8qm-apalis-v1.1-ixora-v1.1.dtb
imx8qm-apalis-v1.1-ixora-v1.2.dtb
imx8qp-apalis-v1.1-eval.dtb
imx8qp-apalis-v1.1-ixora-v1.1.dtb
imx8qp-apalis-v1.1-ixora-v1.2.dtb
imx8mm-verdin-nonwifi-dahlia.dtb
imx8mm-verdin-nonwifi-dev.dtb
imx8mm-verdin-wifi-dahlia.dtb
imx8mm-verdin-wifi-dev.dtb
imx8mp-verdin-nonwifi-dahlia.dtb
imx8mp-verdin-nonwifi-dev.dtb
imx8mp-verdin-wifi-dahlia.dtb
imx8mp-verdin-wifi-dev.dtb
i.MX 7 imx7d-colibri-aster.dtb
imx7d-colibri-emmc-aster.dtb
imx7d-colibri-emmc-eval-v3.dtb
imx7d-colibri-eval-v3.dtb
imx7s-colibri-aster.dtb
imx7s-colibri-eval-v3.dtb
i.MX 6 imx6q-apalis-eval.dtb
imx6q-apalis-ixora.dtb
imx6q-apalis-ixora-v1.1.dtb
imx6q-apalis-ixora-v1.2.dtb
imx6dl-colibri-eval-v3.dtb
i.MX 6ULL imx6ull-colibri-emmc-eval-v3.dtb
imx6ull-colibri-eval-v3.dtb
imx6ull-colibri-wifi-eval-v3.dtb

Building Linux Kernel​

Download the Linux Kernel Source​

Obtain the kernel source code using Git:

$ mkdir -p ~/workdir $ cd ~/workdir $ git clone -b git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git 
$ mkdir -p ~/workdir $ cd ~/workdir $ git clone -b git://git.toradex.com/linux-toradex.git 

Replace by the Kernel Git Branch for your specific configuration. Click below to expand the version information. Check the section Kernel Version for this specific information.

If additional patches are provided, apply them as follows: git am .

If your company firewall/gateway inhibit the git protocol, you may use HTTP or HTTPS instead (e.g. git clone https://git.toradex.com/linux-toradex.git ).

Kernel Configuration​

Our kernel tree provides default kernel configurations for our modules:

Ensure the environment is configured for cross-compilation as explained in the toolchain chapter.

Set the default configuration:

$ cd ~/workdir/linux-toradex $ make 

Replace by the Kernel Configuration for your specific configuration. Check the section Kernel Version for this specific information.

At this point, one may alter the kernel configuration by either editing .config directly (e.g., setting CONFIG_* to either =y or =m aka as module) or use one of the kernel configuration utilities included, e.g.:

Kernel Compilation​

Depending on the module, different kernel image types are used. Furthermore, some kernels require a device tree to describe the system’s hardware (see Device Tree Customization for details).

Our kernel configurations build some drivers as kernel modules.

To assure module compatibility, the Kernel refuses to load modules with a ‘vermagic’ string that does not match its own. On top of that, the modules are stored under a directory named after the version string.

Thus one usually needs to compile and deploy the kernel modules together with the Kernel in order to use them.

To compile the Kernel & device tree:

$ make -j$(nproc) Image.gz 2>&1 | tee build.log $ make DTC_FLAGS="-@" freescale/.dtb 

Replace by the Device Tree for your specific configuration. Check the section Device Tree Binaries Information for this specific information.

To compile the kernel & device tree:

$ make -j$(nproc) zImage 2>&1 | tee build.log $ make DTC_FLAGS="-@" .dtb 

Replace by the Device Tree for your specific configuration. Check the section Device Tree Binaries Information for this specific information.

The Linux kernel for our i.MX7 based modules can show linking issues when using the gold linker:

arm-angstrom-linux-gnueabi-ld: --pic-veneer: unknown option arm-angstrom-linux-gnueabi-ld: use the --help option for usage information 

The recommended solution is to just revert to using the regular bfd linker as follows:

$ make -j$(nproc) zImage LD=$ld.bfd | tee build.log 

To compile the kernel & device tree for BSP 2.8b2 or newer:

$ make -j$(nproc) zImage LOADADDR=10008000 2>&1 | tee build.log $ make DTC_FLAGS="-@" .dtb 

Replace by the Device Tree for your specific configuration. Check the section Device Tree Binaries Information for this specific information.

To compile the kernel & device tree:

$ make -j$(nproc) zImage 2>&1 | tee build.log $ make DTC_FLAGS="-@" .dtb 

Replace by the Device Tree for your specific configuration. Check the section Device Tree Binaries Information for this specific information.

To compile the kernel & device tree for BSP 2.8 or older:

The Linux kernel for our i.MX 6ULL based modules can show linking issues when using the gold linker:

arm-angstrom-linux-gnueabi-ld: --pic-veneer: unknown option arm-angstrom-linux-gnueabi-ld: use the --help option for usage information 

The recommended solution is to just revert to using the regular bfd linker as follows:

$ make -j$(nproc) zImage LD=$ld.bfd | tee build.log 

Источник

Читайте также:  Find linux команда exec
Оцените статью
Adblock
detector