# Build Kernel and ttyACM Module – NVIDIA Jetson TX2

In this article, we cover building the kernel and modules for the NVIDIA Jetson TX2. We also build the ACM module, which allows the Jetson to communicate with devices that report through ttyACM. Looky here:

## Background

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.1 with L4T 28.1. Kernel versions are not compatible across releases.

With the advent of the production version of L4T 28.1 for the NVIDIA Jetson TX2, NVIDIA recommends using a host PC when building a system from source. See the Linux for Tegra R28.1 web page where you can get the required GCC 4.8.5 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.

For example, one of the modules that I need is used to support USB ACM devices. Some USB devices report as USB, others report as ACM. Here’s an article explaining the good bits about what that means. Many devices, such as a Hokoyo LIDAR and some Arduinos, report as ACM devices.

Presented here are some scripts which download the kernel source on to the Jetson TX2 itself, modifies the Makefiles so that it will compile onboard the Jetson, and then copies the kernel Image into the boot directory. The video above shows how to select the ACM module and add it to the Image. The options are:

USB Modem (CDC ACM) support
CONFIG_USB_ACM

## 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. Note: The copyImage.sh script 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. ### Note • The video above was made directly after flashing the Jetson TX2 with L4T 28.1 using JetPack 3.1. • 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 27.1, please visit the earlier article which tells you to git checkout vL4T27.1 after cloning the repository. #### 58 Comments 1. Thanks for your fast respond to the latest jetpack release. I’ve successfully include the CP2102 (Cygnal Integrated Products, Inc. CP210x UART Bridge) driver into kernel and recognized the rplidar as ttyUSB0 device after install the kernel. • You are welcome. Glad to hear you got it working! • Hi,Bro. I have a rplidar a2 and tx2 with jetpack 3.1 and jetsonhacks kernal. However, I can’t see any ports when I type: ls -l /dev |grep ttyUSB Do u have any suggestions? • How did you compile the CP210x module? What is the result of ‘uname -a’ • uname -a: 4.4.38 I didn’t compile the cp210x module. I use lsusb and find : Bus 001 Device 005: ID 10c4:ea60 Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light Then I download ROS_rplidar pkg from github. And use ls -l /dev |grep ttyUSB0, but there is nothing. I check the /dev , and there is no tty port called ttyUSB. • The stock kernel does not have a driver for the CP210x, you will need to compile a module for it. Because there is no driver, the ttyUSB port is not created. • nvidia@tegra-ubuntu:~$ ls -l /dev |grep ttyUSB
nvidia@tegra-ubuntu:~$sudo chmod 666 /dev/ttyUSB0 chmod: cannot access ‘/dev/ttyUSB0’: No such file or directory nvidia@tegra-ubuntu:~$ uname -r
4.4.38
nvidia@tegra-ubuntu:~$2. I’m having trouble, I get error: ‘ENODEV” undeclared during the make -j6 Image command of the makeKernel.sh script. Any ideas? • What version of L4T do you have installed? • Uh, I’m not sure. uname -r gives 4.4.15-tegra and I just bought the it new about a month ago, so I’m assuming it ships latest and greatest…? It is a TX2 running Ubuntu 16.04 with the GUI. How do I check the version of L4T? • You are running an earlier version of L4T. These scripts are for L4T 28.1, which is installed when the system is flashed with JetPack 3.1. There is a tagged version in the Github repository for L4T 27.1. Note that the firmware that is shipped from the factory is usually just a placeholder when the devices are put into production. NVIDIA recommends flashing the device with the latest version of JetPack to upgrade to the latest and greatest. Thanks for reading! 3. Oh, sorry to waste your time with something I could have figured out by doing a little more digging. Thank you! • You’re welcome. And no worries, this is not really straightforward stuff and requires a little outside help sometimes. 4. Hi , I’m working with TX1 and also need to enable ttyACM . My TX1 also run with Jetpack 3.1 . As I know , the “L4T 28.1” could be use for TX1 & TX2 . If I modify the “scripts/getKernelSources.sh” to”sources/kernel_src-tx1.tbz2″ for Tar Extract , could I Still use your build scripts to re-build Kernel ? Thanks • It’s pretty close. I’m working on an article now about the process. One of the patches isn’t used on the TX1 (I recall it’s the sound one). The rather sticky part is that there’s no free space left on the device after building the kernel, so after you copy the Image, you will need to make more space. There’s several ways to do that, the easiest is to copy the compressed sources and/or the kernel sources to external media and delete them from the /usr/src directory. Hope this helps. • Thanks a lot . The free space of TX1 is not problem for me , because I used the 64G SD Card for root directory. After modify the ”sources/kernel_src-tx1.tbz2″ for Tar Extract , I could be use your build scripts to re-build kernel successful . Because I just need the “cdc-acm.ko” , the local version I still used “-tegra” for make xconfig. After append the module name “cdc-acm” to /etc/modules-load.d/modules.conf , It seems work normally with my TX1 now. • Great to hear that you got it to work! 5. Awesome post, was looking up TX2 and CDC, couldn’t have been more perfect timing! • I’m glad you found the article useful. Thanks for reading! 6. Hi, thanks for the tutorials! I also have a TX2 with JP 3.1. My system is running from an external SSD, so I built the kernel exactly as shown in this video and then copied the Image to the /media/……/boot/Image location to install it on the on-board SSD. After rebooting, the ‘uname -a” does show my customized kernel string, however, I don’t see any /dev/ttyACM* devices in the /dev/ directory. I tried connecting a VESC via USB and still don’t see /dev/ttyACM0 or any changes in /var/log/syslog. Any ideas? Thanks! • Sorry, my bad! Ignore the previous question. I discovered that the VESC must be powered separately before the /dev/ttyACM0 port shows up. It’s now working! • I’m glad you got it to work! Thanks for reading. 7. Can we enable TX2 spi using this procedure?? 8. Thank you for this post, very useful. I did the patch for R27.1 to enable ttyACM acquisition. Using ssh I can check that the problem is resolved and it lists my external device as ttyACM0 but I cannot login directly to TX2 through the graphical interface anymore. It just shows a blank purple screen. Any idea what has happened? • Actually, TX2 was out of memory. deleted the /usr/src/kernel folder through ssh connection, rebooted and everything looks good now. Thanks. • I’m glad you got it to work, and thanks for reading! 9. Hi Kangalow, Thanks for your tutorial. I have built kernel with TX2 L4T 28.1, JetPack 3.1, use master version in your github. – In getKernelSources.sh step, in Kernel Configure windows, I checked all option of CAN (CAN bus subsystem support and CAN Device Drivers, images: CAN_1.png and CAN_2.png), ACM and USB CP210x family of UART Bridge Controllers, SPI (SPI.png) – Run makeKernel.sh, I have a problem, it seem build CAN driver error. I dont know what i doing wrong. But don’t check CAN (default option of Kernel Configure), i build Kernel successful but CAN does not active (terminal output in link below). Could I do to use CAN in L4T 28.1. Thank you very much. link images and terminal output when I run makeKernel.sh: https://drive.google.com/drive/folders/0B_jaOTwY1bQuTVA4UmhBeDlyTlU?usp=sharing • Hi Anh, Unfortunately I don’t know enough about the CAN area to be of much help on this. I know there have been lengthy discussions on the official NVIDIA Jetson TX2 forum: https://devtalk.nvidia.com/default/board/188/jetson-tx2/ It’s worth going through some of the threads and see if you can find anything useful, and then ask questions there. The forum has quite a few developers that seem skilled in the CAN bus area, and the NVIDIA engineers hang out there too. I’m under the impression that the CAN drivers need to be built as modules (not built in to the kernel), and that the device tree needs to be modified for SPI. But I don’t know enough about it to be of much help. Thanks for reading! • Thanks for your reply. Thank you very much. I wish you have a good day. 10. Thanks for your reply. Thank you very much. I wish you have a good day. • Which version of L4T are you running? • head -n 1 /etc/nv_tegra_release says “R28 (release), revision 1.0” • A couple of more questions. Are you attempting to build the kernel directly after a flash from JetPack, or have you been doing development on this machine before? Which optional packages did you install during the JetPack installation? The flashed TX2 in the video had all options installed, it could be that one of those packages bring in some tools that are missing from a bare bones build that I am unaware of. • I followed the video for this site while flashing with jetpack I believe. It was a few weeks ago. I’m pretty sure I installed all of them. • And have you been working on the TX2 since the flash, or did you build the kernel directly thereafter? Could you check to make sure that the missing symbols are actually in the source tree? The source should be in /usr/src/kernel/kernel-4.4 On this machine, the symbols are located in /usr/src/kernel/kernel-4.4/include/linux/irq.h It could be the include paths are messed up for some reason. • Looks like my reply went to the wrong indent level. I didn’t build the kernel directly after. 11. It doesn’t look like the symbols are in there: struct irq_data { u32 mask; unsigned int irq; unsigned long hwirq; struct irq_common_data *common; struct irq_chip *chip; struct irq_domain *domain; #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY struct irq_data *parent_data; #endif void *chip_data; }; Isn’t this building there kernel? I didn’t build the kernel after flash. What do I need to do for that? • There is a macro: #define __irqd_to_state(d) ((d)->common->state_use_accessors) in irq.h This macro should be called in /usr/src/kernel/kernel-4.4/kernel/irq/internals.h In your case, this doesn’t seem to be the case. In the internals.h file, is the source in the function irqd_set_move_pending(struct irq_data *d) __irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING; On a stock TX2, it’s using gcc version 5.4.0 to build the kernel$ gcc -v

