Search by Tags

Installing NVIDIA JetPack with L4T on Apalis TK1

 
Article updated at 23 Jan 2020
Compare with Revision




This article discusses how to manually install NVIDIA's JetPack on Toradex' Apalis TK1 Computer/System on Module CoM/SoM. At the time of this writing, we are talking about Apalis TK1 V1.0A prototypes and V1.0B, V1.1A and V1.2A samples.


Note: Please try our new Toradex Easy Installer which is a Linux-based application providing a graphical selection of operating system images that users may choose to install onto the internal flash memory of Toradex modules in an extremely simple way. Both an L4T R21.7 only image as well as a complete L4T R21.7 image with the target side JetPack 3.1 already pre-installed are available out-of-the-box.

Note: Please note that the Toradex Easy Installer will be the default pre-installed software for Apalis TK1, Apalis/Colibri iMX6, Colibri iMX7 and all newer modules in the future.

Contents

NVIDIA's JetPack 3.1 consists of the following items:

  1. Linux For Tegra R21.5 based on Ubuntu ARM 14.04 LTS
  2. VisionWorks 1.4.3
  3. cuDNN v2
  4. CUDA 6.5.53
  5. Tegra System Profiler 3.8.450
  6. Tegra Graphics Debugger 2.4.17023
  7. PerfKit 4.5.1
  8. OpenCV4Tegra 2.4.13
  9. NVIDIA GameWorks OpenGL Samples 2.11

Note: NVIDIA's latest Linux For Tegra R21.7 is not integrated into any JetPack release as of yet and would need to be installed manually if required.

Note: Should you plan to use NVIDIA's JetPack 3.1 it only supports Ubuntu 14.04 (64-bit)!

Prerequisites

The preparation steps need to be executed on a x86-64 development host running a Linux distribution (e.g. Fedora or Ubuntu). Please note that there is no support for 32 bit hosts.

The following host applications and libraries are a pre-requisite for executing the update script and the 64-bit host tools contained in the image tarball.

E.g. for Ubuntu 14.04 (64-bit)

sudo apt-get update
sudo apt-get install dosfstools e2fsprogs gawk mtools parted
sudo apt-get install zlib1g liblzo2-2 libuuid1 libusb-1.0-0

E.g. for Fedora 21 (64-bit)

yum install dosfstools e2fsprogs gawk mtools parted 
yum install zlib lzo libuuid libusbx

On older distros (e.g. Ubuntu 12.04) the tool to create a FAT filesystem was named mkfs.vfat while the update.sh script uses mkfs.fat. If you get an error that mkfs.fat is missing then find the full path to mkfs.vfat and create a symlink by doing the following:

trdx@trdx:~$ sudo sh -c "command -v mkfs.vfat"
/sbin/mkfs.vfat
trdx@trdx:~$ sudo ln -s /sbin/mkfs.vfat /sbin/mkfs.fat

Preparing Linux Kernel and Root File System

To get a base L4T root file system ready to accept later JetPack installation you may now install NVIDIA's JetPack 3.1 on your development workstation. As NVIDIA only supports this for x86 64-bit Ubuntu 14.04 LTS which you may not be using one can revert to a VM e.g. using VirtualBox or the like. For the JetPack installation just download e.g. JetPack-L4T-3.1-linux-x64.run and install it as explained in NVIDIA's documentation as linked to on the top. When asked just proceed using the default standard options for Jetson TK1 up to its post-installation steps.

Note: Due to Toradex Apalis TK1 being pin compatible to the rest of the Apalis family there are a few subtle hardware differences and one can not just flash straight Jetson TK1 firmware onto it.

Therefore at the post-installation during the USB recovery mode step one cannot connect/flash the Apalis TK1 using the JetPack installer but we rather extract the base L4T root file system and flash it onto the Apalis TK1 by our regular procedure and subsequently install the rest of the JetPack as usual via Ethernet.

First we have to get to the L4T root file system:

ubuntu@ubuntu-14:~$ cd ~/TK1/Linux_for_Tegra_tk1/
ubuntu@ubuntu-14:~/TK1/Linux_for_Tegra_tk1$ sudo tar cjvf rootfs.tar.bz2 rootfs

Now we continue integrating the above into our regular Apalis TK1 Embedded Linux BSP demo image package and replace its rootfs with the L4T one as obtained above (use the latest beta image, at the time of writing this is 2.8b3. You can find the latest image here):

