world leader in high performance signal processing
Trace: » simple_hello_world_application_example

Simple Hello World Application Example

This section shows how to compile, download and run a simple “Hello, World” Linux application on a Blackfin STAMP board. For information on more detailed application development, please see the Application Development section.

Here is the program 'hello.c':

#include <stdio.h>
int main() {
        printf("Hello, World\n");
        return 0;

Compiling the application

The Blackfin GCC toolchain comes with three categories:

  1. bfin-elf-*,
  2. bfin-linux-uclibc-* &
  3. bfin-uclinux-*

bfin-uclinux-gcc and bfin-linux-uclibc-gcc are used to compile programs that run on the Linux operating system. They automatically link the application with the the Linux run time libraries, which in turn call the Linux operating system when required (for example, to print a string to the console).

The bfin-elf-gcc compiler is used to compile the Linux kernel and standalone programs as it uses a different set of libraries.

The first step is to ensure that bfin-uclinux-gcc is in your current path.

rgetz@imhotep:~> bfin-uclinux-gcc --version
bfin-uclinux-gcc (ADI-trunk/svn-3343) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO


rgetz@imhotep:~> bfin-uclinux-gcc --version
bash: bfin-uclinux-gcc: command not found

If this results in command not found, then you must modify your PATH to include it. If you installed the rpm package, then it is located in /opt/uClinux/bfin-uclinux/bin/. If you installed the binary tarball, or compiled from source, it will be some other place. See Installing the Blackfin GNU Toolchain for more information.

The second step is to compile hello.c on your host PC:

Compiling as a FLAT file

rgetz@imhotep:~/src> bfin-uclinux-gcc -Wl,-elf2flt hello.c -o hello

Please note that -Wl,-elf2flt has no space between the comma or the dash, and that the character after the W is a lower case L, not the number 1

The output executable is 'hello', also it creates a file “hello.gdb” which is used for debugging.

rgetz@imhotep:~/src> ls -l hello*
-rwxr--r-- 1 rgetz users  5160 2009-04-30 11:16 hello
-rw-r--r-- 1 rgetz users    87 2009-04-30 11:15 hello.c
-rwxr-xr-x 1 rgetz users 78494 2009-04-30 11:16 hello.gdb
rgetz@imhotep:~/src> file hello
hello: BFLT executable - version 4 ram
rgetz@imhotep:~/src> file hello.gdb
hello.gdb: ELF 32-bit LSB executable, Analog Devices Blackfin, version 1 (SYSV), statically linked, not stripped

Compiling as a FDPIC program

Need to use “bfin-linux-uclibc-gcc”.

rgetz@imhotep:~/src> bfin-linux-uclibc-gcc hello.c -o hello

The output executable is 'hello'.

rgetz@imhotep:~/src> ls -l hello*
-rwxr-xr-x 1 rgetz users 10688 2009-04-30 11:17 hello
-rw-r--r-- 1 rgetz users    87 2009-04-30 11:15 hello.c
rgetz@imhotep:~/src> file hello
hello: ELF 32-bit LSB executable, Analog Devices Blackfin, version 1 (SYSV), dynamically linked (uses shared libs), not stripped

Since the output of the compilation has not been stripped, and includes debugging information, which is not necessary for running the application, this can be removed before downloading things to the target.

rgetz@imhotep:~/src> bfin-linux-uclibc-strip hello
rgetz@imhotep:~/src> ls -l hello*
-rwxr-xr-x 1 rgetz users 3556 2009-04-30 11:22 hello
-rw-r--r-- 1 rgetz users   87 2009-04-30 11:15 hello.c

Downloading to the board

The next step is to download the hello to your Blackfin board. There are many ways to do this, involving either the serial port or ethernet.

Including in the uClinux-dist image

On the host:

host:~/checkouts/uClinux-dist> cp ~/test/hello ./romfs/bin/hello
host:~/checkouts/uClinux-dist> make image

This will re-build the files ./images/linux and ./images/uImage so that the 'hello' program is included in the uClinux-dist. Once you've booted the board with this new image, just run 'hello' like any other program.

Network download

Before you can download over the network, the board's network settings must be configured. Use either:

root> dhcpcd &
root> ifconfig eth0
root> ifconfig eth0 up

For more information on how to set up the network, check out the setting up the network page.

Using a Web Server

You can also place the 'hello' program on a web server and use 'wget' on the STAMP board.

Login to your stamp board and download:

root:~> cd /tmp
root:/tmp> wget http://yourwebserver/hello

Now on the board, modify the permissions:

root:/tmp> chmod 777 hello

Using ftp

You can ftp into the board from the host, and upload the file to the board:

host> ftp
username : root
password : uClinux
ftp> binary
ftp> put ./hello
ftp> quit

Now on the board, modify the permissions:

root:/tmp> chmod 777 hello

Using tftp

On the board, you can fetch the file from the host using tftp. The first step in this process is to copy the hello to the host's tftp server directory.

host> cp hello /tftpboot/hello

Then on the board:

root> tftp -g -r hello

Now on the board, modify the permissions:

root:/tmp> chmod 777 hello

Using rcp

From the host, remote copy the file to the board:

host:> rcp ./hello root@

Using the serial port

If lrz (receive z-modem) is built into uClinux-dist, you can use this to transfer files from the PC to the board.

After 'hello' has been transferred, modify the permissions:

root:/tmp> chmod 777 hello

Running the application on the board

root:/tmp> ./hello
Hello, World

Complete Table of Contents/Topics