Interesting. I haven't yet been able to make it work from canon basic, which was actually my main goal in this project. I can load the file, register an event proc to and call it but the camera hangs (not crash or assert,) before reaching CHDK loader/<camera>/entry.s
The canon code (for diskboot and fi2 update) does disable interrupts before calling this function, but I don't do it in the lua version so I'm not sure why it would be required here. There could also be cache/write buffer issues, although I'd expect the verify step to cause pretty much everything to get flushed out.
I know I have event proc registration working, because I can register sprintf under a different name and it works fine.
It's important to remember that this does NOT do the normal camera shutdown sequence. This means
- hardware may not be in the state expected on restart. This could cause abnormal behavior or maybe even damage.
- recently changed camera settings might not be saved to flash (taskBye does some write to rom stuff)
- filesystem stuff may not synced to SD. However, you generally don't lose much in abnormal shutdowns (assert, exception etc) that aren't in the middle of actually writing something, so this should be OK, especially if you switch to play mode before doing the reboot. Switching to play recommended anyway, since I'd expect more of the hardware to be in an off or idle state.
For CHDK, it might be better to copy taskBye and replace the last bit with the load and restart code. Or hook it, and check a global to decide if a reboot or actual shutdown is requested.
I believe the verify stuff just checks the the copied data matches. This could fail if interrupts aren't disabled (because some ram could get modified) or the source and destination overlap. From CHDK, the memory should not overlap, since almost the entire CHDK image has to fit before the start of heap. Loading from canon basic without CHDK, overlapping might be a problem, but can probably be worked around. If verify fails, it does go into a tight loop, which would match the symptoms I'm seeing.