Raspberry Pi Camera not working

Hi, I’m trying to run Raspberry Pi camera with RockPi 4 Plus V1.72.
I use debian. I enabled the modules and installed gstreamer, but I the images I get are quite bad looking and almost completely dark.
With this command:
gst-launch-1.0 v4l2src device=/dev/video0 num-buffers=1 ! jpegenc ! filesink location=test.jpg
I get:

This is not only present in debian, but also in linearo image here -> https://wiki.radxa.com/Rockpi4/MIPI_Camera
When I run this: test_camera-rkisp1.sh
I get this result (green thing is the led of rockpi, without it it’s almost black)

Can this be due to a kernel module?

Edit: the camera is imx219

You possibly need the help from libcamera: https://libcamera.org/

https://libcamera.org/entries/2020-05-05.html

Thank you for the response.

I tried installing the master branch, but it failed(giving some syntax issue in one of the header files), therefore I used an older source from (https://github.com/kbingham/libcamera/commit/e2d00fbcbb1a9b2da50fa2e280817a0de1a7d286)[this link] and installed that one. Finally, it compiled and installed, but now it doesn’t recognize my camera:

rock@rockpi-4b:~$ LIBCAMERA_LOG_LEVELS=*:DEBUG cam -l
[0:08:41.332061256] [1481] DEBUG IPAModule ipa_module.cpp:329 ipa_ipu3.so: IPA module /usr/local/lib/aarch64-linux-gnu/libcamera/ipa_ipu3.so is signed
[0:08:41.334074074] [1481] DEBUG IPAManager ipa_manager.cpp:240 Loaded IPA module '/usr/local/lib/aarch64-linux-gnu/libcamera/ipa_ipu3.so'
[0:08:41.361069635] [1481] DEBUG IPAModule ipa_module.cpp:329 ipa_rkisp1.so: IPA module /usr/local/lib/aarch64-linux-gnu/libcamera/ipa_rkisp1.so is signed
[0:08:41.362032147] [1481] DEBUG IPAManager ipa_manager.cpp:240 Loaded IPA module '/usr/local/lib/aarch64-linux-gnu/libcamera/ipa_rkisp1.so'
[0:08:41.427891924] [1481] DEBUG IPAModule ipa_module.cpp:329 ipa_rpi.so: IPA module /usr/local/lib/aarch64-linux-gnu/libcamera/ipa_rpi.so is signed
[0:08:41.429188400] [1481] DEBUG IPAManager ipa_manager.cpp:240 Loaded IPA module '/usr/local/lib/aarch64-linux-gnu/libcamera/ipa_rpi.so'
[0:08:41.442663284] [1481] DEBUG IPAModule ipa_module.cpp:329 ipa_vimc.so: IPA module /usr/local/lib/aarch64-linux-gnu/libcamera/ipa_vimc.so is signed
[0:08:41.443545879] [1481] DEBUG IPAManager ipa_manager.cpp:240 Loaded IPA module '/usr/local/lib/aarch64-linux-gnu/libcamera/ipa_vimc.so'
[0:08:41.446075828] [1481]  INFO Camera camera_manager.cpp:293 libcamera v0.0.0+3498-e2d00fbc
[0:08:41.447659016] [1485] DEBUG Camera camera_manager.cpp:106 Starting camera manager
[0:08:41.455715454] [1485] ERROR MediaDevice media_device.cpp:236 /dev/media0[rkisp1]: Failed to enumerate topology: Inappropriate ioctl for device
[0:08:41.456236670] [1485]  INFO DeviceEnumerator device_enumerator.cpp:218 Unable to populate media device /dev/media0 (Invalid argument), skipping
[0:08:41.456680884] [1485]  WARN DeviceEnumerator device_enumerator_udev.cpp:173 Failed to add device for '/sys/devices/platform/ff910000.rkisp1/media0', skipping
[0:08:41.460357390] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerIPU3'
[0:08:41.461818951] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerRPi'
[0:08:41.462189956] [1485] DEBUG RPI raspberrypi.cpp:1139 Unable to acquire a Unicam instance
[0:08:41.462472876] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerRkISP1'
[0:08:41.463138760] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'SimplePipelineHandler'
[0:08:41.463524056] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerUVC'
[0:08:41.463879603] [1485] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerVimc'
Available cameras:

I’m a noob and don’t know the relation between /dev/media* and /dev/video*, but I found this one https://github.com/raspberrypi/libcamera-apps/issues/270.

I’m stuck at this point, any help is appreciated :slight_smile:

[0:08:41.455715454] [1485] ERROR MediaDevice media_device.cpp:236 /dev/media0[rkisp1]: Failed to enumerate topology: Inappropriate ioctl for device

That means your kernel is missing the newer v4l2 io control that libcamera is asking for.
See here:
https://www.kernel.org/doc/html/v4.9/media/uapi/mediactl/media-ioc-g-topology.html
And here:
https://patchwork.libcamera.org/patch/399/

Maybe you need to find a patched libcamera version for your kernel.

To clarify things:
What is the output of:
uname -ra

and what is the sensor?

Currently installed kernel is:
Linux rockpi-4b 4.4.154-116-rockchip-g86a614bc15b3 #1 SMP Mon Jan 10 12:03:08 UTC 2022 aarch64 GNU/Linux

The camera sensor is: imx219

I think in the link you shared they say prior to kernel 4.19; therefore I tried upgrading the kernel to 4.19 from https://github.com/rockchip-linux/kernel/tree/develop-4.19

I also enabled this one from kernel config: Hidden v4l2 configs for GKI (NEW)
but the result is compilation fail:

  CC      drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.o
drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.c: In function 'kbase_devfreq_init':
drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.c:409:18: error: 'kbase_dcp' undeclared (first use in this function); did you mean 'kbase_vmap'?
          (u32 *)&kbase_dcp->dyn_power_coeff);
                  ^~~~~~~~~
                  kbase_vmap
drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.c:409:18: note: each undeclared identifier is reported only once for each function it appears in
At top level:
drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.c:334:37: warning: 'kbase_cooling_power' defined but not used [-Wunused-variable]
error, forbidden warning:mali_kbase_devfreq.c:334
 static struct devfreq_cooling_power kbase_cooling_power = {
                                     ^~~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:334: drivers/gpu/arm/bifrost_for_linux/backend/gpu/mali_kbase_devfreq.o] Error 1
make[3]: *** [scripts/Makefile.build:637: drivers/gpu/arm/bifrost_for_linux] Error 2
make[2]: *** [scripts/Makefile.build:637: drivers/gpu/arm] Error 2
make[1]: *** [scripts/Makefile.build:637: drivers/gpu] Error 2
make: *** [Makefile:1198: drivers] Error 2

Maybe you could try this: https://gitlab.collabora.com/koike/linux/-/commit/7d93fa0b60450d1a725a77d81a77ae116f178782

Ok thanks, I will try this, but I wanted to first finish this kernel thing because after 5 hours of fixing bugs(C compile issues, disabling modules), I finally compiled and installed the kernel. However, I cannot boot anymore; no IP, no display, I can use keyboard but I can only reset. The blue led blinks with some constant frequency.

I disabled these modules:

