Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
software:linux:toradex:toradex-build [2019-10-22 13:47] mlammerichsoftware:linux:toradex:toradex-build [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1
Zeile 1: Zeile 1:
-====== Building a New Image ====== 
  
-Images are built using bitbake and yocto. 
- 
-The build process is based on [[ https://developer.toradex.com/knowledge-base/board-support-package/openembedded-%28core%29#update-to-a-specific-version-by-using-its-tag | this toradex guide ]]. 
- 
-===== Customising the Toradex image ===== 
- 
-Note that everything in this section assumes a build environment that is set up according to the guide above. 
- 
-==== Adding a custom application ==== 
- 
-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 [[ https://github.com/DynamicDevices/bbexample | this hello world application from github ]] into the toradex image. If you want to build your own hello world application, check out [[ https://blog.mbedded.ninja/programming/embedded-linux/yocto-project/adding-a-custom-app-to-a-yocto-build/ | this guide ]] on how to do that. 
- 
-=== On layers and recipes === 
- 
-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. 
- 
-=== Creating a custom layer === 
- 
-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: 
- 
-<code> 
-BBPATH := "${BBPATH}:${LAYERDIR}" 
- 
-BBFILES := "${BBFILES} ${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bappend" 
- 
-BBFILE_COLLECTIONS += "ntb" 
- 
-BBFILE_PATTERN_ntb := "^${LAYERDIR}/" 
-BBFILE_PRIORITY_ntb := "5" 
-</code> 
- 
-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: 
- 
-  * oe-core 
-    * ... 
-    * meta-ntb 
-      * conf 
-        * layer.conf 
-      * recipes-ntb 
- 
-Finally, add the new layer to the build by adding it to ''oe-core/build/conf/bblayers.conf'': 
-<code> 
-BBLAYERS ?= "\ 
-... 
-  ${TOPDIR}/../layers/meta-toradex-demos \ 
-  ${TOPDIR}/../layers/meta-ntb \ 
-  \ 
-  \ 
-  ${TOPDIR}/../layers/meta-toradex-distro \ 
-... 
-</code> 
-=== Adding a Recipe to the Layer === 
- 
-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: 
- 
-<code> 
-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 
-</code> 
- 
-''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. 
- 
-== Using cmake == 
- 
-replace ''inherit autotools'' from above with the following: 
- 
-<code> 
-inherit cmake 
-OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "BOTH" 
-</code> 
- 
-''OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "BOTH"'' allows cmake to find ''git'' from within yocto, otherwise cmake will generate an error (''missing: GIT_EXECUTABLE''). 
- 
- 
-== Additional Information == 
- 
-[[ https://blog.mbedded.ninja/programming/embedded-linux/yocto-project/adding-a-custom-app-to-a-yocto-build/ ]] 
- 
-[[ https://wiki.yoctoproject.org/wiki/Building_your_own_recipes_from_first_principles ]] 
- 
-==== Adding a kernel module ==== 
- 
-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 [[ https://github.com/zechenturm/fpga_loader | 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: 
-<code> 
-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}" 
-</code> 
- 
-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'': 
-<code> 
-IMAGE_INSTALL_append = " fpga-loader" 
- 
-MACHINE_EXTRA_RRECOMMENDS = " kernel-modules" 
-</code> 
- 
-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'' 
- 
-== Additional Information == 
- 
-[[ https://www.youtube.com/watch?v=U5G_rT-GwPE ]] 
- 
-===== Building the SDK ===== 
- 
-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 [[ https://developer.toradex.com/knowledge-base/linux-sdks | Toradex guide ]].