从linux到ARM-ELF的交叉编译(armv5tejl)

时间:2017-05-11 01:53:41

标签: arm embedded-linux elf

到目前为止,我已经在我的ubuntu系统上安装了所有交叉编译软件包,但是遇到了问题,需要一些帮助。

Linux 2.6.28.7 #1  CST 2012 armv5tejl unknown

$ cat /proc/cpuinfo
Processor       : ARM926EJ-S rev 5 (v5l)
BogoMIPS        : 199.47
Features        : swp half fastmult edsp java
CPU implementer : 0x41
CPU architecture: 5TEJ
CPU variant     : 0x0
CPU part        : 0x926
CPU revision    : 5

Hardware        : ServerEngines PILOT3
Revision        : 0000
Serial          : 0000000000000000


user@ubuntu:~/code$ arm-linux-gnueabi-readelf -h xxx.bin 
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:               0xa27c
  Start of program headers:          52 (bytes into file)
  Start of section headers:          128752 (bytes into file)
  Flags:                             0x2, GNU EABI, <unknown>
  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

这是我需要交叉编译的目标机器。编译时我应该使用哪些标志?

arm-linux-gnueabi-gcc simple.c -march=armv5 -static -o simplev5
arm-linux-gnueabi-gcc simple.c -mcpu=arm926ej-s -static -o simple926

当我运行simplev5或simple926时,显示:

Segmentation fault

按照@Steven P的建议,我检查了文件格式,如下:

user@ubuntu:~/code$ file simplev5
simplev5: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=f0607da1d809a7d98636d76ee0e538fc828e3b65, not stripped
user@ubuntu:~/code$ file simple926 
simple926: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=ed1e6fdade02c0d2c985a503dafb6efadd13522f, not stripped

1 个答案:

答案 0 :(得分:1)

您很可能拥有正确的编辑,否则您将收到有关无效格式的错误。您可以使用以下方法确认您拥有正确的文件格式:

file simple926

尝试更简单的程序:

int main() { return 123; }

然后,您可以在运行结果代码时检查结果代码以确认它已执行某些操作。

./simple926
echo $?

要解决您的分段错误,您可能需要离开gdb并检查堆栈(回溯)。