How to make ARM cross compilation on Mac OS X (error: invalid listing option `r' - cross compiling error)

前端 未结 4 577
栀梦
栀梦 2020-12-18 07:18

I\'m trying to build a gcc cross compiler on Mac OS X, the target is arm-elf-eabi.

This is what I\'ve done so far:

Install gcc and environmenta

4条回答
  •  感动是毒
    2020-12-18 08:04

    This is the way how I make the cross compilation on Mac OS X, and execute the qemu to check if it works.

    Compilation

    Just follow this instruction - https://github.com/jsnyder/arm-eabi-toolchain

    mkdir /opt/arm # and make it writable
    PREFIX=/opt/arm PROCS=8 CC=clang make install-cross
    PREFIX=/opt/arm PROCS=8 CC=clang make cross-gdb
    

    Check if all the binary files are available.

    Pre-built compiler

    • http://sourceforge.net/projects/yagarto/files/
    • https://launchpad.net/gcc-arm-embedded/+download

      qemu simulation

    Source code

    .text
    entry: b start
    arr:    .byte 1, 2, 3, 4, 5, 6
    eoa:
    .align
    start:  
        ldr r0, =eoa
        ldr r1, =arr
        mov r3, #0
    loop:
        ldrb r2, [r1], #1
        add r3, r2, r3
        cmp r1, r0
        bne loop
    stop:   b stop
    

    Build script

    dd if=/dev/zero of=flash.bin bs=4096 count=4096
    arm-none-eabi-as --gstabs+ -o add.o add.S
    arm-none-eabi-ld -Ttext=0x0 -o add.elf add.o
    arm-none-eabi-objcopy -O binary add.elf add.bin
    dd if=add.bin of=flash.bin bs=4096 conv=notrunc
    

    Execute

    Start the qemu

    qemu-system-arm -M connex -pflash flash.bin -gdb tcp::1234 -S
    

    Execute the debugger

    arm-none-eabi-gdb add.elf
    

    Inside the debugger start the connection

    target remote :1234
    

    You can use n to execute the line one by one.

    (gdb) target remote :1234
    Remote debugging using :1234
    entry () at add.S:2
    2   entry: b start
    (gdb) n
    7       ldr r0, =eoa
    (gdb) n
    8       ldr r1, =arr
    (gdb) n
    9       mov r3, #0
    (gdb) n
    11      ldrb r2, [r1], #1
    (gdb) n
    12      add r3, r2, r3
    (gdb) n
    13      cmp r1, r0
    (gdb) n
    14      bne loop
    (gdb) n
    11      ldrb r2, [r1], #1
    (gdb) n
    12      add r3, r2, r3
    

    References

    • Qemu flash boot up does not work
    • GDB Debugging ARM U-Boot on QEMU
    • Debugging ASM
      • --gstabs+ is the flag to use

提交回复
热议问题