Skip to content

Commit 115afac

Browse files
Nir-Azremibettan
authored andcommitted
PR #14279 from Kontra2B: fixed version comparison issues
1 parent cddff74 commit 115afac

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

scripts/patch-realsense-ubuntu-L4T.sh

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ exec 2>&3
1414
function DisplayNvidiaLicense {
1515
revision=$1
1616

17-
# verify that curl is installed
18-
if ! which curl > /dev/null ; then
19-
echo "curl is not installed."
20-
echo "curl can be installed by 'sudo apt-get install curl'."
21-
exit 1
22-
fi
23-
2417
# By default referencing license agreement of JP 5.0.2
2518
license_path="https://developer.download.nvidia.com/embedded/L4T/${revision}/release/Tegra_Software_License_Agreement-Tegra-Linux.txt"
2619

@@ -34,6 +27,16 @@ function DisplayNvidiaLicense {
3427
read -t 30 -n 1 -s -r -e -p 'Press any key to continue (or wait 30 seconds..)'
3528
}
3629

30+
function version_lt {
31+
IFS='.' read -r -a v1 <<< "$1"
32+
IFS='.' read -r -a v2 <<< "$2"
33+
for i in 0 1 2; do
34+
[[ v1[i] -lt v2[i] ]] && return 0
35+
[[ v1[i] -gt v2[i] ]] && return 1
36+
done
37+
return 1
38+
}
39+
3740
if [[ $con_dev -ne 0 ]];
3841
then
3942
echo -e "\e[32m"
@@ -107,8 +110,8 @@ esac
107110
echo -e "\e[32mL4T ${JETSON_L4T_VERSION} to use patches revision ${PATCHES_REV}\e[0m"
108111

109112
# Get the required tools to build the patched modules
110-
sudo apt-get install build-essential git libssl-dev -y
111-
if [[ "$PATCHES_REV" < "6.0" ]]; then
113+
sudo apt-get install build-essential git libssl-dev curl -y
114+
if version_lt "$PATCHES_REV" "6.0"; then
112115
# Get the linux kernel repo, extract the L4T tag
113116
echo -e "\e[32mRetrieve the corresponding L4T git tag the kernel source tree\e[0m"
114117
l4t_gh_dir=../linux-${KERNEL_RELEASE}-source-tree
@@ -160,8 +163,7 @@ DisplayNvidiaLicense "r${JETSON_L4T_RELEASE}_Release_v${JETSON_L4T_REVISION_LONG
160163
# Download NVIDIA source
161164
./Tegra/$TEGRA_SOURCE_SYNC_SH -k ${TEGRA_TAG}
162165

163-
echo ${KBASE}
164-
pushd ${KBASE}
166+
pushd ${KBASE} > /dev/null
165167

166168
echo -e "\e[32mCopy LibRealSense patches to the sandbox\e[0m"
167169
L4T_Patches_Dir=${sdk_dir}/scripts/Tegra/LRS_Patches/
@@ -175,7 +177,9 @@ fi
175177
#Clean the kernel WS
176178
echo -e "\e[32mPrepare workspace for kernel build\e[0m"
177179

178-
if [[ "$PATCHES_REV" >= "6.0" ]]; then
180+
if version_lt "$PATCHES_REV" "6.0"; then
181+
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1))
182+
else
179183
make ARCH=arm64 mrproper -j$(($(nproc)-1))
180184
echo -e "\e[32mUpdate the kernel tree to support HID IMU sensors\e[0m"
181185
# appending config to defconfig so later .config will be generated with all necessary dependencies
@@ -185,8 +189,6 @@ if [[ "$PATCHES_REV" >= "6.0" ]]; then
185189
echo 'CONFIG_HID_SENSOR_IIO_COMMON=m' >> ./arch/arm64/configs/defconfig
186190
echo 'CONFIG_HID_SENSOR_IIO_TRIGGER=m' >> ./arch/arm64/configs/defconfig
187191
make ARCH=arm64 defconfig -j$(($(nproc)-1))
188-
else
189-
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1))
190192
fi
191193

