CHDK Wiki
mNo edit summary
Tags: Visual edit apiedit
(24 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This is the procedure I used to compile CHDK (April 2007).
 
Look for the shorter alternative procedure at the end of this page.
 
   
  +
Termporary Notice : Starting in Oct 2015, directions for setting up the recommended compiler environment can be found here :
June 2007. I have modified the procedure to use gcc-3.4.6 and
 
  +
> http://chdk.setepontos.com/index.php?topic=12133.msg125084#msg125084
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.
 
   
 
== Getting the CHDK source ==
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.
 
   
  +
{{notice|These instructions use the development (1.3) branch. A stable branch (1.2) exists as well:
== Getting the source ==
 
 
> svn co https://tools.assembla.com/svn/chdk/branches/release-1_2 chdk
{{notice|CHDK source was split into two main streams effective Dec 26,2011. A stable stream was created as a branch and the main trunk became the development or unstable stream. References on this page are to the development or unstable stream. Change https://tools.assembla.com/svn/chdk to https://tools.assembla.com/svn/chdk/branches/release-1_0 to use the stable stream.}}
 
  +
}}
 
* Create a directory where to load the CHDK source code.
 
* Create a directory where to load the CHDK source code.
   
Line 37: Line 20:
   
 
> cd chdk && svn up
 
> cd chdk && svn up
  +
or
 
> svn up chdk
   
== Installing the cross compiler ==
+
== Installing a cross compiler ==
   
  +
Pre-built compilers can be found near the bottom of this page: http://forum.chdk-treff.de/download_dev.php, 32-bit only (use a VM). Using the "gcc 4.6.0" cross-compiler and the packages
{{Attention|There are alternate guides for setting up newer cross compilers here: [[gcc433 | gcc433]] and here [[Gcc452 | gcc452]]}}
 
  +
sudo apt-get install gcc-4.6 subversion make
  +
(ubuntu 13.10 i386, needed to make some tools on the build machine) with a symlink from /usr/bin/gcc-4.6 to /somewhere/on/your/PATH/gcc were able to successfully build trunk (Jan 2014).
  +
  +
Update (Jan 2014): Building trunk is successful, i.e.
 
make PLATFORM=a2200 PLATFORMSUB=100b clean
 
make PLATFORM=a2200 PLATFORMSUB=100b fir
  +
  +
 
== Compiling 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,
  +
 
export 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 <tt>PLATFORM</tt> and <tt>PLATFORMSUB</tt> arguments. For example:
  +
  +
> make PLATFORM=a620 PLATFORMSUB=100f fir
  +
  +
: Before compiling firmware for a different camera, the build directory may need to be cleaned. For example:
  +
  +
> make PLATFORM=a620 PLATFORMSUB=100f clean
  +
 
: To compile firmware for all cameras just type:
  +
 
> make batch-zip
  +
  +
----
  +
  +
== Building a cross compiler ==
  +
=== gcc 4.6.4 ===
  +
Instructions in the form of a bash script: [http://pastebin.com/hvG5nkQj gcc464]
  +
  +
This is working in Ubuntu 13.10 i386 (saucy) and Debian 6 x86_64 (sid) with prereqs
  +
sudo apt-get install gcc make texinfo ed
  +
  +
=== gcc 4.5.2 ===
  +
Instructions in the form of a bash script: [[Gcc452 | gcc452]]
  +
 
Well, this works fine on Ubuntu 8.04.2.
 
=== Alternative gcc 4.5.2 ===
  +
(Updated 23rd Nov 2013) Currently, mpfr.org seems to be unavailable. So download request mentioned in 24th Sep 2013 update won't work. You can download mpfr from [http://ftp.gnu.org/gnu/mpfr/ here].
  +
  +
  +
(Updated 24th Sept 2013)
 
[http://pastebin.com/eYe609dp Here] is a script to build the tool chain needed for building CHDK based on GCC 4.5.2.
  +
  +
Create a suitable folder to build GCC with something like mkdir ~/build-dir and save the script to this folder.
  +
  +
MPFR version 3.0.0 is no longer the current version, therefore you will need edit the script and change the following line...
  +
  +
wget -c http://www.mpfr.org/mpfr-current/$MPFR.tar.bz2
  +
  +
to
  +
  +
wget -c http://www.mpfr.org/mpfr-3.0.0/$MPFR.tar.bz2
  +
  +
Dont forget to chmod the script o+x so you can run it.
  +
  +
If you encounter any issues with the script, don't forget to post any fixes here.
  +
 
After building the tool chain you can now download and build CHDK:
  +
 
> export PATH=${HOME}/build-dir/arm/toolchain/bin:${PATH}
  +
> svn co https://tools.assembla.com/svn/chdk/trunk chdk
  +
> cd chdk
  +
> make PLATFORM=sx200is PLATFORMSUB=100c fir
  +
 
You may need to adjust the PATH to match the build folder you created above and the platform variable in last line to the model of your camera.
 
The ./bin/DISKBOOT.BIN need to be copied to your SD card.
 
If you want a PS.FI2 for auto booting, you need to follow ./platform/fi2.inc.txt to get ./bin/PS.FI2
 
after building CHDK.
  +
  +
Note: If you have pre-existing cross compilers (for example if you have been coding for your raspberry pi), you might need to alter you PATH variable to exclude the related paths (anything like /home/blah/sandbox/raspian/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin ) before you attempt to install GCC with the above script, otherwise you may end up with some very strange results.
  +
  +
=== gcc 4.3.3 ===
  +
Update Jan 2014: gcc-4.3.3 does not compile the current trunk. Use [[Gcc452 | gcc-4.5.2]] or higher.
  +
  +
Instructions in the form of a bash script: [[gcc433 | gcc433]]
  +
  +
=== gcc 3.4.6 ===
  +
Update Jan 2014: gcc-3.4.6 does not compile the current trunk. Use [[Gcc452 | gcc-4.5.2]] or higher.
   
 
Get the sources of gcc and binutils from a GNU repository. Decide where the cross compiler will be on your computer.
 
Get the sources of gcc and binutils from a GNU repository. Decide where the cross compiler will be on your computer.
Line 80: Line 155:
 
: That's it for the installation of the cross-compiler.
 
: That's it for the installation of the cross-compiler.
   
== Compiling the CHDK.==
+
=== Alternative gcc-3.4.6 ===
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 <tt>PLATFORM</tt> and <tt>PLATFORMSUB</tt> arguments. For example:
 
 
> make PLATFORM=a620 PLATFORMSUB=100f fir
 
 
: To compile firmware for all cameras just type:
 
 
> make batch-zip
 
== Alternative cross compilers. ==
 
=== Compiling CHDK on Ubuntu ===
 
See this forum thread : [http://chdk.setepontos.com/index.php?topic=8065.msg84880 Compiling CHDK on Ubuntu 11.10]
 
=== An alternative method with gcc-3.4.6 ===
 
 
There is a patch included in CHDK 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.
 
There is a patch included in CHDK 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.
   
Line 119: Line 169:
 
> ../configure --srcdir=../ --target=arm-elf && make && sudo make install
 
> ../configure --srcdir=../ --target=arm-elf && make && sudo make install
   
=== Compile and install GCC-3.4.6 ===
+
==== Compile and install gcc 3.4.6 ====
 
Download gcc-3.4.6, extract it and change to that directory.
 
Download gcc-3.4.6, extract it and change to that directory.
 
Patch the GCC source with the toolkit patch:
 
Patch the GCC source with the toolkit patch:
Line 135: Line 185:
 
You can now build the CHDK source as directed above
 
You can now build the CHDK source as directed above
   
===Compile and install GCC-4.5.2===
+
=== Older alternative gcc-3.4.6 ===
 
This is the procedure I used to compile CHDK (April 2007).
[http://pastebin.com/eYe609dp Here] is a script to build the tool chain needed for building CHDK
 
 
Look for the shorter alternative procedure at the end of this page.
based on GCC 4.5.2.
 
   
 
June 2007. I have modified the procedure to use gcc-3.4.6 and
After building the tool chain you can now download and build CHDK:
 
 
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'
> export PATH=${HOME}/build-dir/arm/toolchain/bin:${PATH}
 
 
branches, with success
> svn co https://tools.assembla.com/svn/chdk/trunk chdk
 
 
since April until I met a problem using the 'pow' function
> cd chdk
 
 
under 'trunk'. The 'grand' branch addresses the issue differently
> make PLATFORM=sx200is PLATFORMSUB=100c fir
 
 
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
You may need to adjust the platform variable in last line to the model of your camera.
 
 
two compilers. With gcc-4.1.2, the variable __arm__ is defined
The ./bin/DISKBOOT.BIN need to be copied to your SD card.
 
 
even when the compiler is called with option -mtumb;
If you want a PS.FI2 for auto booting, you need to follow ./platform/fi2.inc.txt to get ./bin/PS.FI2
 
 
with gcc-3.4.6 and the patch and option -mthumb, the variable
after building CHDK.
 
 
__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
===The Gentoo way===
 
 
aware of Vitaly's patch.
  +
  +
=== Buidling a cross compiler on Ubuntu ===
  +
Update Jan 2014: The links in the forum post are dead.
  +
 
See this forum thread : [http://chdk.setepontos.com/index.php?topic=8065.msg84880 Compiling CHDK on Ubuntu 11.10]
  +
  +
=== Buidling a cross compiler on Gentoo ===
   
 
Gentoo Linux contains a nice utility to automate this process. Emerge '''sys-devel/crossdev''' and run
 
Gentoo Linux contains a nice utility to automate this process. Emerge '''sys-devel/crossdev''' and run
Line 158: Line 223:
 
PATH&nbsp;:= /usr/i686-pc-linux-gnu/arm-elf/binutils-bin/2.18/:/usr/i686-pc-linux-gnu/arm-elf/gcc-bin/4.4.1/:${PATH}
 
PATH&nbsp;:= /usr/i686-pc-linux-gnu/arm-elf/binutils-bin/2.18/:/usr/i686-pc-linux-gnu/arm-elf/gcc-bin/4.4.1/:${PATH}
   
===GCC 4.x===
+
=== Success reports ===
 
{{notice|'''A gcc 4.3.1-binutils 2.18 environment kit for Linux was available from here: [http://drop.io/chdkdev/asset/linux-env-gcc-4-3-1-binutils-2-18-by-hacky-tar-lzma chdhdev drop] but the link is dead''' <br/>This is the environment running on the CHDK autobuild server (19-Jan-2009), it's compiled under debian etch}}
 
 
Well, this works fine on Ubuntu 8.04.2.
 
About using the latest Gcc-4.3.3 take a look at this [[Gcc433|article]].
 
 
===Success reports===
 
   
 
- binutils-2.22 and gcc-4.5.3 on Gentoo ~amd64 (using sys-devel/crossdev)
 
- binutils-2.22 and gcc-4.5.3 on Gentoo ~amd64 (using sys-devel/crossdev)
Line 171: Line 229:
 
- binutils-2.23 and gcc-4.5.4 gcc-4.6.3 gcc-4.7.2 (latest needs --enable-obsolete to allow arm-elf binary format) OpenSUSE amd64
 
- binutils-2.23 and gcc-4.5.4 gcc-4.6.3 gcc-4.7.2 (latest needs --enable-obsolete to allow arm-elf binary format) OpenSUSE amd64
   
===Python GUI===
+
=== Python GUI ===
 
{{notice|''' An GUI written in python is available here [http://dl.dropbox.com/u/4997718/testing.zip for download]}}
 
{{notice|''' An GUI written in python is available here [http://dl.dropbox.com/u/4997718/testing.zip for download]}}
   
 
cd directory/where/compiler/is
 
cd directory/where/compiler/is
 
python chdk_linux_compiling_gui.py
 
python chdk_linux_compiling_gui.py
The rest schould be self-explaining.
+
The rest should be self-explaining.
   
Mor info can be found in the german forum:
+
More info can be found in the german forum:
   
http://forum.chdk-treff.de/viewtopic.php?f=1&t=1829
+
[http://forum.chdk-treff.de/viewtopic.php?f=1&t=1829 http://forum.chdk-treff.de/viewtopic.php?f=1&t=1829]
   
 
Use google translate if you can't read german.
 
Use google translate if you can't read german.

Revision as of 20:58, 13 February 2016

Termporary Notice : Starting in Oct 2015, directions for setting up the recommended compiler environment can be found here : > http://chdk.setepontos.com/index.php?topic=12133.msg125084#msg125084


Getting the CHDK source

Notice

These instructions use the development (1.3) branch. A stable branch (1.2) exists as well:

> svn co https://tools.assembla.com/svn/chdk/branches/release-1_2 chdk 
  • Create a directory where to load the CHDK source code.
 > mkdir ~/chdk && cd ~/chdk
  • Get the CHDK source code.
 > svn co https://tools.assembla.com/svn/chdk/trunk chdk
  • and update the source code every now and then:
 > cd chdk && svn up

or

 > svn up chdk

Installing a cross compiler

Pre-built compilers can be found near the bottom of this page: http://forum.chdk-treff.de/download_dev.php, 32-bit only (use a VM). Using the "gcc 4.6.0" cross-compiler and the packages

sudo apt-get install gcc-4.6 subversion make

(ubuntu 13.10 i386, needed to make some tools on the build machine) with a symlink from /usr/bin/gcc-4.6 to /somewhere/on/your/PATH/gcc were able to successfully build trunk (Jan 2014).

Update (Jan 2014): Building trunk is successful, i.e.

make PLATFORM=a2200 PLATFORMSUB=100b clean
make PLATFORM=a2200 PLATFORMSUB=100b fir


Compiling 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,
 export 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
Before compiling firmware for a different camera, the build directory may need to be cleaned. For example:
 > make PLATFORM=a620 PLATFORMSUB=100f clean
To compile firmware for all cameras just type:
 > make batch-zip

Building a cross compiler

gcc 4.6.4

Instructions in the form of a bash script: gcc464

This is working in Ubuntu 13.10 i386 (saucy) and Debian 6 x86_64 (sid) with prereqs

sudo apt-get install gcc make texinfo ed

gcc 4.5.2

Instructions in the form of a bash script: gcc452

Well, this works fine on Ubuntu 8.04.2.

Alternative gcc 4.5.2

(Updated 23rd Nov 2013) Currently, mpfr.org seems to be unavailable. So download request mentioned in 24th Sep 2013 update won't work. You can download mpfr from here.


(Updated 24th Sept 2013) Here is a script to build the tool chain needed for building CHDK based on GCC 4.5.2.

Create a suitable folder to build GCC with something like mkdir ~/build-dir and save the script to this folder.

MPFR version 3.0.0 is no longer the current version, therefore you will need edit the script and change the following line...

wget -c http://www.mpfr.org/mpfr-current/$MPFR.tar.bz2

to

wget -c http://www.mpfr.org/mpfr-3.0.0/$MPFR.tar.bz2

Dont forget to chmod the script o+x so you can run it.

If you encounter any issues with the script, don't forget to post any fixes here.

After building the tool chain you can now download and build CHDK:

> export PATH=${HOME}/build-dir/arm/toolchain/bin:${PATH}
> svn co https://tools.assembla.com/svn/chdk/trunk chdk
> cd chdk
> make PLATFORM=sx200is PLATFORMSUB=100c fir

You may need to adjust the PATH to match the build folder you created above and the platform variable in last line to the model of your camera. The ./bin/DISKBOOT.BIN need to be copied to your SD card. If you want a PS.FI2 for auto booting, you need to follow ./platform/fi2.inc.txt to get ./bin/PS.FI2 after building CHDK.

Note: If you have pre-existing cross compilers (for example if you have been coding for your raspberry pi), you might need to alter you PATH variable to exclude the related paths (anything like /home/blah/sandbox/raspian/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin ) before you attempt to install GCC with the above script, otherwise you may end up with some very strange results.

gcc 4.3.3

Update Jan 2014: gcc-4.3.3 does not compile the current trunk. Use gcc-4.5.2 or higher.

Instructions in the form of a bash script: gcc433

gcc 3.4.6

Update Jan 2014: gcc-3.4.6 does not compile the current trunk. Use gcc-4.5.2 or higher.

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

Note: About using the latest Gcc-4.3.3 take a look at this article.

 > cd binutils-2.17
 > ./configure --srcdir=../binutils-2.17 --target=arm-elf \
     --prefix=${HOME}/arm-elf --disable-werror
 > make
 > make install
 > cd ..
Apply Vitaly's patch to the compiler.
 > (cd gcc-3.4.6 && patch -p0 <~/chdk/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.

Alternative gcc-3.4.6

There is a patch included in CHDK 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_chdk]/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 CHDK source as directed above

Older alternative gcc-3.4.6

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.

Buidling a cross compiler on Ubuntu

Update Jan 2014: The links in the forum post are dead.

See this forum thread : Compiling CHDK on Ubuntu 11.10

Buidling a cross compiler on Gentoo

Gentoo Linux contains a nice utility to automate this process. Emerge sys-devel/crossdev and run

crossdev -t arm-elf -s1 --without-headers --binutils 2.18-r4

This commands should compile and merge the latest gcc and binutils 2.18 (the latest binutils-2.19.1 doesn't work with chdk). Look at the versions at $PORTDIR_OVERLAY/cross-arm-elf/binutils/
The first line in makefile.inc should look then like this:

PATH := /usr/i686-pc-linux-gnu/arm-elf/binutils-bin/2.18/:/usr/i686-pc-linux-gnu/arm-elf/gcc-bin/4.4.1/:${PATH}

Success reports

- binutils-2.22 and gcc-4.5.3 on Gentoo ~amd64 (using sys-devel/crossdev)

- binutils-2.23 and gcc-4.5.4 gcc-4.6.3 gcc-4.7.2 (latest needs --enable-obsolete to allow arm-elf binary format) OpenSUSE amd64

Python GUI

Notice

An GUI written in python is available here for download


cd directory/where/compiler/is
python chdk_linux_compiling_gui.py

The rest should be self-explaining.

More info can be found in the german forum:

http://forum.chdk-treff.de/viewtopic.php?f=1&t=1829

Use google translate if you can't read german.