NVIDIA Jetson Orin/Video Capture and Display/Cameras/IMX477 J20: Difference between revisions

From RidgeRun Developer Wiki
mNo edit summary
 
(43 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<noinclude>
<noinclude>
{{NVIDIA Jetson Orin/Head|previous=Video Capture and Display/Cameras/IMX219|next=Video Capture and Display/Software Support|keywords=jetpack,flashing,image,flash,flashing board}}
{{NVIDIA Jetson Orin/Head|previous=Video Capture and Display|next=GStreamer Pipelines|metakeywords=imx477, j20, mipi camera, Auvidea, Auvidea J20 board, Raspberry Pi HQ camera, IMX477 Linux driver for NVIDIA, IMX477 Linux driver}}
</noinclude>
</noinclude>


__TOC__
{{DISPLAYTITLE:NVIDIA Jetson Orin - IMX477 Auvidea J20 board Camera Sensor Driver Support|noerror}}
 


<table>
<table>
Line 82: Line 81:
=== Auvidea J20 adapter ===
=== Auvidea J20 adapter ===


The NVIDIA<sup>®</sup>Jetson Orin™ makes usage of a Samtec connector, this driver makes usage of the J20 from Auvidea: More information recopilated from RidgeRun can be found [[Getting_started_guide_for_Auvidea_J20_board|here]]
The NVIDIA<sup>®</sup>Jetson Orin™ makes use of a Samtec connector, this driver makes use of the J20 from Auvidea
More information recopilated from RidgeRun can be found [[Getting_started_guide_for_Auvidea_J20_board|here]].
 
The driver will work with IMX477 connected to the J1_1, J1_2, and J1_3 ports of the J20.


==IMX477 Linux driver for NVIDIA<sup>®</sup>Jetson Orin™==
==IMX477 Linux driver for NVIDIA<sup>®</sup>Jetson Orin™==


RidgeRun Engineering has developed the driver with NVIDIA Corporation and Leopard Imaging Inc. as a collaborative initiative.
RidgeRun Engineering has developed the driver with NVIDIA Corporation and Leopard Imaging Inc. and Auvidea. as a collaborative initiative. The driver works with three cameras on the J1 ports from the J20.  
In this section, you will find the instructions to patch the JetPack sources enabling the IMX477 sensor driver for the Jetson Orin. These  instructions have been validated in the following JetPack versions:
In this section, you will find the instructions to patch the JetPack sources enabling the IMX477 sensor driver for the Jetson Orin. These  instructions have been validated in the following JetPack versions:
* Jetpack 5.0.1
* Jetpack 5.0.2


===Download JetPack===
===Download JetPack===


The current version of the driver is supported in Jetpack 5.0.1. Porting the driver to other versions and platforms is possible.
The current version of the driver is supported in Jetpack 5.0.2. Porting the driver to other versions and platforms is possible.


1. Download and install the [https://developer.nvidia.com/nvidia-sdk-manager NVIDIA SDK Manager] (membership is required).
1. Download and install the [https://developer.nvidia.com/nvidia-sdk-manager NVIDIA SDK Manager] (membership is required).
Line 98: Line 100:
2. Log in with your NVIDIA membership credentials in the SDK Manager.
2. Log in with your NVIDIA membership credentials in the SDK Manager.


3. Select JetPack version 5.0.1 DP and Jetson Orin as shown below and press ''Continue'':
3. Select JetPack version 5.0.2 DP and Jetson Orin as shown below and press ''Continue'':
[[Image:imx477_sdkmanager1.png|thumb|center|650px]]  
[[Image:Sdk1.png|thumb|center|650px]]  
<div style="text-align: center;">'''Figure 1'''. Required SDK Manager options.</div>
<div style="text-align: center;">'''Figure 1'''. Required SDK Manager options.</div>


Line 118: Line 120:
}}
}}


# Make sure the device is connected to the power adapter, but powered off.
# Make sure the device is connected to the power adapter but powered off.
# Connect the host computer to the front USB Type-C connector on the device.
# Connect the host computer to the front USB Type-C connector on the device.
# Power the device
# Press and hold the middle (Force Recovery) button.
# Press and hold the middle (Force Recovery) button.
# Press and hold the left (Power) button.
# Press and hold the left (Power) button.
Line 126: Line 129:
6. When the OS has been installed successfully in the Jetson Orin AGX, you have multiple options to use the board:
6. When the OS has been installed successfully in the Jetson Orin AGX, you have multiple options to use the board:


