Jetson/Porting Fedora

From eLinux.org
< Jetson
Revision as of 13:58, 13 July 2015 by Cpgonzalez (talk | contribs) (init())
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Introduction

This guide will go over the steps needed to get the ARM version of Fedora 20 running on the Jetson-TK1, after installing the board support package (config, kernel, drivers, etc.) This guide will help you configure the corresponding NVIDIA driver packages and binaries needed to use the Fedora distribution.

The first step is to download the latest TK1 Driver Package: https://developer.nvidia.com/linux-tegra

Extract the Jetson TK1 Driver Packages, which should contain a top folder called "Linux_for_Tegra".

 sudo tar jxpf <latest_l4t_driver_package>.tbz2
 cd Linux_for_Tegra     # We will refer to this directory as <path_to_L4T_TOP_DIR>
 cd rootfs              # We will refer to this directory as <path_to_L4T_rootfs>

NOTE: This guide follows the steps for flashing and booting into a minimal Fedora image. After, we give instructions for making necessary changes to install a desktop environment. If you choose to use a non-minimal Fedora image, you may have to preform some of these changes before flashing.

Obtaining the Fedora Image

Now we need to obtain the image for Fedora in order to place it's contents in the "rootfs" folder of Linux_for_Tegra.

A Fedora mirror can be found here: http://mirror.sfo12.us.leaseweb.net/fedora/linux/releases/20/Images/armhfp/

NOTE: Make sure to select the Minimal 20 "armhfp" version, labeled "Fedora-Minimal-armhfp-20-1-sda.raw.xz" on the link above. The latest Fedora 21 version may not work with the existing Jetson-TK1 BSP due to incompatible versions of Xorg.

Extract the image and then mount it with kpartx:

xz -d Fedora-Minimal-armhfp-20-1-sda.raw.xz 
sudo kpartx -a Fedora-Minimal-armhfp-20-1-sda.raw

Locate the contents of the mounted filesystem in /media/<user_name>/__/ and copy only the contents from the root filesystem that appears here into a desired directory on your local machine. You will want to run cp while preserving Fedora's symbolic links.

