Dies ist eine alte Version des Dokuments!
Images are built using bitbake and yocto.
The build process is based on this toradex guide .
Note that everything in this section assumes a build environment that is set up according to the guide above.
A custom application can be added to a yocto build by means of a new recipes and a new layer.
There are various ways to source application to be added to a build. This guide describes how to add this hello world application from github into the toradex image. If you want to build your own hello world application, check out this guide on how to do that.
Recipes could be considered the fundamental building block of yocto. A recipe describes how to build the thing you want to build (i.e an application, kernel module, …), its dependencies and more.
Groups of recipes that belong together are grouped into layers. For example meta-toradex-nxp
is the layer that contains all the things needed to support the hardware specific to Toradex's modules that use NXP based processors.
To create a new layer, create a new directory in the oe-core/layers
directory(oe-core
is the folder the build environment was set up in above). Since this is the NTB wiki, this guide will use oe-core/layers/meta-ntb
. The directory name can be anything, but it should start with meta-
. Now change into that directory and create another folder called conf
. In conf
, create a file named layer.conf
with the following content:
BBPATH := "${BBPATH}:${LAYERDIR}" BBFILES := "${BBFILES} ${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bappend" BBFILE_COLLECTIONS += "ntb" BBFILE_PATTERN_ntb := "^${LAYERDIR}/" BBFILE_PRIORITY_ntb := "5"
This file configures the layer and where to look for recipes. In this case it will look for file in meta-ntb/recipes-<some name>/<some other name>/<file name>.bb
. .bb
is the file extension used by bitbake
the build system used by yocto. Finally, create a folder named recipes-ntb
inside meta-ntb
. This folder will store all the recipes for this layer. The directory structure should now look like this:
Finally, add the new layer to the build by adding it to oe-core/build/conf/bblayers.conf
:
BBLAYERS ?= "\ ... ${TOPDIR}/../layers/meta-toradex-demos \ ${TOPDIR}/../layers/meta-ntb \ \ \ ${TOPDIR}/../layers/meta-toradex-distro \ ...
As configured above, bitbake
will look for recipes in any sub directory
of recipes-ntb
, but not in recipes-ntb
itself! Create a folder inside recipes-ntb
called helloworld
and inside that create a file called helloworld_1_0.bb
with the following content:
DESCRIPTION = "Example Hello World" SECTION = "ntb" DEPENDS = "" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://LICENSE;md5=96af5705d6f64a88e035781ef00e98a8" FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:" SRCREV = "b9fb7785e9e1f357f29bef63dce8f1d91adb6170" SRC_URI = "git://github.com/DynamicDevices/bbexample.git" S = "${WORKDIR}/git" inherit autotools
bitbake
is very particular about licenses to ensure no closed source software ends up in a project that only wants open source software. Hence the recipe needs to specify the license used (MIT in this case) and a checksum for the license file to ensure it has not been altered. All this is handled by the LIC_FILES_CHKSUM
field. THe other two interesting fields are SRC_URI
and SRC_REV
. SRC_URI
specifies where the source for the application/module/… for this recipe is. In this case git://
lets bitbake
know the source lives in a git repository. Note that https://
will not work. Also note that inherit autotools
is only necessary because the hello world uses autotools.
To add the new recipe to the build edit oe-core/build/conf/local.conf
and append IMAGE_INSTALL_append = „ helloworld“
(make sure to include the space before helloworld
).
Now running bitbake console-tdx-image
should run without errors and the image should include a hello
executable that prints Hello World
when executed.
replace 'inherit autotools
' above with the folling:
inherit cmake OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "BOTH"
'OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = „BOTH“
' allows cmake to find 'git
' from within yocto, otherwise cmake will generate an error ('missing: GIT_EXECUTABLE
').
This part is an extension of the previous and assumes the meta-ntb
layer exists and was added to bblayers.conf
as described above. This part uses the fpga_loader kernel module to demonstrate how to add an out-of-tree kernel module to yocto.
Create a new directory recipes-kernel
under meta-ntb
and in that create another folder inside that called fpga-loader
. Create a file called fpga-loader_1.0.bb
in fpga-loader
and add the following content:
DESCRIPTION = "FPGA Loader Kernel Module" SECTION = "ntb" DEPENDS = "" LICENSE = "CLOSED" FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}:" SRCREV = "df83789290cd8fe8b9d9af8dd7ad509ea25c6b46" SRC_URI = "git://github.com/zechenturm/fpga_loader.git" S = "${WORKDIR}/git" inherit module export KERNELDIR="${KERNEL_SRC}"
Since there is no LICENSE file in the fpga-loader
git repository, the simplest way to not have bitbake
complain about it is to set LICENSE
to CLOSED
even though it actually is open (source). Note that in comparison with helloworld
there is no inherit autotools
since fpga-loader
does not rely on autotools
. However, thjere is inherit module
which lets bitbake
know that this recipe is building a kernel module.
Since fpga_module
s Makefile uses KERNELDIR
but yocto uses KERNEL_SRC
, KERNEL_DIR
needs to be explicitly set in the recipe for the build to succeed.
Finally, fpga-loader
needs to be added to the image in oe-core/build/conf/local.conf
:
IMAGE_INSTALL_append = " fpga-loader" MACHINE_EXTRA_RRECOMMENDS = " kernel-modules"
While IMAGE_INSTALL_append
was sufficient for helloworld
, kernel modules need an extra step to make sure kernel modules are included in the image/rootfs. By default, minimal yocto images do not include them which would mean that fpga-loader
would be built but not added to the rootfs. Setting MACHINE_EXTRA_RECOMMENDS = „ kernel-modules“ ensures they are included
.
To build the SDK for an image append -c populate_sdk
to the bitbake build command.
For example, to build the SDK for the standard toradex image console-tdx-image
run bitbake console-tdx-image -c populate_sdk
For more information check the Toradex guide .