A810 porting thread

  • 106 Replies
  • 15266 Views
*

Offline nafraf

  • *****
  • 1257
  • Publish
    A810 porting thread
    « on: 03 / August / 2012, 13:32:50 »
    Advertisements
    Hi, dumps of 100b and 100d are available at box.net/chdk repository.
    I have access to cameras with both firmware version, I'll start with 100b.

    Code: [Select]
    // Camera info:
    //   DRYOS R50 (DRYOS version 2.3, release #0050)
    //   Firmware Ver GM1.00B
    //   Canon PowerShot A810

    // Camera info:
    //   DRYOS R50 (DRYOS version 2.3, release #0050)
    //   Firmware Ver GM1.00D
    //   Canon PowerShot A810

    Tools used: chdkpt and arm-elf-gcc-4.6.0 for linux.

    LED ADDRESSES
    #define LED_GREEN      0xC0220120 //LED on the back of the camera

    During development, source code will be available at this svn repository.

    UPDATE
    2012/08/07 Version for test is available as attachment.
    2012/08/24 100b-prealpha-r4 and 100d-prealpha-r1 added. 
    2012/08/31 100b-alpha and 100d-alpha added. See details
    2012/09/22 Patch submitted.
    Obsolete attachments deleted
    * a810-100b-1.2.0-alpha.zip (625.53 kB - downloaded 17 times.)
    * a810-100d-1.2.0-alpha.zip (625.53 kB - downloaded 20 times.)
    « Last Edit: 22 / September / 2012, 11:31:50 by nafraf »

    *

    Offline nafraf

    • *****
    • 1257
  • Publish
    Re: A810 porting thread
    « Reply #1 on: 17 / August / 2012, 18:17:58 »
    Hi, games are a topic of debate, as waterwing cited.  But if menu games exists, there will be users trying to play. :) 

    In a800, a810, a2300 functions rand and srand are not identified automatically. Without that functions, some games freeze (sudoku, snake, mastermind).  I tried to find those function checking dissassembled code, but without success.

    So, I have some questions:
    Do you think that it's possible that those function were removed from some cameras?  Or do you have any suggestions of how to find them?

    I assumed that functions were removed, and took assembly code from SX260 for implementation:
    Code: [Select]
    int rand(void) {
    asm volatile (
          "LDR     R1, =0xDC2C \n"
          "LDR     R2, =0x41C64E6D \n"
          "LDR     R0, [R1] \n"
          "MUL     R0, R2, R0 \n"
          "ADD     R0, R0, #0x3000 \n"
          "ADD     R0, R0, #0x39 \n"
          "STR     R0, [R1] \n"
          "MVN     R1, #0x8000 \n"
          "AND     R0, R1, R0, LSR #0x10 \n"
          "BX      LR \n"
        );
    }
    rand() works, games works too, now the question is how to add it to the chdk source tree.

    I think that an option is to add weak attribute to rand definition in platform/generic/wrappers.c, and add the new definition of rand() to platform/CAMERA/lib.c. 
    Is it OK? or how should it be done?

    My first try was to add rand() to platform/CAMERA/wrappers.c but compilation fails.

    Code: [Select]
    lib.c -> lib.o
    wrappers.c -> wrappers.o
    wrappers.c:18:5: error: redefinition of 'rand'
    ../generic/wrappers.c:912:27: note: previous definition of 'rand' was here
    wrappers.c: In function 'rand':

    Thanks

    *

    Offline philmoz

    • *****
    • 2936
      • Photos
  • Publish
    Re: A810 porting thread
    « Reply #2 on: 17 / August / 2012, 18:38:07 »
    Define your custom versions as _rand and _srand - this is how the firmware functions get named and are called from the wrappers.

    Don't define them in stubs_entry_2.S and it should work.

    Phil.
    CHDK ports:
      sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
      g12 (1.00c, 1.00e, 1.00f & 1.00g)
      sx130is (1.01d & 1.01f)
      ixus310hs (1.00a & 1.01a)
      sx40hs (1.00d, 1.00g & 1.00i)
      g1x (1.00e, 1.00f & 1.00g)

    *

    Offline nafraf

    • *****
    • 1257
  • Publish
    Re: A810 porting thread
    « Reply #3 on: 18 / August / 2012, 09:51:41 »
    If I don't define rand in stubs_entry_2.S I got an error during stubs_entry generation
    Code: [Select]
    -> stubs_entry.S
    Time to generate stubs 17.16 seconds
    ERROR! There are unresolved addresses in 'stubs_entry.S' (a810-100b) for the following names:
    rand
    Please, add them into 'stubs_entry_2.S' manually!

    I tried putting _rand function code in platform/a810/lib.c, platform/a810/sub/100b/lib.c and platform/a810/sub/100b/wrappers.c. Nothing of those with success.

    Am I missing something?  Thanks



    *

    Offline philmoz

    • *****
    • 2936
      • Photos
  • Publish
    Re: A810 porting thread
    « Reply #4 on: 18 / August / 2012, 20:25:08 »
    If I don't define rand in stubs_entry_2.S I got an error during stubs_entry generation
    Code: [Select]
    -> stubs_entry.S
    Time to generate stubs 17.16 seconds
    ERROR! There are unresolved addresses in 'stubs_entry.S' (a810-100b) for the following names:
    rand
    Please, add them into 'stubs_entry_2.S' manually!

    I tried putting _rand function code in platform/a810/lib.c, platform/a810/sub/100b/lib.c and platform/a810/sub/100b/wrappers.c. Nothing of those with success.

    Am I missing something?  Thanks


    Sorry, forgot about the error check in the build for stubs_entry.S / stubs_entry_2.S.

    Not at a build PC right now so I can't test this; but you can try adding rand and srand to stubs_entry_2.S using the NSTUB macro rather than NHSTUB (set them to a NULL_SUB entry in the firmware).

    Then add your functions to your a810/lib.c file as _rand and _srand.

    NSTUB generates an overridable function so the versions in a810/lib.c should get picked up without generating any link errors.

    You can add a display of output from rand to make sure your function is getting called.

    Phil.
    CHDK ports:
      sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
      g12 (1.00c, 1.00e, 1.00f & 1.00g)
      sx130is (1.01d & 1.01f)
      ixus310hs (1.00a & 1.01a)
      sx40hs (1.00d, 1.00g & 1.00i)
      g1x (1.00e, 1.00f & 1.00g)

    *

    Offline nafraf

    • *****
    • 1257
  • Publish
    Re: A810 porting thread
    « Reply #5 on: 18 / August / 2012, 22:17:30 »
    Thanks, now games are working.

    *

    Offline srsa_4c

    • ******
    • 3135
  • Publish
    Re: A810 porting thread
    « Reply #6 on: 19 / August / 2012, 00:11:21 »
    I assumed that functions were removed, and took assembly code from SX260 for implementation:
    Code: [Select]
    int rand(void) {
    asm volatile (
          "LDR     R1, =0xDC2C \n"
          "LDR     R2, =0x41C64E6D \n"
          "LDR     R0, [R1] \n"
          "MUL     R0, R2, R0 \n"
          "ADD     R0, R0, #0x3000 \n"
          "ADD     R0, R0, #0x39 \n"
          "STR     R0, [R1] \n"
          "MVN     R1, #0x8000 \n"
          "AND     R0, R1, R0, LSR #0x10 \n"
          "BX      LR \n"
        );
    }
    You're currently using this routine almost unchanged. There's a RAM address in it, 0xDC2C, which is camera specific. I'd change that to something which doesn't corrupt an unknown word in RAM  ;)
    Declare and use a static "int" variable instead.

    Or... http://xkcd.com/221/  :D
    « Last Edit: 19 / August / 2012, 00:15:55 by srsa_4c »

    *

    Offline nafraf

    • *****
    • 1257
  • Publish
    Re: A810 porting thread
    « Reply #7 on: 19 / August / 2012, 13:30:12 »
    srsa_4c, thanks for check the code.

    This is a new version, without corrupting RAM data... I hope so :)
    Code: [Select]
    static unsigned int random_variable;
    void *_srand(unsigned int seed) {
        random_variable = seed;
        return (void *) &random_variable;
    }

    int _rand(void) {
        int value;
        void * ptr = (void*) (&random_variable);

        asm volatile (
          "LDR     R1, %[input] \n"
          "LDR     R2, =0x41C64E6D \n"
          "LDR     R0, [R1] \n"
          "MUL     R0, R2, R0 \n"
          "ADD     R0, R0, #0x3000 \n"
          "ADD     R0, R0, #0x39 \n"
          "STR     R0, [R1] \n"
          "MVN     R1, #0x8000 \n"
          "AND     %[result], R1, R0, LSR #0x10 \n"
          : [result]"=r"   (value)
          : [input]"m"  (ptr)
          : /*No clobbers*/
        );
        return value;
    };


  • Publish
    Re: A810 porting thread
    « Reply #8 on: 21 / August / 2012, 05:54:57 »
    can someone compile a 100d full working build? Thanks
    « Last Edit: 21 / August / 2012, 07:51:46 by marck.smith.33 »

    *

    Offline nafraf

    • *****
    • 1257
  • Publish
    Re: A810 porting thread
    « Reply #9 on: 24 / August / 2012, 20:49:52 »
    a810 is under development, 100d is in earlier version than 100b.   But if you want to test, the last version was added to first post of this thread.

    A new version for 100b (prealpha-r4) was added too.
    Games are working, RAW is working, movie_rec.c is not fully ported.
    « Last Edit: 24 / August / 2012, 21:09:53 by nafraf »

     

    Related Topics