JetsonHacks

Developing on NVIDIA® Jetson™ for AI on the Edge

Build Kernel and Modules – NVIDIA Jetson TX2

Note: This article has been updated. Please see the L4T 28.1 build article.

This article covers building a kernel for L4T 27.1. If you are trying to build a kernel for L4T 27.1, you will need to checkout the vL4T27.1 version after cloning the buildJetsonTX2Kernel.git repository. Note that this is different than the steps followed in the video. The kernel source must match the version of L4T that is being built.

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
# For L4T 27.1, do the following:
$ git checkout vL4T27.1

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

67 Responses

  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

    1. JetPack is an installer that places software on the target and host systems. The actual operating system on the Jetson itself is named L4T (Linux for Tegra). As of this writing, JetPack 3.0 installs L4T 27.1 on the Jetson TX2. For a Jetson TX1, JetPack installs L4T 24.2.1, which is the same version that JetPack 2.3 installed. The L4T versions are not the same, so you must follow the instructions for installing Jetson TX1 kernel here: https://jetsonhacks.com/2016/09/28/build-tx1-kernel-and-modules-nvidia-jetson-tx1/
      Please note that this is for advance developers.

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

      1. Hi
        I have the same issue, Image file is not there after $./makeKernel.sh
        so I get : “cannot stat ‘arch/arm64/boot/Image”
        Can you help?
        Thanks

  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.

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

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

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

    1. 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]: https://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.

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

  16. I got this error :

    nvidia@tegra-ubuntu:~/buildJetsonTX2Kernel$ ./copyImage.sh
    cp: cannot stat ‘arch/arm64/boot/Image’: No such file or directory

    1. The message means that the Image is not there, probably because it did not build correctly. If you are building for JetPack 3.0/L4T 27.1 you must use the tag version vL4T27.1 in the buildJetsonTX2Kernel repository. The master is for the new JetPack 3.1/L4T 28.1 version. Thanks for reading!

          1. sorry for that i didn’t provide my information enough
            i install my TX2 with the film
            https://www.youtube.com/watch?v=D7lkth34rgM&t=443s
            and then i want to create a kernel to it
            so i follow the film
            https://www.youtube.com/watch?v=fxWObd1nK4s&feature=youtu.be
            and i also change the branch from master to tag vL4T27.1
            i did
            $ git clone https://github.com/jetsonhacks/buildJetsonTX2Kernel.git
            $ cd buildJetsonTX2Kernel
            and i didn’t do your suggestion
            $ git checkout vL4T27.1
            i just do like the film to the following step
            i create a new local version
            but in the part of usb setting
            i point ‘USB CP210x family with UART Bridge controller’
            to make my radia sensor work
            and i type
            ‘./makeKernel.sh’
            it’s ok until now
            but when i type
            ‘./copyImage.sh’
            the terminal show
            cp: cannot stat ‘arch/arm64/boot/Image’: No such file or directory

            i will do the additional step that you suggestion
            $ git checkout vL4T27.1
            before ‘./getKernelSource.sh’
            the film didn’t do this step , it’s necessary?

            thank you very much

            1. The video is from March, 2017. Since then there has been a new release to L4T 28.1 (JetPack 3.1). The repository has been updated to reflect the new version. However, a tagged version vL4T27.1 was created so that if you have L4T 27.1 you can use those scripts. Therefore you have to checkout those scripts. Hope this helps.

  17. Hi
    Thanks for your great tutorial,
    one question here:

    If I flashed my jetson TX2 board with latest jetpack 3.1,
    do I need to modified any of the scripts or settings to keep match to it?
    Or the script will figure it out to load the match kernel.

    my “$rname -r” returns “4.4.38-tegra” which is different from the demo you showed in the video.

    Finally, from the above discussion, you mentioned that I have to make sure the kernel on SSD and eMMC are consistent. How can I do that?

    Thanks for your help!

  18. Try to enable KVM in TX2. Following the instruction, but failed.

    in xconfig file, I choose Virusualization option with KVM support.

    during makeKernal.sh step, it reports errors.

    include/linux/irqchip/arm-gic.h: Assembler messages:
    include/linux/irqchip/arm-gic.h:100: Error: unknown mnemonic `enum’ — `enum domain_gic_pm_event{‘
    include/linux/irqchip/arm-gic.h:101: Error: unknown mnemonic `mod_domain_power_on’ — `mod_domain_power_on,’
    include/linux/irqchip/arm-gic.h:102: Error: unknown mnemonic `mod_domain_power_off’ — `mod_domain_power_off’
    include/linux/irqchip/arm-gic.h:103: Error: junk at end of line, first unrecognized character is `}’
    scripts/Makefile.build:297: recipe for target ‘arch/arm64/kvm/vgic-v2-switch.o’ failed
    make[1]: *** [arch/arm64/kvm/vgic-v2-switch.o] Error 1
    Makefile:973: recipe for target ‘arch/arm64/kvm’ failed
    make: *** [arch/arm64/kvm] Error 2

  19. Hi, got my Jetson TX2 today – very proud :). I have a Scanse Sweep LIDAR. Stock-Kernel is 4.4.15-tegra. So I need to build L4T27.1. I used your script, Linux/arm64 4.4.15 Kernel Configurator came up, but when I try to add the ftdi driver for sweep there is no option-box, just the tx usb ftdi single port… I am confused ? What did I do wrong?
    Do I can upgrade to L4T28.1 later?I am new to this Kernel-building. Is my Jetson TX2 not compatible?

    Thank in advance 🙂

    Greetings Thomas

    1. Okay, I fixed the first issue by adding the usb to serial support first. Then I can choose the devices.
      So I am left with the last question -> How can I upgrade my Jetson tx2 to L4T28.1?

      1. You should use JetPack 3.1 on your host PC to upgrade the Jetson to L4T 28.1. This will erase the Jetson and place the new OS on it. You will need to rebuild the kernel for the new OS. Thanks for reading!

  20. Hello, I have some questions. Is it possible to communicate with internal CAN via this installation?
    Or do you have to rebuild the CAN communication build again?

    1. You have to build the appropriate CAN modules for the kernel that you are using. This article did not cover the specific CAN settings, but the method is the same. Thanks for reading!

  21. Thank you for answer. Is there a kernel build video that I can refer to when trying to communicate internal CAN0, CAN1?

  22. What does check and dot mean when you click on a square box in the kernel configuration screen?
    Checking the CAN related box and making a make, is it a build?

  23. How much storage does building the kernel require? I ran ./makeKernel.sh and ran into `net/netfilter/nf_nat_ftp.mod.c:22:1: fatal error: closing dependency file net/netfilter/.nf_nat_ftp.mod.o.d: No space left on device
    “depends=nf_conntrack_ftp,nf_nat”;` halfway through. I tried uninstalling a few packages but I’m afraid it’s not enough. What would be the best way to proceed?

    1. It depends on what you are trying to do. If you are trying to build the entire kernel, probably the only reliable way is to start with a clean JetPack install, and then build the kernel. If you are attempting to just build modules, the command $ make modules would probably use less memory. If you cannot clear enough space on the Jetson for a build, then you should build the kernel on a PC. Thanks for reading.

  24. I had already build kernel for TX2 ,but after that, I can’t use yolo with GPU,I want know why? before I build kernel ,I can run yolo with GPU ,after build ,I can’t run yolov2, it’s show core dumped .anyone can help me ? it’s important
    to me !!!!

  25. Thanks for updating this for Jetpack 3.2.

    I’m currently trying to install kernel modules for an LTE modem according to these instructions:
    ftp://77.47.193.10/pub/pavlov/Distrib/UnitedHelp/Datasheet/Quectel%20EC20%20-%20Multi-mode%20LTE%20Module/User%20Guide/Quectel_WCDMA%20LTE_Linux_USB_Driver_User_Guide_V1.5.pdf

    The instructions call fo modifying various driver source files eg:
    usr/src/kernel/kernel-4.4/drivers/usb/serial/qcserial.c
    usr/src/kernel/kernel-4.4/drivers/net/usb/qmi_wwan.c

    So I edit these files, and then run makeKernel and copyImage – but it appears that the modules are not being installed. Am I editing the correct files?

    Cheers

  26. I’ve also modified the config according to the instructions:
    Enable CONFIG_USB_SERIAL_OPTION
    [*] Device Drivers →
    [*] USB Support →
    [*] USB Serial Converter support →
    [*] USB driver for GSM and CDMA modems

    Enable CONFIG_USB_NET_QMI_WWAN
    [*] Device Drivers →
    -*- Network device support →
    USB Network Adapters →
    {*} Multi-purpose USB Networking Framework
    QMI WWAN driver for Qualcomm MSM based 3G and LTE modems

    I’ve also noticed that the config is retained after I install – despite the guide saying “The .config file is not saved during the installation of the kernel”. This also leads me to believe that the install is somehow not working.

    Is there somewhere I can see a log of the build and the install?

    Thanks again for your help!

  27. Are you compiling this onboard the Jetsons eMMC, or an external device like a SSD?
    The .config is located in the source tree. the intention of the .config comment was to say that if you erase the source tree, then the .config file that you created is erased. I’ll change that wording in the article.

    1. I’m compiling it on the Jetson’s eMMC. Now I understand the comment about the .config file.

      I know that the kernel updates I’m making are having some effect since I tried changing the string appended to the end of the kernel name as you do in your Youtube video – and that worked. But perhaps the issues I’m having are particular to this LTE module.

      In particular the part of the instructions I linked to which say that you must remove references to “Acer Gobi 2000 Modem device (VP413)” in [KERNEL]/drivers/usb/serial/qcserial.c and [KERNEL]/drivers/net/usb/qmi_wwan.c seem to have no effect – when I connect the modem it’s detected as one of these devices.

  28. gzip: /proc/config.gz: No such file or directory
    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    qt5-default is already the newest version.
    The following packages were automatically installed and are no longer required:
    libqpdf13 linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic
    linux-image-4.4.0-31-generic linux-image-extra-4.4.0-31-generic
    Use ‘apt-get autoremove’ to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 139 not upgraded.
    ./scripts/getKernelSources.sh: line 8: cd: /usr/src/kernel/kernel-4.4.: No such file or directory
    make: *** No rule to make target `xconfig’. Stop.

    1. Is there a question here? You don’t state which machine you are running on, which version of L4T and Jetson or anything that would allow someone to help you. That you do not have the kernel source in /usr/src/kernel indicates a failed download. That you do not have /proc/config.gz indicates that you have an invalid install. What version of JetPack did you use to install L4T?

  29. Hardware info:
    Linux manifold2 4.4.38+ #2 SMP PREEMPT Mon Jun 3 20:19:02 CST 2019 aarch64 aarch64 aarch64 GNU/Linux
    Current Kernel version: Linux 4.38+
    Distributor ID: Ubuntu
    Description: Ubuntu 16.04.6 LTS
    Release: 16.04
    Codename: xenial

    I want to let the TX2 to support SOC camera from Lumenera, but I met problems when I configuring and compiling the Kernel with the following steps.
    1. Edit the script getKernelSources.sh and change the lat line ti “make menuconfig” an save.
    2. Run ./getKernelSources.sh.
    (1) On the kernel build configuration,local version is named after “-tx2-xx”.
    (2) Go back to the menu and go to DeviceDrivers–>Multimedia support->V4L platform devices.
    Select “”SOC camera support” by hitting SPACE BUTTON and the letter is shown.
    (3) Escape and save the .config.
    3.Run ./makekernel.sh.
    The error is shown.
    ————————————————————–
    Source Target:
    scripts/kconfig/conf –silentoldconfig Kconfig



    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
    —————————————————————–
    Pls help me find out what cause the meters, thanks!

  30. Just to confirm if all goes well and no errors, there should be a /usr/src/kernel folder and /usr/src/hardware folder right?

  31. Don’t you have a version for L4T 32.2.1?
    I tried to get it from your repository but the 28.2.1 is cominho..
    ($git checkout -b L4T32.2.1 remotes/origin/L4T32.2.1)

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