Real-time kernel for NVIDIA AGX Xavier

Roman
2 min readNov 15, 2019

--

In this blog post i want to share a quick way (one command) of recompiling Linux kernel with PREEMPT_RT patch for NVIDIA Jetson AGX Xavier.

Supported version: Jetpack 4.2.1 (L4T 32.2.1), kernel 4.9.140

Supported hw: Jetson AGX Xavier

New platforms (Nano, TX2, etc.), new versions are welcomed here.

  • Cross-compilation will happen inside docker on your laptop.
  • Kernel update do not require full re-flashing, so Jetson filesystem will be preserved (kittens are safe). Done with Nvidia OTA update service.

Short version

To build RT kernel for Xavier execute following commands on your x86_64 laptop

git clone https://github.com/r7vme/xavier-base-docker-images
cd xavier-base-docker-images/realtime-kernel
docker build -t xavier-rt-kernel:32.2.1 -f Dockerfile.l4t_32_2_1 .

It will download NVIDIA provided sources, apply PREEMPT_RT patches and compile the kernel. Finally it will generate OTA update image that can be used to quickly update kernel.

Description

Make sure you have successfully flashed your Xavier with Jetpack 4.2.1 (later one should also work) and already have ssh access to the board. No need for any USB cables, only one reboot will be required, because NVIDIA OTA (over-the-air-update) service will be used.

For simplicity and reproducibility i provide a Dockerfile. One can also use this Dockerfile as a reference, but execute commands manually on your Linux system.

Dockerfile is just compiled list of commands provided in:

Compile kernel

Make sure you have at least 20GB of free space and docker installed.

git clone https://github.com/r7vme/xavier-base-docker-images
cd xavier-base-docker-images/realtime-kernel
docker build -t xavier-rt-kernel:32.2.1 -f Dockerfile.l4t_32_2_1 .

Extract images and kernel modules

docker run --rm -v $(pwd):/host xavier-rt-kernel:32.2.1 \
cp /Linux_for_Tegra/kernel/kernel_supplements.tbz2 /Linux_for_Tegra/bootloader/payloads_t19x/bl_update_payload /Linux_for_Tegra/bootloader/payloads_t19x/bl_update_payload_default /host

bl_update_payload - image for OTA update containing real-time kernel bl_update_payload_default - image for OTA update containing default kernel kernel_supplements.tbz2 - archive containing kernel modules. Should be extracted to /lib/modules

Update Xavier

WARN: Make sure to have backups in case something will go wrong! Did not go for me, but anyway.

Extract and copy files to Xavier.

scp kernel_supplements.tbz2 <host>:/tmp
scp bl_update_payload bl_update_payload_default <host>:/tmp

Extract kernel modules. This step is necessary, because we are not re-flashing eMMC card (rootfs), but only updating a bootloader (kernel).

sudo -i
tar -C / -xf /tmp/kernel_supplements.tbz2

Flash new bootloader (commands described here)

cp /tmp/bl_update_payload* /opt
mkdir /opt/ota_package
nv_update_engine --enable-ab
cp /opt/bl_update_payload /opt/ota_package/
nv_update_engine --install

If everything went well Jetson will be booted with new kernel

uname -r
4.9.140-rt93+

Now tools like cyclitest should work

sudo cyclictest --mlockall --smp --priority=80 --interval=200 --distance=0

To switch back to default kernel

cp /opt/bl_update_payload_default /opt/ota_package/bl_update_payload
nv_update_engine --install

--

--