Difference between revisions of "HelloWorld"
m (→Compilation) |
m (→TFTP) |
||
Line 42: | Line 42: | ||
Copy your ''hello'' executable on your board either through TFTP or NFS | Copy your ''hello'' executable on your board either through TFTP or NFS | ||
===TFTP=== | ===TFTP=== | ||
− | Be sure to have TFTP server installed, [[Connection_with_U-Boot_on_Linux#TFTP_server| if not it's explained here]] | + | * Be sure to have TFTP server installed, [[Connection_with_U-Boot_on_Linux#TFTP_server| if not it's explained here]]. Copy ''hello'' to your TFTP directory: |
− | Copy ''hello'' to TFTP directory: | + | |
[host demos]$ cp hello /tftpboot/ | [host demos]$ cp hello /tftpboot/ | ||
− | Load your executable on the target (here my host IP is 192.168.0.2): | + | * Load your executable on the target (here my host IP is 192.168.0.2): |
+ | <pre class="apf"> | ||
# tftp -g -r hello -l /usr/bin/hello 192.168.0.2 | # tftp -g -r hello -l /usr/bin/hello 192.168.0.2 | ||
− | Give it executable rights, if lost during TFTP transfer: | + | </pre> |
+ | * Give it executable rights, if lost during TFTP transfer: | ||
+ | <pre class="apf"> | ||
# chmod a+x /usr/bin/hello | # chmod a+x /usr/bin/hello | ||
− | Launch it: | + | </pre> |
+ | * Launch it: | ||
+ | <pre class="apf"> | ||
# /usr/bin/hello | # /usr/bin/hello | ||
APF9328 says: Hello World ! ;-) | APF9328 says: Hello World ! ;-) | ||
# | # | ||
+ | </pre> | ||
Now it's up to you ! ;-) | Now it's up to you ! ;-) |
Revision as of 16:09, 28 May 2009
On this page you will learn how to create your first C application for your Armadeus board
Contents
Source code
- First take your favorite editor/IDE and create the following program:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf( "APF9328 says: Hello World ! ;-)\n" );
exit(0);
}
- Save it as hello.c
Compilation
The C cross compiler is installed in armadeus/buildroot/build_armvXX/staging_dir/usr/bin/ and is named arm-linux-gcc. You can access it with the $ARMADEUS_TOOLCHAIN_PATH environment variable:
$ make shell_env $ . ./armadeus_env.sh $ echo $ARMADEUS_TOOLCHAIN_PATH
There are 2 possibilities to use it:
- either add $ARMADEUS_TOOLCHAIN_PATH to your PATH environment variable and then call arm-linux-gcc instead of gcc
- or call directly $ARMADEUS_TOOLCHAIN_PATH/arm-linux-gcc
So to compile your small program (here hello.c was saved in armadeus/target/demos/ directory) do:
[demos]$ $ARMADEUS_TOOLCHAIN_PATH/arm-linux-gcc -o hello hello.c
or
[demos]$ export PATH=$PATH:$ARMADEUS_TOOLCHAIN_PATH [demos]$ arm-linux-gcc -o hello hello.c
Running
Copy your hello executable on your board either through TFTP or NFS
TFTP
- Be sure to have TFTP server installed, if not it's explained here. Copy hello to your TFTP directory:
[host demos]$ cp hello /tftpboot/
- Load your executable on the target (here my host IP is 192.168.0.2):
# tftp -g -r hello -l /usr/bin/hello 192.168.0.2
- Give it executable rights, if lost during TFTP transfer:
# chmod a+x /usr/bin/hello
- Launch it:
# /usr/bin/hello APF9328 says: Hello World ! ;-) #
Now it's up to you ! ;-)
NFS
Be sure to have NFS server installed, if not it's explained here
I assume that your NFS drive is accessible from /mnt/host
Launch your prog:
[target]# /mnt/host/hello
Putting it all together in a Makefile
You can put your program compiling and copying in a Makefile to make things cleaner:
CC=arm-linux-gcc CFLAGS=-W -Wall LDFLAGS= EXEC=hello SRC= $(wildcard *.c) OBJ= $(SRC:.c=.o) all: $(EXEC) hello: $(OBJ) $(CC) -o $@ $^ $(LDFLAGS) %.o: %.c $(CC) -o $@ -c $< $(CFLAGS) .PHONY: clean install clean: rm -rf *.o rm -f $(EXEC) install: all cp -f $(EXEC) /tftpboot/
Then, just do:
[host demos]$ make clean install
Links
- Things to know when porting x86 software to ARM
- Les Makefiles, comment ça marche ?
- Livre en ligne: Programmation Linux Avancée
Other languages: | |
---|---|
English • Français |