192194
#Reuse existing module.symver
@@ -217,7 +219,7 @@ make ARCH=arm64 prepare modules_prepare LOCALVERSION='' -j$(($(nproc)-1))
217219
#Remove previously applied patches
218220
git reset --hard
219221
echo -e "\e[32mApply Librealsense Kernel Patches\e[0m"
220-
if [[ "$PATCHES_REV" < "6.0" ]]; then
222+
if version_lt "${PATCHES_REV}" "6.0"; then
221223
patch -p1 < ./LRS_Patches/01-realsense-camera-formats-L4T-${PATCHES_REV}.patch
222224
patch -p1 < ./LRS_Patches/02-realsense-metadata-L4T-${PATCHES_REV}.patch
223225
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
@@ -227,9 +229,7 @@ if [[ "$PATCHES_REV" < "6.0" ]]; then
227229
patch -p1 < ./LRS_Patches/04-media-uvcvideo-mark-buffer-error-where-overflow.patch
228230
fi
229231
patch -p1 < ./LRS_Patches/05-realsense-powerlinefrequency-control-fix.patch
230-
fi
231-
232-
if [[ "$PATCHES_REV" >= "6.0" ]]; then
232+
else
233233
patch -p1 < ${sdk_dir}/scripts/realsense-camera-formats-"${UBUNTU_CODENAME}"-master.patch
234234
patch -p1 < ${sdk_dir}/scripts/realsense-metadata-"${UBUNTU_CODENAME}"-master.patch
235235
[[ -f ${sdk_dir}/scripts/realsense-powerlinefrequency-control-fix-"${UBUNTU_CODENAME}".patch ]] \
@@ -247,18 +247,16 @@ if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
247247
echo -e "\e[32mCompiling accelerometer and gyro modules\e[0m"
248248
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules
249249
fi
250-
if [[ "$PATCHES_REV" >= "6.0" ]]; then # from Jetpack 6.0 onward
251-
echo -e "\e[32mCompiling hid support, accelerometer and gyro modules\e[0m"
252-
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/hid modules
253-
export KBUILD_MODPOST_WARN=1
254-
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules
255-
fi
256-
if [[ "$PATCHES_REV" < "6.0" ]]; then # for Jetpack 4-5
250+
if version_lt "$PATCHES_REV" "6.0"; then # for Jetpack 4-5
257251
echo -e "\e[32mCopying the patched modules to (~/) \e[0m"
258252
sudo cp drivers/media/usb/uvc/uvcvideo.ko ~/${TEGRA_TAG}-uvcvideo.ko
259253
sudo cp drivers/media/v4l2-core/videobuf-vmalloc.ko ~/${TEGRA_TAG}-videobuf-vmalloc.ko
260254
sudo cp drivers/media/v4l2-core/videobuf-core.ko ~/${TEGRA_TAG}-videobuf-core.ko
261255
else
256+
echo -e "\e[32mCompiling hid support, accelerometer and gyro modules\e[0m"
257+
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/hid modules
258+
export KBUILD_MODPOST_WARN=1
259+
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules
262260
echo -e "\e[32mCopying the patched modules to destination \e[0m"
263261
fi
264262
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
@@ -268,7 +266,7 @@ if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
268266
sudo cp drivers/iio/gyro/hid-sensor-gyro-3d.ko ~/${TEGRA_TAG}-hid-sensor-gyro-3d.ko
269267
fi
270268

271-
if [[ "$PATCHES_REV" >= "6.0" ]]; then # from Jetpack 6 onward
269+
if ! version_lt "$PATCHES_REV" "6.0"; then # from Jetpack 6 onward
272270
sudo mkdir -p /lib/modules/$(uname -r)/extra/
273271
# uvc modules with formats/sku support
274272
sudo cp drivers/media/usb/uvc/uvcvideo.ko /lib/modules/$(uname -r)/extra/
@@ -301,7 +299,7 @@ fi
301299
sudo depmod
302300

303301
echo -e "\e[32mInsert the modified kernel modules\e[0m"
304-
if [[ "$PATCHES_REV" < "6.0" ]]; then
302+
if version_lt "$PATCHES_REV" "6.0"; then
305303
try_module_insert uvcvideo ~/${TEGRA_TAG}-uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/usb/uvc/uvcvideo.ko
306304
try_load_module uvcvideo
307305
try_load_module hid-sensor-gyro-3d

0 commit comments

Comments
 (0)