Skip to content

Commit

Permalink
l4t jp6 wip3
Browse files Browse the repository at this point in the history
  • Loading branch information
dmipx committed Jun 17, 2024
1 parent a843a8f commit ea7d834
Showing 1 changed file with 77 additions and 77 deletions.
154 changes: 77 additions & 77 deletions scripts/patch-realsense-ubuntu-L4T.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# The script utilizes `sources_sync.sh` provided as
# part of NVidia SDK installer
# part of NVIDIA(R) SDK installer

echo -e "\e[32mThe script patches and applies in-tree kernel modules required for Librealsense SDK\e[0m"
set -e
Expand Down Expand Up @@ -49,31 +49,29 @@ fi
PATCHES_REV=""
#Select the kernel patches revision that matches the paltform configuration
case ${JETSON_L4T_VERSION} in

"32.2.1" | "32.2.3" | "32.3.1" | "32.4.3")
PATCHES_REV="4.4" # Baseline for the patches
echo -e "\e[32mNote: the patch makes changes to kernel device tree to support HID IMU sensors\e[0m"
;;
"32.4.4" | "32.5" | "32.5.1" | "32.6.1" | "32.7.1")
PATCHES_REV="4.4.1" # JP 4.4.1, 32.7.1 is JP 4.6.1
;;
"35.1")
PATCHES_REV="5.0.2" # JP 5.0.2
KERNEL_RELEASE="5.10"
;;
"36.3")
PATCHES_REV="6.0" # JP 6.0
KERNEL_RELEASE="5.15"
;;

"32.2.1" | "32.2.3" | "32.3.1" | "32.4.3")
PATCHES_REV="4.4" # Baseline for the patches
echo -e "\e[32mNote: the patch makes changes to kernel device tree to support HID IMU sensors\e[0m"
;;
"32.4.4" | "32.5" | "32.5.1" | "32.6.1" | "32.7.1")
PATCHES_REV="4.4.1" # JP 4.4.1, 32.7.1 is JP 4.6.1
;;
"35.1")
PATCHES_REV="5.0.2" # JP 5.0.2
KERNEL_RELEASE="5.10"
;;
"36.3")
PATCHES_REV="6.0" # JP 6.0
KERNEL_RELEASE="5.15"
;;
*)
echo -e "\e[41mUnsupported JetPack revision ${JETSON_L4T_VERSION} aborting script\e[0m"
exit;
;;
echo -e "\e[41mUnsupported JetPack revision ${JETSON_L4T_VERSION} aborting script\e[0m"
exit;
;;
esac
echo -e "\e[32mL4T ${JETSON_L4T_VERSION} to use patches revision ${PATCHES_REV}\e[0m"

# JP6.0 fails on:
# TODO: JP6.0 fails on:
# dpkg-dev : Depends: libdpkg-perl (= 1.21.1ubuntu2.1) but 1.21.1ubuntu2.3 is to be installed
#if [ "6.0" = "$PATCHES_REV" ]; then
# sudo apt install libdpkg-perl=1.21.1ubuntu2.1 -y
Expand All @@ -83,48 +81,48 @@ echo -e "\e[32mL4T ${JETSON_L4T_VERSION} to use patches revision ${PATCHES_REV}\
sudo apt-get install build-essential git libssl-dev -y
if [ "6.0" != "$PATCHES_REV" ]; then
# Get the linux kernel repo, extract the L4T tag
echo -e "\e[32mRetrieve the corresponding L4T git tag the kernel source tree\e[0m"
l4t_gh_dir=../linux-${KERNEL_RELEASE}-source-tree
if [ ! -d ${l4t_gh_dir} ]; then
mkdir ${l4t_gh_dir}
echo -e "\e[32mRetrieve the corresponding L4T git tag the kernel source tree\e[0m"
l4t_gh_dir=../linux-${KERNEL_RELEASE}-source-tree
if [ ! -d ${l4t_gh_dir} ]; then
mkdir ${l4t_gh_dir}
pushd ${l4t_gh_dir}
git init
git remote add origin git://nv-tegra.nvidia.com/linux-${KERNEL_RELEASE}
# Use NVIDIA script instead to synchronize source tree and peripherals
#git clone git://nv-tegra.nvidia.com/linux-${KERNEL_RELEASE}
popd
else
echo -e "Directory ${l4t_gh_dir} is present, skipping initialization...\e[0m"
fi

#Search the repository for the tag that matches the maj.min for L4T
pushd ${l4t_gh_dir}
git init
git remote add origin git://nv-tegra.nvidia.com/linux-${KERNEL_RELEASE}
# Use Nvidia script instead to synchronize source tree and peripherals
#git clone git://nv-tegra.nvidia.com/linux-${KERNEL_RELEASE}
TEGRA_TAG=$(git ls-remote --tags origin | grep ${JETSON_L4T_VERSION} | grep '[^^{}]$' | tail -n 1 | awk -F/ '{print $NF}')
echo -e "\e[32mThe matching L4T source tree tag is \e[47m${TEGRA_TAG}\e[0m"
popd
else
echo -e "Directory ${l4t_gh_dir} is present, skipping initialization...\e[0m"
fi

