From 9024a6052c59f4d5a53bab6cccfe1fb3dee4c1cf Mon Sep 17 00:00:00 2001 From: Dmitry Perchanov Date: Mon, 10 Jun 2024 17:21:25 +0300 Subject: [PATCH] L4T UVC/HID manual patch for JP6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Jetson Orin™** with JetPack 6.0 manual patches for UVC compatibility with LRS Tracked-by: LRS-1066 Signed-off-by: Dmitry Perchanov --- doc/installation_jetson.md | 16 +- scripts/Tegra/source_sync_6.0.sh | 344 ++++++++++++++++++++++++++ scripts/patch-realsense-ubuntu-L4T.sh | 210 +++++++++++----- 3 files changed, 503 insertions(+), 67 deletions(-) create mode 100755 scripts/Tegra/source_sync_6.0.sh diff --git a/doc/installation_jetson.md b/doc/installation_jetson.md index 3ac47dfad35..32862446d6c 100644 --- a/doc/installation_jetson.md +++ b/doc/installation_jetson.md @@ -1,4 +1,4 @@ -# Nvidia Jetson Devices +# NVIDIA Jetson Devices **NOTE**: See [support-matrix.md](./support-matrix.md) to learn more about Jetson support for RealSense devices. @@ -8,14 +8,12 @@ ### 1. Prerequisites -* Nvidia® **Jetson Nano™**, **Jetson TX2™**, **Jetson AGX Xavier™** or **Jetson Orin™** board (may also work on other Jetson devices) +* NVIDIA® **Jetson Nano™**, **Jetson TX2™**, **Jetson AGX Xavier™** or **Jetson Orin™** board (may also work on other Jetson devices) * A supported RealSense Camera device ### 2. Establish Developer's Environment -Follow [official instructions](https://developer.nvidia.com/embedded/learn/getting-started-jetson) to get your board ready. This guide will assume you are using **Nvidia® L4T Ubuntu 16.04/18.04/20.04/22.04** image with kernels 4.9/5.10/5.15. Note that in most cases it is necessary to install a toll named "SDK Manager" to flash and install **Jetson** boards with both the L4T (Linux for Tegra) and Nvidia-specific software packages (CUDA, Tensor Flow, AI, etc.) - -For **Jetson Orin™** with JetPack 6.0 you will need to follow build for MIPI driver as Nvidia released Kernel 5.15 default configuration with disabled HID: [Intel® RealSense™ camera driver for GMSL* interface](https://github.com/IntelRealSense/realsense_mipi_platform_driver) +Follow [official instructions](https://developer.nvidia.com/embedded/learn/getting-started-jetson) to get your board ready. This guide will assume you are using **NVIDIA® L4T Ubuntu 16.04/18.04/20.04/22.04** image with kernels 4.9/5.10/5.15. Note that in most cases it is necessary to install a toll named "SDK Manager" to flash and install **Jetson** boards with both the L4T (Linux for Tegra) and NVIDIA-specific software packages (CUDA, Tensor Flow, AI, etc.) For **Jetson Nano™** we strongly recommend enabling the Barrel Jack connector for extra power (See [jetsonhacks.com/jetson-nano-use-more-power/](https://www.jetsonhacks.com/2019/04/10/jetson-nano-use-more-power/) to learn how) @@ -39,7 +37,7 @@ If that's the case, what is the dilemma? In order to enable the full capabilities of RealSense devices certain modifications in the kernel (driver) modules shall be applied, such as support of Depth-related streaming formats and access to per-frame metadata attributes. There is a small set of generic kernel changes that are mostly retrofitted with more advanced kernel versions aimed at improving the overall drivers stability. -Nvidia's L4T delivers an Ubuntu-based distribution with a customized kernel based on version 4.9/5.10. The way the kernel is configured and deployed is different from a desktop Ubuntu image with two notable differences being the list of kernel modules included in default configuration and the way a new image is flashed. +NVIDIA's L4T delivers an Ubuntu-based distribution with a customized kernel based on version 4.9/5.10. The way the kernel is configured and deployed is different from a desktop Ubuntu image with two notable differences being the list of kernel modules included in default configuration and the way a new image is flashed. And while it is possible to rebuild and flash a new kernel image the procedure can be perceived as challenging and shall be performed with extra caution. This guide comes with a script that allows to modify the kernel modules with Librealsense2-related patches without replacing the kernel image. The script has been verified with **Jetson AGX Xavier™** board using L4T versions 4.2.3, 4.3, 4.4 (Sept 2020) and 5.0.2. Scroll to the end of the guide for details. @@ -93,12 +91,10 @@ You can also double-TAB after typing `rs-` to see the full list of SDK examples. ⮕ Use the V4L Native backend by applying the kernel patching -The method was verified with **Jetson AGX** boards with JetPack **4.2.3**[L4T 32.2.1,32.2.3], **4.3**[L4T 32.3.1], **4.4**[L4T 32.4.3], **4.5.1**[L4T 32.5.1] and **5.0.2**[L4T 35.1.0]. +The method was verified with **Jetson Orin™** with JetPack 6.0, **Jetson AGX** boards with JetPack **4.2.3**[L4T 32.2.1,32.2.3], **4.3**[L4T 32.3.1], **4.4**[L4T 32.4.3], **4.5.1**[L4T 32.5.1] and **5.0.2**[L4T 35.1.0]. The method has not yet been verified on the **Jetson Nano** board. -This method is incompatible for board **Jetson Orin™** with JetPack 6.0, checkout [Intel® RealSense™ camera driver for GMSL* interface](https://github.com/IntelRealSense/realsense_mipi_platform_driver) - * **Prerequisite** * Verify the board type and Jetpack versions compatibility. @@ -138,7 +134,7 @@ This method is incompatible for board **Jetson Orin™** with JetPack 6.0, check cmake .. -DBUILD_EXAMPLES=true -DCMAKE_BUILD_TYPE=release -DFORCE_RSUSB_BACKEND=false -DBUILD_WITH_CUDA=true && make -j$(($(nproc)-1)) && sudo make install ``` - The CMAKE `-DBUILD_WITH_CUDA=true` flag assumes CUDA modules are installed. If not, please reconnect the board to the Ubuntu Host PC and use Nvidia `SDK Manager` tool to install the missing components. + The CMAKE `-DBUILD_WITH_CUDA=true` flag assumes CUDA modules are installed. If not, please reconnect the board to the Ubuntu Host PC and use NVIDIA `SDK Manager` tool to install the missing components. * **Connect Realsense Device, run `realsense-viewer` and inspect the results** diff --git a/scripts/Tegra/source_sync_6.0.sh b/scripts/Tegra/source_sync_6.0.sh new file mode 100755 index 00000000000..3614d6cc24c --- /dev/null +++ b/scripts/Tegra/source_sync_6.0.sh @@ -0,0 +1,344 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: Copyright (c) 2012-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# SPDX-License-Identifier: BSD-3-Clause +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +# +# This script sync's NVIDIA's version of +# 1. the kernel source +# from nv-tegra, NVIDIA's public git repository. +# The script also provides opportunities to the sync to a specific tag +# so that the binaries shipped with a release can be replicated. +# +# Usage: +# By default it will download all the listed sources +# ./source_sync.sh +# Use the -t option to provide the TAG to be used to sync all the sources. +# Use the -k option to download only the kernel and device tree repos and optionally sync to TAG +# For detailed usage information run with -h option. +# + + +# verify that git is installed +if ! which git > /dev/null ; then + echo "ERROR: git is not installed. If your linux distro is 10.04 or later," + echo "git can be installed by 'sudo apt-get install git-core'." + exit 1 +fi + +# source dir +LDK_DIR=$(cd `dirname $0` && pwd) +# script name +SCRIPT_NAME=`basename $0` +# info about sources. +# NOTE: *Add only kernel repos here. Add new repos separately below. Keep related repos together* +# NOTE: nvethrnetrm.git should be listed after "linux-nv-oot.git" due to nesting of sync path +SOURCE_INFO=" +k:kernel/kernel-jammy-src:nv-tegra.nvidia.com/3rdparty/canonical/linux-jammy.git: +k:nvgpu:nv-tegra.nvidia.com/linux-nvgpu.git: +k:nvidia-oot:nv-tegra.nvidia.com/linux-nv-oot.git: +k:hwpm:nv-tegra.nvidia.com/linux-hwpm.git: +k:nvethernetrm:nv-tegra.nvidia.com/kernel/nvethernetrm.git: +k:hardware/nvidia/t23x/nv-public:nv-tegra.nvidia.com/device/hardware/nvidia/t23x-public-dts.git: +k:hardware/nvidia/tegra/nv-public:nv-tegra.nvidia.com/device/hardware/nvidia/tegra-public-dts.git: +k:nvdisplay:nv-tegra.nvidia.com/tegra/kernel-src/nv-kernel-display-driver.git: +k:dtc-src/1.4.5:nv-tegra.nvidia.com/3rdparty/dtc-src/1.4.5.git: +o:tegra/argus-cam-libav/argus_cam_libavencoder:nv-tegra.nvidia.com/tegra/argus-cam-libav/argus_cam_libavencoder.git: +o:tegra/cuda-src/nvsample_cudaprocess:nv-tegra.nvidia.com/tegra/cuda-src/nvsample_cudaprocess.git: +o:tegra/gfx-src/nv-xconfig:nv-tegra.nvidia.com/tegra/gfx-src/nv-xconfig.git: +o:tegra/gst-src/gst-egl:nv-tegra.nvidia.com/tegra/gst-src/gst-egl.git: +o:tegra/gst-src/gst-jpeg:nv-tegra.nvidia.com/tegra/gst-src/gst-jpeg.git: +o:tegra/gst-src/gst-nvarguscamera:nv-tegra.nvidia.com/tegra/gst-src/gst-nvarguscamera.git: +o:tegra/gst-src/gst-nvcompositor:nv-tegra.nvidia.com/tegra/gst-src/gst-nvcompositor.git: +o:tegra/gst-src/gst-nvtee:nv-tegra.nvidia.com/tegra/gst-src/gst-nvtee.git: +o:tegra/gst-src/gst-nvv4l2camera:nv-tegra.nvidia.com/tegra/gst-src/gst-nvv4l2camera.git: +o:tegra/gst-src/gst-nvvidconv:nv-tegra.nvidia.com/tegra/gst-src/gst-nvvidconv.git: +o:tegra/gst-src/gst-nvvideo4linux2:nv-tegra.nvidia.com/tegra/gst-src/gst-nvvideo4linux2.git: +o:tegra/gst-src/nvgstapps:nv-tegra.nvidia.com/tegra/gst-src/nvgstapps.git: +o:tegra/gst-src/libgstnvcustomhelper:nv-tegra.nvidia.com/tegra/gst-src/libgstnvcustomhelper.git: +o:tegra/gst-src/libgstnvdrmvideosink:nv-tegra.nvidia.com/tegra/gst-src/libgstnvdrmvideosink.git: +o:tegra/gst-src/libgstnvvideosinks:nv-tegra.nvidia.com/tegra/gst-src/libgstnvvideosinks.git: +o:tegra/v4l2-src/libv4l2_nvargus:nv-tegra.nvidia.com/tegra/v4l2-src/libv4l2_nvargus.git: +o:tegra/nv-sci-src/nvsci_headers:nv-tegra.nvidia.com/tegra/nv-sci-src/nvsci_headers.git: +o:tegra/optee-src/atf:nv-tegra.nvidia.com/tegra/optee-src/atf.git: +o:tegra/optee-src/nv-optee:nv-tegra.nvidia.com/tegra/optee-src/nv-optee.git: +o:tegra/v4l2-src/v4l2_libs:nv-tegra.nvidia.com/tegra/v4l2-src/v4l2_libs.git: +" + +# exit on error on sync +EOE=0 +# after processing SOURCE_INFO +NSOURCES=0 +declare -a SOURCE_INFO_PROCESSED +# download all? +DALL=1 + +function Usages { + local ScriptName=$1 + local LINE + local OP + local DESC + local PROCESSED=() + local i + + echo "Use: $1 [options]" + echo "Available general options are," + echo " -h : help" + echo " -e : exit on sync error" + echo " -d [DIR] : root of source is DIR" + echo " -t [TAG] : Git tag that will be used to sync all the sources" + echo "" + echo "By default, all sources are downloaded." + echo "Only specified sources are downloaded, if one or more of the following options are mentioned." + echo "" + echo "$SOURCE_INFO" | while read LINE; do + if [ ! -z "$LINE" ]; then + OP=$(echo "$LINE" | cut -f 1 -d ':') + DESC=$(echo "$LINE" | cut -f 2 -d ':') + if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then + echo " -${OP} [TAG]: Download $DESC source and optionally sync to TAG" + PROCESSED+=("${OP}") + else + echo " and download $DESC source and sync to the same TAG" + fi + fi + done + echo "" +} + +function ProcessSwitch { + local SWITCH="$1" + local TAG="$2" + local i + local found=0 + + for ((i=0; i < NSOURCES; i++)); do + local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':') + if [ "-${OP}" == "$SWITCH" ]; then + SOURCE_INFO_PROCESSED[i]="${SOURCE_INFO_PROCESSED[i]}${TAG}:y" + DALL=0 + found=1 + fi + done + + if [ "$found" == 1 ]; then + return 0 + fi + + echo "Terminating... wrong switch: ${SWITCH}" >&2 + Usages "$SCRIPT_NAME" + exit 1 +} + +function UpdateTags { + local SWITCH="$1" + local TAG="$2" + local i + + for ((i=0; i < NSOURCES; i++)); do + local OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':') + if [ "${OP}" == "$SWITCH" ]; then + SOURCE_INFO_PROCESSED[i]=$(echo "${SOURCE_INFO_PROCESSED[i]}" \ + | awk -F: -v OFS=: -v var="${TAG}" '{$4=var; print}') + fi + done +} + +function DownloadAndSync { + local WHAT_SOURCE="$1" + local LDK_SOURCE_DIR="$2" + local REPO_URL="$3" + local TAG="$4" + local OPT="$5" + local RET=0 + + if [ -d "${LDK_SOURCE_DIR}" ]; then + echo "Directory for $WHAT, ${LDK_SOURCE_DIR}, already exists!" + pushd "${LDK_SOURCE_DIR}" > /dev/null + git status 2>&1 >/dev/null + if [ $? -ne 0 ]; then + echo "But the directory is not a git repository -- clean it up first" + echo "" + echo "" + popd > /dev/null + return 1 + fi + git fetch --all 2>&1 >/dev/null + popd > /dev/null + else + echo "Downloading default $WHAT source..." + + git clone "$REPO_URL" -n ${LDK_SOURCE_DIR} 2>&1 >/dev/null + if [ $? -ne 0 ]; then + echo "$2 source sync failed!" + echo "" + echo "" + return 1 + fi + + echo "The default $WHAT source is downloaded in: ${LDK_SOURCE_DIR}" + fi + + if [ -z "$TAG" ]; then + echo "Please enter a tag to sync $2 source to" + echo -n "(enter nothing to skip): " + read TAG + TAG=$(echo $TAG) + UpdateTags $OPT $TAG + fi + + if [ ! -z "$TAG" ]; then + pushd ${LDK_SOURCE_DIR} > /dev/null + git tag -l 2>/dev/null | grep -q -P "^$TAG\$" + if [ $? -eq 0 ]; then + echo "Syncing up with tag $TAG..." + git checkout -b mybranch_$(date +%Y-%m-%d-%s) $TAG + echo "$2 source sync'ed to tag $TAG successfully!" + else + echo "Couldn't find tag $TAG" + echo "$2 source sync to tag $TAG failed!" + RET=1 + fi + popd > /dev/null + fi + echo "" + echo "" + + return "$RET" +} + +# prepare processing .... +GETOPT=":ehd:t:" + +OIFS="$IFS" +IFS=$(echo -en "\n\b") +SOURCE_INFO_PROCESSED=($(echo "$SOURCE_INFO")) +IFS="$OIFS" +NSOURCES=${#SOURCE_INFO_PROCESSED[*]} + +for ((i=0; i < NSOURCES; i++)); do + OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':') + GETOPT="${GETOPT}${OP}:" +done + +# parse the command line first +while getopts "$GETOPT" opt; do + case $opt in + d) + case $OPTARG in + -[A-Za-z]*) + Usages "$SCRIPT_NAME" + exit 1 + ;; + *) + LDK_DIR="$OPTARG" + ;; + esac + ;; + e) + EOE=1 + ;; + h) + Usages "$SCRIPT_NAME" + exit 1 + ;; + t) + TAG="$OPTARG" + PROCESSED=() + for ((i=0; i < NSOURCES; i++)); do + OP=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':') + if [[ ! " ${PROCESSED[@]} " =~ " ${OP} " ]]; then + UpdateTags $OP $TAG + PROCESSED+=("${OP}") + fi + done + ;; + [A-Za-z]) + case $OPTARG in + -[A-Za-z]*) + eval arg=\$$((OPTIND-1)) + case $arg in + -[A-Za-Z]-*) + Usages "$SCRIPT_NAME" + exit 1 + ;; + *) + ProcessSwitch "-$opt" "" + OPTIND=$((OPTIND-1)) + ;; + esac + ;; + *) + ProcessSwitch "-$opt" "$OPTARG" + ;; + esac + ;; + :) + case $OPTARG in + #required arguments + d) + Usages "$SCRIPT_NAME" + exit 1 + ;; + #optional arguments + [A-Za-z]) + ProcessSwitch "-$OPTARG" "" + ;; + esac + ;; + \?) + echo "Terminating... wrong switch: $@" >&2 + Usages "$SCRIPT_NAME" + exit 1 + ;; + esac +done +shift $((OPTIND-1)) + +GRET=0 +for ((i=0; i < NSOURCES; i++)); do + OPT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 1 -d ':') + WHAT=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 2 -d ':') + REPO=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 3 -d ':') + TAG=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 4 -d ':') + DNLOAD=$(echo "${SOURCE_INFO_PROCESSED[i]}" | cut -f 5 -d ':') + + if [ $DALL -eq 1 -o "x${DNLOAD}" == "xy" ]; then + DownloadAndSync "$WHAT" "${LDK_DIR}/${WHAT}" "git://${REPO}" "${TAG}" "${OPT}" + tRET=$? + let GRET=GRET+tRET + if [ $tRET -ne 0 -a $EOE -eq 1 ]; then + exit $tRET + fi + fi +done + +ln -sf ../../../../../../nvethernetrm ${LDK_DIR}/nvidia-oot/drivers/net/ethernet/nvidia/nvethernet/nvethernetrm + +exit $GRET diff --git a/scripts/patch-realsense-ubuntu-L4T.sh b/scripts/patch-realsense-ubuntu-L4T.sh index 4205bc6b2c7..fc6b5048975 100755 --- a/scripts/patch-realsense-ubuntu-L4T.sh +++ b/scripts/patch-realsense-ubuntu-L4T.sh @@ -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 @@ -19,10 +19,7 @@ then fi #Include usability functions -source ./scripts/patch-utils.sh - -# Get the required tools to build the patched modules -sudo apt-get install build-essential git libssl-dev -y +source ./scripts/patch-utils-hwe.sh #Activate fan to prevent overheat during KM compilation if [ -f /sys/devices/pwm-fan/target_pwm ]; then @@ -52,62 +49,82 @@ 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" + "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" +# 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 +#fi +# Get the required tools to build the patched modules +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 - - #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" 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 -KBASE=./Tegra/sources/kernel/kernel-$KERNEL_RELEASE +if [ "6.0" = "$PATCHES_REV" ]; then + KBASE=./Tegra/kernel/kernel-jammy-src +else + KBASE=./Tegra/sources/kernel/kernel-$KERNEL_RELEASE +fi + echo ${KBASE} pushd ${KBASE} @@ -122,16 +139,39 @@ fi #Clean the kernel WS echo -e "\e[32mPrepare workspace for kernel build\e[0m" -make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1)) +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" + # 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)) +fi #Reuse existing module.symver kernel_ver=`uname -r` LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu18.04_aarch64" if [ "5.0.2" = "$PATCHES_REV" ]; then LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu20.04_aarch64" fi -cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Module.symvers . -cp /usr/src/$LINUX_HEADERS_NAME/kernel-$KERNEL_RELEASE/Makefile . +if [ "6.0" = "$PATCHES_REV" ]; then + LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu22.04_aarch64" +fi + +if [ "6.0" = "$PATCHES_REV" ]; then + # 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 . +fi #Jetpack prior to 4.4.1 requires manual reconfiguration of kernel if [ "4.4" = "$PATCHES_REV" ]; then @@ -140,20 +180,30 @@ if [ "4.4" = "$PATCHES_REV" ]; then sed -i '/CONFIG_HID_SENSOR_GYRO_3D/c\CONFIG_HID_SENSOR_GYRO_3D=m' .config sed -i '/CONFIG_HID_SENSOR_IIO_COMMON/c\CONFIG_HID_SENSOR_IIO_COMMON=m\nCONFIG_HID_SENSOR_IIO_TRIGGER=m' .config fi + make ARCH=arm64 prepare modules_prepare LOCALVERSION='' -j$(($(nproc)-1)) #Remove previously applied patches git reset --hard echo -e "\e[32mApply Librealsense Kernel Patches\e[0m" -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 +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 fi -if [ "5.0.2" != "$PATCHES_REV" ]; then - patch -p1 < ./LRS_Patches/04-media-uvcvideo-mark-buffer-error-where-overflow.patch + +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.1-realsense/'g ./drivers/media/usb/uvc/uvcvideo.h fi -patch -p1 < ./LRS_Patches/05-realsense-powerlinefrequency-control-fix.patch echo -e "\e[32mCompiling uvcvideo kernel module\e[0m" #sudo -s make -j -C $KBASE M=$KBASE/drivers/media/usb/uvc/ modules @@ -165,19 +215,43 @@ if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older echo -e "\e[32mCompiling accelerometer and gyro modules\e[0m" make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules fi - -echo -e "\e[32mCopying the patched modules to (~/) \e[0m" -sudo cp drivers/media/usb/uvc/uvcvideo.ko ~/${TEGRA_TAG}-uvcvideo.ko -sudo cp drivers/media/v4l2-core/videobuf-vmalloc.ko ~/${TEGRA_TAG}-videobuf-vmalloc.ko -sudo cp drivers/media/v4l2-core/videobuf-core.ko ~/${TEGRA_TAG}-videobuf-core.ko +if [ "6.0" = "$PATCHES_REV" ]; then # for Jetpack 6.0 + echo -e "\e[32mCompiling hid support, accelerometer and gyro modules\e[0m" + make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/hid modules + make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules +fi +if [ "6.0" != "$PATCHES_REV" ]; then # for Jetpack 4-5 + echo -e "\e[32mCopying the patched modules to (~/) \e[0m" + sudo cp drivers/media/usb/uvc/uvcvideo.ko ~/${TEGRA_TAG}-uvcvideo.ko + sudo cp drivers/media/v4l2-core/videobuf-vmalloc.ko ~/${TEGRA_TAG}-videobuf-vmalloc.ko + sudo cp drivers/media/v4l2-core/videobuf-core.ko ~/${TEGRA_TAG}-videobuf-core.ko +else + echo -e "\e[32mCopying the patched modules to destination \e[0m" +fi if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older sudo cp drivers/iio/common/hid-sensors/hid-sensor-iio-common.ko ~/${TEGRA_TAG}-hid-sensor-iio-common.ko sudo cp drivers/iio/common/hid-sensors/hid-sensor-trigger.ko ~/${TEGRA_TAG}-hid-sensor-trigger.ko sudo cp drivers/iio/accel/hid-sensor-accel-3d.ko ~/${TEGRA_TAG}-hid-sensor-accel-3d.ko sudo cp drivers/iio/gyro/hid-sensor-gyro-3d.ko ~/${TEGRA_TAG}-hid-sensor-gyro-3d.ko fi -popd +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 echo -e "\e[32mMove the modified modules into the modules tree\e[0m" if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older #Optional - create kernel modules directories in kernel tree @@ -194,7 +268,29 @@ fi sudo depmod echo -e "\e[32mInsert the modified kernel modules\e[0m" -try_module_insert uvcvideo ~/${TEGRA_TAG}-uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/usb/uvc/uvcvideo.ko +if [ "6.0" != "$PATCHES_REV" ]; then + try_module_insert uvcvideo ~/${TEGRA_TAG}-uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/usb/uvc/uvcvideo.ko + try_load_module uvcvideo + 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 + try_unload_module hid_sensor_gyro_3d + try_unload_module hid_sensor_trigger + try_unload_module industrialio_triggered_buffer + try_unload_module kfifo_buf + echo -e "\e[32mLoad modified kernel modules\e[0m" + try_load_module kfifo_buf + try_load_module industrialio_triggered_buffer + try_load_module hid_sensor_trigger + try_load_module hid_sensor_gyro_3d + try_load_module hid_sensor_accel_3d + try_load_module uvcvideo + echo -e "\e[32mDone\e[0m" +fi if [ "4.4" = "$PATCHES_REV" ]; then # for Jetpack 4.4 and older try_module_insert hid_sensor_accel_3d ~/${TEGRA_TAG}-hid-sensor-accel-3d.ko /lib/modules/`uname -r`/kernel/drivers/iio/accel/hid-sensor-accel-3d.ko try_module_insert hid_sensor_gyro_3d ~/${TEGRA_TAG}-hid-sensor-gyro-3d.ko /lib/modules/`uname -r`/kernel/drivers/iio/gyro/hid-sensor-gyro-3d.ko