camera firmware problems
#11
(06-03-2021, 11:52 PM)wfk Wrote: Any updates?
Yes, I heard back from Martijn who told me that there are different autofocus firmwares out there and that it was a bit of trial and error to find one that worked for the PinePhone's sensor. So it's possible that slightly different sensors are used in different PinePhone's and some may expect a different firmware. So the next step would be finding and trying out other auto focus firmwares.
He also confirmed that this is not a timeout issue, the firmware should start within 10 ms.

(06-03-2021, 11:52 PM)dsimic Wrote: If you have time, maybe you could add some error checking there, recompile the kernel, and check the results?
I might have some time in the next days to get into this and also find and learn how to make available different firmwares since that's probably the most promising direction.
  Reply
#12
(06-06-2021, 12:08 AM)kqlnut Wrote: Yes, I heard back from Martijn who told me that there are different autofocus firmwares out there and that it was a bit of trial and error to find one that worked for the PinePhone's sensor. So it's possible that slightly different sensors are used in different PinePhone's and some may expect a different firmware. So the next step would be finding and trying out other auto focus firmwares.

He also confirmed that this is not a timeout issue, the firmware should start within 10 ms.

This is good to know.  Basically, now we know that the provided autofocus firmware image didn't come through an "official" channel and could be the culprit itself.

(06-06-2021, 12:08 AM)kqlnut Wrote:
(06-03-2021, 11:52 PM)dsimic Wrote: If you have time, maybe you could add some error checking there, recompile the kernel, and check the results?

I might have some time in the next days to get into this and also find and learn how to make available different firmwares since that's probably the most promising direction.

It's rather easy, just provide a different version of the ov5640_af.bin file in /lib/firmware.  By the way, below are a few useful links I've found while searching the web; some of them contain a version of the autofocus firmware image, and some suggest that the firmware can even be "patched" to alter its behavior:
  Reply
#13
(06-06-2021, 12:41 AM)dsimic Wrote: It's rather easy, just provide a different version of the ov5640_af.bin file in /lib/firmware.  By the way, below are a few useful links I've found while searching the web; some of them contain a version of the autofocus firmware image, and some suggest that the firmware can even be "patched" to alter its behavior:
Right, it didn't come from an official source. Thanks a lot for the links! Some of that I've also found and saved for later, but I've been spending time getting into the general background of firmwares and how to interface with devices first since this is a completely new and very interesting field to me and I want to understand what's happening Smile
That being said, to get to quicker results: Could you tell me what's the best way to go about converting those C arrays to proper firmware (.bin) files?
  Reply
#14
(06-06-2021, 01:01 AM)kqlnut Wrote: That being said, to get to quicker results: Could you tell me what's the best way to go about converting those C arrays to proper firmware (.bin) files?

One possible way is to write some semi-throwaway C code that converts the firmware data from arrays into files.  I already wrote the code that does the conversion, but I need to implement some additional checks (such as making sure that the firmware data is continuous) before making the code publicly available.
  Reply
#15
Hello, I created some bin-files from other ov5640.c or ov5640.h
Files. No success...
I disassemled ov5630_af.bin and let it thru a emulator to See what the 8051
Code will do. But no hints whats going wrong.
I suppose we need the source of ov5640_af.bin
Any other ideas?
  Reply
#16
(06-28-2021, 11:31 AM)wfk Wrote: Hello, I created some bin-files from other ov5640.c or ov5640.h
Files. No success...
I disassemled ov5630_af.bin and let it thru a emulator to See what  the 8051
Code will do. But no hints whats going wrong.
I suppose we need the source of ov5640_af.bin
Any other ideas?
Thanks a lot for trying that out! Unfortunately I have no other idea so far and no time at the moment to get deeper into this. Maybe it's possible to get the source code from the vendor directly?
  Reply
#17
My apologies for the delayed response.

(06-28-2021, 12:01 PM)kqlnut Wrote: Thanks a lot for trying that out! Unfortunately I have no other idea so far and no time at the moment to get deeper into this. Maybe it's possible to get the source code from the vendor directly?

Quite frankly, we'll never be able to get the source code of the autofocus firmware.  Making that happen would require an Act of Congress. Smile

I've created a semi-throwaway utility that converts the autofocus firmware image "dumps" contained in C header files into binary images expected by the Linux kernel's firmware loading subsystem.  I've already included a few image "dumps" (i.e., C header files) that are available in various source repositories on the Internet, and I've already converted those header files into binary images that are available as .bin files in the "firmware" directory in the repository.

Please note that the "firmware" directory also contains human-readable .regs files, which contain additional values for the registers that, according to the original C header files, should be configured at the same time when the autofocus firmware is loaded, before and/or after the actual loading.  Just have a look at the .regs files and all this will make much more sense.

