How to do it...

The first step in order to use the extensible SDK is to source the environment setup script, as follows:

$ . environment-setup-cortexa9hf-neon-poky-linux-gnueabi
The source Bash built-in command we have been using can also be substituted by a single ., as shown previously, which is a portable POSIX-compliant syntax.

The SDK environment is now set up; additionally, you may now run devtool to perform development tasks. Run devtool --help for further details.

The devtool command-line application can also be used within a Yocto Project build directory, as we will see in Describing workflows for application development in this chapter.

Let's now add a new helloworld package. This is a Makefile-based C hello world example. We start by using devtool to add the new package by specifying the package name and the GitHub URL that contains the source code:

$ devtool add helloworld https://github.com/yoctocookbook2ndedition/helloworld.git
NOTE: Starting bitbake server...
NOTE: Starting bitbake server...
NOTE: Fetching git://github.com/yoctocookbook2ndedition/helloworld.git;protocol=https...
Loading cache: 100% |###################################################################################################| Time: 0:00:02
Loaded 2269 entries from dependency cache.Parsing recipes: 100% |#################################################################################################| Time: 0:00:01
Parsing of 1658 .bb files complete (1656 cached, 2 parsed). 2271 targets, 192 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Initialising tasks: 100% |##############################################################################################| Time: 0:00:00
NOTE: Executing RunQueue Tasks
NOTE: Tasks Summary: Attempted 2 tasks of which 0 didn't need to be rerun and all succeeded.
NOTE: Using default source tree path /home/alex/poky_sdk/workspace/sources/helloworldNOTE: Starting bitbake server...
NOTE: Using source tree as build directory since that would be the default for this recipe
NOTE: Recipe
/home/alex/poky_sdk/workspace/recipes/helloworld/helloworld_git.bb has been automatically created; further editing may be required to make it fully functional

The devtool utility has cloned the repository and placed it under the ~/poky_sdk/workspace/sources/helloworld/ directory. We are now ready to edit the template recipe that was prepared for us:

$ devtool edit-recipe helloworld
# Recipe created by recipetool
# This is the basis of a recipe and may need further editing in order to be fully functional.
# (Feel free to remove these comments when editing.)

# Unable to find any files that looked like license statements. Check the accompanying
# documentation and source headers and set LICENSE and LIC_FILES_CHKSUM accordingly.
# # NOTE: LICENSE is being set to "CLOSED" to allow you to at least start building - if
# this is not accurate with respect to the licensing of the software being built (it
# will not be in most cases) you must specify the correct value before using this
# recipe for anything other than initial testing/development! LICENSE = "CLOSED" LIC_FILES_CHKSUM = ""


SRC_URI = "git://github.com/yoctocookbook2ndedition/helloworld.git;protocol=https"

# Modify these as desired PV = "1.0+git${SRCPV}" SRCREV = "34d80d900550333d23c1b9193d6569298fb0e968"

S = "${WORKDIR}/git"

# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the
# recipe automatically - you will need to examine the Makefile yourself and ensure
# that the appropriate arguments are passed in.

do_configure () {
# Specify any needed configure commands here
: }

do_compile () {

# You will almost certainly need to add additional arguments here
oe_runmake }

do_install () {
# NOTE: unable to determine what to put here - there is a Makefile but no
# target named "install", so you will need to define this yourself
: }

We edit the recipe to review it and add some basic information that could not be extracted from the source code, like the following:

  • Licensing information: By default, a CLOSED license is set when no specific license can be identified. We will change this to a MIT license.
  • Install task: If the Makefile used had contained an install rule, it would have been called from the install task. As we don't have one, we need to manually provide the installation instructions.

The final recipe is shown next:

DESCRIPTION = "Simple helloworld application"                                    
SECTION = "examples"                                                             
LICENSE = "MIT"                                                                  
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 
 
SRC_URI = "git://github.com/yoctocookbook2ndedition/helloworld.git;protocol=https"
PV = "1.0+git${SRCPV}" SRCREV = "34d80d900550333d23c1b9193d6569298fb0e968"
S = "${WORKDIR}/git"
do_compile () { oe_runmake }
do_install () { install -d ${D}${bindir} install -m 0755 helloworld ${D}${bindir} }

We can now build the package with the following command:

$ devtool build helloworld
NOTE: Starting bitbake server...Loading cache: 100% |###################################################################################################| Time: 0:00:02
Loaded 2269 entries from dependency cache.
Parsing recipes: 100% |#################################################################################################| Time: 0:00:06
Parsing of 1658 .bb files complete (1656 cached, 2 parsed). 2271 targets, 192 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies
Initialising tasks: 100% |##############################################################################################| Time: 0:00:00
Checking sstate mirror object availability: 100% |######################################################################| Time: 0:00:00
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
NOTE: helloworld: compiling from external source tree /home/alex/poky_sdk/workspace/sources/helloworld
NOTE: Tasks Summary: Attempted 443 tasks of which 436 didn't need to be rerun and all succeeded.

Next, we will deploy it into the target to test. Assuming we have an SSH server running on the target, we can do the following:

$ devtool deploy-target helloworld root@<ipaddress>:/bin

The preceding line will only deploy the new package. If it has dependencies on other packages in the devtool workspace, we can also build a whole image and program it into the target with the following command:

$ devtool build-image core-image-base

Once it is tested, we finish working on the package with the final recipe being copied to its final location on the ~/poky_sdk/layers/meta-custom layer:

$ devtool finish helloworld meta-custom
NOTE: Starting bitbake server...Loading cache: 100% |###################################################################################################| Time: 0:00:00
Loaded 2269 entries from dependency cache.Parsing recipes: 100% |#################################################################################################| Time: 0:00:04
Parsing of 1658 .bb files complete (1656 cached, 2 parsed). 2271 targets, 192 skipped, 0 masked, 0 errors.
NOTE: Updating SRCREV in recipe helloworld_git.bb
NOTE: Moving recipe file to /home/alex/poky_sdk/layers/meta-custom/recipes-example/helloworld
NOTE: Leaving source tree /home/alex/poky_sdk/workspace/sources/helloworld as-is; if you no longer need it then please delete it manually
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset