Magic Lantern Firmware Wiki
Advertisement

These are build instructions for the 550D branch of Magic Lantern. They may work on the 5D branch, too, with minor changes. Credits goto Arm.Indy and Phil.

Installing arm-elf-gcc

Step 1. Download the summon-arm-toolchain script (by Uwe Hermann, github repo here) and edit it as follows:

TARGET=arm-elf                
PREFIX=${HOME}/arm-toolchain  # Install location of your final toolchain
PARALLEL="-j 3"               # Or: PARALLEL="-j 5" for 4 cores, "-j 9" for 2 Quad Cores etc. Or just ignore it.
DARWIN_OPT_PATH=/opt/local    # Path in which MacPorts or Fink is installed

USE_LINARO=0                  #use the FSF gcc version instead of linaro

BINUTILS=binutils-2.19.1
GCC=gcc-4.4.2                 # I use 4.4.2 on Ubuntu; Piers successfully used 4.5.2 on Mac. 
                              # DO NOT USE GCC 4.3.2! if you do, the camera will freeze when turned off and on.
if [ ${DEFAULT_TO_CORTEX_M3} == 0 ] ; then
	GCCFLAGS="--with-float=soft"

Step 2. Get the dependencies, as described in summon-arm-toolchain's README.

  • For Debian/Ubuntu, they are:
sudo apt-get install flex bison libgmp3-dev libmpfr-dev libncurses5-dev libmpc-dev autoconf texinfo build-essential git-core mercurial zlibc zlib1g-dev
  • For Fedora users, they are:
yum install wget gmp-devel mpfr-devel ncurses-devel libmpc-devel mercurial zlib-devel
  • For Mac OS X, you need to install gmp, mpfr, libmpc, libiconv and wget packages using MacPorts:
sudo port install gmp mpfr libmpc libiconv wget

For Mac details, check AJ's 2.0.4_Building_ML page and/or Piers' blog entry.

