Note: This article has been updated. Please see the L4T 28.1 build article.
This article covers building a kernel for L4T 27.1. If you are trying to build a kernel for L4T 27.1, you will need to checkout the vL4T27.1 version after cloning the buildJetsonTX2Kernel.git repository. Note that this is different than the steps followed in the video. The kernel source must match the version of L4T that is being built.
In this article, we cover building the kernel onboard the NVIDIA Jetson TX2. Looky here:
Background and Motivation
Note: This article is for intermediate users, and the methods within are somewhat experimental. You should be familiar with the purpose of the kernel. You should be able to read shell scripts to understand the steps described.
With the advent of the new Jetson TX2 running L4T 27.1 with the 4.14 kernel, NVIDIA recommends using a host PC when building a system from source. See the Linux for Tegra R27.1 web page where you can get the required GCC 4.8.5 Tool Chain for 64-bit BSP.
The boot load sequence is more sophisticated on the Jetson TX2 in comparison to the TX1. In addition to the Uboot boot loader, there are additional loaders for hardware support. The previously mentioned tool chain is useful in building those features.
If you are building systems which require generating the entirety of Jetson TX2 system, those are good options. For a person like me, it’s a little overkill. Most of the time I just want to compile an extra driver or three as modules to support some extra hardware with the TX2. What to do, what to do …
Hack of course! With a little bit of coffee and swearing I was able to compile the kernel with modules on a Jetson TX2 itself.
The script files to build the kernel on the Jetson TX2 are available on the JetsonHacks Github account in the buildJetsonTX2 repository.
$ git clone https://github.com/jetsonhacks/buildJetsonTX2Kernel.git
$ cd buildJetsonTX2Kernel
# For L4T 27.1, do the following:
$ git checkout vL4T27.1
There are three main scripts. The first script, getKernelSources.sh gets the kernel sources from the NVIDIA developer website, then unpacks the sources into /usr/src/kernel.
After the sources are installed, the script opens an editor on the kernel configuration file. In the video, the local version of the kernel is set. The stock kernel uses -tegra as its local version identifier. Make sure to save the configuration file when done editing. Note that if you want to just compile a module or two for use with a stock kernel, you should set the local version identifier to match.
The second script, makeKernel.sh, fixes up the makefiles so that the source can be compiled on the Jetson, and then builds the kernel and modules specified.
The modules are then installed in /lib/modules/
The third script, copyImage.sh, copies over the newly built Image and zImage files into the /boot directory.
Once the images have been copied over to the /boot directory, the machine must be restarted for the new kernel to take effect.
The kernel and module sources, along with the compressed versions of the source, are located in /usr/src
After building the kernel, you may want to save the sources off-board to save some space (they take up about 3GB) You can also save the boot images and modules for later use, and to flash other Jetsons from the PC host.
For a lot of use cases, it makes sense to be able to compile the kernel and add modules from the device itself. Note that it is new, and not thoroughly tested at this point. Use it at your own risk.
- The video above was made directly after flashing the Jetson TX2 with L4T 27.1 using JetPack 3.0.
- If you encounter the error ‘cannot stat:’ when you run the copyImage.sh script, it means that the Image file did not build. You should check for error messages generated in the makeKernel.sh step.