CHDK Wiki
Advertisement
Notice

Utilities to automate the preparation an SD card are available.

Cardtricks, running on Windows, supports SD cards of 4G bytes or less, as described here.

To make any size SD card bootable under Windows, follow the instructions at SDM Quick Start using sdminste.exe (StereoData Maker Installer) in common_files.zip downloaded from SDM Downloads and Updates.

To make a card bootable on a Mac - use the SDMInst app as described in FAQ/Mac


An Overview of the Boot Process

If manually loading CHDK, the "PS.FIR" or "PS.FI2" file is found and run when the user selects to do a firmware update from the menus.

When booting ("auto-loading") CHDK, the camera powers up, then checks the volume boot sector of the first partition for the signature string "BOOTDISK", and whether the SD card is locked (the card must be locked, or the boot process will not happen). This signature is stored starting at offset 0x40 (decimal 64) on a FAT16 volume. This location is used for other things on a FAT32 volume, which is why such volumes cannot be booted. If the signature is found, the file "DISKBOOT.BIN" is loaded and run. This file runs the CHDK program. When it loads, CHDK will unlock the SD card, so that images may be stored.

Since booting only works on FAT16 volumes, and the maximum size for FAT16 is 4GB (and that's non-standard), booting from an SD card larger than 4GB is more complicated.

By dividing a >4GB card into multiple partitions (volumes), one can have a small FAT16 partition (500K) from which to boot, and a much larger FAT32 volume using the rest of the SD card for storing images. When using this method, the FAT16 partition must be the first one in the partition table. When it loads, CHDK will logically swap the partitions after loading, so the camera only sees the larger one. Because of this, only the DISKBOOT.BIN file needs to be located in the smaller partition - all the other CHDK files need to be located on the larger partition. Failing to do this will mean the CHDK logo will not display at boot, menu icons will not appear and things like fonts and test scripts will not be available.

SD cards do not normally contain multiple partitions. Some operating systems, particularly Windows, do not have drivers which can properly handle SD cards with multiple partitions. Windows will only see the first partition on an SD card. Because of this, the partitions need to be "swapped" before using a card in Windows if one wishes to transfer images directly. The CHDK debug menu has an option which will do this. When moving the card back to the camera, you will have to manually start CHDK via the firmware update method (because the camera will only see the FAT32 partition, so it won't boot), and do a swap again. Alternatively, tools like sdminste.exe can be used to swap the partitions on the PC before returning the card to your camera.

It should also be noted that doing a card format in the camera will format the entire card into one volume, removing CHDK in the process.

How to prepare the SD card for booting the DISKBOOT.BIN file

  • Format the card to FAT16 with a desktop computer via a USB card reader and create the DCIM and MISC folders on the newly formatted card. Alternatively, you can format your card with the camera, which in some models creates a FAT16 filesystem. (Note that the Canon SX200 IS, firmware version 1.00D formats the SD card to FAT32.  Therefore formatting the SD card in an SX200 IS will not give you a partition from which CHDK can be booted, and you must use the terminal commands on a PC).   You can check how an SD card has been formatted by running the "strings" Unix command on the volume, and looking at the output for FAT16 or FAT32.
  • Important: Due to the limitations of FAT16 this will not work with cards bigger than 4G!

Under MacOS X Leopard, the following series of steps will work:

  • Load your SD card in a card reader (unless your camera appears as a disk drive when you connect it)
  • Open Disk Utility and highlight the volume. Click "Info" and look for "Disk Identifier". For me, it was /dev/disk2s1
  • close the Info window
  • With the volume highlighted (not the "drive"), click "Unmount".
  • From a Terminal command line, run a command like this:
sudo newfs_msdos -F 16 -v MYSDCARD -b 4096 -c 128 /dev/disk2s1

If you get an error on the Mac command line after running this command like "newfs_msdos: warning: /dev/disk2s1 is not a character device" go ahead and re-mount the drive in the Apple Disk Utility. The drive should still show up as a FAT 16 drive, you can then continue.


Note: Newer cards typically use the FAT32 filesystem, because FAT16 tops out at 4 GB. CHDK cannot boot from a FAT32 filesystem. If your card is larger than 4 GB, you must create TWO partitions on the card: a small FAT16 (or FAT12) partition for booting CHDK, and a large FAT32 one for storing everything else. Some details:

  • The small FAT16 (or FAT12) partition must be the first partition on the card.
  • Both partitions must be "primary" partitions (i.e. no "logical" or "extended" partitions).
  • The FAT16 (or FAT12) partition doesn't have to be larger than 1 or 2 MB (the only files it needs to hold are DISKBOOT.BIN and possibly PS.FIR). The FAT32 partition should, naturally, occupy the rest of the card.
NOTE: You may get an error from mkdosfs after creating such a FAT16-Partition with 2 MB saying that it is too small for a FAT16 filesystem and would probably be mis-recognised as a FAT12 Partition; you can either create a FAT12 partition instead or just raise the size to 10 MB and everything will work well.
  • The small FAT16/FAT12 partition can be made bootable following the instructions below.
  • Once CHDK is loaded, it will direct the camera to use the larger FAT32 partition for all storage operations. The small FAT16/12 partition will become inaccessible after this, because CHDK and the camera can only handle one partition at a time. What this means is that you should place all the script/data/etc. files on the large partition, not the small one!

Windows: Case #1

  • Download the HDHacker utility to execute the following steps.
  • Install and run the HDHacker.
  • Select the proper drive letter corresponding to your SD card in the card reader.
  • Select "logical drive" and "first sector" (as far as I know, it's the default)
  • "Read sector from disk"
  • Save this sector to a file for safety (512 bytes) (I named it: BootSector_G9.bin)
  • Use a hex editor to edit this file
  • Go to offset 0x40 (decimal 64) and type BOOTDISK in ASCII mode (as explained here). Keep in mind that, if you do not see FAT12 or FAT16 around 0x36 (decimal 54) in the hex editor, you probably picked the wrong drive. Do not overwrite anything in that case.
  • Save it as a different file (I named it: BootSector_G9_bootable.bin)
  • Use HDHacker to "load sector from file" this new file containing BOOTDISK information onto your SD card
  • "write sector on disk" Don't forget to select the correct drive letter!

Windows: Case #2

  • Extract from above bootable.zip the "bootable.exe" file
  • Put your SD card into reader or SD slot in computer and copy "bootable.exe" to the SD card
  • SD card behaves as disk and has assigned some letter (for example "F:"). Run shell (on winXP: menu Start - Run..., type "cmd") and change to SD card (by typing "F:" and press Enter in this example case)
  • Run "bootable.exe" You will be prompted to give right syntax as "bootable.exe F:"
  • Confirm and your SD card is bootable (Note: Doesn´t work with SanDisk Ultras "USB-Edition"!)

Windows: Case #3

Use CardTricks GUI Utility created by whim THX. For more info read Forum post here.

Windows: Case #4

If you have a SDHC card that is bigger than 4Gb you have to create two partitions on the card. This can now be done entirely on the camera thanks toThorwak's great modification and guide. Here is how to do it, more or less copied from his guide:

  • Low level format card in camera. The card now contains one FAT32 partition.
  • Unpack the small build of CHDK directly to the card using PC.
  • Start CHDK manually (Firmware update).
  • Enter the CHDK menu, and select Miscellaneous stuff -> Debug Parameters -> Create card with two partitions. CHDK now creates the boot partition as before, but also formats it using FAT12 and marks the partition bootable. (not available on all ports)
  • Put the card back in PC. If necessary, format the newly created 2MB partition. Re-unpack small CHDK to this partition.
  • Write protect the card (there is usually a switch on the side of the card; move it to the locked position).
  • The camera should now boot off of the card.
  • Enter the CHDK menu, and select Miscellaneous stuff -> Swap partitions.
  • Unlock the card, and put it back in the PC. Now format the large partition, and unpack full CHDK onto it.
  • Lock the card and put it back in the camera.
  • Start CHDK manually (Firmware update) one more time, and select Miscellaneous stuff -> Swap partitions.

Congratulations, now your camera should boot from CHDK automatically!

Caveats: Windows does not seem to be able to access both partitions at once. You will have to run Swap partitions before you take the card out of the camera so windows can access your photos, then repeat the last step after you put the card back in to make it boot CHDK automatically. To me, this is much better than having to start CHDK manually every time you turn on the camera!

IMPORTANT NOTE: This does not work on ANY official build, since the patch never made it into the main source. This whole method relies on using mostly untested, and very old, unofficial builds. I would advice against using this method until officially supported by CHDK (someone needs to "pick up the ball" for this to happen). Also, the test builds and diff won't be around forever anyway. /Thorwak

Additional step might be required (IXUS 70 / SD1000 user):
After Create card with two partitions above, I needed an additional step on the PC, as Windows (7) wanted to format the card. I cancelled all those Windows alerts. Instead I ran CardTricks:
1) selected card drive (again ignoring Windows formatting alert)
2) Format as FAT
3) Make Bootable
Then continued with the remaining steps (starting with re-unpacking CHDK small), which then worked fine.

