DESK-MX8M-L/Development/Hello World example

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


First DESK-MX8M-L release


DESK-MX8M-L-2.0.0 release
2023/08/22 DESK-MX8M-L-4.0.0 release

Hello World 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 -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 /home/dvdk/desk-mx-l/
  • 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
aarch64-poky-linux-gcc -march=armv8-a+crc+crypto -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/yocto/sdk/desk-mx8m-l/desk-mx8m-l-4.0.0/sysroots/armv8a-poky-linux
  • invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 64-bit for the target microprocessor
dvdk@vagrant:~/myproject$ $CC hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/, BuildID[sha1]=a7220d78ac1016774b614ce1d50adae71cd713a3, for GNU/Linux 3.14.0, with debug_info, not stripped

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-mx-l/rfs/desk-mx8m-l-4.0.0/mx8mp/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx8m-l-4.0.0/mx8mp/home/root/
total 32
drwx------ 3 root root  4096 Jul 25 12:52 .
drwxr-xr-x 4 root root  4096 Mar  9  2018 ..
-rwxr-xr-x 1 root root 13928 Jul 25 12:52 hello
drwxr-xr-x 7 root root  4096 Mar  9  2018 .nxp-demo-experience
-rw-r--r-- 1 root root  1011 Mar  9  2018 .profile

on the target:

[  OK  ] Reached target Multi-User System.
[  OK  ] Started Weston, a Wayland .|mpositor, as a system service.
[  OK  ] Reached target Graphical Interface.
         Starting Record Runlevel Change in UTMP...
[  OK  ] Started Hostname Service.
[  OK  ] Started WPA supplicant.
[  OK  ] Finished Record Runlevel Change in UTMP.

NXP i.MX Release Distro 5.15-kirkstone desk-mx8mp ttymxc1

desk-mx8mp login: root
root@desk-mx8mp:~# ls -la
total 44
drwx------ 3 root root  4096 Jul 25 10:56 .
drwxr-xr-x 4 root root  4096 Mar  9  2018 ..
-rw------- 1 root root  8362 Jul 25 10:53 .bash_history
drwxr-xr-x 7 root root  4096 Mar  9  2018 .nxp-demo-experience
-rw-r--r-- 1 root root  1011 Mar  9  2018 .profile
-rwxr-xr-x 1 root root 13928 Jul 25 10:55 hello
root@desk-mx8mp:~# ./hello 
Hello, World!