Search by Tags

Apalis TK1 Mainline Kernel with Nouveau Driver and Arch Linux Distro

 
Applicable for

Compare with Revision


Subscribe for this article updates

Attention: This document is deprecated. If you require mainline based image for Apalis TK1 please use our mainline BSP image. If you still want to create arch based image have a look at mesa and kernel patches in our meta-toradex-tegra git.

This document describes how to build the mainline Linux kernel and Nouveau driver from scratch for Apalis TK1.

This manual is based on https://github.com/NVIDIA/tegra-nouveau-rootfs

Prerequisites

Fedora 23/24:

sudo dnf install python glib2-devel autoconf automake libtool libffi-devel expat-devel libxml2-devel uboot-tools libtalloc-devel xorg-x11-util-macros
mkdir ~/bin 
export PATH=~/bin:$PATH 
curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo 
chmod a+x ~/bin/repo
git clone https://github.com/proot-me/PRoot.git
cd PRoot/src
make
cp proot ~/bin/

Ubuntu 14.04:

sudo apt-get install git build-essential wget proot phablet-tools autoconf automake libtool libc6-i386 lib32stdc++6 lib32z1 pkg-config libwayland-dev
sudo apt-get install bison flex bc u-boot-tools glib-2.0 libffi-dev xutils-dev python-mako intltool libxml2-dev

Scripts use sudo, your user needs to be a sudoer.

Syncing

All the required projects are synced using Google's repo tool:

mkdir tegra-nouveau-rootfs
cd tegra-nouveau-rootfs
repo init -u https://github.com/NVIDIA/tegra-nouveau-rootfs.git -m tegra-nouveau.xml

Sync all the sources:

repo sync -j4 -c

Once all the sources are downloaded, set the TOP environment variable:

export TOP=$PWD

Then download the cross-compilation toolchain that we will use:

./scripts/download-gcc

Rootfs

By default the scripts included in the NVIDIA repo generate an Arch rootfs. You can prepare an Arch based rootfs by using a simple set of commands:

./scripts/download-rootfs
./scripts/prepare-rootfs

In case you'd like to use the kernel and kernel modules with a different rootfs you can skip downloading and unpacking Arch and just create appropriate folders needed by the kernel scripts:

mkdir -p $TOP/out/target/arm/ArchLinuxArm/boot/
mkdir -p $TOP/out/target/arm/ArchLinuxArm/lib/modules

Kernel Compilation

Modify the build script to build an uImage instead of a zImage:

vi $TOP/scripts/build-linux

Change:

 case $ARCH in
     arm)
         KCONFIG="tegra_defconfig"
-         KIMAGE=zImage
+         KIMAGE=uImage
         KARCH=arm
     ;;
     aarch64)

And:

 # Build all that we need
- run_make_kernel -j$NPROC oldconfig dtbs $KIMAGE modules
+ run_make_kernel -j$NPROC oldconfig dtbs $KIMAGE modules LOADADDR=0x80008000

To make all peripherals on Apalis TK1 work apply the following patches:

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0001-apalis-tk1-remove-spurious-new-lines.patch > linux/0001-apalis-tk1-remove-spurious-new-lines.patch
patch -d linux -p1 < linux/0001-apalis-tk1-remove-spurious-new-lines.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-apalis-tk1-temp-alert-pull-up.patch > linux/0002-apalis-tk1-temp-alert-pull-up.patch
patch -d linux -p1 < linux/0002-apalis-tk1-temp-alert-pull-up.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch > linux/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch
patch -d linux -p1 < linux/0003-apalis-tk1-optional-displayport-hot-plug-detect.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch > linux/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch
patch -d linux -p1 < linux/0004-apalis-tk1-adjust-pin-muxing-for-v1.1-hw.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch > linux/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch
patch -d linux -p1 < linux/0005-apalis-tk1-working-sd-card-detect-on-v1.1-hw.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0006-apalis-tk1-update-compatibility-comment.patch > linux/0006-apalis-tk1-update-compatibility-comment.patch
patch -d linux -p1 < linux/0006-apalis-tk1-update-compatibility-comment.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0002-igb-integrate-tools-only-device-support.patch > linux/0002-igb-integrate-tools-only-device-support.patch
patch -d linux -p1 < linux/0002-igb-integrate-tools-only-device-support.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch > linux/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch
patch -d linux -p1 < linux/0003-apalis_t30-tk1-igb-no-nvm-and-Ethernet-MAC-address-h.patch

