CHDK Wiki
No edit summary
No edit summary
Line 67: Line 67:
 
two errors in building binutils because a macro named asprintf may already be defined.
 
two errors in building binutils because a macro named asprintf may already be defined.
 
If this problem surfaces, simply disable the asprintf definition in libiberty.h using
 
If this problem surfaces, simply disable the asprintf definition in libiberty.h using
"#ifndef asprintf" and "#endif" around the offending line in "binutils-2.18/include/libiberty.h".''
+
"#ifndef asprintf" and "#endif" around the offending line in "binutils-2.18/include/libiberty.h". This issue applies to BOTH binutils and gcc -- you may need to fix two
  +
separate libiberty.h files.''
   
 
:Configure gcc (Thanks to Geekmug [[User:Geekmug/Compiling_CHDK_under_Windows#Building_gcc]])
 
:Configure gcc (Thanks to Geekmug [[User:Geekmug/Compiling_CHDK_under_Windows#Building_gcc]])

Revision as of 18:49, 15 March 2009

This page is about installing a buildenvironment with the gcc 4.3.3 compiler (newest at the time of this page creation). Originally this page used a (slightly modified or fixed) version 2.19.1 of binutils, but since it didn't work, the page is being modified to use version 2.18.

It has been tested and it seems to be able to build working images!

A problem seems to be analysing firmware dumps with binutils 2.18 though. arm-elf-objdump raises the flag "segmentation violation", when trying to dump the firware followring the instructions on this wiki. Binutils 2.19.1 is able to do this, however, it doesn't seem to be able to compile working chdk images. Further investigation is going on. For now, I guess the solution is to have two version of binutils, one to analyse firmware, and one to build chdk images. This page only covers installing binutils 2.18, but you can install binutils 2.19.1 by replacing "2.18" with "2.19.1" in the instructions below.


Here is the original for older gcc: Compiling_CHDK_under_Linux

Below is how I do it with Ubuntu GNU/Linux 8.10:

N.B. You don't need to wget and ln -s for GMP and MPFR sources if they are already installed on your computer. E.g. use the the following on Ubuntu:

 libgmp3-dev - Multiprecision arithmetic library developers tools
 libmpfr-dev - multiple precision floating-point computation developers tools

If you prefer to use the ubuntuversion of those libraries, you can use the followring command instead:

 > sudo apt-get install libgmp3-dev libmpfr-dev

The following assume that you're getting the newer sources for those libraries.

Some steps are common, so instead of reproducing it here, I just refer you to the relavant section on the page Compiling_CHDK_under_Linux.

However, some of it I have copied.

Follow the steps for getting the source.

Get the sources of gcc and binutils from a GNU repository. Decide where the cross compiler will be on your computer.

Create some directories, and modify your path to use the cross compiler and binutils
 > mkdir ~/arm-elf
 > export PATH=${HOME}/arm-elf/bin:$PATH
 > mkdir ~/wa
 > cd ~/wa
Create a place for downloads, and download some stuff you will need. I have chosen some random mirrors here, you are free to choose whatever mirror is closer to you.

Here are some mirrors: gcc mirrors, gmplib mirrors, mpfr mirrors (There appears to be only one mirror for mpfr at this time). It should be noted that mpfr is now at version 2.4.1, and 2.4.1 can be substituted for 2.4.0 in all that follows if you cannot find mpfr-2.4.0.

 > mkdir down
 > cd down
 > wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.3/gcc-4.3.3.tar.bz2
 > wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.4.tar.bz2
 > wget http://www.mpfr.org/mpfr-current/mpfr-2.4.0.tar.bz2
 > wget http://ftp.download-by.net/gnu/gnu/binutils/binutils-2.18.tar.bz2
Unpack and prepare sources.
 > cd ..
 > for zipped in down/* ; do tar xjf $zipped ; done # Note: This may take a while.
 > ln -s $(pwd)/gmp-4.2.4 gcc-4.3.3/gmp
 > ln -s $(pwd)/mpfr-2.4.0 gcc-4.3.3/mpfr
Now we're ready to build binutils
 > cd binutils-2.18/
 > ./configure --srcdir=../binutils-2.18 --target=arm-elf --prefix=${HOME}/arm-elf --disable-werror
 > make -j
 > make install
 > cd ..

Its nessesary for me to pass the "--disable-werror" flag to configure, since I use gcc version 4.3.3. Somewhere between version 4.1.2 and 4.3.3 gcc started producing some new warnings, and the binutils code doesn't avoid those yet. Since I doubt it will harm I included the flag above to enable gcc 4.3.3 users to compile binutils without errors.

Another issue is that libiberty.h contains a definition of asprintf which can cause two errors in building binutils because a macro named asprintf may already be defined. If this problem surfaces, simply disable the asprintf definition in libiberty.h using "#ifndef asprintf" and "#endif" around the offending line in "binutils-2.18/include/libiberty.h". This issue applies to BOTH binutils and gcc -- you may need to fix two separate libiberty.h files.

Configure gcc (Thanks to Geekmug User:Geekmug/Compiling_CHDK_under_Windows#Building_gcc)
 > ed gcc-4.3.3/gcc/config/arm/t-arm-elf << EOF
 > /MULTILIB_OPTIONS/s/^M/# M/
 > /MULTILIB_DIRNAMES/s/^M/# M/
 > /mno-thumb-interwork/s/^# //
 > /normal interwork/s/^# //
 > wq
 > EOF
Compile gcc
 > mkdir gcc-4.3.3-arm-elf && cd gcc-4.3.3-arm-elf
 > ../gcc-4.3.3/configure --srcdir=../gcc-4.3.3 --target=arm-elf \
    --enable-multilib --enable-languages=c --enable-clocale=gnu \
    --disable-libm --disable-libc --disable-threads \
    --disable-nls --disable-libssp --disable-intl \
    --with-cpu=arm9 --with-newlib --prefix=${HOME}/arm-elf
 > (unset LIBRARY_PATH; unset CFLAGS; make -j2 && make install) # Change "-j2" if you don't have two cores

Thats it! You should now have a working buildenvironment, and you can continue from "Compiling the CHDK." at Compiling_CHDK_under_Linux.

Here is the whole process for the impatient:

mkdir ~/arm-elf
export PATH=${HOME}/arm-elf/bin:$PATH
mkdir ~/wa
cd ~/wa

mkdir down
cd down
wget ftp://ftp.nluug.nl/mirror/languages/gcc/releases/gcc-4.3.3/gcc-4.3.3.tar.bz2
wget http://ftp.sunet.se/pub/gnu/gmp/gmp-4.2.4.tar.bz2
wget http://www.mpfr.org/mpfr-current/mpfr-2.4.0.tar.bz2
wget http://ftp.download-by.net/gnu/gnu/binutils/binutils-2.18.tar.bz2

cd ..
for zipped in down/* ; do tar xjf $zipped ; done # Note: This may take a while.
ln -s $(pwd)/gmp-4.2.4 gcc-4.3.3/gmp
ln -s $(pwd)/mpfr-2.4.0 gcc-4.3.3/mpfr

cd binutils-2.18/
./configure --srcdir=../binutils-2.18 --target=arm-elf --prefix=${HOME}/arm-elf --disable-werror
make -j
make install
cd ..

ed gcc-4.3.3/gcc/config/arm/t-arm-elf << EOF
/MULTILIB_OPTIONS/s/^M/# M/
/MULTILIB_DIRNAMES/s/^M/# M/
/mno-thumb-interwork/s/^# //
/normal interwork/s/^# //
wq
EOF

mkdir gcc-4.3.3-arm-elf && cd gcc-4.3.3-arm-elf
../gcc-4.3.3/configure --srcdir=../gcc-4.3.3 --target=arm-elf \
 --enable-multilib --enable-languages=c --enable-clocale=gnu \
 --disable-libm --disable-libc --disable-threads \
 --disable-nls --disable-libssp --disable-intl \
 --with-cpu=arm9 --with-newlib --prefix=${HOME}/arm-elf
(unset LIBRARY_PATH; unset CFLAGS; make -j2 && make install) # Change "-j2" if you don't have two cores