Compile a C program for an embedded system if the toolchain is unknown

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?

链接地址: http://www.djcxy.com/p/15244.html

上一篇: 编译和运行ARM Linux的hello world

下一篇: 如果工具链是未知的,则编译嵌入式系统的C程序