Windows: Case #

Use EOScard GUI Utility to write or change signature string on first Partition (like BOOTDISK).

Linux + Windows:

The best simple way if you have card bigger than 4Gb:

If you have a SDHC card that is bigger than 4Gb you have to create 2 partions on the card.

LINUX:

Install 'gparted ->create two partitions FAT16 (16MB) and other amount with FAT32 for IMAGES

WINDOWS:

Use CardTricks GUI Utility created by whim THX. For more info read Forum post here. Windows will not be able see second partition so you can use mentioned utility for formating only 16MB FAT16 partition

(Tested and working on UBUNTU 11.4 and Windows XP)

Linux:

The simple way:

Case 1: SDHC card no bigger than 4Gb. Create partition and set the type to FAT16 (partition type id 6 in fdisk). Continue making the card bootable.

Case 2: Larger SDHC Cards If you have a SDHC card that is bigger than 4Gb you have to create 2 partions on the card. The first has to be formatted with FAT16 and will hold the CHDK files for booting (16MB is enough). The second partition has to be formated with FAT32 and will hold the images. The simplest way to do this in Linux is to install gparted. With this great GUI based partition manager you can set up the partitions. Within gparted, set the "boot" flag for the first partition. It will not work without this. Note: Windows will not be able to see the second partition holding the pictures unless you do some modification to partition table. Instructions are at the bottom.

