Archive

Posts Tagged ‘GCC’

Building gcc as cross-compiler

Motivation

A cross-compiler is a compiler that runs on your PC and reads source code in your PC and converts that into binary suitable for some other CPU. Sometimes the precise cross compile tool may not be available as a binary package. For example, in my case i wanted to use bare-metal x86 tools(To build BIOS or similar low level system software). It was not available as binary package. Hence only option is to build it.

Dependencies

The packages and libraries needed to build gcc are well documented along with gcc. If you usually build softwares on your linux build PC, there are not much extra dependencies on the PC. One important dependency to build cross gcc is you should already have cross binutils for the same platform. And the binaries especially linker(ld) and assembler(as) should be available in the path. Eg. to build i686-elf-gcc, i686-elf-ld and i686-elf-as should be available in the system path. So

  1. Step 1 is to build binutis
  2. Step 2 is to build gcc

Further I will list the steps needed to build the cross gcc; specifically the i686-elf variant

Step 1: Build binutils as cross-tool

Download binutils. Extract, configure from a separate build directory, build and install it using following commands.

tar -xvf binutils-2.26.tar.bz2
mkdir build_binutils
cd build_binutils
../binutils-2.26/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --with-sysroot
make
make install
cd ..

All binaries will be available in the path specified in <path-to-bin>

Step 2: Build gcc as cross-tool

First set the path to binutils executables that got generated in the previous step.

PATH=<path-to-bin>:$PATH

Download, extract, configure from a separate build directory, build and install it using following commands

tar -xvf gcc-gcc-4_9_3-release.zip
mkdir build_gcccd build_gcc
../gcc-gcc-4_9_3-release/configure --target=i686-elf --prefix=<path-to-bin> --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

All binaries and libraries generated will be available in path specified in <path-to-bin>

References

OSDev: GCC Cross-Compiler

OSDev: GCC tool naming/prefix convention

Categories: Log, Tech Tags: , , ,

Getting FreeRTOS to work with GCC and LPC2129

March 10, 2011 Leave a comment

FreeRTOS is a good OS to start with, if you have some fairly good hardware, like an LPC2129, ARM based chip. FreeRTOS is aimed to work with different processor architectures. The OS has two parts – a set of architecture independent codes, and a set of architecture specific codes called ports. The syntax for non standard functionalities like interrupt handling and inline assembly will be different for different compilers. Interrupt Service Routines and inline assembly are typically necessary for the architecture dependent files. Therefore, a port will be specific to a compiler and a target chip. But the present version of FreeRTOS doesn’t have a port for LPC2129 – GCC combination.

I assume that you have a working gcc compiler and other tools already installed. Refer to ARM Development under Ubuntu 10.04, for how to setup tools under Linux. Download FreeRTOS from sourceforge.net. Unzip into a convenient location.

The files you will need to compile are

  • list.c, queue.c, task.c and croutine.c from Source/
  • port.c and portISR.c form Source/portable/GCC/ARM7_LPC2000
  • heap_2.c from Source/portable/MemMang
  • A file containing the main() routine
  • boot.s and lpc2106-rom.ld from Demo/ARM7_LPC2106_GCC
  • LPC21xx.h from Demo/ARM7_LPC2138_Rowley

Rename lpc2106-rom.ld to LPC2129-ROM.ld, and open it using text editor. You will see the following at the start of the file.

Change these lines as displayed in the following figure. The size of the Flash and RAM are modified to that of the LPC2129.A simple main file will look like

#include “FreeRTOS.h”
#include “task.h”

int main(void)
{

unsigned char para0, para1;
para0 = 0;
xTaskCreate( foobar, “NAME”, configMINIMAL_STACK_SIZE, &para0, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
para1 = 1;
xTaskCreate( foobar, “NAME”, configMINIMAL_STACK_SIZE, &para1, tskIDLE_PRIORITY, ( xTaskHandle * ) NULL );
vTaskStartScheduler();
while(1);

}

void foobar( void* pvParameters )
{

unsigned char *flag;
flag=(unsigned char*)pvParameters;
while (1){

if(*flag==0){

//do something

}
else{

//do something else

}

}

}

(Thanks to my friends Abhishek and Nisarg for the original main file)

Now you can compile and link all the files specified above, along with the libc.a , specified by linker option -lc, and chip specification -TLPC2129-ROM.ld. Also add Source/include directory to your include/compiler search path.

The generated elf file can be converted to hex file using arm-elf-objcopy command (if you have followed ARM Development under Ubuntu 10.04 ). The program can be dumped into the LPC2129 chip through the serial connection using command lpc21isp

eg:- lpc21isp -control -hex trial.hex /dev/ttyS0 9600 12000 will program trial.hex into the chip, through serial port ttyS0 at 9600 baud per second. 12000 is the frequency of the crystal (in kHz) used for the LPC2129 chip.

Categories: Tech Tags: , , ,