Author Topic: A580 porting - minor progress  (Read 17081 times)

Offline ag8

  • Newbie
  • *
  • Posts: 4
A580 porting - minor progress
« on: 07 / January / 2009, 14:50:03 »
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

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #1 on: 08 / January / 2009, 00: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.

Offline mariush

  • Jr. Member
  • **
  • Posts: 63
Re: A580 porting - minor progress
« Reply #2 on: 09 / January / 2009, 20: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

  • Full Member
  • ***
  • Posts: 138
  • IXUS 82 IS
Re: A580 porting - minor progress
« Reply #3 on: 09 / January / 2009, 22: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

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #4 on: 10 / January / 2009, 04: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

  • Newbie
  • *
  • Posts: 4
Re: A580 porting - minor progress
« Reply #5 on: 10 / January / 2009, 15: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, 15:27:31 by ag8 »

Offline reyalp

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #6 on: 11 / January / 2009, 03: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.

Offline mariush

  • Jr. Member
  • **
  • Posts: 63
Re: A580 porting - minor progress
« Reply #7 on: 12 / January / 2009, 04: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

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #8 on: 12 / January / 2009, 04: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.

CHDK Forum

Re: A580 porting - minor progress
« Reply #8 on: 12 / January / 2009, 04:41:35 »

Offline mariush

  • Jr. Member
  • **
  • Posts: 63
Re: A580 porting - minor progress
« Reply #9 on: 12 / January / 2009, 05: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.

Offline ag8

  • Newbie
  • *
  • Posts: 4
Re: A580 porting - minor progress
« Reply #10 on: 15 / January / 2009, 16:19:49 »
Another tiny step:

I was able to jump from the loader to the core, and blink the led from function boot() in ./platform/a580/sub/100c/boot.c.

This however required some strange hack that may indicate a problem in my build process:

From my understanding, code in 'platform' and 'core' is compiled into ./core/main.elf,
converted to ./core/main.bin,
inserted into ./loader/a580/main.elf (as binary blob),
which is then converted into ./loader/a580/main.bin, and encoded into ./bin/DISKBOOT.bin.

During boot, the loader calls 'copy_and_restart()' to copy the core's binary blob into the 'right' memory address (which is MEMISOSTART), and then jumps to that position.

So far - am I right?

The above process assumes that the start of the core's main.bin (i.e. offset 0x0000) is the entry point.
Meaning - ./core/entry.S should reside at offset 0x0000 in ./core/main.bin.

This doesn't happen in my build - ./core/entry.S goes into offset MEMISOSTART+0x6B8.
So jump to MEMISOSTART in copy_and_restart() doesn't work.
I had to change copy_and_restart() and add the following line:
   dst_void = (void*) (MEMISOSTART + 0x6B8) ;

To jump into the correct location.

Inside ./core/main.dump I see that functions such as "__vid_get_bitmap_buffer_width_from_thumb" and "__get_zoom_x_from_thumb" got inserted before the entry point.

Does somebody have an Idea how to fix this?

Thanks for all your help so far.

Offline reyalp

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #11 on: 16 / January / 2009, 03:36:27 »
What binutils are you using ? ISTR the most recent (2.19) do something like this.
Don't forget what the H stands for.

Offline mariush

  • Jr. Member
  • **
  • Posts: 63
Re: A580 porting - minor progress
« Reply #12 on: 18 / January / 2009, 00:48:12 »
I've installed Cygwin and GCC according to the instructions in the wiki here: http://chdk.wikia.com/wiki/User:Geekmug/Compiling_CHDK_under_Windows

I then took the A720 platform and created platform a580 and platformsub 101b, modified camera.h, makefile.inc, kbd.c  (copied what was for A720)... basically done all the steps to reproduce what was tried in the first post... to make the camera go in infinite loop and recover when the card is removed... also to see if the led blinks.

Problem is this showed while compiling:

Code: [Select]

$ PATH=/arm-elf/bin:$PATH make fir
**** Build: 0.9.1
>> Entering to tools
<< Leaving tools
>> Entering to lib
>> Entering to lib/font
<< Leaving lib/font
>> Entering to lib/math
<< Leaving lib/math
>> Entering to lib/ubasic
<< Leaving lib/ubasic
>> Entering to lib/lang
<< Leaving lib/lang
>> Entering to lib/lua
<< Leaving lib/lua
<< Leaving lib
>> Entering to platform
>> Entering to platform/a580
>> Entering to platform/a580/sub
>> Entering to platform/a580/sub/101b
<< Leaving platform/a580/sub/101b
<< Leaving platform/a580/sub
<< Leaving platform/a580
<< Leaving platform
>> Entering to core
gui.c -> gui.o
-> main.elf
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: ERROR: gui.o uses FPA
 instructions, whereas main.elf does not
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: failed to merge targe
t specific data of file gui.o
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: ERROR: /arm-elf/lib/g
cc/arm-elf/4.3.2/thumb/interwork/libgcc.a(_udivsi3.o) uses FPA instructions, whe
reas main.elf does not

[...]

/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: ERROR: /arm-elf/lib/g
cc/arm-elf/4.3.2/thumb/interwork/libgcc.a(_fixsfsi.o) uses FPA instructions, whe
reas main.elf does not
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: failed to merge targe
t specific data of file /arm-elf/lib/gcc/arm-elf/4.3.2/thumb/interwork/libgcc.a(
_fixsfsi.o)
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: ERROR: /arm-elf/lib/g
cc/arm-elf/4.3.2/thumb/interwork/libgcc.a(_fixunssfsi.o) uses FPA instructions,
whereas main.elf does not
/arm-elf/lib/gcc/arm-elf/4.3.2/../../../../arm-elf/bin/ld: failed to merge targe
t specific data of file /arm-elf/lib/gcc/arm-elf/4.3.2/thumb/interwork/libgcc.a(
_fixunssfsi.o)
collect2: ld returned 1 exit status
make[1]: *** [main.elf] Error 1
make: *** [all-recursive] Error 1


Any clue of what's wrong?

Offline reyalp

  • Guru Member
  • ******
  • Posts: 4468
Re: A580 porting - minor progress
« Reply #13 on: 18 / January / 2009, 02:25:41 »
I would suggest using the pre-built gcc 3.x win32 environment.

Otherwise, read this thread: http://chdk.setepontos.com/index.php/topic,2500.0.html
Don't forget what the H stands for.

Offline whim

  • Guru Member
  • ******
  • Posts: 1954
  • A620/A630/A590-101b/i70-101b/i870-101a/i300
Re: A580 porting - minor progress
« Reply #14 on: 18 / January / 2009, 02:37:13 »
I would suggest using the pre-built gcc 3.x win32 environment.

Otherwise, read this thread: http://chdk.setepontos.com/index.php/topic,2500.0.html


... or the pre-built gcc 4.3.2 win32 environment (both  3 & 4 are here: http://drop.io/chdkdev)

... or CHDK-Shell including both here: http://drop.io/gcc_for_chdkshell

Note: NONE of these solutions work under Vista (the cygwin one should, though)

About the errors:
        does it also error compiling a known good platform, like the 720 you cloned your 580 from ?


wim

« Last Edit: 18 / January / 2009, 02:53:40 by whim »

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal