Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JP6 d4xx integration #182

Merged
merged 7 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 90 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# D457 MIPI on Jetson AGX Xavier
The RealSense MIPI platform driver enables the user to control and stream RealSense 3D MIPI cameras.
The system shall include:
* Jetson platform (Currently Supported JetPack versions are: 5.0.2, 4.6.1)
* Jetson platform (Currently Supported JetPack versions are: 6.0, 5.1.2, 5.0.2, 4.6.1)
* RealSense De-Serialize board (https://store.intelrealsense.com/buy-intel-realsense-des457.html)
* RS MIPI camera (e.g. https://store.intelrealsense.com/buy-intel-realsense-depth-camera-d457.html)

Expand All @@ -25,9 +25,26 @@ The developers can set up the source code with NVIDIA's Jetson git repositories
./setup_workspace.sh [JetPack_version]
```

Or download Jetson Linux source code tarball from [JetPack 5.1.2 BSP sources](https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v4.1/sources/public_sources.tbz2), [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).
Or download Jetson Linux source code tarball from
- [JetPack 6.0-DP BSP sources](https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v2.0/sources/public_sources.tbz2)
- [JetPack 5.1.2 BSP sources](https://developer.nvidia.com/downloads/embedded/l4t/r35_release_v4.1/sources/public_sources.tbz2)
- [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)

```
# JetPack 6.0
mkdir -p l4t-gcc/6.0
cd ./l4t-gcc/6.0
wget https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v2.0/toolchain/aarch64--glibc--stable-2022.08-1.tar.bz2 -O aarch64--glibc--stable-final.tar.bz2
tar xf aarch64--glibc--stable-final.tar.bz2 --strip-components 1
cd ../..
wget https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v2.0/sources/public_sources.tbz2
tar xjf public_sources.tbz2
cd Linux_for_Tegra/source
tar xjf kernel_src.tbz2
tar xjf kernel_oot_modules_src.tbz2
tar xjf nvidia_kernel_display_driver_source.tbz2

# JetPack 5.1.2
mkdir -p l4t-gcc/5.1.2
cd ./l4t-gcc/5.1.2
Expand All @@ -43,14 +60,14 @@ tar xjf kernel_src.tbz2
mkdir -p l4t-gcc/5.0.2
cd ./l4t-gcc/5.0.2
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
tar xf aarch64--glibc--stable-final.tar.gz --strip-components 1
cd ../..
wget https://developer.nvidia.com/embedded/l4t/r35_release_v1.0/sources/public_sources.tbz2
tar xjf public_sources.tbz2
cd Linux_for_Tegra/source/public
tar xjf kernel_src.tbz2

# or JetPack 4.6.1
# JetPack 4.6.1
mkdir -p l4t-gcc/4.6.1
cd ./l4t-gcc/4.6.1
wget http://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
Expand All @@ -70,6 +87,8 @@ Apply D457 patches and build the kernel image, dtb and D457 driver.

# or, if using direct download method
# ./apply_patches_ext.sh [--one-cam | --dual-cam] ./Linux_for_tegra/source/public [JetPack_version]
# for JP6.0, source path is ./Linux_for_tegra/source :
# ./apply_patches_ext.sh ./Linux_for_tegra/source 6.0

Note: The `--one-cam` and `--dual-cam` option applies only for JetPack 5.0.2,
compatible with adapter: https://store.intelrealsense.com/buy-intel-realsense-des457.html.
Expand All @@ -91,6 +110,71 @@ sudo apt install build-essential bc flex bison

Debian packages will be generated in `images` folder.

## Install kernel and D457 driver to Jetson Orin
<details>
<summary>JP6.0 build results</summary>

- kernel image (not modified): `images/6.0/rootfs/boot/Image`
- dtb overlay: `images/6.0/rootfs/boot/tegra234-camera-d4xx-overlay.dtbo`
- oot modules: `images/6.0/rootfs/lib/modules/5.15.122-tegra/extra`

Following steps required:

1. Copy entire directory `images/6.0/rootfs/lib/modules/5.15.122-tegra/extra/` from host to `/lib/modules/5.15.122-tegra/extra/` on Orin
2. Copy `tegra234-camera-d4xx-overlay.dtbo` from host to `/boot/tegra234-camera-d4xx-overlay.dtbo` on Orin
3. Run $ `sudo /opt/nvidia/jetson-io/jetson-io.py`
1. Configure Jetson AGX CSI Connector
2. Configure for compatible hardware
3. Jetson RealSense Camera D457
4. $ `sudo depmod`
5. $ `echo "d4xx" | sudo tee /etc/modules-load.d/d4xx.conf`
4. Reboot

Copy them to the right places:

```
scp -r images/6.0/rootfs/boot/tegra234-camera-d4xx-overlay.dtbo [email protected]:~/
scp -r images/6.0/rootfs/lib/modules/5.15.122-tegra/extra [email protected]:~/
```

on target:

```
sudo cp ~/tegra234-camera-d4xx-overlay.dtbo /boot/
# backup:
sudo tar -cjf /lib/modules/$(uname -r)/modules_$(uname -r)_extra.tar.bz2 /lib/modules/$(uname -r)/extra
sudo cp -r ~/extra /lib/modules/$(uname -r)/
```

Enable d4xx overlay:

With Jetson-IO tool:
`sudo /opt/nvidia/jetson-io/jetson-io.py`

1. Configure Jetson AGX CSI Connector
2. Configure for compatible hardware
3. Jetson RealSense Camera D457

With command line

`sudo /opt/nvidia/jetson-io/config-by-hardware.py -n 2="Jetson RealSense Camera D457"`

Expected:
```
nvidia@ubuntu:~$ sudo /opt/nvidia/jetson-io/config-by-hardware.py -n 2="Jetson RealSense Camera D457"
Configuration saved to /boot/tegra234-camera-d4xx-overlay.dtbo.
Reboot system to reconfigure.
```
Enable d4xx autoload:

`echo "d4xx" | sudo tee /etc/modules-load.d/d4xx.conf`

`sudo depmod`

---

</details>

## Install kernel and D457 driver to Jetson AGX Xavier

1. Install the kernel and modules
Expand All @@ -101,7 +185,8 @@ Copy the Debian package `linux-image-5.10.104-d457_5.10.104-d457-1_arm64.deb` to

1.2 If building with `build_all.sh`

The necessary files are at
The necessary files are:

- kernel image `images/<JetPack_version>/arch/arm64/boot/Image`
- dtb `images/<JetPack_version>/arch/arm64/boot/dts/nvidia/tegra194-p2888-0001-p2822-0000.dtb`, or `images/4.6.1/arch/arm64/boot/dts/tegra194-p2888-0001-p2822-0000.dtb` for JetPack 4.6.1.
- D457 driver `images/<JetPack_version>/drivers/media/i2c/d4xx.ko`
Expand Down
31 changes: 24 additions & 7 deletions apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ cd "$DEVDIR"
if [[ "$JETPACK_VERSION" == "4.6.1" ]]; then
JP5_D4XX_DTSI="tegra194-camera-d4xx.dtsi"
fi

if [[ "$JETPACK_VERSION" == "6.0" ]]; then
D4XX_SRC_DST=nvidia-oot
else
D4XX_SRC_DST=kernel/nvidia
fi
# 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 sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen-industrial-dts ]; then
Expand All @@ -46,13 +50,26 @@ apply_external_patches() {
fi
}

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

if [ -d ${KERNEL_DIR}/${JETPACK_VERSION} ]; then
apply_external_patches $1 $KERNEL_DIR
fi

if [[ "$JETPACK_VERSION" == "6.0" ]]; then
apply_external_patches $1 hardware/nvidia/t23x/nv-public
else
apply_external_patches $1 hardware/nvidia/platform/t19x/galen/kernel-dts
fi

if [ $1 = 'apply' ]; then
cp $DEVDIR/kernel/realsense/d4xx.c $DEVDIR/sources_$JETPACK_VERSION/kernel/nvidia/drivers/media/i2c/
cp $DEVDIR/hardware/realsense/$JP5_D4XX_DTSI $DEVDIR/sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-camera-d4xx.dtsi
cp $DEVDIR/kernel/realsense/d4xx.c $DEVDIR/sources_$JETPACK_VERSION/${D4XX_SRC_DST}/drivers/media/i2c/
if [[ "$JETPACK_VERSION" == "6.0" ]]; then
# jp6 overlay
cp $DEVDIR/hardware/realsense/tegra234-camera-d4xx-overlay.dts $DEVDIR/sources_$JETPACK_VERSION/hardware/nvidia/t23x/nv-public/overlay/
else
cp $DEVDIR/hardware/realsense/$JP5_D4XX_DTSI $DEVDIR/sources_$JETPACK_VERSION/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-camera-d4xx.dtsi
fi
elif [ $1 = 'reset' ]; then
[[ -f $DEVDIR/sources_$JETPACK_VERSION/kernel/nvidia/drivers/media/i2c/d4xx.c ]] && rm $DEVDIR/sources_$JETPACK_VERSION/kernel/nvidia/drivers/media/i2c/d4xx.c
[[ -f $DEVDIR/sources_$JETPACK_VERSION/${D4XX_SRC_DST}/drivers/media/i2c/d4xx.c ]] && rm $DEVDIR/sources_$JETPACK_VERSION/${D4XX_SRC_DST}/drivers/media/i2c/d4xx.c
fi
31 changes: 24 additions & 7 deletions apply_patches_ext.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/bash
# Jetson Linux
# JP6.0 https://developer.nvidia.com/downloads/embedded/l4t/r36_release_v2.0/sources/public_sources.tbz2
set -e

if [[ $# < 1 ]]; then
Expand Down Expand Up @@ -29,21 +31,36 @@ cd "$DEVDIR"
if [[ "$JETPACK_VERSION" == "4.6.1" ]]; then
JP5_D4XX_DTSI="tegra194-camera-d4xx.dtsi"
fi

if [[ "$JETPACK_VERSION" == "6.0" ]]; then
D4XX_SRC_DST=nvidia-oot
else
D4XX_SRC_DST=kernel/nvidia
fi
# 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 $1/hardware/nvidia/platform/t19x/galen-industrial-dts ]; then
mv $1/hardware/nvidia/platform/t19x/galen-industrial-dts $1/hardware/nvidia/platform/t19x/galen-industrial
fi

apply_external_patches() {
cat ${PWD}/$2/$JETPACK_VERSION/* | 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_DIR
apply_external_patches $1 hardware/nvidia/platform/t19x/galen/kernel-dts
apply_external_patches $1 $D4XX_SRC_DST
if [ -d ${KERNEL_DIR}/${JETPACK_VERSION} ]; then
apply_external_patches $1 $KERNEL_DIR
fi
if [[ "$JETPACK_VERSION" == "6.0" ]]; then
apply_external_patches $1 hardware/nvidia/t23x/nv-public
else
apply_external_patches $1 hardware/nvidia/platform/t19x/galen/kernel-dts
fi

# For a common driver for JP4 + JP5 we override the i2c driver and ignore the previous that was created from patches
cp $DEVDIR/kernel/realsense/d4xx.c $DEVDIR/$1/kernel/nvidia/drivers/media/i2c/
cp $DEVDIR/hardware/realsense/$JP5_D4XX_DTSI $DEVDIR/$1/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-camera-d4xx.dtsi
cp $DEVDIR/kernel/realsense/d4xx.c $DEVDIR/$1/${D4XX_SRC_DST}/drivers/media/i2c/
if [[ "$JETPACK_VERSION" == "6.0" ]]; then
# jp6 overlay
cp $DEVDIR/hardware/realsense/tegra234-camera-d4xx-overlay.dts $DEVDIR/$1/hardware/nvidia/t23x/nv-public/overlay/
else
cp $DEVDIR/hardware/realsense/$JP5_D4XX_DTSI $DEVDIR/$1/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-camera-d4xx.dtsi
fi
35 changes: 29 additions & 6 deletions build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ if [[ "$1" == "-h" ]]; then
fi

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

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

SRCS="$DEVDIR/sources_$JETPACK_VERSION"
if [[ -n "$2" ]]; then
SRCS="$2"
SRCS=$(realpath $2)
fi

if [[ "$JETPACK_VERSION" == "5.1.2" ]]; then
if [[ "$JETPACK_VERSION" == "6.0" ]]; then
export CROSS_COMPILE=$DEVDIR/l4t-gcc/$JETPACK_VERSION/bin/aarch64-buildroot-linux-gnu-
elif [[ "$JETPACK_VERSION" == "5.1.2" ]]; then
export CROSS_COMPILE=$DEVDIR/l4t-gcc/$JETPACK_VERSION/bin/aarch64-buildroot-linux-gnu-
elif [[ "$JETPACK_VERSION" == "5.0.2" ]]; then
export CROSS_COMPILE=$DEVDIR/l4t-gcc/$JETPACK_VERSION/bin/aarch64-buildroot-linux-gnu-
Expand All @@ -32,8 +35,28 @@ export KERNEL_MODULES_OUT=$TEGRA_KERNEL_OUT/modules
# Check if BUILD_NUMBER is set as it will add a postfix to the kernel name "vermagic" (normally it happens on CI who have BUILD_NUMBER defined)
[[ -n "${BUILD_NUMBER}" ]] && echo "Warning! You have BUILD_NUMBER set to ${BUILD_NUMBER}, This will affect your vermagic"

cd $SRCS/$KERNEL_DIR
# Build jp6 out-of-tree modules
# following:
# https://docs.nvidia.com/jetson/archives/r36.2/DeveloperGuide/SD/Kernel/KernelCustomization.html#building-the-jetson-linux-kernel
if [[ "$JETPACK_VERSION" == "6.0" ]]; then
cd $SRCS
export KERNEL_HEADERS=$SRCS/kernel/kernel-jammy-src
ln -sf $TEGRA_KERNEL_OUT $SRCS/out
make ARCH=arm64 -C kernel
# export KERNEL_HEADERS=$SRCS/out
make ARCH=arm64 modules
make ARCH=arm64 dtbs
mkdir -p $TEGRA_KERNEL_OUT/rootfs/boot/dtb
cp $SRCS/nvidia-oot/device-tree/platform/generic-dts/dtbs/tegra234-p3737-0000+p3701-0000-nv.dtb $TEGRA_KERNEL_OUT/rootfs/boot/dtb/
cp $SRCS/nvidia-oot/device-tree/platform/generic-dts/dtbs/tegra234-camera-d4xx-overlay.dtbo $TEGRA_KERNEL_OUT/rootfs/boot/
export INSTALL_MOD_PATH=$TEGRA_KERNEL_OUT/rootfs/
make ARCH=arm64 install -C kernel
make ARCH=arm64 modules_install
else
#jp4/5
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
fi

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`
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 91e9bb1de78dbd96dc80d47e1a7c1fd28873e8fa Mon Sep 17 00:00:00 2001
From: Dmitry Perchanov <[email protected]>
Date: Mon, 29 Jan 2024 05:52:20 +0200
Subject: [PATCH] overlay: enable d4xx camera for Orin jp6

Signed-off-by: Dmitry Perchanov <[email protected]>
---
overlay/Makefile | 1 +
1 file changed, 1 insertion(+)

diff --git a/overlay/Makefile b/overlay/Makefile
index b3b0638..ff0cb54 100644
--- a/overlay/Makefile
+++ b/overlay/Makefile
@@ -54,6 +54,7 @@ dtbo-y += tegra234-p3737-camera-dual-hawk-ar0234-e3653-overlay.dtbo
dtbo-y += tegra234-p3737-camera-imx390-overlay.dtbo
dtbo-y += tegra234-p3737-camera-p3762-a00-overlay.dtbo
dtbo-y += tegra234-p3740-camera-p3783-a00-overlay.dtbo
+dtbo-y += tegra234-camera-d4xx-overlay.dtbo


ifneq ($(dtb-y),)
--
2.34.1

Loading
Loading