As a side note, loading the firmware image into the OV5640 MCU should be performed using the i2c_transfer() function directly, instead of poking individual registers, but we can get back to that once we discover which firmware image needs to be used.
  Reply
#18
(07-07-2021, 07:25 PM)dsimic Wrote: I've created a semi-throwaway utility that converts the autofocus firmware image "dumps" contained in C header files into binary images expected by the Linux kernel's firmware loading subsystem.  I've already included a few image "dumps" (i.e., C header files) that are available in various source repositories on the Internet, and I've already converted those header files into binary images that are available as .bin files in the "firmware" directory in the repository.

Please note that the "firmware" directory also contains human-readable .regs files, which contain additional values for the registers that, according to the original C header files, should be configured at the same time when the autofocus firmware is loaded, before and/or after the actual loading.  Just have a look at the .regs files and all this will make much more sense.

As a side note, loading the firmware image into the OV5640 MCU should be performed using the i2c_transfer() function directly, instead of poking individual registers, but we can get back to that once we discover which firmware image needs to be used.
Thank you for that tool and all the work, greatly appreciated! I've tried all the firmware images you provided (by replacing the original af firmware in /lib/firmware), but unfortunately all of them failed to start. I haven't set any of the extra registers though because I don't know how to do that except for modifying the driver and rebuilding the kernel which I haven't had the time for (is there another way?). I will look for more firmware dumps too.
  Reply
#19
I am experiencing a similar issue. Here is the dmesg of my NixOS machine, which has Martijn's autofocus patch and firmware.

$ journalctl -k | grep ov56
Jul 18 16:21:15 nixos kernel: sun6i-csi 1cb0000.csi: creating ov5640 5-004c:0 -> sun6i-csi:0 link
Jul 18 16:23:21 nixos kernel: ov5640 5-004c: firmware upload success
Jul 18 16:23:21 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f, retrying...
Jul 18 16:23:21 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f
Jul 18 16:23:21 nixos kernel: ov5640 5-004c: ov5640_set_ctrl_focus: no autofocus firmware loaded
Jul 18 16:24:38 nixos kernel: ov5640 5-004c: firmware upload success
Jul 18 16:24:38 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f, retrying...
Jul 18 16:24:38 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f
Jul 18 16:24:38 nixos kernel: ov5640 5-004c: ov5640_set_ctrl_focus: no autofocus firmware loaded
Jul 18 16:24:42 nixos kernel: ov5640 5-004c: firmware upload success
Jul 18 16:24:42 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f, retrying...
Jul 18 16:24:42 nixos kernel: ov5640 5-004c: uploaded firmware didn't start, got to 0x7f
Jul 18 16:24:42 nixos kernel: ov5640 5-004c: ov5640_set_ctrl_focus: no autofocus firmware loaded

This did once work on this phone, but it has stopped working. I am unaware of any meaningful changes in my system since then.

I am running Megi Linux 5.13.

Each time I open Megapixels, I get new dmesg output starting with "firmware upload success" and ending with "ov5640_set_ctrl_focus: no autofocus firmware loaded".
  Reply
#20
I have a fix for the firmware loading, and will tidy it up for release.

For now, I have a workaround to enable autofocus (assuming you are on a distro with the autofocus patch, such as Arch or Postmarket):
* Open Megapixels
* Touch your screen.

This should trigger the firmware loading (check dmesg) and you should observe Megapixels doing continuous autofocus. Sometimes it might be update the autofocus. Position your autofocus in the middle of your display, and touch the screen to trigger a autofocus.
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  firmware udate Quectel EG25-G modem alwi 7 7,064 07-06-2022, 01:43 PM
Last Post: user641
  Need command to tell what modem firmware I am on. purpletiger 4 3,807 07-06-2022, 12:35 PM
Last Post: Zebulon Walton
  PostmarketOS Camera and ffmeg rafiki88 1 1,839 03-19-2022, 10:09 AM
Last Post: vap0rtranz
  Would another camera work in the PP? nelstomlinson 2 2,708 11-11-2021, 06:25 PM
Last Post: nelstomlinson
Sad Have I got a broken camera module? AKD251 2 2,727 11-07-2021, 11:12 AM
Last Post: beta-user
  3/32 upgrade board, Arrived Without Firmware, Troubleshooting Steps to SOLVED biketool 0 1,963 06-22-2021, 10:03 AM
Last Post: biketool
  camera + megaixel and strange behavior streak 0 1,919 06-02-2021, 06:45 AM
Last Post: streak
  Pinephone camera thread ryo 8 9,620 05-29-2021, 03:21 AM
Last Post: ryo
  Camera clicking sound unsatisfactory212 2 3,279 05-07-2021, 02:57 PM
Last Post: megous
  Fail safe way to update ANX7688 firmware scholbert 24 29,847 04-01-2021, 01:28 PM
Last Post: zborgerd

Forum Jump:


Users browsing this thread: 13 Guest(s)