• Seems like it:
/*
* Manipulation functions for irq_data.state
*/
static inline void irqd_set_move_pending(struct irq_data *d)
{
__irqd_to_state(d) |= IRQD_SETAFFINITY_PENDING;
}

I also have gcc 5.4. How do I get the correct source?

• I believe that you have the correct source, you have the script file. Just check to see if it grabbed 28.1 sources.

It feels like an issue with the include paths, or something equally terrible. Here’s what I always do:
Flash the Jetson
Build the kernel
That’s the demonstration above.
My guess is what happened in your case is that some other tools were installed that merrily went on their way and changed some settings, include paths or something here and there.

Unfortunately it’s difficult for me to debug, since I don’t have a build that fails. You can build a disk image that I can debug, though I don’t know if I will be able to find the issue. The most straightforward path is to reflash the Jetson and then build the kernel directly thereafter.

• Ok. I’ll give that a go. So I reflash with the Jetpack instructions on this site then immediately follow these instructions afterward?

• Yes

12. hi all.
I don’t have success with kernel !!
I’m booting and working on ssd,

here is my process :
* ./getKernelSources.sh
* in local version : ‘-alfred-v1.0’
* add spidev and acm (I really need them !!)
* save
* ./makeKernel.sh
* ./copyImage.sh
* sudo reboot
and voila.