[user@host ~]$ wget -c https://developer.toradex.com/files/toradex-dev/uploads/media/Colibri/Linux/Images/old/Apalis-TK1_LXDE-Image_2.8b3.111-20180626.tar.bz2
[user@host ~]$ sudo tar xjf Apalis-TK1_LXDE-Image_2.8b3.111-20180626.tar.bz2
[user@host ~]$ cd Apalis-TK1_LXDE-Image_2.8.3/rootfs/
[user@host rootfs]$ sudo cp lib/firmware/apalis-tk1-k20.bin ../
[user@host rootfs]$ sudo tar cjf ../mod.tar.bz2 lib/modules
[user@host rootfs]$ cd ..
[user@host Apalis-TK1_LXDE-Image_2.8.3]$ sudo rm -rf rootfs
[user@host Apalis-TK1_LXDE-Image_2.8.3]$ sudo tar xjvf ~/TK1/Linux_for_Tegra_tk1/rootfs.tar.bz2
[user@host Apalis-TK1_LXDE-Image_2.8.3]$ cd rootfs
[user@host rootfs]$ sudo cp ../apalis-tk1-k20.bin lib/firmware/
[user@host rootfs]$ sudo tar xjvf ../mod.tar.bz2
[user@host rootfs]$ cd ..

Now proceed to generate an update media (e.g. SD card or TFTP location) as usual. Make sure to pass the -m 2 parameter to our update.sh script in order for it to assume a Apalis TK1 root file system to be generated e.g. as follows:

[user@host Apalis-TK1_LXDE-Image_2.8.3]$ ./update.sh -m 2 -o /var/lib/tftpboot/

Flashing Latest Boot Loader

First, we have to make sure the latest U-Boot bootloader and its default environment are installed. We use the one from our latest BSP release which we already generated an update media for in the previous step.

Update U-Boot as usual e.g.:

Apalis TK1 # run setupdate
Apalis TK1 # run update_uboot

Should the above fail you may be running an older prototype U-Boot version which used a different board/board_name. This can be worked around by additionally doing the following right before the above:

Apalis TK1 # setenv board apalis-tk1
Apalis TK1 # setenv board_name apalis-tk1

Once running the latest U-Boot also make sure to use resp. latest default environment e.g.:

Apalis TK1 # env default -a; saveenv; reset

As Ubuntu 14.04 requires the root file system to initially already be mounted in read/write mode change the emmcargs e.g. as follows:

Apalis TK1 # setenv emmcargs 'ip=off root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait'; saveenv; reset

Should your module not boot into U-Boot anymore you will have to use the flashing from scratch procedure as explained in the following article.

You are now running the latest bootloader.

Flashing Linux Kernel and Root File System

Then back at your bootloader prompt proceed with the installation as follows:

Apalis TK1 # run setupdate
Apalis TK1 # run update

The update takes some time and completes with a reset. Your Apalis TK1 should now boot into a base L4T system.

You may now disable the screen power-saving and lock as well as enable auto login.

Unless you do have a single channel LVDS display connected you may want to disable the built-in display as well.

For the L4T root file system one has to manually re-size the file system to use the full partition size as follows:

ubuntu@tegra-ubuntu:~$ sudo resize2fs /dev/mmcblk0p2

As a further convenience one may want to add a DISPLAY variable to the regular terminal e.g. as follows:

ubuntu@tegra-ubuntu:~$ sudo sh -c 'echo "" >> /etc/profile'
ubuntu@tegra-ubuntu:~$ sudo sh -c 'echo "test -z \"\$DISPLAY\" && DISPLAY=\":0.0\" # have the X display defined, unless it is already set, e.g. by a ssh connection" >> /etc/profile'
ubuntu@tegra-ubuntu:~$ sudo sh -c 'echo "export DISPLAY" >> /etc/profile'

If you are using an Ixora carrier board an optional fan may be enabled via its GPIO as follows:

ubuntu@tegra-ubuntu:~$ sudo sh -c 'echo 234 > /sys/class/gpio/export'
ubuntu@tegra-ubuntu:~$ sudo sh -c 'echo high > /sys/class/gpio/gpio234/direction'

The above may, of course, be added to any Ubuntu start script of your liking.

After a reboot, your Apalis TK1 should now be ready to accept further JetPack installation.

Installing JetPack

You may still have your JetPack installer waiting at the post-installation USB recovery mode step. If not just proceed through the JetPack installer again using the default options for Jetson TK1 up to its post-installation steps. Do not connect your development workstation to your target by means of a USB device cable and do not put your target into recovery mode but rather ensure both your development workstation as well as your Apalis TK1 do have basic Ethernet connectivity on the same subnet. Then just confirm the following question given in a separate terminal:

Please put your device to Force USB Recovery Mode, when you are ready, press Enter key

Upon which the installer will respond as follows:

Failed to flash device. Check /home/ubuntu/_installer/logs/TK1/flash_os_tk1.log for more details. Please close this terminal window, fix the issue mentioned in log, and run JetPack again to reinstall.

Previous JetPack installers may respond as follows:

Failed to flash device. Please check /home/ubuntu/_installer/logs/TK1/flash_os_tk1.log for more details. Then press Enter key and try again.

