Magic Lantern Firmware Wiki
Register
Advertisement

These are build instructions for the Unified branch of Magic Lantern. Credits goto Arm.Indy, Phil and Sztupy.

Installing arm-elf-gcc 4.6.2[]

Step 1. Download summon-arm script and 'patches' directory save it in your Home folder: /home/yourusername/

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

  • For Fedora, CentOS, RedHat users, the dependencies are:
yum install wget gmp-devel mpfr-devel ncurses-devel libmpc-devel mercurial zlib-devel texinfo
  • For openSUSE users, the dependencies are:
sudo zypper install wget gmp-devel ncurses-devel mpc-devel mercurial zlib-devel
sudo zypper install python-mathplotlib python-docutils texlive-latex ruby poppler-tools ImageMagick
  • 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 Coutts' guide Magic_Lantern_Development_on_Mac, AJ's 2.0.4_Building_ML page and/or Piers' blog entry.

You will also need gnutar and mercurial.

  • 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

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

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

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

and run the script again.

If the summon-arm script fails during the gcc build with error:

gtype-desc.c:8893:18: error: subscripted value is neither array nor pointer nor vector

It is most likely because you are compiling with gcc version 4.7. For a full fix, see the fixing common compiling problems section titled Building the arm toolchain with gcc 4.7.

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-toolchain462/bin:$PATH
which arm-elf-gcc
/home/.../arm-toolchain462/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 / Unified[]

Next, get the source code (Unified branch):

hg clone -r unified https://bitbucket.org/hudson/magic-lantern/ && cd magic-lantern

[20130320 dmanso2: as far as I tried, building instructions in this page work with repository tag ML2.3-stable, but it fails with last repository version, so you should use "-r ML2.3-stable" instead of "-r unified"]

Check the gcc version number in the Makefile.user.default:

GCC_VERSION=4.4.2          # or whatever you have installed

If you are using the official ARM toolchain in the same file also set ARM_ABI=none-eabi and ARM_PATH as appropriate.

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! If there are any issues run "make clean" and try again.

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 & BMP)[]

make docs

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.inc. It should look like this:

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

The arm-elf directory, ~/arm-toolchain462/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-toolchain462/bin/arm-elf-gcc

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.

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 (which is basically deleting the font-*.in rules from the Makefile and using font-*.in from the repo).

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

This appears if you try to build the old 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...[]

Fix: use a 32-bit compiler.

What does this error mean?

  • Short answer: black magic

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

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

Warning: this will make the binary larger (bug in 64-bit gcc?)

Link problems with the LDS file[]

Piers said [4]:

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


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.

Building ARM toolchain with gcc 4.7[]

If you are using gcc version 4.7 (you can confirm by running gcc -v) then you must perform the following fix.

Save the following as summon.patch in your home directory.

--- summon-arm-orig	2013-11-23 19:56:49.582988112 -0800
+++ summon-arm	2013-11-23 19:36:23.614400625 -0800
@@ -375,6 +375,11 @@ if [ ! -e ${STAMPS}/${GCC}-${NEWLIB}.bui
     log "Adding libgloss symlink to gcc"
     ln -f -s `pwd`/${NEWLIB}/libgloss ${GCC}
 
+    cd ${GCC}/gcc
+    log "Patching gcc to fix building 4.6 with 4.7"
+    patch -p2 < ~/patches/gccfix.patch
+    cd ../..
+
     log "Patching gcc to add multilib support"
     cd ${GCC}
     patch -p0 -i ../patches/patch-${GCC}-config-arm-t-arm-elf.diff

Patch summon-arm, from your home folder[]

patch < summon.patch

Save the following as gccfix.patch in your patches directory (the patches directory should be under your home directory).

diff --git a/gcc/gengtype.c b/gcc/gengtype.c
index abf17f8..550d3bb 100644
--- a/gcc/gengtype.c
+++ b/gcc/gengtype.c
@@ -3594,13 +3594,13 @@ write_field_root (outf_p f, pair_p v, type_p type, const char *name,
                  int has_length, struct fileloc *line, const char *if_marked,
                  bool emit_pch, type_p field_type, const char *field_name)
 {
+  struct pair newv;
   /* If the field reference is relative to V, rather than to some
      subcomponent of V, we can mark any subarrays with a single stride.
      We're effectively treating the field as a global variable in its
      own right.  */
   if (v && type == v->type)
     {
-      struct pair newv;
 
       newv = *v;
       newv.type = field_type;


Now summon-arm should complete successfully!

Operating system specific notes[]

Ubuntu[]

Virtual Machine 1[]

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

Also tested on Ubuntu Karmic.


Virtual Machine 2[]

Ubuntu 10.04 VMware VM with ML Build Environment

  • Download link after email request


Virtual Machine 3[]

In the forums a user posted a link to share the Ubuntu image for WMware with all the tools you need.

  • 1,92 GB
  • hosted on his dropbox, maybe someone can upload it somewhere else?
  • admin password: admin

if you use this vm, you have to change two things in the Makefile.inc:

  1. ARM_ABI=elf
  2. ARM_PATH=~/arm-toolchain462

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 [5]

CygWin/Yagarto: Download cygwin http://cygwin.com/setup.exe Install cygwin for windows
- Check the following packages:
Archive: unzip, zip
Base: Everything
Devel: automake, autoconf, binutils, bison, byacc, gcc, gcc-core, gcc-g++, libtool, make, nasm, patchutils, subversion
Libs: libbz2-devel
Perl: perl
Python: python
Utils: bzip2, cygutils, diffutils, patch, patchutils
Web: wget
- confirm to download the dependencies too

Get http://sourceforge.net/projects/yagarto/files/YAGARTO%20for%20Windows/20111119/yagarto-bu-2.21_gcc-4.6.2-c-c%2B%2B_nl-1.19.0_gdb-7.3.1_eabi_20111119.exe/download file and run it
Install it to "yourcygwindir"/home/"yourusername"/arm-toolchain462

Download http://mercurial.selenic.com/release/windows/mercurial-2.3.2-x64.msi (if you are running a 64bit Windows) or http://mercurial.selenic.com/release/windows/mercurial-2.3.2-x86.msi (for a 32-bit system) and install it.

Start cygwin, go to your home folder ("yourcygwindir"/home/"yourusername") and get the source:
hg clone -r unified https://bitbucket.org/hudson/magic-lantern

Go to the magic-lantern folder and create Makefile.user
Edit Makefile.user:
ARM_ABI=none-eabi
ARM_LIBC_A=../../../arm-toolchain462/arm-none-eabi/lib/libc.a
PYTHON=python2.6

Run make to compile your own autoexec.bin

Other compilers which (seem to) work[]

  • 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 [7], 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. (see above for a tested functional version)
  • 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