Build Kernel and Modules – NVIDIA Jetson TX2

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.

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

$ ./makeKernel.sh

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.

$ ./copyImage.sh

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

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. Note that it is new, and not thoroughly tested at this point. Use it at your own risk.

Note

The video above was made directly after flashing the Jetson TX2 with L4T 27.1 using JetPack 3.0.

29 Comments

  1. Hi Jim

    I’m trying to compile the Kernel for a TX1 using the Jetpack 3.0, will this scripts will work or shall I use the ones you did on the Kernel build for TX1 (but this are not Jetpack 3.0

  2. Thanks a lot for your great content and this video! It helped me to finally get my rplidar working on the Jetson TX2 (the cp2102-driver was missing).

  3. I put a TX2 SOM (which you can get from Arrow now) on a TX1 Jetson carrier board and am getting significantly enough different error messages during a kernel compile to lead me to believe that these boards are subtly incompatible. I can give you specifics if you want, but I wanted to know if this was expected. Who would buy a SOM if it was? JTX2s are pretty much the same price anyhow.

  4. I get a error when I run the command ‘./copyImage.sh’:
    cp: cannot stat ‘arch/arm64/boot/zImage’: No such file or directory
    cp: cannot stat ‘arch/arm64/boot/Image’: No such file or directory

    But I success in before two step.
    Why??

  5. Before and after building the kernel I get the same error when running tensorflow:

    stream_executor/cuda/cuda_driver.cc:509] failed call to cuInit: CUDA_ERROR_NO_DEVICE
    I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (jet): /proc/driver/nvidia/version does not exist
    W tensorflow/compiler/xla/service/platform_util.cc:61] platform CUDA present but no visible devices found

    But I am able to build and run the NVIDIA samples. Is there some cuda device driver install I’m missing? I don’t see anything like that in the kernel config.

      • This turned out to be a permissions problem. I made a new user and the account needed to be in the ‘video’ group. The error message really threw me off.

        • Interesting. When people ask questions on this website, I’m always tempted to just say “It must be a permissions problem”. That seems to be the cause of 80% of the issues reported.

  6. Hey thanks for all your help and tutorials. Its awesome.

    While doing this after i ./getkernelsources.sh I get error “Could not find Qt via plg-config
    Makefile:531: recipe for target ‘xconfig’ failed
    Make: ***[xconfig] Error 2

  7. I ran this script EXACTLY as directed on the video and the web page and everything seemed to go well. However, after reboot, my wired ethernet refuses to cooperate. Switching on the wifi worked but of course it is considerably slower than wired. Any ideas what I did wrong and/or how to correct it? Reflash everything from scratch yet again? If so, running this kernel modification will probably yield the same result. Help, someone, please!

    • Hi David,
      I’ve never seen this error, so I am unable to offer any help. You could try:
      apt-get remove –purge resolveconf
      then
      apt-get install –reinstall resolvconf
      but it’s all just guess work on my part. You’ll have to use JetPack to flash your machine again.

  8. Forgot to mention it is a TX2 and in preparation for using realsense R200.

    Error message is: active connection removed before it was initialized. Web searches give answers all over the place but none mention the kernel having been rebuilt.

  9. Hi Jim,
    Nice work! Thanks for sharing your knowledge.
    I have one big question:
    Assuming I have followed your procedures.
    I need to build my own driver for IMX290 image sensor, my plan is to copy the existing IMX sensor driver and edit it to work for IMX290. Question: I just need to run the MakeKernel.sh and CopyImage.sh to compile and run my driver? Am I correct? Or is there any other things to do? Sorry I am still new to linux systems. Thanks

    • I have not built any camera drivers. My understanding is that there are some other things you need to do in order to get them to work in addition to compiling the module. The steps in this article will build the module and kernel, which will probably one of the steps. You should ask if others have any experience with this sensor on the NVIDIA Jetson TX2 forum: https://devtalk.nvidia.com/default/board/188/jetson-tx2/

      Thanks for reading!

  10. Ran the getKernelSources script and got:
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-eqos.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-spi.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-prod.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-base.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-thermal.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-power-domain.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-a57-cpuidle.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-ufshc.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-cpus-4A.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-actmon.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-cpus-2D2A.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-reilly-prod.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-uart.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-trusty.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-vcm-prod.dtsi
    hardware/nvidia/soc/t18x/kernel-dts/tegra186-soc/tegra186-soc-sata.dtsi
    gzip: /proc/config.gz: No such file or directory
    HOSTCC scripts/basic/fixdep
    CHECK qt
    SHIPPED scripts/kconfig/zconf.tab.c

  11. Is there a file at /proc/config.gz
    I just opened up a brand new system today. After flashing with JetPack 3.0, I built the kernel using these scripts and did not encounter any issues. Is this a fresh system you are working from?

  12. hi Jim, all,
    I run a TX2, and boot on SSD
    I followed all the process, renaming kernel “-elpimous-V1.0”
    after rebooting, “uname -r” tells me 4.4.15-tegra

    saving modifs in file was ok, no errors on the 3 .sh execution.

    But at start, it doesn’t load my kernel !!

    Is the problem due to my SSD boot ?
    Any help, please friends
    Vincent

  13. Hello,
    I didn’t have success. Now, I know why and I send…

    [u]Add module on kernel[/u]:

    [b]Board [/b]: Jetson TX2
    [b]Boot [/b]: SSD
    [b]Howto [/b]: http://www.jetsonhacks.com/2017/03/25/build-kernel-and-modules-nvidia-jetson-tx2/

    –> just after the command : ./copyImage.sh,

    Image is finished, ready to read… But,
    Image is on a wrong directory (on the SSD Disk !!!)
    You must put it on the TX2 board 32Go disk !

    backup image in board disk :
    sudo cp /media/nvidia/xxxxxx/boot/Image/media/nvidia/xxxxxx/boot/Image_backup

    sudo cp /boot/Image/media/nvidia/xxxxxx/boot/Image

    sudo reboot

    Enjoy

    Vincent.

  14. Success. Thanks for writing this post.

    I noticed that the /boot directory on my Jetson TX2 did not have a zImage – so when installing a new kernel, I refrained from copying zImage and just copied Image. This appeared to work fine – the board booted into the new kernel without issue.

    • You’re welcome, I am glad you found it useful. I believe that there were some changes since the TX1, the zImage doesn’t appear on the TX2. Since this is a “Developer Preview” version, I’m going to wait to see what the next release brings. Thanks for reading!

  15. Hi Jim,
    Thanks for all your videos.

    I received the following error when I was making the Kernel.

    rm: invalid option — ‘0’
    Try ‘rm –help’ for more information.
    Makefile:1137: recipe for target ‘_modinst_’ failed
    make: *** [_modinst_] Error 1

    Is there a way I can fix this error? Thanks!

Leave a Reply

Your email address will not be published.


*