add notes about building stlink too, assuming I move it to git.gag.com
[web/altusmetrum] / AltOS / building.mdwn
1 # Building AltOS
2
3 The AltOS source tree has a fairly long list of build dependencies, because
4 it builds firmware for at least 4 different processor cores, ground station 
5 software in Java, various utilities in C, etc.  By *far* the easiest way to
6 build from source is to start with a [Debian](http://debian.org) 'unstable' 
7 installation and take advantage of Debian tools and processes.  From this
8 platform, it is possible to build installable packages not only for Debian,
9 but also for Windows, Mac OS X, and generic Linux.
10
11 ## Compilers
12
13 We use standard gcc and OpenJDK to build all of the ground software, but the
14 situation for building the firmware is a bit more complicated.  Because we
15 realize many people may be only interested in working on the ground station
16 software, or may only care about building firmware for a single target, we
17 have crafted the Makefile contents to test for the presence of the various
18 compilers... and will only build firmware for the targets we can find the
19 right tools for!
20
21 ### cc1111
22
23 The first generation of Altus Metrum products were all based on the TI cc1111,
24 which has an 8051 core.  We started out using standard SDCC, but Keith made a
25 number of changes to better support the cc1111, and then SDCC 3.X changed code
26 generation such that 8051 executables became significantly larger and our code
27 just wouldn't fit in available flash any more!  
28
29 As a result, we maintain a fork of SDCC we call 'cc1111' that is based
30 on the last upstream version of SDCC 2.X, plus a highly modified sdcdb with
31 support for the cc1111 debugging interface.  This is avilable as a package in
32 Debian, or you can find the sources on [git.gag.com](http://git.gag.com)
33 in the project [debian/cc1111](http://git.gag.com/?p=debian/cc1111;a=summary).
34
35 ### AVR
36
37 We use the standard gcc-avr tools for this target, which thanks to the 
38 popularity of the [Arduino](http://arduino.cc) community are well taken care 
39 of in Debian.
40
41 ### ARM Cortex
42
43 Most of the new products we're working on now are based on system on chip
44 parts using ARM Cortex M3 or ARM Cortex M0 cores.  These require a "bare metal"
45 toolchain, not the standard ARM compiler and libraries used for ARM Linux.  We
46 continue to discuss our needs with others in the Debian community and have
47 high hopes for a suitable toolchain to eventually be part of the main 
48 distribution.  But, in the meantime, here's what it takes to build a suitable
49 toolchain in /opt/cortex:
50
51 * mkdir /opt/cortex, and ensure it's owned by you (so no root privs are needed)
52 * clone our [cortex-toolchain](http://git.gag.com/?p=fw/cortex-toolchain;a=summary) with `git clone git://git.gag.com/fw/cortex-toolchain`
53 * cd into the cortex-toolchain directory, review the list of build dependencies
54   documented in the README file, then build using 
55   `./summon-arm-toolchain`.  This will download all
56   the source packages, unpack them, build everything, and install it all in
57   /opt/cortex automatically.  This takes a bunch of disk space and a lot of
58   time, so be patient!
59 * clone our [pdclib](http://git.gag.com/?p=fw/pdclib;a=summary) C library
60   repository with `git clone git://git.gag.com/fw/pdclib`
61 * cd into the pdclib directory, and build using `make ; make install` which
62   will build the library using the just-installed cortex tools and deliver
63   the results to the /opt/cortex tree
64
65 That's it!  You should now have an ARM toolchain targetting bare metal for
66 both Cortex M0 and M3 variants including a minimal C runtime library.
67
68 If you're using a debug/programming interface from ST (either an STlinkV2 USB
69 dongle or something like a Discovery board) then you may also want to build
70 and install tools for that as follows:
71
72 * clone our fork of the [stlink](http://git.gag.com/?p=fw/stlink;a=xummary) 
73   reposirtory with `git clone git://git.gag.com/fw/pdclib`
74 * cd into the stlink directory, and build using 
75   './configure --prefix=/opt/cortex; make ; make install'.  This will install
76   the stlink library and related utilities in /opt/cortex.
77