Sunday, March 2, 2014

Cross compiling programs (userspace) for embedded Linux ARM boards like OLinuXino


This post describes how to use a Ubuntu Desktop/Laptop to compile C programs that can run on embedded ARM boards like iMX233-OLinuXino-MAXI
  1. On your Ubuntu x86 laptop (I used Ubuntu 12.04 x86), visit http://www.mentor.com/embedded-software/codesourcery and click on "Download Lite Edition". Sourcery CodeBench Lite Edition is a free, unsupported version of Sourcery CodeBench, available for select processors.
  2. On the next page, click on "Download the GNU/Linux Release" under the section titled "ARM Processors" 
  3. You will need to enter you contact details on the next page before you can download. The download link will be emailed to you. Click on the link in your mail. It will be something like:
    Download your Lite edition copy of Sourcery CodeBench now: http://go.mentor.com/3kcqy
  4. On the page that opens up, there will be a link to the recommended latest version of the compiler as well as links to the older releases. Click on the link to the recommended release. It will look something like:
    Recommended Release
    This is a fully-validated release.
    Download Sourcery CodeBench Lite 2013.11-33
  5. On the next page, you will be asked to select the package. The package depends on the operating system on which we want to run the compiler. In our case its Ubuntu, so we must select: "IA32 GNU/Linux Installer":
    Package needs to be selected depending on your host computer's operating system
  6. The download will begin. The will be named something like:
    arm-2013.11-33-arm-none-linux-gnueabi.bin
  7. Make sure you have around 1GB of free space on your hard drive before you bein installation of the compiler.
  8. Execute the compiler by issuing the command: ./arm-2013.11-33-arm-none-linux-gnueabi.bin
    (You will need to change the name of the file to that of the one you actually downloaded)
    (Also, you might need to change the permission on the file: sudo chmod +x arm-2013.11-33-arm-none-linux-gnueabi.bin)
  9. The installation wizard will be launched. Just follow the steps and complete the installation.
    Installation Wizard
  10. After completing the installation, reboot the system and issue the command:
    arm-none-linux-gnueabi-gcc -v
    Confirming if the compiler is working properly post installation using the version checking command.
  11. Create a hello world program. Execute the command gedit hello.c and type the following lines of code in it:
    1
    2
    3
    4
    #include
    main() {
        printf("Hello World\n");
    }
    

  12. Compile the program using the command arm-none-linux-gnueabi-gcc hello.c
  13. We need to now transfer the compiled executable a.out to our OLinuXino. We can do this using the scp command if the OLinuXino board is attached to the same local area network as your host PC. We would also remove the SD card from the OLinuXino board and copy the executable to it but doing that repeatedly while developing a program would be too cumbersome and time consuming. So if you were operating out of your home folder on your development PC, issue the following command to copy the file to the OLinuXino which in my case had the IP address 10.10.10.22:
    scp a.out root@10.10.10.22:~
    Using SCP to transfer files to OLinuXino.
    When prompted for password, enter root
  14. Now using PuTTY (works on Windows as well as Linux), connect to OLinuXino over serial port or network. Use login as root and password as root. You can run the program by issuing the command to the board: ./a.out
    Hello World running on OLinuXino.
NOTES:
  1. In case the hello world program doesn't execute, you may need to set the permission to allow the compiled binary file. Issue the command to the board using PuTTY: chmod +x a.out
  2. If you connect your OLinuXino ARM board to your WiFi router, the router will assign it an IP address using DHCP. Now if you want to access the console of your OLinuXino ARM Board, you can either do it over serial port or network. In case of network you will need to figure out the IP address of your ARM board. To do this use the router's web management GUI to figure out what IP address has been assigned to the ARM board. If your router doesn't show you a list of devices and the IP addresses assigned to them, you can use Advanced IP Scanner (works on Windows) or Angry IP Scanner (Java based, works on Windows as well as Linux) to ping the local IP address range and figure out the IP address of OLinuXino. Use username as root and password as root to login.
    Using Angry IP Scanner to figure out the IP address of OLinuXino.
    IP address is required for the SCP/SSH clients (PuTTY, WinSCP, scp command)
    to connect to OLinuXino on the local network.
  3. scp equivalent for Windows is WinSCP. You can use this to transfer files to your OLinuXino ARM board. This is useful if you are running Ubuntu using VMWare or VirtualBox on your Windows Host PC. This way yopu can share a folder between Ubuntu and and use WinSCP - which has a nice GUI - to transfer files to your ARM Board. Use username as root and password as root to login.

0 comments:

Post a Comment