Resuming activity from the LED blinker program - page 2 - General Discussion and Assistance - CHDK Forum

Resuming activity from the LED blinker program

  • 37 Replies
  • 9551 Views
*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #10 on: 26 / August / 2009, 21:19:01 »
Advertisements
Yes, I am sure, I am using the LED blinking as a debug message.

I have a function like this:
Code: [Select]
void FirmwareStart()
{
    asm("LDR PC, =0xffc00000\n");
}

I tried other addresses, such as ffff0000 as well, but no luck :/

I looked at the CHDK loader, in boot.c for example. Which other files should I look at?

*

Offline reyalp

  • ******
  • 13502
Re: Resuming activity from the LED blinker program
« Reply #11 on: 26 / August / 2009, 21:48:27 »
I looked at the CHDK loader, in boot.c for example. Which other files should I look at?
You should start at the beginning, loader/a530/entry.S

One other thing, if you are loading with diskboot.bin, jumping back into the firmware should give you a boot loop, since the canon firmware will find diskboot again and try to load it.
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #12 on: 26 / August / 2009, 21:52:45 »
Yes, I was thinking of that, so I am using the firmware update version. Either way, the debug LED only blinks shortly then it goes off, and so does the camera. However, I can restart the camera with the power button, which does not happen if I try to jump into some random ROM function. So I would guess the camera is being shut down nicely by the firmware.

I'll take a look at the loader.

*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #13 on: 26 / August / 2009, 23:06:35 »
Ok, the entry.S code seems simple to understand, because it is short and well documented.
However, at the end it jumps into a C function, my_restart()
I would guess the magic is done there, but it is not documented at all, and it seems to have some CHDK specific stuff in it.

If you or someone else could explain how/what that function does exactly, I'd appreciate it.


*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #14 on: 26 / August / 2009, 23:17:34 »
After looking even more, it seems the magic is really done in copy_and_restart() which has a big chunk of undocumented ASM, and at the end we have this beauty:
Code: [Select]
"MOV     SP, #0x1900\n"
"MOV     LR, PC\n"
"MOV     PC, %0\n"

*

Offline reyalp

  • ******
  • 13502
Re: Resuming activity from the LED blinker program
« Reply #15 on: 26 / August / 2009, 23:18:24 »
It copies the reset code to a safe place (outside of the area where CHDK will reside) and runs it.

This code copies CHDK to it's final location, runs some assembler copied from the cameras reboot function, and then jumps to the CHDK boot code (which is itself a clone of the camera code starting at FFC00000)
Don't forget what the H stands for.

*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #16 on: 26 / August / 2009, 23:32:33 »
Ok, so then.. how exactly would I go about just restarting the camera? I understand that all this stuff must be done to protect CHDK, but if I just want to jump to the beginning of the ROM, why wouldn't it work?
I tried to incorporate the code in entry.S so my function became:

Code: [Select]
void FirmwareStart()
{
    asm(
"LDR     R3, =0xC02200bc\n"
"MOV     R2, #0x44\n"
"STR     R2, [R3]\n"

// looks like idle cycle is required for proper shutdown
"MOV     R3, #0x8000\n"
"idle_cycle:"
"SUB R3, R3, #1\n"
"CMP R3, #0\n"
"BNE idle_cycle\n"

// ordinary startup...

"MOV     SP, #0x1900\n"
"MOV     R11, #0\n"
"LDR PC, =0xffc00000\n"
    );
}

It looks as if the camera is not happy with how it was started or something, because it runs the shutdown routine (most likely).

*

Offline reyalp

  • ******
  • 13502
Re: Resuming activity from the LED blinker program
« Reply #17 on: 26 / August / 2009, 23:39:56 »
I would try the asm code from resetcode/main.c:copy_and_restart
Don't forget what the H stands for.


*

Offline RaduP

  • *****
  • 908
Re: Resuming activity from the LED blinker program
« Reply #18 on: 26 / August / 2009, 23:57:11 »
Ok, but before I can use that code, I must understand this part:

Code: [Select]
"MOV     PC, %0\n"
    : : "r"(dst_void) : "memory","r1","r2","r3");

Specifically, what does "MOV     PC, %0\n" become before it is assemblied?
And what does     ": : "r"(dst_void) : "memory","r1","r2","r3");" this line mean?

*

Offline reyalp

  • ******
  • 13502
Don't forget what the H stands for.

 

Related Topics