Yocto Hello World: Difference between revisions

From Variscite Wiki
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 2: Line 2:
--> {{INIT_RELEASE_PARAM|RELEASE_MORTY_V1.0_DART-6UL}}<!--
--> {{INIT_RELEASE_PARAM|RELEASE_MORTY_V1.0_DART-6UL}}<!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Yocto_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{#lst:Debian_Platform_Customization|{{#var:RELEASE_PARAM}}}} <!--
--> {{COMMON_YOCTO_VARS}} <!--
Initialize platform-dependent variables
--> {{#vardefine:PLATFORM_OS|Yocto}}<!--
--> {{#vardefine:BUILD_RELEASE_GUIDE|Yocto_Build_Release}}<!--
--> {{#varexists:DEBIAN_NAME |<!--
-->    {{#vardefine:PLATFORM_OS|Debian}}<!--
-->    {{#vardefine:BUILD_RELEASE_GUIDE|Yocto_Debian_Build_Release}}<!--
--> }} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Hello, World!}} {{DocImage|category1={{#var:HARDWARE_NAME}}|category2=Yocto}} __toc__
--> {{PageHeader|{{#var:HARDWARE_NAME}} - Hello, World!}} {{DocImage|category1={{#var:HARDWARE_NAME}}|category2=Yocto}} __toc__


= Yocto references =
= Yocto references =
* [http://www.yoctoproject.org/docs/2.1/adt-manual/adt-manual.html Yocto Project Application Developer's Guide 2.1]<br>
* [http://www.yoctoproject.org/docs/2.1/adt-manual/adt-manual.html Yocto Project Application Developer's Guide 2.1]<br>
* Full Yocto OpenEmbedded environment is required for this tutorial.<br> See detailed instructions here: {{Varlink|Yocto_Build_Release|{{#var:RELEASE_LINK}}|Build Yocto from source code}}
* Full Yocto OpenEmbedded environment is required for this tutorial.<br> See detailed instructions here: {{Varlink|{{#var:BUILD_RELEASE_GUIDE}}|{{#var:RELEASE_LINK}}|Build {{#var:PLATFORM_OS}} from source code}}


= Sample C "Hello, world!" program =
= Sample C "Hello, world!" program =
Line 57: Line 69:
   
   
Create the following directory tree under your Yocto directory, and place in it the two files described above:
Create the following directory tree under your Yocto directory, and place in it the two files described above:
<pre>
sources/{{#var:META_VARISCITE|meta-variscite-fslc}}/recipes-examples/
└── myhello
    ├── files
    │   └── myhello.c
    └── myhello.bb


2 directories, 2 files
sources/{{#var:META_VARISCITE_REPO|meta-variscite-fslc}}/recipes-examples/
</pre>
└── myhello
    ├── files
    │   └── myhello.c
    └── myhello.bb
2 directories, 2 files


== Build ==
== Build ==
Line 79: Line 90:


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:
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:
{{#ifexpr: {{#var:YOCTO_VERSION}} < 4.0 |
 
<pre>IMAGE_INSTALL_append = " myhello"</pre>
IMAGE_INSTALL{{#var:YOCTO_OVERRIDE_PREFIX}}append = " myhello"
|
<pre>IMAGE_INSTALL:append = " myhello"</pre>
}}


This will put the myhello app in your rootfs.
This will put the myhello app in your rootfs.

Latest revision as of 21:09, 23 August 2024

Warning: This page is designed to be used with a 'release' URL parameter.

This page is using the default release RELEASE_MORTY_V1.0_DART-6UL.
To view this page for a specific Variscite SoM and software release, please follow these steps:

  1. Visit variwiki.com
  2. Select your SoM
  3. Select the software release
DART-6UL - Hello, World!

Yocto references

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 follow Yocto Toolchain installation guide.

Build

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

Compile:
$ $CC 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} myhello.c ${LDFLAGS} -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-fslc/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.