Skip to content

Commit

Permalink
Porting to JetPack 5.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jnzw committed Oct 20, 2022
1 parent ed65905 commit f8c4c03
Show file tree
Hide file tree
Showing 101 changed files with 9,246 additions and 39 deletions.
98 changes: 72 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,36 @@

## Jetson AGX Xavier board setup

Please follow the [instruction](https://docs.nvidia.com/sdk-manager/install-with-sdkm-jetson/index.html) to flash JetPack 4.6.1 to the Jetson AGX Xavier with NVIDIA SDK Manager. Currently SDK Manager requires the host to be Ubuntu 18.04 only.
Please follow the [instruction](https://docs.nvidia.com/sdk-manager/install-with-sdkm-jetson/index.html) to flash JetPack to the Jetson AGX Xavier with NVIDIA SDK Manager or other methods NVIDIA provides. Make sure the board is ready to use.

Please make sure the board is ready to use.
Currently Supported JetPack versions are:

- 5.0.2 (default)
- 4.6.1

## Build kernel, dtb and D457 driver

In previous step to flash Jetson board with NVIDIA SDK Manager, the JetPack 4.6.1 folder should already be downloaded to your home directory at `~/nvidia/nvidia_sdk/JetPack_4.6.1_Linux_JETSON_AGX_XAVIER_TARGETS/Linux_for_Tegra`. Get JetPack kernel source code using existing script in JetPack 4.6.1, or download directly from [JetPack 4.6.1 BSP sources](https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t186/public_sources.tbz2).
The developers can set up the source code with NVIDIA's Jetson git repositories by using the provided setup script:

```
# SDK Manager method, download kernel source code
cd ~/nvidia/nvidia_sdk/JetPack_4.6.1_Linux_JETSON_AGX_XAVIER_TARGETS/Linux_for_Tegra
./source_sync.sh -t tegra-l4t-r32.7.1
# Using setup script, recommended for developers. If JetPack version is not given, default version will be chosen.
./setup_workspace.sh [JetPack_version]
```

# direct download method
Or download Jetson Linux source code tarball from [JetPack 5.0.2 BSP sources](https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/sources/public_sources.tbz2), [JetPack 4.6.1 BSP sources](https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t186/public_sources.tbz2).

```
mkdir l4t-gcc
cd ./l4t-gcc
wget https://developer.nvidia.com/embedded/jetson-linux/bootlin-toolchain-gcc-93 -O aarch64--glibc--stable-final.tar.gz
tar xf aarch64--glibc--stable-final.tar.gz
cd ..
# JetPack 5.0.2
wget https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/sources/public_sources.tbz2
# or JetPack 4.6.1
wget https://developer.nvidia.com/embedded/l4t/r32_release_v7.1/sources/t186/public_sources.tbz2
tar xjf public_sources.tbz2
cd Linux_for_Tegra/source/public
tar xjf kernel_src.tbz2
Expand All @@ -25,30 +40,23 @@ tar xjf kernel_src.tbz2
Apply D457 patches and build the kernel image, dtb and D457 driver.

```
# NVIDIA SDK Manager method
cd ~/nvidia/nvidia_sdk/JetPack_4.6.1_Linux_JETSON_AGX_XAVIER_TARGETS/Linux_for_Tegra/sources
# direct download method
cd Linux_for_Tegra/source/public
# if using setup script
./apply_patches.sh apply [JetPack_version]
# get and apply our patches
git clone https://github.com/IntelRealSense/perc_hw_ds5u_android-jetson_tx2.git
cd perc_hw_ds5u_android-jetson_tx2
./apply_patches.sh apply
# or, if using direct download method
# ./apply_patches_ext.sh ..
# ./apply_patches_ext.sh ./Linux_for_tegra/source/public [JetPack_version]
# build kernel, dtb and D457 driver
sudo apt install gcc-aarch64-linux-gnu build-essential bc
./build_all.sh
sudo apt install build-essential bc
./build_all.sh [JetPack_version] [JetPack_source_dir]
# remove our patches from JetPack kernel source code if using NVIDIA SDK Manager method
# ./apply_patches.sh reset
# remove our patches from JetPack kernel source code if using setup script
# ./apply_patches.sh reset [JetPack_version]
```

Then the necessary files are at
- kernel image `images/arch/arm64/boot/Image`
- dtb `images/arch/arm64/boot/dts/tegra194-p2888-0001-p2822-0000.dtb`
- dtb `images/arch/arm64/boot/dts/nvidia/tegra194-p2888-0001-p2822-0000.dtb`, or `images/arch/arm64/boot/dts/tegra194-p2888-0001-p2822-0000.dtb` for JetPack 4.6.1.
- D457 driver `images/drivers/media/i2c/d4xx.ko`
- UVC Video driver `images/drivers/media/usb/uvc/uvcvideo.ko`
- V4L2 Core Video driver `images/drivers/media/v4l2-core/videobuf-core.ko`
Expand All @@ -72,14 +80,16 @@ Then move the images in place and enable driver autoload at kernel boot.
```
sudo cp Image /boot
sudo cp tegra194-p2888-0001-p2822-0000.dtb /boot/dtb
sudo cp d4xx.ko /lib/modules/4.9.253-tegra/kernel/drivers/media/i2c/
sudo cp d4xx.ko /lib/modules/5.10.104-tegra/kernel/drivers/media/i2c/
echo "d4xx" | sudo tee /etc/modules-load.d/d4xx.conf
sudo cp uvcvideo.ko /lib/modules/4.9.253-tegra/kernel/drivers/media/usb/uvc/
sudo cp videobuf-core.ko /lib/modules/4.9.253-tegra/kernel/drivers/media/v4l2-core/
sudo cp videobuf-vmalloc.ko /lib/modules/4.9.253-tegra/kernel/drivers/media/v4l2-core/
sudo cp uvcvideo.ko /lib/modules/5.10.104-tegra/kernel/drivers/media/usb/uvc/
sudo cp videobuf-core.ko /lib/modules/5.10.104-tegra/kernel/drivers/media/v4l2-core/
sudo cp videobuf-vmalloc.ko /lib/modules/5.10.104-tegra/kernel/drivers/media/v4l2-core/
sudo depmod
```

Please change the kernel version in path accordingly, for example for JetPack 4.6.1 the version is `4.9.253-tegra`.

After rebooting Jetson, the D457 driver should work.

## Available directives on max9295/max9296 register setting
Expand Down Expand Up @@ -111,3 +121,39 @@ echo 0 | sudo tee /sys/module/max9296/parameters/max9296_dynamic_update
echo 1 | sudo tee /sys/bus/i2c/drivers/max9295/30-0040/refresh_setting
echo 1 | sudo tee /sys/bus/i2c/drivers/max9296/30-0048/refresh_setting
```

## JetPack 5.0.2 updates

* Script for syncing kernel sources can be obtained from [Linux_for_Tegra/source_sync.sh](https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/release/jetson_linux_r35.1.0_aarch64.tbz2)

> Note: there is a [glitch](https://forums.developer.nvidia.com/t/jetpack5-0-2-kernel-compile-error/224160/8) in the script that prevents part of kernel source to be downloaded, it must be fixed manually by changing the order of repos in the script.
The tag is:
```
./source_sync.sh -t jetson_35.1
```
* Kernel source direct download method:
```
wget https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/sources/public_sources.tbz2
```
* Follow [instructions](https://docs.nvidia.com/jetson/archives/r35.1/DeveloperGuide/text/AT/JetsonLinuxToolchain.html) to set up Bootlin gcc 9.3.0 toolchain
* Run `./apply_patches_jetpack5.0.2.sh` to apply/reset patches (or `./apply_patches_ext_jetpack5.0.2.sh ..` if using direct download method) The patch files are located under directories named `porting`

* Run `./build_all_jetpack5.0.2.sh` to build kernel, dtb, and driver. Location of built artifacts remain same except the path for the dtb has changed from
```
images/arch/arm64/boot/dts/tegra194-p2888-0001-p2822-0000.dtb
```
to
```
images/arch/arm64/boot/dts/nvidia/tegra194-p2888-0001-p2822-0000.dtb
```
* Default `/boot/extlinux/extlinux.conf` after flashing now contains
a default FDT entry:
```
FDT /boot/dtb/kernel_tegra194-p2888-0001-p2822-0000.dtb
```
To use our dtb, whose name doesn't contain the `kernel_` prefix, modify this line to:
```
FDT /boot/dtb/tegra194-p2888-0001-p2822-0000.dtb
```
* Kernel version string has changed from 4.9.253-tegra to 5.10.104-tegra
22 changes: 14 additions & 8 deletions apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,32 @@

set -e

if [ $# != 1 ]; then
echo "1st arg should be 'apply' or 'reset'"
if [[ $# < 1 ]]; then
echo "apply_patches.sh apply [JetPack_version]"
echo "apply_patches.sh reset [JetPack_version]"
exit 1
fi

DEVDIR=$(cd `dirname $0` && pwd)

. $DEVDIR/scripts/setup-common "$2"

cd "$DEVDIR"

# NVIDIA SDK Manager's JetPack 4.6.1 source_sync.sh doesn't set the right folder name, it mismatches with the direct tar
# package source code. Correct the folder name.
if [ -d ../hardware/nvidia/platform/t19x/galen-industrial-dts ]; then
mv ../hardware/nvidia/platform/t19x/galen-industrial-dts ../hardware/nvidia/platform/t19x/galen-industrial
if [ -d sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen-industrial-dts ]; then
mv sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen-industrial-dts sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen-industrial
fi

apply_external_patches() {
if [ $1 = 'apply' ]; then
git -C ../$2 am ${PWD}/$2/*
git -C sources_$JETPACK_VERSION/$2 am ${PWD}/$2/$JETPACK_VERSION/*
elif [ $1 = 'reset' ]; then
git -C ../$2 reset --hard tegra-l4t-r32.7.1
git -C sources_$JETPACK_VERSION/$2 reset --hard $L4T_VERSION
fi
}

apply_external_patches $1 kernel/nvidia
apply_external_patches $1 kernel/kernel-4.9
apply_external_patches $1 $KERNEL_DIR
apply_external_patches $1 hardware/nvidia/platform/t19x/galen/kernel-dts

16 changes: 13 additions & 3 deletions apply_patches_ext.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash
set -e
set -x

if [[ $# < 1 ]]; then
echo "apply_patches_ext.sh source_dir [JetPack_version]"
exit 1
fi

DEVDIR=$(cd `dirname $0` && pwd)

. $DEVDIR/scripts/setup-common "$2"

cd "$DEVDIR"

# NVIDIA SDK Manager's JetPack 4.6.1 source_sync.sh doesn't set the right folder name, it mismatches with the direct tar
# package source code. Correct the folder name.
Expand All @@ -9,9 +19,9 @@ if [ -d $1/hardware/nvidia/platform/t19x/galen-industrial-dts ]; then
fi

apply_external_patches() {
cat ${PWD}/$2/* | patch -p1 --directory=${PWD}/$1/$2/
cat ${PWD}/$2/$JETPACK_VERSION/* | patch -p1 --directory=${PWD}/$1/$2/
}

apply_external_patches $1 kernel/nvidia
apply_external_patches $1 kernel/kernel-4.9
apply_external_patches $1 $KERNEL_DIR
apply_external_patches $1 hardware/nvidia/platform/t19x/galen/kernel-dts
21 changes: 19 additions & 2 deletions build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,31 @@

set -e

if [[ "$1" == "-h" ]]; then
echo "build_all.sh [JetPack_version] [JetPack_Linux_source]"
echo "build_all.sh -h"
exit 1
fi

export DEVDIR=$(cd `dirname $0` && pwd)

export CROSS_COMPILE=aarch64-linux-gnu-
. $DEVDIR/scripts/setup-common "$1"

if [[ -z "$2" ]]; then
SRCS="$DEVDIR/sources_$JETPACK_VERSION"
fi

export CROSS_COMPILE=$DEVDIR/l4t-gcc/bin/aarch64-buildroot-linux-gnu-
export LOCALVERSION=-tegra
export TEGRA_KERNEL_OUT=$DEVDIR/images
mkdir -p $TEGRA_KERNEL_OUT
export KERNEL_MODULES_OUT=$TEGRA_KERNEL_OUT/modules
cd $DEVDIR/../kernel/kernel-4.9

if [[ $JETPACK_VERSION =~ 5.* ]]; then
cp $DEVDIR/d4xx.c $DEVDIR/sources_$JETPACK_VERSION/kernel/nvidia/drivers/media/i2c/
fi
cd $SRCS/$KERNEL_DIR

make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j`nproc`
make ARCH=arm64 O=$TEGRA_KERNEL_OUT modules_install INSTALL_MOD_PATH=$KERNEL_MODULES_OUT -j`nproc`
Loading

0 comments on commit f8c4c03

Please sign in to comment.