Skip to content

Commit 547fe51

Browse files
committed
better readable conditions
1 parent 8d720d0 commit 547fe51

1 file changed

Lines changed: 21 additions & 22 deletions

File tree

scripts/patch-realsense-ubuntu-L4T.sh

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ case ${JETSON_L4T_VERSION} in
9191
# 36.4 -> 6.1
9292
# 36.4.3 --> 6.2
9393
# 36.4.4 --> 6.2.1
94-
# same patch set from 6.0 onward
9594
PATCHES_REV="6.0"
9695
KERNEL_RELEASE="5.15"
9796
;;
@@ -109,7 +108,7 @@ echo -e "\e[32mL4T ${JETSON_L4T_VERSION} to use patches revision ${PATCHES_REV}\
109108

110109
# Get the required tools to build the patched modules
111110
sudo apt-get install build-essential git libssl-dev -y
112-
if [[ "6.0" > "$PATCHES_REV" ]]; then
111+
if [[ "$PATCHES_REV" < "6.0" ]]; then
113112
# Get the linux kernel repo, extract the L4T tag
114113
echo -e "\e[32mRetrieve the corresponding L4T git tag the kernel source tree\e[0m"
115114
l4t_gh_dir=../linux-${KERNEL_RELEASE}-source-tree
@@ -139,16 +138,16 @@ sdk_dir=$(pwd)
139138
echo -e "\e[32mCreate the sandbox - NVIDIA L4T source tree(s)\e[0m"
140139
mkdir -p ${sdk_dir}/Tegra
141140
TEGRA_SOURCE_SYNC_SH="source_sync.sh"
142-
if [[ "5.0.2" = "$PATCHES_REV" ]]; then
141+
if [[ "$PATCHES_REV" = "5.0.2" ]]; then
143142
KBASE=./Tegra/sources/kernel/kernel-$KERNEL_RELEASE
144143
TEGRA_SOURCE_SYNC_SH="source_sync_5.0.2.sh"
145144
fi
146-
if [[ "6.0" = "$PATCHES_REV" ]]; then
145+
if [[ "$PATCHES_REV" = "6.0" ]]; then
147146
KBASE=./Tegra/kernel/kernel-jammy-src
148147
TEGRA_SOURCE_SYNC_SH="source_sync_6.0.sh"
149148
TEGRA_TAG="jetson_$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
150149
fi
151-
if [[ "7.0" = "$PATCHES_REV" ]]; then
150+
if [[ "$PATCHES_REV" = "7.0" ]]; then
152151
KBASE=./Tegra/kernel/kernel-noble-src
153152
TEGRA_SOURCE_SYNC_SH="source_sync_7.0.sh"
154153
TEGRA_TAG="jetson_$JETSON_L4T_RELEASE.$JETSON_L4T_REVISION"
@@ -176,7 +175,7 @@ fi
176175
#Clean the kernel WS
177176
echo -e "\e[32mPrepare workspace for kernel build\e[0m"
178177

179-
if [[ ! "6.0" > "$PATCHES_REV" ]]; then
178+
if [[ "$PATCHES_REV" >= "6.0" ]]; then
180179
make ARCH=arm64 mrproper -j$(($(nproc)-1))
181180
echo -e "\e[32mUpdate the kernel tree to support HID IMU sensors\e[0m"
182181
# appending config to defconfig so later .config will be generated with all necessary dependencies
@@ -193,20 +192,20 @@ fi
193192
#Reuse existing module.symver
194193
kernel_ver=`uname -r`
195194
LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu18.04_aarch64"
196-
if [[ "5.0.2" = "$PATCHES_REV" ]]; then
195+
if [[ "$PATCHES_REV" = "5.0.2" ]]; then
197196
LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu20.04_aarch64"
198197
fi
199-
if [[ "6.0" = "$PATCHES_REV" ]]; then
198+
if [[ "$PATCHES_REV" = "6.0" ]]; then
200199
LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu22.04_aarch64"
201200
fi
202-
if [[ "7.0" = "$PATCHES_REV" ]]; then
201+
if [[ "$PATCHES_REV" = "7.0" ]]; then
203202
LINUX_HEADERS_NAME="linux-headers-${kernel_ver}-ubuntu24.04_aarch64"
204203
fi
205204

