Build Kernel and Modules – NVIDIA Jetson TX1

In this article, we cover building the kernel and modules for the NVIDIA Jetson TX1 running L4T 28.2. We also build the CH341 module, which is a USB to serial converter. Looky here:

Background

Note: This article is for intermediate users. You should be familiar with the purpose of the kernel. You should be able to read shell scripts to understand the steps described.

Note: The kernel source must match the version of L4T that has been flashed onto the Jetson. For example, here we use the kernel source for L4T 28.2 with L4T 28.2. Kernel versions are not compatible across releases.

NVIDIA recommends using a host PC when building a kernel from source. See the Linux for Tegra R28.2 web page where you can get the required information about GCC Tool Chain for 64-bit BSP.

If you are building systems which require a large amount of kernel development, that is a good option. 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 TX1.

Presented here are scripts which download the kernel source on to the Jetson TX1 itself, builds the kernel image and modules, and installs the modules and copies the kernel Image to the boot directory. The video above shows how to select the CH341 module and build it as an external module.

Installation

Note: On the Jetson TX1, space is at a premium. We advise that you build the kernel and modules immediately after flashing the Jetson.

The script files to build the kernel on the Jetson TX1 are available on the JetsonHacks Github account in the buildJetsonTX1Kernel repository.

$ git clone https://github.com/jetsonhacks/buildJetsonTX1Kernel.git
$ cd buildJetsonTX2Kernel
$ git clone v1.0-L4T28.2

There are five main scripts.

getKernelSources.sh

The first script, getKernelSources.sh gets the kernel sources from the NVIDIA developer website, then unpacks the sources into /usr/src/kernel.

$ ./getKernelSources.sh

After the sources are installed, the script opens an editor on the kernel configuration file.

Note: The local version needs to be set to match the release that you are building. For example, if you are building modules for a stock kernel, then the local versions should be -tegra which makes the kernel release name 4.4.38-tegra. If you are building a custom kernel, then you should add your own local version. In the video above, we used -jetsonbotv0.1 which results in 4.4.38-jetsobotv0.1.

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 stock version.

getKernelSourcesNoGUI.sh

getKernelSourcesNoGUI.sh gets the kernel sources from the NVIDIA developer website, then unpacks the sources into /usr/src/kernel.

$ ./getKernelSourcesNoGUI.sh

This script is useful for scripting purposes, SSH purposes, and in the case where you want to use an alternate method to edit the .config file.

makeKernel.sh

makeKernel.sh prepares the kernel and modules for building, and then builds the kernel and modules as specified.

$ ./makeKernel.sh

The modules are then installed in /lib/modules/

copyImage.sh

copyImage.sh copies over the newly built Image file into the /boot directory.

$ ./copyImage.sh

Note: This is probably overly simplistic. In most development cases (and as shown in the video), you will want to duplicate the stock kernel Image file, and modify the file /boot/extlinux/extlinux.conf so that you have the option to boot from the the stock image or the newly created image through the serial console. This is in case something, ahem, goes wrong. Because this is related to your specific development needs, this exercise is left to the reader.

Once the images have been copied over to the /boot directory, the machine must be restarted for the new kernel to take effect.

Note: The copyImage.sh script simply copies the Image file to the /boot directory of the current device. If you are using an external device such as a SSD as your root directory and still using the eMMC to boot from, you will need to copy the Image file to the /boot directory of the eMMC.

removeAllKernelSources.sh

removeAllKernelSources.sh removes all of the kernel sources and compressed source files. You may want to make a backup of the files before deletion.

$ ./removeAllKernelSources.sh

Spaces!

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.

Conclusion

For a lot of use cases, it makes sense to be able to compile the kernel and add modules from the device itself. Hopefully this article helps along this path.

Note

  • The video above was made directly after flashing the Jetson TX1 with L4T 28.2 using JetPack 3.2.
  • For earlier version of L4T, look in the tags in the Github buildJetsonKernelTX1 repository.

2 Comments

Leave a Reply

Your email address will not be published.


*