Edit 27 Mar 2010A fix for these startup crashes is now in the main CHDK code (changeset 1106).
To enable this fix add '#define CAM_STARTUP_CRASH_FILE_OPEN_FIX 1' to the relevant section of camera.h (see g12 or sx30 for example).
Edit: From changeset 1141 you need to add the #define to the 'platform_camera.h' file in your cameras platform directory.
Testing shows that this appears to fix the startup problem for the G12, SX30is, SX110is and IXUS1000 cameras.
========================================================
Recently there have been a number of postings related to various cameras intermittently crashing on startup. Usually the camera shutsdown shortly after starting CHDK. A romlog dump usually shows that the error is coming from the FsIoNotify code in the firmware.
Having experienced this with the G12 and SX30 ports I'm posting this discussion to outline what I've found while investigating the problem. I think I've found a solution for these cameras (fingers crossed) and hope this may help others.
Initially I thought it was related to the calls to 'taskHook' during CHDK startup and some changes I made appeared to fix the problem on the G12 and SX30 - unfortunately this was not the case and the problem re-occurred a few days ago.
After dumping the romlog and working back through the stack trace and the build dump file I tracked the problem down to a call to the firmware 'Open' function to open the symbol font file (in rbf_load_symbol). This is called during startup from conf_restore.
The firmware 'Open' function on the G12 and SX30 is shown below:
ROM:FF873BFC Open ; CODE XREF: sub_FFB00988+20
ROM:FF873BFC ; sub_FFB00B44+AC
ROM:FF873BFC STMFD SP!, {R4-R8,LR}
ROM:FF873C00 MOV R5, R0
ROM:FF873C04 LDRB R0, [R0]
ROM:FF873C08 MOV R6, R2
ROM:FF873C0C MOV R4, R1
ROM:FF873C10 BL _sub_FF875690__DriveLetterManager.c__103 ; LOCATION: DriveLetterManager.c:103
ROM:FF873C14 MOV R7, R0
ROM:FF873C18 ORR R4, R4, #0x20000
ROM:FF873C1C MOV R1, #1
ROM:FF873C20 BL _sub_FF876A20__Mounter.c__0 ; LOCATION: Mounter.c:0
ROM:FF873C24 MOV R2, R6
ROM:FF873C28 MOV R1, R4
ROM:FF873C2C MOV R0, R5
ROM:FF873C30 BL open <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ROM:FF873C34 MOV R6, R0
ROM:FF873C38 MOV R2, R4
ROM:FF873C3C MOV R1, R5
ROM:FF873C40 BL _sub_FF8735FC__FsIoNotify.c__0 ; LOCATION: FsIoNotify.c:0
ROM:FF873C44 MOV R0, R7
ROM:FF873C48 BL _sub_FF876A98__Mounter.c__0 ; LOCATION: Mounter.c:0
ROM:FF873C4C MOV R0, R6
ROM:FF873C50 LDMFD SP!, {R4-R8,PC}
ROM:FF873C50 ; End of function Open
About two thirds of the way down this code is a call to 'BL open' - this is the IO library call to actually open the file. After this is another call to 'BL _sub_FF8735FC__FsIoNotify.c__0', and it's in this code that the actual crash is happening (via a call to DebugAssert).
The '_sub_FF8735FC__FsIoNotify.c__0' code takes the file handle returned from 'open' and attempts to store it into an array of data structures. At this stage I don't know exactly what the array is for; but it may be used to do buffered or asynchronous IO. The array only holds 10 entries and if the code can't find an empty slot it calls 'DebugAssert' which shuts down the camera.
What may be happening here is that there are already too many open files when the call to open the symbol font file is made, thus the camera shuts down. This could also explain why the problem is intermittent because the various startup tasks (both Canon and CHDK) will take different amounts of time depending on the card speed and what is on the card. So files will get opened and closed at different times.
In my case the G12 would crash more often if there were a lot of images or movies on the card when starting up, it would also crash more often on a partitioned 16GB card than it would on a single partition 4GB card.
Now if this array is used for some Canon buffered / asynch IO system then it's possible it isn't needed for CHDK. My idea is that it should be possible to use the 'open' function from CHDK instead of 'Open' (the one that 'Open' calls).
I've done this on the G12 and SX30 by changing the address of Open in the stubs_entry_2.s file and so far it does not seem to have caused any problems. CHDK on the cameras still seem to work ok and so far (touch wood) I have not had any more startup crashes.
Regards,
Phil.