| 1 | static void __attribute__((noreturn)) shutdown(); |
|---|
| 2 | static void __attribute__((noreturn)) panic(int cnt); |
|---|
| 3 | |
|---|
| 4 | extern long *blob_chdk_core; |
|---|
| 5 | extern long *blob_copy_and_reset; |
|---|
| 6 | extern long blob_chdk_core_size; |
|---|
| 7 | extern long blob_copy_and_reset_size; |
|---|
| 8 | |
|---|
| 9 | /* @brief Makes a copy of CHDK core in instruction memory and restarts FW. |
|---|
| 10 | * |
|---|
| 11 | * Starts by copying existing copy_and_restart procedure to 0x50000 and then using |
|---|
| 12 | * copied start_and_restart procedure to copy CHDK core to 0x9C890. Absolute HEX |
|---|
| 13 | * addresses come from makefile.inc definitions. |
|---|
| 14 | * |
|---|
| 15 | * @note This is required because camera starts in standard FW (i.e. canon). To switch between |
|---|
| 16 | * canon and CHDK FW a reset is required. If start of CHDK FW was a reset then new FW would |
|---|
| 17 | * continually restart. As a result CHDK FW on first pass must copy CHDK core (i.e. removing reset |
|---|
| 18 | * code) to instruction memory and then restarting FW so CHDK core executes. |
|---|
| 19 | * |
|---|
| 20 | * @return Does not return. |
|---|
| 21 | */ |
|---|
| 22 | void __attribute__((noreturn)) my_restart() |
|---|
| 23 | { |
|---|
| 24 | void __attribute__((noreturn)) (*copy_and_restart)(char *dst, char *src, long length); |
|---|
| 25 | int i; |
|---|
| 26 | |
|---|
| 27 | // Make a copy of the procedure copy_and_reset in another memory space. |
|---|
| 28 | for (i = 0 ; i < (blob_copy_and_reset_size / sizeof(long)) ; i++ ) |
|---|
| 29 | { |
|---|
| 30 | ((long*)(RESTARTSTART))[i] = blob_copy_and_reset[i]; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | // Execute duplicated code in non-instruction memory space. |
|---|
| 34 | copy_and_restart = (void*)RESTARTSTART; |
|---|
| 35 | copy_and_restart((void*)MEMISOSTART, (char*)blob_chdk_core, blob_chdk_core_size); |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | #define LED_PR 0xc0220084 |
|---|
| 39 | |
|---|
| 40 | static void __attribute__((noreturn)) shutdown() |
|---|
| 41 | { |
|---|
| 42 | volatile long *p = (void*)0xc02200a0; |
|---|
| 43 | |
|---|
| 44 | asm( |
|---|
| 45 | "MRS R1, CPSR\n" |
|---|
| 46 | "AND R0, R1, #0x80\n" |
|---|
| 47 | "ORR R1, R1, #0x80\n" |
|---|
| 48 | "MSR CPSR_cf, R1\n" |
|---|
| 49 | :::"r1","r0"); |
|---|
| 50 | |
|---|
| 51 | *p = 0x44; |
|---|
| 52 | |
|---|
| 53 | while(1); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | static void __attribute__((noreturn)) panic(int cnt) |
|---|
| 58 | { |
|---|
| 59 | volatile long *p=(void*)LED_PR; |
|---|
| 60 | int i; |
|---|
| 61 | |
|---|
| 62 | for(;cnt>0;cnt--){ |
|---|
| 63 | p[0]=0x46; |
|---|
| 64 | |
|---|
| 65 | for(i=0;i<0x200000;i++){ |
|---|
| 66 | asm ("nop\n"); |
|---|
| 67 | asm ("nop\n"); |
|---|
| 68 | } |
|---|
| 69 | p[0]=0x44; |
|---|
| 70 | for(i=0;i<0x200000;i++){ |
|---|
| 71 | asm ("nop\n"); |
|---|
| 72 | asm ("nop\n"); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | shutdown(); |
|---|
| 76 | } |
|---|