Changes

Jump to: navigation, search

DESK-XZ7-L/Development/Hello World example

5,132 bytes added, 29 January
Created page with "<section begin="History" /> {| style="border-collapse:collapse; " ! colspan="4" style="width:100%; text-align:left" ; border-bottom:solid 2px #ededed" |History |- ! style="bo..."
<section begin="History" />
{| style="border-collapse:collapse; "
! colspan="4" style="width:100%; text-align:left" ; border-bottom:solid 2px #ededed" |History
|-
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white" |Issue Date
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white" |Notes
|-
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |2023/01/25
! style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#ededed; padding:5px; color:#000000" |DESK-XZ7-L-1.0.1 release
|-
|}
<section end="History" />
__FORCETOC__
<section begin="Body" />

==Hello World example==

Here below an example on C code displaying the classic [https://en.wikipedia.org/wiki/%22Hello,_World!%22_program 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 ===

* start the Linux development VM and login into the system
* install the toolchain, for example for Bora

<pre class="workstation-terminal">
dvdk@vagrant:~$ wget https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_bora_sdk.sh
--2024-01-26 11:57:04-- https://mirror.dave.eu/desk-xz-l/desk-xz7-l-1.0.1/desk-xz7-l-1.0.1_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: 998591008 (952M) [text/x-sh]
Saving to: ‘desk-xz7-l-1.0.1_bora_sdk.sh’

desk-xz7-l-1.0.1_bora_sdk.sh 100%[====================================================================================================>] 952.33M 10.8MB/s in 1m 40s

2024-01-26 11:58:43 (9.57 MB/s) - ‘desk-xz7-l-1.0.1_bora_sdk.sh’ saved [998591008/998591008]

dvdk@vagrant:~$ chmod 755 desk-xz7-l-1.0.1_bora_sdk.sh
dvdk@vagrant:~$ ./desk-xz7-l-1.0.1_bora_sdk.sh
PetaLinux SDK installer version 2021.2
======================================
Enter target directory for SDK (default: /opt/petalinux/2021.2):
You are about to install the SDK to "/opt/petalinux/2021.2". Proceed [Y/n]? y
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/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi
</pre>

* open a terminal window and ''cd'' into your source code directory

<pre class="workstation-terminal">
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;
}
</pre>

* configure the build environment
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ source /opt/petalinux/2021.2/environment-setup-cortexa9t2hf-neon-xilinx-linux-gnueabi
</pre>

* as you can see here below, the <code>$CC</code> environment variable has been properly configured for using the SDK <code>sysroot</code> parameter:
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ echo $CC
arm-xilinx-linux-gnueabi-gcc -mthumb -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/petalinux/2021.2/sysroots/cortexa9t2hf-neon-xilinx-linux-gnueabi
</pre>

* invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 64-bit for the target microprocessor
<pre class="workstation-terminal">
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]=cd0630d98370eb6b80423fb1b4b1e3411f2f4576, for GNU/Linux 3.2.0, with debug_info, not stripped
</pre>

=== Running the example on the target ===

Now it is enough to copy the object file on target and perform the following command:

<pre class="workstation-terminal">
...
...
root@bora:~# ./hello
Hello, World!
root@bora:~#
</pre>

<section end="Body" />
[[Category:BORA]]
[[Category:BORA Xpress]]
[[Category:BORA Lite]]
dave_user
428
edits

Navigation menu