SBC Lynx SBC/Hello word example

From DAVE Developer's Wiki
Jump to: navigation, search
History
Issue Date Notes
2021/07/21 First DESK-MX6UL-L 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/desk-mx6ul-l-1.0.1_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
arm-poky-linux-gnueabi-gcc -march=armv7ve -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=/home/dvdk/desk-mx-l/sdk/desk-mx6ul-l-1.0.1-toolchain/sysroots/cortexa7hf-neon-poky-linux-gnueabi
dvdk@vagrant:~/myproject$ 
  • 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 executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=9afa4b55f9a187d69a3a8356ea2d2afc3565cf7a, 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-mx6ul-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx6ul-l/home/root/
total 32
drwx------ 2 root root  4096 Jun  8 12:36 .
drwxr-xr-x 3 root root  4096 Jan 28 23:54 ..
-rwxr-xr-x 1 root root 16432 Jun  8 12:36 hello
-rw-r--r-- 1 root root  1011 Nov 25  2020 .profile
dvdk@vagrant:~/myproject$ 

on the target:

...
...
...
[  OK  ] Started Getty on tty1.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started Job spooling tools.
         Starting Network Time Service (one-shot ntpdate mode)...
         Starting System Logging Service...
[  OK  ] Reached target Timers.
[  OK  ] Started RPC Bind Service.
[  OK  ] Started Avahi mDNS/DNS-SD Stack.
[  OK  ] Started Telephony service.
[  OK  ] Started NFS status monitor for NFSv2/3 locking..
[  OK  ] Started Network Time Service (one-shot ntpdate mode).

NXP i.MX Release Distro 4.14-sumo desk-mx6ul-axelulite ttymxc0

desk-mx6ul-axelulite login: root
root@desk-mx6ul-axelulite:~# ls -la
total 32
drwx------ 2 root root  4096 Jul  2  2021 .
drwxr-xr-x 3 root root  4096 Jun 16  2021 ..
-rw------- 1 root root    25 Jun 29  2021 .bash_history
-rwxr-xr-x 1 root root 16436 Jul  2  2021 hello
root@desk-mx6ul-axelulite:~# ./hello
Hello, World!
root@desk-mx6ul-axelulite:~#