CHDK PTP interface - page 117 - General Discussion and Assistance - CHDK Forum

CHDK PTP interface

  • 1220 Replies
  • 255117 Views
*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1160 on: 26 / March / 2019, 14:33:47 »
Advertisements
Turns out we spent quite a bit of time digging around the same areas in 2012 (:o) for the original  NULL packet / length bug, discussed starting around https://chdk.setepontos.com/index.php?topic=4338.msg87093#msg87093

When I have a bit more time I'll poke around to see which of the several cases in recv_data that can return 1 is failing.

edit:
In fact, I even saw the d10 failure after we fixed the original problem, but didn't realize that it was reproducible at that length.
« Last Edit: 26 / March / 2019, 15:21:45 by reyalp »
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1161 on: 05 / April / 2019, 02:17:30 »
A bit more:
When the problem happens, recv_data itself takes a long time (~5 sec) to complete, so presumably it's waiting for something that times out. This isn't surprising since the actual communication is done in other tasks.

I confirmed that forcing the camera to do recv_data in chunks smaller than the problem size avoids the problem. Doing one read that isn't a 512 multiple first and then trying to do all the rest still fails.

Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1162 on: 14 / April / 2019, 18:44:03 »
I confirmed that forcing the camera to do recv_data in chunks smaller than the problem size avoids the problem.
I was about to check in a workaround based on this, but it turns out it only delays the problem to 0x45f4  >:(

edit:
One thing I'd like to test is whether the stock Canon code suffers the same issue. If so, then at least we know it's a Canon firmware bug, and if not, maybe there would be clues how they avoid it.

Standard PTP commands I found that send data are
SendObjectInfo
SendObject
SetDevicePropValue

Of these, SendObject seems the most likely to allow a problem size file, but it requires a SendObjectInfo first and seems complicated to set up. The original ptpcam code for SendObject and SendObjectInfo, but didn't implement code to actually use them. The Canon code does appear to implement them.
« Last Edit: 15 / April / 2019, 00:25:36 by reyalp »
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1163 on: 16 / April / 2019, 00:54:40 »
gphoto2 supports upload, so I thought I could get the problem size by padding the exif description of a 640x480 camera jpeg. Unfortunately, attempting to upload an unmodified jpeg from the camera fails with "Invalid Object Format Code"

This happens in response to the SendObjectInfo operation, so doesn't have anything to do with the content on the file.

When gphoto2 encounters an error, it suggests a command to provide a debug log, like

Code: [Select]
env LANG=C gphoto2 --debug --debug-logfile=my-logfile.txt ...
which produce a very nice log of device info, supported operations and each PTP operation used.

Based the fact that SendObjectInfo and SendObject are listed as supported and the amount of code associated with the handlers, I don't think it's just stubbed out in the Canon firmware, but maybe there's some details in the SendObjectInfo that need to be set a particular way.


Don't forget what the H stands for.


*

Offline srsa_4c

  • ******
  • 3952
Re: CHDK PTP interface
« Reply #1164 on: 16 / April / 2019, 13:27:08 »
gphoto2 supports upload, so I thought I could get the problem size by padding the exif description of a 640x480 camera jpeg. Unfortunately, attempting to upload an unmodified jpeg from the camera fails with "Invalid Object Format Code"
File upload with gphoto used to work on old cameras. Back in the days, I successfully used it on my first PowerShot (A200). I tested it on my s3is now, with success (card root was not accepted, but one of the image dirs worked). Same thing doesn't work on a more recent cam (g10).

I have no experience with the Windows built-in ptp/mtp support or Canon's utilities, does upload work with them?

The 0x100c handler can be found by looking up references to add_ptp_handler, the 0x100c one is located in a table.

*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1165 on: 16 / April / 2019, 23:33:46 »
I have no experience with the Windows built-in ptp/mtp support or Canon's utilities, does upload work with them?
Not windows 10 built in at least, haven't tried Canon yet.

Quote
The 0x100c handler can be found by looking up references to add_ptp_handler, the 0x100c one is located in a table.
Yeah, looking at those was part of reason I thought it wasn't just disabled, since it's fairly complicated. But maybe it's dead code.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3952
Re: CHDK PTP interface
« Reply #1166 on: 17 / April / 2019, 13:15:28 »
Yeah, looking at those was part of reason I thought it wasn't just disabled, since it's fairly complicated. But maybe it's dead code.
Found the following in it (using ghidra's decompiler).
Code: [Select]
      if (local_c0 == 0x3002) {
        uVar5 = (uint)local_c0;
        if (param_7 != -1) {
          uVar5 = local_9c;
        }
        if (param_7 == -1 || uVar5 == 0xffffffff) {
          local_ec[0] = 0x201a;
          goto LAB_ff8c3ce4;
        }
      }
      else {
        if (local_c0 != 0xbf01) {
          local_ec[0] = 0x200b;
          goto LAB_ff8c3ce4;
        }
      }
local_c0: seems to be the ptp object format code (this code is loaded in other local vars too, but those copies seem unreferenced)
The constants:
From libgphoto ptp.h
Code: [Select]
#define PTP_OFC_Script 0x3002

#define PTP_RC_InvalidObjectFormatCode  0x200B
#define PTP_RC_InvalidParentObject      0x201A
Google found 0xbf01 in our svn, tools/patches/libptp2-1.1.0-canon-upload.diff
Code: [Select]
+// ((int*)data)[1]=0xbf01; // canon firmwareSo, could it be that uploading firmware files is supported? The upload patch is from vitalyb and pre-dates DryOS cameras.

*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1167 on: 17 / April / 2019, 13:33:23 »
So, could it be that uploading firmware files is supported? The upload patch is from vitalyb and pre-dates DryOS cameras.
PS2 files are listed in PTP (even on windows), with type 0xbf01. I tried uploading with gphoto2 and windows, but it presumably doesn't set the type.

Interesting that "script" is another supported type...
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 12006
Re: CHDK PTP interface
« Reply #1168 on: 21 / April / 2019, 02:02:02 »
I added support in chdkptp r849 for the necessary operations to test upload.

On SX710, I can upload arbitrary files using the FI2 type. The actual file doesn't need to have an FI2 extension. The following works
Code: [Select]
!newfi2={ Filename="TEST.FI2", ObjectFormat=48897, ObjectCompressedSize=80448 }
!return con:ptp_send_object_info(newfi2)
=65537,0,262185
!con:ptp_send_object(('x'):rep(80448))
The 3 numbers are storage ID, parent handle and object handle, but we don't need them. SendObject just needs to send the size specified in the earlier SendObjectInfo.

The same sequence of commands on D10 crashes with ASSERT!! OpObjHdl.c Line 2645 in PTPSessionTA0, regardless of size  :-[

I initially tried modifying an object info of an existing FI2 return by GetObjectInfo, just setting the name and size. This also works on SX710, and fails on D10.

Using GetObjectHandles puts the camera into the black screen PTP mode. The GetStorage* and SendObject* do not.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3952
Re: CHDK PTP interface
« Reply #1169 on: 21 / April / 2019, 07:31:35 »
The same sequence of commands on D10 crashes with ASSERT!! OpObjHdl.c Line 2645 in PTPSessionTA0, regardless of size  :-[
I tested a few DryOS cameras (did not test file content).
sx100 (r23): test executed
a470 (newer r23): the ptp_send_object command failed with "ERROR: call failed:Transaction Canceled", no fi2 file created
ixus110, g10, ixus870 (r31): all cams crashed on ptp_send_object
a490 (r43), a3200 (r47), a3400 (r50), ixus150 (r54): test executed

 

Related Topics