ixus175_elph180_100c porting attempt - page 18 - DryOS Development - CHDK Forum

ixus175_elph180_100c porting attempt

  • 201 Replies
  • 111569 Views
*

Offline srsa_4c

  • ******
  • 4451
Re: ixus175_elph180_100c porting attempt
« Reply #170 on: 27 / May / 2018, 15:51:45 »
Advertisements
Regarding the dysfunctional FI2, I managed to find the culprit. A checksum in the FI2 file is computed differently in the newest cameras: it was sum of bytes previously, now it's sum of words. The routine with the calculation can be found right above the "FIRhandler.c" string (the string, not its reference) in fw - sub_FFBBA7A8 in 100a.

A possible way to handle the issue is in the patch below (using the M10 as example - it's also affected).
Code: [Select]
Index: Makefile
===================================================================
--- Makefile (revision 5018)
+++ Makefile (working copy)
@@ -97,7 +97,13 @@
     endif
 endif
 
+ifdef FI2FLAGS
+    FI2FLAG=-x $(FI2FLAGS)
+else
+    FI2FLAG=
+endif
 
+
 .PHONY: toolchaincheck
 toolchaincheck:
     ifdef THUMB_FW
@@ -127,7 +133,7 @@
  $(PAKWIF) $(FW_UPD_FILE) $(bin)/main.bin $(TARGET_PID) 0x01000101
         endif
         ifeq ($(PLATFORMOS),dryos)
- $(PAKFI2) $(bin)/main.bin -p $(TARGET_PID) -pv $(PLATFORMOSVER) -key $(FI2KEY) -iv $(FI2IV) $(FW_UPD_FILE)
+ $(PAKFI2) $(bin)/main.bin -p $(TARGET_PID) -pv $(PLATFORMOSVER) -key $(FI2KEY) -iv $(FI2IV) $(FI2FLAG) $(FW_UPD_FILE)
         endif
     endif
     ifdef NEED_ENCODED_DISKBOOT
Index: platform/m10/makefile.inc
===================================================================
--- platform/m10/makefile.inc (revision 5018)
+++ platform/m10/makefile.inc (working copy)
@@ -16,6 +16,9 @@
 # Found @
 KEYSYS=d4g
 
+# generated FI2 needs word-based checksum
+FI2FLAGS=W
+
 PLATFORMOSVER=57
 
 # mandatory for DIGIC 6
@@ -22,7 +25,7 @@
 MEMBASEADDR=0x8000
 
 # force FI2 off because of various issues
-override OPT_FI2=
+# override OPT_FI2=
 
 # next line is for the compatibility check, as comment
 # PLATFORMID @ 0xfff20270
Index: tools/packfi2/fi2enc.c
===================================================================
--- tools/packfi2/fi2enc.c (revision 5018)
+++ tools/packfi2/fi2enc.c (working copy)
@@ -11,7 +11,10 @@
 #include "aes128.h"
 
 static const char *g_str_err_malloc = "memory allocation error (requested %d bytes)\n";
-static const char *g_str_shorthelp = "Usage: fi2encdec [-p PID] [-key KEY -iv IV] in.file out.file\n";
+static const char *g_str_shorthelp = "Usage: fi2encdec [-p PID] [-key KEY -iv IV] [-x FLAGS] in.file out.file\n"
+                                     "    FLAGS: one or more of the following letters\n"
+                                     "           W: checksum is word based (on new models)\n"
+                                     "\n";
 
 char *_strlwr(char *moep) {
      char *tmp = moep;
@@ -111,7 +114,8 @@
     }
 }
 
-static int fi2enc( char *infname, char *outfname, uint32_t *key, uint32_t *iv , uint32_t pid, uint32_t dryos_ver)
+static int fi2enc( char *infname, char *outfname, uint32_t *key, uint32_t *iv , uint32_t pid, uint32_t dryos_ver,
+                   int32_t cs_words)
 {
  unsigned long i;
  size_t flen;
@@ -184,7 +188,14 @@
  // encrypt data block
  aes128_cbc_encrypt( buf, exkey, iv, fi2rec.len );
  pblk = buf;
- for( i = 0; i < (int)fi2rec.len; i++) cs += buf[i]; // update block checksum
+    if (cs_words) {
+        uint32_t *wbuf = (uint32_t*)buf;
+        for( i = 0; i < (int)fi2rec.len/4; i++) cs += wbuf[i]; // update block checksum
+    }
+    else {
+        for( i = 0; i < (int)fi2rec.len; i++) cs += buf[i]; // update block checksum
+    }
+
  free( upkbuf ); upkbuf = NULL;
  // process next block
  // finalize header
@@ -237,6 +248,8 @@
  char *fni = NULL, *fno = NULL;
  uint32_t pid=0;
     uint32_t dryos_ver=0;
+    char *flags = NULL;
+    int32_t cs_words = 0;
 
  // parse command line
  for( i = 1; i < argc; i++){
@@ -260,6 +273,9 @@
          dryos_ver = strtoul(argv[++i], &err, 0);
  if (*err) return -1;
  }
+ else if( !strcmp( "x", _strlwr(argv[i]+1) ) ){ // extra flags, single string without spaces
+         flags = argv[++i];
+ }
  else {
  printf("Unexpected option: %s\n", argv[i]);
  return -1;
@@ -277,8 +293,13 @@
  fputs( g_str_shorthelp, stdout );
  return -1;
  }
+    if (flags) {
+        if ( strstr(flags, "W") ) {
+            cs_words = 1;
+        }
+    }
  for( i = 0; i < 4; i ++ )  key[i] = read32_be( key+i );
-        i = fi2enc( fni, fno, key, iv , pid, dryos_ver);
+        i = fi2enc( fni, fno, key, iv , pid, dryos_ver, cs_words);
  if ( !i ) printf( "Done\n" ); else printf( "Failed!\n" );
  return i;
 }

