Jetson TX-2 Flashing Custom Image

As the title says, I want to flash my custom image to the tx2 using command line tools in order to automatize this operation. What I have done so far is:

1- Creating a ubuntu base image on the tx2 using debootstrap
2- Download Linux_for_tegra(Tegra186_Linux_R32.2.1_aarch64.tbz2) and populate it’s rootfs folder with the one prepared in step 1.
3- Mount required directories, copy /etc/resolv.conf to Linux_for_Tegra/rootfs folder.
4- install qemu-user-static and copy /usr/bin/qemu-aarch64-static to Linux_for_Tegra/rootfs/usr/bin
5-*** chroot and get a bash shell. Install required packages/software.
6- Clean up (unmount etc.)
7- Flash

Problems occur in step 5 where I try to install packages. I have fetched the packages sdk manager downloads using .json file in download path, copied them into rootfs folder and inside chroot bash tried to install them using either dpkg (it didn’t work because of dependency problems) or apt install (it didn’t work because it cannot find packages) but no luck. I have tried to copy my host’s etc/apt/sources.list to rootfs and run apt-get update but it didn’t work.

Is there any solution I can try? What I try to achive is simply choose and install whatever packages/software that I want in whatever root file system (ubuntu base, ubuntu 18.04, ubuntu base + lightweight desktop etc.) I want. Any ideas to get there? (It would be great to use sdkmanager --cli instead of my scripts but I couldn’t find a way to do that)

I have never found a way to run a cross-arch dpkg/apt setup within a chroot environment. The only solution I’ve found is to actually run the package operations on the Jetson in question, and to then clone that, followed by using the clone in place of the sample rootfs.

Note that once you have a loopback mounted clone that the clone itself could be updated from a running Jetson via rsync, or a running Jetson could be updated from the loopback mounted clone.

The clone operation produces both a “.img” and a “.img.raw” file. The former is “sparse” and can be used for faster flash, but is otherwise useless since open source tools cannot deal with this form of sparse file. The raw image is very useful and incredibly utilitarian since it can be loopback mounted. Just be sure you save a safe copy of this file since there are a lot of operations which could overwrite it.

Clones are done on command line with the flash.sh utility. Instructions vary depending on release. Typically it goes something like this:

  1. Connect the Jetson in recovery mode.
  2. Make sure you have lots of disk space at the "flash.sh" location. cd to that location.
  3. sudo ./flash.sh -r -k APP -G backup.img jetson-tx2 mmcblk0p1

After

After lots of try-fail-retry-success loop, I have managed to build an image with desired applications installed. Preparation of this image was done in amd64 arch host machine using chroot environment. For the ones who are interested in such operation here are the things should be considered:

  • You have to use correct sources.list and correct configuration files(e.g. /etc/resolv.conf for DNS resolving) inside chroot. Prepare one and copy before getting inside chroot.
  • You have to be careful what you mount and umount.
  • Adding a user inside chroot is not allowed. Look for useradd commands's -R flag. Also you need to make sudo group real sudo and add your newly created user to this group.
  • You have to make your user login as default. See /etc/lightdm/lightdm.conf
  • You need to look at what nvidia does in SDK manager. Download packages using this app and see downloads.json file, use .deb files for some applications (e.g. cuda) from links inside this file. Also dependency management should be performed inside chroot. apt-rdepends can be used.