WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: PiCore 14.1 Pi0W ZeroCam  (Read 2129 times)

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
PiCore 14.1 Pi0W ZeroCam
« on: January 21, 2024, 04:20:22 AM »
Hi,

I have a Pi Zero W V1.1 and a ZeroCam NoIR.

I believe the ZerCam uses the 5Mpixel OV5647 camera as used in the official RPi V1 camera. With that in mind the end of my config.txt looks like this (the rest is as supplied in piCore 14.1):

Code: [Select]
[all]
dtoverlay=ov5647
start_x=1
gpu_mem=128

Actually I've tried various things in config.txt including removing the ov5647 overlay which didn't seem necessary in other forum posts.

I have libcamera.tcz and libcamera-apps.tcz installed and have added the following as per libcarea.tcz.info

Code: [Select]
tc@box:~$ sudo chown tc:staff /dev/media*
tc@box:~$ sudo chown tc:staff /dev/dma_heap/*
tc@box:~$ ls -l /dev/media*
crw-------    1 tc       staff     242,   0 Jan  1  1970 /dev/media0
crw-------    1 tc       staff     242,   1 Jan  1  1970 /dev/media1
crw-------    1 tc       staff     242,   2 Jan  1  1970 /dev/media2

I get the following with libcamera-hello:

Code: [Select]
tc@box:~$ libcamera-hello -n
[0:04:00.730156000] [1669]  INFO Camera camera_manager.cpp:293 libcamera v0.0.1+1-f4201e96
ERROR: *** no cameras available ***

I don't know that the ZeroCam works with other OSes, soon as I can get my hands on another sd card I'll test that. Meanwhile...any clues?

Cheers

Online patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 680
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #1 on: January 21, 2024, 06:46:56 AM »
I suggest you should start with Raspberry Pi OS, and get it working, with your camera.

And then you should try to get all info how to get it working, like what kernel modules was loaded and so on.
And what config.txt contains.

Then you could try to implement the same concept to picore.


Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #2 on: January 21, 2024, 02:17:39 PM »
Found an SD card. Brilliant. Good news is that the camera works with the latest raspberry pi lite os.

Here's the output of libcamera-hello on the Raspberry Pi OS:

Code: [Select]
pi@test:~ $ libcamera-hello -n
[0:38:34.309563252] [1281]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+118-563cd78e
[0:38:34.580764632] [1286]  WARN RPiSdn sdn.cpp:39 Using legacy SDN tuning - please consider moving SDN inside rpi.denoise
[0:38:34.603822834] [1286]  INFO RPI vc4.cpp:444 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media1
[0:38:34.606098854] [1286]  INFO RPI pipeline_base.cpp:1142 Using configuration file '/usr/share/libcamera/pipeline/rpi/vc4/rpi_apps.yaml'
Mode selection for 1296:972:12:P
    SGBRG10_CSI2P,640x480/0 - Score: 3296
    SGBRG10_CSI2P,1296x972/0 - Score: 1000
    SGBRG10_CSI2P,1920x1080/0 - Score: 1349.67
    SGBRG10_CSI2P,2592x1944/0 - Score: 1567
Stream configuration adjusted
[0:38:34.638816142] [1281]  INFO Camera camera.cpp:1183 configuring streams: (0) 1296x972-YUV420 (1) 1296x972-SGBRG10_CSI2P
[0:38:34.643148180] [1286]  INFO RPI vc4.cpp:608 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAA


And here's the config.txt:

Code: [Select]
# For more options and information see
# http://rptl.io/configtxt
# Some settings may impact device functionality. See link above for details

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Additional overlays and parameters are documented
# /boot/firmware/overlays/README

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Automatically load initramfs files, if found
auto_initramfs=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Don't have the firmware create an initial video= setting in cmdline.txt.
# Use the kernel's default instead.
disable_fw_kms_setup=1

# Disable compensation for displays with overscan
disable_overscan=1

# Run as fast as firmware / board allows
arm_boost=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

So I've added the following (and only the following - everything else as default) to the bottom of my config.txt since it seemed relevant

Code: [Select]
camera_auto_detect=1
dtoverlay=vc4-kms-v3d

But no improvement, output of libcamera-hello in piCore is still as per the original post.

I also notice that libcamera is v0.1.0 in rpios and 0.0.1 in piCore.

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #3 on: January 22, 2024, 05:16:42 AM »
More to add.

In rpiOS the ov5647 module is loaded, in piCore it is not. I manually add the module with modprobe but the result is unchanged.

I notice the debug output from the working libcamera-hello on RPiOS mentions i2c and furthermore I see these i2c modules loaded with lsmod:

Code: [Select]
i2c_mux_pinctrl         3610  0
i2c_mux                 6207  1 i2c_mux_pinctrl

If I try to load modules by those names in piCore I get a not found in modules.dep error and I don't see those modules where I would expect them.

If I download and untar http://tinycorelinux.net/14.x/armv6/releases/RPi/src/kernel/modules-6.1.68-piCore.tar.xz I see the following:

Code: [Select]
ls -R modules-6.1.68-piCore/lib/modules/6.1.68-piCore/kernel/drivers/i2c/
modules-6.1.68-piCore/lib/modules/6.1.68-piCore/kernel/drivers/i2c/:
algos  busses  i2c-dev.ko  i2c-mux.ko  muxes

modules-6.1.68-piCore/lib/modules/6.1.68-piCore/kernel/drivers/i2c/algos:
i2c-algo-bit.ko

modules-6.1.68-piCore/lib/modules/6.1.68-piCore/kernel/drivers/i2c/busses:
i2c-bcm2708.ko i2c-gpio.ko        i2c-tiny-usb.ko
i2c-bcm2835.ko i2c-robotfuzz-osif.ko

modules-6.1.68-piCore/lib/modules/6.1.68-piCore/kernel/drivers/i2c/muxes:
i2c-mux-gpmux.ko  i2c-mux-pca954x.ko  i2c-mux-pinctrl.ko

But if I list the modules on the installed piCore system I cannot see the i2c-mux stuff:

Code: [Select]
ls -R /lib/modules/6.1.68-piCore/kernel/drivers/i2c/
/lib/modules/6.1.68-piCore/kernel/drivers/i2c/:
algos/         busses/        i2c-dev.ko.gz

/lib/modules/6.1.68-piCore/kernel/drivers/i2c/algos:
i2c-algo-bit.ko.gz

/lib/modules/6.1.68-piCore/kernel/drivers/i2c/busses:
i2c-bcm2708.ko.gz  i2c-bcm2835.ko.gz  i2c-gpio.ko.gz

Is there a reason why I should not expect the modules in an installed system to be the complete set as per the modules in the source?

Incidentally, is any way to find out exactly what happens when using the camera_auto_detect=1 option in config.txt (I realise this is a more general RPi question rather than a tinyCore one but Google hasn't sorted me out)? I presume a script runs to identify the camera and work out which overlays to load but how? What is it and can I see the source?

Thanks

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11282
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #4 on: January 22, 2024, 06:58:06 AM »
Hi mistakenot...
If you wish to package any of the kernel modules into an
extension yourself, you should be able to use this example
as a guide:
https://forum.tinycorelinux.net/index.php/topic,20195.msg154211.html#msg154211

Online patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 680
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #5 on: January 22, 2024, 10:54:44 AM »
First thank you for testing your camera on the working environment(raspios), so we know that camera is supported on the hardware and so on.

With your question regarding the config.txt file you can read about it on this place.
https://www.raspberrypi.com/documentation/computers/config_txt.html#camera_auto_detect

Code: [Select]
# Automatically load overlays for detected cameras
camera_auto_detect=1

And if you scroll in your file you can also see that this has already being set.

And reading about camera in this url location they talking about camera firmware, you may looking in the dmesg log to see maybe some more info when the module is loading in in the kernel, of course in raspios.
So try to execute.
Code: [Select]
sudo dmesg

Or maybe if that return to many lines you may try to grep on some keywords like camera and so on.
Code: [Select]
sudo dmesg | grep camera
And when we also talking about the device tree, that are set via config.txt file, and some options are also set via kernel command line via the boot code, so you can also take that info, stored in proc.
So you can take this info via this command.

Code: [Select]
cat /proc/cmdline
« Last Edit: January 22, 2024, 11:02:41 AM by patrikg »

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #6 on: January 22, 2024, 11:52:12 AM »
I've made some progress.

I extracted some relevant i2c modules from modules-6.1.68-piCore.tar.xz and added them:

Code: [Select]
sudo depmod
sudo modprobe i2c-mux
sudo modprobe i2c-mux-pinctrl

And it works!

My bottom of my config.txt file looks like this at the moment:

Code: [Select]
dtoverlay=i2c-mux
dtoverlay=ov5647
dtoverlay=vc4-kms-v3d

But maybe it will now work with camera_auto_detect=1? More experiments, back in a bit...

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #7 on: January 22, 2024, 12:43:40 PM »
Working after these commands

Code: [Select]
tc@box:~$ sudo cp /mnt/mmcblk0p2/tce/lib/modules/6.1.68-piCore/kernel/drivers/i2c/i2c-mux.ko /lib/modules/6.1.68-piCore/kernel/drivers/i2c/
tc@box:~$ sudo mkdir /lib/modules/6.1.68-piCore/kernel/drivers/i2c/muxes
tc@box:~$ sudo cp /mnt/mmcblk0p2/tce/lib/modules/6.1.68-piCore/kernel/drivers/i2c/muxes/i2c-mux-pinctrl.ko  /lib/modules/6.1.68-piCore/kernel/drivers/i2c/muxes/
tc@box:~$ sudo depmod
tc@box:~$ sudo modprobe i2c-mux
tc@box:~$ sudo modprobe i2c-mux-pinctrl
tc@box:~$ sudo chown tc:staff /dev/media*
tc@box:~$ sudo chown tc:staff /dev/dma_heap/*
tc@box:~$ libcamera-hello
Made DRM preview window
[0:02:42.322427000] [1772]  INFO Camera camera_manager.cpp:293 libcamera v0.0.1+1-f4201e96
[0:02:42.550616000] [1773]  INFO RPI raspberrypi.cpp:1377 Registered camera /base/soc/i2c0mux/i2c@1/ov5647@36 to Unicam device /dev/media3 and ISP device /dev/media0
[0:02:42.558512000] [1772]  INFO Camera camera.cpp:1026 configuring streams: (0) 1296x972-YUV420
[0:02:42.564587000] [1773]  INFO RPI raspberrypi.cpp:764 Sensor: /base/soc/i2c0mux/i2c@1/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected unicam format: 1296x972-pGAA

and this config.txt:

Code: [Select]
camera_auto_detect=1
dtoverlay=vc4-kms-v3d

Thanks for the help so far gang. Now to get those modules into an extension...

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #8 on: January 30, 2024, 04:57:44 AM »
Last issue I hope:

As per comments in http://tinycorelinux.net/14.x/armv6/tcz/libcamera.tcz.info by juanito

Quote
Comments:       camera support library
                ----------
                for the moment, after loading:
                sudo chown tc:staff /dev/media*
                sudo chown tc:staff /dev/dma_heap/*
                can optionally use gst-plugins-base

I set the ownership and it works. But I want that to happen at boot time. If I put the chown commands in bootlocal.sh it doesn't work. How do I set ownership of devices automatically at boot?

Cheers

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11282
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #9 on: January 30, 2024, 06:57:10 AM »
Hi mistakenot...
... If I put the chown commands in bootlocal.sh it doesn't work. ...
Maybe the devices don't exist yet?
Here is an example of how to test for that:
https://forum.tinycorelinux.net/index.php/topic,26667.msg171934.html#msg171934

Do you have  libcamera.tcz  listed in your  onboot.lst  file.
It probably creates those devices.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14620
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #10 on: January 30, 2024, 09:15:04 AM »
Quote
Comments:       camera support library
                ----------
                for the moment, after loading:
                sudo chown tc:staff /dev/media*
                sudo chown tc:staff /dev/dma_heap/*
                can optionally use gst-plugins-base

I thought this had been fixed in the piCore udev rules - perhaps only in piCore64?

Online Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1099
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #11 on: January 30, 2024, 12:54:54 PM »
dma-heap is in 99-com rules
media is in 50-udev-default-rules

https://github.com/tinycorelinux/Core-scripts/blob/d5b60ea6b708e3b4ec2ac4b1a961ec7dce667395/etc/udev/rules.d/50-udev-default.rules#L49

but media only sets the guid bit.  It does not change the file mode, so perhaps the newer kernel is only setting the file mode to 600

Offline mistakenot...

  • Newbie
  • *
  • Posts: 7
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #12 on: February 01, 2024, 02:24:44 PM »
Maybe the devices don't exist yet?

Spot on Rich. I added this dirty fix to make bootlocal.sh wait for the devices to appear:
Code: [Select]
while [ ! -c /dev/media3 ]
do
  sleep .5
done

The very slight delay of about 2 to 3 seconds is acceptable for my purpose.

Thanks  ;D

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11282
Re: PiCore 14.1 Pi0W ZeroCam
« Reply #13 on: February 01, 2024, 02:48:46 PM »
Hi mistakenot...
There's nothing wrong with your fix. You can however
push that delay into the background if you wish.

Place this in a separate file,  /opt/FixCam.sh  for example:
Code: [Select]
#!/bin/sh

while [ ! -c /dev/media3 ]
do
  sleep .5
done

sudo chown tc:staff /dev/media*
sudo chown tc:staff /dev/dma_heap/*

Then call it from  bootlocal.sh  like this:
Code: [Select]
/opt/FixCam.sh &That will run in the background while bootlocal continues
and your desktop loads.