JetsonHacks

Developing on NVIDIA® Jetson™ for AI on the Edge

Build Kernel and Modules – NVIDIA Jetson TX2

Note (September, 2021): While not officially deprecated, this article points to the outdated JetsonHacks Github repository buildJetsonTX2Kernel. The later L4T versions for building the Jetson kernel and modules are now in: jetson-linux-build https://github.com/jetsonhacks/jetson-linux-build

Original Article:

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.
Facebook
Twitter
LinkedIn
Reddit
Email
Print

19 Responses

  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

    1. 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!

  5. After having built a kernel and copied the image, how to roll back to the original one? Can I just delete the image or should I have backed up the original image?

  6. Thank you for your tutorials.
    But in the process I confronted a problem when I ran the command “./getKernelSources.sh”, I did exactly the same thing I don’t know why I have this issue.

    ./scripts/getKernelSources.sh: line 6: cd: /usr/src/kernel/kernel-4.4: No such file or directory

  7. It’s an embarrassing mistake because I can not connect to the nvida website to download the source. I have my VPN installed and solve this problem. Thank you for your reply.

  8. I wanner to configure the jetson TX2 to support SOC camera from the Lumenera, but I failed to compiling the kernel with the following steps.
    1. I had modified the getKernelSources.sh in /buildJetsonTx2Kernel/scripts, the last line changed to “make menuconfig”.
    2. Run ./getKernelSources.sh, and local vision with “-tx2-XXxx”, then go to “DeviceDrivers”–>Multimedia support–>V4L platfor devices.
    Select “SOC camera support ” by hitting space button, the letter is shownn.
    3. Escape with save, the configuration is saved with .config.
    4. Run ./makeKernel.sh.
    Error is `tegra_bpmp_debugfs_add_file’ mutiple definition, conflicting components:
    “drivers/cpufreq/tegra194_cpufreq.o” and the
    “/usr/src/buildJetsonTx2Kernel/scripts/kernel/nvidia/include/soc/tegra/tegra_bpmp.h”.
    ————————————————————————–
    Source Target:
    CHK include/config/kernel.release
    CHK include/generated/uapi/linux/version.h
    CHK include/generated/utsrelease.h
    CHK scripts/mod/devicetable-offsets.h
    CHK include/generated/timeconst.h
    CHK include/generated/bounds.h
    CHK include/generated/asm-offsets.h
    CALL scripts/checksyscalls.sh
    CHK include/generated/compile.h
    CHK kernel/config_data.h
    LD drivers/cpufreq/built-in.o
    drivers/cpufreq/tegra194_cpufreq.o: In function `tegra_bpmp_debugfs_add_file’:
    /usr/src/buildJetsonTx2Kernel/scripts/kernel/nvidia/include/soc/tegra/tegra_bpmp.h:72: multiple definition of `tegra_bpmp_debugfs_add_file’
    drivers/cpufreq/tegra_cpufreq.o:/usr/src/buildJetsonTx2Kernel/scripts/kernel/nvidia/include/soc/tegra/tegra_bpmp.h:72: first defined here
    scripts/Makefile.build:509: recipe for target ‘drivers/cpufreq/built-in.o’ failed
    make[2]: *** [drivers/cpufreq/built-in.o] Error 1
    scripts/Makefile.build:649: recipe for target ‘drivers/cpufreq’ failed
    make[1]: *** [drivers/cpufreq] Error 2
    Makefile:1104: recipe for target ‘drivers’ failed
    make: *** [drivers] Error 2
    make: *** Waiting for unfinished jobs….

    real 0m13.410s
    user 0m12.208s
    sys 0m10.112s
    Make did not build
    Retrying …
    CHK include/config/kernel.release
    CHK include/generated/uapi/linux/version.h
    CHK include/generated/utsrelease.h
    CHK include/generated/bounds.h
    CHK include/generated/timeconst.h
    CHK include/generated/asm-offsets.h
    CALL scripts/checksyscalls.sh
    CHK scripts/mod/devicetable-offsets.h
    CHK include/generated/compile.h
    CHK kernel/config_data.h
    LD drivers/cpufreq/built-in.o
    drivers/cpufreq/tegra194_cpufreq.o: In function `tegra_bpmp_debugfs_add_file’:
    /usr/src/buildJetsonTx2Kernel/scripts/kernel/nvidia/include/soc/tegra/tegra_bpmp.h:72: multiple definition of `tegra_bpmp_debugfs_add_file’
    drivers/cpufreq/tegra_cpufreq.o:/usr/src/buildJetsonTx2Kernel/scripts/kernel/nvidia/include/soc/tegra/tegra_bpmp.h:72: first defined here
    scripts/Makefile.build:509: recipe for target ‘drivers/cpufreq/built-in.o’ failed
    make[2]: *** [drivers/cpufreq/built-in.o] Error 1
    scripts/Makefile.build:649: recipe for target ‘drivers/cpufreq’ failed
    make[1]: *** [drivers/cpufreq] Error 2
    Makefile:1104: recipe for target ‘drivers’ failed
    make: *** [drivers] Error 2
    Make did not successfully build
    Please fix issues and retry build
    —————————————————————–
    Can you help me find what is cause the issue?

Leave a Reply

Your email address will not be published. Required fields are marked *

Disclaimer

Some links here are affiliate links. If you purchase through these links I will receive a small commission at no additional cost to you. As an Amazon Associate, I earn from qualifying purchases.

Books, Ideas & Other Curiosities