USB Gadget Support (USB_GADGET) [Y/n/m/?] y
  Debugging messages (DEVELOPMENT) (USB_GADGET_DEBUG) [N/y/?] n
  Debugging information files (DEVELOPMENT) (USB_GADGET_DEBUG_FILES) [Y/n/?] y
  Debugging information files in debugfs (DEVELOPMENT) (USB_GADGET_DEBUG_FS) [N/y/?] n
  Maximum VBUS Power usage (2-500 mA) (USB_GADGET_VBUS_DRAW) [500] 500
  Number of storage pipeline buffers (USB_GADGET_STORAGE_NUM_BUFFERS) [2] 2
  Serial gadget console support (U_SERIAL_CONSOLE) [N/y/?] n
  USB Gadget functions configurable through configfs (USB_CONFIGFS) [M/n/y/?] m
    Uevent notification of Gadget state (USB_CONFIGFS_UEVENT) [N/y/?] n
    Generic serial bulk in/out (USB_CONFIGFS_SERIAL) [N/y/?] n
    Abstract Control Model (CDC ACM) (USB_CONFIGFS_ACM) [Y/n/?] y
    Object Exchange Model (CDC OBEX) (USB_CONFIGFS_OBEX) [N/y/?] n
    Network Control Model (CDC NCM) (USB_CONFIGFS_NCM) [N/y/?] n
    Ethernet Control Model (CDC ECM) (USB_CONFIGFS_ECM) [N/y/?] n
    Ethernet Control Model (CDC ECM) subset (USB_CONFIGFS_ECM_SUBSET) [N/y/?] n
    RNDIS (USB_CONFIGFS_RNDIS) [Y/n/?] y
    Ethernet Emulation Model (EEM) (USB_CONFIGFS_EEM) [N/y/?] n
    Mass storage (USB_CONFIGFS_MASS_STORAGE) [Y/n/?] y
    Loopback and sourcesink function (for testing) (USB_CONFIGFS_F_LB_SS) [N/y/?] n
    Function filesystem (FunctionFS) (USB_CONFIGFS_F_FS) [Y/n/?] y
    Accessory gadget (USB_CONFIGFS_F_ACC) [N/y/?] n
    Audio Source gadget (USB_CONFIGFS_F_AUDIO_SRC) [N/y/?] n
    Audio Class 1.0 (USB_CONFIGFS_F_UAC1) [N/y/?] n
    Audio Class 1.0 (legacy implementation) (USB_CONFIGFS_F_UAC1_LEGACY) [N/y/?] n
    Audio Class 2.0 (USB_CONFIGFS_F_UAC2) [N/y/?] n
    MIDI function (USB_CONFIGFS_F_MIDI) [Y/n/?] y
    HID function (USB_CONFIGFS_F_HID) [N/y/?] n
    USB Webcam function (USB_CONFIGFS_F_UVC) [Y/n/?] y
    Printer function (USB_CONFIGFS_F_PRINTER) [N/y/?] n
  USB Gadget precomposed configurations [M/n/y/?] m
    Gadget Zero (DEVELOPMENT) (USB_ZERO) [N/m/?] n
    Audio Gadget (USB_AUDIO) [N/m/?] (NEW) n
    Ethernet Gadget (with CDC Ethernet support) (USB_ETH) [M/n/?] m
      RNDIS support (USB_ETH_RNDIS) [Y/n/?] y
      Ethernet Emulation Model (EEM) support (USB_ETH_EEM) [N/y/?] n
    Network Control Model (NCM) support (USB_G_NCM) [M/n/?] m
    Gadget Filesystem (USB_GADGETFS) [M/n/?] m
    Function Filesystem (USB_FUNCTIONFS) [M/n/?] m
      Include configuration with CDC ECM (Ethernet) (USB_FUNCTIONFS_ETH) [Y/n/?] y
      Include configuration with RNDIS (Ethernet) (USB_FUNCTIONFS_RNDIS) [Y/n/?] y
      Include 'pure' configuration (USB_FUNCTIONFS_GENERIC) [Y/n/?] y
    Mass Storage Gadget (USB_MASS_STORAGE) [M/n/?] m
    Serial Gadget (with CDC ACM and CDC OBEX support) (USB_G_SERIAL) [M/n/?] m
    MIDI Gadget (USB_MIDI_GADGET) [M/n/?] m
    Printer Gadget (USB_G_PRINTER) [M/n/?] m
    CDC Composite Device (Ethernet and ACM) (USB_CDC_COMPOSITE) [M/n/?] m
    CDC Composite Device (ACM and mass storage) (USB_G_ACM_MS) [M/n/?] m
    Multifunction Composite Gadget (USB_G_MULTI) [M/n/?] m
      RNDIS + CDC Serial + Storage configuration (USB_G_MULTI_RNDIS) [Y/n/?] y
      CDC Ethernet + CDC Serial + Storage configuration (USB_G_MULTI_CDC) [Y/n/?] y
    HID Gadget (USB_G_HID) [M/n/?] m
    EHCI Debug Device Gadget (USB_G_DBGP) [N/m/?] n
    USB Webcam Gadget (USB_G_WEBCAM) [M/n/?] m
    USB Raw Gadget (USB_RAW_GADGET) [N/m/?] n