# Use the username and password previously selected to connect over SSH to the corresponded IP (normally 192.168.55.1 over the USB connection).  
# Use the username and password previously selected to connect over SSH to the corresponding IP (normally 192.168.55.1 over the USB connection).  
# Connect over the UART connection opened by attaching the micro-USB, for example minicom: <code>sudo minicom -D /dev/ttyUSB0 -b 115200</code> and use the same username and password
# Connect over the UART connection opened by attaching the micro-USB, for example, minicom: <code>sudo minicom -D /dev/ttyUSB0 -b 115200</code> and use the same username and password
# Connect over display.
# Connect over display.


Line 135: Line 138:
|small=left
|small=left
|issue='''IMPORTANT:'''
|issue='''IMPORTANT:'''
*From now on we will refer as <code>$JETPACK_DIR/</code> to the directory where the SDK Manager placed the <code>JetPack_5.0.1_DP_Linux_JETSON_AGX_ORIN_TARGETS/Linux_for_Tegra/.<br>
*From now on we will refer as <code>$JETPACK_DIR</code> to the directory where the SDK Manager placed the <code>JetPack_5.0.2_DP_Linux_JETSON_AGX_ORIN_TARGETS<br>
       This directory is usually in <code>$HOME/nvidia/nvidia_sdk.<code>
       This directory is usually in <code>$HOME/nvidia/nvidia_sdk<code>
|style=width:unset;
|style=width:unset;
}}
}}
Line 145: Line 148:
===Download the JetPack sources===
===Download the JetPack sources===


You can obtain the JetPack 5.0.1 DP sources by doing the following:
You can obtain the JetPack 5.0.2 DP sources by doing the following:


<syntaxhighlight lang=bash>
1. Go to https://developer.nvidia.com/embedded/jetson-linux-archive and download the source files for your release.
cd $JETPACK_DIR/Linux_for_Tegra/
./source_sync.sh -t jetson_34.1.1
JETSON_KERNEL_SOURCE=$JETPACK_DIR/Linux_for_Tegra/sources
</syntaxhighlight>


=== Fix kernel before patching ===
2. Extract the .tbz2 file:
 
<pre>
The raw kernel has some considerations before patching:
tar -xjf public_sources.tbz2
 
</pre>
Move the t23x hardware common to common/kernel-dts
3. Extract the kernel source file:
<syntaxhighlight lang=bash>
<pre>
cd $JETSON_KERNEL_SOURCE/hardware/nvidia/platform/t23x/
cd Linux_for_Tegra/source/public
mv common common_tmp/
JETSON_SOURCES=$PWD
mkdir -p common
tar –xjf kernel_src.tbz2
mv common_tmp common/kernel-dts
</pre>
</syntaxhighlight>
This extracts the kernel source to the kernel/ subdirectory.
 
Also you need to create a symbolic link:
<syntaxhighlight lang=bash>
cd $JETSON_KERNEL_SOURCE
ln -s $(pwd)/kernel/nvethernetrm $(pwd)/kernel/nvidia/drivers/net/ethernet/nvidia/nvethernet/nvethernetrm
 
# OR
ln -s ../../../../../../nvethernetrm $(pwd)/kernel/nvidia/drivers/net/ethernet/nvidia/nvethernet/nvethernetrm
</syntaxhighlight>


===Patch instructions===
===Patch instructions===
Line 178: Line 168:
====Download the patches====
====Download the patches====


