Magic Lantern Firmware Wiki
Register
Advertisement

[25th December 2010] I hit a problem with inline assembly compilation. There's a bug in 4.3.2. This manifests at compile time if you try add the following code, and make a call to test().

void test()
{
    asm("B aj_unique_label");
    asm("aj_unique_label:");
}


Error: symbol `aj_unique_label' is already defined make: *** [aj.o] Error 1

After spending 2 days trying to code around (and the nasty GCC inline syntax!) ... I finally decided to bite the bullet and try and upgrade to Alex's GCC 4.4.2 list (from the 15th Dec 2010) as follows:


BINUTILS=binutils-2.20
NEWLIB=newlib-1.18.0
GDB=gdb-7.2
LIBCMSIS=v1.10-2
LIBSTM32=v3.0.0-1
LIBSTM32USB=v3.0.1-1
LIBOPENSTM32=master


I am hoping that this doesn't take me as long as it did last time to get the environment up and running again. Especially ... as I am eager to test my ASM 'Pixel Brain'. AJ


==> Back. This worked first time! You'll also need to update the Makefile from 4.3.2 to 4.4.2


Parent: 2.0.4 AJ .

YOU CAN NOW USE THIS PAGE TO BUILD MAGIC LANTERN ON MAC OS / SNOW LEOPARD!

THIS PAGE DETAILS HOW TO BUILD ML WITH NOTHING ON YOUR MAC OTHER THAN MAX OS X (SNOW LEOPARD).
 
--> Special thanks to AI + Alex who are giving me 'beginners' tips on setting up the Environment!
--> Credit to L0RE (who is also living life in the fun lane, testing compilation theories on his camera)

--> NOT forgetting TH of course who pioneered ML in the first place :)


My intention wass to Build n Test ML based on Canon firmware 2.0.4 / 5Dii. [2010_10_25]

My initial attempt in 2010_03 failed on Mac OS X / SnowLeopard.

AI's success in porting ML to the 550D gave me enough hope that I'd succeed this time around.


AJ's Hardware

  • Mac Pro (2 x Quad Core) / OS X SnowLeopard 10.6.4
  • Canon 5d II @ Dry OS 2.0.4
  • Kinston 32GB 133X CCF


Build instructions that I going to work through


Activity STEPs. (I'm a complete novice in this area!)

STEP 0.0  -  MERCURIAL (Source Code Repository)
  • From [BP] page:
  • Run Applications->Utilities->Termnal (Unix Prompt)
  • hg version -> should show version 1.6.3 is installed
  • [AJ] If theres remnants of previous directory -> Rename / delete magic-lantern folder from the Finder.
STEP 0.1  - Install XCODE & X11  
  • If you already have an old copy of Xcode on your Mac. Uninstall it, and reinstall from scratch.
    This should increase the stability of Xcode.
  • Use Mac OS X Snow Leopard install disc to install Xcode -> Optional Installs.mpkg -> Xcode.mpkg ->
    -> Ticked everything ... including Max OS X 10.4 Support -> Install -> Done
  • Use Mac OS X Snow Leopard install disc to install X11 -> Optional Installs.mpkg -> Applications -> Tick X11 -> Install -> Done
  • Checked for software updates: Apple -> Software Update
    "Xcode" 592.2 MB software patch now downloading.
    Install -> Done
  • Checked for software updates again : Apple -> Software Update
    Nothing else to install
  • Reboot your machine - an Apple recommendation.
STEP 0.2  - Install of MacPorts 1.9.1
  • MacPorts is a provides an easy tool for installing and upgrading software titles (ie 'Port'ing software to a Mac): http://www.macports.org/
Downloaded Macports 1.9.1 (for SnowLeopard)
    (MacPorts requires that Xcode and X11 are installed before it will install - Done in Step 0.1)
  • Installed MacPorts 1.9.1 -> Done
STEP 0.3  - Using MacPorts to Install things (needed for ToolChain actions to succeed later on)
  • Should be "install gmp, mpfr, libmpc, libiconv and wget packages using MacPorts."
  • This is done by starting the 'Terminal' window and performing a single command:
    sudo port install gmp mpfr libmpc libiconv wget
  • If the above (all-in-one command) is failing - you can it can do this one install at the time using the following commands
    to help understand which is causing problems (eg if you don't want to wade through you Terminal logs):
    sudo port install gmp
    sudo port install mpfr
    sudo port install libmpc
    sudo port install libiconv
    sudo port install wget


  • I used the all-in-one command:
    macintosh:~ jfdi$ sudo port install gmp mpfr libmpc libiconv wget
    ---> Computing dependencies for gmp ................ Cleaning wget
    Done

--> HUGE thanks to Alex for geting me on the right track for this!! <--


STEP 0.4  - Change Snow Leopard 'tar' back to gnu tar.  

After a few failed attempts with 'tar' (decompressing) commands - I found this:


http://macitbetter.com/node/354

The problem is that Apple used to include the GNU version of tar at /usr/bin/tar.

With Snow Leopard Apple changed /usr/bin/tar to point to bsdtar, breaking any scripts or applications that depended on gnutar

To change it type the following in terminal:

  • cd /usr/bin; sudo ln -fs gnutar tar && /usr/bin/tar --version

To verify, it should say GNU somewhere in the output.
To change it back to default: (only needed after we have succeeded in getting the Summon-tool-chain to work btw)

  • To revert the earlier command (ie not now!) cd /usr/bin; sudo ln -fs bsdtar tar && /usr/bin/tar --version

Done

STEP 1  - SUMMON-ARM-TOOLCHAIN
 
a) Download the summon-arm-toolchain script 
b)  (by Uwe Hermann, 
c)  github repo here) 
d)  edit it as follows: 

TARGET=arm-elf  
PREFIX=${HOME}/arm-toolchain  # Install location of your final toolchain
PARALLEL="-j 9"               # AJ 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

BINUTILS=binutils-2.19.1
GCC=gcc-4.3.2
NEWLIB=newlib-1.17.0
GDB=gdb-7.1 

tar xf${TARFLAGS} ${SOURCES}/$1.tar.*  # AJ changed from xaf as "a" option not allowed in gnutar on Snowleopard

  --enable-languages="c" \             # AJ changed from --enable-languages="c,c++" \
  • Before we start, we need to create a Unix file.
    This will enable us to edit in TextEdit (and avoid using the vi editor )
    Open Terminal. In home UNIX directory - create a Unix file using:
    echo "test" > summon-arm-toolchain.sh
  • a) Open URL -> Select all -> Paste into TextEdit of summon-arm-toolchain.sh -> Save (ie back to Unix home directory)
  • b) ignore this page - it's out of date
  • c) this explains the compilation steps that much be completed using MacPorts. These actions are listed above in Steps 0.3
  • d) Make the changes in TextEdit -> Save (ie back to Unix home directory)


Done

Step 2. Get the dependencies ....
  • All these steps were done in Steps 0.3

Done

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.

Note: In this section, you may need to rerun the toolchain stript (eg if a download gets stuck).
Rerunning uses a (time) stamps directory in you UNIX home directory to determine where the script got to last time.
If you do want to rerun this process from scratch -> open Finder -> got to UNIX home directory / sources -> Delete stamps,

sources, build directory and then -> rerun summon-arm-toolchain scipt again.
(Note: If the downloading gets stuck, I recommend deleteing everything and rerunning from scratch)



  • Run Terminal.
  • bash summon-arm-toolchain.sh
    [39 sec] Downloading binutils-2.19.1 sources
    [3 min 2 sec] Downloading gcc-4.3.2 sources
    [35 sec] Downloading newlib-1.17.0 sources
    [43 sec] Downloading gdb-7.1 sources
    Unpacking binutils-2.19.1 -> Configuring binutils-2.19.1 -> Building binutils-2.19.1 -> Cleaning Up -> Done
    Unpacking gcc-4.3.2 boot -> Configuring gcc-4.3.2 -boot -> Building gcc-4.3.2-boot -> Done
    Unpacking newlib-1.17.0 sources -> Configuring newlib-1.17.0 sources -> Building newlib-1.17.0 -> Cleaning Up -> Done
    Unpacking gcc-4.3.2 -> Configuring gcc-4.3.2 -> Building gcc-4.3.2 -> Cleaning Up -> Done
    Unpacking Downloading gdb-7.1 sources -> Configuring Downloading gdb-7.1 sources ------> Done


Done


Note: Until I removed c++ references from the Summon script (done in previous Step 1), it was unable to comfile the GCC properly.

I emailed the Summon script creator. His response is as follows:

> Hi,
>
> The Summon-arm-toolchain compiles GCC twice - but with different options that I list below.
>
> 1st time around: --enable-languages="c" \
> --without-headers \
>
> 2nd time around: --enable-languages="c,c++" \
>
> Is this deliberate? Or was the second GCC compile supposed to have the same options as the first time around?

Yes it is deliberate, the first time around we are only bootstrapping the c compiler. 

The second time around we are compiling the real compiler, so it is also time where we 
can decide that we want the C++ compiler too. It does not make sense to compile the C++ 
compiler two times, but the C compiler as it is our jump pad to get the whole toolchain 
compiled is necessary both times.

Cheers
Esden


Done

Step 4. 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-toolchain/bin/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.
  • Copied the summon script file to hello.c
  • Edited in TextEdit, and replaced with above.
  • macintosh:~ jfdi$ ~/arm-toolchain/bin/arm-elf-gcc -c hello.c
  • ls hello.o
    hello.o

Yayyyy! -> Done


Step 5. You may also like to add the arm-elf-gcc binaries to your PATH. 

This is not required for building Magic Lantern, but might help in some cases.

PATH=~/arm-toolchain/bin/:$PATH
  • Open Terminal
  • Change to home directory of UNIX.
  • vi .profile
    added the following line to the end
    export PATH=~/arm-toolchain/bin/:$PATH
    save file
  • echo $PATH
    /opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
    . .profile
    echo $PATH
    /Users/jfdi/arm-toolchain/bin/:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

Done


Step 6. MAGIC LANTERN - Setup the Make File  [Thanks for the help on this Alex]
  • Looking at [BP550] there are more steps to get the 550D branch of ML, and a bucket full of makefile changes.
    Seem like I need to apply the 550D changes to the Makefile that relate to the SummonToolChain.
  • Unix home /magic-lantern/Makefile is the ML Makefile -> Open in TextEdit
  • Changed in accordance to [BP550]
#AJAJ ARM_PATH=/opt/local/bin
ARM_PATH=~/arm-toolchain

ARM_BINPATH=$(ARM_PATH)/bin
GCC_VERSION=4.3.2

#AJAJ CC=$(ARM_PATH)/arm-elf-gcc-4.3.2
CC=$(ARM_BINPATH)/arm-elf-gcc-$(GCC_VERSION)

#AJAJ OBJCOPY=$(ARM_PATH)/arm-elf-objcopy
OBJCOPY=$(ARM_BINPATH)/arm-elf-objcopy

#AJAJ AR=$(ARM_PATH)/arm-elf-ar
AR=$(ARM_BINPATH)/arm-elf-ar

#AJAJ RANLIB=$(ARM_PATH)/arm-elf-ranlib
RANLIB=$(ARM_BINPATH)/arm-elf-ranlib

..


#AJAJ CONFIG_LUA        = y
CONFIG_LUA        = n         # to disable LUA in the Makefile:
..

#AJAJ ARM_LIBC_A = /opt/local/arm-elf/lib/libc.a
ARM_LIBC_A = $(ARM_PATH)/arm-elf/lib/libc.a

..
#AJAJ  $(ARM_PATH)/arm-linux-objdump \
       $(ARM_BINPATH)/arm-linux-objdump \

..
#AJAJ @if [ "$V" == 1 ]; then \
@if [ X"$V" = X"1" ]; then \


CFLAGS=\
	$(FLAGS) \
	-g \
	-O3 \
	-Wall \
	-W \
	-Wno-unused-parameter \
 	-D__ARM__ \
	-mlong-calls\               # AJ: Seach for -Wno to find where to add this.  (Credit: L0RE)

The following are not made - as they were not in the 5d Branch of the Makefile:

if=$< \
                bs=1 \
                conv=notrunc \
-               oseek=0 \
+               seek=0 \

Done

Step 7. BUILDING MAGIC LANTERN 

Run make and keep your fingers crossed!

make

In the event that the following 'make' fails, and you need to hack the Makefile, use 'make clean' from the magic-lantern directory.


Note: Following was done to enable build to succeed (both of these changes to the Makefile are now in Step 6)

-> added CONFIG_LUA = n (thanks Alex)

-> To fix the error on the following line, added add -mlong-calls: (Thanks L0RE and Alex)

5d-hack.o: In function `my_init_task':

