A580 porting - minor progress

  • 125 Replies
  • 26033 Views
*

Offline ag8

  • *
  • 4
  • Publish
    A580 porting - minor progress
    « on: 07 / January / 2009, 04:50:03 »
    Advertisements
    Hello,

    I have an A580-100c and interested in porting CHDK.
    I have little asm experience, and would appriciate any advice you can give.

    This is what I've got so far:
    1. setup a build environment (on linux)
    2. got the firmware from http://chdk.wikia.com/wiki/A580
    3. created 'A580' platform+loader sub-trees based on A590 (which I think is the closest model).

    Some results:
    1.
    I followed the instructions from http://chdk.setepontos.com/index.php/topic,1132.msg10255.html#msg10255 including removal of card while camera is on - the camera resumed normal operation.

    2.
    Un-commented the debug-led blinking in loader/a580/resetcode/main.c:
    The led indeed blinks.

    3.
    The MEMIOSSTART value is probably 0xA47E0,
    Based on the instructions here:
    http://chdk.setepontos.com/index.php/topic,1132.msg10317.html#msg10317
    The value 0xA47E0 is found at offset 0x12378 in the PRIMARY.BIN file.

    4.
    Added led-blinking code to platform/a580/sub/100c/boot.c in boot():
    No blink. camera hangs.

    -----------------

    So I'm guessing the boot loader works, but not much else.

    I'd appriciate any pointers / suggestions on how to continue.

    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: A580 porting - minor progress
    « Reply #1 on: 07 / January / 2009, 14:51:59 »
    Hello,

    I have an A580-100c and interested in porting CHDK.
    I have little asm experience, and would appriciate any advice you can give.

    This is what I've got so far:
    1. setup a build environment (on linux)
    2. got the firmware from http://chdk.wikia.com/wiki/A580
    3. created 'A580' platform+loader sub-trees based on A590 (which I think is the closest model).
    Just a warning: The A590 port was largely done by people new to CHDK, and has had a LOT of problems. While it may well be the closest model, I'd suggest it isn't a great starting point. You may be better off starting with a more mature port (perhaps the a720, which is also the reference dryos firmware).
    Don't forget what the H stands for.

  • Publish
    Re: A580 porting - minor progress
    « Reply #2 on: 09 / January / 2009, 10:54:45 »
    Depending on the spare time I have, I think I'm going to try to do some porting, but unlike the original poster my camera is 101b.
    The only problem is that it's years since I've done any C programming and I hated it at that time. I'm mostly programming in VB6 and PHP/ASP/JS.

    I was thinking of using the same A590is base and wanted to ask you guys if there is any chance I could permanently damage the camera experimenting with chdk? I shouldn't be able to, right?


    *

    Offline chr

    • ***
    • 138
    • IXUS 82 IS
  • Publish
    Re: A580 porting - minor progress
    « Reply #3 on: 09 / January / 2009, 12:58:23 »
    I was thinking of using the same A590is base and wanted to ask you guys if there is any chance I could permanently damage the camera experimenting with chdk? I shouldn't be able to, right?

    to be honest: u can! While porting my cam, I found a way to engage Lens mechanic via scripts (or simply using manual focus!) in play mode while lens was not out! This should be fixed but these checks only work if u found the "Lens busy/ready" state! (see stubs_min.S)

    Also I always booted the cam in play mode for two reasons:

    * I guess it's worse if the cam crashes while booting and while it's tracking out the lens.

    * The lens may hit your hand if u power on in REC mode! ;)




    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: A580 porting - minor progress
    « Reply #4 on: 09 / January / 2009, 18:29:38 »
    Depending on the spare time I have, I think I'm going to try to do some porting, but unlike the original poster my camera is 101b.
    You should definitely coordinate/share code with ag8, since the difference between sub-versions of the same camera are fairly minor. Typically the code and hardware addresses are the same, while constants and addresses of functions and variables are different.
    Quote
    The only problem is that it's years since I've done any C programming and I hated it at that time. I'm mostly programming in VB6 and PHP/ASP/JS.
    If you don't know assembler, or struggled with pointers, you will have a challenge ahead. Note that it's not essential you know ARM assembler: if you are fluent in some other flavor, you can easily pick up the ARM specifics from the reference manuals.
    Quote
    I was thinking of using the same A590is base and wanted to ask you guys if there is any chance I could permanently damage the camera experimenting with chdk? I shouldn't be able to, right?
    It's fairly unlikely, but as chr says, it is possible. As far as we know, no one has yet destroyed a camera this way, although more than a few have got scary noises ;)
    Don't forget what the H stands for.

    *

    Offline ag8

    • *
    • 4
  • Publish
    Re: A580 porting - minor progress
    « Reply #5 on: 10 / January / 2009, 05:01:25 »
    Hello,

    I've re-created the a580 loader/platform tree based on a720, but didn't get better results.

    Here's what I've got so far;
    1. the value for The MEMIOSSTART (0xA47E0) also appears in the begining of the PRIMARY.BIN file (offset 0x194) and is used in a loop which writes zeros (BSS initialization?).

    I don't have IDA, and my ARM assembly skills as severely lacking, but here's what I gathered from the PRIMARY.BIN file.
    If somebody can comment on that, it'll be helpful:
    The loop code starts at offset 0x130.
    First, a loop copies data from 0xffebfb4c (ROM?) to 0x1900 -> 0xD700.
    Then, a second loop zeros data from 0xD700 -> 0xA47E0.

    2. The boot loader part ( copy_and_restart() in loader/a580/resetcode/main.c ) works OK, led is blinking.

    3. I've created a short assembly code which flashes the led, and put it inside ./core/entry.S - but no led is blinking.
    (I've verified that the code is correct and working).
    Unless I'm missing something, it means the loader is working, including 'copy_and_restart', but jumping to the chdk core doesn't work. Maybe copying the wrong region, or jumping to the wrong position?

    Any ideas are welcomed...



    « Last Edit: 10 / January / 2009, 05:27:31 by ag8 »

    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: A580 porting - minor progress
    « Reply #6 on: 10 / January / 2009, 17:57:30 »
    Hello,

    I've re-created the a580 loader/platform tree based on a720, but didn't get better results.
    I wouldn't expect it to help in the early parts, but there's less chance of copying something broken as you progress.
    Quote
    Here's what I've got so far;
    1. the value for The MEMIOSSTART (0xA47E0) also appears in the begining of the PRIMARY.BIN file (offset 0x194) and is used in a loop which writes zeros (BSS initialization?).

    I don't have IDA, and my ARM assembly skills as severely lacking, but here's what I gathered from the PRIMARY.BIN file.
    If somebody can comment on that, it'll be helpful:
    The loop code starts at offset 0x130.
    First, a loop copies data from 0xffebfb4c (ROM?) to 0x1900 -> 0xD700.
    Then, a second loop zeros data from 0xD700 -> 0xA47E0.

    2. The boot loader part ( copy_and_restart() in loader/a580/resetcode/main.c ) works OK, led is blinking.

    3. I've created a short assembly code which flashes the led, and put it inside ./core/entry.S - but no led is blinking.
    (I've verified that the code is correct and working).
    Unless I'm missing something, it means the loader is working, including 'copy_and_restart', but jumping to the chdk core doesn't work. Maybe copying the wrong region, or jumping to the wrong position?

    Any ideas are welcomed...
    Yes, the normal canon boot up process is to copy some static data from ROM, and then zero the (canon firmware) bss after that. MEMISOSTART needs to come after canon data + bss. (so 0x1900 + data size + bss size)

    You might want to look at How does CHDK start running
    Don't forget what the H stands for.

  • Publish
    Re: A580 porting - minor progress
    « Reply #7 on: 11 / January / 2009, 18:09:11 »
    I've spent a few hours today looking at the firmware of A580 and the firmware of A720 in parallel, trying to see the differences between them and most importantly, where were the A720 memory values were deducted from, in the hope that something similar would be in the A580's firmware. Unfortunately, no such luck.

    Well, I didn't have much hope anyway, because (and I'm sorry to say it) it's very hard to understand how everything actually works and what really I must do.

    My experience with ASM is pretty much mouse enabling, x-video resolution switching in Pascal when DOS and Windows 95 was king. So you can realize how much I understand from the IDA's assembly list, it's nothing like x86 asm I used to write 8-10 years ago.

    Regarding C, I understand C code and almost all the C code in CHDK.

    But I don't think that's the problem. For me at least, the problem is that I really don't know what I'm supposed to do to achieve a porting, no matter how many forum topics I've read.

    Where do I start, what should I look for, what needs to be adapted from camera to camera to make the very basic port of a camera... and so on and so forth.

    So far, I just assumed I need to make a copy of A720 from the platform folder, rename it to A580 and look for various addresses in the firmware dump. Finally I think I have to modify the makefile.inc to include the A580 camera in the list and build. I'm sure I'm also wrong here.

    What would really be awesome... would be for someone to actually explain what does CHDK need from the firmwares, explained in detail... for example "In order to use CHDK on a new camera, the software needs to know the address of the video screen, to draw pixels on it, the memory address of the area when the sensor places the picture after snapshot button is pressed"... you get the picture.

    It would also be awesome for someone to get an easier firmware go through the steps he took to determine those addresses, like looking in the strings list, finding a reference to camera display and going back in the code and determining the address or something like that.

    Maybe I'm asking too much but right now I'm just upset because I don't know enough programming to actually help with something.


    *

    Offline reyalp

    • ******
    • 9802
  • Publish
    Re: A580 porting - minor progress
    « Reply #8 on: 11 / January / 2009, 18:41:35 »
    1) you should understand the boot process. See http://chdk.setepontos.com/index.php/topic,1454.0.html
    2) You need adjust all the asm in loader and platform to be correct for your camera. Generally, this means
     - find the corresponding function in your firmwares ROM
     - Copy it to inline asm.
     - Modify in a way that is equivalent to the modifications done in the reference cam.
    3) Find the addresses for stubs_min.S and various platform C files. The general process is
    - look at a firmware for a similar camera
    - finding where the desired value is used in. Frequently, the actual constant isn't used directly. Instead and offset is calculated that results in the desired address, or the address is built from a sequence of shifts and adds.
    - find the corresponding code in your camera firmware to get the address.
    4) Verify that all the automatically detected entry points in stubs_entry.S are correct. This is done by comparing the function in your firmware to the same function in a known good firmware. Where they are wrong, find the correct function and add it to stubs_entry_2.S.
    5) Find any additional entry in the stubs_entry_2.S of your reference camera, and add them to stubs_entry_2.S of your camera.

    I've probably left some things out.

    Now a rant. There is no way anyone can just tell you what you need to do. To make a port, you have to understand the loader an platform directories, and have a general idea how the rest fits together. No amount of tutorials or forum posts will do this for you. Only reading and understanding the code will do it. If you don't understand them, then you can't make a port. We can give you hints of where to start, but the major effort has to come from your side. If you aren't sufficiently knowledgeable in C and ASM to understand these files, you need to learn, or give up. There is no shortcut.
    Don't forget what the H stands for.

  • Publish
    Re: A580 porting - minor progress
    « Reply #9 on: 11 / January / 2009, 19:54:55 »
    Thank you for the detailed explanation, it really helps. I'll try harder. I'm also sorry if I sounded ungrateful in the previous post, I was just frustrated with the whole process and complexity of it.

     

    Related Topics