USB Gadget Support (USB_GADGET) [Y/n/m/?] y
  Debugging messages (DEVELOPMENT) (USB_GADGET_DEBUG) [N/y/?] n
  Debugging information files (DEVELOPMENT) (USB_GADGET_DEBUG_FILES) [Y/n/?] y
  Debugging information files in debugfs (DEVELOPMENT) (USB_GADGET_DEBUG_FS) [N/y/?] n
  Maximum VBUS Power usage (2-500 mA) (USB_GADGET_VBUS_DRAW) [500] 500
  Number of storage pipeline buffers (USB_GADGET_STORAGE_NUM_BUFFERS) [2] 2
  Serial gadget console support (U_SERIAL_CONSOLE) [N/y/?] n
  USB Gadget functions configurable through configfs (USB_CONFIGFS) [M/n/y/?] m
    Uevent notification of Gadget state (USB_CONFIGFS_UEVENT) [N/y/?] n
    Generic serial bulk in/out (USB_CONFIGFS_SERIAL) [N/y/?] n
    Abstract Control Model (CDC ACM) (USB_CONFIGFS_ACM) [Y/n/?] y
    Object Exchange Model (CDC OBEX) (USB_CONFIGFS_OBEX) [N/y/?] n
    Network Control Model (CDC NCM) (USB_CONFIGFS_NCM) [N/y/?] n
    Ethernet Control Model (CDC ECM) (USB_CONFIGFS_ECM) [N/y/?] n
    Ethernet Control Model (CDC ECM) subset (USB_CONFIGFS_ECM_SUBSET) [N/y/?] n
    RNDIS (USB_CONFIGFS_RNDIS) [Y/n/?] y
    Ethernet Emulation Model (EEM) (USB_CONFIGFS_EEM) [N/y/?] n
    Mass storage (USB_CONFIGFS_MASS_STORAGE) [Y/n/?] y
    Loopback and sourcesink function (for testing) (USB_CONFIGFS_F_LB_SS) [N/y/?] n
    Function filesystem (FunctionFS) (USB_CONFIGFS_F_FS) [Y/n/?] y
    Accessory gadget (USB_CONFIGFS_F_ACC) [N/y/?] n
    Audio Source gadget (USB_CONFIGFS_F_AUDIO_SRC) [N/y/?] n
    Audio Class 1.0 (USB_CONFIGFS_F_UAC1) [N/y/?] n
    Audio Class 1.0 (legacy implementation) (USB_CONFIGFS_F_UAC1_LEGACY) [N/y/?] n
    Audio Class 2.0 (USB_CONFIGFS_F_UAC2) [N/y/?] n
    MIDI function (USB_CONFIGFS_F_MIDI) [Y/n/?] y
    HID function (USB_CONFIGFS_F_HID) [N/y/?] n
    USB Webcam function (USB_CONFIGFS_F_UVC) [Y/n/?] y
    Printer function (USB_CONFIGFS_F_PRINTER) [N/y/?] n
  USB Gadget precomposed configurations [M/n/y/?] m
    Gadget Zero (DEVELOPMENT) (USB_ZERO) [N/m/?] n
    Audio Gadget (USB_AUDIO) [N/m/?] n
    Ethernet Gadget (with CDC Ethernet support) (USB_ETH) [M/n/?] m
      RNDIS support (USB_ETH_RNDIS) [Y/n/?] y
      Ethernet Emulation Model (EEM) support (USB_ETH_EEM) [N/y/?] n
    Network Control Model (NCM) support (USB_G_NCM) [M/n/?] m
    Gadget Filesystem (USB_GADGETFS) [M/n/?] m
    Function Filesystem (USB_FUNCTIONFS) [M/n/?] m
      Include configuration with CDC ECM (Ethernet) (USB_FUNCTIONFS_ETH) [Y/n/?] y
      Include configuration with RNDIS (Ethernet) (USB_FUNCTIONFS_RNDIS) [Y/n/?] y
      Include 'pure' configuration (USB_FUNCTIONFS_GENERIC) [Y/n/?] y
    Mass Storage Gadget (USB_MASS_STORAGE) [M/n/?] m
    Serial Gadget (with CDC ACM and CDC OBEX support) (USB_G_SERIAL) [M/n/?] m
    MIDI Gadget (USB_MIDI_GADGET) [M/n/?] m
    Printer Gadget (USB_G_PRINTER) [M/n/?] m
    CDC Composite Device (Ethernet and ACM) (USB_CDC_COMPOSITE) [M/n/?] m
    CDC Composite Device (ACM and mass storage) (USB_G_ACM_MS) [M/n/?] m
    Multifunction Composite Gadget (USB_G_MULTI) [M/n/?] m
      RNDIS + CDC Serial + Storage configuration (USB_G_MULTI_RNDIS) [Y/n/?] y
      CDC Ethernet + CDC Serial + Storage configuration (USB_G_MULTI_CDC) [Y/n/?] y
    HID Gadget (USB_G_HID) [M/n/?] m
    EHCI Debug Device Gadget (USB_G_DBGP) [N/m/?] n
    USB Webcam Gadget (USB_G_WEBCAM) [N/m/?] (NEW) n
    USB Raw Gadget (USB_RAW_GADGET) [N/m/?] n

