root/platform/ixus185_elph185/sub/100a/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. log_fwt_msg
  2. log_fwt_start
  3. filewritetask
  4. sub_FFAD9434_my
  5. sub_FFAD9CF4_my
  6. sub_FFAD9610_my

   1 /*
   2  * filewrite.c - auto-generated by CHDK code_gen.
   3  */
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 
   7 // debug
   8 //#define FILEWRITE_DEBUG_LOG 1
   9 extern void _LogCameraEvent(int id,const char *fmt,...);
  10 
  11 typedef struct {
  12     unsigned int address;
  13     unsigned int length;
  14 } cam_ptp_data_chunk; //camera specific structure
  15 
  16 #define MAX_CHUNKS_FOR_JPEG 7 // filewritetask is prepared for this many chunks
  17 
  18 
  19 // comments below from elph180, firmware code appears very similar, offsets verified
  20 /*
  21  * fwt_data_struct: defined here as it's camera dependent
  22  * unneeded members are designated with unkn
  23  * file_offset, full_size, seek_flag only needs to be defined for cameras with CAM_FILEWRITETASK_SEEK/CAM_FILEWRITETASK_MULTIPASS
  24  * pdc is always required
  25  * name is not currently used
  26  */
  27 typedef struct
  28 {
  29     int unkn1; // message number
  30     int file_offset;
  31     int maybe_full_size; // maybe, on g7x wasn't always full size
  32     int unkn2, unkn3;
  33     int unkn4;
  34     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  35     int maybe_seek_flag;      // 0x2083 jpeg, 0x100 create dir, 0x200 CacheFlush
  36     int unkn5, unkn6;
  37     char name[32];      // offset from start 0x5c, from Open case
  38 } fwt_data_struct;
  39 /*
  40 observed message sequences
  41 JPEG
  42 12 maybe_full_size = 0x004437ac (=actual size), seek_flag = 0x2083
  43  0 chunk 0-0x004437ac
  44  1 chunk 0-0
  45  7 close
  46 
  47 new directory
  48 11 seek_flag = 0x100
  49 before m 12 for shot, after raw hook in capt_seq
  50 
  51 after shot
  52 10 A/ seek_flag 0x200
  53 */
  54 
  55 #include "../../../generic/filewrite.c"
  56 
  57 #ifdef FILEWRITE_DEBUG_LOG
  58 void log_fwt_msg(fwt_data_struct *fwd)
  59 {
  60     int m=fwd->unkn1;
  61     _LogCameraEvent(0x60,"fw m:%d o:0x%08x fs:0x%08x sf:0x%x",m,fwd->file_offset,fwd->maybe_full_size,fwd->maybe_seek_flag);
  62     _LogCameraEvent(0x60,"fw %s",fwd->name);
  63     if(m >= 0 && m <=6) {
  64         _LogCameraEvent(0x60,"fw chunk adr:0x%08x l:0x%08x",fwd->pdc[m].address,fwd->pdc[m].length);
  65     }
  66     _LogCameraEvent(0x60,"fw u %08x %08x %08x %08x %08x %08x",fwd->unkn2,fwd->unkn3,fwd->unkn4,fwd->unkn5,fwd->unkn6);
  67 }
  68 
  69 void log_fwt_start(void)
  70 {
  71     _LogCameraEvent(0x60,"fw start");
  72 }
  73 #endif
  74 
  75 
  76 /*************************************************************/
  77 //** filewritetask @ 0xFFAD9824 - 0xFFAD9964, length=81
  78 void __attribute__((naked,noinline)) filewritetask() {
  79 asm volatile (
  80 "    STMFD   SP!, {R1-R5,LR} \n"
  81 #ifdef FILEWRITE_DEBUG_LOG
  82 "bl log_fwt_start\n"
  83 #endif
  84 "    LDR     R5, =0xAC30 \n"
  85 
  86 "loc_FFAD982C:\n"
  87 "    MOV     R2, #0 \n"
  88 "    LDR     R0, [R5, #0x14] \n"
  89 "    ADD     R1, SP, #8 \n"
  90 "    BL      sub_FF838728 /*_ReceiveMessageQueue*/ \n"
  91 "    CMP     R0, #0 \n"
  92 "    LDRNE   R2, =0x405 \n"
  93 "    LDRNE   R1, =0xFFAD9998 /*'dwFWrite.c'*/ \n"
  94 "    MOVNE   R0, #0 \n"
  95 "    BLNE    _DebugAssert \n"
  96 #ifdef FILEWRITE_DEBUG_LOG
  97 "ldr     r0, [sp,#8]\n"
  98 "bl log_fwt_msg\n"
  99 #endif
 100 "    LDR     R0, [SP, #8] \n"
 101 "    LDR     R1, [R0] \n"
 102 "    CMP     R1, #0xD \n"
 103 "    ADDCC   PC, PC, R1, LSL#2 \n"
 104 "    B       loc_FFAD982C \n"
 105 "    B       loc_FFAD9958 \n"
 106 "    B       loc_FFAD9958 \n"
 107 "    B       loc_FFAD9958 \n"
 108 "    B       loc_FFAD9958 \n"
 109 "    B       loc_FFAD9958 \n"
 110 "    B       loc_FFAD9958 \n"
 111 "    B       loc_FFAD9958 \n"
 112 "    B       loc_FFAD9960 \n"
 113 "    B       loc_FFAD9898 \n"
 114 "    B       loc_FFAD9920 \n"
 115 "    B       loc_FFAD9950 \n"
 116 "    B       loc_FFAD9910 \n"
 117 "    B       loc_FFAD9918 \n"
 118 
 119 "loc_FFAD9898:\n"
 120 "    MOV     R0, #0 \n"
 121 "    STR     R0, [SP] \n"
 122 
 123 "loc_FFAD98A0:\n"
 124 "    LDR     R0, [R5, #0x14] \n"
 125 "    MOV     R1, SP \n"
 126 "    BL      sub_FF8389BC /*_GetNumberOfPostedMessages*/ \n"
 127 "    LDR     R0, [SP] \n"
 128 "    CMP     R0, #0 \n"
 129 "    BEQ     loc_FFAD98CC \n"
 130 "    LDR     R0, [R5, #0x14] \n"
 131 "    MOV     R2, #0 \n"
 132 "    ADD     R1, SP, #4 \n"
 133 "    BL      sub_FF838728 /*_ReceiveMessageQueue*/ \n"
 134 "    B       loc_FFAD98A0 \n"
 135 
 136 "loc_FFAD98CC:\n"
 137 "    LDR     R0, [R5, #8] \n"
 138 "    MOV     R4, R5 \n"
 139 "    CMN     R0, #1 \n"
 140 "    BEQ     loc_FFAD9904 \n"
 141 "    BL      _Close \n"
 142 "    MVN     R0, #0 \n"
 143 "    STR     R0, [R4, #8] \n"
 144 "    MOV     R1, #0 \n"
 145 "    MOV     R0, #0x48 \n"
 146 "    BL      sub_FF8BB258 \n"
 147 "    LDR     R0, =0xFCCF0 \n"
 148 "    BL      sub_FF831430 \n"
 149 "    MOV     R1, #0 \n"
 150 "    BL      sub_FF82F310 \n"
 151 
 152 "loc_FFAD9904:\n"
 153 "    LDR     R0, [R4, #0x10] \n"
 154 "    BL      _GiveSemaphore \n"
 155 "    B       loc_FFAD982C \n"
 156 
 157 "loc_FFAD9910:\n"
 158 "    BL      sub_FFAD9BB8 \n"
 159 "    B       loc_FFAD982C \n"
 160 
 161 "loc_FFAD9918:\n"
 162 "    BL      sub_FFAD9434_my \n"  // --> Patched. Old value = 0xFFAD9434. msg 12 - open, main hook
 163 "    B       loc_FFAD982C \n"
 164 
 165 "loc_FFAD9920:\n"
 166 "    LDR     R1, [R0, #4] \n"
 167 "    MOV     R4, R0 \n"
 168 "    LDR     R0, [R5, #8] \n"
 169 "    MOV     R2, #0 \n"
 170 "    BL      _lseek \n"
 171 "    CMN     R0, #1 \n"
 172 "    LDREQ   R0, =0x9200013 \n"
 173 "    MOVEQ   R1, R4 \n"
 174 "    STREQ   R0, [R4, #0x14] \n"
 175 "    MOVEQ   R0, #7 \n"
 176 "    BLEQ    sub_FFAD936C \n"
 177 "    B       loc_FFAD982C \n"
 178 
 179 "loc_FFAD9950:\n"
 180 "    BL      sub_FFAD9C58 \n"
 181 "    B       loc_FFAD982C \n"
 182 
 183 "loc_FFAD9958:\n"
 184 "    BL      sub_FFAD9CF4_my \n"  // --> Patched. Old value = 0xFFAD9CF4. msg 0-6 - write chunk
 185 "    B       loc_FFAD982C \n"
 186 
 187 "loc_FFAD9960:\n"
 188 "    BL      sub_FFAD9610_my \n"  // --> Patched. Old value = 0xFFAD9610. msg 7 - close
 189 "    B       loc_FFAD982C \n"
 190 );
 191 }
 192 
 193 /*************************************************************/
 194 //** sub_FFAD9434_my @ 0xFFAD9434 - 0xFFAD960C, length=119
 195 void __attribute__((naked,noinline)) sub_FFAD9434_my() {
 196 asm volatile (
 197 "    STMFD   SP!, {R4-R9,LR} \n"
 198 "    MOV     R4, R0 \n"
 199 //hook placed here to avoid conditional branch a few instructions below (watch out for registers!)
 200 //"  MOV   R0, R4\n"      //data block start, commented out as R0 is already holding what we need
 201 "    BL filewrite_main_hook\n"
 202 "    MOV     R0, R4\n"      //restore register(s)
 203 "    LDR     R0, [R0, #0x50] \n"
 204 "    LDR     R7, =0xAC30 \n"
 205 "    TST     R0, #5 \n"
 206 "    SUB     SP, SP, #0x44 \n"
 207 "    BEQ     loc_FFAD9478 \n"
 208 "    LDR     R0, [R7, #0x1C] \n"
 209 "    CMP     R0, #0 \n"
 210 "    BLXNE   R0 \n"
 211 "    ADD     R0, R4, #0x5C \n"
 212 "    BL      sub_FF831430 \n"
 213 "    MOV     R1, #0 \n"
 214 "    BL      sub_FF82F1D0 \n"
 215 "    MOV     R1, #0 \n"
 216 "    MOV     R0, #0x47 \n"
 217 "    BL      sub_FF8BB258 \n"
 218 
 219 "loc_FFAD9478:\n"
 220 "    LDR     R0, [R4, #0x50] \n"
 221 "    TST     R0, #1 \n"
 222 "    BEQ     loc_FFAD95E0 \n"
 223 "    LDR     R0, [R4, #0x10] \n"
 224 "    BL      sub_FF82E260 \n"
 225 "    LDR     R0, [R4, #0x50] \n"
 226 "    LDR     R5, =0x301 \n"
 227 "    TST     R0, #0x10 \n"
 228 "    MOVNE   R5, #9 \n"
 229 "    BNE     loc_FFAD94A8 \n"
 230 "    TST     R0, #0x40 \n"
 231 "    MOVNE   R5, #1 \n"
 232 
 233 "loc_FFAD94A8:\n"
 234 "    TST     R0, #0x20 \n"
 235 "    BNE     loc_FFAD94BC \n"
 236 "    LDR     R0, [R4, #0x58] \n"
 237 "    CMP     R0, #1 \n"
 238 "    BNE     loc_FFAD94C0 \n"
 239 
 240 "loc_FFAD94BC:\n"
 241 "    ORR     R5, R5, #0x8000 \n"
 242 
 243 "loc_FFAD94C0:\n"
 244 "    LDR     R9, =0x1B6 \n"
 245 "    ADD     R8, R4, #0x5C \n"
 246 "    LDR     R6, [R4, #0x10] \n"
 247 "    MOV     R2, R9 \n"
 248 "    MOV     R1, R5 \n"
 249 "    MOV     R0, R8 \n"
 250 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 251 "    CMN     R0, #1 \n"
 252 "    BNE     loc_FFAD9544 \n"
 253 "    MOV     R0, R8 \n"
 254 "    BL      sub_FF827B74 \n"
 255 "    MOV     R2, #0xF \n"
 256 "    MOV     R1, R8 \n"
 257 "    MOV     R0, SP \n"
 258 "    BL      sub_006BA914 \n"
 259 "    MOV     R0, #0 \n"
 260 "    LDR     R1, =0x41FF \n"
 261 "    STRB    R0, [SP, #0xF] \n"
 262 "    STR     R1, [SP, #0x20] \n"
 263 "    MOV     R1, #0x10 \n"
 264 "    STR     R1, [SP, #0x24] \n"
 265 "    STR     R0, [SP, #0x28] \n"
 266 "    STR     R0, [SP, #0x2C] \n"
 267 "    ADD     R1, SP, #0x20 \n"
 268 "    MOV     R0, SP \n"
 269 "    STR     R6, [SP, #0x30] \n"
 270 "    STR     R6, [SP, #0x34] \n"
 271 "    STR     R6, [SP, #0x38] \n"
 272 "    BL      sub_FF82EB4C \n"
 273 "    MOV     R2, R9 \n"
 274 "    MOV     R1, R5 \n"
 275 "    MOV     R0, R8 \n"
 276 "    BL      _Open \n"
 277 
 278 "loc_FFAD9544:\n"
 279 "    CMN     R0, #1 \n"
 280 "    MOV     R5, R0 \n"
 281 "    STR     R0, [R7, #8] \n"
 282 "    BNE     loc_FFAD95A0 \n"
 283 "    MOV     R1, #0 \n"
 284 "    MOV     R0, #0x48 \n"
 285 "    BL      sub_FF8BB258 \n"
 286 "    ADD     R0, R4, #0x5C \n"
 287 "    BL      sub_FF831430 \n"
 288 "    LDR     R1, [R7, #0x20] \n"
 289 "    BL      sub_FF82F310 \n"
 290 "    LDR     R0, [R7, #0x18] \n"
 291 "    CMP     R0, #0 \n"
 292 "    BEQ     loc_FFAD9608 \n"
 293 "    LDR     R5, =0x9200001 \n"
 294 "    MOV     R0, R4 \n"
 295 "    MOV     R1, R5 \n"
 296 "    BL      sub_FFAD9308 \n"
 297 "    LDR     R1, [R7, #0x18] \n"
 298 "    MOV     R0, R5 \n"
 299 "    ADD     SP, SP, #0x44 \n"
 300 "    LDMFD   SP!, {R4-R9,LR} \n"
 301 "    BX      R1 \n"
 302 
 303 "loc_FFAD95A0:\n"
 304 "    LDR     R0, =0xFCCF0 \n"
 305 "    MOV     R2, #0x20 \n"
 306 "    ADD     R1, R4, #0x5C \n"
 307 "    BL      sub_006BAAFC \n"
 308 "    LDR R3, =current_write_ignored\n"
 309 "    LDR R3, [R3]\n"
 310 "    CMP R3, #0\n"
 311 "    BNE loc_C\n" // jump over the next block
 312 "    LDR     R0, [R4, #0x50] \n"
 313 "    TST     R0, #0x80 \n"
 314 "    BEQ     loc_FFAD95E0 \n"
 315 "    LDR     R1, [R4, #0xC] \n"
 316 "    MOV     R0, R5 \n"
 317 "    BL      sub_FF827844 \n"
 318 "    CMP     R0, #0 \n"
 319 "    LDREQ   R0, =0x9200017 \n"
 320 "    MOVEQ   R1, R4 \n"
 321 "    STREQ   R0, [R4, #0x14] \n"
 322 "    MOVEQ   R0, #7 \n"
 323 "    BEQ     loc_FFAD9604 \n"
 324 
 325 "loc_FFAD95E0:\n"
 326 "loc_C:\n"
 327 "    LDR     R0, [R4, #0x50] \n"
 328 "    TST     R0, #0x40 \n"
 329 "    LDREQ   R0, [R4, #4] \n"
 330 "    CMPEQ   R0, #0 \n"
 331 "    MOVNE   R1, R4 \n"
 332 "    MOVNE   R0, #9 \n"
 333 "    BLNE    sub_FFAD936C \n"
 334 "    MOV     R1, R4 \n"
 335 "    MOV     R0, #0 \n"
 336 
 337 "loc_FFAD9604:\n"
 338 "    BL      sub_FFAD936C \n"
 339 
 340 "loc_FFAD9608:\n"
 341 "    ADD     SP, SP, #0x44 \n"
 342 "    LDMFD   SP!, {R4-R9,PC} \n"
 343 );
 344 }
 345 
 346 /*************************************************************/
 347 //** sub_FFAD9CF4_my @ 0xFFAD9CF4 - 0xFFAD9DD8, length=58
 348 void __attribute__((naked,noinline)) sub_FFAD9CF4_my() {
 349 asm volatile (
 350 "    STMFD   SP!, {R4-R10,LR} \n"
 351 "    MOV     R5, R0 \n"
 352 "    LDR     R0, [R0] \n"
 353 "    CMP     R0, #6 \n"
 354 "    BHI     loc_FFAD9D20 \n"
 355 "    ADD     R0, R5, R0, LSL#3 \n"
 356 "    LDR     R8, [R0, #0x18]! \n"
 357 "    LDR     R7, [R0, #4] \n"
 358 "    CMP     R7, #0 \n"
 359 "    BNE     loc_FFAD9D3C \n"
 360 "    B       loc_FFAD9D30 \n"
 361 
 362 "loc_FFAD9D20:\n"
 363 "    MOV     R2, #0x348 \n"
 364 "    LDR     R1, =0xFFAD9998 /*'dwFWrite.c'*/ \n"
 365 "    MOV     R0, #0 \n"
 366 "    BL      _DebugAssert \n"
 367 
 368 "loc_FFAD9D30:\n"
 369 "    MOV     R1, R5 \n"
 370 "    MOV     R0, #7 \n"
 371 "    B       loc_FFAD9DD4 \n"
 372 
 373 "loc_FFAD9D3C:\n"
 374 "    LDR     R9, =0xAC30 \n"
 375 "    MOV     R4, R7 \n"
 376 
 377 "loc_FFAD9D44:\n"
 378 "    LDR     R0, [R5, #4] \n"
 379 "    CMP     R4, #0x1000000 \n"
 380 "    MOVLS   R6, R4 \n"
 381 "    MOVHI   R6, #0x1000000 \n"
 382 "    BIC     R1, R0, #0xFF000000 \n"
 383 "    CMP     R1, #0 \n"
 384 "    BICNE   R0, R0, #0xFF000000 \n"
 385 "    RSBNE   R0, R0, #0x1000000 \n"
 386 "    CMPNE   R6, R0 \n"
 387 "    MOVHI   R6, R0 \n"
 388 "    LDR     R0, [R9, #8] \n"
 389 "    MOV     R2, R6 \n"
 390 "    MOV     R1, R8 \n"
 391 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 392 "    LDR     R1, [R5, #4] \n"
 393 "    CMP     R6, R0 \n"
 394 "    ADD     R1, R1, R0 \n"
 395 "    STR     R1, [R5, #4] \n"
 396 "    BEQ     loc_FFAD9DA4 \n"
 397 "    CMN     R0, #1 \n"
 398 "    LDRNE   R0, =0x9200015 \n"
 399 "    LDREQ   R0, =0x9200005 \n"
 400 "    STR     R0, [R5, #0x14] \n"
 401 "    B       loc_FFAD9D30 \n"
 402 
 403 "loc_FFAD9DA4:\n"
 404 "    SUB     R4, R4, R0 \n"
 405 "    CMP     R4, R7 \n"
 406 "    LDRCS   R2, =0x372 \n"
 407 "    LDRCS   R1, =0xFFAD9998 /*'dwFWrite.c'*/ \n"
 408 "    ADD     R8, R8, R0 \n"
 409 "    MOVCS   R0, #0 \n"
 410 "    BLCS    _DebugAssert \n"
 411 "    CMP     R4, #0 \n"
 412 "    BNE     loc_FFAD9D44 \n"
 413 "    LDR     R0, [R5] \n"
 414 "    MOV     R1, R5 \n"
 415 "    ADD     R0, R0, #1 \n"
 416 
 417 "loc_FFAD9DD4:\n"
 418 "    LDMFD   SP!, {R4-R10,LR} \n"
 419 "    B       sub_FFAD936C \n"
 420 );
 421 }
 422 
 423 /*************************************************************/
 424 //** sub_FFAD9610_my @ 0xFFAD9610 - 0xFFAD96B0, length=41
 425 void __attribute__((naked,noinline)) sub_FFAD9610_my() {
 426 asm volatile (
 427 "    STMFD   SP!, {R4-R7,LR} \n"
 428 "    MOV     R4, R0 \n"
 429 "    LDR     R0, [R0, #0x50] \n"
 430 "    LDR     R5, =0xAC30 \n"
 431 "    TST     R0, #0xA \n"
 432 "    SUB     SP, SP, #0x44 \n"
 433 "    BEQ     sub_FFAD97F0 \n"
 434 "    TST     R0, #2 \n"
 435 "    MOV     R6, #0 \n"
 436 "    BEQ     sub_FFAD96C4 \n"
 437 "    TST     R0, #0x80 \n"
 438 "    LDRNE   R0, [R4, #8] \n"
 439 "    LDRNE   R1, [R4, #0xC] \n"
 440 "    CMPNE   R0, R1 \n"
 441 "    BEQ     loc_FFAD968C \n"
 442 "    MOV     R1, R0 \n"
 443 "    LDR     R0, [R5, #8] \n"
 444 "    BL      sub_FF827844 \n"
 445 "    CMP     R0, #0 \n"
 446 "    LDREQ   R0, =0x9200017 \n"
 447 "    STREQ   R0, [R4, #0x14] \n"
 448 "    BEQ     loc_FFAD968C \n"
 449 "    LDR     R0, [R4, #8] \n"
 450 "    ADD     R1, SP, #0x20 \n"
 451 "    STR     R0, [R4, #4] \n"
 452 "    ADD     R0, R4, #0x5C \n"
 453 "    BL      sub_FF82EA94 \n"
 454 "    CMP     R0, #1 \n"
 455 "    LDREQ   R0, [R4, #4] \n"
 456 "    STREQ   R6, [SP, #0x2C] \n"
 457 "    STREQ   R0, [SP, #0x28] \n"
 458 
 459 "loc_FFAD968C:\n"
 460 "    LDR     R0, [R5, #8] \n"
 461 "    CMN     R0, #1 \n"
 462 "    BEQ     sub_FFAD96C4 \n"
 463 "    LDR     R1, [R4, #0x58] \n"
 464 "    LDR     R7, =0x9200003 \n"
 465 "    CMP     R1, #1 \n"
 466 "    BNE     loc_FFAD96B0 \n"
 467 "    LDR R3, =current_write_ignored\n"
 468 "    LDR R3, [R3]\n"
 469 "    CMP R3, #0\n"
 470 "    BNE loc_D\n" // jump over the next block
 471 "    BL      sub_FF827464 \n"
 472 "    B       sub_FFAD96B4 \n"
 473 
 474 "loc_FFAD96B0:\n"
 475 "loc_D:\n"
 476 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 477 "    LDR     PC, =0xFFAD96B4 \n"  // Continue in firmware
 478 );
 479 }

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