IMX477 / IMX577 on Rock 5

Today i received an IMX577 camera sensor that i had planned to interface it with Rock 5 (B/C).
I was preparing myself for the torture of getting something out of the sensor, based on the information that there is some compatibility with IMX477. Also, there appears to be a Rockchip driver in the kernel tree, so that might help.

The problem is the vendor announced it as a camera module for Raspberry Pi 4, 15 PIN but the FPC cable is 0.5mm pitch (or 0.3mm, not sure), so i need an adapter.

Does anyone know if there is an FPC adapter, 15P 0.5mm pitch to 1.0 mm pitch?

@radxa team, any chance we will see an imx577 camera module with CS mounting bracket for the Rock 5 series?

1 Like

We heard your voice :slight_smile: Let’s just make it. We have a new platform upcoming, which we will support the imx577 by default. It’s time to customize a imx577 sensor.

1 Like

You can use this adapter cable to use the RPi 15pin camera on Radxa 31pin CSI:

https://radxa.com/products/accessories/fpc-cable-008/

Hi Jack,
It’s great to hear about the imx577 support. Let me know when you have a prototype.

Regarding the adapter, it is impossible to use the 15P FPC cable, let’s wait for the Radxa solution.


But for IMX477, yes, it works great.

Hi ninja, could you point me to a way to use IMX477 with Rock 5C?Is there any link available explaining how it works? Thanks in advance.

You need that adapter cable (from Radxa) and the rpi acrylic case for the HQ camera as in the photo.
You can also refer to the work done by @Monstrofil in his post here: Connect Arducam HQ Camera to ROCK5B

I don’t have written instructions but this weekend i can provide it, i just need to clean up my desk and organize things here, it’s a mess.

You need to build the driver (kernel) and prepare the overlay (i don’t use overlay, but i think the imx219 overlay can be adjusted).

I will prepare a patch based on radxa kernel, maybe they can build an image.

Thank you ninja, this is really helpful, I also responded to you on the linked thread, I really look forward to your instructions, even a brief one, as I have not sufficient time to work these things out all by myself.

Here is a patch for imx477 that can be applied to rk kernel 6.1.
I added a dtb property to start the driver in a specific mode.

3 modes are available:

/* camera-mode = <0>;  10fps - full, 1 - 3K 40fps, 2 - 2K 50fps, 3 - 1K 120fps */
/* mode: 0 - 4048x3040 10 fps */
/* mode: 1 - 2016x1520 40 fps */
/* mode: 2 - 2016x1080 50 fps */

I am struggling to get an overlay working, but i am finishing my Ubuntu 22.04 CLI (Weston) image and am willing to share it as soon as i get a lean and mean image for Rock5C.

If you want to apply the patch, it is like this:

  • download radxa kernel
  • unzip the file into the kernel tree
  • apply this patch
    git apply 0001-Add-support-for-imx477-HQ-camera.patch
    git apply 0002-Add-support-for-imx477-HQ-camera.patch

imx477_patch.zip (15.8 KB)

in the config, add:
CONFIG_VIDEO_IMX415=y
CONFIG_VIDEO_IMX464=y
CONFIG_VIDEO_IMX477=y

1 Like

Huge thanks my friend, I haven’t had much experience playing with Linux kernels but your instruction appears to be very concise and clear, I will definitely try this once I get my hands free from some work stuff lately, and let you know the outcome.
Otherwise I’ll have to program a socket and send the frames from a RPi 4B over ethernet or serial to the ROCK 5, lol

PART 1

Sharing a Rock5C image with support for IMX477 with the following features:

  • Ubuntu 22.04 - minimum image
  • lean and mean, no bloat software
  • cli (command line interface)
  • Weston (wayland) for graphics support
  • Hardware acceleration
  • Hardware Encoder / Decoder enabled
  • NPU enabled
  • IMX477 support with the following modes:
    12.3M - 10 fps (default)
    2016x1520 - 40 fps
    2016x1080 - 50 fps

What this image is for:

  • Development, embedded usage without bloated software
  • Using a Raspberry Pi HQ camera (imx477 sensor) with reasonable quality

What this image is NOT for:

  • Graphical Desktop (X11 and Gnome Wayland)
  • End user experience although this minimum image can be extended to suit your need

This image is prepared with the latest Rockchip / Radxa / Developer contributions,
and it runs with mali lib (not panthor) and stock Ubuntu packages.

What you should not do (unless you know what you are doing):

  • Upgrade kernel, if you do, apply the imx477 patch provided on this post
  • Upgrade distro, this will possibly break hw acceleration