206205
export KBUILD_EXTRA_SYMBOLS="/lib/modules/${kernel_ver}/build/Module.symvers"
207206

208207
#Jetpack prior to 4.4.1 requires manual reconfiguration of kernel
209-
if [[ "4.4" = "$PATCHES_REV" ]]; then
208+
if [[ "$PATCHES_REV" = "4.4" ]]; then
210209
echo -e "\e[32mUpdate the kernel tree to support HID IMU sensors\e[0m"
211210
sed -i '/CONFIG_HID_SENSOR_ACCEL_3D/c\CONFIG_HID_SENSOR_ACCEL_3D=m' .config
212211
sed -i '/CONFIG_HID_SENSOR_GYRO_3D/c\CONFIG_HID_SENSOR_GYRO_3D=m' .config
@@ -218,19 +217,19 @@ make ARCH=arm64 prepare modules_prepare LOCALVERSION='' -j$(($(nproc)-1))
218217
#Remove previously applied patches
219218
git reset --hard
220219
echo -e "\e[32mApply Librealsense Kernel Patches\e[0m"
221-
if [[ "6.0" > "$PATCHES_REV" ]]; then
220+
if [[ "$PATCHES_REV" < "6.0" ]]; then
222221
patch -p1 < ./LRS_Patches/01-realsense-camera-formats-L4T-${PATCHES_REV}.patch
223222
patch -p1 < ./LRS_Patches/02-realsense-metadata-L4T-${PATCHES_REV}.patch
224-
if [[ "4.4" = "$PATCHES_REV" ]]; then # for Jetpack 4.4 and older
223+
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
225224
patch -p1 < ./LRS_Patches/03-realsense-hid-L4T-4.9.patch
226225
fi
227-
if [[ "5.0.2" != "$PATCHES_REV" ]]; then
226+
if [[ "$PATCHES_REV" != "5.0.2" ]]; then
228227
patch -p1 < ./LRS_Patches/04-media-uvcvideo-mark-buffer-error-where-overflow.patch
229228
fi
230229
patch -p1 < ./LRS_Patches/05-realsense-powerlinefrequency-control-fix.patch
231230
fi
232231

