Skip to content

Commit

Permalink
l4t jp6 wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
dmipx committed Jun 16, 2024
1 parent cde5628 commit a843a8f
Showing 1 changed file with 69 additions and 13 deletions.
82 changes: 69 additions & 13 deletions scripts/patch-realsense-ubuntu-L4T.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ echo -e "\e[32mL4T ${JETSON_L4T_VERSION} to use patches revision ${PATCHES_REV}\

# 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
#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
Expand Down Expand Up @@ -143,7 +143,18 @@ fi
echo -e "\e[32mPrepare workspace for kernel build\e[0m"

if [ "6.0" = "$PATCHES_REV" ]; then
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && 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"
# 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))
else
make ARCH=arm64 mrproper -j$(($(nproc)-1)) && make ARCH=arm64 tegra_defconfig -j$(($(nproc)-1))
fi
Expand All @@ -158,8 +169,9 @@ 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 .
# 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 .
Expand All @@ -172,6 +184,7 @@ 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
Expand All @@ -193,6 +206,7 @@ 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
fi

echo -e "\e[32mCompiling uvcvideo kernel module\e[0m"
Expand All @@ -205,19 +219,40 @@ 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/
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/
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/
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
Expand All @@ -234,7 +269,28 @@ 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
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
Expand Down

0 comments on commit a843a8f

Please sign in to comment.