In this post, we will cross-compile a small baremetal program for ARM processor on an Ubuntu machine.
ARM cross-compile toolchain
First step is to install the ARM cross-compiler toolchain. Luckily Ubuntu already has it in its software repository. Execute the following command in the terminal to install ARM EABI compatible tool chain:
sudo apt install gcc-arm-none-eabi
Check the version of the installed compiler using the following command:
Sample baremetal program
Now, we need a sample baremetal program to compile. I have choosen a very simple assembly program.
.global _start _start: B _reset /* Reset */ B . /* Undefined */ B . /* SWI */ B . /* Prefetch Abort */ B . /* Data Abort */ B . /* reserved */ B . /* IRQ */ B . /* FIQ */ _reset: mov r1, #10 ldr r0, =0x20000000 str r1, [r0] ldr r2, [r0] B .
Lets assemble the assembly file using GCC assembler.
arm-none-eabi-as -mcpu=cortex-m3 -g startup.S -o startup.out
Finally lets link the object file
startup.out generated by the assembler.
arm-none-eabi-ld -Ttext=0x0 -o startup.elf startup.out
Note: Since the program is very simple, I haven’t used any linker script here.
-Ttext=0x0 option instructs the linker to use 0x0 as the starting address of