RidgeRun has created a [https://github.com/RidgeRun/NVIDIA-Jetson-IMX477-RPIV3.git repository] from where you can download the patch files.
RidgeRun has created a [https://github.com/RidgeRun/NVIDIA-Jetson-IMX477-RPIV3/tree/jetpack-5.0.2 repository] from where you can download the patch files.


You need to clone it and use the branch for the jetpack.
<pre>
<pre>
git clone https://github.com/RidgeRun/NVIDIA-Jetson-IMX477-RPIV3.git
cd $HOME
git clone https://github.com/RidgeRun/NVIDIA-Jetson-IMX477-RPIV3.git -b jetpack-5.0.2
</pre>
</pre>


Once you have downloaded the repository, move the files to the <code>$JETSON_KERNEL_SOURCE</code> directory (create the patches directory inside JETSON_KERNEL_SOURCE if necessary):
Once you have downloaded the repository, copy the files to the <code>$JETSON_SOURCES</code> directory:


<pre>
<pre>
KERNEL_PATCH=$(pwd)/NVIDIA-Jetson-IMX477-RPIV3/
KERNEL_PATCH=$(pwd)/NVIDIA-Jetson-IMX477-RPIV3/
mv -v $KERNEL_PATCH/patches_orin/* $JETSON_KERNEL_SOURCE/patches/
cp $KERNEL_PATCH/patches_orin/5.0.2_agx_imx477_v0.1.patch $JETSON_SOURCES/
</pre>
</pre>


====Apply the patches====
====Apply the patches====
<pre>
<pre>
cd $JETSON_KERNEL_SOURCE/patches
cd $JETSON_SOURCES
quilt push -a
git apply 5.0.2_agx_imx477_v0.1.patch
</pre>
</pre>


Line 202: Line 194:


====Install the Toolchain====
====Install the Toolchain====
First, download the [https://developer.nvidia.com/embedded/jetson-linux Bootlin toolchain binaries] from the NVIDIA Jetson Linux home page. Go to the bottom of the page and click on the Bootlin Toolchain gcc option as shown in the image below:
<br>
[[File:Toolchain.png|thumb|center|650px]]


After that do:
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
mkdir -p /opt/l4t-gcc
mkdir $HOME/l4t-gcc
cd /opt/l4t-gcc/
cd $HOME/l4t-gcc
wget https://toolchains.bootlin.com/downloads/releases/toolchains/aarch64/tarballs/aarch64--glibc--stable-2020.08-1.tar.bz2
tar xf <path_to_toolchain_archive>
tar -xvf aarch64--glibc--stable-2020.08-1.tar.bz2 -C .
</syntaxhighlight>
</syntaxhighlight>


====Build the kernel====
====Build the kernel====


* Establish the building paths anc reate directories:
* Establish the building paths and create directories:
<pre>
<pre>
TOOLCHAIN_PREFIX=/opt/l4t-gcc/aarch64--glibc--stable-2020.08-1/bin/aarch64-buildroot-linux-gnu-
KERNEL_OUT=$JETSON_SOURCES/kernel_out
TEGRA_KERNEL_OUT=$JETSON_KERNEL_SOURCE/../building/kernel_build
MODULES_OUT=$JETSON_SOURCES/modules_out
KERNEL_MODULES_OUT=$JETSON_KERNEL_SOURCE/../building/kernel_modules
mkdir -p $KERNEL_OUT
mkdir -p $TEGRA_KERNEL_OUT
mkdir -p $MODULES_OUT
mkdir -p $KERNEL_MODULES_OUT
</pre>
</pre>


Line 226: Line 220:
</pre>
</pre>


* Configure and build kernel:
* Export environment variables:
<pre>
<pre>
cd $JETSON_KERNEL_SOURCE
export CROSS_COMPILE_AARCH64_PATH=$HOME/l4t-gcc
make -C kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} tegra_defconfig
export CROSS_COMPILE_AARCH64=$HOME/l4t-gcc/bin/aarch64-buildroot-linux-gnu-
</pre>
</pre>


* Compile kernel, device tree, and modules:
* Compile kernel:
<pre>
cd $JETSON_SOURCES
./nvbuild.sh -o $KERNEL_OUT
</pre>


*Install the modules
<pre>
<pre>
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) Image
make -C $JETSON_SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$MODULES_OUT modules_install
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) dtbs
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra CROSS_COMPILE=${TOOLCHAIN_PREFIX} -j$(nproc) modules
make -C $SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$TEGRA_KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$KERNEL_MODULES_OUT modules_install
</pre>
</pre>


Line 250: Line 246:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
# Copy the new compiled kernel
# Copy the new compiled kernel.
sudo cp -rfv $TEGRA_KERNEL_OUT/arch/arm64/boot/Image $JETPACK_DIR/Linux_for_Tegra/kernel/
cp -r $KERNEL_OUT/arch/arm64/boot/Image $JETPACK_DIR/Linux_for_Tegra/kernel/


# Copy all new compiled DTBs and DTB overlays.  
# Copy all new compiled DTBs and DTB overlays.  
sudo cp -rfv $TEGRA_KERNEL_OUT/arch/arm64/boot/dts/nvidia/* $JETPACK_DIR/Linux_for_Tegra/kernel/dtb/
cp -r $KERNEL_OUT/arch/arm64/boot/dts/nvidia/* $JETPACK_DIR/Linux_for_Tegra/kernel/dtb/


# Update rootfs with compiled modules, which include the driver
# Update rootfs with compiled modules, which include the driver.
sudo rsync -azPu $KERNEL_MODULES_OUT/lib/modules/5.10.65-tegra $JETPACK_DIR/Linux_for_Tegra/rootfs/lib/modules/
rsync -azPu $MODULES_OUT/lib/modules/5.10.104-tegra $JETPACK_DIR/Linux_for_Tegra/rootfs/lib/modules/


# Update the rootfs with all the binaries (to make sure the /boot/ folder is updated too)
# Update the rootfs with all the binaries (to make sure the /boot/ folder is updated too).
cd $JETPACK_DIR/Linux_for_Tegra
cd $JETPACK_DIR/Linux_for_Tegra
sudo ./apply_binaries.sh
sudo ./apply_binaries.sh
# Copy the module to the correct location.
sudo cp $KERNEL_OUT/drivers/media/i2c/nv_imx477.ko $JETPACK_DIR/Linux_for_Tegra/rootfs/lib/modules/5.10.104-tegra/kernel/drivers/media/i2c/
</syntaxhighlight>
</syntaxhighlight>


Line 271: Line 270:
</syntaxhighlight>
</syntaxhighlight>


=== Manual installation ===
==== Manual installation ====


Update the kernel and DTB files used by /boot/extlinux/extlinux.conf when there is an already running board.  
Update the kernel and DTB files used by /boot/extlinux/extlinux.conf when there is an already running board.  
This assumes that the Jetson can be reach by SSH using:


==== Updating the kernel ====
<pre>
ssh jetson
</pre>
 
'''Updating the kernel'''


Updating the kernel is as simple as copying into the board:
Updating the kernel is as simple as copying into the board:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
# Update Image on Linux_for_Tegra folder just to make sure
# Update Image on Linux_for_Tegra folder just to sync the flash folders
sudo cp -rfv ./building/kernel_build/arch/arm64/boot/Image Linux_for_Tegra/kernel/
sudo cp -rfv $KERNEL_OUT/arch/arm64/boot/Image $JETPACK_DIR/Linux_for_Tegra/kernel/


# Copy the Image to the tmp folder on the board
# Copy the Image to the tmp folder on the board
scp Linux_for_Tegra/kernel/Image jetson:/tmp/
scp $JETPACK_DIR/Linux_for_Tegra/kernel/Image jetson:/tmp/


# Copy the Image to the boot directory on the board
# Copy the Image to the boot directory on the board
sudo mv /tmp/Image /boot/Image
sudo mv /tmp/Image /boot/Image
</syntaxhighlight>
</syntaxhighlight>
'''Updating the DTB'''


==== Updating the DTB ====
The new JetPack uses the FDT property of the /boot/extlinux/extlinux.conf file, and it sets it to a device tree located in /boot/dtb/ with a prefix of kernel_tegra. We can update this DTB with the following:
The new JetPack uses the FDT property and it sets it to a device tree located in /boot/dtb/ with a prefix of kernel_tegra. We can generate this DTB with the flash script, but probably you can just paste whichever DTB you want as usual.
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
# Update on Linux_for_Tegra folder with the new DTBs and overlays
# Update on Linux_for_Tegra folder with the new DTBs and overlays
sudo cp -rfv ./building/kernel_build/arch/arm64/boot/dts/nvidia/* Linux_for_Tegra/kernel/dtb/
sudo cp -rfv $KERNEL_OUT/arch/arm64/boot/dts/nvidia/* $JETPACK_DIR/Linux_for_Tegra/kernel/dtb/


# Generate required prefixed DTB using flash script with no flash option
# Generate required prefixed DTB using flash script with no flash option
cd  $JETPACK_DIR/Linux_for_Tegra
sudo ./flash.sh -r --no-flash jetson-agx-orin-devkit mmcblk0p1
sudo ./flash.sh -r --no-flash jetson-agx-orin-devkit mmcblk0p1


# Copy the device tree to the board
# Copy the device tree to the board
scp Linux_for_Tegra/bootloader/kernel_tegra234-p3701-0000-p3737-0000.dtb jetson:/tmp/
scp $JETPACK_DIR/Linux_for_Tegra/bootloader/kernel_tegra234-p3701-0000-p3737-0000.dtb jetson:/tmp/


# Update the device tree on the board
# Update the device tree on the board
Line 308: Line 313:
==== Updating modules ====
==== Updating modules ====


Inside the board run the following to update the modules:
Inside the board run the following to update the modules folder, copying them from the host:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 314: Line 319:
HOST_IP=192.168.55.100
HOST_IP=192.168.55.100
cd /lib/modules/
cd /lib/modules/
sudo rsync -azPu $HOST_NAME@$HOST_IP:/path_to_builddir/building/kernel_modules/lib/modules/5.10.65-tegra .
sudo rsync -azPu $HOST_NAME@$HOST_IP:$MODULES_OUT/lib/modules/5.10.104-tegra .
</syntaxhighlight>
</syntaxhighlight>
===Copy the kernel modules===
* You can just access your SD card in your PC and copy the '''KERNEL_MODULES=$JETPACK_DIR/JetPack_[JETPACK_VERSION]_Linux_JETSON_[PLATFORM]_DEVKIT/Linux_for_Tegra/modules/lib/modules/4.9.201/*''' directory content into '''/lib/modules/4.9.201/''' in your SD card to update the modules. Where <code>[PLATFORM]</code> must be replaced by <code>XAVIER_NX</code> or <code>NANO</code>, and <code>[JETPACK_VERSION]</code> must be replaced by <code>4.4</code>, <code>4.4.1</code> or <code>4.5</code>.
* Or you can update with your compiled modules  If your board is up you can update the kernel modules as follows:
<pre>
KERNEL_MODULES=$JETPACK_DIR/JetPack_[JETPACK_VERSION]_Linux_JETSON_[PLATFORM]_DEVKIT/Linux_for_Tegra/modules/lib/modules/4.9.140
cd $KERNEL_MODULES
# use rsync instead of scp to avoid symlink recursion problems
rsync --progress -avhe ssh ../4.9.201 <nvidia-nx-user>@<nvidia-nx-ip>:/tmp/
</pre>
Where <code>[PLATFORM]</code> must be replaced by <code>XAVIER_NX</code> or <code>NANO</code>, and <code>[JETPACK_VERSION]</code> must be replaced by <code>4.4</code>, <code>4.4.1</code> or <code>4.5</code>.
* Move the modules from <code>/tmp</code> to the <code>/lib/modules/</code> folder inside the Jetson's filesystem and reboot:
<pre>
sudo mv /tmp/4.9.201/ /lib/modules/
sudo reboot
</pre>
* If you find that the directory name is '''/lib/modules/4.9.201-tegra/''', change the directory name to '''/lib/modules/4.9.201/'''
* After these steps, the driver should be working and you can run some capture tests described below.
* '''IMPORTANT''': You may see some washed-out colors in the captured image. This is because you haven't applied the ISP configuration file. Make sure to install the ISP file that you can find in the repo using [https://developer.ridgerun.com/wiki/index.php?title=Raspberry_Pi_HQ_camera_IMX477_Linux_driver_for_Jetson#ISP_camera_overrides_installation these instructions].


==ISP camera overrides installation==
==ISP camera overrides installation==


Please, visit the [https://developer.ridgerun.com/wiki/index.php?title=JetsonTX2/HowTo%27s/NVIDIA_Jetson_ISP_Control#Custom_ISP_Configuration Custom ISP Configuration page] in order to learn how to use the <code>camera_overrides.isp</code> file to configure the ISP.
Please, visit the [[JetsonTX2/HowTo%27s/NVIDIA_Jetson_ISP_Control#Custom_ISP_Configuration | Custom ISP Configuration page]] in order to learn how to use the <code>camera_overrides.isp</code> file to configure the ISP.


'''NOTE:''' This is causing some timeout issues currently.
{{Ambox
|type=notice
|small=left
|issue='''NOTE:''' This is causing some timeout issues currently.
|style=width:unset;
}}


==Supported Features==
==Supported Features==
Line 355: Line 338:


* 1920x1080 @ 60fps
* 1920x1080 @ 60fps
* 4032x3040 @ 30fps
* 3840x2160 @ 30fps


===Controls===
===Controls===
Line 372: Line 355:
====1920x1080====
====1920x1080====
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvvidconv ! nvoverlaysink
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvvidconv ! nvoverlaysink
</syntaxhighlight>
</syntaxhighlight>


====4032x3040====
====3840x2160====


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvvidconv ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvoverlaysink
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvvidconv ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvoverlaysink
</syntaxhighlight>
</syntaxhighlight>


Line 389: Line 372:
====1920x1080====
====1920x1080====
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4
</syntaxhighlight>
</syntaxhighlight>


====4032x3040====
====3840x2160====


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4
</syntaxhighlight>
</syntaxhighlight>


Line 406: Line 389:
====1920x1080====
====1920x1080====
<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
NUMBER_OF_SNAPSHOTS=20
NUMBER_OF_SNAPSHOTS=20
Line 412: Line 395:
</syntaxhighlight>
</syntaxhighlight>


====4032x3040====
====3840x2160====


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
SENSOR_ID=0 # 0 for CAM0 and 1 for CAM1 ports
SENSOR_ID=0 # 0 to 2 depending on cam port.
FRAMERATE=30 # Framerate can go from 2 to 30 for 4032x3040 mode
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
NUMBER_OF_SNAPSHOTS=20
NUMBER_OF_SNAPSHOTS=20
gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=4032,height=3040,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg
gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg
</syntaxhighlight>
</syntaxhighlight>


Line 428: Line 411:


<noinclude>
<noinclude>
{{NVIDIA Jetson Orin/Foot|Video Capture and Display/Cameras/IMX219|Video Capture and Display/Software Support}}
{{NVIDIA Jetson Orin/Foot|Video Capture and Display|GStreamer Pipelines}}
</noinclude>
</noinclude>

Latest revision as of 09:47, 11 February 2023


Previous: Video Capture and Display Index Next: GStreamer Pipelines






Problems running the pipelines shown on this page? Please see our GStreamer Debugging guide for help.

Introduction to Sony IMX477 Linux driver

RidgeRun is actively working to enable customers with great software solutions on top of powerful hardware. For this reason, RidgeRun has worked on enabling a triple capture for the V4L2 driver for the Raspberry Pi HQ camera using an Auvidea J20 board. This wiki contains a brief introduction to the sensor and hardware that will be used to use the driver. Also please keep in mind that the driver can be ported to other Jetson platforms if needed. Please contact us if you require more information.

Raspberry Pi HQ camera


Camera Features

  • 12.3-Megapixel high-resolution Sony IMX477 sensor.
  • 1.55μm × 1.55μm Pixel Size – double the pixel area of IMX219 for improved low-light performance.
  • Back-illuminated sensor architecture for improved sensitivity.
  • Support for different C- and CS-mount lenses.
  • Integrated back-focus adjustment ring and tripod mount.

Sony IMX477 Basic Drive Mode

The Raspberry Pi HQ camera uses the IMX477 CMOS sensor of Sony to capture. Such a sensor provides the modes included in the table below. At this point, RidgeRun is working to support one mode only but others can be added per request.

Drive Mode Number of active pixels Maximum frame rate
[frame/s]
Output Interface ADC
[bit]
Full (4:3) (Normal) 4056 x 3040
approx. 12.33 M pixels
60 CSI-2 10
40 CSI-2 12
Full (4:3) (DOL-HDR) 4056 x 3040
approx. 12.33 M pixels
DOL 2 frame:30
DOL 3 frame:15
CSI-2 10
Full (16:9) 4K2K (Normal) 4056 x 2288
approx. 9.28 M pixels
79 CSI-2 10
Full (16:9) 4K2K (DOL-HDR) 4056 x 2288
approx. 9.28 M pixels
DOL 2 frame:39
DOL 3 frame:19
CSI-2 10
Full (4:3) Binning (Normal) 2028 x 1520
approx. 3.08 M pixels
179 CSI-2 10
Full (16:9) Binning 1080P (Normal) 2028 x 1128
approx. 2.29 M pixels
240 CSI-2 10
Full (16:9) Binning 720P (Normal) 1348 x 750
approx. 1.01 M pixels
240 CSI-2 10
Full (16:9) Scaling 1080P (Normal) 2024 x 1142
approx. 2.31 M pixels
79 CSI-2 10
Full (16:9) Scalling 720P (Normal) 1348 x 762
approx. 1.03 M pixels
79 CSI-2 10

Compatibility with NVIDIA®Jetson™ Platforms

R8 resistor

The Raspberry Pi HQ camera module requires a hardware modification in order to work with Jetson Platforms. Jetson Platforms provide 1.8V for reset GPIO in the camera interface, but the camera module requires 3.3V.

To fix this issue a resistor labeled as R8 must be removed from the camera module. If you decide to apply this fix it is under your own risk. RidgeRun is not responsible for any damage caused to your board. The following picture shows the location of the R8 in the module.

Figure 1. R8 resistor on RPi HQ camera module.

Auvidea J20 adapter

The NVIDIA®Jetson Orin™ makes use of a Samtec connector, this driver makes use of the J20 from Auvidea More information recopilated from RidgeRun can be found here.

The driver will work with IMX477 connected to the J1_1, J1_2, and J1_3 ports of the J20.

IMX477 Linux driver for NVIDIA®Jetson Orin™

RidgeRun Engineering has developed the driver with NVIDIA Corporation and Leopard Imaging Inc. and Auvidea. as a collaborative initiative. The driver works with three cameras on the J1 ports from the J20. In this section, you will find the instructions to patch the JetPack sources enabling the IMX477 sensor driver for the Jetson Orin. These instructions have been validated in the following JetPack versions:

  • Jetpack 5.0.2

Download JetPack

The current version of the driver is supported in Jetpack 5.0.2. Porting the driver to other versions and platforms is possible.

1. Download and install the NVIDIA SDK Manager (membership is required).

2. Log in with your NVIDIA membership credentials in the SDK Manager.

3. Select JetPack version 5.0.2 DP and Jetson Orin as shown below and press Continue:

Figure 1. Required SDK Manager options.

4. Accept the terms and conditions and press Continue. The SDK Manager will download and install the selected components:

Figure 2. SDK Manager download and install software.

5. Select Manual Setup. Create a Make sure the board is in Recovery Mode and then press Flash:

Figure 3. Manual setup to start the flashing process.

Recovery Mode for Jetson Orin AGX

  1. Make sure the device is connected to the power adapter but powered off.
  2. Connect the host computer to the front USB Type-C connector on the device.
  3. Power the device
  4. Press and hold the middle (Force Recovery) button.
  5. Press and hold the left (Power) button.
  6. Release both buttons.

6. When the OS has been installed successfully in the Jetson Orin AGX, you have multiple options to use the board:

  1. Use the username and password previously selected to connect over SSH to the corresponding IP (normally 192.168.55.1 over the USB connection).
  2. Connect over the UART connection opened by attaching the micro-USB, for example, minicom: sudo minicom -D /dev/ttyUSB0 -b 115200 and use the same username and password
  3. Connect over display.



Installing the Driver - JetPack sources patch

Download the JetPack sources

You can obtain the JetPack 5.0.2 DP sources by doing the following:

1. Go to https://developer.nvidia.com/embedded/jetson-linux-archive and download the source files for your release.

2. Extract the .tbz2 file:

tar -xjf public_sources.tbz2

3. Extract the kernel source file:

cd Linux_for_Tegra/source/public
JETSON_SOURCES=$PWD
tar –xjf kernel_src.tbz2

This extracts the kernel source to the kernel/ subdirectory.

Patch instructions

Download the patches

RidgeRun has created a repository from where you can download the patch files.

You need to clone it and use the branch for the jetpack.

cd $HOME
git clone https://github.com/RidgeRun/NVIDIA-Jetson-IMX477-RPIV3.git -b jetpack-5.0.2

Once you have downloaded the repository, copy the files to the $JETSON_SOURCES directory:

KERNEL_PATCH=$(pwd)/NVIDIA-Jetson-IMX477-RPIV3/
cp $KERNEL_PATCH/patches_orin/5.0.2_agx_imx477_v0.1.patch $JETSON_SOURCES/

Apply the patches

cd $JETSON_SOURCES
git apply 5.0.2_agx_imx477_v0.1.patch

Kernel build instructions

Once the sources have been patched, perform the following steps in order to build and install the driver.

Install the Toolchain

First, download the Bootlin toolchain binaries from the NVIDIA Jetson Linux home page. Go to the bottom of the page and click on the Bootlin Toolchain gcc option as shown in the image below:

After that do:

mkdir $HOME/l4t-gcc
cd $HOME/l4t-gcc
tar xf <path_to_toolchain_archive>

Build the kernel

  • Establish the building paths and create directories:
KERNEL_OUT=$JETSON_SOURCES/kernel_out
MODULES_OUT=$JETSON_SOURCES/modules_out
mkdir -p $KERNEL_OUT
mkdir -p $MODULES_OUT
  • Use the following command to install dependencies on Ubuntu:
sudo apt install libncurses-dev
  • Export environment variables:
export CROSS_COMPILE_AARCH64_PATH=$HOME/l4t-gcc
export CROSS_COMPILE_AARCH64=$HOME/l4t-gcc/bin/aarch64-buildroot-linux-gnu-
  • Compile kernel:
cd $JETSON_SOURCES
./nvbuild.sh -o $KERNEL_OUT
  • Install the modules
make -C $JETSON_SOURCES/kernel/kernel-5.10/ ARCH=arm64 O=$KERNEL_OUT LOCALVERSION=-tegra INSTALL_MOD_PATH=$MODULES_OUT modules_install

Flash the Jetson

We present two methods to install the customized kernel, one requires a complete flash, and the other is for quick updating while developing.

Complete flash

Update the Linux_for_Tegra directory

# Copy the new compiled kernel.
cp -r $KERNEL_OUT/arch/arm64/boot/Image $JETPACK_DIR/Linux_for_Tegra/kernel/

# Copy all new compiled DTBs and DTB overlays. 
cp -r $KERNEL_OUT/arch/arm64/boot/dts/nvidia/* $JETPACK_DIR/Linux_for_Tegra/kernel/dtb/

# Update rootfs with compiled modules, which include the driver.
rsync -azPu $MODULES_OUT/lib/modules/5.10.104-tegra $JETPACK_DIR/Linux_for_Tegra/rootfs/lib/modules/

# Update the rootfs with all the binaries (to make sure the /boot/ folder is updated too).
cd $JETPACK_DIR/Linux_for_Tegra
sudo ./apply_binaries.sh

# Copy the module to the correct location.
sudo cp $KERNEL_OUT/drivers/media/i2c/nv_imx477.ko $JETPACK_DIR/Linux_for_Tegra/rootfs/lib/modules/5.10.104-tegra/kernel/drivers/media/i2c/

Flash

Finally, flash the driver

sudo ./flash.sh jetson-agx-orin-devkit mmcblk0p1

Manual installation

Update the kernel and DTB files used by /boot/extlinux/extlinux.conf when there is an already running board. This assumes that the Jetson can be reach by SSH using:

ssh jetson

Updating the kernel

Updating the kernel is as simple as copying into the board:

# Update Image on Linux_for_Tegra folder just to sync the flash folders
sudo cp -rfv $KERNEL_OUT/arch/arm64/boot/Image $JETPACK_DIR/Linux_for_Tegra/kernel/

# Copy the Image to the tmp folder on the board
scp $JETPACK_DIR/Linux_for_Tegra/kernel/Image jetson:/tmp/

# Copy the Image to the boot directory on the board
sudo mv /tmp/Image /boot/Image

Updating the DTB

The new JetPack uses the FDT property of the /boot/extlinux/extlinux.conf file, and it sets it to a device tree located in /boot/dtb/ with a prefix of kernel_tegra. We can update this DTB with the following:

# Update on Linux_for_Tegra folder with the new DTBs and overlays
sudo cp -rfv $KERNEL_OUT/arch/arm64/boot/dts/nvidia/* $JETPACK_DIR/Linux_for_Tegra/kernel/dtb/

# Generate required prefixed DTB using flash script with no flash option
cd  $JETPACK_DIR/Linux_for_Tegra
sudo ./flash.sh -r --no-flash jetson-agx-orin-devkit mmcblk0p1

# Copy the device tree to the board
scp $JETPACK_DIR/Linux_for_Tegra/bootloader/kernel_tegra234-p3701-0000-p3737-0000.dtb jetson:/tmp/

# Update the device tree on the board
sudo mv /tmp/kernel_tegra234-p3701-0000-p3737-0000.dtb /boot/dtb/

Updating modules

Inside the board run the following to update the modules folder, copying them from the host:

HOST_NAME=host
HOST_IP=192.168.55.100
cd /lib/modules/
sudo rsync -azPu $HOST_NAME@$HOST_IP:$MODULES_OUT/lib/modules/5.10.104-tegra .

ISP camera overrides installation

Please, visit the Custom ISP Configuration page in order to learn how to use the camera_overrides.isp file to configure the ISP.

Supported Features

Resolutions and framerates

  • 1920x1080 @ 60fps
  • 3840x2160 @ 30fps

Controls

  • Gain
  • Exposure
  • Framerate
  • Group Hold

Example Pipelines

Find some example pipelines to use the IMX477 on Jetson Xavier NX below:

Display

1920x1080

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvvidconv ! nvoverlaysink

3840x2160

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
gst-launch-1.0 nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvvidconv ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvoverlaysink

MP4 Recording

1920x1080

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4

3840x2160

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
gst-launch-1.0 -e nvarguscamerasrc sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvv4l2h264enc ! h264parse ! mp4mux ! filesink location=rpi_v3_imx477_cam$SENSOR_ID.mp4

JPEG snapshots

1920x1080

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=60 # Framerate can go from 2 to 60 for 1920x1080 mode
NUMBER_OF_SNAPSHOTS=20
gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=1920,height=1080,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg

3840x2160

SENSOR_ID=0 # 0 to 2 depending on cam port. 
FRAMERATE=30 # Framerate can go from 2 to 30 for 3840x2160 mode
NUMBER_OF_SNAPSHOTS=20
gst-launch-1.0 -e nvarguscamerasrc num-buffers=$NUMBER_OF_SNAPSHOTS sensor-id=$SENSOR_ID ! "video/x-raw(memory:NVMM),width=3840,height=2160,framerate=$FRAMERATE/1" ! nvjpegenc ! multifilesink location=%03d_rpi_v3_imx477_cam$SENSOR_ID.jpeg


RidgeRun Resources

Quick Start Client Engagement Process RidgeRun Blog Homepage
Technical and Sales Support RidgeRun Online Store RidgeRun Videos Contact Us
RidgeRun.ai: Artificial Intelligence | Generative AI | Machine Learning

Contact Us

Visit our Main Website for the RidgeRun Products and Online Store. RidgeRun Engineering information is available at RidgeRun Engineering Services, RidgeRun Professional Services, RidgeRun Subscription Model and Client Engagement Process wiki pages. Please email to support@ridgerun.com for technical questions and contactus@ridgerun.com for other queries. Contact details for sponsoring the RidgeRun GStreamer projects are available in Sponsor Projects page.




Previous: Video Capture and Display Index Next: GStreamer Pipelines