root/platform/ixus30_sd200/sub/100k/boot.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. boot
  2. h_usrInit
  3. h_usrKernelInit
  4. h_usrRoot
  5. ttyRead
  6. mytty_nextline
  7. mytty_putc
  8. ttyWrite
  9. replaceConsoleDriver
  10. h_ios_tty_Init

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 #include "core.h"
   4 
   5 /* These functions need to be taken from the original firmware and addresses need to be modified */
   6 
   7 /* Ours stuff */
   8 extern long wrs_kernel_bss_start;
   9 extern long wrs_kernel_bss_end;
  10 extern void createHook (void *pNewTcb);
  11 extern void deleteHook (void *pTcb);
  12 const char * const new_sa = &_end;
  13 
  14 void boot();
  15 
  16 /* "relocated" functions */
  17 void __attribute__((naked,noinline)) h_usrInit();
  18 void __attribute__((naked,noinline)) h_usrKernelInit();
  19 void __attribute__((naked,noinline)) h_usrRoot();
  20 
  21 
  22 void boot()
  23 {
  24     long *canon_data_src = (void*)0xFFAD74A0; // This is the address of the "Startofdata" string on the firmware -4
  25     long *canon_data_dst = (void*)0x1900; // This is where the boot data is copiedduring firmware update
  26     long canon_data_len = 0xEAE0; // This is the length of data from "Startofdata" to the end of the firmware dump (???)
  27     long *canon_bss_start = (void*)0x103E0; //  = 0xEAE0 + 0x1900,  just after data //103E0
  28     long canon_bss_len = 0x72D40 - 0x103E0; // The original address of h_usrKernelInit - bss start
  29 
  30     long i;
  31 
  32     asm volatile (
  33         "MRC     p15, 0, R0,c1,c0\n"
  34         "ORR     R0, R0, #0x1000\n"
  35         "ORR     R0, R0, #4\n"
  36         "ORR     R0, R0, #1\n"
  37         "MCR     p15, 0, R0,c1,c0\n"
  38     :::"r0");
  39 
  40 
  41     for(i=0;i<canon_data_len/4;i++)
  42         canon_data_dst[i]=canon_data_src[i];
  43 
  44     for(i=0;i<canon_bss_len/4;i++)
  45         canon_bss_start[i]=0;
  46 
  47     asm volatile (
  48         "MRC     p15, 0, R0,c1,c0\n"
  49         "ORR     R0, R0, #0x1000\n"
  50         "BIC     R0, R0, #4\n"
  51         "ORR     R0, R0, #1\n"
  52         "MCR     p15, 0, R0,c1,c0\n"
  53     :::"r0");
  54     
  55     h_usrInit();
  56 }
  57 
  58 
  59 void h_usrInit() //@ff811b5c
  60 {
  61         asm volatile (
  62         "STR     LR, [SP,#-4]!\n"
  63         "BL      sub_FF811B20\n"
  64         "MOV     R0, #2\n"
  65         "MOV     R1, R0\n"
  66         "BL      sub_FFABDA10\n"//
  67         "BL      sub_FFAA9FE0\n"//
  68         "BL      sub_FF81125C\n"
  69         "BL      sub_FF811838\n"
  70         "LDR     LR, [SP],#4\n"
  71         "B       h_usrKernelInit\n"
  72         );
  73 
  74 }
  75 
  76 void  h_usrKernelInit() //@FF811854
  77 {
  78         asm volatile (
  79 "    STMFD   SP!, {R4,LR}\n"
  80 "    SUB     SP, SP, #8\n"
  81 "    BL      sub_FFABDF10\n"
  82 "    BL      sub_FFAD09D0\n"
  83 "    LDR     R3, =0xF814\n"
  84 "    LDR     R2, =0x70420\n"
  85 "    LDR     R1, [R3]\n"
  86 "    LDR     R0, =0x7270C\n"
  87 "    MOV     R3, #0x100\n"
  88 "    BL      sub_FFACC20C\n"
  89 "    LDR     R3, =0xF7D4\n"
  90 "    LDR     R0, =0xFBF4\n"
  91 "    LDR     R1, [R3]\n"
  92 "    BL      sub_FFACC20C\n"
  93 "    LDR     R3, =0xF890\n"
  94 "    LDR     R0, =0x726E0\n"
  95 "    LDR     R1, [R3]\n"
  96 "    BL      sub_FFACC20C\n"
  97 "    BL      sub_FFAD5550\n"
  98 "    BL      sub_FF811348\n"
  99 "    MOV     R4, #0\n"
 100 "    MOV     R3, R0\n"
 101 "    MOV     R12, #0x800\n"
 102 "    LDR     R0, =h_usrRoot\n" //=0xFF811C3C
 103 "    MOV     R1, #0x4000\n"
 104 //"    LDR     R2, =0x72D40\n" //-
 105     );
 106     asm volatile (
 107         "LDR     R2, =new_sa\n" //+
 108         "LDR     R2, [R2]\n" //+
 109     );
 110     asm volatile ( 
 111 "    STR     R12, [SP]\n"
 112 "    STR     R4, [SP,#4]\n"
 113 "    BL      sub_FFACDC10\n"
 114 "    ADD     SP, SP, #8\n"
 115 "    LDMFD   SP!, {R4,PC}\n"
 116         );
 117 }
 118 
 119 
 120 void  h_usrRoot() //@ff811c3c
 121 {
 122         asm volatile (
 123 "    STMFD   SP!, {R4,R5,LR}\n"
 124 "    MOV     R5, R0\n"
 125 "    MOV     R4, R1\n"
 126 "    BL      sub_FF811BA0\n" //init vxworks libs
 127 "    MOV     R1, R4\n"
 128 "    MOV     R0, R5\n"
 129 "    BL      sub_FFAC41F8\n" //memLibInit
 130 "    MOV     R1, R4\n"
 131 "    MOV     R0, R5\n"
 132 "    BL      sub_FFAC4C70\n" //memPartLibInit
 133 //"    BL      sub_FF811928\n" //- no boot when this BL is active...
 134 "    BL      sub_FF811814\n"
 135 "    MOV     R0, #0x32\n"
 136 "    BL      sub_FFAC66E0\n" //selectInit
 137 "    BL      sub_FF811BE4\n"
 138 "    BL      sub_FF811BC4\n"
 139 "    BL      sub_FF811C10\n"
 140 "    BL      sub_FFAC5FA0\n" //selTaskDeleteHookAdd
 141 "    BL      sub_FF811B94\n"
 142         );
 143     _taskCreateHookAdd(createHook);
 144     _taskDeleteHookAdd(deleteHook);
 145 
 146     drv_self_hide();
 147 
 148         asm volatile (
 149 
 150 "    LDMFD   SP!, {R4,R5,LR}\n"
 151 "    B       sub_FF811408\n"
 152         );
 153 }
 154 
 155 
 156 #if CAM_CONSOLE_LOG_ENABLED
 157 // not yet ported to ixus30
 158 typedef struct { 
 159                     long dev_hdr[4]; 
 160                     long opened; 
 161                  
 162                     long fill[64]; 
 163                 } MY_DEV; 
 164                  
 165                 #define CONS_W (45) 
 166                 #define CONS_H (128) 
 167                  
 168                 char console_buf[CONS_H][CONS_W]; 
 169                 long console_buf_line = 0; 
 170                 long console_buf_line_ptr = 0; 
 171                  
 172                 char cmd[100] = "ShowCameraLog\n\0"; 
 173                 int cons_cmd_ptr = -1; 
 174                  
 175                 void mytty_putc(char c); 
 176                  
 177                 int ttyRead(MY_DEV* tty,  char* buffer, int nBytes) 
 178                 { 
 179                     int r = 1; 
 180                  
 181                     if (cons_cmd_ptr == -1){ 
 182                         msleep(2000); 
 183                         cons_cmd_ptr = 0; 
 184                     } 
 185                  
 186                     mytty_putc('r'); 
 187                      
 188                     if (cmd[cons_cmd_ptr] != 0){ 
 189                         *buffer = cmd[cons_cmd_ptr]; 
 190                         cons_cmd_ptr++; 
 191                     } else { 
 192                         while (cons_cmd_ptr != 0){ 
 193                             msleep(10); 
 194                         } 
 195                         *buffer = cmd[cons_cmd_ptr]; 
 196                         cons_cmd_ptr++; 
 197                     } 
 198                  
 199                     return r; 
 200                 } 
 201                  
 202                 void mytty_nextline() 
 203                 { 
 204                     int i; 
 205                  
 206                     console_buf_line_ptr=0; 
 207                     console_buf_line++; 
 208                     if (console_buf_line>=CONS_H){ 
 209                         console_buf_line = 0; 
 210                     } 
 211                     for (i=0;i<15;i++){ 
 212                         int l=i+console_buf_line; 
 213                         if (l>=CONS_H) 
 214                             l-=CONS_H; 
 215                         console_buf[l][0] = 0; 
 216                     } 
 217                 } 
 218                  
 219                 void mytty_putc(char c) 
 220                 { 
 221                     if (c == 0xa){ 
 222                         mytty_nextline(); 
 223                     } else { 
 224                         if (console_buf_line_ptr>=(CONS_W-1)){ 
 225                             mytty_nextline(); 
 226                         } 
 227                  
 228                         console_buf[console_buf_line][console_buf_line_ptr++] = c; 
 229                         console_buf[console_buf_line][console_buf_line_ptr] = 0; 
 230                     } 
 231                 } 
 232                  
 233                 int tyWrite = 0xFFACA1E4; //FFB19FF8; 
 234                 
 235     //ttyWrite seems to work, Read might be broken 
 236                 int ttyWrite(MY_DEV* tty,  char* buffer, int nBytes) 
 237                 { 
 238                     int i; 
 239                  
 240                     for (i=0;i<nBytes;i++){ 
 241                         mytty_putc(buffer[i]); 
 242                     } 
 243                  
 244                     return ((int(*)(void *p, void *p2, int l))tyWrite)(tty, buffer, nBytes); 
 245                 //    return nBytes; 
 246                 } 
 247                  
 248                  
 249                 /* 
 250                   Referenced from ttyDrv_init as 
 251                      LDR     R11, =TTY_DRV_NUM 
 252                   and ttyDevCreate as 
 253                      LDR     R9, =TTY_DRV_NUM 
 254                 */ 
 255                 int *TTY_DRV_NUM = (int*)0x0006F578; 
 256                  
 257                 static void replaceConsoleDriver() 
 258                 { 
 259                     // These function addresses are from ttyDrv_init function call 
 260                     int f0 = 0xFFAC9274; //0xFFB19088; 
 261                     int f1 = 0; 
 262                     int f2 = 0xFFAC9274; //0xFFB19088; 
 263                     int f3 = 0xFFAC92B4; //0xFFB190C8; 
 264                     int f6 = 0xFFAC92F8; //0xFFB1910C; 
 265                     int fRead = (int)&ttyRead; 
 266                     int fWrite = (int)&ttyWrite; 
 267                     int newdriver_id = _iosDrvInstall((void*)f0, (void*)f1, (void*)f2, (void*)f3, (void*)fRead, (void*)fWrite, (void*)f6); 
 268                  
 269                     *TTY_DRV_NUM = newdriver_id; 
 270                 } 
 271                  
 272                 void h_ios_tty_Init() 
 273                 { 
 274                 /* 
 275                   asm volatile 
 276                   ( 
 277                       "MOV     R0, #0x1000" 
 278                       "BL      sub_FF811478" 
 279                  
 280                       "MOV     R1, #0x32"                  
 281                       "LDR     R2, =aNull" 
 282                       "MOV     R0, #0x14"                        
 283                       "BL      iosInit" 
 284                   ); 
 285                 */   
 286                   _iosInit(0x14, 0x32, "/null"); 
 287                   replaceConsoleDriver(); 
 288            
 289                 /*  asm volatile 
 290                   ( 
 291                       "BL      sub_FF811878" 
 292                   ); 
 293                 */ 
 294                 } 
 295 #endif
 296     

/* [<][>][^][v][top][bottom][index][help] */