#Search the repository for the tag that matches the maj.min for L4T
pushd ${l4t_gh_dir}
TEGRA_TAG=$(git ls-remote --tags origin | grep ${JETSON_L4T_VERSION} | grep '[^^{}]$' | tail -n 1 | awk -F/ '{print $NF}')
echo -e "\e[32mThe matching L4T source tree tag is \e[47m${TEGRA_TAG}\e[0m"
popd
fi

#Retrieve tegra tag version for sync, required for get and sync kernel source with Jetson:
#https://forums.developer.nvidia.com/t/r32-1-tx2-how-can-i-build-extra-module-in-the-tegra-device/72942/9
#Download kernel and peripheral sources as the L4T github repo is not self-contained to build kernel modules
sdk_dir=$(pwd)
echo -e "\e[32mCreate the sandbox - NVidia L4T source tree(s)\e[0m"
echo -e "\e[32mCreate the sandbox - NVIDIA L4T source tree(s)\e[0m"
mkdir -p ${sdk_dir}/Tegra
TEGRA_SOURCE_SYNC_SH="source_sync.sh"
if [ "5.0.2" = "$PATCHES_REV" ]; then
TEGRA_SOURCE_SYNC_SH="source_sync_5.0.2.sh"
TEGRA_SOURCE_SYNC_SH="source_sync_5.0.2.sh"
fi
if [ "6.0" = "$PATCHES_REV" ]; then
TEGRA_SOURCE_SYNC_SH="source_sync_6.0.sh"
TEGRA_TAG="jetson_36.3"
TEGRA_SOURCE_SYNC_SH="source_sync_6.0.sh"
TEGRA_TAG="jetson_36.3"
fi
cp ./scripts/Tegra/$TEGRA_SOURCE_SYNC_SH ${sdk_dir}/Tegra
#Download NVidia source, disregard errors on module tag sync
#Download NVIDIA source, disregard errors on module tag sync
./Tegra/$TEGRA_SOURCE_SYNC_SH -k ${TEGRA_TAG} || true
if [ "6.0" = "$PATCHES_REV" ]; then
KBASE=./Tegra/kernel/kernel-jammy-src
KBASE=./Tegra/kernel/kernel-jammy-src
else
KBASE=./Tegra/sources/kernel/kernel-$KERNEL_RELEASE
KBASE=./Tegra/sources/kernel/kernel-$KERNEL_RELEASE
fi

echo ${KBASE}
Expand All @@ -143,20 +141,17 @@ fi
echo -e "\e[32mPrepare workspace for kernel build\e[0m"

if [ "6.0" = "$PATCHES_REV" ]; then
make ARCH=arm64 mrproper -j$(($(nproc)-1))
echo -e "\e[32mUpdate the kernel tree to support HID IMU sensors\e[0m"
# echo 'CONFIG_HID=m' >> ./arch/arm64/configs/defconfig
# echo 'CONFIG_HID_RAW=y' >> ./arch/arm64/configs/defconfig
# echo 'CONFIG_HID_GENERIC=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_HUB=m' >> ./arch/arm64/configs/defconfig
# echo 'CONFIG_USB_HID=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_ACCEL_3D=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_GYRO_3D=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_IIO_COMMON=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_IIO_TRIGGER=m' >> ./arch/arm64/configs/defconfig
make ARCH=arm64 defconfig -j$(($(nproc)-1))
make ARCH=arm64 mrproper -j$(($(nproc)-1))
echo -e "\e[32mUpdate the kernel tree to support HID IMU sensors\e[0m"
# appending config to defconfig so later .config will be generated with all necessary dependencies
echo 'CONFIG_HID_SENSOR_HUB=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_ACCEL_3D=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_GYRO_3D=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_IIO_COMMON=m' >> ./arch/arm64/configs/defconfig
echo 'CONFIG_HID_SENSOR_IIO_TRIGGER=m' >> ./arch/arm64/configs/defconfig
make ARCH=arm64 defconfig -j$(($(nproc)-1))
else
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1))
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1))
fi
#Reuse existing module.symver
kernel_ver=`uname -r`
Expand All @@ -169,12 +164,13 @@ if [ "6.0" = "$PATCHES_REV" ]; then
fi

