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; }
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 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
OR
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:
rgetz@imhotep:~/src> bfin-uclinux-gcc -Wl,-elf2flt hello.c -o hello
-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
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
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.
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.
Before you can download over the network, the board's network settings must be configured. Use either:
root> dhcpcd & root> ifconfig eth0or
root> ifconfig eth0 192.168.0.1 up
For more information on how to set up the network, check out the setting up the network page.
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
You can ftp into the board from the host, and upload the file to the board:
host> ftp 192.168.0.1 username : root password : uClinux ftp> binary ftp> put ./hello ftp> quit
Now on the board, modify the permissions:
root:/tmp> chmod 777 hello
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 192.168.0.1
Now on the board, modify the permissions:
root:/tmp> chmod 777 hello
From the host, remote copy the file to the board:
host:> rcp ./hello root@192.168.0.1:/hello
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
root:/tmp> ./hello Hello, World