Linux中针对ARM 9的交叉编译

时间:2013-11-17 21:52:58

标签: linux arm cross-compiling

我总是使用这个程序在我的Arch Linux机器上交叉编译ARM926ej-s的程序:

第一我使用以下方法编译程序集源文件:

arm-none-eabi-as -mcpu=arm926ej-s -c -Wall -ooutput_as.o input_as.s

第二次我使用以下方法编译C源文件:

arm-none-eabi-gcc -mcpu=arm926ej-s -c -Wall -mno-thumb-interwork -mapcs-frame -mno-sched-prolog -fno-hosted -O3 -gdwarf-2 -ooutput_c.o input_c.c

3rd 我链接这些以获取可执行的精灵文件executable

arm-none-eabi-ld -Tlinker_script.ld -oexecutable output_as.o output_c.o 

第4次我使用以下方法将elf转换为二进制文件:

arm-none-eabi-objcopy -Ielf32-littlearm -Obinary --strip-all --verbose executable executable_bin

5th 我使用应用程序unsimgcr为USB-DFU传输准备二进制文件 - 此应用程序以某种方式准备要上传到ARM微处理器的格式:

unsimgcr -pd executable_bin executable_bin_usb

然后我通常使用应用程序dfu-util将准备好的程序executable_bin_usb上传到ARM926ej-s:

sudo dfu-util -R -t2048 -Dexecutable_bin_usb

由于某些原因,当我使用unsimgcr时,在步骤 5 时出现此错误:

[ziga@ziga-cq56 test]$ unsimgcr -pd executable_bin executable_bin_usbLPC3130/31/41/52 Un-Secure Image Creator Utility v1.1

Opening executable_bin
Incompatible file size!

有没有人知道我可能做错了什么或我的程序有什么问题只是一个基本的测试程序 - 这里是我得到的所有源文件here(这个工具链适用于其他程序):

input_as.s

.section INTERRUPT_VECTOR, "x"
.global _Reset
_Reset:
  B Reset_Handler
  B . 
  B .
  B .
  B .
  B .
  B .
  B .

Reset_Handler:
  LDR sp, =stack_top
  BL c_entry
  B .

input_c.c

int c_entry() {
  return 0;
}

linker_script.ld

ENTRY(_Reset)
SECTIONS
{
 . = 0x11029000;
 .text : {
 startup.o (INTERRUPT_VECTOR)
 *(.text)
 }
 .data : { *(.data) }
 .bss : { *(.bss) }
 . = . + 0x1000;
 stack_top = .;
}

在链接器脚本中,我们在ARM所需的位置0x11029000设置了入口点,但我不知道为什么我的程序的大小不兼容......有没有人有任何线索?

如果我使用命令arm-none-eabi-readelf -a executable获取有关我的精灵文件executable的一些信息,我会收到此信息。它可能会派上用场:

[ziga@ziga-cq56 test]$ arm-none-eabi-readelf -a executable
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:               0x11029000
  Start of program headers:          52 (bytes into file)
  Start of section headers:          4716 (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:         1
  Size of section headers:           40 (bytes)
  Number of section headers:         14
  Section header string table index: 11

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        11029000 001000 000038 00  AX  0   0  4
  [ 2] .ARM.attributes   ARM_ATTRIBUTES  00000000 001038 000030 00      0   0  1
  [ 3] .comment          PROGBITS        00000000 001068 00002a 01  MS  0   0  1
  [ 4] .debug_abbrev     PROGBITS        00000000 001092 000034 00      0   0  1
  [ 5] .debug_info       PROGBITS        00000000 0010c6 000044 00      0   0  1
  [ 6] .debug_line       PROGBITS        00000000 00110a 000035 00      0   0  1
  [ 7] .debug_pubnames   PROGBITS        00000000 00113f 00001e 00      0   0  1
  [ 8] .debug_aranges    PROGBITS        00000000 00115d 000020 00      0   0  1
  [ 9] .debug_str        PROGBITS        00000000 00117d 000034 01  MS  0   0  1
  [10] .debug_frame      PROGBITS        00000000 0011b4 000020 00      0   0  4
  [11] .shstrtab         STRTAB          00000000 0011d4 000097 00      0   0  1
  [12] .symtab           SYMTAB          00000000 00149c 000140 10     13  17  4
  [13] .strtab           STRTAB          00000000 0015dc 000035 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings)
  I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
  O (extra OS processing required) o (OS specific), p (processor specific)

There are no section groups in this file.

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x11028000 0x11028000 0x01038 0x01038 R E 0x8000

 Section to Segment mapping:
  Segment Sections...
   00     .text 

There is no dynamic section in this file.

There are no relocations in this file.

There are no unwind sections in this file.

Symbol table '.symtab' contains 20 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 11029000     0 SECTION LOCAL  DEFAULT    1 
     2: 00000000     0 SECTION LOCAL  DEFAULT    2 
     3: 00000000     0 SECTION LOCAL  DEFAULT    3 
     4: 00000000     0 SECTION LOCAL  DEFAULT    4 
     5: 00000000     0 SECTION LOCAL  DEFAULT    5 
     6: 00000000     0 SECTION LOCAL  DEFAULT    6 
     7: 00000000     0 SECTION LOCAL  DEFAULT    7 
     8: 00000000     0 SECTION LOCAL  DEFAULT    8 
     9: 00000000     0 SECTION LOCAL  DEFAULT    9 
    10: 00000000     0 SECTION LOCAL  DEFAULT   10 
    11: 11029020     0 NOTYPE  LOCAL  DEFAULT    1 Reset_Handler
    12: 11029000     0 NOTYPE  LOCAL  DEFAULT    1 $a
    13: 1102902c     0 NOTYPE  LOCAL  DEFAULT    1 $d
    14: 00000000     0 FILE    LOCAL  DEFAULT  ABS main.c
    15: 11029030     0 NOTYPE  LOCAL  DEFAULT    1 $a
    16: 00000010     0 NOTYPE  LOCAL  DEFAULT   10 $d
    17: 11029538     0 NOTYPE  GLOBAL DEFAULT  ABS stack_top
    18: 11029030     8 FUNC    GLOBAL DEFAULT    1 c_entry
    19: 11029000     0 NOTYPE  GLOBAL DEFAULT    1 _Reset

No version information found in this file.
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM926EJ-S"
  Tag_CPU_arch: v5TEJ
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_enum_size: small
  Tag_DIV_use: Not allowed

0 个答案:

没有答案