*

Offline reyalp

  • ******
  • 14128
Re: ixus175_elph180_100c porting attempt
« Reply #171 on: 01 / June / 2018, 01:09:27 »
Regarding the dysfunctional FI2, I managed to find the culprit. A checksum in the FI2 file is computed differently in the newest cameras: it was sum of bytes previously, now it's sum of words. The routine with the calculation can be found right above the "FIRhandler.c" string (the string, not its reference) in fw - sub_FFBBA7A8 in 100a.

A possible way to handle the issue is in the patch below (using the M10 as example - it's also affected).
Thanks, verified and added in trunk 5019.

I added the w flag to M10 for documentation purposes, but left FI2 forced off, since I assume it still has the other normal digic 6 FI2 problems.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 4451
Re: ixus175_elph180_100c porting attempt
« Reply #172 on: 01 / June / 2018, 17:06:04 »
Thanks, verified and added in trunk 5019.
Thanks for checking that in. To explain my choice to add a generic switch to fi2enc rather than a specific one for the checksum: it's possible that other changes will be needed later. For example, some cameras around DryOS r54 use one 'unknown' word less in a header. If someone decided to port one of them, we'd need a new flag.

Quote
I added the w flag to M10 for documentation purposes, but left FI2 forced off, since I assume it still has the other normal digic 6 FI2 problems.
At the moment, yes, but that will likely change soon.

*

Offline reyalp

  • ******
  • 14128
Re: ixus175_elph180_100c porting attempt
« Reply #173 on: 02 / June / 2018, 19:29:58 »
I've enabled this ixus175_elph180 100c in the autobuild, it seems to be in pretty decent shape. Thanks @tsamma, @blackhole and @axman

notes.txt reflects what I've tested. The main things missing at the moment are filewrite and video control.

FI2 building is disabled pending confirmation the autobuild server has the correct keys.
Don't forget what the H stands for.

*

Offline blackhole

  • *****
  • 946
  • A590IS 101b
    • Planetary astrophotography
Re: ixus175_elph180_100c porting attempt
« Reply #174 on: 03 / June / 2018, 12:44:28 »
I've enabled this ixus175_elph180 100c in the autobuild, it seems to be in pretty decent shape.
It's nice to see it in the autobuild.  :)

Not related to this, we have two more cameras that are reported to work well, ixus170/elph170  and  sx610. Users have been using test builds for a long time, but there is no longer any response for a long time.
Maybe it's time to add these cameras to the trunk and skip the autobuild.

*

Offline reyalp

  • ******
  • 14128
Re: ixus175_elph180_100c porting attempt
« Reply #175 on: 03 / June / 2018, 19:20:29 »
I added filewrite / remoteshoot support in trunk 5024.

The filewrite code on this cam appears to be like g7x and sx710. This means it does not require CAM_FILEWRITETASK_SEEKS, and does not crash when switching to play after using remoteshoot.

Not related to this, we have two more cameras that are reported to work well, ixus170/elph170  and  sx610. Users have been using test builds for a long time, but there is no longer any response for a long time.
Maybe it's time to add these cameras to the trunk and skip the autobuild.
Thanks for the pointer. I agree, it would be good to have them in the official source.
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14128
Re: ixus175_elph180_100c porting attempt
« Reply #176 on: 04 / June / 2018, 01:55:03 »
Based on sigfinder output, firmware 100a and 100b should be able to use the same build as 100c (except for the compatibility check).

Here's a test build set to load on those firmwares for anyone who has those has them. Please report if it works. It almost certainly will.
Don't forget what the H stands for.

Re: ixus175_elph180_100c porting attempt
« Reply #177 on: 21 / June / 2018, 12:05:43 »
So I have a 180 running firmware version 1.00c and "disable lcd off" doesn't seem to be working, unless I'm just using it wrong. Screen goes black upon plugging in a USB.

Also I'm unable to use it with chdkptp. I have libusb installed and I can connect to it but none of the functions work.

*

Offline reyalp

  • ******
  • 14128
Re: ixus175_elph180_100c porting attempt
« Reply #178 on: 21 / June / 2018, 17:02:24 »
So I have a 180 running firmware version 1.00c and "disable lcd off" doesn't seem to be working, unless I'm just using it wrong. Screen goes black upon plugging in a USB.
If it goes black immediately when you plug in the USB, this has nothing to do with the "disable LCD off" option. It usually means something sent regular (non CHDK) PTP commands to the camera.
Quote
Also I'm unable to use it with chdkptp. I have libusb installed and I can connect to it but none of the functions work.
Do you see any messages in the console?
I assume you are using windows? Did you install libusb specifically for this camera using zadig?
Did you verify that CHDK is actually running when you connected?
Don't forget what the H stands for.

*

Offline koshy

  • *****
  • 1096
Re: ixus175_elph180_100c porting attempt
« Reply #179 on: 21 / June / 2018, 18:04:28 »
I assume you are using windows? Did you install libusb specifically for this camera using zadig?
Just in case it helps as I'm doing this a lot obviously.
I don't use zadig but rather the plain libUSB from https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/
In the /bin directory there is an "inf-wizard.exe", run that, select "Canon Digital Camera" after connecting the camera and having it powered on, create an inf file and choose to install that driver when prompted. If Windows complains choose to install anyway. After that the camera should no longer switch off, when plugged into USB. If you need more detail than that let me know.
Koshy had a little ELPH which wasn't white as snow but everywhere that Koshy went the ELPH was sure to go. (actually an SD, but that detail ruins the rhyme...)

 

Related Topics


SimplePortal © 2008-2014, SimplePortal