sudo cp -av /media/<user_name>/__/* <path_to_L4T_rootfs>

Changes to the Apply Binaries script

As the apply binaries script (apply_binaries.sh) was written to work with Ubuntu, and Ubuntu stores its libraries in a different place than Fedora, the script will need to be updated to look in the correct place. Navigate to your Linux_for_Tegra folder and make these changes to the apply_binaries.sh file.

Find the section of the file that looks similar to the script below, and add the two lines indicated:

if [ -d "${LDK_ROOTFS_DIR}/usr/lib/arm-linux-gnueabihf/tegra" ]; then
	ARM_ABI_DIR="${LDK_ROOTFS_DIR}/usr/lib/arm-linux-gnueabihf"
elif [ -d "${LDK_ROOTFS_DIR}/usr/lib/arm-linux-gnueabi/tegra" ]; then
	ARM_ABI_DIR="${LDK_ROOTFS_DIR}/usr/lib/arm-linux-gnueabi"
elif [ -d "${LDK_ROOTFS_DIR}/usr/lib/aarch64-linux-gnu/tegra" ]; then
	ARM_ABI_DIR="${LDK_ROOTFS_DIR}/usr/lib/aarch64-linux-gnu"
elif [ -d "${LDK_ROOTFS_DIR}/usr/lib/tegra" ]; then                     # Add this line
        ARM_ABI_DIR="${LDK_ROOTFS_DIR}/usr/lib"                         # and this one.
else
	echo "Error: None of Hardfp/Softfp Tegra libs found"
	exit 4
fi

Next, you will need to add flags to several tar commands in order to preserve symbolic links, since Fedora uses these links for its /bin, /sbin, and /lib folders. There are 4 lines you need to change like this:

#Replace these
tar xpfm
#With these
tar --keep-directory-symlink -xpmf

Similarly, there are 4 more lines that need to change like this:

#Replace these 
sudo tar jxpfm
#With these
sudo tar --keep-directory-symlink -jxpmf

Configuration Changes

Compared to Ubuntu a few configuration changes are needed

In order to address these changes, we will need to make a few edits to the "nv_tegra" folder, found within Linux_for_Tegra.

  • 1. Navigate to Linux_for_Tegra/nv_tegra
  • 2. Extract the "nvidia_drivers.tbz2" file and an "nvidia_drivers" file should appear
  • 3. Navigate to nvidia_drivers/usr/lib/arm-linux-gnueabihf
  • 4. Move the "tegra" and "tegra-egl" folders found here up one directory into /nvidia_drivers/usr/lib/
  • 5. Remove the old nvidia_drivers.tbz2 in /nv_tegra/
  • 6. Repackage the contents of nvidia_drivers
cd <path_to_L4T_TOP_DIR>/nv_tegra
sudo mkdir nvidia_drivers
sudo tar -xpjf nvidia_drivers.tbz2 -C nvidia_drivers/
cd nvidia_drivers/usr/lib/arm-linux-gnueabihf
sudo mv tegra ../tegra
sudo mv tegra-egl ../tegra-egl
cd ../../..
sudo rm ../nvidia_drivers.tbz2 
sudo tar -cpjf ../nvidia_drivers.tbz2 *

Initialization Script

Because Fedora uses systemd rather than upstart, the init script will need to be converted into a systemd service. Information on systemd and how to create services can be found on the Arch Wiki page for systemd. The process is the same for Fedora.

To create the systemd service, we will need the service descriptor file, that tells systemd about the service. The one that I created is below.

##Location
##<path_to_L4T_rootfs>/etc/systemd/system/nvidia-tegra.service

[Unit]
Description=The NVIDIA tegra init script

[Service]
type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/nvidia-tegra-init-script

[Install]
WantedBy=multi-user.target

You can sudo <some-text-editor> with <path_to_L4T_TOP_DIR>/rootfs/usr/lib/systemd/system/nvidia-tegra.service and place the contents above into this empty file.

fstab

Depending on the image you obtained, you may need to be updated before flashing. As the Fedora install / image is distributed as a raw disk image, it assumes you will flash that image directly to the target device, which is not the case here. The fstab has the UUID's of the partitions which are not the same when flashing to the Jetson.

A blank fstab will work fine.

sudo rm <path_to_L4T_rootfs>/etc/fstab
sudo touch <path_to_L4T_rootfs>/etc/fstab

Flashing Jetson TK1

The steps for flashing the Fedora image to the Jetson are no different than flashing the image for Ubuntu.

First, make sure the Jetson-TK1 is in recovery mode by holding down the 'Force Recovery' button and then tapping the 'Reset' button on the board. Run the following commands to apply the configuration, create the image, and flash it to the Jetson

cd <path_to_L4T_TOP_DIR>
# Apply the NVIDIA specific configuration, binaries, and the L4T kernel
sudo ./apply_binaries.sh

# Create the image from the contents of rootfs and flash the image to the Jetson
sudo ./flash.sh -S 14580MiB jetson-tk1 mmcblk0p1

NOTE: If flash fails, try rebooting your host machine to clear device nodes

After flashing successfully, your Jetson-TK1 should boot and prompt you to set a root password, user, and timezone.

X11 Support

First, we need to install the base x11 packages. You can do this easily by running the following group install command:

yum install @base-x

Then, you will need to make sure that X is using the libglx.so that nvidia provides, and not the default

cd /usr/lib/xorg/modules/extensions
rm libglx.so
ln -sf /usr/lib/tegra/libglx.so libglx.so

Desktop Environment

To run Fedora's GUI environment you will need to choose a desktop environment and install it. For simplicity, I used XFCE.

yum install @xfce

Depending on the desktop environment, you may need to configure xinitrc. XFCE, for example, will not do this for you. You can configure your xinitrc by modifying / creating the .xinitrc file in your home directory.

nano ~/.xinitrc

You can also copy the default from /etc/X11/xinit/xinitrc to your home directory and modify it accordingly.

The addition of

exec startxfce4

is needed to tell xinit to launch xfce. A minimal configuration file is below.

#!/bin/bash
#For those using XFCE
exec startxfce4

Finally launch your desktop environment:

startx

Testing

The tests performed to verify that the nvidia drivers are installed correctly and everything is working as it should

Mesa Demos

Install the mesa demo utilities. You will need to have a libgl provider.

yum install mesa-libGL mesa-libGLU

Execute glxgears

glxgears

NVIDIA GL Tests

The internal NVIDIA gl tests can be found in the full Linux For Tegra package, which is available from the latest release here

Inside the full_linux_for_tegra.tbz2 there is a tests_output.tbz2 which contain a variety of tests for OpenGL.

Instructions on how to execute these tests can be found here

Before you run this, you will want to add the tegra-egl path to nvidia-tegra.conf, located in /etc/ld.so.conf.d/

#nvidia-tegra.conf needs to have both of these paths
/usr/lib/tegra
/usr/lib/tegra-egl

If you follow the instructions correctly, you should be able to run tests located in the /home/ubuntu directory, extracted from tests_output.tbz2 in full_linux_for_tegra.tbz2

#For example
./nvtest gles2_gears

A few notes on these instructions

  • The location of where the tests are installed does not matter, but the LD_LIBRARY_PATH must reflect where the tests were extracted (defaults to /home/ubuntu)
  • Ensure that the tegra-egl libraries are loaded properly. Should see the /usr/lib/tegra-egl/ folder with libEGL and GLES libraries inside.
ldconfig -v # shows all of the libraries loaded. 

Additionally you can check which libraries are being used by the binary, glxgears in this case.

ldd /usr/bin/glxgears

Multimedia Tests

The test package in the section above also comes with an application for testing multimedia, omxplayer.

First you will need to have a video file to test with, preferably an HD video. I used Big Buck Bunny which can be downloaded from here

To play the video file

./nvtest ./omxplayer.so --hdmi -i <MEDIA_FILE_NAME>

CUDA Tests

Acquire the pre-compiled CUDA tests from the following network share

\\linux4tegra\l4t\Demo\R19.1_GTC\CUDA_SDK_samples

The README has some information about executing the tests. The main three applications are nbody, particles, and smokeParticles. Before the running the tests you should set up cuda drivers by executing this:

yum install mesa-libGLU freeglut
ln -s /usr/lib/tegra/libcuda.so.1 /usr/lib/libcuda.so
ldconfig 

The tests can be run by simply executing the binaries

./nbody
./particles
./smokeParticles

If you wish to max the GPU performance

./nbody -numbodies=16384

For tipsy simulation

./nbody -tipsy=data/galaxy_20K.bin