WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: libcamera  (Read 2907 times)

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14799
libcamera
« on: October 17, 2022, 08:39:43 AM »
libcamera and libcamera-apps added to the armv* repos - note that piCore-13.1 is required.

Add the following to config.txt: to enable the camera:
Code: [Select]
camera_auto_detect=0
dtoverlay=imx219

Load libcamera-apps and then:
Code: [Select]
sudo chown tc:staff /dev/media*
sudo chown tc:staff /dev/dma_heap/*

Check things are OK with:
Code: [Select]
libcamera-hello -n
libcamera-still -r -n -o test.jpg

* tested with an RPi3
* RPi camera v2.1 used - a different dtoverlay will be required for other cameras
* there is a fix for /dev/media permissions in tc git

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #1 on: July 13, 2024, 10:21:42 AM »
Are there any official plans to upgrade the libcamera extension?

I just tested installed libcamera on piCore v14, which results in an error with libtiff.so.

I also just tested it withe the same hardware, but running piCore v13 and there it works fine,
using: camera_auto_detect=1

Machine: Raspberry Pi 2 Model B V1.1
Camera: picamera v2.1

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #2 on: July 13, 2024, 11:03:16 AM »
Hi segfault
I think libtiff.tcz needs to be changed to libtiff5.tcz in libcamera-apps.tcz.dep.

Try this:
Code: [Select]
tce-load -wi libtiff5.tczand let us know if that fixes the issue.

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #3 on: July 13, 2024, 03:40:29 PM »
Code: [Select]
tce-load -wi libtiff5.tczand let us know if that fixes the issue.

Success. Yes that fixes the issue with libtiff. Yeay!!!!

The camera is still not working. Now I got another error.
Using the same config.txt camera config (which is a single line: camera_auto_detect=1) and same hardware (swiching SDCARD on device I get repeated and 100% reproduceability, so not likely HW issue), I did the following on both piCore v13 and v14:

Code: [Select]
sudo chown tc:staff /dev/media*
sudo chown tc:staff /dev/dma_heap/*
export LIBCAMERA_LOG_LEVELS=0
libcamera-hello -n

Then I compared the logs. The logs were first very similar, but on piCore v14 I get this error:
[0:08:32.444569804] [1699] DEBUG DeviceEnumerator device_enumerator_udev.cpp:320 All dependencies for media device /dev/media1 found
[0:08:32.444826314] [1699] DEBUG DeviceEnumerator device_enumerator.cpp:252 Added device /dev/media1: bcm2835-isp
[0:08:32.445415116] [1699] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerRPi'
[0:08:32.445719543] [1699] DEBUG RPI raspberrypi.cpp:1163 Unable to acquire a Unicam instance
ERROR: *** no cameras available ***


While on piCore v13 I first get:
[0:04:48.718246712] [889] DEBUG DeviceEnumerator device_enumerator.cpp:252 Added device /dev/media0: unicam

Then:
[0:04:48.718126556] [889] DEBUG DeviceEnumerator device_enumerator_udev.cpp:320 All dependencies for media device /dev/media0 found
[0:04:48.718246712] [889] DEBUG DeviceEnumerator device_enumerator.cpp:252 Added device /dev/media0: unicam
[0:04:48.718732285] [889] DEBUG Camera camera_manager.cpp:149 Found registered pipeline handler 'PipelineHandlerRPi'
[0:04:48.718939004] [889] DEBUG DeviceEnumerator device_enumerator.cpp:312 Successful match for media device "unicam"
[0:04:48.719118379] [889] DEBUG DeviceEnumerator device_enumerator.cpp:312 Successful match for media device "bcm2835-isp"
[0:04:48.719868118] [889] DEBUG V4L2 v4l2_device.cpp:627 'imx219 10-0010': Control: Exposure (0x00980911)


So it seems as though on piCore v14 the software is unable to register unicam.
From what I gather it could be either kernel mismatch or some bad permission.
Im going to look into this tomorrow.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #4 on: July 13, 2024, 06:16:08 PM »
Hi segfault
I changed libtiff.tcz to libtiff5.tcz in libcamera-apps.tcz.dep.

Seems a little odd to me TC13 finds it on /dev/media0 but TC14 is
looking at /dev/media1.

I'm not up on piCore or cameras but could this be related:
https://github.com/raspberrypi/libcamera/issues/44

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #5 on: July 15, 2024, 04:56:12 AM »
Thank for the input Rich! 8)

I'm a JavaScript developer and not well versed in the intricacies of Linux, so there be dragons. Anyway since I don't know much about how Linux works, I created a delta between TC13 and TC14 and started to compare the two.

Studying the delta of dmesg logs, I noticed that something called imx219 was not showing up in TC14 while in TC13 it is ("imx219 10-0010: Consider updating driver imx219 to match on endpoints"). imx219 sees to be related to picamera. It also seems as though imx219 is dependent on i2c. While lsmod on TC14 does lists i2c, when I run cat /lib/modules/<piCore-version>/modules.dep and compared the two, there was a lot of i2c use on TC13, but in the kernel dep on TC14, i2c is barely mentioned.  There is only one mention of imx219 on both of the systems: kernel.tclocal/drivers/media/i2c/imx219.ko but while im219 depends on kernel.tclocal/drivers/media/v4l2-core/v4l2-fwnode.ko kernel on TC13, on TC14 it depends on v4l2-async.ko (a ko that does not exist on TC13).

i2c and v4l2-async seems to serve different purposes.

Adding to config.txt: dtoverlay=imx219, startx=1 doesn't fix the problem, so this is where I'm at right now:
Maybe i2c is not properly loaded or something on TC14, or maybe v4l2-async fails at registering the camera.

Will investigate further...

« Last Edit: July 15, 2024, 04:59:04 AM by segfault »

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #6 on: July 15, 2024, 05:49:53 AM »
On TC13 lsmod does list i2c-mux and i2c-mux-pinctrl-pinctrl along with imx219, but on TC14 it does not. I discovered a useful tool insmod with which I could load imx219 from the kernel.tclocal and then it shows up in lsmod also on TC14. But I don't find the i2c muxes folder on TC14 at all... maybe it was built into the kernel and just a red herring.

But I guess that perhaps it's noteworthy that imx219 doesn't show up on TC14, even though I got camera_auto_detect, start_x and dtoverlay=im219 in the config file, along with dtparam=i2c_arm=on.

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #7 on: July 15, 2024, 06:52:52 AM »
Issue reproduced on my RBP 4 Model B.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #8 on: July 15, 2024, 08:26:23 AM »
Hi segfault
Juanito said:
... Add the following to config.txt: to enable the camera:
Code: [Select]
camera_auto_detect=0
dtoverlay=imx219
...

You used:
Code: [Select]
camera_auto_detect=1See it works better with 0. There may be a driver related timing issue trying
to auto detect while booting.  libcamera should load any drivers it needs on
its own.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #9 on: July 15, 2024, 08:41:22 AM »
Hi segfault
... But I don't find the i2c muxes folder on TC14 at all ...
Maybe under:
Code: [Select]
/lib/modules/KERNEL/kernel/drivers/i2c/muxes/
Quote
... But I guess that perhaps it's noteworthy that imx219 doesn't show up on TC14, even though I got camera_auto_detect, start_x and dtoverlay=im219 in the config file, along with dtparam=i2c_arm=on.
You meant  imx219 , right?
« Last Edit: July 15, 2024, 09:11:18 AM by Rich »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #10 on: July 15, 2024, 09:17:56 AM »
Hi segfault
I just took a look in  modules-6.1.68-piCore-v7l.gz  and though the
i2c-mux*  drivers are listed in  modules.order , they don't seem to
appear anywhere else in  modules-6.1.68-piCore-v7l.gz.

They also don't appear to be listed in any extensions.

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #11 on: July 15, 2024, 10:00:35 AM »
Quote
... But I guess that perhaps it's noteworthy that imx219 doesn't show up on TC14, even though I got camera_auto_detect, start_x and dtoverlay=im219 in the config file, along with dtparam=i2c_arm=on.
You meant  imx219 , right?

Yes, this was a typo in my forum post.

Code: [Select]
camera_auto_detect=1See it works better with 0. There may be a driver related timing issue....

I've tried with 1 and with 0, and tried different combinations with start_x=1 along with camera_auto_detect=1 and 0, and specifying the dtoverlay and not specyfying it too. Nothing seems to work on TC14, while TC13 different kind of combinations works.

Hi segfault
I just took a look in  modules-6.1.68-piCore-v7l.gz  and though the
i2c-mux*  drivers are listed in  modules.order , they don't seem to
appear anywhere else in  modules-6.1.68-piCore-v7l.gz.
They also don't appear to be listed in any extensions.

Just just learned how to do find -L /lib -name "*mux*" and also tried to find "*pin*" but on TC14 there is only one hit: video-mux.ko. However I'm beginning to think that it might be a red herring this thing with i2c, because after I learned how to check kernel dependencies, I noticed that the imx219.ko don't have a dep to i2c_mux_pinctrl.

I took at look at the link you posted previously related to "no camera detected" when running libcamera-hello, but I'm not sure if it is related. From what I gather tinycore works like this: the config.txt is being parsed, the computer encounters dtoveraly or camera_auto_detect and tries to register the camera, but for some reason it fails. Thus the camera is never even registered in the system, when libcamera-hello is run.

I've tried googling to find what code is parsing camera_auto_detect, so that I can track the progress from there. Maybe its even possible to follow the stack trace or something, but I've not been able to find the code.

All of these is way beyond my "comfort zone", so I'm pretty much at a loss here.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11594
Re: libcamera
« Reply #12 on: July 15, 2024, 10:38:28 AM »
Hi segfault
... I noticed that the imx219.ko don't have a dep to i2c_mux_pinctrl. ...
That may be, but it's possible something in  libcamera  or  libcamera-apps  does.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1243
Re: libcamera
« Reply #13 on: July 15, 2024, 10:45:54 AM »
I would try out the piCore15 beta.  See if that makes any difference.

Offline segfault

  • Newbie
  • *
  • Posts: 27
Re: libcamera
« Reply #14 on: July 15, 2024, 02:57:22 PM »
That may be, but it's possible something in  libcamera  or  libcamera-apps  does.

Right I hear you! Inspired by someone who also tried to get a camera working (https://forum.tinycorelinux.net/index.php/topic,26713.0.html) I took a peak in: http://tinycorelinux.net/14.x/armv7/releases/RPi/src/kernel/modules-6.1.68-piCore-v7.tar.xz and it turns out that the ic2/muxes folder exists there:
kernel/drivers/i2c/muxes/i2c-mux-pca954x.ko [i2c-mux-pinctrl.ko, etc]
I tried copying it to TC14 and tried loading is using sudo insmod but got invalid module format.

I would try out the piCore15 beta.  See if that makes any difference.

Yes, good idea! I'll so that ASAP. Cheers.