curl http://git.toradex.com/cgit/meta-toradex-tegra.git/plain/recipes-kernel/linux/linux-toradex-mainline-4.9/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch > linux/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch
patch -d linux -p1 < linux/0004-mmc-tegra-apalis-tk1-hack-to-make-sd1-functional.patch

Arch requires extra options to work properly:

CONFIG_SECCOMP=y

It can be simply appended to the defconfig file:

echo CONFIG_SECCOMP=y >> $TOP/linux/arch/arm/configs/tegra_defconfig

If you need any special kernel configuration now it's time to edit defconfig:

vi $TOP/linux/arch/arm/configs/tegra_defconfig

Now you can build the Kernel:

./scripts/build-linux

And the Nouveau driver:

./scripts/build-nouveau

Afterwards you should have a kernel and several kernel modules (including the Nouveau driver) ready and included in your rootfs.

Extra Packages

To use the GPU in applications you'll need to build custom mesa. Run:

./scripts/build-mesa

Installing Generated Arch Image on Apalis TK1

UMS Mode

While on the U-Boot prompt enter:

ums 0 mmc 0

Connect the board to the PC, two partitions should show up (boot & rootfs). Mount both of them.

Erase all files on mounted partitions. Then copy rootfs files to rootfs partition:

sudo rsync -aAXv $TOP/out/target/arm/ArchLinuxArm/* /path/to/rootfs/mountpoint/ 

As well as kernel and device tree to boot partition:

sudo cp $TOP/out/target/arm/ArchLinuxArm/boot/uImage-nouveau-arm /path/to/boot/mountpoint/uImage
sudo cp $TOP/out/target/arm/ArchLinuxArm/boot/dtb-nouveau/tegra124-apalis-eval.dtb /path/to/boot/mountpoint/

U-Boot Configuration

You need to clear the vidargs used with the BSP demo image to avoid any problems with displays. Enter U-Boot prompt and enter this commands:

setenv vidargs
saveenv

Installing Wayland\Weston

By default there is no graphical user interface. Proceed as follows to install weston after having logged in as root/root:

pacman -S weston

After in finished installing, simply run it:

weston-launch

Installing Xorg Server

Initially Arch will not have any Xorg server installed. Proceed as follows to install one after having logged in as root/root:

pacman -S xorg-server xorg-xrandr

And then it may be started as follows:

X &
export DISPLAY=:0.0
xrandr
glxgears

To install a full blown desktop environment have a look at the following article on the Arch wiki:

Arch Linux Desktop Environments

E.g. LXDE worked fine for me:

pacman -S lxde
systemctl enable lxdm
reboot

GPU Speed

Since there is no dynamic frequency scaling in Nouveau yet. You can check and change the GPU frequency via sysfs:

    cat /sys/kernel/debug/dri/128/pstate
    01: core 72 MHz *
    02: core 108 MHz
    03: core 180 MHz
    04: core 252 MHz
    05: core 324 MHz
    06: core 396 MHz
    07: core 468 MHz
    08: core 540 MHz
    09: core 612 MHz
    0a: core 648 MHz
    0b: core 684 MHz
    0c: core 708 MHz
    0d: core 756 MHz
    0e: core 804 MHz
    0f: core 852 MHz
    DC: core 72 MHz 

echo 0f > /sys/kernel/debug/dri/128/pstate

Known Issues

The following Nouveau kernel boot messages are not to be worried about. The 0 Mib VRAM message is due to the K1 SoC using unified memory rather than separate GPU VRAM. And the ce channel error -22 is due to the GPU being integrated directly on the K1 SoC and not having to pass via PCIe:

[   11.367215] nouveau: loading out-of-tree module taints kernel.
[   11.400352] nouveau 57000000.gpu: NVIDIA GK20A (0ea000a1)
[   11.406127] nouveau 57000000.gpu: imem: using IOMMU
[   11.483058] [TTM] Zone  kernel: Available graphics memory: 378360 kiB
[   11.489737] [TTM] Zone highmem: Available graphics memory: 1033718 kiB
[   11.496474] [TTM] Initializing pool allocator
[   11.501044] [TTM] Initializing DMA pool allocator
[   11.506112] nouveau 57000000.gpu: DRM: VRAM: 0 MiB
[   11.511076] nouveau 57000000.gpu: DRM: GART: 1048576 MiB
[   11.521936] nouveau 57000000.gpu: DRM: failed to create ce channel, -22
[   11.637449] nouveau 57000000.gpu: DRM: MM: using GRCE for buffer copies