Linux Kernel User’s Guide
- Users Guide
- Getting the Kernel Source Code
- Preparing to Build
- Configuring the Kernel
- Compiling the Sources
- Creating the kernel fitImage for high security device (using SDK)
- Creating the kernel fitImage for high security device (using Kernel source)
- Installing the Kernel
The easiest way to get access to the kernel source code is by downloading and installing the Processor SDK Linux J721e. You can download the latest Processor SDK Linux J721e installer from Jacinto7-Linux-SDK-Download-page. Once installed, the kernel source code is included in the SDK’s board-support directory. For your convenience the sources also includes the kernel’s git repository including commit history. Alternatively, Kernel sources can directly be fetched from GIT.
It is important that when using the GCC toolchain provided with the SDK or stand alone from TI that you do NOT source the environment-setup file included with the toolchain when building the kernel. Doing so will cause the compilation of host side components within the kernel tree to fail.
The following commands are intended to be run from the root of the kernel tree unless otherwise specified. The root of the kernel tree is the top-level directory and can be identified by looking for the “MAINTAINERS” file.
Before compiling the kernel or kernel modules the SDK’s toolchain needs to be added to the PATH environment variable
export PATH=<sdk path>/linux-devkit/sysroots/x86_64-arago-linux/usr/bin:$PATH
The current compiler supported for this release along with download location can be found in the release notes for the kernel release.
Prior to compiling the Linux kernel it is often a good idea to make sure that the kernel sources are clean and that there are no remnants left over from a previous build.
The next step will delete any saved .config file in the kernel tree as well as the generated object files. If you have done a previous configuration and do not wish to lose your configuration file you should save a copy of the configuration file (.config) before proceeding.
The command to clean the kernel is:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- distclean
Before compiling the Linux kernel it needs to be configured to select what components will become part of the kernel image, which components will be build as dynamic modules, and which components will be left out all together. This is done using the Linux kernel configuration system.
It is often easiest to start with a base default configuration and then customize it for your use case if needed. Apply Linux kernel configurations with a command of the form:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- <defconfig>
For this sdk, tisdk_[platformName]_defconfig was used to create the prebuilt files. We recommend users to use this kernel configuration (or at least use it as a starting point).
platformName is am64xx-evm for AM64x, and am65xx-evm for AM65x.
For example, to apply the default AM64x kernel configuration, use:
am64xx-evm: make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- tisdk_am64xx-evm_defconfig am64xx-hs-evm: make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- tisdk_am64xx-hs-evm_defconfig
After the configuration step has run the full configuration file is saved to the root of the kernel tree as .config. Any further configuration changes are based on this file until it is cleaned up by doing a kernel clean as mentioned above.
If the kernel was downloaded directly from the git repository, the defconfig will need to be built with scripts. Please see ti_config_fragments/README within the kernel sources for more information. Otherwise a user will notice a significant amount of features not working.
Below is the procedure to build the defconfig from the kernel git repository.
ti_config_fragments/defconfig_builder.sh -t ti_sdk_arm64_release export ARCH=arm64 make ti_sdk_arm64_release_defconfig mv .config arch/arm64/configs/tisdk_[platformName]-evm_defconfig
The list of defconfig map file (i.e., ti_sdk_[device]_release used above) supported can be found from ti_config_fragments/v8_defconfig_map.txt file.
When you want to customize the kernel configuration the easiest way is to use the built in kernel configuration systems. One popular configuration system is menuconfig. menuconfig is an ncurses based configuration utility.
To invoke the kernel configuration you simply use a command like:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- <config type>
i.e. for menuconfig the command would look like
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- menuconfig
Once the configuration window is open you can then select which kernel components should be included in the build. Exiting the configuration will save your selections to a file in the root of the kernel tree called .config.
Once the kernel has been configured it must be compiled to generate the bootable kernel image as well as any dynamic kernel modules that were selected.
By default U-boot expects Image to be the type of kernel image used.
To just build the Image use this command
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- Image
This will result in a kernel image file being created in the arch/arm64/boot/ directory called Image.
Each TI evm has an unique device tree binary file required by the kernel. Therefore, you will need to build and install the correct dtb for the target device. TI device tree files are located in arch/arm64/boot/dts/ti. Below list various TI evms and the matching device tree file.
|Boards||Device Tree File|
|AM65x EVM / AM65x IDK||k3-am654-base-board.dts, daughter cards use .dtso files|
To build an individual device tree file find the name of the dts file for the board you are using and replace the .dts extension with .dtb. Then run the following command:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- ti/<dt filename>.dtb
The compiled device tree file with be located in arch/arm64/boot/dts/ti.
For example, the AM64x EVM device tree file is named k3-am642-evm.dts. To build the device tree binary you would run:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- ti/k3-am642-evm.dtb
Alternatively, you can build every device tree binary with command
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- dtbs
By default the majority of the Linux drivers used in the sdk are not integrated into the kernel image file (Image). These drivers are built as dynamic modules. The command to build these modules is:
make ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- modules
This will result in .ko (kernel object) files being placed in the kernel tree. These .ko files are the dynamic kernel modules.
If you make a change to the kernel which requires you to recompile the kernel, then you should also recompile the kernel modules and reinstall the kernel modules. Otherwise your kernel modules may refuse to load, which will result in a loss of functionality.
Build kernel image and dtbs as per instructions given above.
Get the Security Dev Tool
git clone https://git.ti.com/git/security-development-tools/core-secdev-k3.git -b master export TI_SECURE_DEV_PKG=`pwd`/core-secdev-k3
Sign kernel image and copy to <sdk path>/board_support/signed-images
mkdir <sdk path>/board_support/signed-images $TI_SECURE_DEV_PKG/scripts/secure-binary-image.sh Image Image.sec cp -p Image.sec <sdk path>/board-support/signed-images
Sign devicetree binaries, and copy the signed binaries to <sdk path>/board_support/signed-images. The binaries to be signed is listed in <sdk path>/board-support/prebuilt-images/fitImage-its.its
cd <sdk path>/board-support/linux-5.10*/arch/arm64/boot/dts/ti/ $TI_SECURE_DEV_PKG/scripts/secure-binary-image.sh k3-j721e-common-proc-board.dtb k3-j721e-common-proc-board.dtb.sec $TI_SECURE_DEV_PKG/scripts/secure-binary-image.sh k3-j721e-proc-board-tps65917.dtb k3-j721e-proc-board-tps65917.dtb.sec $TI_SECURE_DEV_PKG/scripts/secure-binary-image.sh k3-j721e-common-proc-board-infotainment.dtbo k3-j721e-common-proc-board-infotainment.dtbo.sec $TI_SECURE_DEV_PKG/scripts/secure-binary-image.sh k3-j721e-sk.dtb k3-j721e-sk.dtb.sec cp -p *.sec <sdk path>/board-support/signed-images
Generate the FIT image
cp <sdk path>/board-support/prebuilt-images/fitImage-its.its <sdk path>/board-support/signed-images cd <sdk path>/board-support/signed-images mkimage -f fitImage-its.its -r fitImage
Install the generated FIT image to “rootfs/boot” for MMC/SD card boot as an example
sudo cp -p fitImage /media/$(USER)/rootfs/boot/fitImage
SDKs have pre-built FIT images that contain the default kernel and dtb files. But developers may want to deploy and test new kernel and dtb without going through the standard build system. Developers can generate the fitImage directly in the “root/boot” partition of the SD card from the host system. For that, a Makefile is needed.
Download the Makefile from
Have u-boot 'mkimage' tool in your path. This can be done with the following command: $ sudo apt install u-boot-tools Get the Security Dev Tools as mentioned in the section above. $ export TI_SECURE_DEV_PKG=`pwd`/core-secdev-k3 Add the Makefile to the "root/boot" directory in SD card.
Add the new images in the "root/boot" directory of SD card Modify the fitImage.its accordingly From the host system, go to the "root/boot" directory and run: $ make
Once the Linux kernel, dtb files and modules have been compiled they must be installed. In the case of the kernel image this can be installed by copying the kernel image file to the location where it is going to be read from. The device tree binaries should also be copied to the same directory that the kernel image was copied to.
cd <kernel sources dir> sudo cp arch/arm64/boot/Image <rootfs path>/boot sudo cp arch/arm64/boot/dts/ti/<dt file>.dtb <rootfs path>/boot
For example, if you wanted to copy the kernel image and AM64x EVM device tree file to the rootfs partition of a SD card you would enter the below commands:
cd <kernel sources dir> sudo cp arch/arm64/boot/Image /media/rootfs/boot sudo cp arch/arm64/boot/dts/ti/k3-am642-evm.dtb /media/rootfs/boot
Starting with U-boot 2013.10, the kernel and device tree binaries are read from the root file system’s boot directory when booting from MMC/EMMC. (NOT from the /boot/ partition on the MMC). This would mean you copy the kernel image and device tree binaries to /media/rootfs/boot instead of /media/boot.
To install the kernel modules you use another make command similar to the others, but with an additional parameter which give the base location where the modules should be installed. This command will create a directory tree from that location like lib/modules/<kernel version> which will contain the dynamic modules corresponding to this version of the kernel. The base location should usually be the root of your target file system. The general format of the command is:
sudo make ARCH=arm64 INSTALL_MOD_PATH=<path to root of file system> modules_install
For example if you are installing the modules on the rootfs partition of the SD card you would do:
sudo make ARCH=arm64 INSTALL_MOD_PATH=/media/rootfs modules_install
Append INSTALL_MOD_STRIP=1 to the make modules_install command to reduce the size of the resulting installation