IMX Hello World: Difference between revisions

From Variscite Wiki
No edit summary
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{PageHeader|VAR-SOM-MX6 - Hello World}} {{DocImage|category1=VAR-SOM-MX6|category2=Yocto}} __toc__
{{PageHeader|Hello, World!}} {{DocImage|category1=Yocto|category2=VAR-SOM-MX6}}[[Category:DART-6UL]][[Category:VAR-SOM-MX7]] __toc__
= Reference =
[http://www.yoctoproject.org/docs/2.0/adt-manual/adt-manual.html Yocto Project Application Developer's Guide 2.0]
= Toolchain installation for out of Yocto builds=


Build the toolchain by:
= Yocto references =
<pre>$ bitbake meta-ide-support
- [http://www.yoctoproject.org/docs/2.1/adt-manual/adt-manual.html Yocto Project Application Developer's Guide 2.1]<br>
$ bitbake meta-toolchain
- See the "Build Yocto from source code" section in this Wiki website, for your appropriate board and Yocto release.
 
= Sample C "Hello, world!" program =
Create a file called myhello.c with the following content:
<pre>
#include <stdio.h>
 
int main() {
printf("Hello, World!\n");
return 0;
}
</pre>
</pre>
In your Yocto build directory.
The output will be located at tmp/deploy/sdk/. On a 64 bit Ubuntu you will get:


sdk/poky-eglibc-x86_64-meta-toolchain-cortexa9hf-vfp-neon-toolchain-1.8.sh
= Building out of Yocto =
== Toolchain installation for out of Yocto builds ==
To install the toolchain:<br>
For Variscite's MX6 boards, follow [[VAR-SOM-MX6 Toolchain installation for out of Yocto Krogoth builds]].<br>
For DART-6UL, follow [[DART-6UL Toolchain installation for out of Yocto Krogoth builds]].<br>
For VAR-SOM-MX7, follow [[VAR-SOM-MX7 Toolchain installation for out of Yocto Krogoth builds]].<br>


Install the tools by running:
== Build ==
<pre>$ tmp/deploy/sdk/poky-eglibc-x86_64-meta-toolchain-cortexa9hf-vfp-neon-toolchain-1.8.sh</pre>
Reply to all defaults 'y'<br>
The toolchain name depend on your build machine and may change.
 
= hello World C =
<pre>
<pre>
$ mkdir ~/applications
Source the environment setup script (see the previous "Toolchain installation" section)
$ cd ~/applications
$ gedit hello.c &
 
#include <stdio.h>
int main(int argc, char **argv)
{
    printf("Hello World\n");
    return(0);
}


Compile:
Compile:
$ source /opt/poky/1.8/environment-setup-armv7a-vfp-neon-poky-linux-gnueabi
$ $CC $CFLAGS $LDFLAGS myhello.c -o myhello
$ $CC -o hello hello.c
</pre>
Find you target ipaddr.
Copy:
$ scp hello root@192.168.1.130:~/


On Target:
Now you should have an app called myhello, that can be copied (using scp, for example) and run on your target board.
Fix an issue with the library happen in poky version 1.8
$ ln -s /lib/ld-linux-armhf.so.3 /lib/ld-linux.so.3
Run:
root@var-som-mx6:~# ./hello
Hello World
</pre>


= Hello with BitBake =
= Building using Yocto =


== File hello_0.0.bb ==
== Sample bitbake recipe of an "Hello, world!" application ==
Create a file called myhello.bb with the following content:
<pre>
<pre>
#
DESCRIPTION = "Simple helloworld application"
#@DESCRIPTION: Variscite Hello world example"
LICENSE = "MIT"
#@MAINTAINER: Ron Donio <ron.d@variscite.com>
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#
# http://www.variscite.com
# support@variscite.com
#


PR = "r0"
SRC_URI = "file://myhello.c"
LICENSE = "GPLv2"


S = "${WORKDIR}"
S = "${WORKDIR}"
LIC_FILES_CHKSUM = "file://hellov.c;md5=360191807313df2e50fded385dd7532b"
SRC_URI = "file://hellov.c"


do_compile() {
do_compile() {
            ${CC} ${CFLAGS} ${LDFLAGS} -o hellov hellov.c
${CC} ${CFLAGS} ${LDFLAGS} myhello.c -o myhello
}
}


do_install() {
do_install() {
            install -d ${D}${bindir}/
install -d ${D}${bindir}
            install -m 0755 ${S}/hellov ${D}${bindir}/
install -m 0755 myhello ${D}${bindir}
}
}
</pre>
Create the following directory tree under your Yocto directory, and place in it the two files described above:
<pre>
sources/meta-variscite-imx/recipes-examples/
└── myhello
    ├── files
    │   └── myhello.c
    └── myhello.bb


FILES_${PN} = "${bindir}/hellov"
2 directories, 2 files
</pre>
</pre>


== File hello.c ==
== Build ==
Run the following in your Yocto build directory:
<pre>
<pre>
/*
$ bitbake myhello
* Variscite sample Hello World example
*/
 
#include <stdio.h>
 
int main () {
    printf("Hello World<>\n");
    return 0;
}
</pre>
</pre>
== Directory tree ==
To find the location of the output package you can run the following in your Yocto build directory:
<pre>
<pre>
variscite@rd-ub-14:~/var-som-mx6-yocto-fido$ tree sources/meta-variscite-mx6/recipes-test/
$ cd tmp/deploy/rpm
sources/meta-variscite-mx6/recipes-test/
$ find -name myhello*
└── hello
    ├── hello
    │   └── hello.c
    └── hello_0.0.bb
 
2 directories, 2 files
</pre>
</pre>
Create the directory tree as describe above and place the 2 files in the right directories.
== Build ==
edit local.conf file and add:
IMAGE_INSTALL_append = " hellov"


To add the output of this recipe to your output images, add the following to your conf/local.conf file in your Yocto build directory:
<pre>
<pre>
$ bitbake hello
IMAGE_INSTALL_append = " myhello"
</pre>
</pre>
This will put the myhello app in your rootfs.

Latest revision as of 18:44, 31 May 2017

Hello, World!

Yocto references

- Yocto Project Application Developer's Guide 2.1
- See the "Build Yocto from source code" section in this Wiki website, for your appropriate board and Yocto release.

Sample C "Hello, world!" program

Create a file called myhello.c with the following content:

#include <stdio.h>

int main() {
	printf("Hello, World!\n");
	return 0;
}

Building out of Yocto

Toolchain installation for out of Yocto builds

To install the toolchain:
For Variscite's MX6 boards, follow VAR-SOM-MX6 Toolchain installation for out of Yocto Krogoth builds.
For DART-6UL, follow DART-6UL Toolchain installation for out of Yocto Krogoth builds.
For VAR-SOM-MX7, follow VAR-SOM-MX7 Toolchain installation for out of Yocto Krogoth builds.

Build

Source the environment setup script (see the previous "Toolchain installation" section)

Compile:
$ $CC $CFLAGS $LDFLAGS myhello.c -o myhello

Now you should have an app called myhello, that can be copied (using scp, for example) and run on your target board.

Building using Yocto

Sample bitbake recipe of an "Hello, world!" application

Create a file called myhello.bb with the following content:

DESCRIPTION = "Simple helloworld application"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"

SRC_URI = "file://myhello.c"

S = "${WORKDIR}"

do_compile() {
	${CC} ${CFLAGS} ${LDFLAGS} myhello.c -o myhello
}

do_install() {
	install -d ${D}${bindir}
	install -m 0755 myhello ${D}${bindir}
}

Create the following directory tree under your Yocto directory, and place in it the two files described above:

sources/meta-variscite-imx/recipes-examples/
└── myhello
    ├── files
    │   └── myhello.c
    └── myhello.bb

2 directories, 2 files

Build

Run the following in your Yocto build directory:

$ bitbake myhello

To find the location of the output package you can run the following in your Yocto build directory:

$ cd tmp/deploy/rpm
$ find -name myhello*

To add the output of this recipe to your output images, add the following to your conf/local.conf file in your Yocto build directory:

IMAGE_INSTALL_append = " myhello"

This will put the myhello app in your rootfs.