CHDK Wiki
Advertisement

This is the procedure I used to compile CHDK (April 2007). Look for the shorter alternative procedure at the end of this page.

June 2007. I have modified the procedure to use gcc-3.4.6 and Vitaly's patch in place of gcc-4.1.2. The reason for the change is that there is an issue with 'endianness' and floating point numbers that is addressed by Vitaly's patch.

I compiled the CHDK with gcc-4.1.2, both 'trunk' and 'grand' branches, with success since April until I met a problem using the 'pow' function under 'trunk'. The 'grand' branch addresses the issue differently and the floating point code worked fine under the 'grand' branch when compiled with gcc-4.1.2.

There is a 'minor' difference of behavior between the two compilers. With gcc-4.1.2, the variable __arm__ is defined even when the compiler is called with option -mtumb; with gcc-3.4.6 and the patch and option -mthumb, the variable __arm__ is not defined but variable __thumb__ is. The CHDK file 'include/lowlevel.h' is sensitive to that difference of behavior.

The reason I used gcc-4.1.2 in the first place is that I was not aware of Vitaly's patch.

  • Create a directory where to load the CHDK source code.
 > mkdir ~/chdk && cd ~/chdk
  • Get the CHDK source code.
 > svn co http://tools.assembla.com/svn/chdk/trunk

or

 > svn co http://tools.assembla.com/svn/chdk/branches/grand
  • Or update the source code
 > cd grand && svn up
  • Install the cross compiler
Get the sources of gcc and binutils from a GNU repository.
Decide where the cross compiler will be on your computer.
 > mkdir ~/arm-elf
Tell your computer you are going to run programs from that location.
 > export PATH=${HOME}/arm-elf/bin:$PATH
Create a working area and build binutils and gcc.
 > mkdir ~/wa
 > cd ~/wa
 > tar xvfj ~/src/binutils-2.17.tar.bz2
 > tar xvfj ~/src/gcc-3.4.6.tar.bz2
 > cd binutils-2.17
 > ./configure --srcdir=../binutils-2.17 --target=arm-elf \
     --prefix=${HOME})/arm-elf
 > make
 > make install
 > cd ..
Apply Vitaly's patch to the compiler.
 > (cd gcc-3.4.6 && patch -p0 <~/chdk/grand/tools/patches/gcc-3.4-arm.diff)
 > mkdir gcc-3.4.6-arm-elf && cd gcc-3.4.6-arm-elf
 > ../gcc-3.4.6/configure --srcdir=../gcc-3.4.6 --target=arm-elf \
    --enable-multilib --enable-languages=c --enable-clocale=gnu \
    --disable-libm --disable-libc --disable-threads \
    --disable-nls --disable-libssp --disable-intl --disable-libiberty \
    --with-cpu=arm9 --with-newlib --prefix=${HOME}/arm-elf
 > (unset LIBRARY_PATH; unset CFLAGS; make && make install)
That's it for the installation of the cross-compiler.
  • Compiling the CHDK. Go to either 'trunk' or 'grand'.
 > cd ~/chdk/grand
Manually edit file <makefile.inc> to select PLATFORM and PLATFORMSUB for your camera: just remove the "#" comment characters. Also, add the following line at the beginning of file <makefile.inc> to tell CHDK where the arm cross compiler is,
 PATH := ${HOME}/arm-elf/bin:${PATH}
You should be ready to compile everything.
 > make fir
The results are left in the "bin" directory.
If you want to compile firmware for an another camera, just execute make with PLATFORM and PLATFORMSUB arguments. For example:
 > make PLATFORM=a620 PLATFORMSUB=100f fir
To compile firmware for all cameras just type:
 > make batch-zip


An alternative method with gcc-3.4.6

There is a patch included in HDK for building with gcc-3.4.6. It's a simpler install if you want to use this version of gcc. This method uses a global install of the arm-elf tools.

Remember to clear any CFLAGS you've got set:

 > export CFLAGS=""

Compile and install binutils

Extract the source, change to its directory, and

 > mkdir binutils-2.17-arm-elf
 > cd binutils-2.17-arm-elf/
 > ../configure --srcdir=../ --target=arm-elf && make && sudo make install

Compile and install GCC-3.4.6

Download gcc-3.4.6, extract it and change to that directory. Patch the GCC source with the toolkit patch:

 > patch -p0 < [path_to_hdk]/grand/tools/patches/gcc-3.4-arm.diff
Build the source:
 > mkdir gcc-arm-elf
 > cd gcc-arm-elf/ 
 > ../configure --srcdir=../ --target=arm-elf --with-cpu=arm9 \
   --with-newlib --enable-multilib  --enable-languages=c \
   && make && sudo make install

You can now build the HDK source as directed above

Advertisement