It could be a kernel config or you missed to enable HDMI and eth in dts. Both things are related.
For this case, you need a USB-TTL serial debug.
BTW, i found some cheap imx219 cameras, just ordered one and i will test it on Rock 3A and see what i get.

I connected using serial, I am attaching logs.

It gets stuck at:

Device 0: unknown device
ethernet@fe300000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Could not initialize PHY ethernet@fe300000
missing environment variable: pxeuuid
Retrieving file: /extlinux/pxelinux.cfg/01-b6-d1-14-54-41-6b
ethernet@fe300000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Could not initialize PHY ethernet@fe300000
Retrieving file: /extlinux/pxelinux.cfg/00000000
ethernet@fe300000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Could not initialize PHY ethernet@fe300000
Retrieving file: /extlinux/pxelinux.cfg/0000000
ethernet@fe300000 Waiting for PHY auto negotiation to complete......... TIMEOUT !
Could not initialize PHY ethernet@fe300000
Retrieving file: /extlinux/pxelinux.cfg/000000
ethernet@fe300000 Waiting for PHY auto negotiation to complete..

it might be trying to boot over ethernet because when I plug in the ethernet cable, I get

Using ethernet@fe300000 device
TFTP from server 10.42.0.1; our IP address is 10.42.0.213
Load address: 0x600000
Loading: T T T T T (some more T)
Retry count exceeded; starting again

debian_log.zip (1.7 KB)

I have missing files inside dtbs/4.19.206-rt87 do you know how can install them?

I don’t know which u-boot you are using.
Read buildroot scripts, it may help.
Looks like you need something like: https://fossies.org/linux/buildroot/board/firefly/roc-rk3399-pc/extlinux.conf

I don’t know how to check which u-boot I’m using. I’m using extlinux.conf file to change the boot order.

I think the problem is my bad because I assumed rockchip kernel would work on rockpi. It might be the kernel not supporting rockpi4 because there is no such file as rk3399-rock-pi-4b.dtb inside the build directory (but I have tons of dtb file there), it might be this kernel -> https://github.com/rockchip-linux/kernel/tree/develop-4.19 will never work on rockpi4b.

The error is:
** Unable to read file /dtbs/4.19.206-rt87/rockchip/rk3399-rock-pi-4b.dtb

You need to create a new dtb for your rockpi 4b. rockchip-linux support their evb.
You have a few choices:

  1. create the dtb for your hardware and name it rk3399-rock-pi-4b.dtb
  2. go for a kernel with dts that support the hardware
  3. look for the android kernel and get some inside info there, if i don’t mistake is 4.19.219

good luck

Could you help me creating dtb for the hardware?

The android kernel is 4.19.111 #22 Thu Oct 15 11:16:14 CST 2020 and works without any problems