Skip to content

Setting up Realtime Kernel on Jetson

Update

As of Jan 21, 2021, Nvidia now natively supports the PREEMPT_RT kernel patch on the Jetson boards. Steps to install:

sudo echo 'deb https://repo.download.nvidia.com/jetson/rt-kernel r32.5 main' \
        >> /etc/apt/sources.list.d/nvidia-l4t-apt-source.list
sudo apt update
sudo apt install nvidia-l4t-rt-kernel nvidia-l4t-rt-kernel-headers

Reboot and your Jetson board will be running a real-time kernel.

If you want to customize the kernel source

Find the source as a bzip file here under “Linux Driver Package (BSP) Sources”.

See instructions here on how to build it.


Original Article (no need to read this anymore)

The Jetson board is often used for autonomous driving applications, many of which require hard realtime determinism. The Jetson source code even includes realtime patches from the PREEMPT_RT kernel community. So why no one at Nvidia has documented how to use them is beyond me. Here’s the walk-through:

Step 1: Install Jetpack SDK on Host Machine

You’ll need a host machine running Ubuntu (tested on 18.04) to compile your kernel and flash your Jetson board. You can find the link to Jetpack here. Install it, run it, and you should see this screen:

Step 1 of Jetpack SDK Manager. Jetpack 4.3 selected.

Select your hardware, and the version of Jetpack you want to use. They will have the developer preview, 4.4 selected by default, but I recommend using 4.3. Click Next

Step 2 of Jetpack SDK Manager. Target components deselected.

On this screen, you’ll install the host components (I’ve already installed them in the screenshot). Deselect the Jetson OS, as we’ll be installing our own custom image with a realtime kernel. Also deselect Jetson SDK components as those will be installed later. Press continue and go grab coffee while CUDA, OpenCV, Visionworks, and the like are installed on your host machine.

Nvidia’s SDK manager installs OpenCV in an unconventionally named directory. This can be confusing for other software that doesn’t know where to look. Run the following commands to correct this
cd /usr/include
sudo ln -s opencv4/opencv2/ opencv

Exit when finished.

Step 2: Make your own Kernel

Now create a folder in your home directory to store your kernel source and auxillary goodies.

mkdir nvidia
cd nvidia

Clone the jetson-agx-build repo into it.

git clone https://github.com/jtagxhub/jetpack-agx-build.git build

This provides useful scripts to build your own kernel and flash it onto the Jetson. It downloads a lot of the same things the SDK Manager does; but also downloads the Jetson source code, complete with realtime kernel patches.

To set up the repo, run

source build/envsetup.sh

It’ll prompt you for your target board, your release, your user and password for your board, and your device IP. Answers should be the following:

  • Probably Xavier or TX2, but put whatever you’re using
  • 4.3, if you heeded my recommendations above
  • The username and password you plan on using when you install Ubuntu on your Jetson
  • 192.168.55.1, this is the IP address the Jetson assigns to itself in the Ethernet-over-USB mini-network

Finish setup with:

l4tout_setup
bspsetup

Now your nvidia directory will resemble the structure seen in the build/README.md. You’re ready to edit kernel code.

cd sources/kernel/kernel/kernel-4.9

This is the source for your kernel. It includes patches for realtime functionality. Apply these with:

./scripts/rt-patch.sh apply-patches

Your kernel is now realtime! Do some quick config and build it

kdefconfig
kmenuconfig     # You don't HAVE to change anything
ksavedefconfig
kbuild -a

Go grab coffee.

Step 3: Flash your Jetson

Unplug your Jetson and replug it in. The only things connected should be power, a keyboard, an HDMI monitor, and a USB connecting it to your host machine. Mouse is optional. Do not connect ethernet.

Enter recovery mode by holding down the Recovery switch (location varies by board) and then holding down the Power button. Release both after a couple seconds. Also plug in a monitor now.

Back on your host, run:

flash

It’ll prompt you for a conf file. If you’re using an AGX, it’s probably not the 8GB one, fyi. Go get coffee again. If this process isn’t done in 10 minutes, something went wrong.

Step 4: Install Ubuntu

The guaranteed way you know your flash works is the that the Jetson will power up, and you’ll see an install screen on its monitor. Connect a keyboard and do all the things.

When it prompts you for username and password, be sure to use the same ones you specified in step 2 after running envsetup.sh.

When installation is complete, and your Jetson restarted, login and run uname -a to see what kernel you have. If it has PREEMPT RT in it, congratulations! Your Jetson is running a fully preemptive realtime kernel!

Step 5: Install SDK components on Jetson

, bring up the SDK Manger again. Select all the same things on Step 1 (be careful not to accidentally select 4.4) and press continue.

Step 2 of Jetpack SDK Manager. Jetson SDK components selected.

This time, only leave Jetson OS unchecked, since we already flashed it. Take note of the Target HW Image Folder. Notice how I made mine a subfolder of the same nvidia directory we used before.

Press continue and take a quick potty break on account of the three coffee breaks you had during this tutorial.

When this is done, there will be CUDA and Visionworks demos installed on your Jetson. JetsonHacks has a YouTube video exploring these. Check that out if you want, but if not, you’re finished!

Footnote

If you’re digging into jetson-agx-build’s scripts and you’d rather use a git repo instead of a tarball, the link is:

git://nv-tegra.nvidia.com/linux-4.9.git

Their opensource graphics driver is

git://nv-tegra.nvidia.com/linux-nvgpu.git

And you can find code for related projects here