DESK-MX9-L/Development/Hello World example

From DAVE Developer's Wiki
< DESK-MX9-L
Revision as of 10:21, 1 February 2024 by U0007 (talk | contribs)

(diff) ← Older revision | Approved revision (diff) | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
History
Issue Date Notes
2024/01/30 DESK-MX9-L-5.0.0 release



Hello word example[edit | edit source]

Here below is 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-mx-l/desk-mx9-l-5.0.0_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
aarch64-poky-linux-gcc -march=armv8-a+crc+crypto -mbranch-protection=standard -fstack-protector-strong -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/opt/yocto/sdk/desk-mx9-l/desk-mx9-l-5.0.0/sysroots/armv8a-poky-linux
dvdk@vagrant:~/myproject$ 
  • 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 shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=c64beb8181cc5a2fe6290f8b61b217a25041b429, for GNU/Linux 3.14.0, with debug_info, not stripped
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-mx-l/rfs/desk-mx9-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx9-l/home/root/
total 32
drwx------ 3 root root  4096 Jan 31 10:46 .
drwxr-xr-x 4 root root  4096 Mar  9  2018 ..
-rwxr-xr-x 1 root root 75624 Jan 31 10:46 hello
-rw-r--r-- 1 root root  1011 Mar  9  2018 .profile
dvdk@vagrant:~/myproject$ 

on the target:

...
[  OK  ] Mounted /run/media/root-mmcblk1p2.
[  OK  ] Started Weston, a Wayland …mpositor, as a system service.
[  OK  ] Reached target Graphical Interface.
         Starting Record Runlevel Change in UTMP...
[  OK  ] Finished Record Runlevel Change in UTMP.

NXP i.MX Release Distro 6.1-mickledore desk-mx93 ttyLP0

desk-mx93 login: root
root@desk-mx93:~# ls -la
total 32
drwx------ 3 root root  4096 Jan 31  2024 .
drwxr-xr-x 4 root root  4096 Mar  9  2018 ..
-rw-r--r-- 1 root root  1011 Mar  9  2018 .profile
-rwxr-xr-x 1 root root 75624 Jan 31  2024 hello
root@desk-mx93:~# ./hello
Hello, World!
root@desk-mx93:~#