Insert the card before starting gparted. If you find the 'fat16'menu option greyed out in the 'format to' menu, you may need to install dosfstools in the package manager (in this case you may also have to restart gparted).

Remember to hit 'apply all operations' in the edit menu to apply the changes you made to the card before exiting gparted.

Making the card bootable

To make the first partition bootable apply one of the steps below. I used:

echo -n BOOTDISK | dd bs=1 count=8 seek=64 of=/dev/sdx1

Its short, simple and from gparted you already know the correct location of your card (/dev/sdb1 or b2 or a1 or a2 ....)

(Yes, that "BOOTDISK" is a literal string.). Also giving dmesg just after you inserted will show you your SD card device name e.g. look for a line sometine like [ 9888.596295] sdb: sdb1 then sdb1 is your device

General:

  • Start a terminal, if you haven't done so already
  • Determine the location of your card, it is usually something like /dev/sdx. If the card is mounted, you can determine the location from the mount command. Make sure you pick the right one! Replace the x in /dev/sdx appropriately.
  • Make sure your card is unmounted (umount /dev/sdx1)
  • Now, you need to alter the partition's bootsector. There are two ways to do this. This guide assumes hexedit is used, though you can use any hex editor. Keep in mind that, if you do not see FAT12 or FAT16 around 0x36 (decimal 54) in the hex editor, you probably picked the wrong drive. Do not overwrite anything in that case. If you see FAT32, you will have to reformat the card in FAT16 - this can be easily done with mkdosfs -F 16 /dev/your_card_partition. Make sure to copy all the needed images off the card before doing this.
    1. Directly
      • Open your SD card's FAT partition in hexedit: hexedit /dev/sdx1
      • Go to offset 0x40 (decimal 64) and type BOOTDISK in ASCII mode.
      • Save (Ctrl-X in hexedit) and quit.
    2. Directly (without hexedit)
      • echo -n BOOTDISK | dd bs=1 count=8 seek=64 of=/dev/sdx1 (if you get "dd: /dev/sdx1 Permission denied" put "sudo " before dd)


    1. Indirectly
      • First, extract the bootsector like this: dd if=/dev/sdx1 of=BootSector_G9.bin bs=512 count=1
      • Copy the saved file, so you have a backup: cp BootSector_G9{,_bootable}.bin
      • Open the copy in a hex editor: hexedit BootSector_G9_bootable.bin
      • Go to offset 0x40 (decimal 64) and type BOOTDISK in ASCII mode.
      • Save (Ctrl-X in hexedit) and quit.
      • Upload the bootsector to the card again: dd if=BootSector_G9_bootable.bin of=/dev/sdx1 bs=512 count=1
    2. Indirectly (without hexedit, assuming bash)
      • First, extract the start of the bootsector like this: dd if=/dev/sdx1 of=BS.bootable bs=64 count=1
      • Next, append the required name: echo -n BOOTDISK >> BS.bootable
      • Finally, append the rest: dd if=/dev/sdx1 bs=1 skip=72 count=$[512-72] >> BS.bootable
      • Upload the bootsector to the card again like in the former example: dd if=BS.bootable of=/dev/sdx1 bs=512
    3. Indirectly with script (szymonolko_a_t_o2.pl)
      • Save below lines as script
      • Run it with one argument which is the partition to be made bootable, eg. make.bootable /dev/mmcblk1p1
