In this article, we cover building the kernel and modules for the NVIDIA Jetson TX2 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 TX2.
Presented here are scripts which download the kernel source on to the Jetson TX2 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
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
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.
$ ./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.
The second script, makeKernel.sh, prepares the kernel and modules for building, and then builds the kernel and modules specified.
$ ./makeKernel.sh
The modules are then installed in /lib/modules/
The third script, 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, 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.
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 TX2 with L4T 28.2 using JetPack 3.2.
- 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.
- For L4T 28.1, please visit the earlier article which tells you to git checkout vL4T28.1 after cloning the repository.
The post Build Kernel and Modules – NVIDIA Jetson TX2 appeared first on JetsonHacks.