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
  3/32 upgrade board, Arrived Without Firmware, Troubleshooting Steps to SOLVED biketool 0 444 06-22-2021, 10:03 AM
Last Post: biketool
  camera + megaixel and strange behavior streak 0 398 06-02-2021, 06:45 AM
Last Post: streak
  Pinephone camera thread ryo 9 2,483 05-29-2021, 03:21 AM
Last Post: ryo
  Camera clicking sound unsatisfactory212 2 659 05-07-2021, 02:57 PM
Last Post: megous
  Fail safe way to update ANX7688 firmware scholbert 24 7,236 04-01-2021, 01:28 PM
Last Post: zborgerd
  Strange SD Card Problems anhilde 7 1,346 02-21-2021, 07:52 AM
Last Post: Zebulon Walton
  New motherboard - ANX firmware won't flash. --- 17 3,693 12-26-2020, 01:53 PM
Last Post: p1x3l3d
  Main Board Swap: Camera connector problems tyha 5 1,710 11-19-2020, 06:25 PM
Last Post: pajux
  Camera with stange colors zykran 0 737 09-18-2020, 10:05 AM
Last Post: zykran
  camera question xinyiman 3 1,975 08-31-2020, 05:50 AM
Last Post: Veraendert

Forum Jump:


Users browsing this thread: 1 Guest(s)