/Users/jfdi/magic-lantern/5d-hack.c:268: relocation truncated to fit: R_ARM_PC24 against symbol `init_task' defined in *ABS* section in magiclantern


  • From Unix Home directory:
    cd magic-lantern
  • make


DONE!


  • For reference - his is my final output from the Terminal:

macintosh:magic-lantern jfdi$ make

[ CPP ] magiclantern.lds

[ AS ] entry.o

[ CC ] 5d-hack.o

[ AS ] stubs-5d2.204.o

[ VERSION ] version.c

[ CC ] version.o

[ CC ] stdio.o

stdio.c: In function 'realloc':

stdio.c:277: warning: comparison between signed and unsigned

[ CC ] config.o

[ CC ] debug.o

debug.c: In function 'efic_temp_display':

debug.c:131: warning: format '%d' expects type 'int', but argument 5 has type 'uint32_t'

debug.c: In function 'mvr_time_const_display':

debug.c:144: warning: unused variable 'mvr_state_object'

debug.c:143: warning: unused variable 'mvr_hdr'

debug.c:142: warning: unused variable 'mvr_struct'

debug.c: At top level:

debug.c:221: warning: initialization from incompatible pointer type

debug.c: In function 'debug_property_handler':

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 7 has type 'long unsigned int'

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 8 has type 'long unsigned int'

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 9 has type 'long unsigned int'

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 10 has type 'long unsigned int'

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 11 has type 'long unsigned int'

debug.c:308: warning: format '%08x' expects type 'unsigned int', but argument 12 has type 'long unsigned int'

debug.c: In function 'debug_init':

debug.c:386: warning: passing argument 5 of 'prop_register_slave' from incompatible pointer type

debug.c: At top level:

debug.c:433: warning: initialization from incompatible pointer type

debug.c:472: warning: initialization from incompatible pointer type

debug.c:141: warning: 'mvr_time_const_display' defined but not used

[ CC ] menu.o

menu.c: In function 'menu_task':

menu.c:666: warning: unused variable 'y'

menu.c:666: warning: unused variable 'x'

menu.c: At top level:

menu.c:726: warning: initialization from incompatible pointer type

menu.c:46: warning: 'draw_version' defined but not used

[ CC ] property.o

property.c: In function 'prop_init':

property.c:44: warning: passing argument 5 of 'prop_register_slave' from incompatible pointer type

property.c: At top level:

property.c:49: warning: initialization from incompatible pointer type

[ CC ] bmp.o

bmp.c: In function 'con_printf':

bmp.c:159: warning: unused variable 'len'

[ MKFONT ] font-huge.c

[ CC ] font-huge.o

[ MKFONT ] font-large.c

[ CC ] font-large.o

[ MKFONT ] font-med.c

[ CC ] font-med.o

[ MKFONT ] font-small.c

[ CC ] font-small.o

[ CC ] gui.o

[ CC ] focus.o

focus.c:123: warning: initialization from incompatible pointer type

focus.c:308: warning: initialization from incompatible pointer type

focus.c:383: warning: initialization from incompatible pointer type

[ CC ] lens.o

lens.c:618: warning: initialization from incompatible pointer type

[ CC ] spotmeter.o

[ CC ] audio.o

audio.c:309: warning: initialization from incompatible pointer type

audio.c:328: warning: initialization from incompatible pointer type

[ CC ] zebra.o

zebra.c:721: warning: initialization from incompatible pointer type

[ CC ] hotplug.o

[ CC ] bootflags.o

bootflags.c: In function 'bootflag_write_bootblock':

bootflags.c:101: warning: format '%08x' expects type 'unsigned int', but argument 5 has type 'uint8_t *'

bootflags.c:101: warning: format '%08x' expects type 'unsigned int', but argument 6 has type 'int (*)(struct cf_device *, uintptr_t, size_t, void *)'

bootflags.c: At top level:

bootflags.c:182: warning: initialization from incompatible pointer type

bootflags.c:192: warning: initialization from incompatible pointer type

bootflags.c:221: warning: initialization from incompatible pointer type

[ CC ] ptp.o

ptp.c: In function 'ptp_handler_0x9999':

ptp.c:29: warning: format '%08x' expects type 'unsigned int', but argument 5 has type 'struct ptp_context *'

ptp.c:29: warning: format '%08x' expects type 'unsigned int', but argument 6 has type 'struct ptp_handle *'

ptp.c: In function 'ptp_handler_0x9995':

ptp.c:137: warning: initialization makes integer from pointer without a cast

ptp.c: In function 'ptp_state_display':

ptp.c:176: warning: format '%x' expects type 'unsigned int', but argument 5 has type 'uint32_t'

ptp.c:176: warning: format '%08x' expects type 'unsigned int', but argument 6 has type 'uint32_t'

ptp.c: At top level:

ptp.c:220: warning: initialization from incompatible pointer type

[ CC ] bracket.o

~/arm-toolchain/bin/arm-elf-ar xv /Users/jfdi/arm-toolchain/arm-elf/lib/libc.a lib_a-setjmp.o lib_a-strchr.o lib_a-strrchr.o lib_a-strlen.o lib_a-strcat.o lib_a-strncat.o lib_a-strcmp.o lib_a-strncmp.o lib_a-strncpy.o lib_a-strstr.o lib_a-strcspn.o lib_a-memcmp.o lib_a-strcoll.o lib_a-ctype_.o

x - lib_a-setjmp.o

x - lib_a-strchr.o

x - lib_a-strrchr.o

x - lib_a-strlen.o

x - lib_a-strcat.o

x - lib_a-strncat.o

x - lib_a-strcmp.o

x - lib_a-strncmp.o

x - lib_a-strncpy.o

x - lib_a-strstr.o

x - lib_a-strcspn.o

x - lib_a-memcmp.o

x - lib_a-strcoll.o

x - lib_a-ctype_.o

~/arm-toolchain/bin/arm-elf-ar cr libstdio.a lib_a-setjmp.o lib_a-strchr.o lib_a-strrchr.o lib_a-strlen.o lib_a-strcat.o lib_a-strncat.o lib_a-strcmp.o lib_a-strncmp.o lib_a-strncpy.o lib_a-strstr.o lib_a-strcspn.o lib_a-memcmp.o lib_a-strcoll.o lib_a-ctype_.o

[ LD ] magiclantern

[ OBJCOPY ] magiclantern.bin

[ CC ] reboot.o

[ LD ] autoexec

[ OBJCOPY ] autoexec.bin

[ ASSEMBLE ] magiclantern.fir

magiclantern.fir: New CRC: ffffffffff8f8d92 OLD b7932bae

macintosh:magic-lantern jfdi$



BINGO!

autoexec 221 KB

autoexec.bin 184 KB (Last item metioned in [BP550] before referring you back to [BP]

magiclantern.bin 176 KB

magiclantern.fir 188KB created


Step 102. Whats next  - back to the Original Build instructions
  • Making sure that everything looks OK


Short build instructions -> OK

Camera-specific build instructions -> OK

magiclantern ELF image -> OK

Fonts -> OK

Object files -> OK

Initial Linking -> OK

Reboot shim -> OK

Firmware file -> OK

Distribution zip file -> OK

Make targets -> [AJ this could be useful]
" vvv

  • 'make install' is a convenience target for my Macbook with a CF card reader. You may need to update it for the path to you card reader, or you can just copy the files by hand.

" ^^^ Dependency tracking-> OK

Extending Magic Lantern -> [AJ this could be useful]
" vvv

  • If you want to create a task, add the TASK_CREATE() macro in your code. Look at zebra.c for an example of how to create a new task automatically. There are no dependencies to zebra.o elsewhere in the code, so if it is not linked in there will be no compilation failures.
  • To be notified via a callback when another task modifies a property, use prop_register_slave(). Look at lens.c to see how to hook the lens change events for examples.
  • To modify a property, use prop_request_change(). Again, look at lens.h for how it adjusts the aperture and shutter speeds.
  • To add a menu, call menu_add(). The exact syntax may change between released until the Magic Lantern API settles down.
  • To draw text to the screen, use bmp_printf(). It is similar to the normal printf, but takes a fontspec which encodes the size, fg color and bg color, and an x/y bitmap vram coordinate. Embedded newlines ('\n') are correctly handled.
  • To draw rectangles to the screen, you can use bmp_fill().
  • Hooking keys is complicated. It requires creating a fake Canon dialog, which isn't fully understood yet.
  • There are not any more complicated graphics drawing primitives yet. We need to either figure out how to use the Canon dialog API or create a full-featured graphics API.

" ^^^

... Done

Step 101. (Big jump in steps for now) BUILDING the Documentation
  • sudo port install doxygen
    (takes about 35 mins as it installs half the world in your Unix kitchen)
  • doxygen
    and then browse to docs/html/index.html.

Done


Step 102. OK - Magic Lantern Build - time to test it out

General instructions at: http://magiclantern.wikia.com/wiki/Download_firmware


"vvv

  • Copy the magiclantern.fir and magiclantern.cfg file to the root directory on the CF card
  • Select "Updated firmware" from the menu

"^^^


OMG ... it works!

(Something tells me this weekend should be fun.)


Also - a special thanks to Arm.Indy & Alex for helping a complete (Unix) novice in getting a development environment setup on a Mac (with Snow Leopard).

/Antony

Advertisement