233-
if [[ ! "6.0" > "$PATCHES_REV" ]]; then
232+
if [[ "$PATCHES_REV" >= "6.0" ]]; then
234233
patch -p1 < ${sdk_dir}/scripts/realsense-camera-formats-"${UBUNTU_CODENAME}"-master.patch
235234
patch -p1 < ${sdk_dir}/scripts/realsense-metadata-"${UBUNTU_CODENAME}"-master.patch
236235
[[ -f ${sdk_dir}/scripts/realsense-powerlinefrequency-control-fix-"${UBUNTU_CODENAME}".patch ]] \
@@ -244,32 +243,32 @@ make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/media/usb/uvc/ modules
244243
echo -e "\e[32mCompiling v4l2-core modules\e[0m"
245244
#sudo -s make -j -C $KBASE M=$KBASE/drivers/media/v4l2-core modules
246245
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/media/v4l2-core modules
247-
if [[ "4.4" = "$PATCHES_REV" ]]; then # for Jetpack 4.4 and older
246+
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
248247
echo -e "\e[32mCompiling accelerometer and gyro modules\e[0m"
249248
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules
250249
fi
251-
if [[ ! "6.0" > "$PATCHES_REV" ]]; then # from Jetpack 6.0 onward
250+
if [[ "$PATCHES_REV" >= "6.0" ]]; then # from Jetpack 6.0 onward
252251
echo -e "\e[32mCompiling hid support, accelerometer and gyro modules\e[0m"
253252
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/hid modules
254253
export KBUILD_MODPOST_WARN=1
255254
make -j$(($(nproc)-1)) ARCH=arm64 M=drivers/iio modules
256255
fi
257-
if [[ "6.0" > "$PATCHES_REV" ]]; then # for Jetpack 4-5
256+
if [[ "$PATCHES_REV" < "6.0" ]]; then # for Jetpack 4-5
258257
echo -e "\e[32mCopying the patched modules to (~/) \e[0m"
259258
sudo cp drivers/media/usb/uvc/uvcvideo.ko ~/${TEGRA_TAG}-uvcvideo.ko
260259
sudo cp drivers/media/v4l2-core/videobuf-vmalloc.ko ~/${TEGRA_TAG}-videobuf-vmalloc.ko
261260
sudo cp drivers/media/v4l2-core/videobuf-core.ko ~/${TEGRA_TAG}-videobuf-core.ko
262261
else
263262
echo -e "\e[32mCopying the patched modules to destination \e[0m"
264263
fi
265-
if [[ "4.4" = "$PATCHES_REV" ]]; then # for Jetpack 4.4 and older
264+
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
266265
sudo cp drivers/iio/common/hid-sensors/hid-sensor-iio-common.ko ~/${TEGRA_TAG}-hid-sensor-iio-common.ko
267266
sudo cp drivers/iio/common/hid-sensors/hid-sensor-trigger.ko ~/${TEGRA_TAG}-hid-sensor-trigger.ko
268267
sudo cp drivers/iio/accel/hid-sensor-accel-3d.ko ~/${TEGRA_TAG}-hid-sensor-accel-3d.ko
269268
sudo cp drivers/iio/gyro/hid-sensor-gyro-3d.ko ~/${TEGRA_TAG}-hid-sensor-gyro-3d.ko
270269
fi
271270

272-
if [[ ! "6.0" > "$PATCHES_REV" ]]; then # from Jetpack 6 onward
271+
if [[ "$PATCHES_REV" >= "6.0" ]]; then # from Jetpack 6 onward
273272
sudo mkdir -p /lib/modules/$(uname -r)/extra/
274273
# uvc modules with formats/sku support
275274
sudo cp drivers/media/usb/uvc/uvcvideo.ko /lib/modules/$(uname -r)/extra/
@@ -287,7 +286,7 @@ if [[ ! "6.0" > "$PATCHES_REV" ]]; then # from Jetpack 6 onward
287286
fi
288287
popd
289288
echo -e "\e[32mMove the modified modules into the modules tree\e[0m"
290-
if [[ "4.4" = "$PATCHES_REV" ]]; then # for Jetpack 4.4 and older
289+
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
291290
#Optional - create kernel modules directories in kernel tree
292291
sudo mkdir -p /lib/modules/`uname -r`/kernel/drivers/iio/accel
293292
sudo mkdir -p /lib/modules/`uname -r`/kernel/drivers/iio/gyro
@@ -302,7 +301,7 @@ fi
302301
sudo depmod
303302

304303
echo -e "\e[32mInsert the modified kernel modules\e[0m"
305-
if [[ "6.0" > "$PATCHES_REV" ]]; then
304+
if [[ "$PATCHES_REV" < "6.0" ]]; then
306305
try_module_insert uvcvideo ~/${TEGRA_TAG}-uvcvideo.ko /lib/modules/`uname -r`/kernel/drivers/media/usb/uvc/uvcvideo.ko
307306
try_load_module uvcvideo
308307
try_load_module hid-sensor-gyro-3d
@@ -325,7 +324,7 @@ else
325324
try_load_module uvcvideo
326325
echo -e "\e[32mDone\e[0m"
327326
fi
328-
if [[ "4.4" = "$PATCHES_REV" ]]; then # for Jetpack 4.4 and older
327+
if [[ "$PATCHES_REV" = "4.4" ]]; then # for Jetpack 4.4 and older
329328
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
330329
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
331330
#Preventively unload all HID-related modules

0 commit comments

Comments
 (0)