Build Kernel and Modules – NVIDIA Jetson TX2

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.

12 Comments

  1. Hi and thank you for your valuable tools!
    Any idea if this could work on a Jetson TX1 with with L4T 28.2 using JetPack 3.2?

    Thank you!

  2. Hi Jim. Thanks for all workings and sharings. I’m following your instructions step by step to prepare my tx2 board for using at university project. i’ve installed jetpack 3.2 – 28.2 (uname -r => 4.4.38-tegra // there was no -tegra but i’ve added with your config tool) and i want to use ps3 eye cam at the project, but i’m taking error messages after saved kernel configuration tool while i typing “sudo make modules_prepare” then “make: *** no rule to make target ‘modules_prepare’. Stop

    that i understand no working any “make” comment because of no make file found.

    i would glad with your responses

    • It sounds like you are in the wrong directory for building. If you used the getKernelSources.sh script, and if you are not using the ./makeKernel.sh script, then you need to be in the /usr/src/kernel/kernel-4.4 directory before running make modules_prepare. Good luck on your build.

  3. hi agin Jim,
    thank you for your guidences. i’ve passed the prev issue but i’ve stucked another line. i’ve executed “sudo make prepare_modules” without any warnings but i’ve taken below messages while i’ve typed “sudo make modules” in same folder

    “rm drivers/mics/mods/mods.dtb drivers/mics/mods/mods.dtb.S
    Building modules, stage 2.
    MODPOST 144 modules
    WARNING: could not open drivers/misc/mods/mods.dtb.S: No such file or directory ”

    and there is no gspca_main.ko file in the /lib/modules/4.4.38-tegra/kernel/drivers/media/usb/gspca folder however there is only one file gspca_ov534.ko file in that folder.

    when i try “sudo insmod gspca_ov534.ko” at gspca folder and occured error like below
    “insmod: ERROR: could not insert module gspca_ov534.ko: File exists”
    and then i try cheese application but there is no webcam.

    i’ve checked lsusb -> device 007 – sony playstation eye already exists
    i need your advices againg thank you

  4. hi,kangalow!
    Thanks a lot for all workings and sharings. I’m following your instructions step by step . i’ve installed jetpack 3.2 –L4t 28.2 . when i ,i get these error message!
    “drivers/soc/built-in.o:/usr/src/kernel/kernel-4.4/drivers/soc/tegra/fuse/fuse-tegra.c:130: first defined here
    scripts/Makefile.build:340: recipe for target ‘drivers/built-in.o’ failed
    make[1]: *** [drivers/built-in.o] Error 1
    Makefile:958: recipe for target ‘drivers’ failed”
    could u help me? thank u a lot!

Leave a Reply

Your email address will not be published.


*