DESK-MX6-L/Development/Hello word example

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


First DESK release
2023/04/07 DESK-MX6-L 4.0.0 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]

It is assumed that the development environment has been set up properly as described here.

  • 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 ~/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
arm-poky-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 --sysroot=/home/dvdk/desk-mx-l/sdk/desk-mx6-l-4.0.0-toolchain/sysroots/cortexa9t2hf-neon-poky-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 hello.c -o hello
dvdk@vagrant:~/myproject$ file hello
hello: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/, BuildID[sha1]=cca65e0cfb17eb97c0aca03d1222d4db656bda9f, for GNU/Linux 3.2.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-mx6-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx6-l/home/root
total 28
drwx------ 3 root root  4096 Apr  7 16:02 .
drwxr-xr-x 4 root root  4096 Mar  9  2018 ..
-rwxr-xr-x 1 root root 12180 Apr  7 16:02 hello
drwxr-xr-x 6 root root  4096 Mar  9  2018 .nxp-demo-experience
-rw-r--r-- 1 root root  1011 Mar  9  2018 .profile

on the target:

[  OK  ] Started Xinetd A Powerful Replacement For Inetd.
[  OK  ] Started Avahi mDNS/DNS-SD Stack.
[  OK  ] Started Target Communication Framework agent.
[  OK  ] Reached target Multi-User System.
         Starting Record Runlevel Change in UTMP...
[  OK  ] Finished Record Runlevel Change in UTMP.

NXP i.MX Release Distro 5.15-kirkstone desk-mx6 ttymxc2

desk-mx6 login: root
root@desk-mx6:~# ls -la
total 24
drwx------ 2 root root  4096 Apr 28 22:23 .
drwxr-xr-x 3 root root  4096 Mar  9  2018 ..
-rw------- 1 root root   475 Apr 28 18:01 .bash_history
-rwxr-xr-x 1 root root 12180 Apr 28 22:23 hello
root@desk-mx6:~# ./hello
Hello, World!