DESK-MX8M-L/Development/Hello World example

From DAVE Developer's Wiki
< DESK-MX8M-L
Revision as of 14:11, 17 February 2022 by U0007 (talk | contribs) (Hello word example)

Jump to: navigation, search
History
Version Issue Date Notes
1.0.0 Feb 2022 First DESK-MX8M-L 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]

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 /home/dvdk/desk-mx-l/desk-mx8m-l-2.0.0-rc2_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 -mcpu=cortex-a53+crc+crypto -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/dvdk/desk-mx-l/sdk/desk-mx8m-l-2.0.0-rc2-toolchain/sysroots/aarch64-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]=497fafcb543f87ac45afb33d43506381c3473e7b, for GNU/Linux 3.14.0, 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-mx8m-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx8m-l/home/root/
total 24
drwx------ 2 root root  4096 Feb 15 18:53 .
drwxr-xr-x 3 root root  4096 Jan 20 16:44 ..
-rwxr-xr-x 1 root root 13256 Feb 15 18:53 hello
dvdk@vagrant:~/myproject$ 

on the target:

...
...
...
[  OK  ] Started NFS status monitor for NFSv2/3 locking..
         Starting Permit User Sessions...
[  OK  ] Started Target Communication Framework agent.
[  OK  ] Started Xinetd A Powerful Replacement For Inetd.
[  OK  ] Started Kernel Logging Service.
[  OK  ] Started Permit User Sessions.
[  OK  ] Started Avahi mDNS/DNS-SD Stack.
[  OK  ] Started Getty on tty1.
[  OK  ] Started Serial Getty on ttymxc1.
[  OK  ] Reached target Login Prompts.
[  OK  ] Reached target Multi-User System.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Started Update UTMP about System Runlevel Changes.

NXP i.MX Release Distro 5.4-zeus desk-mx8mp ttymxc1

desk-mx8mp login: root
root@desk-mx8mp:~# ls -la
total 32
drwx------ 3 root root  4096 Dec 15 21:35 .
drwxr-xr-x 3 root root  4096 Jan 20  2022 ..
-rw------- 1 root root     7 Dec 15  2021 .bash_history
-rwxr-xr-x 1 root root 13256 Dec 15 21:35 hello
root@desk-mx8mp:~# ./hello
Hello, World!
root@desk-mx8mp:~#