> uname -r
4.4.38-tegra
I shoud have 4.4.38-alfred-v1.0, with acm and spi

no changes ! I don’t anderstand why my new kernel doesn’t appear ! I did all needed parts !
Thanks, Vincent

Note: The copyImage.sh script 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.

The Image file is located in
/usr/src/kernel/kernel-4.4/arch/arm64/boot/
on the SSD.

The Jetson boots from eMMC, therefore you must place the Image file into the /boot directory on the eMMC. The copyImage.sh file simply copies the Image file to the /boot directory of the current device, it does not know if the current device is the eMMC or not.

13. u didn’t copy image to imagessd

14. @kangalow, Jing Xia,
Thanks guys ! I didn’t copy Image (I needed SSD extlinux.conf and dtb dir to eMMC too !)

Could I abuse ?

but I need tty_acm too !
tuto about Build Kernel and ttyACM Module TX2 works nice, but erases spi !!

should I copy eMMC Image to anywere on SSD before playing with ttyACM tuto ?
Didn’t have success.

Thanks friends
Vincent

• Glad you got it to work.

15. Thanks for the great resource and tutorial!

Just having an issue while trying to run ./copyImage.sh
It is giving:
\$ cp: cannot stat ‘arch/arm64/boot/Image’: No such file or directory.

Any help would be great as I am lost and need this for a final project for engineering.

Thanks!

• This usually means that compiling the kernel failed. You should look for error messages in the compilation, and make sure that the kernel source matches the version of L4T that you are using.

16. i meet this error on my jetson tx2,can you help me!!!
tar: this does not look like a tar achieve
bzip2:(stdin)is not a bzip2 file
tar: source/kernel_src-tx2.tbz2:cannot open :no such file or directory
make: no rule to make target”xconfig”
thank you

• Does the file actually exist? More than likely, the kernel sources file did not download correctly. This may be due to firewall issues. The compressed sources file should be:

/usr/src/source_release.tbz2

17. Hi！ My TX2 is R27 version and I want to update to R28 because /dev/ttyTHS2 couldn’t be found.
Can you tell me how I update or I must reinstall Jetpack? Thank you!

• You must use JetPack.

18. Hi there,

I’ve followed instructions from this post to add a missing networking kernel module on my Jetson TX2. Everything went fine with the new added module after flashing the custom kernel, but it looks like V4L2 driver is missing from new kernel.

Any idea what went wrong?

Thanks,

B.

• I have not encountered that issue. You will need to check what the difference is between the default configuration and the new version that you have created.