Do NOT close the terminal window as suggested but just hit ENTER in that terminal with the installer proceeding as follows:

Determining the IP address of target...

Now if after three more minutes you do not get any response yet you need to manually kill nc in a separate new terminal as follows:

killall -s SIGKILL nc

Now you should get the following response:

JetPack is unable to determine the IP address of the Jetson Developer Kit
Please select which action do you want:
    1. Retry
    2. Manually enter IP address
Your Option is <1/2>:

This you confirm with 2 to be able to manually enter your boards IP address into the main JetPack installer UI.

On the Apalis TK1 you may find out about your currently obtained IP address using the following command:

ubuntu@tegra-ubuntu:~$ ip addr

The relevant interface for the gigabit Ethernet connection is called eth0.

After the successful JetPack installation first make sure to remove any excess .deb files as they will use up all space of our precious root file system.

Then finally proceed to updating your L4T system e.g. as follows:

ubuntu@tegra-ubuntu:~$ sudo apt-get update
ubuntu@tegra-ubuntu:~$ sudo apt-get dist-upgrade
ubuntu@tegra-ubuntu:~$ sudo apt-get autoremove
ubuntu@tegra-ubuntu:~$ sudo apt-get autoclean
ubuntu@tegra-ubuntu:~$ sudo apt-get clean

Congratulations, your Apalis TK1 should now be running a fully up-to-date JetPack/L4T installation.

Build Linux Kernel from Source Code

While we recommend cross-compiling the Linux kernel as explained in the following article one can of course natively build it as well.

First one needs to get the proper Linux kernel sources for our BSP from the Toradex git server:

ubuntu@tegra-ubuntu:~$ git clone -b toradex_tk1_l4t_r21.7 git://git.toradex.com/linux-toradex.git

Then for BSPs prior to 2.8b2 to be able to create an uImage later the u-boot-tools need installing:

ubuntu@tegra-ubuntu:~$ sudo apt-get update
ubuntu@tegra-ubuntu:~$ sudo apt-get install u-boot-tools

Now configure and compile the kernel as follows:

ubuntu@tegra-ubuntu:~$ cd linux-toradex/
ubuntu@tegra-ubuntu:~linux-toradex$ make apalis-tk1_defconfig
ubuntu@tegra-ubuntu:~linux-toradex$ make -j6
ubuntu@tegra-ubuntu:~linux-toradex$ make -j6 zImage

Note: BSPs prior to 2.8b2 were still using uImage instead of zImage.

And we deploy the kernel binary and its accompanying device tree blobs. You should copy the kernel and device tree binaries to the boot partition. You can use a command such as mount | grep -i boot to find where the boot partition is mounted.

Last but not least we deploy the matching kernel modules:

ubuntu@tegra-ubuntu:~linux-toradex$ sudo make modules_install

Now before attempting to compile further kernel modules out-of-tree reboot into this freshly built kernel:

ubuntu@tegra-ubuntu:~linux-toradex$ sudo reboot

After rebooting one can go ahead and compile out-of-tree kernel modules as well. As an example, I show how one can do this for the Hello, World (part 1): The Simplest Module:

ubuntu@tegra-ubuntu:~$ cd kernel_module/
ubuntu@tegra-ubuntu:~/kernel_module$ make
make -C /lib/modules/3.10.40-g19722d4/build M=/home/ubuntu/kernel_module modules
make[1]: Entering directory `/home/ubuntu/linux-toradex'
  CC [M]  /home/ubuntu/kernel_module/hello-1.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /home/ubuntu/kernel_module/hello-1.mod.o
  LD [M]  /home/ubuntu/kernel_module/hello-1.ko
make[1]: Leaving directory `/home/ubuntu/linux-toradex'

ubuntu@tegra-ubuntu:~/kernel_module$ uname -a
Linux tegra-ubuntu 3.10.40-g19722d4 #1 SMP PREEMPT Thu Mar 23 09:54:35 UTC 2017 armv7l armv7l armv7l GNU/Linux

ubuntu@tegra-ubuntu:~/kernel_module$ modinfo hello-1.ko
filename:       /home/ubuntu/kernel_module/hello-1.ko
srcversion:     140276773A3090F6F33891F
depends:        
vermagic:       3.10.40-g19722d4 SMP preempt mod_unload modversions ARMv7 p2v8 

ubuntu@tegra-ubuntu:~/kernel_module$ sudo insmod hello-1.ko

ubuntu@tegra-ubuntu:~/kernel_module$ lsmod
Module                  Size  Used by
hello_1                  684  0 
joydev                  8195  0 
rfcomm                 33184  0 
bnep                    9543  2 
apalis_tk1_k20          9080  0 
bluetooth             269569  10 bnep,rfcomm
rfkill                 10359  3 bluetooth
nvhost_vi               2889  0