Hempl/Compiling Hempl

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Use the Web Builder[edit | edit source]

The Mizar32 Web Builder at http://builder.simplemachines.it lets you customise the firmware in several ways and will build you a new firmware image without you having to do any of this horrible stuff. But unfortunately at the moment, we don't have this feature yet for Hempl. See issue #4.

If that doesn't do enough for you, or if you just enjoy this kind of thing, then take a deep breath and...

Install an AVR32 cross-compiler[edit | edit source]

On GNU/Linux[edit | edit source]

Atmel AVR 32-bit Toolchain 3.4.2[edit | edit source]

The cross-compiler for GNU/Linux is the Atmel AVR Toolchain for Linux.

At the time of writing, July 2015, the latest version is Atmel AVR Toolchain 3.4.2, based on the GNU C Compiler version 4.4.7.

To skip the Atmel registration form, you can use these quick download links:

You will also need

and, if you are interested in building the toolchain yourself, the source code is here:

Fetching and unpacking the toolchain[edit | edit source]

Here we show the steps to install the 32-bit version:

wget http://www.atmel.com/Images/avr32-gnu-toolchain-
tar xfz avr32-gnu-toolchain-
# Fetch, unpack and install the header files
wget http://www.atmel.com/Images/atmel-headers-
unzip atmel-headers-
mv atmel-headers- avr32-gnu-toolchain-linux_x86/avr32/include/
# Clean up
rm -r atmel-headers*
rm avr32-gnu-toolchain-*.gz

then, to use it, once per session:

export PATH

you can, set the include path (C_INCLUDE_PATH), to use atmel-headers- with avr32.

For the 64-bit version, replace every "x86" in the above with "x86_64"

Installing it as a Debian/Ubuntu package[edit | edit source]

To make a Debian/Ubuntu package out of this, do the above, then go:

sudo apt-get install alien fakeroot
cd avr32-gnu-toolchain-linux_x86
mkdir usr
mv [a-s]* usr/
# It includes a lot of files that it shouldn't, so select the toolchain ones.
tar cfz avr32-gnu-toolchain-3.4.2.tgz usr/avr32 usr/bin/avr32-* \
    usr/lib/gcc/avr32 usr/libexec usr/share/man/man1 
fakeroot alien --keep-version avr32-gnu-toolchain-3.4.2.tgz
mv avr32-gnu-toolchain_3.4.2-1_all.deb avr32-gnu-toolchain_3.4.2-1_i386.deb
rm avr32-gnu-toolchain-3.4.2.tgz
rm -r usr

or, for the 64-bit version, do the same thing in avr32-gnu-toolchain-linux_x86_64 and rename the .deb file to ..._amd64.deb

If you had installed their old 2.4.2 Ubuntu packages, you will need to remove those first:

sudo apt-get purge avr32-binutils avr32-buildroot-essentials avr32-gcc-newlib \
 avr32-gdb avr32gdbproxy avr32headers avr32parts avr32program avr32trace \
 avrfwupgrade libavr32ocd libavr32sim libavrtools libelfdwarfparser

then you can install the new toolchain with

sudo dpkg -i avr32-gnu-toolchain_3.4.2-1_*.deb

(to remove it again, sudo apt-get purge avr32-gnu-toolchain)

Build a toolchain from source code[edit | edit source]

ct-ng, a fork of crosstool-ng, builds better AVR32 cross compilers for you:

sudo apt-get install git autoconf bash gawk g++ libncurses-dev
git clone http://anonymous@spaces.atmel.com/git/ct-ng 
cd ct-ng
./configure --enable-local
./ct-ng build

By default, it installs the cross-toolchain under your home directory, so before building eLua you need to say:

export PATH

On Windows[edit | edit source]

Atmel also provide the Atmel AVR Toolchain for Windows as a setup.exe, for which the quick download link is:

Install the build system[edit | edit source]

The Hempl build system (same as the official elua0.9) uses "scons" and "gcc". The Hempl sources are under git, so install those.

On Debian or Ubuntu:

sudo apt-get install scons gcc git

Download the sources[edit | edit source]

Stable release[edit | edit source]

The latest stable source release is hempl-1.0, which fully supports the Mizar32 boards.

wget https://github.com/simplemachines-italy/hempl/archive/v1.0.tar.gz
tar xfz v1.0.tar.gz
cd v1.0

An alternative is:

The current development version[edit | edit source]

The Hempl project[edit | edit source]

git clone https://github.com/simplemachines-italy/hempl.git
cd hempl

Compile Hempl[edit | edit source]

For Mizar32 A and B[edit | edit source]

The 256KB and 512KB flash/64MB internal RAM versions of Mizar32 use the same Hempl firmware. Use this command:

scons board=mizar32 cpu=AT32UC3A0256

If you're compiling the Hempl sources, the build will create a file hempl_at32uc3a0256.elf.

For Mizar32 C[edit | edit source]

We can't directly compile Hempl for Mizar32-C. It only has 128K of flash! There's another way. We use emBLOD for that. To understand how that works, see the chapter The emBLOD second-stage boot loader.

Program the firmware to the board[edit | edit source]

When the compilation is finished, it should have created a file called something like hempl_at32uc3a0256.elf which can be programmed into the Mizar32 board in various ways: see the chapter on Flashing firmware.

If you will be using dfu-programmer to do this, you will first need to convert your .elf file to a .hex file. For example:

avr32-objcopy -O ihex $hempl.elf $hempl.hex