You will also need gnutar and mercurial (can they be installed with port install?! I don't use a Mac...)

  • For other Linux distros, use the package management system (yum, zypper etc.) and be careful, since the packages may have a slightly different name.


Step 3. Run the script (it will take a long time):

bash summon-arm-toolchain

This will install arm-elf-gcc under ~/arm-toolchain/bin.

If the script fails to download newlib, try changing the FTP transfer mode to passive:

-wget -c --no-passive-ftp $2
+wget -c $2

and run the script again.

Step 4. Add the arm-elf-gcc binaries to your PATH. This is not required for building Magic Lantern, but is required for ARM console and other related tools.

PATH=~/arm-toolchain/bin:$PATH
which arm-elf-gcc
/home/.../arm-toolchain/bin/arm-elf-gcc

Step 5. Test the installation by compiling a Hello World program:

hello.c

#include <stdint.h>
#include <sys/types.h>
int main() 
{
    int x;
    x = 5;
}
arm-elf-gcc -c hello.c

You should get a file named hello.o . When compiling without "-c", it may complain about missing _exit and _sbrk, but this is OK according to this forum post.

Compiling Magic Lantern / 550D

Next, get the source code (550D branch) and the precompiled magiclantern.fir:

hg clone -r 550d https://bitbucket.org/hudson/magic-lantern/ && cd magic-lantern
wget http://bitbucket.org/hudson/magic-lantern/downloads/magiclantern-0.2.0.rc1.550d.fw109.zip
unzip magiclantern-0.2.0.rc1.550d.fw109.zip magiclantern.fir

Check the gcc version number in the Makefile:

GCC_VERSION=4.4.2          # or whatever you have installed

Install python, perl and the file::slurp extension:

sudo apt-get install perl python
sudo perl -MCPAN -e 'install File::Slurp'

Run make and keep your fingers crossed!

make

This will compile a new autoexec.bin, which contains unencrypted ARM code, ready to brick your camera (God forbid...) See Build_instructions for next steps.

Building the documentation

User guides (PDF & Wiki)

cd doc
python mkdoc.py

Source code docs (Doxygen)

Just run:

doxygen

and then browse to docs/html/index.html.

For more fancy output, install Graphviz and put these settings into the Doxyfile:

FILE_PATTERNS          = *.c *.h *.S
HAVE_DOT               = YES
CALL_GRAPH             = YES
CALLER_GRAPH           = YES

Fixing common compiling problems

Magic Lantern is not easy to compile, and this section attempts to provide a little guidance if some problems appear. Please feel free to improve this if you succeed in compiling Magic Lantern.

arm-elf-gcc not found

Check the paths and version number in the Makefile. It should look like this:

ARM_PATH=~/arm-toolchain           # you might have installed arm-elf-gcc somewhere else...
ARM_BINPATH=$(ARM_PATH)/bin
GCC_VERSION=4.4.2                  # or what gcc version you have installed...
CC=$(ARM_BINPATH)/arm-elf-gcc-$(GCC_VERSION)
...

The arm-elf directory, ~/arm-toolchain/bin, is not required to be in PATH. You should be able to invoke arm-elf-gcc from the terminal with this command: (Check your version number)

$ ~/arm-toolchain/bin/arm-elf-gcc-4.3.2

Make sure you install arm-elf-gcc with the summon-arm-toolchain script. I've tested 5 other builds of arm-elf-gcc, and none of them was able to compile Magic Lantern.

libc.a problems

Magic Lantern extracts some functions from the standard C library. Some arm-elf-gcc builds don't have libc.a, while others have up to 20 versions of libc.a (which one is good?!)

Solution: just do a fresh install of arm-elf-gcc with summon-arm-toolchain, as described on top of this page.

Some fonts do not appear when running the compiled ML on the camera

This may happen if you don't have bigtext and the Makefile font-*.in rules are executed when they should not. I believe this can happen if your date/time is set incorrectly.

In this case, some font-*.c files become empty. This should be fixed, either in the Makefile or in the script which creates them.

Until this problem is fixed, see Arm.Indy's workaround here.

make: No rule to make target `lua-glue.o'.

This appears if you try to build the 5D branch with these instructions. You have to turn it off in the Makefile:

CONFIG_LUA = n

and re-build with:

make clean
make

Sometimes, running make clean fixes strange compiling problems... and sometimes not.


relocation truncated to fit: R_ARM_PC24...

What does this error mean?

  • Short answer: black magic


Workaround from L0RE: add -mlong-calls to the CFLAGS in the Makefile

CFLAGS=\
	$(FLAGS) \
	-g \
	-O3 \
	-Wall \
	-W \
	-Wno-unused-parameter \
	-D__ARM__ \
	-mlong-calls\

Link problems with the LDS file

Piers said [4]:

link problems – zero-byte .lds file causing trouble. deleted it. got rebuilt


Camera hangs after being switched off and on

See [5].

This seems to be caused by the compiler. Use a GCC version which is known to work (like GCC 4.4.2).

GCC 4.3.2 causes this bug and also other instabilities (looks like an invalid pointer issue).

This problem may also appear when ML is started without a config file on FAT32 cards. See [6].


ERROR: libgcc.a(_udivsi3.o) uses hardware FP, whereas magiclantern uses software FP

I'm not sure what causes this. If I write code which does floating point stuff on doubles (sqrts, sin, cos, divs), it compiles well, without this error.

My workaround was to add GCCFLAGS="--with-float=soft" in summon-arm script and recompile arm-toolchain. See the top of this page.

Operating system specific notes

Ubuntu

You can use this virtual machine: http://www.vmware.com/appliances/directory/542303

Also tested on Ubuntu Karmic.

Ubuntu 10.04 VMware VM with ML Build Environment

Mac

todo...

Do not use TextEdit or MS Word to edit script files! Use a plain ASCII editor, like TextWrangler or vi.

Windows

You don't need the nickel any more [7]

Other compilers which (seem to) work

L0RE and Arm.Indy successfully built ML with the compiler from http://www.openhardware.net/Embedded_ARM/Toolchain/, but there were some stability problems on 550D (camera hangs after being switched off and on) [8]. The 5D version might be fine, though.

Trammell used 4.3.2 on Mac (I believe it was installed with "port install") and 3.4.4 on Linux (ref: Download_sources). OpenHardware says gcc 3.4.x has some critical bugs [9], so it's better to avoid it unless you know what are you doing.

Compilers which do not work

I have tried the following compilers on Ubuntu Karmic. None of them worked, maybe 'cause they detected that I'm not a Linux guru :)

  • Prebuilt arm-elf-gcc 3.4.6 from http://www.idt.mdh.se/kurser/cdt214/#athome. It seems to work, but you have to modify the Makefile in several places. Resulting autoexec.bin is huge (over 700k), while the good one is around 150k. OpenHardware says it has some bugs which can lead to stack corruption.
  • Build 4.3.2 / 4.3.3 from source: see http://chdk.wikia.com/wiki/Gcc433 . For 4.3.2 just do a find/replace. Complains about missing headers and doesn't include libc.a. I don't know how to build it.
  • Zylin 4.3.2 (arm-elf-gcc). Complains about missing headers. Has 20 versions of libc.a (!)
  • CodeSourcery 4.3.2 (arm-none-linux-gnueabi-gcc). Finds headers, but complains about undefined reference to `raise'. Has 3 versions of libc.a.
  • Prebuilt 4.3.1: get chdk_linux_compiler (Python GUI) and run it. It will install arm-elf-gcc under newenv subdirectory. It compiles CHDK successfully, but not ML. It complains about missing headers even for hello world programs (don't know why). Doesn't include libc.a.
Advertisement