1

I have a C program which I want to benchmark on an (old) custom embedded platform. The problem is that I only have the hardware but not the toolchain to compile programs for this platform. The CPU is an Atmel AT91SAM9260 (ARM) and runs an embedded Linux to which I have full access. I have downloaded a program from the embedded system and analyse its format with 'readelf -h ...':

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            ARM
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8520
  Start of program headers:          52 (bytes into file)
  Start of section headers:          3772 (bytes into file)
  Flags:                             0x602, has entry point, GNU EABI, software FP, VFP
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         25
  Section header string table index: 24

Then I have written the following test program:

#include <stdio.h>

int main() {
  printf("Hello World!\n");
  return(0);
}

If I use the standard ARM cross-compiler in Ubuntu 12.04 (arm-linux-gnueabi-gcc test.c -o test), the wrong EABI is chosen (Version5 EABI instead of GNU EABI) and it doesn't run on the embedded system (access rights etc. are correct).

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x8881
  Start of program headers:          52 (bytes into file)
  Start of section headers:          372148 (bytes into file)
  Flags:                             0x5000002, has entry point, Version5 EABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         30
  Section header string table index: 27

If I use a bare metal compiler like Sourcery CodeBench I get errors like "undefined reference to...". This is clear because the stdlib is missing. I have tried to solve it by copying all lib-files from the embedding platform to the host and compile it with "./arm-none-eabi-gcc test.c -o test -static -lc -L ./lib". I still get (the same) undefined reference errors.

What is best practise to compile a C program for an embedded system if the toolchain is unknown?

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
user3226575
  • 107
  • 1
  • 7
  • Perhaps `arm-linux-eabi-`? – D Krueger Jan 31 '14 at 23:46
  • `-mabi=` ? http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html – auselen Feb 01 '14 at 19:46
  • I think the problem is that support for arm-elf targets (GNU EABI) has been dropped in newer GCC versions. Only arm-eabi targets are supported now (http://www.rtems.org/pipermail/rtems-devel/2012-April/000893.html). I will try to get older toolchains and specify the target with --target=arm-elf and see if this works. – user3226575 Feb 01 '14 at 22:51
  • use arm-none-linux-gnueabi-gcc from Sourcery CodeBench .also refer http://stackoverflow.com/questions/21217425/cross-compile-error-arm-none-eabi-g-can-not-find-entry-symbol/21217588#21217588 – vinay hunachyal Feb 14 '14 at 04:36

0 Answers0