ETRA SBC/Hello world example

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes

2023/08/01

DESK-MP1-L-1.0.0 release
2023/08/31 DESK-MP1-L-1.0.1 release



Hello word example[edit | edit source]

Here below an example on C code displaying the classic Hello World! message on the target serial console.

This example shows how to use the arm cross-compiler using the environment configured for this purpose

Setting the cross-compiler[edit | edit source]

  • start the Linux development VM and login into the system
  • open a terminal window and cd into your source code directory
dvdk@vagrant:~$ mkdir myproject
dvdk@vagrant:~$ cd myproject/
dvdk@vagrant:~/myproject$ vi hello.c
dvdk@vagrant:~/myproject$ cat hello.c
#include <stdio.h>

int main(){
	printf("Hello, World!\n");
	return 0;
}
  • configure the build environment
dvdk@vagrant:~/myproject$ source /home/dvdk/desk-mp1-l/desk-mp1-l-1.0.1_env.sh
  • as you can see here below, the $CC environment variable has been properly configured for using the SDK sysroot parameter:
dvdk@vagrant:~/myproject$ echo $CC
arm-ostl-linux-gnueabi-gcc -mthumb -mfpu=neon-vfpv4 -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/opt/yocto/sdk/desk-mp1-l/desk-mp1-l-1.0.1/sysroots/cortexa7t2hf-neon-vfpv4-ostl-linux-gnueabi
dvdk@vagrant:~/myproject$ 
  • invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 32-bit for the target microprocessor
dvdk@vagrant:~/myproject$ $CC hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=70fc28d38cfb763980920bd9c16765823ed4b087, for GNU/Linux 3.2.0, with debug_in
dvdk@vagrant:~/myproject$ 

Running the example on the target[edit | edit source]

Now it is enough to copy the object file in the /home/root rfs directory and boot from nfs...

dvdk@vagrant:~/myproject$ sudo cp hello /home/dvdk/desk-mp1-l/rfs/desk-mp1-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mp1-l/rfs/desk-mp1-l/home/root/
total 28
drwx------ 2 root root  4096 Aug  1 08:21 .
drwxr-xr-x 4 root root  4096 Sep 20  2022 ..
-rwxr-xr-x 1 root root 11980 Aug  1 08:21 hello
-rw-r--r-- 1 root root   959 Sep 20  2022 .profile
-rw-r--r-- 1 root root   238 Sep 20  2022 README-CHECK-GPU
dvdk@vagrant:~/myproject$ 

on the target:

root@desk-mp1:~# ls -la
total 32
drwx------ 2 root root  4096 Aug  1  2023 .
drwxr-xr-x 4 root root  4096 Sep 20  2022 ..
-rw------- 1 root root    13 Aug  1  2023 .ash_history
-rw-r--r-- 1 root root   959 Sep 20  2022 .profile
-rw-r--r-- 1 root root   238 Sep 20  2022 README-CHECK-GPU
-rwxr-xr-x 1 root root 11980 Aug  1  2023 hello
root@desk-mp1:~# ./hello 
Hello, World!
root@desk-mp1:~#