DESK-MX6-L/Development/Hello word example

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

16990

21/07/2021 First DESK 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-mx6-l-1.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
arm-poky-linux-gnueabi-gcc -march=armv7-a -mfpu=neon -mfloat-abi=hard -mcpu=cortex-a9 --sysroot=/home/dvdk/desk-mx-l/sdk/desk-mx6-l-1.0.0-toolchain/sysroots/cortexa9hf-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]=212bc8245d6274bb4ed675b71128b0e835870fab, 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-mx6-l/home/root/
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx6-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 Terminate Psplash Boot Screen.
[  OK  ] Started /etc/rc.local Compatibility.
         Starting Hostname Service...
         Starting WPA supplicant...
[  OK  ] Started Serial Getty on ttymxc2.
[  OK  ] Started Getty on tty1.
[  OK  ] Started WPA supplicant.
[  OK  ] Started Hostname Service.

NXP i.MX Release Distro 4.14-sumo desk-mx6 ttymxc2

desk-mx6 login: root
root@desk-mx6:~# ls -la
total 32
drwx------ 2 root root  4096 Jun  8  2021 .
drwxr-xr-x 3 root root  4096 Jan 28  2021 ..
-rw-r--r-- 1 root root  1011 Nov 25  2020 .profile
-rwxr-xr-x 1 root root 16432 Jun  8  2021 hello
root@desk-mx6:~# ./hello
Hello, World!
root@desk-mx6:~#