Difference between revisions of "DESK-MX8M-L/Development/Hello World example"

From DAVE Developer's Wiki
Jump to: navigation, search
(Created page with "{{subst:HelloWorld | nome-som=ORCA | kit-code=MX8M}}")
 
Line 7: Line 7:
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
 
!style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#73B2C7; padding:5px; color:white"|Notes
 
|-
 
|-
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|X.Y.Z
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|1.0.0
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Month Year
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Feb 2022
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|TBD
+
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|First DESK-MX8M-L release
|-
 
|-
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|[TBD_link X.Y.Z]
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|Month Year
 
|style="border-left:solid 2px #73B2C7; border-right:solid 2px #73B2C7;border-top:solid 2px #73B2C7; border-bottom:solid 2px #73B2C7; background-color:#edf8fb; padding:5px; color:#000000"|TBD
 
 
|-
 
|-
 
|}
 
|}
Line 28: Line 23:
  
 
=== Setting the cross-compiler ===
 
=== Setting the cross-compiler ===
It is assumed that the development environment has been set up properly as described [[DESK-MX6-L#Quick_start_guide|here]].
+
It is assumed that the development environment has been set up properly as described [[DESK-MX8-L#Quick_start_guide|here]].
 
* start the Linux development VM and login into the system
 
* start the Linux development VM and login into the system
 
* open a terminal window and ''cd'' into your source code directory
 
* open a terminal window and ''cd'' into your source code directory
Line 47: Line 42:
 
* configure the build environment
 
* configure the build environment
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ source /home/dvdk/desk-mx-l/desk-mx6-l-1.0.0_env.sh  
+
dvdk@vagrant:~/myproject$ source /home/dvdk/desk-mx-l/desk-mx8m-l-2.0.0-rc2_env.sh
 
</pre>
 
</pre>
  
Line 53: Line 48:
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
 
dvdk@vagrant:~/myproject$ echo $CC
 
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
+
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$  
 
dvdk@vagrant:~/myproject$  
 
</pre>
 
</pre>
  
* invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 32-bit for the target microprocessor
+
* invoke the cross-compiler for compiling your source code example: the object file obtained, is a proper ELF 64-bit for the target microprocessor
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
 
dvdk@vagrant:~/myproject$ $CC hello.c -o hello
 
dvdk@vagrant:~/myproject$ $CC hello.c -o hello
 
dvdk@vagrant:~/myproject$ file 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
+
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$  
 
dvdk@vagrant:~/myproject$  
 
</pre>
 
</pre>
Line 67: Line 62:
 
=== Running the example on the target ===
 
=== Running the example on the target ===
  
Now it is enough to copy the object file in the <code>/home/root</code> rfs directory and [[ORCA SOM/DESK-MX8M-L/General/Booting_from_NFS | boot from nfs...]]
+
Now it is enough to copy the object file in the <code>/home/root</code> rfs directory and [[DESK-MX8M-L/General/Booting_from_NFS | boot from nfs...]]
  
 
<pre class="workstation-terminal">
 
<pre class="workstation-terminal">
dvdk@vagrant:~/myproject$ sudo cp hello /home/dvdk/desk-mx-l/rfs/desk-mx6-l/home/root/
+
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-mx6-l/home/root/
+
dvdk@vagrant:~/myproject$ sudo ls -la /home/dvdk/desk-mx-l/rfs/desk-mx8m-l/home/root/
total 32
+
total 24
drwx------ 2 root root  4096 Jun  8 12:36 .
+
drwx------ 2 root root  4096 Feb 15 18:53 .
drwxr-xr-x 3 root root  4096 Jan 28 23:54 ..
+
drwxr-xr-x 3 root root  4096 Jan 20 16:44 ..
-rwxr-xr-x 1 root root 16432 Jun  8 12:36 hello
+
-rwxr-xr-x 1 root root 13256 Feb 15 18:53 hello
-rw-r--r-- 1 root root  1011 Nov 25  2020 .profile
 
 
dvdk@vagrant:~/myproject$  
 
dvdk@vagrant:~/myproject$  
 
</pre>
 
</pre>
Line 86: Line 80:
 
...
 
...
 
...
 
...
[  OK  ] Started Terminate Psplash Boot Screen.
+
[  OK  ] Started NFS status monitor for NFSv2/3 locking..
[  OK  ] Started /etc/rc.local Compatibility.
+
        Starting Permit User Sessions...
        Starting Hostname Service...
+
[  OK  ] Started Target Communication Framework agent.
        Starting WPA supplicant...
+
[  OK  ] Started Xinetd A Powerful Replacement For Inetd.
[  OK  ] Started Serial Getty on ttymxc2.
+
[  OK  ] Started Kernel Logging Service.
 +
[  OK  ] Started Permit User Sessions.
 +
[  OK  ] Started Avahi mDNS/DNS-SD Stack.
 
[  OK  ] Started Getty on tty1.
 
[  OK  ] Started Getty on tty1.
[  OK  ] Started WPA supplicant.
+
[  OK  ] Started Serial Getty on ttymxc1.
[  OK  ] Started Hostname Service.
+
[  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 4.14-sumo desk-mx6 ttymxc2
+
NXP i.MX Release Distro 5.4-zeus desk-mx8mp ttymxc1
  
desk-mx6 login: root
+
desk-mx8mp login: root
root@desk-mx6:~# ls -la
+
root@desk-mx8mp:~# ls -la
 
total 32
 
total 32
drwx------ 2 root root  4096 Jun  8  2021 .
+
drwx------ 3 root root  4096 Dec 15 21:35 .
drwxr-xr-x 3 root root  4096 Jan 28 2021 ..
+
drwxr-xr-x 3 root root  4096 Jan 20 2022 ..
-rw-r--r-- 1 root root  1011 Nov 25  2020 .profile
+
-rw------- 1 root root     7 Dec 15 2021 .bash_history
-rwxr-xr-x 1 root root 16432 Jun  8  2021 hello
+
-rwxr-xr-x 1 root root 13256 Dec 15 21:35 hello
root@desk-mx6:~# ./hello
+
root@desk-mx8mp:~# ./hello
 
Hello, World!
 
Hello, World!
root@desk-mx6:~#
+
root@desk-mx8mp:~#
 
</pre>
 
</pre>
  
Line 112: Line 111:
 
----
 
----
  
[[Category:ORCA]]
+
[[Category:ORCA]] [[Category:MITO 8M Mini]]

Revision as of 17:58, 15 February 2022

History
Version Issue Date Notes
1.0.0 Feb 2022 First DESK-MX8M-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 /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:~#