You can use it freely, but if you encounter a license issue, please stop using it or fix it yourself.

Credit goes to:
[ https://github.com/radxa ]
[ https://github.com/nyanmisaka ]
[ https://github.com/avafinger ]
[ https://github.com/JeffyCN ]
Developers who left this community or are still around

What you need:

  • Raspberry Pi HQ camera
  • CS camera lens, i have tested some lenses, 3MP, 10MP with good results, best using raspi lens
  • Raspberry Pi HQ camera acrylic case with stand (an extra spacer is used to allow airflow)
  • Radxa 8M camera cable

What works, what not:

  • 10 fps, 40 fps, and 50 fps work
  • HFLIP, VFLIP not work

Limitations:

  • Depending on the source light a blinking effect can occur, move the camera a little bit to another position
  • Some light scenes can have a washing look or minor ghosting
  • Camera can have only one position, i think compared to Raspberry Pi it seems upside down
  • Not using overlays although you can transplant the radxa ones and run it on this image as usual

Enjoy

PART 2
uploading image… Instructions…

1 Like

PART 2

What you need to assembly:

Image download:

https://mega.nz/file/MagklZpJ#AXa-inWofrXl1NabvKCCRJhgyG-_Piw8mc9UycoHxQQ

Instructions

  • get an SD card, 8GB minimum or more

  • Use your preferred image writer to flash the sd card or

  • Unzip the 7z file and write using Linux to the sd card, example:
    insert the sd card into your USB, and type in:

    df -lh
     /dev/sde         30G   13G   17G  44% /media/alex/6AD9-B80F
    
  • Write the .img file to /dev/sde

    sudo dd if=./rock5c-ubuntu_22.04_8GB_weston_cli.img of=/dev/sde bs=4096 status=progress

    When finished, type in:

    sync

  • remove the sd card, and boot up your board, it should get you in a cli asking user/password

  • type user/password: rock/rock

First thing first:

After you log in, issue the command:

sudo apt-get update

Configure your language and keyboard map:

sudo dpkg-reconfigure locales
sudo dpkg-reconfigure keyboard-configuration

  • Update the packages

sudo apt-get dist-upgrade

PART 3

the goodies…

3 Likes

PART3

If you got this far and had a successful boot, you will want to extend the partition to use all available space. Unfortunately, you have to do it manually with fdisk or use a script available from well-known distros or a simpler method (resize2fs) while running.

Checking if the camera is recognized

rock@rock5c:~$ dmesg|grep -i imx
[ 11.464872] platform csi2-dphy0: Fixed dependency cycle(s) with /i2c@feab0000/camera-imx477@1a
[ 11.465364] imx477 3-001a: camera_default_mode: default_4048x3040
[ 11.465440] imx477 3-001a: Looking up VANA-supply from device tree
[ 11.465444] imx477 3-001a: Looking up VANA-supply property in node /i2c@feab0000/camera-imx477@1a failed
[ 11.465457] imx477 3-001a: supply VANA not found, using dummy regulator
[ 11.465495] imx477 3-001a: Looking up VDIG-supply from device tree
[ 11.465499] imx477 3-001a: Looking up VDIG-supply property in node /i2c@feab0000/camera-imx477@1a failed
[ 11.465508] imx477 3-001a: supply VDIG not found, using dummy regulator
[ 11.465524] imx477 3-001a: Looking up VDDL-supply from device tree
[ 11.465528] imx477 3-001a: Looking up VDDL-supply property in node /i2c@feab0000/camera-imx477@1a failed
[ 11.465537] imx477 3-001a: supply VDDL not found, using dummy regulator
[ 11.475292] imx477 3-001a: Device found is imx477
[ 11.589897] imx477 3-001a: Consider updating driver imx477 to match on endpoints
[ 11.589928] rockchip-csi2-dphy csi2-dphy0: dphy0 matches m00_f_imx477 3-001a:bus type 5
[ 13.290265] iqfile: imx477_IMX477_default_4048x3040.json

Using the camera

The available tools to grab images from the camera are:

  • ffmpeg / ffplay
  • gstreamer (need to update some packages)
  • fswebcam

Here are some examples:

  • 12.3 M mode (10 fps)

ffplay -f v4l2 -pixel_format nv12 -framerate 30 -video_size 1920x1080 -i /dev/video11 -top 0 -left 0
DISPLAY=:0.0 ffplay -f v4l2 -pixel_format nv12 -framerate 30 -video_size 4064x3040 -i /dev/video11
fswebcam --displayfps 1 -S 90 -d /dev/video11 -r 4064x3040 --jpeg 95 -p NV12 - > 4064x3040_1.jpg

  • 50 fps mode

ffplay -f v4l2 -pixel_format nv12 -framerate 30 -video_size 2016x1080 -i /dev/video11 -top 0 -left 0

Weston

By default, the image runs on CLI but you can fire Weston for graphical apps.
Type in the command (not from ssh):

weston

Now you can run graphics apps from ssh
If you want weston with command line and windowing, edit .config\weston.ini and comment on the lines that disable bar and window.

If you want to boot with weston, you must manually add the Weston service.

Gstreamer

I was focused on ffmpeg / ffplay, and had gstreamer working fine, but i must have removed some packages, i need to review which one(s).

Looks like the dma-buf patch to fix ffmpeg broken the gstreamer, if you want to use gstreamer try to unzip the file mpp.zip (attached) to a /tmp, install the deb packages with *'sudo dpkg -i *.deb’ and reboot. Unfortunately, you have to make a choice, ffmpeg / ffplay with HW encoder/decoder/acceleration or gstreamer with HW encoder/decoder/acceleration due to the dma-buf patch for ffmpeg.

More about the ffmpeg fix here: ( [FFmpeg] Introduce FFmpeg-Rockchip for hyper fast video transcoding via CLI )

mpp.zip (1.1 MB)

try gstreamer:

gst-launch-1.0 v4l2src device=/dev/video11 io-mode=dmabuf ! ‘video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1’ ! glimagesink

Changing camera mode

You have a directory with pre-made modes, you just copy it to the boot.

ls ~/dtb
rk3588s-rock-5c.dtb_IMX477_2016x1080_50fps
rk3588s-rock-5c.dtb_IMX477_2016x1520_40fps
rk3588s-rock-5c.dtb_IMX477_4048x3040_10fps

  • 50 fps mode:

cd ~/dtb
rock@rock5c:~/dtb$ sudo cp -vf rk3588s-rock-5c.dtb_IMX477_2016x1080_50fps /boot/dtbs/6.1.43-rk3588-v4l2-cam/rockchip/rk3588s-rock-5c.dtb
‘rk3588s-rock-5c.dtb_IMX477_2016x1080_50fps’ -> ‘/boot/dtbs/6.1.43-rk3588-v4l2-cam/rockchip/rk3588s-rock-5c.dtb’
sudo reboot

Check FPS with gstreamer (after you restore/rollback dma-buf ffmpeg fix, see above), fire weston and:

GST_GL_X11_NO_DECORATIONS=1 DISPLAY=:0.0 gst-launch-1.0 v4l2src device=/dev/video11 io-mode=dmabuf ! ‘video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1’ ! fpsdisplaysink video-sink=waylandsink sync=false

Performance / Optimizations

Set performance governor with:
p.sh.zip (407 Bytes)

If you like to be on the edge you can set frequencies and governor to performance and get a boost.
Save the attached file p.sh, set run flag: sudo chmod +x ./p.sh and run with sudo, like this:

rock@rock5c:~$ sudo ./p.sh
CPU0-3 Available Frequencies:
408000 600000 816000 1008000 1200000 1416000 1608000 1800000 
performance
CPU0-3 current freq:
1800000

CPU4-5 Available Frequencies:
408000 600000 816000 1008000 1200000 1416000 1608000 1800000 2016000 2208000 2304000 
performance
CPU4-5 current freq:
2304000

CPU6-7 Available Frequencies:
408000 600000 816000 1008000 1200000 1416000 1608000 1800000 2016000 2208000 2304000 
performance
CPU6-7 current freq:
2304000

NPU Available Frequencies:
300000000 400000000 500000000 600000000 700000000 800000000 900000000 1000000000
performance
NPU current freq:
1000000000

GPU Available Frequencies:
1000000000 900000000 800000000 700000000 600000000 500000000 400000000 300000000
GPU current freq:
1000000000

Monitor
mon.sh.zip (445 Bytes)

With a new ssh connection, you can monitor the performance, like this:

rock@rock5c:~$ sudo chmod +x mon.sh
rock@rock5c:~$ sudo ./mon.sh
[sudo] password for rock: 
 CPU0-3  CPU4-5  CPU6-7     DDR     DSU     GPU     NPU
   1800    2304    2304     528    1800     200     200
   1800    2304    2304     528    1800     200     200
   1800    2304    2304     528    1800     200     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304    2112    1800    1000     200
   1800    2304    2304     528    1800     200     200
   1800    2304    2304     528    1800     200     200

Benchmark

After you set performance governor you can run glmark2 to check the score.

  • In the main console, run :

weston

  • in an SSH connection, run :

sudo ./p.sh

  • in an shh connection, run :
rock@rock5c:~$ glmark2-es2-wayland 
arm_release_ver of this libmali is 'g6p0-01eac0', rk_so_ver is '6'.
=======================================================
    glmark2 2021.02
=======================================================
    OpenGL Information
    GL_VENDOR:     ARM
    GL_RENDERER:   Mali-LODX
    GL_VERSION:    OpenGL ES 3.2 v1.g6p0-01eac0.ba52c908d926792b8f5fe28f383a2b03
=======================================================
[build] use-vbo=false: FPS: 4235 FrameTime: 0.236 ms
[build] use-vbo=true: FPS: 5263 FrameTime: 0.190 ms
[texture] texture-filter=nearest: FPS: 3939 FrameTime: 0.254 ms
[texture] texture-filter=linear: FPS: 3421 FrameTime: 0.292 ms
[texture] texture-filter=mipmap:^C FPS: 3843 FrameTime: 0.260 ms
=======================================================
                                  glmark2 Score: 4140 
=======================================================
1 Like

Patch for kernel 6.1.84
0001-Add-support-for-imx477-HQ-camera.patch.zip (15.3 KB)

Upgrading the kernel

Here are the instructions for upgrading kernel 6.1.43 to 6.1.84.
The way to update/upgrade the kernel is non-orthodox but has some advantages/disadvantages.

Upgrade Kernel kernel_6.1.43 to kernel_6.1.84

*OBS: use ethernet on the next reboot

Download the file: upgrade_kernel.zip (https://mega.nz/file/sSRiEK4I#74ClKGy4K1SevjFjGc9izGZXuaG441vjAUShN23MQxQ)

Put it in a tmp dir and unzip, follow verbatim:

rock@rock5c:~$ mkdir tmp
rock@rock5c:~$ cd tmp/
—> move upgrade_kernel.zip here
rock@rock5c:~/tmp$ unzip upgrade_kernel.zip
rock@rock5c:~/tmp$ cd upgrade_kernel/
rock@rock5c:~/tmp/upgrade_kernel$ sudo tar -xvpzf kernel_6.1.84-rk3588-v4l2-cam.tar.gz -C /
rock@rock5c:~/tmp/upgrade_kernel$ sudo cp -vfr extlinux.conf /boot/extlinux/extlinux.conf
rock@rock5c:~/tmp/upgrade_kernel$ sync
rock@rock5c:~/tmp/upgrade_kernel$ sudo reboot

You should be now on the new kernel:

rock@rock5c:~$ uname -ra
Linux rock5c 6.1.84-rk3588-v4l2-cam #1 SMP Fri Nov 22 17:32:21 -03 2024 aarch64 aarch64 aarch64 GNU/Linux

Build the wifi6

rock@rock5c:~$ cd tmp/upgrade_kernel
rock@rock5c:~/tmp/upgrade_kernel$
rock@rock5c:~/tmp/upgrade_kernel$ sudo dpkg -i linux-headers-6.1.84-rk3588-v4l2-cam_6.1.84-rk3588-v4l2-cam-2_arm64.deb
rock@rock5c:~/tmp/upgrade_kernel$ sudo cp -vfr ./scripts /usr/src/linux-headers-$(uname -r)/
rock@rock5c:~/tmp/upgrade_kernel$ sudo dpkg -i aic8800-firmware_3.0+git20240116.ec460377-8_all.deb
rock@rock5c:~/tmp/upgrade_kernel$ sudo dpkg -i aicrf-test_3.0+git20240116.ec460377-8_arm64.deb
rock@rock5c:~/tmp/upgrade_kernel$ sudo dpkg -i aic8800-usb-dkms_3.0+git20240116.ec460377-8_all.deb
rock@rock5c:~/tmp/upgrade_kernel$ sync
rock@rock5c:~/tmp/upgrade_kernel$ sudo reboot

Check if you have wlan0

rock@rock5c:~/tmp/upgrade_kernel$ ifconfig|grep wlan
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

Next you check the camera with:

DISPLAY=:0.0 ffplay -f v4l2 -pixel_format nv12 -framerate 30 -video_size 1920x1080 -i /dev/video11

or if you updated mpp to have gstreamer also:

gst-launch-1.0 v4l2src device=/dev/video11 io-mode=dmabuf ! ‘video/x-raw,format=NV12,width=2016,height=1080’ ! fpsdisplaysink video-sink=glimagesink sync=false

Note that if rolling back the mpp to have gstreamer, it does not affect ffplay decoding capabilities!

TODO

  • audio
  • mpv

As I’ve never done the (analog) audio properly in Linux, feel free to show how it should be done!

Enjoy it

Update: Attached are the camera modes for kernel 6.1.84, proceed in a similar way as described above for kernel 6.1.43
dtb_v2.zip (121.3 KB)

I’m just comparing the 50fps mode (the worst mode on imx477) at 1280x720 to an H264 USB 2.0 camera and H265 USB 2.0 camera in parallel, rendered all in Weston at 1920x1080.

Upper left: Fixed focus lens (640x480) 30fps
Bottom left: CS 3M lens (640x480) 30fps
IMX477: CS 10M lens (1280x720) 50fps

sudo htop
htop

Notes about the available software to get images from the camera:

  1. ffplay / ffmpeg
  2. gstreamer
  3. mpv
  4. fswebcam

Examples on Weston, run weston and from an ssh instance run the commands:

  • ffplay

ffplay -f v4l2 -pixel_format nv12 -framerate 30 -video_size 1920x1080 -i /dev/video11

  • gstreamer

gst-launch-1.0 v4l2src device=/dev/video11 io-mode=dmabuf ! ‘video/x-raw,format=NV12,width=1920,height=1080,framerate=50/1’ ! fpsdisplaysink video-sink=waylandsink sync=false

  • mpv

DISPLAY=:0.0 mpv --hwdec=rkmpp --vo=gpu --gpu-api=opengl --opengl-es=yes --gpu-context=wayland --drm-draw-plane=overlay --drm-drmprime-video-plane=primary --drm-device=/dev/dri/card0 --demuxer-lavf-format=video4linux2 --demuxer-lavf-o-set=input_format=nv12 av://v4l2:/dev/video11 --fps=30 --profile=low-latency --loop-file=inf --no-border --audio-device=alsa:device=rockchip-hdmi0 --geometry=1920x1080 -v

  • fswebcam

fswebcam --displayfps 1 -S 90 -d /dev/video11 -r 4048x3040 --jpeg 95 -p NV12 - > 4048x3040.jpg

Please be careful if you copy and paste the examples above directly into the command line. The formatting sometimes introduces hidden characters, resulting in a command or format error (gstreamer).

Installing MPV

  • download the attached file in /tmp, unzip it and install the deb packages

    sudo apt-get update
    sudo apt-get install liblua5.2-dev libmujs-dev libplacebo-dev libsixel-dev libspirv-cross-c-shared-dev libuchardet-dev python3-docutils spirv-cross
    sudo dpkg -i *.deb
    sudo apt --fix-broken install
    sudo dpkg -i *.deb

Final note and Warning

MPV, FFmpeg, and FFplay have a limitation in kernel 6.1.x if your board has more than 4GB, to bypass this limitation, please use gstreamer.

Things you should not do that will crash the kernel:

  • Encoding or decoding for a board with 8GB or 16GB/32GB with ffplay/ffmpeg, use mpv or gstreamer.

  • Changing or setting HFliping or VFliping

mpv deb package to install:
mpv.zip (2.1 MB)

Update:

I checked decoding with mpv on Rock 5B with 16G RAM, worked fine:

rock@rock5b:~$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       347Mi        13Gi        26Mi       1.7Gi        14Gi
Swap:          6.2Gi          0B       6.2Gi

rock@rock5b:~$ mpv --hwdec=rkmpp --vo=gpu --gpu-api=opengl --gpu-context=drm --drm-device=/dev/dri/card0 ./jellyfish-30-mbps-hd-h264.mkv
(+) Video --vid=1 (*) (h264 1920x1080 29.970fps)
[vo/gpu] VT_GETMODE failed: Inappropriate ioctl for device
[vo/gpu/opengl] Failed to set up VT switcher. Terminal switching will be unavailable.
arm_release_ver of this libmali is ‘g6p0-01eac0’, rk_so_ver is ‘6’.
[vo/gpu/drmprime-drm] No drmprime video plane. You might need to specify it manually using --drm-drmprime-video-plane
Using hardware decoding (rkmpp).
No video PTS! Making something up. Using 29.970031 FPS.
[autoconvert] HW-downloading from drm_prime
VO: [gpu] 1920x1080 nv12
V: 00:00:29 / 00:00:30 (100%)

Exiting… (End of file)