I mentioned here
http://chdk.setepontos.com/index.php/topic,3368.msg35090.html#msg35090 I was going to take a look at formatting the boot partition from within CHDK. I thought I could maybe adapt some existing code, but I ended up writing it from scratch, using wikipedia and similar a lot
And now I have something to be tested
It's a fairly basic FAT12 formatter, but that is quite enough for small partitions like the boot partition (2 MB). This is a first step to be able to completely install a bootable CHDK once the first PS.FI? and DISKBOOT.BIN has been copied to the card from within the cam, yay
I tested the new code on my 8 GB SDHC card this way:
- Low level format card in camera to make sure nothing else would interfere. Card is now 8 GB FAT32.
- Unpack the "small" build of CHDK directly to the card using PC
- Start CHDK (Firmware update), "Create card with two partitions" (change name maybe to "Create boot partition?). CHDK now creates the boot partition as before, but also formats it using FAT12 and marks the partition bootable.
- Card back in PC, re-unpack small CHDK dist to the 2 MB partition, write protect card.
- Camera now boots on card
-> "Swap partition"
- Finally back in PC, format big partion, unpack full CHDK dist
- Firmware update start method one more time, "Swap partition".
There, no special card reader drivers nor manual boot sector hacking needed.
Here's the diff (against trunk 766)
http://nostalgia.suroot.com/chdk-a470-unofficial/patch-chdk-766-bootpart-fat12-formatting.txtSince the managers of CHDK may very well have opinions where I put the code and put it somewhere else (if it gets accepted), I didn't bother to change every single makefile for the platforms - just look at how it's done for a470. I first tried to put it in wrappers.c, but some platforms would bail out when trying a batchbuild (assembler errors, I think related to ARM 4k boundaries) so I had to put it in a separate object.
Thinking ahead, it would be VERY nice to read DISKBOOT.BIN to temporary RAM before re-partioning the card and then write it back to the bootable partition. That is definately possible, but writing an entire FAT FS handler would be lots of work and would make CHDK bigger than it has to be. It may be possible to have the camera work from the new partition table without rebooting though. After all, it does this when you low-level format the card. Then one could use the built in file handing to do all the copying (should be trivial) and skip all file copying with the PC above, except the very first one.
If one were to try to implement (safe) internal CHDK file handling without the camera knowing about the correct partition table, there would be a need for a _ReadSDCard. Has this been considered? Surely there must be a function in the firmware that reads raw sectors?
Finally, it's of course tempting to try writing a similar formatter for FAT16 (not so different, I think) and FAT32 (wee, entire card prepared without even rebooting, that would be really cool
)
Please do test and report, I have only tested my own a470 1.02c so far... If you happen to have a 470, prebuilt binaries are here:
http://nostalgia.suroot.com/chdk-a470-unofficial/(And, don't forget to backup your card
You WILL loose everything on it)
Have fun!
EDIT: Updated the makefiles etc after all (scripted it), bug fix in FAT allocation, root directory and volume label implemented. Test built binaries for all cams that have CAM_MULTIPART.
Test binaries:
http://nostalgia.suroot.com/chdk-build/bootpart-fat12formatNew patch (776)
http://nostalgia.suroot.com/chdk-build/bootpart-fat12format/patch-chdk-776-bootpart-fat12-formatting-v2.txt