#!/bin/bash
DEV=$1
if [[ -z "${DEV}" ]]
then
   echo "Usage: $0 partition"
   exit 1
fi
dd if=${DEV} of=1.tmp.bin bs=64 count=1
echo "BOOTDISK" > 2.tmp
dd  if=2.tmp of=2.tmp.bin bs=8 count=1
rm 2.tmp
#512-64-8=440
dd if=${DEV} of=3.tmp.bin skip=9 bs=8 count=55
cat 1.tmp.bin 2.tmp.bin 3.tmp.bin > bootable.bin
rm 1.tmp.bin
rm 2.tmp.bin
rm 3.tmp.bin
dd if=bootable.bin of=${DEV} bs=512 count=1
rm bootable.bin

or

#!/bin/bash
[ "$1" ] || { echo "Usage: $0 partition"; exit 1; }
dd if="$1" of=bootable.bin bs=512 count=1
echo -n "BOOTDISK" | dd of=bootable.bin bs=1 count=8 seek=64 conv=notrunc
dd if=bootable.bin of="$1" bs=512 count=1
rm bootable.bin


Making second partition visible for Windows:

Assuming your memory card is /dev/sdX

  1. Open fdisk
    1. fdisk /dev/sdX
  1. Create an empty dos partition table.
    1. o <enter>
  2. Create sdX1 and sdX2 as primary partitions:
    1. n <enter> p <enter> 1 <enter> 1 <enter> +10M <enter>
    2. n <enter> p <enter> 2 <enter> <enter> <enter>
  3. Change sdX1 -> fat16, sdX2 -> fat32
    1. t <enter> 1 <enter> 6 <enter>
    2. t <enter> 2 <enter> b <enter>
  4. Write changes to disk & exit
    1. w <enter>
  5. Make filesystems
    1. mkdosfs /dev/sdX1; mkdosfs -F32 /dev/sdX2
  6. Make the sdX1 bootable (see instructions above)
  7. Look at the partition layout for /dev/sdX1
    1. fdisk -l /dev/sdX
    2. Note the numbers under the "Start", "#sectors", and "Id" parameters
    3. Example output:
      1. Device Boot Start End #sectors Id System
        /dev/sdd1 32 18431 18400 6 FAT16
        /dev/sdd2 18432 31115263 31096832 b W95 FAT32
        /dev/sdd3 0 - 0 0 Empty
        /dev/sdd4 0 - 0 0 Empty
  8. use sfdisk to create sdX3 as clone of sdX1
    1. sfdisk -uS -N3 -f /dev/sdX
    2. Use the numbers you wrote down in the last step for sdX1.
    3. {start} {#sectors} {id} <enter>
      1. From the example output: type "32 18400 6" and press <enter>
  9. Note: It will warn you that partitions 1 and 3 overlap. This is normal. Type "y" confirming that you want to run the command.
    1. y <enter>
  10. Change partition id of sdX1 to extended
    1. sfdisk --id /dev/sdX 1 5


Credit from above instructions to cg at http://chdk.setepontos.com/index.php/topic,255.30.html

Mac

More complete directions - FAQ/Mac

    1. If you have darwin ports installed, the instructions for the Linux direct method also work for the Mac, provided you have darwin ports installed
      • Go to MacPorts website and install MacPorts [1]
      • type sudo port install hexedit to install hexedit
      • type man hexedit to familiarize yourself with the commands of hexedit
      • Open Disk Utility and click on the image for the SD card - click on "Get Info" to determine the location of the partition (such as disk4s1)
      • Use Disk Utility to unmount the partition
      • in a terminal window, type sudo hexedit /dev/disk4s1. Press enter (that's fn+return on some keyboards). Type in '40' to go to offset 0x40. Hit enter. Hit "tab" to switch to typing on the ASCII side. Type "BOOTDISK". Hit control-X and type "Y" when prompted to save.
    2. If you don't want to install darwinports and hexedit, you can also use the free 0xED [2], or Hex Fiend, which will work with the indirect way as well. This may be the simplest way for a Mac user to get a bootable SD disk.
      • Go to the Disk Utility. Select your SD card from the list at the left, and click Informations to get the disk identifier (example: disk4s1). Use this in the steps below
      • Using Disk Utility, unmount (don't eject!) your SD card.
      • Open a Terminal window and type: dd if=/dev/disk4s1 of=BootSector_G9.bin bs=512 count=1. This copies a sector of the SD card to your Mac's hard disk.
      • The BootSector_G9.bin file in your Home directory contains your SD card's boot sector. Make a backup of it in case anything goes wrong.
      • Open BootSector_G9.bin with 0xED. Keep in mind that, if you do not see FAT12 or FAT16 around 0x36 (decimal 54) in the hex editor, you probably picked the wrong drive. Do not overwrite anything in that case.
      • If the file is correct, select the Overwrite writing method (Command+Shift+O).
      • Go to offset hex 40 (decimal 64) and press Tab. Type BOOTDISK. Save and quit.
      • In your Terminal window, type: dd if=BootSector_G9.bin of=/dev/disk4s1 bs=512 count=1. This copies the modified file to the boot sector of your SD card.
      • Using Disk Utility, mount the card.
      • Copy the file DISKBOOT.BIN to the SD card. Make sure to use the correct version for your model of Canon camera.
      • Eject the SD card. Slide the tab to the LOCK position

It is necessary to LOCK the SD card to load the CHDK software. In locked mode and booted into CHDK, you are still able to save your pictures on the card!

Now you have a Bootable SD card. The camera will now attempt to load the DISKBOOT.BIN file whenever the camera is started with that SD card (when it's locked).


For FAT32 and ExFAT (FAT64) see also:

successfully tested on DSLR and 'autoexec.bin', with bootflag enabled

Advertisement