ARM cross development in Linux

Linux is growing attractive for Embedded engineers day after day. One good thing about Linux is that GNU C compiler is available for almost any CPU architecture you can name. ARM is no exception. This post is about setting up the development environment to cross compile applications for ARM.

Cross compiling is the process in which code for a target processor is compiled in a different host processor. This is usually done because the target processor might not have enough resources to be able to compile applications on it. In our case target processor is ARM and host processor is x86.

First you need to download the cross compiler tool chain. You can either build your own tool chain or download prebuilt tool chain. I prefer using the prebuilt version. To download the toolchain, visit

http://www.gnuarm.com/

http://download.ronetix.info/toolchains/arm/

Once you have downloaded the toolchain, uncompress it in the place of your choice. I uncompressed it in /usr/cross/. Now add the following line to the end of .bashrc file in your home directory.

export PATH=$PATH:/usr/cross/arm-elf/bin/

Replace the /usr/cross/arm-elf/bin with the path to the bin directory where you have extracted your toolcahin. Now test tool chain by typing the following

arm-elf-gcc -v

This should print out some information regarding your tool chain. If it prints out Command not found, then you have entered wrong path in the export statement. Now let us compile our first program for ARM.

.global _start
_start:    mov r1,#21;
mov r2,#32;
add r3,r1,r2;
b _start;
.end

Save this file as arm_hello.asm. Now type the following in terminal to compile this assembly file.

arm-elf-as arm_hello.asm -o arm_hello.o
arm-elf-ld arm_hello.o -o main.elf

If your arm_hello.o and main.elf files are created, congrats! Your ARM toolchain is working. In our next post we will discuss a more complex project involving makefiles and linker files.

tejainece

Ravi Teja is a technology entrepreneur with interest in Embedded Systems, Software engineering, Operating Systems, Web development, Cloud computing, Machine learning, etc.

More Posts - Website

Follow Me:
LinkedInGoogle Plus