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:
In the directory build-gcc/gcc
, there exists an as
script file to be invoked instead of the /usr/bin/as
. When I renamed as
to as_temp
, and rerun, everything works fine.
The environmental variable AS=/usr/bin/as
does not seem to solve this issue.
I needed one more modification that /opt/cross/arm-elf-eabi/sys-root/usr/include
should be created in order to prevent another error message.
I also found that this site is pretty useful in cross compilation on Mac OS X.
There's a pre-configured cross-compiler, its name is Linaro, and you can get it from the official site. If you need, here's a guide which shows you how to install it and compile with it. For example, for .c files:
${PREFIX}gcc -Wall -Wextra -Os -ffreestanding -mcpu=cortex-a8 -march=armv7-a -mfpu=neon -marm -c filename.c
where Prefix stands for the directory where you've installed the tool.
Install homebrew, brew cask and then:
brew cask install gcc-arm-embedded
This is the way how I make the cross compilation on Mac OS X, and execute the qemu to check if it works.
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.
.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
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
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
--gstabs+
is the flag to use