DESK-XZ7-L/Development/Application examples/Hello World example

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

2024/01/29

DESK-XZ7-L-1.x.x release
2025/06/12 DESK-XZ7-L 2.x.x release



Hello World example[edit | edit source]

Here below is an example of 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
  • install the toolchain, for example for BORA SOM
dvdk@vagrant:~$ wget https://mirror.dave.eu/desk-xz-l/desk-xz7-l-2.0.0/Petalinux/bora_sdk.sh
--2025-06-13 09:27:27--  https://mirror.dave.eu/desk-xz-l/desk-xz7-l-2.0.0/Petalinux/bora_sdk.sh
Resolving mirror.dave.eu (mirror.dave.eu)... 84.46.251.143
Connecting to mirror.dave.eu (mirror.dave.eu)|84.46.251.143|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 963331875 (919M) [text/x-sh]
Saving to: ‘bora_sdk.sh’

bora_sdk.sh                                     100%[====================================================================================================>] 918.70M   236KB/s    in 27m 56s 

2025-06-13 09:55:23 (561 KB/s) - ‘bora_sdk.sh’ saved [963331875/963331875]

dvdk@vagrant:~$ chmod 755 bora_sdk.sh 
dvdk@vagrant:~$ ./bora_sdk.sh 
PetaLinux SDK installer version 2024.2
======================================
Enter target directory for SDK (default: /opt/petalinux/2024.2): 
You are about to install the SDK to "/opt/petalinux/2024.2". Proceed [Y/n]? 
Extracting SDK.......................................................................................................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /opt/petalinux/2024.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi
dvdk@vagrant:~$ 
  • open a terminal window and cd into your source code directory
dvdk@vagrant:~$ mkdir -p ~/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 /opt/petalinux/2024.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi 
  • 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-xilinx-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 --sysroot=/opt/petalinux/2024.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
  • 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 -O hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, BuildID[sha1]=aa46219962c8dc3a3437b0c572c5c4d59b2a77c1, for GNU/Linux 5.15.0, with debug_info, not stripped

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

Now it is enough to copy the object file on target and execute it:

...
...
root@bora:~# ./hello
Hello, World!
root@bora:~#