CHDK Wiki
(Added Information for subversion login.)
 
(25 intermediate revisions by 6 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.
 
   
 
== Getting the CHDK source ==
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.
 
   
  +
The CHDK source is available from the official [https://subversion.apache.org/ subversion] repository. To get the current development source into a directory called chdk in your home directory use
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.
 
   
 
svn co http://subversion.assembla.com/svn/chdk/trunk ~/chdk
There is a 'minor' difference of behavior between the
 
  +
''(When subversion.assembla.com requires a login, use anything, e.g. "guest"/"guest".)''
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.
 
   
  +
Stable releases are available in branches named like /svn/chdk/branches/release-N_M
The reason I used gcc-4.1.2 in the first place is that I was not
 
aware of Vitaly's patch.
 
   
  +
To update your source tree with changes added by the CHDK developers after your initial checkout, use
== Getting the source ==
 
{{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.
 
   
> mkdir ~/chdk && cd ~/chdk
+
svn up ~/chdk
   
  +
Subversion is generally available from your distro package manager. For more information about subversion usage, see the [http://svnbook.red-bean.com/ documentation].
* Get the CHDK source code.
 
   
 
== Installing a cross compiler ==
> svn co https://tools.assembla.com/svn/chdk/trunk chdk
 
  +
As of late 2020, the CHDK development branch requires gcc-arm-none-eabi version 4, 5, 8, 9 or (experimentally) 10. The 1.5 stable branch requires gcc 3, 4 or 5, either none-eabi or elf (for digic 5 and below ports only). Note that CHDK is sensitive to toolchain version and configuration, and that an incorrect toolchain may result in builds that compile but do not run.
   
  +
If your distro provides a supported gcc cross compiler version, simply install it using the package manager. On Debian based distros, the package is typically called gcc-arm-none-eabi, but beware that some distro versions may only offer a non-supported gcc version like 6 or 7.
* and update the source code every now and then:
 
   
  +
If no suitable package is available, pre-compiled toolchains are available from [https://launchpad.net/gcc-arm-embedded/+download]. gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 is known to work for both the development and stable branches. Note this toolchain is 32 bit, meaning 32 bit application support may need to be enabled in your distro (see [https://chdk.setepontos.com/index.php?topic=12133.msg125084#msg125084 here). Pre-compiled toolchains are also available from https://releases.linaro.org/components/toolchain/binaries/
> cd chdk && svn up
 
   
  +
If you install a 3rd party toolchain, you may need to add it to your path.
== Installing the cross compiler ==
 
   
  +
==Host toolchain and other dependencies==
{{Attention|There are alternate guides for setting up newer cross compilers here: [[gcc433 | gcc433]] and here [[Gcc452 | gcc452]]}}
 
  +
You will also need to install gcc for your host platform to build various CHDK tools. Distro package managers generally include a group / meta package like build-essentials or similar. At a minimum, you need gcc, make and libc development files. Building CHDK packages also requires zip.
   
  +
To build stubs (automatically identified firmware functions and variables) for Digic 6 and later, you also need the capstone libriary configured as described on [[Digic_6-7_Porting#Configuring_CHDK_capstone_tools]]. This is generally required for porting new models, but not for building existing ports or adding non-camera specific features.
Get the sources of gcc and binutils from a GNU repository. Decide where the cross compiler will be on your computer.
 
   
 
== Compiling CHDK ==
> mkdir ~/arm-elf
 
  +
To configure compile time options, copy buildconf.inc to localbuildconf.inc and edit to taste. In particular, you may want to set the default PLATFORM and PLATFORMSUB, and the paths to capstone libraries, and the OPT_GEN_STUBS settings. For the stable branch, you may also need to set OPT_USE_GCC_EABI to match your compiler.
   
  +
To do a full build of a port (a2200 firmware 100b, in this example), use the following in the root of your CHDK source tree
:Tell your computer you are going to run programs from that location.
 
   
 
make PLATFORM=a2200 PLATFORMSUB=100b clean fir
> export PATH=${HOME}/arm-elf/bin:$PATH
 
   
  +
The compiled CHDK core binary files DISKBOOT.BIN and PS.FIR/FI2 (if enabled) are output to bin in the source directory. Modules are output in the CHDK/modules directory.
:Create a working area and build binutils and gcc.
 
   
  +
You can do an incremental build (recompiling only changed files) by omitting clean, but beware that some changes may not be correctly detected, especially in header files and makefiles.
> mkdir ~/wa
 
> cd ~/wa
 
> tar xvfj ~/src/binutils-2.17.tar.bz2
 
> tar xvfj ~/src/gcc-3.4.6.tar.bz2
 
   
  +
To build a full zip package of CHDK files suitable for installing on an SD card, use
Note: About using the latest Gcc-4.3.3 take a look at [[Gcc433|this article]].
 
   
 
make PLATFORM=... PLATFORMSUB=... firzipsubcomplete
> cd binutils-2.17
 
> ./configure --srcdir=../binutils-2.17 --target=arm-elf \
 
--prefix=${HOME}/arm-elf --disable-werror
 
> make
 
> make install
 
> cd ..
 
   
  +
To build packages for all ports, use
:Apply Vitaly's patch to the compiler.
 
   
 
make batch-zip-complete
> (cd gcc-3.4.6 && patch -p0 <~/chdk/tools/patches/gcc-3.4-arm.diff)
 
 
[[Category:Development]]
 
> 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,
 
 
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
 
 
== 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.
 
 
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
 
 
===Compile and install GCC-4.5.2===
 
[http://pastebin.com/eYe609dp Here] is a script to build the tool chain needed for building CHDK
 
based on GCC 4.5.2.
 
 
You will need to change the following line...
 
 
MPFR=mpfr-3.0.0
 
 
to
 
MPFR=mpfr-3.1.2
 
 
... as mpfr-3.0.0 is no longer available.
 
 
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 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.
 
 
===The Gentoo way===
 
 
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/<br />The first line in makefile.inc should look then like this:<br />
 
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===
 
 
{{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.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 [http://dl.dropbox.com/u/4997718/testing.zip for download]}}
 
 
cd directory/where/compiler/is
 
python chdk_linux_compiling_gui.py
 
The rest schould be self-explaining.
 
 
Mor 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.
 
[[Category:Development|Compiling CHDK under Linux]]
 

Latest revision as of 17:56, 30 October 2022

Getting the CHDK source

The CHDK source is available from the official subversion repository. To get the current development source into a directory called chdk in your home directory use

 svn co http://subversion.assembla.com/svn/chdk/trunk ~/chdk

(When subversion.assembla.com requires a login, use anything, e.g. "guest"/"guest".)

Stable releases are available in branches named like /svn/chdk/branches/release-N_M

To update your source tree with changes added by the CHDK developers after your initial checkout, use

 svn up ~/chdk

Subversion is generally available from your distro package manager. For more information about subversion usage, see the documentation.

Installing a cross compiler

As of late 2020, the CHDK development branch requires gcc-arm-none-eabi version 4, 5, 8, 9 or (experimentally) 10. The 1.5 stable branch requires gcc 3, 4 or 5, either none-eabi or elf (for digic 5 and below ports only). Note that CHDK is sensitive to toolchain version and configuration, and that an incorrect toolchain may result in builds that compile but do not run.

If your distro provides a supported gcc cross compiler version, simply install it using the package manager. On Debian based distros, the package is typically called gcc-arm-none-eabi, but beware that some distro versions may only offer a non-supported gcc version like 6 or 7.

If no suitable package is available, pre-compiled toolchains are available from [1]. gcc-arm-none-eabi-4_9-2015q3-20150921-linux.tar.bz2 is known to work for both the development and stable branches. Note this toolchain is 32 bit, meaning 32 bit application support may need to be enabled in your distro (see [https://chdk.setepontos.com/index.php?topic=12133.msg125084#msg125084 here). Pre-compiled toolchains are also available from https://releases.linaro.org/components/toolchain/binaries/

If you install a 3rd party toolchain, you may need to add it to your path.

Host toolchain and other dependencies

You will also need to install gcc for your host platform to build various CHDK tools. Distro package managers generally include a group / meta package like build-essentials or similar. At a minimum, you need gcc, make and libc development files. Building CHDK packages also requires zip.

To build stubs (automatically identified firmware functions and variables) for Digic 6 and later, you also need the capstone libriary configured as described on Digic_6-7_Porting#Configuring_CHDK_capstone_tools. This is generally required for porting new models, but not for building existing ports or adding non-camera specific features.

Compiling CHDK

To configure compile time options, copy buildconf.inc to localbuildconf.inc and edit to taste. In particular, you may want to set the default PLATFORM and PLATFORMSUB, and the paths to capstone libraries, and the OPT_GEN_STUBS settings. For the stable branch, you may also need to set OPT_USE_GCC_EABI to match your compiler.

To do a full build of a port (a2200 firmware 100b, in this example), use the following in the root of your CHDK source tree

make PLATFORM=a2200 PLATFORMSUB=100b clean fir

The compiled CHDK core binary files DISKBOOT.BIN and PS.FIR/FI2 (if enabled) are output to bin in the source directory. Modules are output in the CHDK/modules directory.

You can do an incremental build (recompiling only changed files) by omitting clean, but beware that some changes may not be correctly detected, especially in header files and makefiles.

To build a full zip package of CHDK files suitable for installing on an SD card, use

make PLATFORM=... PLATFORMSUB=... firzipsubcomplete

To build packages for all ports, use

make batch-zip-complete