if [ "6.0" = "$PATCHES_REV" ]; then
# cp /usr/src/$LINUX_HEADERS_NAME/3rdparty/canonical/linux-jammy/kernel-source/Module.symvers .
# cp /usr/src/$LINUX_HEADERS_NAME/3rdparty/canonical/linux-jammy/kernel-source/Makefile .
echo ""
# we will skip copy module symbols as it will result in failing to compile iio core modules
#cp /usr/src/$LINUX_HEADERS_NAME/3rdparty/canonical/linux-jammy/kernel-source/Module.symvers .
#cp /usr/src/$LINUX_HEADERS_NAME/3rdparty/canonical/linux-jammy/kernel-source/Makefile .
echo ""
else
cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Module.symvers .
cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Makefile .
cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Module.symvers .
cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Makefile .
fi

#Jetpack prior to 4.4.1 requires manual reconfiguration of kernel
Expand All @@ -191,22 +187,22 @@ make ARCH=arm64 prepare modules_prepare LOCALVERSION='' -j$(($(nproc)-1))
git reset --hard
echo -e "\e[32mApply Librealsense Kernel Patches\e[0m"
if [ "6.0" != "$PATCHES_REV" ]; then
patch -p1 < ./LRS_Patches/01-realsense-camera-formats-L4T-${PATCHES_REV}.patch
patch -p1 < ./LRS_Patches/02-realsense-metadata-L4T-${PATCHES_REV}.patch
if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older
patch -p1 < ./LRS_Patches/03-realsense-hid-L4T-4.9.patch
fi
if [ "5.0.2" != "$PATCHES_REV" ]; then
patch -p1 < ./LRS_Patches/04-media-uvcvideo-mark-buffer-error-where-overflow.patch
fi
patch -p1 < ./LRS_Patches/05-realsense-powerlinefrequency-control-fix.patch
patch -p1 < ./LRS_Patches/01-realsense-camera-formats-L4T-${PATCHES_REV}.patch
patch -p1 < ./LRS_Patches/02-realsense-metadata-L4T-${PATCHES_REV}.patch
if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older
patch -p1 < ./LRS_Patches/03-realsense-hid-L4T-4.9.patch
fi
if [ "5.0.2" != "$PATCHES_REV" ]; then
patch -p1 < ./LRS_Patches/04-media-uvcvideo-mark-buffer-error-where-overflow.patch
fi
patch -p1 < ./LRS_Patches/05-realsense-powerlinefrequency-control-fix.patch
fi

if [ "6.0" = "$PATCHES_REV" ]; then
patch -p1 < ${sdk_dir}/scripts/realsense-camera-formats-jammy-master.patch
patch -p1 < ${sdk_dir}/scripts/realsense-metadata-jammy-master.patch
patch -p1 < ${sdk_dir}/scripts/realsense-powerlinefrequency-control-fix-jammy.patch
sed -i s'/1.1.1/1.1.2/'g ./drivers/media/usb/uvc/uvcvideo.h
patch -p1 < ${sdk_dir}/scripts/realsense-camera-formats-jammy-master.patch
patch -p1 < ${sdk_dir}/scripts/realsense-metadata-jammy-master.patch
patch -p1 < ${sdk_dir}/scripts/realsense-powerlinefrequency-control-fix-jammy.patch
sed -i s'/1.1.1/1.1.1-realsense/'g ./drivers/media/usb/uvc/uvcvideo.h
fi

echo -e "\e[32mCompiling uvcvideo kernel module\e[0m"
Expand Down Expand Up @@ -241,15 +237,18 @@ fi

if [ "6.0" = "$PATCHES_REV" ]; then # for Jetpack 6
sudo mkdir -p /lib/modules/$(uname -r)/extra/
# uvc modules with formats/sku support
sudo cp drivers/media/usb/uvc/uvcvideo.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/media/v4l2-core/videodev.ko /lib/modules/$(uname -r)/extra/
# iio modules for iio-hid support
sudo cp drivers/iio/buffer/kfifo_buf.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/iio/buffer/industrialio-triggered-buffer.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/iio/common/hid-sensors/hid-sensor-iio-common.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/hid/hid-sensor-hub.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/iio/accel/hid-sensor-accel-3d.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/iio/gyro/hid-sensor-gyro-3d.ko /lib/modules/$(uname -r)/extra/
sudo cp drivers/iio/common/hid-sensors/hid-sensor-trigger.ko /lib/modules/$(uname -r)/extra/
# set depmod search path to include "extra" modules
sudo sed -i 's/search updates/search extra updates/g' /etc/depmod.d/ubuntu.conf
fi
popd
Expand All @@ -275,6 +274,7 @@ if [ "6.0" != "$PATCHES_REV" ]; then
try_load_module hid-sensor-gyro-3d
try_load_module hid-sensor-accel-3d
else
# for JP6.0 we will try to remove old modules and then load updated ones
echo -e "\e[32mUnload kernel modules\e[0m"
try_unload_module uvcvideo
try_unload_module hid_sensor_accel_3d
Expand Down

0 comments on commit ea7d834

Please sign in to comment.