1*4882a593Smuzhiyun.. SPDX-License-Identifier: CC-BY-SA-2.0-UK 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun************ 4*4882a593SmuzhiyunCommon Tasks 5*4882a593Smuzhiyun************ 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThis chapter describes fundamental procedures such as creating layers, 8*4882a593Smuzhiyunadding new software packages, extending or customizing images, porting 9*4882a593Smuzhiyunwork to new hardware (adding a new machine), and so forth. You will find 10*4882a593Smuzhiyunthat the procedures documented here occur often in the development cycle 11*4882a593Smuzhiyunusing the Yocto Project. 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunUnderstanding and Creating Layers 14*4882a593Smuzhiyun================================= 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunThe OpenEmbedded build system supports organizing 17*4882a593Smuzhiyun:term:`Metadata` into multiple layers. 18*4882a593SmuzhiyunLayers allow you to isolate different types of customizations from each 19*4882a593Smuzhiyunother. For introductory information on the Yocto Project Layer Model, 20*4882a593Smuzhiyunsee the 21*4882a593Smuzhiyun":ref:`overview-manual/yp-intro:the yocto project layer model`" 22*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunCreating Your Own Layer 25*4882a593Smuzhiyun----------------------- 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun.. note:: 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun It is very easy to create your own layers to use with the OpenEmbedded 30*4882a593Smuzhiyun build system, as the Yocto Project ships with tools that speed up creating 31*4882a593Smuzhiyun layers. This section describes the steps you perform by hand to create 32*4882a593Smuzhiyun layers so that you can better understand them. For information about the 33*4882a593Smuzhiyun layer-creation tools, see the 34*4882a593Smuzhiyun ":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" 35*4882a593Smuzhiyun section in the Yocto Project Board Support Package (BSP) Developer's 36*4882a593Smuzhiyun Guide and the ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" 37*4882a593Smuzhiyun section further down in this manual. 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunFollow these general steps to create your layer without using tools: 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun1. *Check Existing Layers:* Before creating a new layer, you should be 42*4882a593Smuzhiyun sure someone has not already created a layer containing the Metadata 43*4882a593Smuzhiyun you need. You can see the :oe_layerindex:`OpenEmbedded Metadata Index <>` 44*4882a593Smuzhiyun for a list of layers from the OpenEmbedded community that can be used in 45*4882a593Smuzhiyun the Yocto Project. You could find a layer that is identical or close 46*4882a593Smuzhiyun to what you need. 47*4882a593Smuzhiyun 48*4882a593Smuzhiyun2. *Create a Directory:* Create the directory for your layer. When you 49*4882a593Smuzhiyun create the layer, be sure to create the directory in an area not 50*4882a593Smuzhiyun associated with the Yocto Project :term:`Source Directory` 51*4882a593Smuzhiyun (e.g. the cloned ``poky`` repository). 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun While not strictly required, prepend the name of the directory with 54*4882a593Smuzhiyun the string "meta-". For example:: 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun meta-mylayer 57*4882a593Smuzhiyun meta-GUI_xyz 58*4882a593Smuzhiyun meta-mymachine 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun With rare exceptions, a layer's name follows this form:: 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun meta-root_name 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun Following this layer naming convention can save 65*4882a593Smuzhiyun you trouble later when tools, components, or variables "assume" your 66*4882a593Smuzhiyun layer name begins with "meta-". A notable example is in configuration 67*4882a593Smuzhiyun files as shown in the following step where layer names without the 68*4882a593Smuzhiyun "meta-" string are appended to several variables used in the 69*4882a593Smuzhiyun configuration. 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun3. *Create a Layer Configuration File:* Inside your new layer folder, 72*4882a593Smuzhiyun you need to create a ``conf/layer.conf`` file. It is easiest to take 73*4882a593Smuzhiyun an existing layer configuration file and copy that to your layer's 74*4882a593Smuzhiyun ``conf`` directory and then modify the file as needed. 75*4882a593Smuzhiyun 76*4882a593Smuzhiyun The ``meta-yocto-bsp/conf/layer.conf`` file in the Yocto Project 77*4882a593Smuzhiyun :yocto_git:`Source Repositories </poky/tree/meta-yocto-bsp/conf>` 78*4882a593Smuzhiyun demonstrates the required syntax. For your layer, you need to replace 79*4882a593Smuzhiyun "yoctobsp" with a unique identifier for your layer (e.g. "machinexyz" 80*4882a593Smuzhiyun for a layer named "meta-machinexyz"):: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun # We have a conf and classes directory, add to BBPATH 83*4882a593Smuzhiyun BBPATH .= ":${LAYERDIR}" 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun # We have recipes-* directories, add to BBFILES 86*4882a593Smuzhiyun BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ 87*4882a593Smuzhiyun ${LAYERDIR}/recipes-*/*/*.bbappend" 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun BBFILE_COLLECTIONS += "yoctobsp" 90*4882a593Smuzhiyun BBFILE_PATTERN_yoctobsp = "^${LAYERDIR}/" 91*4882a593Smuzhiyun BBFILE_PRIORITY_yoctobsp = "5" 92*4882a593Smuzhiyun LAYERVERSION_yoctobsp = "4" 93*4882a593Smuzhiyun LAYERSERIES_COMPAT_yoctobsp = "dunfell" 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun Following is an explanation of the layer configuration file: 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun - :term:`BBPATH`: Adds the layer's 98*4882a593Smuzhiyun root directory to BitBake's search path. Through the use of the 99*4882a593Smuzhiyun :term:`BBPATH` variable, BitBake locates class files (``.bbclass``), 100*4882a593Smuzhiyun configuration files, and files that are included with ``include`` 101*4882a593Smuzhiyun and ``require`` statements. For these cases, BitBake uses the 102*4882a593Smuzhiyun first file that matches the name found in :term:`BBPATH`. This is 103*4882a593Smuzhiyun similar to the way the ``PATH`` variable is used for binaries. It 104*4882a593Smuzhiyun is recommended, therefore, that you use unique class and 105*4882a593Smuzhiyun configuration filenames in your custom layer. 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun - :term:`BBFILES`: Defines the 108*4882a593Smuzhiyun location for all recipes in the layer. 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun - :term:`BBFILE_COLLECTIONS`: 111*4882a593Smuzhiyun Establishes the current layer through a unique identifier that is 112*4882a593Smuzhiyun used throughout the OpenEmbedded build system to refer to the 113*4882a593Smuzhiyun layer. In this example, the identifier "yoctobsp" is the 114*4882a593Smuzhiyun representation for the container layer named "meta-yocto-bsp". 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun - :term:`BBFILE_PATTERN`: 117*4882a593Smuzhiyun Expands immediately during parsing to provide the directory of the 118*4882a593Smuzhiyun layer. 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun - :term:`BBFILE_PRIORITY`: 121*4882a593Smuzhiyun Establishes a priority to use for recipes in the layer when the 122*4882a593Smuzhiyun OpenEmbedded build finds recipes of the same name in different 123*4882a593Smuzhiyun layers. 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun - :term:`LAYERVERSION`: 126*4882a593Smuzhiyun Establishes a version number for the layer. You can use this 127*4882a593Smuzhiyun version number to specify this exact version of the layer as a 128*4882a593Smuzhiyun dependency when using the 129*4882a593Smuzhiyun :term:`LAYERDEPENDS` 130*4882a593Smuzhiyun variable. 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun - :term:`LAYERDEPENDS`: 133*4882a593Smuzhiyun Lists all layers on which this layer depends (if any). 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun - :term:`LAYERSERIES_COMPAT`: 136*4882a593Smuzhiyun Lists the :yocto_wiki:`Yocto Project </Releases>` 137*4882a593Smuzhiyun releases for which the current version is compatible. This 138*4882a593Smuzhiyun variable is a good way to indicate if your particular layer is 139*4882a593Smuzhiyun current. 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun4. *Add Content:* Depending on the type of layer, add the content. If 142*4882a593Smuzhiyun the layer adds support for a machine, add the machine configuration 143*4882a593Smuzhiyun in a ``conf/machine/`` file within the layer. If the layer adds 144*4882a593Smuzhiyun distro policy, add the distro configuration in a ``conf/distro/`` 145*4882a593Smuzhiyun file within the layer. If the layer introduces new recipes, put the 146*4882a593Smuzhiyun recipes you need in ``recipes-*`` subdirectories within the layer. 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun .. note:: 149*4882a593Smuzhiyun 150*4882a593Smuzhiyun For an explanation of layer hierarchy that is compliant with the 151*4882a593Smuzhiyun Yocto Project, see the ":ref:`bsp-guide/bsp:example filesystem layout`" 152*4882a593Smuzhiyun section in the Yocto Project Board Support Package (BSP) Developer's Guide. 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun5. *Optionally Test for Compatibility:* If you want permission to use 155*4882a593Smuzhiyun the Yocto Project Compatibility logo with your layer or application 156*4882a593Smuzhiyun that uses your layer, perform the steps to apply for compatibility. 157*4882a593Smuzhiyun See the 158*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`" 159*4882a593Smuzhiyun section for more information. 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunFollowing Best Practices When Creating Layers 162*4882a593Smuzhiyun--------------------------------------------- 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunTo create layers that are easier to maintain and that will not impact 165*4882a593Smuzhiyunbuilds for other machines, you should consider the information in the 166*4882a593Smuzhiyunfollowing list: 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun- *Avoid "Overlaying" Entire Recipes from Other Layers in Your 169*4882a593Smuzhiyun Configuration:* In other words, do not copy an entire recipe into 170*4882a593Smuzhiyun your layer and then modify it. Rather, use an append file 171*4882a593Smuzhiyun (``.bbappend``) to override only those parts of the original recipe 172*4882a593Smuzhiyun you need to modify. 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun- *Avoid Duplicating Include Files:* Use append files (``.bbappend``) 175*4882a593Smuzhiyun for each recipe that uses an include file. Or, if you are introducing 176*4882a593Smuzhiyun a new recipe that requires the included file, use the path relative 177*4882a593Smuzhiyun to the original layer directory to refer to the file. For example, 178*4882a593Smuzhiyun use ``require recipes-core/``\ `package`\ ``/``\ `file`\ ``.inc`` instead 179*4882a593Smuzhiyun of ``require`` `file`\ ``.inc``. If you're finding you have to overlay 180*4882a593Smuzhiyun the include file, it could indicate a deficiency in the include file 181*4882a593Smuzhiyun in the layer to which it originally belongs. If this is the case, you 182*4882a593Smuzhiyun should try to address that deficiency instead of overlaying the 183*4882a593Smuzhiyun include file. For example, you could address this by getting the 184*4882a593Smuzhiyun maintainer of the include file to add a variable or variables to make 185*4882a593Smuzhiyun it easy to override the parts needing to be overridden. 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun- *Structure Your Layers:* Proper use of overrides within append files 188*4882a593Smuzhiyun and placement of machine-specific files within your layer can ensure 189*4882a593Smuzhiyun that a build is not using the wrong Metadata and negatively impacting 190*4882a593Smuzhiyun a build for a different machine. Following are some examples: 191*4882a593Smuzhiyun 192*4882a593Smuzhiyun - *Modify Variables to Support a Different Machine:* Suppose you 193*4882a593Smuzhiyun have a layer named ``meta-one`` that adds support for building 194*4882a593Smuzhiyun machine "one". To do so, you use an append file named 195*4882a593Smuzhiyun ``base-files.bbappend`` and create a dependency on "foo" by 196*4882a593Smuzhiyun altering the :term:`DEPENDS` 197*4882a593Smuzhiyun variable:: 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun DEPENDS = "foo" 200*4882a593Smuzhiyun 201*4882a593Smuzhiyun The dependency is created during any 202*4882a593Smuzhiyun build that includes the layer ``meta-one``. However, you might not 203*4882a593Smuzhiyun want this dependency for all machines. For example, suppose you 204*4882a593Smuzhiyun are building for machine "two" but your ``bblayers.conf`` file has 205*4882a593Smuzhiyun the ``meta-one`` layer included. During the build, the 206*4882a593Smuzhiyun ``base-files`` for machine "two" will also have the dependency on 207*4882a593Smuzhiyun ``foo``. 208*4882a593Smuzhiyun 209*4882a593Smuzhiyun To make sure your changes apply only when building machine "one", 210*4882a593Smuzhiyun use a machine override with the :term:`DEPENDS` statement:: 211*4882a593Smuzhiyun 212*4882a593Smuzhiyun DEPENDS:one = "foo" 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun You should follow the same strategy when using ``:append`` 215*4882a593Smuzhiyun and ``:prepend`` operations:: 216*4882a593Smuzhiyun 217*4882a593Smuzhiyun DEPENDS:append:one = " foo" 218*4882a593Smuzhiyun DEPENDS:prepend:one = "foo " 219*4882a593Smuzhiyun 220*4882a593Smuzhiyun As an actual example, here's a 221*4882a593Smuzhiyun snippet from the generic kernel include file ``linux-yocto.inc``, 222*4882a593Smuzhiyun wherein the kernel compile and link options are adjusted in the 223*4882a593Smuzhiyun case of a subset of the supported architectures:: 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun DEPENDS:append:aarch64 = " libgcc" 226*4882a593Smuzhiyun KERNEL_CC:append:aarch64 = " ${TOOLCHAIN_OPTIONS}" 227*4882a593Smuzhiyun KERNEL_LD:append:aarch64 = " ${TOOLCHAIN_OPTIONS}" 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun DEPENDS:append:nios2 = " libgcc" 230*4882a593Smuzhiyun KERNEL_CC:append:nios2 = " ${TOOLCHAIN_OPTIONS}" 231*4882a593Smuzhiyun KERNEL_LD:append:nios2 = " ${TOOLCHAIN_OPTIONS}" 232*4882a593Smuzhiyun 233*4882a593Smuzhiyun DEPENDS:append:arc = " libgcc" 234*4882a593Smuzhiyun KERNEL_CC:append:arc = " ${TOOLCHAIN_OPTIONS}" 235*4882a593Smuzhiyun KERNEL_LD:append:arc = " ${TOOLCHAIN_OPTIONS}" 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun KERNEL_FEATURES:append:qemuall=" features/debug/printk.scc" 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun - *Place Machine-Specific Files in Machine-Specific Locations:* When 240*4882a593Smuzhiyun you have a base recipe, such as ``base-files.bb``, that contains a 241*4882a593Smuzhiyun :term:`SRC_URI` statement to a 242*4882a593Smuzhiyun file, you can use an append file to cause the build to use your 243*4882a593Smuzhiyun own version of the file. For example, an append file in your layer 244*4882a593Smuzhiyun at ``meta-one/recipes-core/base-files/base-files.bbappend`` could 245*4882a593Smuzhiyun extend :term:`FILESPATH` using :term:`FILESEXTRAPATHS` as follows:: 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun FILESEXTRAPATHS:prepend := "${THISDIR}/${BPN}:" 248*4882a593Smuzhiyun 249*4882a593Smuzhiyun The build for machine "one" will pick up your machine-specific file as 250*4882a593Smuzhiyun long as you have the file in 251*4882a593Smuzhiyun ``meta-one/recipes-core/base-files/base-files/``. However, if you 252*4882a593Smuzhiyun are building for a different machine and the ``bblayers.conf`` 253*4882a593Smuzhiyun file includes the ``meta-one`` layer and the location of your 254*4882a593Smuzhiyun machine-specific file is the first location where that file is 255*4882a593Smuzhiyun found according to :term:`FILESPATH`, builds for all machines will 256*4882a593Smuzhiyun also use that machine-specific file. 257*4882a593Smuzhiyun 258*4882a593Smuzhiyun You can make sure that a machine-specific file is used for a 259*4882a593Smuzhiyun particular machine by putting the file in a subdirectory specific 260*4882a593Smuzhiyun to the machine. For example, rather than placing the file in 261*4882a593Smuzhiyun ``meta-one/recipes-core/base-files/base-files/`` as shown above, 262*4882a593Smuzhiyun put it in ``meta-one/recipes-core/base-files/base-files/one/``. 263*4882a593Smuzhiyun Not only does this make sure the file is used only when building 264*4882a593Smuzhiyun for machine "one", but the build process locates the file more 265*4882a593Smuzhiyun quickly. 266*4882a593Smuzhiyun 267*4882a593Smuzhiyun In summary, you need to place all files referenced from 268*4882a593Smuzhiyun :term:`SRC_URI` in a machine-specific subdirectory within the layer in 269*4882a593Smuzhiyun order to restrict those files to machine-specific builds. 270*4882a593Smuzhiyun 271*4882a593Smuzhiyun- *Perform Steps to Apply for Yocto Project Compatibility:* If you want 272*4882a593Smuzhiyun permission to use the Yocto Project Compatibility logo with your 273*4882a593Smuzhiyun layer or application that uses your layer, perform the steps to apply 274*4882a593Smuzhiyun for compatibility. See the 275*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:making sure your layer is compatible with yocto project`" 276*4882a593Smuzhiyun section for more information. 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun- *Follow the Layer Naming Convention:* Store custom layers in a Git 279*4882a593Smuzhiyun repository that use the ``meta-layer_name`` format. 280*4882a593Smuzhiyun 281*4882a593Smuzhiyun- *Group Your Layers Locally:* Clone your repository alongside other 282*4882a593Smuzhiyun cloned ``meta`` directories from the :term:`Source Directory`. 283*4882a593Smuzhiyun 284*4882a593SmuzhiyunMaking Sure Your Layer is Compatible With Yocto Project 285*4882a593Smuzhiyun------------------------------------------------------- 286*4882a593Smuzhiyun 287*4882a593SmuzhiyunWhen you create a layer used with the Yocto Project, it is advantageous 288*4882a593Smuzhiyunto make sure that the layer interacts well with existing Yocto Project 289*4882a593Smuzhiyunlayers (i.e. the layer is compatible with the Yocto Project). Ensuring 290*4882a593Smuzhiyuncompatibility makes the layer easy to be consumed by others in the Yocto 291*4882a593SmuzhiyunProject community and could allow you permission to use the Yocto 292*4882a593SmuzhiyunProject Compatible Logo. 293*4882a593Smuzhiyun 294*4882a593Smuzhiyun.. note:: 295*4882a593Smuzhiyun 296*4882a593Smuzhiyun Only Yocto Project member organizations are permitted to use the 297*4882a593Smuzhiyun Yocto Project Compatible Logo. The logo is not available for general 298*4882a593Smuzhiyun use. For information on how to become a Yocto Project member 299*4882a593Smuzhiyun organization, see the :yocto_home:`Yocto Project Website <>`. 300*4882a593Smuzhiyun 301*4882a593SmuzhiyunThe Yocto Project Compatibility Program consists of a layer application 302*4882a593Smuzhiyunprocess that requests permission to use the Yocto Project Compatibility 303*4882a593SmuzhiyunLogo for your layer and application. The process consists of two parts: 304*4882a593Smuzhiyun 305*4882a593Smuzhiyun1. Successfully passing a script (``yocto-check-layer``) that when run 306*4882a593Smuzhiyun against your layer, tests it against constraints based on experiences 307*4882a593Smuzhiyun of how layers have worked in the real world and where pitfalls have 308*4882a593Smuzhiyun been found. Getting a "PASS" result from the script is required for 309*4882a593Smuzhiyun successful compatibility registration. 310*4882a593Smuzhiyun 311*4882a593Smuzhiyun2. Completion of an application acceptance form, which you can find at 312*4882a593Smuzhiyun :yocto_home:`/webform/yocto-project-compatible-registration`. 313*4882a593Smuzhiyun 314*4882a593SmuzhiyunTo be granted permission to use the logo, you need to satisfy the 315*4882a593Smuzhiyunfollowing: 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun- Be able to check the box indicating that you got a "PASS" when 318*4882a593Smuzhiyun running the script against your layer. 319*4882a593Smuzhiyun 320*4882a593Smuzhiyun- Answer "Yes" to the questions on the form or have an acceptable 321*4882a593Smuzhiyun explanation for any questions answered "No". 322*4882a593Smuzhiyun 323*4882a593Smuzhiyun- Be a Yocto Project Member Organization. 324*4882a593Smuzhiyun 325*4882a593SmuzhiyunThe remainder of this section presents information on the registration 326*4882a593Smuzhiyunform and on the ``yocto-check-layer`` script. 327*4882a593Smuzhiyun 328*4882a593SmuzhiyunYocto Project Compatible Program Application 329*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 330*4882a593Smuzhiyun 331*4882a593SmuzhiyunUse the form to apply for your layer's approval. Upon successful 332*4882a593Smuzhiyunapplication, you can use the Yocto Project Compatibility Logo with your 333*4882a593Smuzhiyunlayer and the application that uses your layer. 334*4882a593Smuzhiyun 335*4882a593SmuzhiyunTo access the form, use this link: 336*4882a593Smuzhiyun:yocto_home:`/webform/yocto-project-compatible-registration`. 337*4882a593SmuzhiyunFollow the instructions on the form to complete your application. 338*4882a593Smuzhiyun 339*4882a593SmuzhiyunThe application consists of the following sections: 340*4882a593Smuzhiyun 341*4882a593Smuzhiyun- *Contact Information:* Provide your contact information as the fields 342*4882a593Smuzhiyun require. Along with your information, provide the released versions 343*4882a593Smuzhiyun of the Yocto Project for which your layer is compatible. 344*4882a593Smuzhiyun 345*4882a593Smuzhiyun- *Acceptance Criteria:* Provide "Yes" or "No" answers for each of the 346*4882a593Smuzhiyun items in the checklist. There is space at the bottom of the form for 347*4882a593Smuzhiyun any explanations for items for which you answered "No". 348*4882a593Smuzhiyun 349*4882a593Smuzhiyun- *Recommendations:* Provide answers for the questions regarding Linux 350*4882a593Smuzhiyun kernel use and build success. 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun``yocto-check-layer`` Script 353*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 354*4882a593Smuzhiyun 355*4882a593SmuzhiyunThe ``yocto-check-layer`` script provides you a way to assess how 356*4882a593Smuzhiyuncompatible your layer is with the Yocto Project. You should run this 357*4882a593Smuzhiyunscript prior to using the form to apply for compatibility as described 358*4882a593Smuzhiyunin the previous section. You need to achieve a "PASS" result in order to 359*4882a593Smuzhiyunhave your application form successfully processed. 360*4882a593Smuzhiyun 361*4882a593SmuzhiyunThe script divides tests into three areas: COMMON, BSP, and DISTRO. For 362*4882a593Smuzhiyunexample, given a distribution layer (DISTRO), the layer must pass both 363*4882a593Smuzhiyunthe COMMON and DISTRO related tests. Furthermore, if your layer is a BSP 364*4882a593Smuzhiyunlayer, the layer must pass the COMMON and BSP set of tests. 365*4882a593Smuzhiyun 366*4882a593SmuzhiyunTo execute the script, enter the following commands from your build 367*4882a593Smuzhiyundirectory:: 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun $ source oe-init-build-env 370*4882a593Smuzhiyun $ yocto-check-layer your_layer_directory 371*4882a593Smuzhiyun 372*4882a593SmuzhiyunBe sure to provide the actual directory for your 373*4882a593Smuzhiyunlayer as part of the command. 374*4882a593Smuzhiyun 375*4882a593SmuzhiyunEntering the command causes the script to determine the type of layer 376*4882a593Smuzhiyunand then to execute a set of specific tests against the layer. The 377*4882a593Smuzhiyunfollowing list overviews the test: 378*4882a593Smuzhiyun 379*4882a593Smuzhiyun- ``common.test_readme``: Tests if a ``README`` file exists in the 380*4882a593Smuzhiyun layer and the file is not empty. 381*4882a593Smuzhiyun 382*4882a593Smuzhiyun- ``common.test_parse``: Tests to make sure that BitBake can parse the 383*4882a593Smuzhiyun files without error (i.e. ``bitbake -p``). 384*4882a593Smuzhiyun 385*4882a593Smuzhiyun- ``common.test_show_environment``: Tests that the global or per-recipe 386*4882a593Smuzhiyun environment is in order without errors (i.e. ``bitbake -e``). 387*4882a593Smuzhiyun 388*4882a593Smuzhiyun- ``common.test_world``: Verifies that ``bitbake world`` works. 389*4882a593Smuzhiyun 390*4882a593Smuzhiyun- ``common.test_signatures``: Tests to be sure that BSP and DISTRO 391*4882a593Smuzhiyun layers do not come with recipes that change signatures. 392*4882a593Smuzhiyun 393*4882a593Smuzhiyun- ``common.test_layerseries_compat``: Verifies layer compatibility is 394*4882a593Smuzhiyun set properly. 395*4882a593Smuzhiyun 396*4882a593Smuzhiyun- ``bsp.test_bsp_defines_machines``: Tests if a BSP layer has machine 397*4882a593Smuzhiyun configurations. 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun- ``bsp.test_bsp_no_set_machine``: Tests to ensure a BSP layer does not 400*4882a593Smuzhiyun set the machine when the layer is added. 401*4882a593Smuzhiyun 402*4882a593Smuzhiyun- ``bsp.test_machine_world``: Verifies that ``bitbake world`` works 403*4882a593Smuzhiyun regardless of which machine is selected. 404*4882a593Smuzhiyun 405*4882a593Smuzhiyun- ``bsp.test_machine_signatures``: Verifies that building for a 406*4882a593Smuzhiyun particular machine affects only the signature of tasks specific to 407*4882a593Smuzhiyun that machine. 408*4882a593Smuzhiyun 409*4882a593Smuzhiyun- ``distro.test_distro_defines_distros``: Tests if a DISTRO layer has 410*4882a593Smuzhiyun distro configurations. 411*4882a593Smuzhiyun 412*4882a593Smuzhiyun- ``distro.test_distro_no_set_distros``: Tests to ensure a DISTRO layer 413*4882a593Smuzhiyun does not set the distribution when the layer is added. 414*4882a593Smuzhiyun 415*4882a593SmuzhiyunEnabling Your Layer 416*4882a593Smuzhiyun------------------- 417*4882a593Smuzhiyun 418*4882a593SmuzhiyunBefore the OpenEmbedded build system can use your new layer, you need to 419*4882a593Smuzhiyunenable it. To enable your layer, simply add your layer's path to the 420*4882a593Smuzhiyun:term:`BBLAYERS` variable in your ``conf/bblayers.conf`` file, which is 421*4882a593Smuzhiyunfound in the :term:`Build Directory`. 422*4882a593SmuzhiyunThe following example shows how to enable your new 423*4882a593Smuzhiyun``meta-mylayer`` layer (note how your new layer exists outside of 424*4882a593Smuzhiyunthe official ``poky`` repository which you would have checked out earlier):: 425*4882a593Smuzhiyun 426*4882a593Smuzhiyun # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf 427*4882a593Smuzhiyun # changes incompatibly 428*4882a593Smuzhiyun POKY_BBLAYERS_CONF_VERSION = "2" 429*4882a593Smuzhiyun BBPATH = "${TOPDIR}" 430*4882a593Smuzhiyun BBFILES ?= "" 431*4882a593Smuzhiyun BBLAYERS ?= " \ 432*4882a593Smuzhiyun /home/user/poky/meta \ 433*4882a593Smuzhiyun /home/user/poky/meta-poky \ 434*4882a593Smuzhiyun /home/user/poky/meta-yocto-bsp \ 435*4882a593Smuzhiyun /home/user/mystuff/meta-mylayer \ 436*4882a593Smuzhiyun " 437*4882a593Smuzhiyun 438*4882a593SmuzhiyunBitBake parses each ``conf/layer.conf`` file from the top down as 439*4882a593Smuzhiyunspecified in the :term:`BBLAYERS` variable within the ``conf/bblayers.conf`` 440*4882a593Smuzhiyunfile. During the processing of each ``conf/layer.conf`` file, BitBake 441*4882a593Smuzhiyunadds the recipes, classes and configurations contained within the 442*4882a593Smuzhiyunparticular layer to the source directory. 443*4882a593Smuzhiyun 444*4882a593SmuzhiyunAppending Other Layers Metadata With Your Layer 445*4882a593Smuzhiyun----------------------------------------------- 446*4882a593Smuzhiyun 447*4882a593SmuzhiyunA recipe that appends Metadata to another recipe is called a BitBake 448*4882a593Smuzhiyunappend file. A BitBake append file uses the ``.bbappend`` file type 449*4882a593Smuzhiyunsuffix, while the corresponding recipe to which Metadata is being 450*4882a593Smuzhiyunappended uses the ``.bb`` file type suffix. 451*4882a593Smuzhiyun 452*4882a593SmuzhiyunYou can use a ``.bbappend`` file in your layer to make additions or 453*4882a593Smuzhiyunchanges to the content of another layer's recipe without having to copy 454*4882a593Smuzhiyunthe other layer's recipe into your layer. Your ``.bbappend`` file 455*4882a593Smuzhiyunresides in your layer, while the main ``.bb`` recipe file to which you 456*4882a593Smuzhiyunare appending Metadata resides in a different layer. 457*4882a593Smuzhiyun 458*4882a593SmuzhiyunBeing able to append information to an existing recipe not only avoids 459*4882a593Smuzhiyunduplication, but also automatically applies recipe changes from a 460*4882a593Smuzhiyundifferent layer into your layer. If you were copying recipes, you would 461*4882a593Smuzhiyunhave to manually merge changes as they occur. 462*4882a593Smuzhiyun 463*4882a593SmuzhiyunWhen you create an append file, you must use the same root name as the 464*4882a593Smuzhiyuncorresponding recipe file. For example, the append file 465*4882a593Smuzhiyun``someapp_3.1.bbappend`` must apply to ``someapp_3.1.bb``. This 466*4882a593Smuzhiyunmeans the original recipe and append filenames are version 467*4882a593Smuzhiyunnumber-specific. If the corresponding recipe is renamed to update to a 468*4882a593Smuzhiyunnewer version, you must also rename and possibly update the 469*4882a593Smuzhiyuncorresponding ``.bbappend`` as well. During the build process, BitBake 470*4882a593Smuzhiyundisplays an error on starting if it detects a ``.bbappend`` file that 471*4882a593Smuzhiyundoes not have a corresponding recipe with a matching name. See the 472*4882a593Smuzhiyun:term:`BB_DANGLINGAPPENDS_WARNONLY` 473*4882a593Smuzhiyunvariable for information on how to handle this error. 474*4882a593Smuzhiyun 475*4882a593SmuzhiyunOverlaying a File Using Your Layer 476*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 477*4882a593Smuzhiyun 478*4882a593SmuzhiyunAs an example, consider the main formfactor recipe and a corresponding 479*4882a593Smuzhiyunformfactor append file both from the :term:`Source Directory`. 480*4882a593SmuzhiyunHere is the main 481*4882a593Smuzhiyunformfactor recipe, which is named ``formfactor_0.0.bb`` and located in 482*4882a593Smuzhiyunthe "meta" layer at ``meta/recipes-bsp/formfactor``:: 483*4882a593Smuzhiyun 484*4882a593Smuzhiyun SUMMARY = "Device formfactor information" 485*4882a593Smuzhiyun DESCRIPTION = "A formfactor configuration file provides information about the \ 486*4882a593Smuzhiyun target hardware for which the image is being built and information that the \ 487*4882a593Smuzhiyun build system cannot obtain from other sources such as the kernel." 488*4882a593Smuzhiyun SECTION = "base" 489*4882a593Smuzhiyun LICENSE = "MIT" 490*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" 491*4882a593Smuzhiyun PR = "r45" 492*4882a593Smuzhiyun 493*4882a593Smuzhiyun SRC_URI = "file://config file://machconfig" 494*4882a593Smuzhiyun S = "${WORKDIR}" 495*4882a593Smuzhiyun 496*4882a593Smuzhiyun PACKAGE_ARCH = "${MACHINE_ARCH}" 497*4882a593Smuzhiyun INHIBIT_DEFAULT_DEPS = "1" 498*4882a593Smuzhiyun 499*4882a593Smuzhiyun do_install() { 500*4882a593Smuzhiyun # Install file only if it has contents 501*4882a593Smuzhiyun install -d ${D}${sysconfdir}/formfactor/ 502*4882a593Smuzhiyun install -m 0644 ${S}/config ${D}${sysconfdir}/formfactor/ 503*4882a593Smuzhiyun if [ -s "${S}/machconfig" ]; then 504*4882a593Smuzhiyun install -m 0644 ${S}/machconfig ${D}${sysconfdir}/formfactor/ 505*4882a593Smuzhiyun fi 506*4882a593Smuzhiyun } 507*4882a593Smuzhiyun 508*4882a593SmuzhiyunIn the main recipe, note the :term:`SRC_URI` 509*4882a593Smuzhiyunvariable, which tells the OpenEmbedded build system where to find files 510*4882a593Smuzhiyunduring the build. 511*4882a593Smuzhiyun 512*4882a593SmuzhiyunFollowing is the append file, which is named ``formfactor_0.0.bbappend`` 513*4882a593Smuzhiyunand is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The 514*4882a593Smuzhiyunfile is in the layer at ``recipes-bsp/formfactor``:: 515*4882a593Smuzhiyun 516*4882a593Smuzhiyun FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" 517*4882a593Smuzhiyun 518*4882a593SmuzhiyunBy default, the build system uses the 519*4882a593Smuzhiyun:term:`FILESPATH` variable to 520*4882a593Smuzhiyunlocate files. This append file extends the locations by setting the 521*4882a593Smuzhiyun:term:`FILESEXTRAPATHS` 522*4882a593Smuzhiyunvariable. Setting this variable in the ``.bbappend`` file is the most 523*4882a593Smuzhiyunreliable and recommended method for adding directories to the search 524*4882a593Smuzhiyunpath used by the build system to find files. 525*4882a593Smuzhiyun 526*4882a593SmuzhiyunThe statement in this example extends the directories to include 527*4882a593Smuzhiyun``${``\ :term:`THISDIR`\ ``}/${``\ :term:`PN`\ ``}``, 528*4882a593Smuzhiyunwhich resolves to a directory named ``formfactor`` in the same directory 529*4882a593Smuzhiyunin which the append file resides (i.e. 530*4882a593Smuzhiyun``meta-raspberrypi/recipes-bsp/formfactor``. This implies that you must 531*4882a593Smuzhiyunhave the supporting directory structure set up that will contain any 532*4882a593Smuzhiyunfiles or patches you will be including from the layer. 533*4882a593Smuzhiyun 534*4882a593SmuzhiyunUsing the immediate expansion assignment operator ``:=`` is important 535*4882a593Smuzhiyunbecause of the reference to :term:`THISDIR`. The trailing colon character is 536*4882a593Smuzhiyunimportant as it ensures that items in the list remain colon-separated. 537*4882a593Smuzhiyun 538*4882a593Smuzhiyun.. note:: 539*4882a593Smuzhiyun 540*4882a593Smuzhiyun BitBake automatically defines the :term:`THISDIR` variable. You should 541*4882a593Smuzhiyun never set this variable yourself. Using ":prepend" as part of the 542*4882a593Smuzhiyun :term:`FILESEXTRAPATHS` ensures your path will be searched prior to other 543*4882a593Smuzhiyun paths in the final list. 544*4882a593Smuzhiyun 545*4882a593Smuzhiyun Also, not all append files add extra files. Many append files simply 546*4882a593Smuzhiyun allow to add build options (e.g. ``systemd``). For these cases, your 547*4882a593Smuzhiyun append file would not even use the :term:`FILESEXTRAPATHS` statement. 548*4882a593Smuzhiyun 549*4882a593SmuzhiyunThe end result of this ``.bbappend`` file is that on a Raspberry Pi, where 550*4882a593Smuzhiyun``rpi`` will exist in the list of :term:`OVERRIDES`, the file 551*4882a593Smuzhiyun``meta-raspberrypi/recipes-bsp/formfactor/formfactor/rpi/machconfig`` will be 552*4882a593Smuzhiyunused during :ref:`ref-tasks-fetch` and the test for a non-zero file size in 553*4882a593Smuzhiyun:ref:`ref-tasks-install` will return true, and the file will be installed. 554*4882a593Smuzhiyun 555*4882a593SmuzhiyunInstalling Additional Files Using Your Layer 556*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 557*4882a593Smuzhiyun 558*4882a593SmuzhiyunAs another example, consider the main ``xserver-xf86-config`` recipe and a 559*4882a593Smuzhiyuncorresponding ``xserver-xf86-config`` append file both from the :term:`Source 560*4882a593SmuzhiyunDirectory`. Here is the main ``xserver-xf86-config`` recipe, which is named 561*4882a593Smuzhiyun``xserver-xf86-config_0.1.bb`` and located in the "meta" layer at 562*4882a593Smuzhiyun``meta/recipes-graphics/xorg-xserver``:: 563*4882a593Smuzhiyun 564*4882a593Smuzhiyun SUMMARY = "X.Org X server configuration file" 565*4882a593Smuzhiyun HOMEPAGE = "http://www.x.org" 566*4882a593Smuzhiyun SECTION = "x11/base" 567*4882a593Smuzhiyun LICENSE = "MIT" 568*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" 569*4882a593Smuzhiyun PR = "r33" 570*4882a593Smuzhiyun 571*4882a593Smuzhiyun SRC_URI = "file://xorg.conf" 572*4882a593Smuzhiyun 573*4882a593Smuzhiyun S = "${WORKDIR}" 574*4882a593Smuzhiyun 575*4882a593Smuzhiyun CONFFILES:${PN} = "${sysconfdir}/X11/xorg.conf" 576*4882a593Smuzhiyun 577*4882a593Smuzhiyun PACKAGE_ARCH = "${MACHINE_ARCH}" 578*4882a593Smuzhiyun ALLOW_EMPTY:${PN} = "1" 579*4882a593Smuzhiyun 580*4882a593Smuzhiyun do_install () { 581*4882a593Smuzhiyun if test -s ${WORKDIR}/xorg.conf; then 582*4882a593Smuzhiyun install -d ${D}/${sysconfdir}/X11 583*4882a593Smuzhiyun install -m 0644 ${WORKDIR}/xorg.conf ${D}/${sysconfdir}/X11/ 584*4882a593Smuzhiyun fi 585*4882a593Smuzhiyun } 586*4882a593Smuzhiyun 587*4882a593SmuzhiyunFollowing is the append file, which is named ``xserver-xf86-config_%.bbappend`` 588*4882a593Smuzhiyunand is from the Raspberry Pi BSP Layer named ``meta-raspberrypi``. The 589*4882a593Smuzhiyunfile is in the layer at ``recipes-graphics/xorg-xserver``:: 590*4882a593Smuzhiyun 591*4882a593Smuzhiyun FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:" 592*4882a593Smuzhiyun 593*4882a593Smuzhiyun SRC_URI:append:rpi = " \ 594*4882a593Smuzhiyun file://xorg.conf.d/98-pitft.conf \ 595*4882a593Smuzhiyun file://xorg.conf.d/99-calibration.conf \ 596*4882a593Smuzhiyun " 597*4882a593Smuzhiyun do_install:append:rpi () { 598*4882a593Smuzhiyun PITFT="${@bb.utils.contains("MACHINE_FEATURES", "pitft", "1", "0", d)}" 599*4882a593Smuzhiyun if [ "${PITFT}" = "1" ]; then 600*4882a593Smuzhiyun install -d ${D}/${sysconfdir}/X11/xorg.conf.d/ 601*4882a593Smuzhiyun install -m 0644 ${WORKDIR}/xorg.conf.d/98-pitft.conf ${D}/${sysconfdir}/X11/xorg.conf.d/ 602*4882a593Smuzhiyun install -m 0644 ${WORKDIR}/xorg.conf.d/99-calibration.conf ${D}/${sysconfdir}/X11/xorg.conf.d/ 603*4882a593Smuzhiyun fi 604*4882a593Smuzhiyun } 605*4882a593Smuzhiyun 606*4882a593Smuzhiyun FILES:${PN}:append:rpi = " ${sysconfdir}/X11/xorg.conf.d/*" 607*4882a593Smuzhiyun 608*4882a593SmuzhiyunBuilding off of the previous example, we once again are setting the 609*4882a593Smuzhiyun:term:`FILESEXTRAPATHS` variable. In this case we are also using 610*4882a593Smuzhiyun:term:`SRC_URI` to list additional source files to use when ``rpi`` is found in 611*4882a593Smuzhiyunthe list of :term:`OVERRIDES`. The :ref:`ref-tasks-install` task will then perform a 612*4882a593Smuzhiyuncheck for an additional :term:`MACHINE_FEATURES` that if set will cause these 613*4882a593Smuzhiyunadditional files to be installed. These additional files are listed in 614*4882a593Smuzhiyun:term:`FILES` so that they will be packaged. 615*4882a593Smuzhiyun 616*4882a593SmuzhiyunPrioritizing Your Layer 617*4882a593Smuzhiyun----------------------- 618*4882a593Smuzhiyun 619*4882a593SmuzhiyunEach layer is assigned a priority value. Priority values control which 620*4882a593Smuzhiyunlayer takes precedence if there are recipe files with the same name in 621*4882a593Smuzhiyunmultiple layers. For these cases, the recipe file from the layer with a 622*4882a593Smuzhiyunhigher priority number takes precedence. Priority values also affect the 623*4882a593Smuzhiyunorder in which multiple ``.bbappend`` files for the same recipe are 624*4882a593Smuzhiyunapplied. You can either specify the priority manually, or allow the 625*4882a593Smuzhiyunbuild system to calculate it based on the layer's dependencies. 626*4882a593Smuzhiyun 627*4882a593SmuzhiyunTo specify the layer's priority manually, use the 628*4882a593Smuzhiyun:term:`BBFILE_PRIORITY` 629*4882a593Smuzhiyunvariable and append the layer's root name:: 630*4882a593Smuzhiyun 631*4882a593Smuzhiyun BBFILE_PRIORITY_mylayer = "1" 632*4882a593Smuzhiyun 633*4882a593Smuzhiyun.. note:: 634*4882a593Smuzhiyun 635*4882a593Smuzhiyun It is possible for a recipe with a lower version number 636*4882a593Smuzhiyun :term:`PV` in a layer that has a higher 637*4882a593Smuzhiyun priority to take precedence. 638*4882a593Smuzhiyun 639*4882a593Smuzhiyun Also, the layer priority does not currently affect the precedence 640*4882a593Smuzhiyun order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake 641*4882a593Smuzhiyun might address this. 642*4882a593Smuzhiyun 643*4882a593SmuzhiyunManaging Layers 644*4882a593Smuzhiyun--------------- 645*4882a593Smuzhiyun 646*4882a593SmuzhiyunYou can use the BitBake layer management tool ``bitbake-layers`` to 647*4882a593Smuzhiyunprovide a view into the structure of recipes across a multi-layer 648*4882a593Smuzhiyunproject. Being able to generate output that reports on configured layers 649*4882a593Smuzhiyunwith their paths and priorities and on ``.bbappend`` files and their 650*4882a593Smuzhiyunapplicable recipes can help to reveal potential problems. 651*4882a593Smuzhiyun 652*4882a593SmuzhiyunFor help on the BitBake layer management tool, use the following 653*4882a593Smuzhiyuncommand:: 654*4882a593Smuzhiyun 655*4882a593Smuzhiyun $ bitbake-layers --help 656*4882a593Smuzhiyun NOTE: Starting bitbake server... 657*4882a593Smuzhiyun usage: bitbake-layers [-d] [-q] [-F] [--color COLOR] [-h] <subcommand> ... 658*4882a593Smuzhiyun 659*4882a593Smuzhiyun BitBake layers utility 660*4882a593Smuzhiyun 661*4882a593Smuzhiyun optional arguments: 662*4882a593Smuzhiyun -d, --debug Enable debug output 663*4882a593Smuzhiyun -q, --quiet Print only errors 664*4882a593Smuzhiyun -F, --force Force add without recipe parse verification 665*4882a593Smuzhiyun --color COLOR Colorize output (where COLOR is auto, always, never) 666*4882a593Smuzhiyun -h, --help show this help message and exit 667*4882a593Smuzhiyun 668*4882a593Smuzhiyun subcommands: 669*4882a593Smuzhiyun <subcommand> 670*4882a593Smuzhiyun layerindex-fetch Fetches a layer from a layer index along with its 671*4882a593Smuzhiyun dependent layers, and adds them to conf/bblayers.conf. 672*4882a593Smuzhiyun layerindex-show-depends 673*4882a593Smuzhiyun Find layer dependencies from layer index. 674*4882a593Smuzhiyun add-layer Add one or more layers to bblayers.conf. 675*4882a593Smuzhiyun remove-layer Remove one or more layers from bblayers.conf. 676*4882a593Smuzhiyun flatten flatten layer configuration into a separate output 677*4882a593Smuzhiyun directory. 678*4882a593Smuzhiyun show-layers show current configured layers. 679*4882a593Smuzhiyun show-overlayed list overlayed recipes (where the same recipe exists 680*4882a593Smuzhiyun in another layer) 681*4882a593Smuzhiyun show-recipes list available recipes, showing the layer they are 682*4882a593Smuzhiyun provided by 683*4882a593Smuzhiyun show-appends list bbappend files and recipe files they apply to 684*4882a593Smuzhiyun show-cross-depends Show dependencies between recipes that cross layer 685*4882a593Smuzhiyun boundaries. 686*4882a593Smuzhiyun create-layer Create a basic layer 687*4882a593Smuzhiyun 688*4882a593Smuzhiyun Use bitbake-layers <subcommand> --help to get help on a specific command 689*4882a593Smuzhiyun 690*4882a593SmuzhiyunThe following list describes the available commands: 691*4882a593Smuzhiyun 692*4882a593Smuzhiyun- ``help:`` Displays general help or help on a specified command. 693*4882a593Smuzhiyun 694*4882a593Smuzhiyun- ``show-layers:`` Shows the current configured layers. 695*4882a593Smuzhiyun 696*4882a593Smuzhiyun- ``show-overlayed:`` Lists overlayed recipes. A recipe is overlayed 697*4882a593Smuzhiyun when a recipe with the same name exists in another layer that has a 698*4882a593Smuzhiyun higher layer priority. 699*4882a593Smuzhiyun 700*4882a593Smuzhiyun- ``show-recipes:`` Lists available recipes and the layers that 701*4882a593Smuzhiyun provide them. 702*4882a593Smuzhiyun 703*4882a593Smuzhiyun- ``show-appends:`` Lists ``.bbappend`` files and the recipe files to 704*4882a593Smuzhiyun which they apply. 705*4882a593Smuzhiyun 706*4882a593Smuzhiyun- ``show-cross-depends:`` Lists dependency relationships between 707*4882a593Smuzhiyun recipes that cross layer boundaries. 708*4882a593Smuzhiyun 709*4882a593Smuzhiyun- ``add-layer:`` Adds a layer to ``bblayers.conf``. 710*4882a593Smuzhiyun 711*4882a593Smuzhiyun- ``remove-layer:`` Removes a layer from ``bblayers.conf`` 712*4882a593Smuzhiyun 713*4882a593Smuzhiyun- ``flatten:`` Flattens the layer configuration into a separate 714*4882a593Smuzhiyun output directory. Flattening your layer configuration builds a 715*4882a593Smuzhiyun "flattened" directory that contains the contents of all layers, with 716*4882a593Smuzhiyun any overlayed recipes removed and any ``.bbappend`` files appended to 717*4882a593Smuzhiyun the corresponding recipes. You might have to perform some manual 718*4882a593Smuzhiyun cleanup of the flattened layer as follows: 719*4882a593Smuzhiyun 720*4882a593Smuzhiyun - Non-recipe files (such as patches) are overwritten. The flatten 721*4882a593Smuzhiyun command shows a warning for these files. 722*4882a593Smuzhiyun 723*4882a593Smuzhiyun - Anything beyond the normal layer setup has been added to the 724*4882a593Smuzhiyun ``layer.conf`` file. Only the lowest priority layer's 725*4882a593Smuzhiyun ``layer.conf`` is used. 726*4882a593Smuzhiyun 727*4882a593Smuzhiyun - Overridden and appended items from ``.bbappend`` files need to be 728*4882a593Smuzhiyun cleaned up. The contents of each ``.bbappend`` end up in the 729*4882a593Smuzhiyun flattened recipe. However, if there are appended or changed 730*4882a593Smuzhiyun variable values, you need to tidy these up yourself. Consider the 731*4882a593Smuzhiyun following example. Here, the ``bitbake-layers`` command adds the 732*4882a593Smuzhiyun line ``#### bbappended ...`` so that you know where the following 733*4882a593Smuzhiyun lines originate:: 734*4882a593Smuzhiyun 735*4882a593Smuzhiyun ... 736*4882a593Smuzhiyun DESCRIPTION = "A useful utility" 737*4882a593Smuzhiyun ... 738*4882a593Smuzhiyun EXTRA_OECONF = "--enable-something" 739*4882a593Smuzhiyun ... 740*4882a593Smuzhiyun 741*4882a593Smuzhiyun #### bbappended from meta-anotherlayer #### 742*4882a593Smuzhiyun 743*4882a593Smuzhiyun DESCRIPTION = "Customized utility" 744*4882a593Smuzhiyun EXTRA_OECONF += "--enable-somethingelse" 745*4882a593Smuzhiyun 746*4882a593Smuzhiyun 747*4882a593Smuzhiyun Ideally, you would tidy up these utilities as follows:: 748*4882a593Smuzhiyun 749*4882a593Smuzhiyun ... 750*4882a593Smuzhiyun DESCRIPTION = "Customized utility" 751*4882a593Smuzhiyun ... 752*4882a593Smuzhiyun EXTRA_OECONF = "--enable-something --enable-somethingelse" 753*4882a593Smuzhiyun ... 754*4882a593Smuzhiyun 755*4882a593Smuzhiyun- ``layerindex-fetch``: Fetches a layer from a layer index, along 756*4882a593Smuzhiyun with its dependent layers, and adds the layers to the 757*4882a593Smuzhiyun ``conf/bblayers.conf`` file. 758*4882a593Smuzhiyun 759*4882a593Smuzhiyun- ``layerindex-show-depends``: Finds layer dependencies from the 760*4882a593Smuzhiyun layer index. 761*4882a593Smuzhiyun 762*4882a593Smuzhiyun- ``create-layer``: Creates a basic layer. 763*4882a593Smuzhiyun 764*4882a593SmuzhiyunCreating a General Layer Using the ``bitbake-layers`` Script 765*4882a593Smuzhiyun------------------------------------------------------------ 766*4882a593Smuzhiyun 767*4882a593SmuzhiyunThe ``bitbake-layers`` script with the ``create-layer`` subcommand 768*4882a593Smuzhiyunsimplifies creating a new general layer. 769*4882a593Smuzhiyun 770*4882a593Smuzhiyun.. note:: 771*4882a593Smuzhiyun 772*4882a593Smuzhiyun - For information on BSP layers, see the ":ref:`bsp-guide/bsp:bsp layers`" 773*4882a593Smuzhiyun section in the Yocto 774*4882a593Smuzhiyun Project Board Specific (BSP) Developer's Guide. 775*4882a593Smuzhiyun 776*4882a593Smuzhiyun - In order to use a layer with the OpenEmbedded build system, you 777*4882a593Smuzhiyun need to add the layer to your ``bblayers.conf`` configuration 778*4882a593Smuzhiyun file. See the ":ref:`dev-manual/common-tasks:adding a layer using the \`\`bitbake-layers\`\` script`" 779*4882a593Smuzhiyun section for more information. 780*4882a593Smuzhiyun 781*4882a593SmuzhiyunThe default mode of the script's operation with this subcommand is to 782*4882a593Smuzhiyuncreate a layer with the following: 783*4882a593Smuzhiyun 784*4882a593Smuzhiyun- A layer priority of 6. 785*4882a593Smuzhiyun 786*4882a593Smuzhiyun- A ``conf`` subdirectory that contains a ``layer.conf`` file. 787*4882a593Smuzhiyun 788*4882a593Smuzhiyun- A ``recipes-example`` subdirectory that contains a further 789*4882a593Smuzhiyun subdirectory named ``example``, which contains an ``example.bb`` 790*4882a593Smuzhiyun recipe file. 791*4882a593Smuzhiyun 792*4882a593Smuzhiyun- A ``COPYING.MIT``, which is the license statement for the layer. The 793*4882a593Smuzhiyun script assumes you want to use the MIT license, which is typical for 794*4882a593Smuzhiyun most layers, for the contents of the layer itself. 795*4882a593Smuzhiyun 796*4882a593Smuzhiyun- A ``README`` file, which is a file describing the contents of your 797*4882a593Smuzhiyun new layer. 798*4882a593Smuzhiyun 799*4882a593SmuzhiyunIn its simplest form, you can use the following command form to create a 800*4882a593Smuzhiyunlayer. The command creates a layer whose name corresponds to 801*4882a593Smuzhiyun"your_layer_name" in the current directory:: 802*4882a593Smuzhiyun 803*4882a593Smuzhiyun $ bitbake-layers create-layer your_layer_name 804*4882a593Smuzhiyun 805*4882a593SmuzhiyunAs an example, the following command creates a layer named ``meta-scottrif`` 806*4882a593Smuzhiyunin your home directory:: 807*4882a593Smuzhiyun 808*4882a593Smuzhiyun $ cd /usr/home 809*4882a593Smuzhiyun $ bitbake-layers create-layer meta-scottrif 810*4882a593Smuzhiyun NOTE: Starting bitbake server... 811*4882a593Smuzhiyun Add your new layer with 'bitbake-layers add-layer meta-scottrif' 812*4882a593Smuzhiyun 813*4882a593SmuzhiyunIf you want to set the priority of the layer to other than the default 814*4882a593Smuzhiyunvalue of "6", you can either use the ``--priority`` option or you 815*4882a593Smuzhiyuncan edit the 816*4882a593Smuzhiyun:term:`BBFILE_PRIORITY` value 817*4882a593Smuzhiyunin the ``conf/layer.conf`` after the script creates it. Furthermore, if 818*4882a593Smuzhiyunyou want to give the example recipe file some name other than the 819*4882a593Smuzhiyundefault, you can use the ``--example-recipe-name`` option. 820*4882a593Smuzhiyun 821*4882a593SmuzhiyunThe easiest way to see how the ``bitbake-layers create-layer`` command 822*4882a593Smuzhiyunworks is to experiment with the script. You can also read the usage 823*4882a593Smuzhiyuninformation by entering the following:: 824*4882a593Smuzhiyun 825*4882a593Smuzhiyun $ bitbake-layers create-layer --help 826*4882a593Smuzhiyun NOTE: Starting bitbake server... 827*4882a593Smuzhiyun usage: bitbake-layers create-layer [-h] [--priority PRIORITY] 828*4882a593Smuzhiyun [--example-recipe-name EXAMPLERECIPE] 829*4882a593Smuzhiyun layerdir 830*4882a593Smuzhiyun 831*4882a593Smuzhiyun Create a basic layer 832*4882a593Smuzhiyun 833*4882a593Smuzhiyun positional arguments: 834*4882a593Smuzhiyun layerdir Layer directory to create 835*4882a593Smuzhiyun 836*4882a593Smuzhiyun optional arguments: 837*4882a593Smuzhiyun -h, --help show this help message and exit 838*4882a593Smuzhiyun --priority PRIORITY, -p PRIORITY 839*4882a593Smuzhiyun Layer directory to create 840*4882a593Smuzhiyun --example-recipe-name EXAMPLERECIPE, -e EXAMPLERECIPE 841*4882a593Smuzhiyun Filename of the example recipe 842*4882a593Smuzhiyun 843*4882a593SmuzhiyunAdding a Layer Using the ``bitbake-layers`` Script 844*4882a593Smuzhiyun-------------------------------------------------- 845*4882a593Smuzhiyun 846*4882a593SmuzhiyunOnce you create your general layer, you must add it to your 847*4882a593Smuzhiyun``bblayers.conf`` file. Adding the layer to this configuration file 848*4882a593Smuzhiyunmakes the OpenEmbedded build system aware of your layer so that it can 849*4882a593Smuzhiyunsearch it for metadata. 850*4882a593Smuzhiyun 851*4882a593SmuzhiyunAdd your layer by using the ``bitbake-layers add-layer`` command:: 852*4882a593Smuzhiyun 853*4882a593Smuzhiyun $ bitbake-layers add-layer your_layer_name 854*4882a593Smuzhiyun 855*4882a593SmuzhiyunHere is an example that adds a 856*4882a593Smuzhiyunlayer named ``meta-scottrif`` to the configuration file. Following the 857*4882a593Smuzhiyuncommand that adds the layer is another ``bitbake-layers`` command that 858*4882a593Smuzhiyunshows the layers that are in your ``bblayers.conf`` file:: 859*4882a593Smuzhiyun 860*4882a593Smuzhiyun $ bitbake-layers add-layer meta-scottrif 861*4882a593Smuzhiyun NOTE: Starting bitbake server... 862*4882a593Smuzhiyun Parsing recipes: 100% |##########################################################| Time: 0:00:49 863*4882a593Smuzhiyun Parsing of 1441 .bb files complete (0 cached, 1441 parsed). 2055 targets, 56 skipped, 0 masked, 0 errors. 864*4882a593Smuzhiyun $ bitbake-layers show-layers 865*4882a593Smuzhiyun NOTE: Starting bitbake server... 866*4882a593Smuzhiyun layer path priority 867*4882a593Smuzhiyun ========================================================================== 868*4882a593Smuzhiyun meta /home/scottrif/poky/meta 5 869*4882a593Smuzhiyun meta-poky /home/scottrif/poky/meta-poky 5 870*4882a593Smuzhiyun meta-yocto-bsp /home/scottrif/poky/meta-yocto-bsp 5 871*4882a593Smuzhiyun workspace /home/scottrif/poky/build/workspace 99 872*4882a593Smuzhiyun meta-scottrif /home/scottrif/poky/build/meta-scottrif 6 873*4882a593Smuzhiyun 874*4882a593Smuzhiyun 875*4882a593SmuzhiyunAdding the layer to this file 876*4882a593Smuzhiyunenables the build system to locate the layer during the build. 877*4882a593Smuzhiyun 878*4882a593Smuzhiyun.. note:: 879*4882a593Smuzhiyun 880*4882a593Smuzhiyun During a build, the OpenEmbedded build system looks in the layers 881*4882a593Smuzhiyun from the top of the list down to the bottom in that order. 882*4882a593Smuzhiyun 883*4882a593SmuzhiyunCustomizing Images 884*4882a593Smuzhiyun================== 885*4882a593Smuzhiyun 886*4882a593SmuzhiyunYou can customize images to satisfy particular requirements. This 887*4882a593Smuzhiyunsection describes several methods and provides guidelines for each. 888*4882a593Smuzhiyun 889*4882a593SmuzhiyunCustomizing Images Using ``local.conf`` 890*4882a593Smuzhiyun--------------------------------------- 891*4882a593Smuzhiyun 892*4882a593SmuzhiyunProbably the easiest way to customize an image is to add a package by 893*4882a593Smuzhiyunway of the ``local.conf`` configuration file. Because it is limited to 894*4882a593Smuzhiyunlocal use, this method generally only allows you to add packages and is 895*4882a593Smuzhiyunnot as flexible as creating your own customized image. When you add 896*4882a593Smuzhiyunpackages using local variables this way, you need to realize that these 897*4882a593Smuzhiyunvariable changes are in effect for every build and consequently affect 898*4882a593Smuzhiyunall images, which might not be what you require. 899*4882a593Smuzhiyun 900*4882a593SmuzhiyunTo add a package to your image using the local configuration file, use 901*4882a593Smuzhiyunthe :term:`IMAGE_INSTALL` variable with the ``:append`` operator:: 902*4882a593Smuzhiyun 903*4882a593Smuzhiyun IMAGE_INSTALL:append = " strace" 904*4882a593Smuzhiyun 905*4882a593SmuzhiyunUse of the syntax is important; specifically, the leading space 906*4882a593Smuzhiyunafter the opening quote and before the package name, which is 907*4882a593Smuzhiyun``strace`` in this example. This space is required since the ``:append`` 908*4882a593Smuzhiyunoperator does not add the space. 909*4882a593Smuzhiyun 910*4882a593SmuzhiyunFurthermore, you must use ``:append`` instead of the ``+=`` operator if 911*4882a593Smuzhiyunyou want to avoid ordering issues. The reason for this is because doing 912*4882a593Smuzhiyunso unconditionally appends to the variable and avoids ordering problems 913*4882a593Smuzhiyundue to the variable being set in image recipes and ``.bbclass`` files 914*4882a593Smuzhiyunwith operators like ``?=``. Using ``:append`` ensures the operation 915*4882a593Smuzhiyuntakes effect. 916*4882a593Smuzhiyun 917*4882a593SmuzhiyunAs shown in its simplest use, ``IMAGE_INSTALL:append`` affects all 918*4882a593Smuzhiyunimages. It is possible to extend the syntax so that the variable applies 919*4882a593Smuzhiyunto a specific image only. Here is an example:: 920*4882a593Smuzhiyun 921*4882a593Smuzhiyun IMAGE_INSTALL:append:pn-core-image-minimal = " strace" 922*4882a593Smuzhiyun 923*4882a593SmuzhiyunThis example adds ``strace`` to the ``core-image-minimal`` image only. 924*4882a593Smuzhiyun 925*4882a593SmuzhiyunYou can add packages using a similar approach through the 926*4882a593Smuzhiyun:term:`CORE_IMAGE_EXTRA_INSTALL` variable. If you use this variable, only 927*4882a593Smuzhiyun``core-image-*`` images are affected. 928*4882a593Smuzhiyun 929*4882a593SmuzhiyunCustomizing Images Using Custom ``IMAGE_FEATURES`` and ``EXTRA_IMAGE_FEATURES`` 930*4882a593Smuzhiyun------------------------------------------------------------------------------- 931*4882a593Smuzhiyun 932*4882a593SmuzhiyunAnother method for customizing your image is to enable or disable 933*4882a593Smuzhiyunhigh-level image features by using the 934*4882a593Smuzhiyun:term:`IMAGE_FEATURES` and 935*4882a593Smuzhiyun:term:`EXTRA_IMAGE_FEATURES` 936*4882a593Smuzhiyunvariables. Although the functions for both variables are nearly 937*4882a593Smuzhiyunequivalent, best practices dictate using :term:`IMAGE_FEATURES` from within 938*4882a593Smuzhiyuna recipe and using :term:`EXTRA_IMAGE_FEATURES` from within your 939*4882a593Smuzhiyun``local.conf`` file, which is found in the 940*4882a593Smuzhiyun:term:`Build Directory`. 941*4882a593Smuzhiyun 942*4882a593SmuzhiyunTo understand how these features work, the best reference is 943*4882a593Smuzhiyun:ref:`meta/classes/image.bbclass <ref-classes-image>`. 944*4882a593SmuzhiyunThis class lists out the available 945*4882a593Smuzhiyun:term:`IMAGE_FEATURES` of which most map to package groups while some, such 946*4882a593Smuzhiyunas ``debug-tweaks`` and ``read-only-rootfs``, resolve as general 947*4882a593Smuzhiyunconfiguration settings. 948*4882a593Smuzhiyun 949*4882a593SmuzhiyunIn summary, the file looks at the contents of the :term:`IMAGE_FEATURES` 950*4882a593Smuzhiyunvariable and then maps or configures the feature accordingly. Based on 951*4882a593Smuzhiyunthis information, the build system automatically adds the appropriate 952*4882a593Smuzhiyunpackages or configurations to the 953*4882a593Smuzhiyun:term:`IMAGE_INSTALL` variable. 954*4882a593SmuzhiyunEffectively, you are enabling extra features by extending the class or 955*4882a593Smuzhiyuncreating a custom class for use with specialized image ``.bb`` files. 956*4882a593Smuzhiyun 957*4882a593SmuzhiyunUse the :term:`EXTRA_IMAGE_FEATURES` variable from within your local 958*4882a593Smuzhiyunconfiguration file. Using a separate area from which to enable features 959*4882a593Smuzhiyunwith this variable helps you avoid overwriting the features in the image 960*4882a593Smuzhiyunrecipe that are enabled with :term:`IMAGE_FEATURES`. The value of 961*4882a593Smuzhiyun:term:`EXTRA_IMAGE_FEATURES` is added to :term:`IMAGE_FEATURES` within 962*4882a593Smuzhiyun``meta/conf/bitbake.conf``. 963*4882a593Smuzhiyun 964*4882a593SmuzhiyunTo illustrate how you can use these variables to modify your image, 965*4882a593Smuzhiyunconsider an example that selects the SSH server. The Yocto Project ships 966*4882a593Smuzhiyunwith two SSH servers you can use with your images: Dropbear and OpenSSH. 967*4882a593SmuzhiyunDropbear is a minimal SSH server appropriate for resource-constrained 968*4882a593Smuzhiyunenvironments, while OpenSSH is a well-known standard SSH server 969*4882a593Smuzhiyunimplementation. By default, the ``core-image-sato`` image is configured 970*4882a593Smuzhiyunto use Dropbear. The ``core-image-full-cmdline`` and ``core-image-lsb`` 971*4882a593Smuzhiyunimages both include OpenSSH. The ``core-image-minimal`` image does not 972*4882a593Smuzhiyuncontain an SSH server. 973*4882a593Smuzhiyun 974*4882a593SmuzhiyunYou can customize your image and change these defaults. Edit the 975*4882a593Smuzhiyun:term:`IMAGE_FEATURES` variable in your recipe or use the 976*4882a593Smuzhiyun:term:`EXTRA_IMAGE_FEATURES` in your ``local.conf`` file so that it 977*4882a593Smuzhiyunconfigures the image you are working with to include 978*4882a593Smuzhiyun``ssh-server-dropbear`` or ``ssh-server-openssh``. 979*4882a593Smuzhiyun 980*4882a593Smuzhiyun.. note:: 981*4882a593Smuzhiyun 982*4882a593Smuzhiyun See the ":ref:`ref-manual/features:image features`" section in the Yocto 983*4882a593Smuzhiyun Project Reference Manual for a complete list of image features that ship 984*4882a593Smuzhiyun with the Yocto Project. 985*4882a593Smuzhiyun 986*4882a593SmuzhiyunCustomizing Images Using Custom .bb Files 987*4882a593Smuzhiyun----------------------------------------- 988*4882a593Smuzhiyun 989*4882a593SmuzhiyunYou can also customize an image by creating a custom recipe that defines 990*4882a593Smuzhiyunadditional software as part of the image. The following example shows 991*4882a593Smuzhiyunthe form for the two lines you need:: 992*4882a593Smuzhiyun 993*4882a593Smuzhiyun IMAGE_INSTALL = "packagegroup-core-x11-base package1 package2" 994*4882a593Smuzhiyun inherit core-image 995*4882a593Smuzhiyun 996*4882a593SmuzhiyunDefining the software using a custom recipe gives you total control over 997*4882a593Smuzhiyunthe contents of the image. It is important to use the correct names of 998*4882a593Smuzhiyunpackages in the :term:`IMAGE_INSTALL` variable. You must use the 999*4882a593SmuzhiyunOpenEmbedded notation and not the Debian notation for the names (e.g. 1000*4882a593Smuzhiyun``glibc-dev`` instead of ``libc6-dev``). 1001*4882a593Smuzhiyun 1002*4882a593SmuzhiyunThe other method for creating a custom image is to base it on an 1003*4882a593Smuzhiyunexisting image. For example, if you want to create an image based on 1004*4882a593Smuzhiyun``core-image-sato`` but add the additional package ``strace`` to the 1005*4882a593Smuzhiyunimage, copy the ``meta/recipes-sato/images/core-image-sato.bb`` to a new 1006*4882a593Smuzhiyun``.bb`` and add the following line to the end of the copy:: 1007*4882a593Smuzhiyun 1008*4882a593Smuzhiyun IMAGE_INSTALL += "strace" 1009*4882a593Smuzhiyun 1010*4882a593SmuzhiyunCustomizing Images Using Custom Package Groups 1011*4882a593Smuzhiyun---------------------------------------------- 1012*4882a593Smuzhiyun 1013*4882a593SmuzhiyunFor complex custom images, the best approach for customizing an image is 1014*4882a593Smuzhiyunto create a custom package group recipe that is used to build the image 1015*4882a593Smuzhiyunor images. A good example of a package group recipe is 1016*4882a593Smuzhiyun``meta/recipes-core/packagegroups/packagegroup-base.bb``. 1017*4882a593Smuzhiyun 1018*4882a593SmuzhiyunIf you examine that recipe, you see that the :term:`PACKAGES` variable lists 1019*4882a593Smuzhiyunthe package group packages to produce. The ``inherit packagegroup`` 1020*4882a593Smuzhiyunstatement sets appropriate default values and automatically adds 1021*4882a593Smuzhiyun``-dev``, ``-dbg``, and ``-ptest`` complementary packages for each 1022*4882a593Smuzhiyunpackage specified in the :term:`PACKAGES` statement. 1023*4882a593Smuzhiyun 1024*4882a593Smuzhiyun.. note:: 1025*4882a593Smuzhiyun 1026*4882a593Smuzhiyun The ``inherit packagegroup`` line should be located near the top of the 1027*4882a593Smuzhiyun recipe, certainly before the :term:`PACKAGES` statement. 1028*4882a593Smuzhiyun 1029*4882a593SmuzhiyunFor each package you specify in :term:`PACKAGES`, you can use :term:`RDEPENDS` 1030*4882a593Smuzhiyunand :term:`RRECOMMENDS` entries to provide a list of packages the parent 1031*4882a593Smuzhiyuntask package should contain. You can see examples of these further down 1032*4882a593Smuzhiyunin the ``packagegroup-base.bb`` recipe. 1033*4882a593Smuzhiyun 1034*4882a593SmuzhiyunHere is a short, fabricated example showing the same basic pieces for a 1035*4882a593Smuzhiyunhypothetical packagegroup defined in ``packagegroup-custom.bb``, where 1036*4882a593Smuzhiyunthe variable :term:`PN` is the standard way to abbreviate the reference to 1037*4882a593Smuzhiyunthe full packagegroup name ``packagegroup-custom``:: 1038*4882a593Smuzhiyun 1039*4882a593Smuzhiyun DESCRIPTION = "My Custom Package Groups" 1040*4882a593Smuzhiyun 1041*4882a593Smuzhiyun inherit packagegroup 1042*4882a593Smuzhiyun 1043*4882a593Smuzhiyun PACKAGES = "\ 1044*4882a593Smuzhiyun ${PN}-apps \ 1045*4882a593Smuzhiyun ${PN}-tools \ 1046*4882a593Smuzhiyun " 1047*4882a593Smuzhiyun 1048*4882a593Smuzhiyun RDEPENDS:${PN}-apps = "\ 1049*4882a593Smuzhiyun dropbear \ 1050*4882a593Smuzhiyun portmap \ 1051*4882a593Smuzhiyun psplash" 1052*4882a593Smuzhiyun 1053*4882a593Smuzhiyun RDEPENDS:${PN}-tools = "\ 1054*4882a593Smuzhiyun oprofile \ 1055*4882a593Smuzhiyun oprofileui-server \ 1056*4882a593Smuzhiyun lttng-tools" 1057*4882a593Smuzhiyun 1058*4882a593Smuzhiyun RRECOMMENDS:${PN}-tools = "\ 1059*4882a593Smuzhiyun kernel-module-oprofile" 1060*4882a593Smuzhiyun 1061*4882a593SmuzhiyunIn the previous example, two package group packages are created with 1062*4882a593Smuzhiyuntheir dependencies and their recommended package dependencies listed: 1063*4882a593Smuzhiyun``packagegroup-custom-apps``, and ``packagegroup-custom-tools``. To 1064*4882a593Smuzhiyunbuild an image using these package group packages, you need to add 1065*4882a593Smuzhiyun``packagegroup-custom-apps`` and/or ``packagegroup-custom-tools`` to 1066*4882a593Smuzhiyun:term:`IMAGE_INSTALL`. For other forms of image dependencies see the other 1067*4882a593Smuzhiyunareas of this section. 1068*4882a593Smuzhiyun 1069*4882a593SmuzhiyunCustomizing an Image Hostname 1070*4882a593Smuzhiyun----------------------------- 1071*4882a593Smuzhiyun 1072*4882a593SmuzhiyunBy default, the configured hostname (i.e. ``/etc/hostname``) in an image 1073*4882a593Smuzhiyunis the same as the machine name. For example, if 1074*4882a593Smuzhiyun:term:`MACHINE` equals "qemux86", the 1075*4882a593Smuzhiyunconfigured hostname written to ``/etc/hostname`` is "qemux86". 1076*4882a593Smuzhiyun 1077*4882a593SmuzhiyunYou can customize this name by altering the value of the "hostname" 1078*4882a593Smuzhiyunvariable in the ``base-files`` recipe using either an append file or a 1079*4882a593Smuzhiyunconfiguration file. Use the following in an append file:: 1080*4882a593Smuzhiyun 1081*4882a593Smuzhiyun hostname = "myhostname" 1082*4882a593Smuzhiyun 1083*4882a593SmuzhiyunUse the following in a configuration file:: 1084*4882a593Smuzhiyun 1085*4882a593Smuzhiyun hostname:pn-base-files = "myhostname" 1086*4882a593Smuzhiyun 1087*4882a593SmuzhiyunChanging the default value of the variable "hostname" can be useful in 1088*4882a593Smuzhiyuncertain situations. For example, suppose you need to do extensive 1089*4882a593Smuzhiyuntesting on an image and you would like to easily identify the image 1090*4882a593Smuzhiyununder test from existing images with typical default hostnames. In this 1091*4882a593Smuzhiyunsituation, you could change the default hostname to "testme", which 1092*4882a593Smuzhiyunresults in all the images using the name "testme". Once testing is 1093*4882a593Smuzhiyuncomplete and you do not need to rebuild the image for test any longer, 1094*4882a593Smuzhiyunyou can easily reset the default hostname. 1095*4882a593Smuzhiyun 1096*4882a593SmuzhiyunAnother point of interest is that if you unset the variable, the image 1097*4882a593Smuzhiyunwill have no default hostname in the filesystem. Here is an example that 1098*4882a593Smuzhiyununsets the variable in a configuration file:: 1099*4882a593Smuzhiyun 1100*4882a593Smuzhiyun hostname:pn-base-files = "" 1101*4882a593Smuzhiyun 1102*4882a593SmuzhiyunHaving no default hostname in the filesystem is suitable for 1103*4882a593Smuzhiyunenvironments that use dynamic hostnames such as virtual machines. 1104*4882a593Smuzhiyun 1105*4882a593SmuzhiyunWriting a New Recipe 1106*4882a593Smuzhiyun==================== 1107*4882a593Smuzhiyun 1108*4882a593SmuzhiyunRecipes (``.bb`` files) are fundamental components in the Yocto Project 1109*4882a593Smuzhiyunenvironment. Each software component built by the OpenEmbedded build 1110*4882a593Smuzhiyunsystem requires a recipe to define the component. This section describes 1111*4882a593Smuzhiyunhow to create, write, and test a new recipe. 1112*4882a593Smuzhiyun 1113*4882a593Smuzhiyun.. note:: 1114*4882a593Smuzhiyun 1115*4882a593Smuzhiyun For information on variables that are useful for recipes and for 1116*4882a593Smuzhiyun information about recipe naming issues, see the 1117*4882a593Smuzhiyun ":ref:`ref-manual/varlocality:recipes`" section of the Yocto Project 1118*4882a593Smuzhiyun Reference Manual. 1119*4882a593Smuzhiyun 1120*4882a593SmuzhiyunOverview 1121*4882a593Smuzhiyun-------- 1122*4882a593Smuzhiyun 1123*4882a593SmuzhiyunThe following figure shows the basic process for creating a new recipe. 1124*4882a593SmuzhiyunThe remainder of the section provides details for the steps. 1125*4882a593Smuzhiyun 1126*4882a593Smuzhiyun.. image:: figures/recipe-workflow.png 1127*4882a593Smuzhiyun :align: center 1128*4882a593Smuzhiyun 1129*4882a593SmuzhiyunLocate or Automatically Create a Base Recipe 1130*4882a593Smuzhiyun-------------------------------------------- 1131*4882a593Smuzhiyun 1132*4882a593SmuzhiyunYou can always write a recipe from scratch. However, there are three choices 1133*4882a593Smuzhiyunthat can help you quickly get started with a new recipe: 1134*4882a593Smuzhiyun 1135*4882a593Smuzhiyun- ``devtool add``: A command that assists in creating a recipe and an 1136*4882a593Smuzhiyun environment conducive to development. 1137*4882a593Smuzhiyun 1138*4882a593Smuzhiyun- ``recipetool create``: A command provided by the Yocto Project that 1139*4882a593Smuzhiyun automates creation of a base recipe based on the source files. 1140*4882a593Smuzhiyun 1141*4882a593Smuzhiyun- *Existing Recipes:* Location and modification of an existing recipe 1142*4882a593Smuzhiyun that is similar in function to the recipe you need. 1143*4882a593Smuzhiyun 1144*4882a593Smuzhiyun.. note:: 1145*4882a593Smuzhiyun 1146*4882a593Smuzhiyun For information on recipe syntax, see the 1147*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:recipe syntax`" section. 1148*4882a593Smuzhiyun 1149*4882a593SmuzhiyunCreating the Base Recipe Using ``devtool add`` 1150*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1151*4882a593Smuzhiyun 1152*4882a593SmuzhiyunThe ``devtool add`` command uses the same logic for auto-creating the 1153*4882a593Smuzhiyunrecipe as ``recipetool create``, which is listed below. Additionally, 1154*4882a593Smuzhiyunhowever, ``devtool add`` sets up an environment that makes it easy for 1155*4882a593Smuzhiyunyou to patch the source and to make changes to the recipe as is often 1156*4882a593Smuzhiyunnecessary when adding a recipe to build a new piece of software to be 1157*4882a593Smuzhiyunincluded in a build. 1158*4882a593Smuzhiyun 1159*4882a593SmuzhiyunYou can find a complete description of the ``devtool add`` command in 1160*4882a593Smuzhiyunthe ":ref:`sdk-manual/extensible:a closer look at \`\`devtool add\`\``" section 1161*4882a593Smuzhiyunin the Yocto Project Application Development and the Extensible Software 1162*4882a593SmuzhiyunDevelopment Kit (eSDK) manual. 1163*4882a593Smuzhiyun 1164*4882a593SmuzhiyunCreating the Base Recipe Using ``recipetool create`` 1165*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1166*4882a593Smuzhiyun 1167*4882a593Smuzhiyun``recipetool create`` automates creation of a base recipe given a set of 1168*4882a593Smuzhiyunsource code files. As long as you can extract or point to the source 1169*4882a593Smuzhiyunfiles, the tool will construct a recipe and automatically configure all 1170*4882a593Smuzhiyunpre-build information into the recipe. For example, suppose you have an 1171*4882a593Smuzhiyunapplication that builds using Autotools. Creating the base recipe using 1172*4882a593Smuzhiyun``recipetool`` results in a recipe that has the pre-build dependencies, 1173*4882a593Smuzhiyunlicense requirements, and checksums configured. 1174*4882a593Smuzhiyun 1175*4882a593SmuzhiyunTo run the tool, you just need to be in your 1176*4882a593Smuzhiyun:term:`Build Directory` and have sourced the 1177*4882a593Smuzhiyunbuild environment setup script (i.e. 1178*4882a593Smuzhiyun:ref:`structure-core-script`). 1179*4882a593SmuzhiyunTo get help on the tool, use the following command:: 1180*4882a593Smuzhiyun 1181*4882a593Smuzhiyun $ recipetool -h 1182*4882a593Smuzhiyun NOTE: Starting bitbake server... 1183*4882a593Smuzhiyun usage: recipetool [-d] [-q] [--color COLOR] [-h] <subcommand> ... 1184*4882a593Smuzhiyun 1185*4882a593Smuzhiyun OpenEmbedded recipe tool 1186*4882a593Smuzhiyun 1187*4882a593Smuzhiyun options: 1188*4882a593Smuzhiyun -d, --debug Enable debug output 1189*4882a593Smuzhiyun -q, --quiet Print only errors 1190*4882a593Smuzhiyun --color COLOR Colorize output (where COLOR is auto, always, never) 1191*4882a593Smuzhiyun -h, --help show this help message and exit 1192*4882a593Smuzhiyun 1193*4882a593Smuzhiyun subcommands: 1194*4882a593Smuzhiyun create Create a new recipe 1195*4882a593Smuzhiyun newappend Create a bbappend for the specified target in the specified 1196*4882a593Smuzhiyun layer 1197*4882a593Smuzhiyun setvar Set a variable within a recipe 1198*4882a593Smuzhiyun appendfile Create/update a bbappend to replace a target file 1199*4882a593Smuzhiyun appendsrcfiles Create/update a bbappend to add or replace source files 1200*4882a593Smuzhiyun appendsrcfile Create/update a bbappend to add or replace a source file 1201*4882a593Smuzhiyun Use recipetool <subcommand> --help to get help on a specific command 1202*4882a593Smuzhiyun 1203*4882a593SmuzhiyunRunning ``recipetool create -o OUTFILE`` creates the base recipe and 1204*4882a593Smuzhiyunlocates it properly in the layer that contains your source files. 1205*4882a593SmuzhiyunFollowing are some syntax examples: 1206*4882a593Smuzhiyun 1207*4882a593Smuzhiyun - Use this syntax to generate a recipe based on source. Once generated, 1208*4882a593Smuzhiyun the recipe resides in the existing source code layer:: 1209*4882a593Smuzhiyun 1210*4882a593Smuzhiyun recipetool create -o OUTFILE source 1211*4882a593Smuzhiyun 1212*4882a593Smuzhiyun - Use this syntax to generate a recipe using code that 1213*4882a593Smuzhiyun you extract from source. The extracted code is placed in its own layer 1214*4882a593Smuzhiyun defined by :term:`EXTERNALSRC`. 1215*4882a593Smuzhiyun :: 1216*4882a593Smuzhiyun 1217*4882a593Smuzhiyun recipetool create -o OUTFILE -x EXTERNALSRC source 1218*4882a593Smuzhiyun 1219*4882a593Smuzhiyun - Use this syntax to generate a recipe based on source. The options 1220*4882a593Smuzhiyun direct ``recipetool`` to generate debugging information. Once generated, 1221*4882a593Smuzhiyun the recipe resides in the existing source code layer:: 1222*4882a593Smuzhiyun 1223*4882a593Smuzhiyun recipetool create -d -o OUTFILE source 1224*4882a593Smuzhiyun 1225*4882a593SmuzhiyunLocating and Using a Similar Recipe 1226*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1227*4882a593Smuzhiyun 1228*4882a593SmuzhiyunBefore writing a recipe from scratch, it is often useful to discover 1229*4882a593Smuzhiyunwhether someone else has already written one that meets (or comes close 1230*4882a593Smuzhiyunto meeting) your needs. The Yocto Project and OpenEmbedded communities 1231*4882a593Smuzhiyunmaintain many recipes that might be candidates for what you are doing. 1232*4882a593SmuzhiyunYou can find a good central index of these recipes in the 1233*4882a593Smuzhiyun:oe_layerindex:`OpenEmbedded Layer Index <>`. 1234*4882a593Smuzhiyun 1235*4882a593SmuzhiyunWorking from an existing recipe or a skeleton recipe is the best way to 1236*4882a593Smuzhiyunget started. Here are some points on both methods: 1237*4882a593Smuzhiyun 1238*4882a593Smuzhiyun- *Locate and modify a recipe that is close to what you want to do:* 1239*4882a593Smuzhiyun This method works when you are familiar with the current recipe 1240*4882a593Smuzhiyun space. The method does not work so well for those new to the Yocto 1241*4882a593Smuzhiyun Project or writing recipes. 1242*4882a593Smuzhiyun 1243*4882a593Smuzhiyun Some risks associated with this method are using a recipe that has 1244*4882a593Smuzhiyun areas totally unrelated to what you are trying to accomplish with 1245*4882a593Smuzhiyun your recipe, not recognizing areas of the recipe that you might have 1246*4882a593Smuzhiyun to add from scratch, and so forth. All these risks stem from 1247*4882a593Smuzhiyun unfamiliarity with the existing recipe space. 1248*4882a593Smuzhiyun 1249*4882a593Smuzhiyun- *Use and modify the following skeleton recipe:* If for some reason 1250*4882a593Smuzhiyun you do not want to use ``recipetool`` and you cannot find an existing 1251*4882a593Smuzhiyun recipe that is close to meeting your needs, you can use the following 1252*4882a593Smuzhiyun structure to provide the fundamental areas of a new recipe. 1253*4882a593Smuzhiyun :: 1254*4882a593Smuzhiyun 1255*4882a593Smuzhiyun DESCRIPTION = "" 1256*4882a593Smuzhiyun HOMEPAGE = "" 1257*4882a593Smuzhiyun LICENSE = "" 1258*4882a593Smuzhiyun SECTION = "" 1259*4882a593Smuzhiyun DEPENDS = "" 1260*4882a593Smuzhiyun LIC_FILES_CHKSUM = "" 1261*4882a593Smuzhiyun 1262*4882a593Smuzhiyun SRC_URI = "" 1263*4882a593Smuzhiyun 1264*4882a593SmuzhiyunStoring and Naming the Recipe 1265*4882a593Smuzhiyun----------------------------- 1266*4882a593Smuzhiyun 1267*4882a593SmuzhiyunOnce you have your base recipe, you should put it in your own layer and 1268*4882a593Smuzhiyunname it appropriately. Locating it correctly ensures that the 1269*4882a593SmuzhiyunOpenEmbedded build system can find it when you use BitBake to process 1270*4882a593Smuzhiyunthe recipe. 1271*4882a593Smuzhiyun 1272*4882a593Smuzhiyun- *Storing Your Recipe:* The OpenEmbedded build system locates your 1273*4882a593Smuzhiyun recipe through the layer's ``conf/layer.conf`` file and the 1274*4882a593Smuzhiyun :term:`BBFILES` variable. This 1275*4882a593Smuzhiyun variable sets up a path from which the build system can locate 1276*4882a593Smuzhiyun recipes. Here is the typical use:: 1277*4882a593Smuzhiyun 1278*4882a593Smuzhiyun BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \ 1279*4882a593Smuzhiyun ${LAYERDIR}/recipes-*/*/*.bbappend" 1280*4882a593Smuzhiyun 1281*4882a593Smuzhiyun Consequently, you need to be sure you locate your new recipe inside 1282*4882a593Smuzhiyun your layer such that it can be found. 1283*4882a593Smuzhiyun 1284*4882a593Smuzhiyun You can find more information on how layers are structured in the 1285*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:understanding and creating layers`" section. 1286*4882a593Smuzhiyun 1287*4882a593Smuzhiyun- *Naming Your Recipe:* When you name your recipe, you need to follow 1288*4882a593Smuzhiyun this naming convention:: 1289*4882a593Smuzhiyun 1290*4882a593Smuzhiyun basename_version.bb 1291*4882a593Smuzhiyun 1292*4882a593Smuzhiyun Use lower-cased characters and do not include the reserved suffixes 1293*4882a593Smuzhiyun ``-native``, ``-cross``, ``-initial``, or ``-dev`` casually (i.e. do not use 1294*4882a593Smuzhiyun them as part of your recipe name unless the string applies). Here are some 1295*4882a593Smuzhiyun examples: 1296*4882a593Smuzhiyun 1297*4882a593Smuzhiyun .. code-block:: none 1298*4882a593Smuzhiyun 1299*4882a593Smuzhiyun cups_1.7.0.bb 1300*4882a593Smuzhiyun gawk_4.0.2.bb 1301*4882a593Smuzhiyun irssi_0.8.16-rc1.bb 1302*4882a593Smuzhiyun 1303*4882a593SmuzhiyunRunning a Build on the Recipe 1304*4882a593Smuzhiyun----------------------------- 1305*4882a593Smuzhiyun 1306*4882a593SmuzhiyunCreating a new recipe is usually an iterative process that requires 1307*4882a593Smuzhiyunusing BitBake to process the recipe multiple times in order to 1308*4882a593Smuzhiyunprogressively discover and add information to the recipe file. 1309*4882a593Smuzhiyun 1310*4882a593SmuzhiyunAssuming you have sourced the build environment setup script (i.e. 1311*4882a593Smuzhiyun:ref:`structure-core-script`) and you are in 1312*4882a593Smuzhiyunthe :term:`Build Directory`, use 1313*4882a593SmuzhiyunBitBake to process your recipe. All you need to provide is the 1314*4882a593Smuzhiyun``basename`` of the recipe as described in the previous section:: 1315*4882a593Smuzhiyun 1316*4882a593Smuzhiyun $ bitbake basename 1317*4882a593Smuzhiyun 1318*4882a593SmuzhiyunDuring the build, the OpenEmbedded build system creates a temporary work 1319*4882a593Smuzhiyundirectory for each recipe 1320*4882a593Smuzhiyun(``${``\ :term:`WORKDIR`\ ``}``) 1321*4882a593Smuzhiyunwhere it keeps extracted source files, log files, intermediate 1322*4882a593Smuzhiyuncompilation and packaging files, and so forth. 1323*4882a593Smuzhiyun 1324*4882a593SmuzhiyunThe path to the per-recipe temporary work directory depends on the 1325*4882a593Smuzhiyuncontext in which it is being built. The quickest way to find this path 1326*4882a593Smuzhiyunis to have BitBake return it by running the following:: 1327*4882a593Smuzhiyun 1328*4882a593Smuzhiyun $ bitbake -e basename | grep ^WORKDIR= 1329*4882a593Smuzhiyun 1330*4882a593SmuzhiyunAs an example, assume a Source Directory 1331*4882a593Smuzhiyuntop-level folder named ``poky``, a default Build Directory at 1332*4882a593Smuzhiyun``poky/build``, and a ``qemux86-poky-linux`` machine target system. 1333*4882a593SmuzhiyunFurthermore, suppose your recipe is named ``foo_1.3.0.bb``. In this 1334*4882a593Smuzhiyuncase, the work directory the build system uses to build the package 1335*4882a593Smuzhiyunwould be as follows:: 1336*4882a593Smuzhiyun 1337*4882a593Smuzhiyun poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 1338*4882a593Smuzhiyun 1339*4882a593SmuzhiyunInside this directory you can find sub-directories such as ``image``, 1340*4882a593Smuzhiyun``packages-split``, and ``temp``. After the build, you can examine these 1341*4882a593Smuzhiyunto determine how well the build went. 1342*4882a593Smuzhiyun 1343*4882a593Smuzhiyun.. note:: 1344*4882a593Smuzhiyun 1345*4882a593Smuzhiyun You can find log files for each task in the recipe's ``temp`` 1346*4882a593Smuzhiyun directory (e.g. ``poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0/temp``). 1347*4882a593Smuzhiyun Log files are named ``log.taskname`` (e.g. ``log.do_configure``, 1348*4882a593Smuzhiyun ``log.do_fetch``, and ``log.do_compile``). 1349*4882a593Smuzhiyun 1350*4882a593SmuzhiyunYou can find more information about the build process in 1351*4882a593Smuzhiyun":doc:`/overview-manual/development-environment`" 1352*4882a593Smuzhiyunchapter of the Yocto Project Overview and Concepts Manual. 1353*4882a593Smuzhiyun 1354*4882a593SmuzhiyunFetching Code 1355*4882a593Smuzhiyun------------- 1356*4882a593Smuzhiyun 1357*4882a593SmuzhiyunThe first thing your recipe must do is specify how to fetch the source 1358*4882a593Smuzhiyunfiles. Fetching is controlled mainly through the 1359*4882a593Smuzhiyun:term:`SRC_URI` variable. Your recipe 1360*4882a593Smuzhiyunmust have a :term:`SRC_URI` variable that points to where the source is 1361*4882a593Smuzhiyunlocated. For a graphical representation of source locations, see the 1362*4882a593Smuzhiyun":ref:`overview-manual/concepts:sources`" section in 1363*4882a593Smuzhiyunthe Yocto Project Overview and Concepts Manual. 1364*4882a593Smuzhiyun 1365*4882a593SmuzhiyunThe :ref:`ref-tasks-fetch` task uses 1366*4882a593Smuzhiyunthe prefix of each entry in the :term:`SRC_URI` variable value to determine 1367*4882a593Smuzhiyunwhich :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>` to use to get your 1368*4882a593Smuzhiyunsource files. It is the :term:`SRC_URI` variable that triggers the fetcher. 1369*4882a593SmuzhiyunThe :ref:`ref-tasks-patch` task uses 1370*4882a593Smuzhiyunthe variable after source is fetched to apply patches. The OpenEmbedded 1371*4882a593Smuzhiyunbuild system uses 1372*4882a593Smuzhiyun:term:`FILESOVERRIDES` for 1373*4882a593Smuzhiyunscanning directory locations for local files in :term:`SRC_URI`. 1374*4882a593Smuzhiyun 1375*4882a593SmuzhiyunThe :term:`SRC_URI` variable in your recipe must define each unique location 1376*4882a593Smuzhiyunfor your source files. It is good practice to not hard-code version 1377*4882a593Smuzhiyunnumbers in a URL used in :term:`SRC_URI`. Rather than hard-code these 1378*4882a593Smuzhiyunvalues, use ``${``\ :term:`PV`\ ``}``, 1379*4882a593Smuzhiyunwhich causes the fetch process to use the version specified in the 1380*4882a593Smuzhiyunrecipe filename. Specifying the version in this manner means that 1381*4882a593Smuzhiyunupgrading the recipe to a future version is as simple as renaming the 1382*4882a593Smuzhiyunrecipe to match the new version. 1383*4882a593Smuzhiyun 1384*4882a593SmuzhiyunHere is a simple example from the 1385*4882a593Smuzhiyun``meta/recipes-devtools/strace/strace_5.5.bb`` recipe where the source 1386*4882a593Smuzhiyuncomes from a single tarball. Notice the use of the 1387*4882a593Smuzhiyun:term:`PV` variable:: 1388*4882a593Smuzhiyun 1389*4882a593Smuzhiyun SRC_URI = "https://strace.io/files/${PV}/strace-${PV}.tar.xz \ 1390*4882a593Smuzhiyun 1391*4882a593SmuzhiyunFiles mentioned in :term:`SRC_URI` whose names end in a typical archive 1392*4882a593Smuzhiyunextension (e.g. ``.tar``, ``.tar.gz``, ``.tar.bz2``, ``.zip``, and so 1393*4882a593Smuzhiyunforth), are automatically extracted during the 1394*4882a593Smuzhiyun:ref:`ref-tasks-unpack` task. For 1395*4882a593Smuzhiyunanother example that specifies these types of files, see the 1396*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:autotooled package`" section. 1397*4882a593Smuzhiyun 1398*4882a593SmuzhiyunAnother way of specifying source is from an SCM. For Git repositories, 1399*4882a593Smuzhiyunyou must specify :term:`SRCREV` and you should specify :term:`PV` to include 1400*4882a593Smuzhiyunthe revision with :term:`SRCPV`. Here is an example from the recipe 1401*4882a593Smuzhiyun``meta/recipes-core/musl/gcompat_git.bb``:: 1402*4882a593Smuzhiyun 1403*4882a593Smuzhiyun SRC_URI = "git://git.adelielinux.org/adelie/gcompat.git;protocol=https;branch=current" 1404*4882a593Smuzhiyun 1405*4882a593Smuzhiyun PV = "1.0.0+1.1+git${SRCPV}" 1406*4882a593Smuzhiyun SRCREV = "af5a49e489fdc04b9cf02547650d7aeaccd43793" 1407*4882a593Smuzhiyun 1408*4882a593SmuzhiyunIf your :term:`SRC_URI` statement includes URLs pointing to individual files 1409*4882a593Smuzhiyunfetched from a remote server other than a version control system, 1410*4882a593SmuzhiyunBitBake attempts to verify the files against checksums defined in your 1411*4882a593Smuzhiyunrecipe to ensure they have not been tampered with or otherwise modified 1412*4882a593Smuzhiyunsince the recipe was written. Two checksums are used: 1413*4882a593Smuzhiyun``SRC_URI[md5sum]`` and ``SRC_URI[sha256sum]``. 1414*4882a593Smuzhiyun 1415*4882a593SmuzhiyunIf your :term:`SRC_URI` variable points to more than a single URL (excluding 1416*4882a593SmuzhiyunSCM URLs), you need to provide the ``md5`` and ``sha256`` checksums for 1417*4882a593Smuzhiyuneach URL. For these cases, you provide a name for each URL as part of 1418*4882a593Smuzhiyunthe :term:`SRC_URI` and then reference that name in the subsequent checksum 1419*4882a593Smuzhiyunstatements. Here is an example combining lines from the files 1420*4882a593Smuzhiyun``git.inc`` and ``git_2.24.1.bb``:: 1421*4882a593Smuzhiyun 1422*4882a593Smuzhiyun SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \ 1423*4882a593Smuzhiyun ${KERNELORG_MIRROR}/software/scm/git/git-manpages-${PV}.tar.gz;name=manpages" 1424*4882a593Smuzhiyun 1425*4882a593Smuzhiyun SRC_URI[tarball.md5sum] = "166bde96adbbc11c8843d4f8f4f9811b" 1426*4882a593Smuzhiyun SRC_URI[tarball.sha256sum] = "ad5334956301c86841eb1e5b1bb20884a6bad89a10a6762c958220c7cf64da02" 1427*4882a593Smuzhiyun SRC_URI[manpages.md5sum] = "31c2272a8979022497ba3d4202df145d" 1428*4882a593Smuzhiyun SRC_URI[manpages.sha256sum] = "9a7ae3a093bea39770eb96ca3e5b40bff7af0b9f6123f089d7821d0e5b8e1230" 1429*4882a593Smuzhiyun 1430*4882a593SmuzhiyunProper values for ``md5`` and ``sha256`` checksums might be available 1431*4882a593Smuzhiyunwith other signatures on the download page for the upstream source (e.g. 1432*4882a593Smuzhiyun``md5``, ``sha1``, ``sha256``, ``GPG``, and so forth). Because the 1433*4882a593SmuzhiyunOpenEmbedded build system only deals with ``sha256sum`` and ``md5sum``, 1434*4882a593Smuzhiyunyou should verify all the signatures you find by hand. 1435*4882a593Smuzhiyun 1436*4882a593SmuzhiyunIf no :term:`SRC_URI` checksums are specified when you attempt to build the 1437*4882a593Smuzhiyunrecipe, or you provide an incorrect checksum, the build will produce an 1438*4882a593Smuzhiyunerror for each missing or incorrect checksum. As part of the error 1439*4882a593Smuzhiyunmessage, the build system provides the checksum string corresponding to 1440*4882a593Smuzhiyunthe fetched file. Once you have the correct checksums, you can copy and 1441*4882a593Smuzhiyunpaste them into your recipe and then run the build again to continue. 1442*4882a593Smuzhiyun 1443*4882a593Smuzhiyun.. note:: 1444*4882a593Smuzhiyun 1445*4882a593Smuzhiyun As mentioned, if the upstream source provides signatures for 1446*4882a593Smuzhiyun verifying the downloaded source code, you should verify those 1447*4882a593Smuzhiyun manually before setting the checksum values in the recipe and 1448*4882a593Smuzhiyun continuing with the build. 1449*4882a593Smuzhiyun 1450*4882a593SmuzhiyunThis final example is a bit more complicated and is from the 1451*4882a593Smuzhiyun``meta/recipes-sato/rxvt-unicode/rxvt-unicode_9.20.bb`` recipe. The 1452*4882a593Smuzhiyunexample's :term:`SRC_URI` statement identifies multiple files as the source 1453*4882a593Smuzhiyunfiles for the recipe: a tarball, a patch file, a desktop file, and an 1454*4882a593Smuzhiyunicon. 1455*4882a593Smuzhiyun:: 1456*4882a593Smuzhiyun 1457*4882a593Smuzhiyun SRC_URI = "http://dist.schmorp.de/rxvt-unicode/Attic/rxvt-unicode-${PV}.tar.bz2 \ 1458*4882a593Smuzhiyun file://xwc.patch \ 1459*4882a593Smuzhiyun file://rxvt.desktop \ 1460*4882a593Smuzhiyun file://rxvt.png" 1461*4882a593Smuzhiyun 1462*4882a593SmuzhiyunWhen you specify local files using the ``file://`` URI protocol, the 1463*4882a593Smuzhiyunbuild system fetches files from the local machine. The path is relative 1464*4882a593Smuzhiyunto the :term:`FILESPATH` variable 1465*4882a593Smuzhiyunand searches specific directories in a certain order: 1466*4882a593Smuzhiyun``${``\ :term:`BP`\ ``}``, 1467*4882a593Smuzhiyun``${``\ :term:`BPN`\ ``}``, and 1468*4882a593Smuzhiyun``files``. The directories are assumed to be subdirectories of the 1469*4882a593Smuzhiyundirectory in which the recipe or append file resides. For another 1470*4882a593Smuzhiyunexample that specifies these types of files, see the 1471*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:single .c file package (hello world!)`" section. 1472*4882a593Smuzhiyun 1473*4882a593SmuzhiyunThe previous example also specifies a patch file. Patch files are files 1474*4882a593Smuzhiyunwhose names usually end in ``.patch`` or ``.diff`` but can end with 1475*4882a593Smuzhiyuncompressed suffixes such as ``diff.gz`` and ``patch.bz2``, for example. 1476*4882a593SmuzhiyunThe build system automatically applies patches as described in the 1477*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:patching code`" section. 1478*4882a593Smuzhiyun 1479*4882a593SmuzhiyunFetching Code Through Firewalls 1480*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1481*4882a593Smuzhiyun 1482*4882a593SmuzhiyunSome users are behind firewalls and need to fetch code through a proxy. 1483*4882a593SmuzhiyunSee the ":doc:`/ref-manual/faq`" chapter for advice. 1484*4882a593Smuzhiyun 1485*4882a593SmuzhiyunLimiting the Number of Parallel Connections 1486*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1487*4882a593Smuzhiyun 1488*4882a593SmuzhiyunSome users are behind firewalls or use servers where the number of parallel 1489*4882a593Smuzhiyunconnections is limited. In such cases, you can limit the number of fetch 1490*4882a593Smuzhiyuntasks being run in parallel by adding the following to your ``local.conf`` 1491*4882a593Smuzhiyunfile:: 1492*4882a593Smuzhiyun 1493*4882a593Smuzhiyun do_fetch[number_threads] = "4" 1494*4882a593Smuzhiyun 1495*4882a593SmuzhiyunUnpacking Code 1496*4882a593Smuzhiyun-------------- 1497*4882a593Smuzhiyun 1498*4882a593SmuzhiyunDuring the build, the 1499*4882a593Smuzhiyun:ref:`ref-tasks-unpack` task unpacks 1500*4882a593Smuzhiyunthe source with ``${``\ :term:`S`\ ``}`` 1501*4882a593Smuzhiyunpointing to where it is unpacked. 1502*4882a593Smuzhiyun 1503*4882a593SmuzhiyunIf you are fetching your source files from an upstream source archived 1504*4882a593Smuzhiyuntarball and the tarball's internal structure matches the common 1505*4882a593Smuzhiyunconvention of a top-level subdirectory named 1506*4882a593Smuzhiyun``${``\ :term:`BPN`\ ``}-${``\ :term:`PV`\ ``}``, 1507*4882a593Smuzhiyunthen you do not need to set :term:`S`. However, if :term:`SRC_URI` specifies to 1508*4882a593Smuzhiyunfetch source from an archive that does not use this convention, or from 1509*4882a593Smuzhiyunan SCM like Git or Subversion, your recipe needs to define :term:`S`. 1510*4882a593Smuzhiyun 1511*4882a593SmuzhiyunIf processing your recipe using BitBake successfully unpacks the source 1512*4882a593Smuzhiyunfiles, you need to be sure that the directory pointed to by ``${S}`` 1513*4882a593Smuzhiyunmatches the structure of the source. 1514*4882a593Smuzhiyun 1515*4882a593SmuzhiyunPatching Code 1516*4882a593Smuzhiyun------------- 1517*4882a593Smuzhiyun 1518*4882a593SmuzhiyunSometimes it is necessary to patch code after it has been fetched. Any 1519*4882a593Smuzhiyunfiles mentioned in :term:`SRC_URI` whose names end in ``.patch`` or 1520*4882a593Smuzhiyun``.diff`` or compressed versions of these suffixes (e.g. ``diff.gz`` are 1521*4882a593Smuzhiyuntreated as patches. The 1522*4882a593Smuzhiyun:ref:`ref-tasks-patch` task 1523*4882a593Smuzhiyunautomatically applies these patches. 1524*4882a593Smuzhiyun 1525*4882a593SmuzhiyunThe build system should be able to apply patches with the "-p1" option 1526*4882a593Smuzhiyun(i.e. one directory level in the path will be stripped off). If your 1527*4882a593Smuzhiyunpatch needs to have more directory levels stripped off, specify the 1528*4882a593Smuzhiyunnumber of levels using the "striplevel" option in the :term:`SRC_URI` entry 1529*4882a593Smuzhiyunfor the patch. Alternatively, if your patch needs to be applied in a 1530*4882a593Smuzhiyunspecific subdirectory that is not specified in the patch file, use the 1531*4882a593Smuzhiyun"patchdir" option in the entry. 1532*4882a593Smuzhiyun 1533*4882a593SmuzhiyunAs with all local files referenced in 1534*4882a593Smuzhiyun:term:`SRC_URI` using ``file://``, 1535*4882a593Smuzhiyunyou should place patch files in a directory next to the recipe either 1536*4882a593Smuzhiyunnamed the same as the base name of the recipe 1537*4882a593Smuzhiyun(:term:`BP` and 1538*4882a593Smuzhiyun:term:`BPN`) or "files". 1539*4882a593Smuzhiyun 1540*4882a593SmuzhiyunLicensing 1541*4882a593Smuzhiyun--------- 1542*4882a593Smuzhiyun 1543*4882a593SmuzhiyunYour recipe needs to have both the 1544*4882a593Smuzhiyun:term:`LICENSE` and 1545*4882a593Smuzhiyun:term:`LIC_FILES_CHKSUM` 1546*4882a593Smuzhiyunvariables: 1547*4882a593Smuzhiyun 1548*4882a593Smuzhiyun- :term:`LICENSE`: This variable specifies the license for the software. 1549*4882a593Smuzhiyun If you do not know the license under which the software you are 1550*4882a593Smuzhiyun building is distributed, you should go to the source code and look 1551*4882a593Smuzhiyun for that information. Typical files containing this information 1552*4882a593Smuzhiyun include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could 1553*4882a593Smuzhiyun also find the information near the top of a source file. For example, 1554*4882a593Smuzhiyun given a piece of software licensed under the GNU General Public 1555*4882a593Smuzhiyun License version 2, you would set :term:`LICENSE` as follows:: 1556*4882a593Smuzhiyun 1557*4882a593Smuzhiyun LICENSE = "GPL-2.0-only" 1558*4882a593Smuzhiyun 1559*4882a593Smuzhiyun The licenses you specify within :term:`LICENSE` can have any name as long 1560*4882a593Smuzhiyun as you do not use spaces, since spaces are used as separators between 1561*4882a593Smuzhiyun license names. For standard licenses, use the names of the files in 1562*4882a593Smuzhiyun ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names 1563*4882a593Smuzhiyun defined in ``meta/conf/licenses.conf``. 1564*4882a593Smuzhiyun 1565*4882a593Smuzhiyun- :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this 1566*4882a593Smuzhiyun variable to make sure the license text has not changed. If it has, 1567*4882a593Smuzhiyun the build produces an error and it affords you the chance to figure 1568*4882a593Smuzhiyun it out and correct the problem. 1569*4882a593Smuzhiyun 1570*4882a593Smuzhiyun You need to specify all applicable licensing files for the software. 1571*4882a593Smuzhiyun At the end of the configuration step, the build process will compare 1572*4882a593Smuzhiyun the checksums of the files to be sure the text has not changed. Any 1573*4882a593Smuzhiyun differences result in an error with the message containing the 1574*4882a593Smuzhiyun current checksum. For more explanation and examples of how to set the 1575*4882a593Smuzhiyun :term:`LIC_FILES_CHKSUM` variable, see the 1576*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:tracking license changes`" section. 1577*4882a593Smuzhiyun 1578*4882a593Smuzhiyun To determine the correct checksum string, you can list the 1579*4882a593Smuzhiyun appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect 1580*4882a593Smuzhiyun md5 strings, attempt to build the software, and then note the 1581*4882a593Smuzhiyun resulting error messages that will report the correct md5 strings. 1582*4882a593Smuzhiyun See the ":ref:`dev-manual/common-tasks:fetching code`" section for 1583*4882a593Smuzhiyun additional information. 1584*4882a593Smuzhiyun 1585*4882a593Smuzhiyun Here is an example that assumes the software has a ``COPYING`` file:: 1586*4882a593Smuzhiyun 1587*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" 1588*4882a593Smuzhiyun 1589*4882a593Smuzhiyun When you try to build the 1590*4882a593Smuzhiyun software, the build system will produce an error and give you the 1591*4882a593Smuzhiyun correct string that you can substitute into the recipe file for a 1592*4882a593Smuzhiyun subsequent build. 1593*4882a593Smuzhiyun 1594*4882a593SmuzhiyunDependencies 1595*4882a593Smuzhiyun------------ 1596*4882a593Smuzhiyun 1597*4882a593SmuzhiyunMost software packages have a short list of other packages that they 1598*4882a593Smuzhiyunrequire, which are called dependencies. These dependencies fall into two 1599*4882a593Smuzhiyunmain categories: build-time dependencies, which are required when the 1600*4882a593Smuzhiyunsoftware is built; and runtime dependencies, which are required to be 1601*4882a593Smuzhiyuninstalled on the target in order for the software to run. 1602*4882a593Smuzhiyun 1603*4882a593SmuzhiyunWithin a recipe, you specify build-time dependencies using the 1604*4882a593Smuzhiyun:term:`DEPENDS` variable. Although there are nuances, 1605*4882a593Smuzhiyunitems specified in :term:`DEPENDS` should be names of other 1606*4882a593Smuzhiyunrecipes. It is important that you specify all build-time dependencies 1607*4882a593Smuzhiyunexplicitly. 1608*4882a593Smuzhiyun 1609*4882a593SmuzhiyunAnother consideration is that configure scripts might automatically 1610*4882a593Smuzhiyuncheck for optional dependencies and enable corresponding functionality 1611*4882a593Smuzhiyunif those dependencies are found. If you wish to make a recipe that is 1612*4882a593Smuzhiyunmore generally useful (e.g. publish the recipe in a layer for others to 1613*4882a593Smuzhiyunuse), instead of hard-disabling the functionality, you can use the 1614*4882a593Smuzhiyun:term:`PACKAGECONFIG` variable to allow functionality and the 1615*4882a593Smuzhiyuncorresponding dependencies to be enabled and disabled easily by other 1616*4882a593Smuzhiyunusers of the recipe. 1617*4882a593Smuzhiyun 1618*4882a593SmuzhiyunSimilar to build-time dependencies, you specify runtime dependencies 1619*4882a593Smuzhiyunthrough a variable - 1620*4882a593Smuzhiyun:term:`RDEPENDS`, which is 1621*4882a593Smuzhiyunpackage-specific. All variables that are package-specific need to have 1622*4882a593Smuzhiyunthe name of the package added to the end as an override. Since the main 1623*4882a593Smuzhiyunpackage for a recipe has the same name as the recipe, and the recipe's 1624*4882a593Smuzhiyunname can be found through the 1625*4882a593Smuzhiyun``${``\ :term:`PN`\ ``}`` variable, then 1626*4882a593Smuzhiyunyou specify the dependencies for the main package by setting 1627*4882a593Smuzhiyun``RDEPENDS:${PN}``. If the package were named ``${PN}-tools``, then you 1628*4882a593Smuzhiyunwould set ``RDEPENDS:${PN}-tools``, and so forth. 1629*4882a593Smuzhiyun 1630*4882a593SmuzhiyunSome runtime dependencies will be set automatically at packaging time. 1631*4882a593SmuzhiyunThese dependencies include any shared library dependencies (i.e. if a 1632*4882a593Smuzhiyunpackage "example" contains "libexample" and another package "mypackage" 1633*4882a593Smuzhiyuncontains a binary that links to "libexample" then the OpenEmbedded build 1634*4882a593Smuzhiyunsystem will automatically add a runtime dependency to "mypackage" on 1635*4882a593Smuzhiyun"example"). See the 1636*4882a593Smuzhiyun":ref:`overview-manual/concepts:automatically added runtime dependencies`" 1637*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual for further 1638*4882a593Smuzhiyundetails. 1639*4882a593Smuzhiyun 1640*4882a593SmuzhiyunConfiguring the Recipe 1641*4882a593Smuzhiyun---------------------- 1642*4882a593Smuzhiyun 1643*4882a593SmuzhiyunMost software provides some means of setting build-time configuration 1644*4882a593Smuzhiyunoptions before compilation. Typically, setting these options is 1645*4882a593Smuzhiyunaccomplished by running a configure script with options, or by modifying 1646*4882a593Smuzhiyuna build configuration file. 1647*4882a593Smuzhiyun 1648*4882a593Smuzhiyun.. note:: 1649*4882a593Smuzhiyun 1650*4882a593Smuzhiyun As of Yocto Project Release 1.7, some of the core recipes that 1651*4882a593Smuzhiyun package binary configuration scripts now disable the scripts due to 1652*4882a593Smuzhiyun the scripts previously requiring error-prone path substitution. The 1653*4882a593Smuzhiyun OpenEmbedded build system uses ``pkg-config`` now, which is much more 1654*4882a593Smuzhiyun robust. You can find a list of the ``*-config`` scripts that are disabled 1655*4882a593Smuzhiyun in the ":ref:`migration-1.7-binary-configuration-scripts-disabled`" section 1656*4882a593Smuzhiyun in the Yocto Project Reference Manual. 1657*4882a593Smuzhiyun 1658*4882a593SmuzhiyunA major part of build-time configuration is about checking for 1659*4882a593Smuzhiyunbuild-time dependencies and possibly enabling optional functionality as 1660*4882a593Smuzhiyuna result. You need to specify any build-time dependencies for the 1661*4882a593Smuzhiyunsoftware you are building in your recipe's 1662*4882a593Smuzhiyun:term:`DEPENDS` value, in terms of 1663*4882a593Smuzhiyunother recipes that satisfy those dependencies. You can often find 1664*4882a593Smuzhiyunbuild-time or runtime dependencies described in the software's 1665*4882a593Smuzhiyundocumentation. 1666*4882a593Smuzhiyun 1667*4882a593SmuzhiyunThe following list provides configuration items of note based on how 1668*4882a593Smuzhiyunyour software is built: 1669*4882a593Smuzhiyun 1670*4882a593Smuzhiyun- *Autotools:* If your source files have a ``configure.ac`` file, then 1671*4882a593Smuzhiyun your software is built using Autotools. If this is the case, you just 1672*4882a593Smuzhiyun need to modify the configuration. 1673*4882a593Smuzhiyun 1674*4882a593Smuzhiyun When using Autotools, your recipe needs to inherit the 1675*4882a593Smuzhiyun :ref:`autotools <ref-classes-autotools>` class 1676*4882a593Smuzhiyun and your recipe does not have to contain a 1677*4882a593Smuzhiyun :ref:`ref-tasks-configure` task. 1678*4882a593Smuzhiyun However, you might still want to make some adjustments. For example, 1679*4882a593Smuzhiyun you can set 1680*4882a593Smuzhiyun :term:`EXTRA_OECONF` or 1681*4882a593Smuzhiyun :term:`PACKAGECONFIG_CONFARGS` 1682*4882a593Smuzhiyun to pass any needed configure options that are specific to the recipe. 1683*4882a593Smuzhiyun 1684*4882a593Smuzhiyun- *CMake:* If your source files have a ``CMakeLists.txt`` file, then 1685*4882a593Smuzhiyun your software is built using CMake. If this is the case, you just 1686*4882a593Smuzhiyun need to modify the configuration. 1687*4882a593Smuzhiyun 1688*4882a593Smuzhiyun When you use CMake, your recipe needs to inherit the 1689*4882a593Smuzhiyun :ref:`cmake <ref-classes-cmake>` class and your 1690*4882a593Smuzhiyun recipe does not have to contain a 1691*4882a593Smuzhiyun :ref:`ref-tasks-configure` task. 1692*4882a593Smuzhiyun You can make some adjustments by setting 1693*4882a593Smuzhiyun :term:`EXTRA_OECMAKE` to 1694*4882a593Smuzhiyun pass any needed configure options that are specific to the recipe. 1695*4882a593Smuzhiyun 1696*4882a593Smuzhiyun .. note:: 1697*4882a593Smuzhiyun 1698*4882a593Smuzhiyun If you need to install one or more custom CMake toolchain files 1699*4882a593Smuzhiyun that are supplied by the application you are building, install the 1700*4882a593Smuzhiyun files to ``${D}${datadir}/cmake/Modules`` during ``do_install``. 1701*4882a593Smuzhiyun 1702*4882a593Smuzhiyun- *Other:* If your source files do not have a ``configure.ac`` or 1703*4882a593Smuzhiyun ``CMakeLists.txt`` file, then your software is built using some 1704*4882a593Smuzhiyun method other than Autotools or CMake. If this is the case, you 1705*4882a593Smuzhiyun normally need to provide a 1706*4882a593Smuzhiyun :ref:`ref-tasks-configure` task 1707*4882a593Smuzhiyun in your recipe unless, of course, there is nothing to configure. 1708*4882a593Smuzhiyun 1709*4882a593Smuzhiyun Even if your software is not being built by Autotools or CMake, you 1710*4882a593Smuzhiyun still might not need to deal with any configuration issues. You need 1711*4882a593Smuzhiyun to determine if configuration is even a required step. You might need 1712*4882a593Smuzhiyun to modify a Makefile or some configuration file used for the build to 1713*4882a593Smuzhiyun specify necessary build options. Or, perhaps you might need to run a 1714*4882a593Smuzhiyun provided, custom configure script with the appropriate options. 1715*4882a593Smuzhiyun 1716*4882a593Smuzhiyun For the case involving a custom configure script, you would run 1717*4882a593Smuzhiyun ``./configure --help`` and look for the options you need to set. 1718*4882a593Smuzhiyun 1719*4882a593SmuzhiyunOnce configuration succeeds, it is always good practice to look at the 1720*4882a593Smuzhiyun``log.do_configure`` file to ensure that the appropriate options have 1721*4882a593Smuzhiyunbeen enabled and no additional build-time dependencies need to be added 1722*4882a593Smuzhiyunto :term:`DEPENDS`. For example, if the configure script reports that it 1723*4882a593Smuzhiyunfound something not mentioned in :term:`DEPENDS`, or that it did not find 1724*4882a593Smuzhiyunsomething that it needed for some desired optional functionality, then 1725*4882a593Smuzhiyunyou would need to add those to :term:`DEPENDS`. Looking at the log might 1726*4882a593Smuzhiyunalso reveal items being checked for, enabled, or both that you do not 1727*4882a593Smuzhiyunwant, or items not being found that are in :term:`DEPENDS`, in which case 1728*4882a593Smuzhiyunyou would need to look at passing extra options to the configure script 1729*4882a593Smuzhiyunas needed. For reference information on configure options specific to 1730*4882a593Smuzhiyunthe software you are building, you can consult the output of the 1731*4882a593Smuzhiyun``./configure --help`` command within ``${S}`` or consult the software's 1732*4882a593Smuzhiyunupstream documentation. 1733*4882a593Smuzhiyun 1734*4882a593SmuzhiyunUsing Headers to Interface with Devices 1735*4882a593Smuzhiyun--------------------------------------- 1736*4882a593Smuzhiyun 1737*4882a593SmuzhiyunIf your recipe builds an application that needs to communicate with some 1738*4882a593Smuzhiyundevice or needs an API into a custom kernel, you will need to provide 1739*4882a593Smuzhiyunappropriate header files. Under no circumstances should you ever modify 1740*4882a593Smuzhiyunthe existing 1741*4882a593Smuzhiyun``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc`` file. 1742*4882a593SmuzhiyunThese headers are used to build ``libc`` and must not be compromised 1743*4882a593Smuzhiyunwith custom or machine-specific header information. If you customize 1744*4882a593Smuzhiyun``libc`` through modified headers all other applications that use 1745*4882a593Smuzhiyun``libc`` thus become affected. 1746*4882a593Smuzhiyun 1747*4882a593Smuzhiyun.. note:: 1748*4882a593Smuzhiyun 1749*4882a593Smuzhiyun Never copy and customize the ``libc`` header file (i.e. 1750*4882a593Smuzhiyun ``meta/recipes-kernel/linux-libc-headers/linux-libc-headers.inc``). 1751*4882a593Smuzhiyun 1752*4882a593SmuzhiyunThe correct way to interface to a device or custom kernel is to use a 1753*4882a593Smuzhiyunseparate package that provides the additional headers for the driver or 1754*4882a593Smuzhiyunother unique interfaces. When doing so, your application also becomes 1755*4882a593Smuzhiyunresponsible for creating a dependency on that specific provider. 1756*4882a593Smuzhiyun 1757*4882a593SmuzhiyunConsider the following: 1758*4882a593Smuzhiyun 1759*4882a593Smuzhiyun- Never modify ``linux-libc-headers.inc``. Consider that file to be 1760*4882a593Smuzhiyun part of the ``libc`` system, and not something you use to access the 1761*4882a593Smuzhiyun kernel directly. You should access ``libc`` through specific ``libc`` 1762*4882a593Smuzhiyun calls. 1763*4882a593Smuzhiyun 1764*4882a593Smuzhiyun- Applications that must talk directly to devices should either provide 1765*4882a593Smuzhiyun necessary headers themselves, or establish a dependency on a special 1766*4882a593Smuzhiyun headers package that is specific to that driver. 1767*4882a593Smuzhiyun 1768*4882a593SmuzhiyunFor example, suppose you want to modify an existing header that adds I/O 1769*4882a593Smuzhiyuncontrol or network support. If the modifications are used by a small 1770*4882a593Smuzhiyunnumber programs, providing a unique version of a header is easy and has 1771*4882a593Smuzhiyunlittle impact. When doing so, bear in mind the guidelines in the 1772*4882a593Smuzhiyunprevious list. 1773*4882a593Smuzhiyun 1774*4882a593Smuzhiyun.. note:: 1775*4882a593Smuzhiyun 1776*4882a593Smuzhiyun If for some reason your changes need to modify the behavior of the ``libc``, 1777*4882a593Smuzhiyun and subsequently all other applications on the system, use a ``.bbappend`` 1778*4882a593Smuzhiyun to modify the ``linux-kernel-headers.inc`` file. However, take care to not 1779*4882a593Smuzhiyun make the changes machine specific. 1780*4882a593Smuzhiyun 1781*4882a593SmuzhiyunConsider a case where your kernel is older and you need an older 1782*4882a593Smuzhiyun``libc`` ABI. The headers installed by your recipe should still be a 1783*4882a593Smuzhiyunstandard mainline kernel, not your own custom one. 1784*4882a593Smuzhiyun 1785*4882a593SmuzhiyunWhen you use custom kernel headers you need to get them from 1786*4882a593Smuzhiyun:term:`STAGING_KERNEL_DIR`, 1787*4882a593Smuzhiyunwhich is the directory with kernel headers that are required to build 1788*4882a593Smuzhiyunout-of-tree modules. Your recipe will also need the following:: 1789*4882a593Smuzhiyun 1790*4882a593Smuzhiyun do_configure[depends] += "virtual/kernel:do_shared_workdir" 1791*4882a593Smuzhiyun 1792*4882a593SmuzhiyunCompilation 1793*4882a593Smuzhiyun----------- 1794*4882a593Smuzhiyun 1795*4882a593SmuzhiyunDuring a build, the ``do_compile`` task happens after source is fetched, 1796*4882a593Smuzhiyununpacked, and configured. If the recipe passes through ``do_compile`` 1797*4882a593Smuzhiyunsuccessfully, nothing needs to be done. 1798*4882a593Smuzhiyun 1799*4882a593SmuzhiyunHowever, if the compile step fails, you need to diagnose the failure. 1800*4882a593SmuzhiyunHere are some common issues that cause failures. 1801*4882a593Smuzhiyun 1802*4882a593Smuzhiyun.. note:: 1803*4882a593Smuzhiyun 1804*4882a593Smuzhiyun For cases where improper paths are detected for configuration files 1805*4882a593Smuzhiyun or for when libraries/headers cannot be found, be sure you are using 1806*4882a593Smuzhiyun the more robust ``pkg-config``. See the note in section 1807*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:Configuring the Recipe`" for additional information. 1808*4882a593Smuzhiyun 1809*4882a593Smuzhiyun- *Parallel build failures:* These failures manifest themselves as 1810*4882a593Smuzhiyun intermittent errors, or errors reporting that a file or directory 1811*4882a593Smuzhiyun that should be created by some other part of the build process could 1812*4882a593Smuzhiyun not be found. This type of failure can occur even if, upon 1813*4882a593Smuzhiyun inspection, the file or directory does exist after the build has 1814*4882a593Smuzhiyun failed, because that part of the build process happened in the wrong 1815*4882a593Smuzhiyun order. 1816*4882a593Smuzhiyun 1817*4882a593Smuzhiyun To fix the problem, you need to either satisfy the missing dependency 1818*4882a593Smuzhiyun in the Makefile or whatever script produced the Makefile, or (as a 1819*4882a593Smuzhiyun workaround) set :term:`PARALLEL_MAKE` to an empty string:: 1820*4882a593Smuzhiyun 1821*4882a593Smuzhiyun PARALLEL_MAKE = "" 1822*4882a593Smuzhiyun 1823*4882a593Smuzhiyun For information on parallel Makefile issues, see the 1824*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:debugging parallel make races`" section. 1825*4882a593Smuzhiyun 1826*4882a593Smuzhiyun- *Improper host path usage:* This failure applies to recipes building 1827*4882a593Smuzhiyun for the target or ``nativesdk`` only. The failure occurs when the 1828*4882a593Smuzhiyun compilation process uses improper headers, libraries, or other files 1829*4882a593Smuzhiyun from the host system when cross-compiling for the target. 1830*4882a593Smuzhiyun 1831*4882a593Smuzhiyun To fix the problem, examine the ``log.do_compile`` file to identify 1832*4882a593Smuzhiyun the host paths being used (e.g. ``/usr/include``, ``/usr/lib``, and 1833*4882a593Smuzhiyun so forth) and then either add configure options, apply a patch, or do 1834*4882a593Smuzhiyun both. 1835*4882a593Smuzhiyun 1836*4882a593Smuzhiyun- *Failure to find required libraries/headers:* If a build-time 1837*4882a593Smuzhiyun dependency is missing because it has not been declared in 1838*4882a593Smuzhiyun :term:`DEPENDS`, or because the 1839*4882a593Smuzhiyun dependency exists but the path used by the build process to find the 1840*4882a593Smuzhiyun file is incorrect and the configure step did not detect it, the 1841*4882a593Smuzhiyun compilation process could fail. For either of these failures, the 1842*4882a593Smuzhiyun compilation process notes that files could not be found. In these 1843*4882a593Smuzhiyun cases, you need to go back and add additional options to the 1844*4882a593Smuzhiyun configure script as well as possibly add additional build-time 1845*4882a593Smuzhiyun dependencies to :term:`DEPENDS`. 1846*4882a593Smuzhiyun 1847*4882a593Smuzhiyun Occasionally, it is necessary to apply a patch to the source to 1848*4882a593Smuzhiyun ensure the correct paths are used. If you need to specify paths to 1849*4882a593Smuzhiyun find files staged into the sysroot from other recipes, use the 1850*4882a593Smuzhiyun variables that the OpenEmbedded build system provides (e.g. 1851*4882a593Smuzhiyun :term:`STAGING_BINDIR`, :term:`STAGING_INCDIR`, :term:`STAGING_DATADIR`, and so 1852*4882a593Smuzhiyun forth). 1853*4882a593Smuzhiyun 1854*4882a593SmuzhiyunInstalling 1855*4882a593Smuzhiyun---------- 1856*4882a593Smuzhiyun 1857*4882a593SmuzhiyunDuring ``do_install``, the task copies the built files along with their 1858*4882a593Smuzhiyunhierarchy to locations that would mirror their locations on the target 1859*4882a593Smuzhiyundevice. The installation process copies files from the 1860*4882a593Smuzhiyun``${``\ :term:`S`\ ``}``, 1861*4882a593Smuzhiyun``${``\ :term:`B`\ ``}``, and 1862*4882a593Smuzhiyun``${``\ :term:`WORKDIR`\ ``}`` 1863*4882a593Smuzhiyundirectories to the ``${``\ :term:`D`\ ``}`` 1864*4882a593Smuzhiyundirectory to create the structure as it should appear on the target 1865*4882a593Smuzhiyunsystem. 1866*4882a593Smuzhiyun 1867*4882a593SmuzhiyunHow your software is built affects what you must do to be sure your 1868*4882a593Smuzhiyunsoftware is installed correctly. The following list describes what you 1869*4882a593Smuzhiyunmust do for installation depending on the type of build system used by 1870*4882a593Smuzhiyunthe software being built: 1871*4882a593Smuzhiyun 1872*4882a593Smuzhiyun- *Autotools and CMake:* If the software your recipe is building uses 1873*4882a593Smuzhiyun Autotools or CMake, the OpenEmbedded build system understands how to 1874*4882a593Smuzhiyun install the software. Consequently, you do not have to have a 1875*4882a593Smuzhiyun ``do_install`` task as part of your recipe. You just need to make 1876*4882a593Smuzhiyun sure the install portion of the build completes with no issues. 1877*4882a593Smuzhiyun However, if you wish to install additional files not already being 1878*4882a593Smuzhiyun installed by ``make install``, you should do this using a 1879*4882a593Smuzhiyun ``do_install:append`` function using the install command as described 1880*4882a593Smuzhiyun in the "Manual" bulleted item later in this list. 1881*4882a593Smuzhiyun 1882*4882a593Smuzhiyun- *Other (using* ``make install``\ *)*: You need to define a ``do_install`` 1883*4882a593Smuzhiyun function in your recipe. The function should call 1884*4882a593Smuzhiyun ``oe_runmake install`` and will likely need to pass in the 1885*4882a593Smuzhiyun destination directory as well. How you pass that path is dependent on 1886*4882a593Smuzhiyun how the ``Makefile`` being run is written (e.g. ``DESTDIR=${D}``, 1887*4882a593Smuzhiyun ``PREFIX=${D}``, ``INSTALLROOT=${D}``, and so forth). 1888*4882a593Smuzhiyun 1889*4882a593Smuzhiyun For an example recipe using ``make install``, see the 1890*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:makefile-based package`" section. 1891*4882a593Smuzhiyun 1892*4882a593Smuzhiyun- *Manual:* You need to define a ``do_install`` function in your 1893*4882a593Smuzhiyun recipe. The function must first use ``install -d`` to create the 1894*4882a593Smuzhiyun directories under 1895*4882a593Smuzhiyun ``${``\ :term:`D`\ ``}``. Once the 1896*4882a593Smuzhiyun directories exist, your function can use ``install`` to manually 1897*4882a593Smuzhiyun install the built software into the directories. 1898*4882a593Smuzhiyun 1899*4882a593Smuzhiyun You can find more information on ``install`` at 1900*4882a593Smuzhiyun https://www.gnu.org/software/coreutils/manual/html_node/install-invocation.html. 1901*4882a593Smuzhiyun 1902*4882a593SmuzhiyunFor the scenarios that do not use Autotools or CMake, you need to track 1903*4882a593Smuzhiyunthe installation and diagnose and fix any issues until everything 1904*4882a593Smuzhiyuninstalls correctly. You need to look in the default location of 1905*4882a593Smuzhiyun``${D}``, which is ``${WORKDIR}/image``, to be sure your files have been 1906*4882a593Smuzhiyuninstalled correctly. 1907*4882a593Smuzhiyun 1908*4882a593Smuzhiyun.. note:: 1909*4882a593Smuzhiyun 1910*4882a593Smuzhiyun - During the installation process, you might need to modify some of 1911*4882a593Smuzhiyun the installed files to suit the target layout. For example, you 1912*4882a593Smuzhiyun might need to replace hard-coded paths in an initscript with 1913*4882a593Smuzhiyun values of variables provided by the build system, such as 1914*4882a593Smuzhiyun replacing ``/usr/bin/`` with ``${bindir}``. If you do perform such 1915*4882a593Smuzhiyun modifications during ``do_install``, be sure to modify the 1916*4882a593Smuzhiyun destination file after copying rather than before copying. 1917*4882a593Smuzhiyun Modifying after copying ensures that the build system can 1918*4882a593Smuzhiyun re-execute ``do_install`` if needed. 1919*4882a593Smuzhiyun 1920*4882a593Smuzhiyun - ``oe_runmake install``, which can be run directly or can be run 1921*4882a593Smuzhiyun indirectly by the 1922*4882a593Smuzhiyun :ref:`autotools <ref-classes-autotools>` and 1923*4882a593Smuzhiyun :ref:`cmake <ref-classes-cmake>` classes, 1924*4882a593Smuzhiyun runs ``make install`` in parallel. Sometimes, a Makefile can have 1925*4882a593Smuzhiyun missing dependencies between targets that can result in race 1926*4882a593Smuzhiyun conditions. If you experience intermittent failures during 1927*4882a593Smuzhiyun ``do_install``, you might be able to work around them by disabling 1928*4882a593Smuzhiyun parallel Makefile installs by adding the following to the recipe:: 1929*4882a593Smuzhiyun 1930*4882a593Smuzhiyun PARALLEL_MAKEINST = "" 1931*4882a593Smuzhiyun 1932*4882a593Smuzhiyun See :term:`PARALLEL_MAKEINST` for additional information. 1933*4882a593Smuzhiyun 1934*4882a593Smuzhiyun - If you need to install one or more custom CMake toolchain files 1935*4882a593Smuzhiyun that are supplied by the application you are building, install the 1936*4882a593Smuzhiyun files to ``${D}${datadir}/cmake/Modules`` during 1937*4882a593Smuzhiyun :ref:`ref-tasks-install`. 1938*4882a593Smuzhiyun 1939*4882a593SmuzhiyunEnabling System Services 1940*4882a593Smuzhiyun------------------------ 1941*4882a593Smuzhiyun 1942*4882a593SmuzhiyunIf you want to install a service, which is a process that usually starts 1943*4882a593Smuzhiyunon boot and runs in the background, then you must include some 1944*4882a593Smuzhiyunadditional definitions in your recipe. 1945*4882a593Smuzhiyun 1946*4882a593SmuzhiyunIf you are adding services and the service initialization script or the 1947*4882a593Smuzhiyunservice file itself is not installed, you must provide for that 1948*4882a593Smuzhiyuninstallation in your recipe using a ``do_install:append`` function. If 1949*4882a593Smuzhiyunyour recipe already has a ``do_install`` function, update the function 1950*4882a593Smuzhiyunnear its end rather than adding an additional ``do_install:append`` 1951*4882a593Smuzhiyunfunction. 1952*4882a593Smuzhiyun 1953*4882a593SmuzhiyunWhen you create the installation for your services, you need to 1954*4882a593Smuzhiyunaccomplish what is normally done by ``make install``. In other words, 1955*4882a593Smuzhiyunmake sure your installation arranges the output similar to how it is 1956*4882a593Smuzhiyunarranged on the target system. 1957*4882a593Smuzhiyun 1958*4882a593SmuzhiyunThe OpenEmbedded build system provides support for starting services two 1959*4882a593Smuzhiyundifferent ways: 1960*4882a593Smuzhiyun 1961*4882a593Smuzhiyun- *SysVinit:* SysVinit is a system and service manager that manages the 1962*4882a593Smuzhiyun init system used to control the very basic functions of your system. 1963*4882a593Smuzhiyun The init program is the first program started by the Linux kernel 1964*4882a593Smuzhiyun when the system boots. Init then controls the startup, running and 1965*4882a593Smuzhiyun shutdown of all other programs. 1966*4882a593Smuzhiyun 1967*4882a593Smuzhiyun To enable a service using SysVinit, your recipe needs to inherit the 1968*4882a593Smuzhiyun :ref:`update-rc.d <ref-classes-update-rc.d>` 1969*4882a593Smuzhiyun class. The class helps facilitate safely installing the package on 1970*4882a593Smuzhiyun the target. 1971*4882a593Smuzhiyun 1972*4882a593Smuzhiyun You will need to set the 1973*4882a593Smuzhiyun :term:`INITSCRIPT_PACKAGES`, 1974*4882a593Smuzhiyun :term:`INITSCRIPT_NAME`, 1975*4882a593Smuzhiyun and 1976*4882a593Smuzhiyun :term:`INITSCRIPT_PARAMS` 1977*4882a593Smuzhiyun variables within your recipe. 1978*4882a593Smuzhiyun 1979*4882a593Smuzhiyun- *systemd:* System Management Daemon (systemd) was designed to replace 1980*4882a593Smuzhiyun SysVinit and to provide enhanced management of services. For more 1981*4882a593Smuzhiyun information on systemd, see the systemd homepage at 1982*4882a593Smuzhiyun https://freedesktop.org/wiki/Software/systemd/. 1983*4882a593Smuzhiyun 1984*4882a593Smuzhiyun To enable a service using systemd, your recipe needs to inherit the 1985*4882a593Smuzhiyun :ref:`systemd <ref-classes-systemd>` class. See 1986*4882a593Smuzhiyun the ``systemd.bbclass`` file located in your :term:`Source Directory` 1987*4882a593Smuzhiyun section for 1988*4882a593Smuzhiyun more information. 1989*4882a593Smuzhiyun 1990*4882a593SmuzhiyunPackaging 1991*4882a593Smuzhiyun--------- 1992*4882a593Smuzhiyun 1993*4882a593SmuzhiyunSuccessful packaging is a combination of automated processes performed 1994*4882a593Smuzhiyunby the OpenEmbedded build system and some specific steps you need to 1995*4882a593Smuzhiyuntake. The following list describes the process: 1996*4882a593Smuzhiyun 1997*4882a593Smuzhiyun- *Splitting Files*: The ``do_package`` task splits the files produced 1998*4882a593Smuzhiyun by the recipe into logical components. Even software that produces a 1999*4882a593Smuzhiyun single binary might still have debug symbols, documentation, and 2000*4882a593Smuzhiyun other logical components that should be split out. The ``do_package`` 2001*4882a593Smuzhiyun task ensures that files are split up and packaged correctly. 2002*4882a593Smuzhiyun 2003*4882a593Smuzhiyun- *Running QA Checks*: The 2004*4882a593Smuzhiyun :ref:`insane <ref-classes-insane>` class adds a 2005*4882a593Smuzhiyun step to the package generation process so that output quality 2006*4882a593Smuzhiyun assurance checks are generated by the OpenEmbedded build system. This 2007*4882a593Smuzhiyun step performs a range of checks to be sure the build's output is free 2008*4882a593Smuzhiyun of common problems that show up during runtime. For information on 2009*4882a593Smuzhiyun these checks, see the 2010*4882a593Smuzhiyun :ref:`insane <ref-classes-insane>` class and 2011*4882a593Smuzhiyun the ":ref:`ref-manual/qa-checks:qa error and warning messages`" 2012*4882a593Smuzhiyun chapter in the Yocto Project Reference Manual. 2013*4882a593Smuzhiyun 2014*4882a593Smuzhiyun- *Hand-Checking Your Packages*: After you build your software, you 2015*4882a593Smuzhiyun need to be sure your packages are correct. Examine the 2016*4882a593Smuzhiyun ``${``\ :term:`WORKDIR`\ ``}/packages-split`` 2017*4882a593Smuzhiyun directory and make sure files are where you expect them to be. If you 2018*4882a593Smuzhiyun discover problems, you can set 2019*4882a593Smuzhiyun :term:`PACKAGES`, 2020*4882a593Smuzhiyun :term:`FILES`, 2021*4882a593Smuzhiyun ``do_install(:append)``, and so forth as needed. 2022*4882a593Smuzhiyun 2023*4882a593Smuzhiyun- *Splitting an Application into Multiple Packages*: If you need to 2024*4882a593Smuzhiyun split an application into several packages, see the 2025*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:splitting an application into multiple packages`" 2026*4882a593Smuzhiyun section for an example. 2027*4882a593Smuzhiyun 2028*4882a593Smuzhiyun- *Installing a Post-Installation Script*: For an example showing how 2029*4882a593Smuzhiyun to install a post-installation script, see the 2030*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:post-installation scripts`" section. 2031*4882a593Smuzhiyun 2032*4882a593Smuzhiyun- *Marking Package Architecture*: Depending on what your recipe is 2033*4882a593Smuzhiyun building and how it is configured, it might be important to mark the 2034*4882a593Smuzhiyun packages produced as being specific to a particular machine, or to 2035*4882a593Smuzhiyun mark them as not being specific to a particular machine or 2036*4882a593Smuzhiyun architecture at all. 2037*4882a593Smuzhiyun 2038*4882a593Smuzhiyun By default, packages apply to any machine with the same architecture 2039*4882a593Smuzhiyun as the target machine. When a recipe produces packages that are 2040*4882a593Smuzhiyun machine-specific (e.g. the 2041*4882a593Smuzhiyun :term:`MACHINE` value is passed 2042*4882a593Smuzhiyun into the configure script or a patch is applied only for a particular 2043*4882a593Smuzhiyun machine), you should mark them as such by adding the following to the 2044*4882a593Smuzhiyun recipe:: 2045*4882a593Smuzhiyun 2046*4882a593Smuzhiyun PACKAGE_ARCH = "${MACHINE_ARCH}" 2047*4882a593Smuzhiyun 2048*4882a593Smuzhiyun On the other hand, if the recipe produces packages that do not 2049*4882a593Smuzhiyun contain anything specific to the target machine or architecture at 2050*4882a593Smuzhiyun all (e.g. recipes that simply package script files or configuration 2051*4882a593Smuzhiyun files), you should use the 2052*4882a593Smuzhiyun :ref:`allarch <ref-classes-allarch>` class to 2053*4882a593Smuzhiyun do this for you by adding this to your recipe:: 2054*4882a593Smuzhiyun 2055*4882a593Smuzhiyun inherit allarch 2056*4882a593Smuzhiyun 2057*4882a593Smuzhiyun Ensuring that the package architecture is correct is not critical 2058*4882a593Smuzhiyun while you are doing the first few builds of your recipe. However, it 2059*4882a593Smuzhiyun is important in order to ensure that your recipe rebuilds (or does 2060*4882a593Smuzhiyun not rebuild) appropriately in response to changes in configuration, 2061*4882a593Smuzhiyun and to ensure that you get the appropriate packages installed on the 2062*4882a593Smuzhiyun target machine, particularly if you run separate builds for more than 2063*4882a593Smuzhiyun one target machine. 2064*4882a593Smuzhiyun 2065*4882a593SmuzhiyunSharing Files Between Recipes 2066*4882a593Smuzhiyun----------------------------- 2067*4882a593Smuzhiyun 2068*4882a593SmuzhiyunRecipes often need to use files provided by other recipes on the build 2069*4882a593Smuzhiyunhost. For example, an application linking to a common library needs 2070*4882a593Smuzhiyunaccess to the library itself and its associated headers. The way this 2071*4882a593Smuzhiyunaccess is accomplished is by populating a sysroot with files. Each 2072*4882a593Smuzhiyunrecipe has two sysroots in its work directory, one for target files 2073*4882a593Smuzhiyun(``recipe-sysroot``) and one for files that are native to the build host 2074*4882a593Smuzhiyun(``recipe-sysroot-native``). 2075*4882a593Smuzhiyun 2076*4882a593Smuzhiyun.. note:: 2077*4882a593Smuzhiyun 2078*4882a593Smuzhiyun You could find the term "staging" used within the Yocto project 2079*4882a593Smuzhiyun regarding files populating sysroots (e.g. the :term:`STAGING_DIR` 2080*4882a593Smuzhiyun variable). 2081*4882a593Smuzhiyun 2082*4882a593SmuzhiyunRecipes should never populate the sysroot directly (i.e. write files 2083*4882a593Smuzhiyuninto sysroot). Instead, files should be installed into standard 2084*4882a593Smuzhiyunlocations during the 2085*4882a593Smuzhiyun:ref:`ref-tasks-install` task within 2086*4882a593Smuzhiyunthe ``${``\ :term:`D`\ ``}`` directory. The 2087*4882a593Smuzhiyunreason for this limitation is that almost all files that populate the 2088*4882a593Smuzhiyunsysroot are cataloged in manifests in order to ensure the files can be 2089*4882a593Smuzhiyunremoved later when a recipe is either modified or removed. Thus, the 2090*4882a593Smuzhiyunsysroot is able to remain free from stale files. 2091*4882a593Smuzhiyun 2092*4882a593SmuzhiyunA subset of the files installed by the :ref:`ref-tasks-install` task are 2093*4882a593Smuzhiyunused by the :ref:`ref-tasks-populate_sysroot` task as defined by the the 2094*4882a593Smuzhiyun:term:`SYSROOT_DIRS` variable to automatically populate the sysroot. It 2095*4882a593Smuzhiyunis possible to modify the list of directories that populate the sysroot. 2096*4882a593SmuzhiyunThe following example shows how you could add the ``/opt`` directory to 2097*4882a593Smuzhiyunthe list of directories within a recipe:: 2098*4882a593Smuzhiyun 2099*4882a593Smuzhiyun SYSROOT_DIRS += "/opt" 2100*4882a593Smuzhiyun 2101*4882a593Smuzhiyun.. note:: 2102*4882a593Smuzhiyun 2103*4882a593Smuzhiyun The `/sysroot-only` is to be used by recipes that generate artifacts 2104*4882a593Smuzhiyun that are not included in the target filesystem, allowing them to share 2105*4882a593Smuzhiyun these artifacts without needing to use the :term:`DEPLOY_DIR`. 2106*4882a593Smuzhiyun 2107*4882a593SmuzhiyunFor a more complete description of the :ref:`ref-tasks-populate_sysroot` 2108*4882a593Smuzhiyuntask and its associated functions, see the 2109*4882a593Smuzhiyun:ref:`staging <ref-classes-staging>` class. 2110*4882a593Smuzhiyun 2111*4882a593SmuzhiyunUsing Virtual Providers 2112*4882a593Smuzhiyun----------------------- 2113*4882a593Smuzhiyun 2114*4882a593SmuzhiyunPrior to a build, if you know that several different recipes provide the 2115*4882a593Smuzhiyunsame functionality, you can use a virtual provider (i.e. ``virtual/*``) 2116*4882a593Smuzhiyunas a placeholder for the actual provider. The actual provider is 2117*4882a593Smuzhiyundetermined at build-time. 2118*4882a593Smuzhiyun 2119*4882a593SmuzhiyunA common scenario where a virtual provider is used would be for the 2120*4882a593Smuzhiyunkernel recipe. Suppose you have three kernel recipes whose 2121*4882a593Smuzhiyun:term:`PN` values map to ``kernel-big``, 2122*4882a593Smuzhiyun``kernel-mid``, and ``kernel-small``. Furthermore, each of these recipes 2123*4882a593Smuzhiyunin some way uses a :term:`PROVIDES` 2124*4882a593Smuzhiyunstatement that essentially identifies itself as being able to provide 2125*4882a593Smuzhiyun``virtual/kernel``. Here is one way through the 2126*4882a593Smuzhiyun:ref:`kernel <ref-classes-kernel>` class:: 2127*4882a593Smuzhiyun 2128*4882a593Smuzhiyun PROVIDES += "virtual/kernel" 2129*4882a593Smuzhiyun 2130*4882a593SmuzhiyunAny recipe that inherits the :ref:`kernel <ref-classes-kernel>` class is 2131*4882a593Smuzhiyungoing to utilize a :term:`PROVIDES` statement that identifies that recipe as 2132*4882a593Smuzhiyunbeing able to provide the ``virtual/kernel`` item. 2133*4882a593Smuzhiyun 2134*4882a593SmuzhiyunNow comes the time to actually build an image and you need a kernel 2135*4882a593Smuzhiyunrecipe, but which one? You can configure your build to call out the 2136*4882a593Smuzhiyunkernel recipe you want by using the :term:`PREFERRED_PROVIDER` variable. As 2137*4882a593Smuzhiyunan example, consider the :yocto_git:`x86-base.inc 2138*4882a593Smuzhiyun</poky/tree/meta/conf/machine/include/x86/x86-base.inc>` include file, which is a 2139*4882a593Smuzhiyunmachine (i.e. :term:`MACHINE`) configuration file. This include file is the 2140*4882a593Smuzhiyunreason all x86-based machines use the ``linux-yocto`` kernel. Here are the 2141*4882a593Smuzhiyunrelevant lines from the include file:: 2142*4882a593Smuzhiyun 2143*4882a593Smuzhiyun PREFERRED_PROVIDER_virtual/kernel ??= "linux-yocto" 2144*4882a593Smuzhiyun PREFERRED_VERSION_linux-yocto ??= "4.15%" 2145*4882a593Smuzhiyun 2146*4882a593SmuzhiyunWhen you use a virtual provider, you do not have to "hard code" a recipe 2147*4882a593Smuzhiyunname as a build dependency. You can use the 2148*4882a593Smuzhiyun:term:`DEPENDS` variable to state the 2149*4882a593Smuzhiyunbuild is dependent on ``virtual/kernel`` for example:: 2150*4882a593Smuzhiyun 2151*4882a593Smuzhiyun DEPENDS = "virtual/kernel" 2152*4882a593Smuzhiyun 2153*4882a593SmuzhiyunDuring the build, the OpenEmbedded build system picks 2154*4882a593Smuzhiyunthe correct recipe needed for the ``virtual/kernel`` dependency based on 2155*4882a593Smuzhiyunthe :term:`PREFERRED_PROVIDER` variable. If you want to use the small kernel 2156*4882a593Smuzhiyunmentioned at the beginning of this section, configure your build as 2157*4882a593Smuzhiyunfollows:: 2158*4882a593Smuzhiyun 2159*4882a593Smuzhiyun PREFERRED_PROVIDER_virtual/kernel ??= "kernel-small" 2160*4882a593Smuzhiyun 2161*4882a593Smuzhiyun.. note:: 2162*4882a593Smuzhiyun 2163*4882a593Smuzhiyun Any recipe that :term:`PROVIDES` a ``virtual/*`` item that is ultimately not 2164*4882a593Smuzhiyun selected through :term:`PREFERRED_PROVIDER` does not get built. Preventing these 2165*4882a593Smuzhiyun recipes from building is usually the desired behavior since this mechanism's 2166*4882a593Smuzhiyun purpose is to select between mutually exclusive alternative providers. 2167*4882a593Smuzhiyun 2168*4882a593SmuzhiyunThe following lists specific examples of virtual providers: 2169*4882a593Smuzhiyun 2170*4882a593Smuzhiyun- ``virtual/kernel``: Provides the name of the kernel recipe to use 2171*4882a593Smuzhiyun when building a kernel image. 2172*4882a593Smuzhiyun 2173*4882a593Smuzhiyun- ``virtual/bootloader``: Provides the name of the bootloader to use 2174*4882a593Smuzhiyun when building an image. 2175*4882a593Smuzhiyun 2176*4882a593Smuzhiyun- ``virtual/libgbm``: Provides ``gbm.pc``. 2177*4882a593Smuzhiyun 2178*4882a593Smuzhiyun- ``virtual/egl``: Provides ``egl.pc`` and possibly ``wayland-egl.pc``. 2179*4882a593Smuzhiyun 2180*4882a593Smuzhiyun- ``virtual/libgl``: Provides ``gl.pc`` (i.e. libGL). 2181*4882a593Smuzhiyun 2182*4882a593Smuzhiyun- ``virtual/libgles1``: Provides ``glesv1_cm.pc`` (i.e. libGLESv1_CM). 2183*4882a593Smuzhiyun 2184*4882a593Smuzhiyun- ``virtual/libgles2``: Provides ``glesv2.pc`` (i.e. libGLESv2). 2185*4882a593Smuzhiyun 2186*4882a593Smuzhiyun.. note:: 2187*4882a593Smuzhiyun 2188*4882a593Smuzhiyun Virtual providers only apply to build time dependencies specified with 2189*4882a593Smuzhiyun :term:`PROVIDES` and :term:`DEPENDS`. They do not apply to runtime 2190*4882a593Smuzhiyun dependencies specified with :term:`RPROVIDES` and :term:`RDEPENDS`. 2191*4882a593Smuzhiyun 2192*4882a593SmuzhiyunProperly Versioning Pre-Release Recipes 2193*4882a593Smuzhiyun--------------------------------------- 2194*4882a593Smuzhiyun 2195*4882a593SmuzhiyunSometimes the name of a recipe can lead to versioning problems when the 2196*4882a593Smuzhiyunrecipe is upgraded to a final release. For example, consider the 2197*4882a593Smuzhiyun``irssi_0.8.16-rc1.bb`` recipe file in the list of example recipes in 2198*4882a593Smuzhiyunthe ":ref:`dev-manual/common-tasks:storing and naming the recipe`" section. 2199*4882a593SmuzhiyunThis recipe is at a release candidate stage (i.e. "rc1"). When the recipe is 2200*4882a593Smuzhiyunreleased, the recipe filename becomes ``irssi_0.8.16.bb``. The version 2201*4882a593Smuzhiyunchange from ``0.8.16-rc1`` to ``0.8.16`` is seen as a decrease by the 2202*4882a593Smuzhiyunbuild system and package managers, so the resulting packages will not 2203*4882a593Smuzhiyuncorrectly trigger an upgrade. 2204*4882a593Smuzhiyun 2205*4882a593SmuzhiyunIn order to ensure the versions compare properly, the recommended 2206*4882a593Smuzhiyunconvention is to set :term:`PV` within the 2207*4882a593Smuzhiyunrecipe to "previous_version+current_version". You can use an additional 2208*4882a593Smuzhiyunvariable so that you can use the current version elsewhere. Here is an 2209*4882a593Smuzhiyunexample:: 2210*4882a593Smuzhiyun 2211*4882a593Smuzhiyun REALPV = "0.8.16-rc1" 2212*4882a593Smuzhiyun PV = "0.8.15+${REALPV}" 2213*4882a593Smuzhiyun 2214*4882a593SmuzhiyunPost-Installation Scripts 2215*4882a593Smuzhiyun------------------------- 2216*4882a593Smuzhiyun 2217*4882a593SmuzhiyunPost-installation scripts run immediately after installing a package on 2218*4882a593Smuzhiyunthe target or during image creation when a package is included in an 2219*4882a593Smuzhiyunimage. To add a post-installation script to a package, add a 2220*4882a593Smuzhiyun``pkg_postinst:``\ `PACKAGENAME`\ ``()`` function to the recipe file 2221*4882a593Smuzhiyun(``.bb``) and replace `PACKAGENAME` with the name of the package you want 2222*4882a593Smuzhiyunto attach to the ``postinst`` script. To apply the post-installation 2223*4882a593Smuzhiyunscript to the main package for the recipe, which is usually what is 2224*4882a593Smuzhiyunrequired, specify 2225*4882a593Smuzhiyun``${``\ :term:`PN`\ ``}`` in place of 2226*4882a593SmuzhiyunPACKAGENAME. 2227*4882a593Smuzhiyun 2228*4882a593SmuzhiyunA post-installation function has the following structure:: 2229*4882a593Smuzhiyun 2230*4882a593Smuzhiyun pkg_postinst:PACKAGENAME() { 2231*4882a593Smuzhiyun # Commands to carry out 2232*4882a593Smuzhiyun } 2233*4882a593Smuzhiyun 2234*4882a593SmuzhiyunThe script defined in the post-installation function is called when the 2235*4882a593Smuzhiyunroot filesystem is created. If the script succeeds, the package is 2236*4882a593Smuzhiyunmarked as installed. 2237*4882a593Smuzhiyun 2238*4882a593Smuzhiyun.. note:: 2239*4882a593Smuzhiyun 2240*4882a593Smuzhiyun Any RPM post-installation script that runs on the target should 2241*4882a593Smuzhiyun return a 0 exit code. RPM does not allow non-zero exit codes for 2242*4882a593Smuzhiyun these scripts, and the RPM package manager will cause the package to 2243*4882a593Smuzhiyun fail installation on the target. 2244*4882a593Smuzhiyun 2245*4882a593SmuzhiyunSometimes it is necessary for the execution of a post-installation 2246*4882a593Smuzhiyunscript to be delayed until the first boot. For example, the script might 2247*4882a593Smuzhiyunneed to be executed on the device itself. To delay script execution 2248*4882a593Smuzhiyununtil boot time, you must explicitly mark post installs to defer to the 2249*4882a593Smuzhiyuntarget. You can use ``pkg_postinst_ontarget()`` or call 2250*4882a593Smuzhiyun``postinst_intercept delay_to_first_boot`` from ``pkg_postinst()``. Any 2251*4882a593Smuzhiyunfailure of a ``pkg_postinst()`` script (including exit 1) triggers an 2252*4882a593Smuzhiyunerror during the 2253*4882a593Smuzhiyun:ref:`ref-tasks-rootfs` task. 2254*4882a593Smuzhiyun 2255*4882a593SmuzhiyunIf you have recipes that use ``pkg_postinst`` function and they require 2256*4882a593Smuzhiyunthe use of non-standard native tools that have dependencies during 2257*4882a593Smuzhiyunroot filesystem construction, you need to use the 2258*4882a593Smuzhiyun:term:`PACKAGE_WRITE_DEPS` 2259*4882a593Smuzhiyunvariable in your recipe to list these tools. If you do not use this 2260*4882a593Smuzhiyunvariable, the tools might be missing and execution of the 2261*4882a593Smuzhiyunpost-installation script is deferred until first boot. Deferring the 2262*4882a593Smuzhiyunscript to the first boot is undesirable and impossible for read-only 2263*4882a593Smuzhiyunroot filesystems. 2264*4882a593Smuzhiyun 2265*4882a593Smuzhiyun.. note:: 2266*4882a593Smuzhiyun 2267*4882a593Smuzhiyun There is equivalent support for pre-install, pre-uninstall, and post-uninstall 2268*4882a593Smuzhiyun scripts by way of ``pkg_preinst``, ``pkg_prerm``, and ``pkg_postrm``, 2269*4882a593Smuzhiyun respectively. These scrips work in exactly the same way as does 2270*4882a593Smuzhiyun ``pkg_postinst`` with the exception that they run at different times. Also, 2271*4882a593Smuzhiyun because of when they run, they are not applicable to being run at image 2272*4882a593Smuzhiyun creation time like ``pkg_postinst``. 2273*4882a593Smuzhiyun 2274*4882a593SmuzhiyunTesting 2275*4882a593Smuzhiyun------- 2276*4882a593Smuzhiyun 2277*4882a593SmuzhiyunThe final step for completing your recipe is to be sure that the 2278*4882a593Smuzhiyunsoftware you built runs correctly. To accomplish runtime testing, add 2279*4882a593Smuzhiyunthe build's output packages to your image and test them on the target. 2280*4882a593Smuzhiyun 2281*4882a593SmuzhiyunFor information on how to customize your image by adding specific 2282*4882a593Smuzhiyunpackages, see ":ref:`dev-manual/common-tasks:customizing images`" section. 2283*4882a593Smuzhiyun 2284*4882a593SmuzhiyunExamples 2285*4882a593Smuzhiyun-------- 2286*4882a593Smuzhiyun 2287*4882a593SmuzhiyunTo help summarize how to write a recipe, this section provides some 2288*4882a593Smuzhiyunexamples given various scenarios: 2289*4882a593Smuzhiyun 2290*4882a593Smuzhiyun- Recipes that use local files 2291*4882a593Smuzhiyun 2292*4882a593Smuzhiyun- Using an Autotooled package 2293*4882a593Smuzhiyun 2294*4882a593Smuzhiyun- Using a Makefile-based package 2295*4882a593Smuzhiyun 2296*4882a593Smuzhiyun- Splitting an application into multiple packages 2297*4882a593Smuzhiyun 2298*4882a593Smuzhiyun- Adding binaries to an image 2299*4882a593Smuzhiyun 2300*4882a593SmuzhiyunSingle .c File Package (Hello World!) 2301*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2302*4882a593Smuzhiyun 2303*4882a593SmuzhiyunBuilding an application from a single file that is stored locally (e.g. 2304*4882a593Smuzhiyununder ``files``) requires a recipe that has the file listed in the 2305*4882a593Smuzhiyun:term:`SRC_URI` variable. Additionally, you need to manually write the 2306*4882a593Smuzhiyun``do_compile`` and ``do_install`` tasks. The :term:`S` variable defines the 2307*4882a593Smuzhiyundirectory containing the source code, which is set to 2308*4882a593Smuzhiyun:term:`WORKDIR` in this case - the 2309*4882a593Smuzhiyundirectory BitBake uses for the build. 2310*4882a593Smuzhiyun:: 2311*4882a593Smuzhiyun 2312*4882a593Smuzhiyun SUMMARY = "Simple helloworld application" 2313*4882a593Smuzhiyun SECTION = "examples" 2314*4882a593Smuzhiyun LICENSE = "MIT" 2315*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302" 2316*4882a593Smuzhiyun 2317*4882a593Smuzhiyun SRC_URI = "file://helloworld.c" 2318*4882a593Smuzhiyun 2319*4882a593Smuzhiyun S = "${WORKDIR}" 2320*4882a593Smuzhiyun 2321*4882a593Smuzhiyun do_compile() { 2322*4882a593Smuzhiyun ${CC} ${LDFLAGS} helloworld.c -o helloworld 2323*4882a593Smuzhiyun } 2324*4882a593Smuzhiyun 2325*4882a593Smuzhiyun do_install() { 2326*4882a593Smuzhiyun install -d ${D}${bindir} 2327*4882a593Smuzhiyun install -m 0755 helloworld ${D}${bindir} 2328*4882a593Smuzhiyun } 2329*4882a593Smuzhiyun 2330*4882a593SmuzhiyunBy default, the ``helloworld``, ``helloworld-dbg``, and 2331*4882a593Smuzhiyun``helloworld-dev`` packages are built. For information on how to 2332*4882a593Smuzhiyuncustomize the packaging process, see the 2333*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:splitting an application into multiple packages`" 2334*4882a593Smuzhiyunsection. 2335*4882a593Smuzhiyun 2336*4882a593SmuzhiyunAutotooled Package 2337*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~ 2338*4882a593Smuzhiyun 2339*4882a593SmuzhiyunApplications that use Autotools such as ``autoconf`` and ``automake`` 2340*4882a593Smuzhiyunrequire a recipe that has a source archive listed in :term:`SRC_URI` and 2341*4882a593Smuzhiyunalso inherit the 2342*4882a593Smuzhiyun:ref:`autotools <ref-classes-autotools>` class, 2343*4882a593Smuzhiyunwhich contains the definitions of all the steps needed to build an 2344*4882a593SmuzhiyunAutotool-based application. The result of the build is automatically 2345*4882a593Smuzhiyunpackaged. And, if the application uses NLS for localization, packages 2346*4882a593Smuzhiyunwith local information are generated (one package per language). 2347*4882a593SmuzhiyunFollowing is one example: (``hello_2.3.bb``) 2348*4882a593Smuzhiyun:: 2349*4882a593Smuzhiyun 2350*4882a593Smuzhiyun SUMMARY = "GNU Helloworld application" 2351*4882a593Smuzhiyun SECTION = "examples" 2352*4882a593Smuzhiyun LICENSE = "GPL-2.0-or-later" 2353*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://COPYING;md5=751419260aa954499f7abaabaa882bbe" 2354*4882a593Smuzhiyun 2355*4882a593Smuzhiyun SRC_URI = "${GNU_MIRROR}/hello/hello-${PV}.tar.gz" 2356*4882a593Smuzhiyun 2357*4882a593Smuzhiyun inherit autotools gettext 2358*4882a593Smuzhiyun 2359*4882a593SmuzhiyunThe variable :term:`LIC_FILES_CHKSUM` is used to track source license 2360*4882a593Smuzhiyunchanges as described in the 2361*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:tracking license changes`" section in 2362*4882a593Smuzhiyunthe Yocto Project Overview and Concepts Manual. You can quickly create 2363*4882a593SmuzhiyunAutotool-based recipes in a manner similar to the previous example. 2364*4882a593Smuzhiyun 2365*4882a593SmuzhiyunMakefile-Based Package 2366*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~ 2367*4882a593Smuzhiyun 2368*4882a593SmuzhiyunApplications that use GNU ``make`` also require a recipe that has the 2369*4882a593Smuzhiyunsource archive listed in :term:`SRC_URI`. You do not need to add a 2370*4882a593Smuzhiyun``do_compile`` step since by default BitBake starts the ``make`` command 2371*4882a593Smuzhiyunto compile the application. If you need additional ``make`` options, you 2372*4882a593Smuzhiyunshould store them in the 2373*4882a593Smuzhiyun:term:`EXTRA_OEMAKE` or 2374*4882a593Smuzhiyun:term:`PACKAGECONFIG_CONFARGS` 2375*4882a593Smuzhiyunvariables. BitBake passes these options into the GNU ``make`` 2376*4882a593Smuzhiyuninvocation. Note that a ``do_install`` task is still required. 2377*4882a593SmuzhiyunOtherwise, BitBake runs an empty ``do_install`` task by default. 2378*4882a593Smuzhiyun 2379*4882a593SmuzhiyunSome applications might require extra parameters to be passed to the 2380*4882a593Smuzhiyuncompiler. For example, the application might need an additional header 2381*4882a593Smuzhiyunpath. You can accomplish this by adding to the :term:`CFLAGS` variable. The 2382*4882a593Smuzhiyunfollowing example shows this:: 2383*4882a593Smuzhiyun 2384*4882a593Smuzhiyun CFLAGS:prepend = "-I ${S}/include " 2385*4882a593Smuzhiyun 2386*4882a593SmuzhiyunIn the following example, ``lz4`` is a makefile-based package:: 2387*4882a593Smuzhiyun 2388*4882a593Smuzhiyun SUMMARY = "Extremely Fast Compression algorithm" 2389*4882a593Smuzhiyun DESCRIPTION = "LZ4 is a very fast lossless compression algorithm, providing compression speed at 400 MB/s per core, scalable with multi-cores CPU. It also features an extremely fast decoder, with speed in multiple GB/s per core, typically reaching RAM speed limits on multi-core systems." 2390*4882a593Smuzhiyun HOMEPAGE = "https://github.com/lz4/lz4" 2391*4882a593Smuzhiyun 2392*4882a593Smuzhiyun LICENSE = "BSD-2-Clause | GPL-2.0-only" 2393*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://lib/LICENSE;md5=ebc2ea4814a64de7708f1571904b32cc \ 2394*4882a593Smuzhiyun file://programs/COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \ 2395*4882a593Smuzhiyun file://LICENSE;md5=d57c0d21cb917fb4e0af2454aa48b956 \ 2396*4882a593Smuzhiyun " 2397*4882a593Smuzhiyun 2398*4882a593Smuzhiyun PE = "1" 2399*4882a593Smuzhiyun 2400*4882a593Smuzhiyun SRCREV = "d44371841a2f1728a3f36839fd4b7e872d0927d3" 2401*4882a593Smuzhiyun 2402*4882a593Smuzhiyun SRC_URI = "git://github.com/lz4/lz4.git;branch=release;protocol=https \ 2403*4882a593Smuzhiyun file://CVE-2021-3520.patch \ 2404*4882a593Smuzhiyun " 2405*4882a593Smuzhiyun UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>.*)" 2406*4882a593Smuzhiyun 2407*4882a593Smuzhiyun S = "${WORKDIR}/git" 2408*4882a593Smuzhiyun 2409*4882a593Smuzhiyun # Fixed in r118, which is larger than the current version. 2410*4882a593Smuzhiyun CVE_CHECK_IGNORE += "CVE-2014-4715" 2411*4882a593Smuzhiyun 2412*4882a593Smuzhiyun EXTRA_OEMAKE = "PREFIX=${prefix} CC='${CC}' CFLAGS='${CFLAGS}' DESTDIR=${D} LIBDIR=${libdir} INCLUDEDIR=${includedir} BUILD_STATIC=no" 2413*4882a593Smuzhiyun 2414*4882a593Smuzhiyun do_install() { 2415*4882a593Smuzhiyun oe_runmake install 2416*4882a593Smuzhiyun } 2417*4882a593Smuzhiyun 2418*4882a593Smuzhiyun BBCLASSEXTEND = "native nativesdk" 2419*4882a593Smuzhiyun 2420*4882a593SmuzhiyunSplitting an Application into Multiple Packages 2421*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2422*4882a593Smuzhiyun 2423*4882a593SmuzhiyunYou can use the variables :term:`PACKAGES` and :term:`FILES` to split an 2424*4882a593Smuzhiyunapplication into multiple packages. 2425*4882a593Smuzhiyun 2426*4882a593SmuzhiyunFollowing is an example that uses the ``libxpm`` recipe. By default, 2427*4882a593Smuzhiyunthis recipe generates a single package that contains the library along 2428*4882a593Smuzhiyunwith a few binaries. You can modify the recipe to split the binaries 2429*4882a593Smuzhiyuninto separate packages:: 2430*4882a593Smuzhiyun 2431*4882a593Smuzhiyun require xorg-lib-common.inc 2432*4882a593Smuzhiyun 2433*4882a593Smuzhiyun SUMMARY = "Xpm: X Pixmap extension library" 2434*4882a593Smuzhiyun LICENSE = "MIT" 2435*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://COPYING;md5=51f4270b012ecd4ab1a164f5f4ed6cf7" 2436*4882a593Smuzhiyun DEPENDS += "libxext libsm libxt" 2437*4882a593Smuzhiyun PE = "1" 2438*4882a593Smuzhiyun 2439*4882a593Smuzhiyun XORG_PN = "libXpm" 2440*4882a593Smuzhiyun 2441*4882a593Smuzhiyun PACKAGES =+ "sxpm cxpm" 2442*4882a593Smuzhiyun FILES:cxpm = "${bindir}/cxpm" 2443*4882a593Smuzhiyun FILES:sxpm = "${bindir}/sxpm" 2444*4882a593Smuzhiyun 2445*4882a593SmuzhiyunIn the previous example, we want to ship the ``sxpm`` and ``cxpm`` 2446*4882a593Smuzhiyunbinaries in separate packages. Since ``bindir`` would be packaged into 2447*4882a593Smuzhiyunthe main :term:`PN` package by default, we prepend the :term:`PACKAGES` variable 2448*4882a593Smuzhiyunso additional package names are added to the start of list. This results 2449*4882a593Smuzhiyunin the extra ``FILES:*`` variables then containing information that 2450*4882a593Smuzhiyundefine which files and directories go into which packages. Files 2451*4882a593Smuzhiyunincluded by earlier packages are skipped by latter packages. Thus, the 2452*4882a593Smuzhiyunmain :term:`PN` package does not include the above listed files. 2453*4882a593Smuzhiyun 2454*4882a593SmuzhiyunPackaging Externally Produced Binaries 2455*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2456*4882a593Smuzhiyun 2457*4882a593SmuzhiyunSometimes, you need to add pre-compiled binaries to an image. For 2458*4882a593Smuzhiyunexample, suppose that there are binaries for proprietary code, 2459*4882a593Smuzhiyuncreated by a particular division of a company. Your part of the company 2460*4882a593Smuzhiyunneeds to use those binaries as part of an image that you are building 2461*4882a593Smuzhiyunusing the OpenEmbedded build system. Since you only have the binaries 2462*4882a593Smuzhiyunand not the source code, you cannot use a typical recipe that expects to 2463*4882a593Smuzhiyunfetch the source specified in 2464*4882a593Smuzhiyun:term:`SRC_URI` and then compile it. 2465*4882a593Smuzhiyun 2466*4882a593SmuzhiyunOne method is to package the binaries and then install them as part of 2467*4882a593Smuzhiyunthe image. Generally, it is not a good idea to package binaries since, 2468*4882a593Smuzhiyunamong other things, it can hinder the ability to reproduce builds and 2469*4882a593Smuzhiyuncould lead to compatibility problems with ABI in the future. However, 2470*4882a593Smuzhiyunsometimes you have no choice. 2471*4882a593Smuzhiyun 2472*4882a593SmuzhiyunThe easiest solution is to create a recipe that uses the 2473*4882a593Smuzhiyun:ref:`bin_package <ref-classes-bin-package>` class 2474*4882a593Smuzhiyunand to be sure that you are using default locations for build artifacts. 2475*4882a593SmuzhiyunIn most cases, the :ref:`bin_package <ref-classes-bin-package>` class handles "skipping" the 2476*4882a593Smuzhiyunconfigure and compile steps as well as sets things up to grab packages 2477*4882a593Smuzhiyunfrom the appropriate area. In particular, this class sets ``noexec`` on 2478*4882a593Smuzhiyunboth the :ref:`ref-tasks-configure` 2479*4882a593Smuzhiyunand :ref:`ref-tasks-compile` tasks, 2480*4882a593Smuzhiyunsets ``FILES:${PN}`` to "/" so that it picks up all files, and sets up a 2481*4882a593Smuzhiyun:ref:`ref-tasks-install` task, which 2482*4882a593Smuzhiyuneffectively copies all files from ``${S}`` to ``${D}``. The 2483*4882a593Smuzhiyun:ref:`bin_package <ref-classes-bin-package>` class works well when the files extracted into ``${S}`` 2484*4882a593Smuzhiyunare already laid out in the way they should be laid out on the target. 2485*4882a593SmuzhiyunFor more information on these variables, see the 2486*4882a593Smuzhiyun:term:`FILES`, 2487*4882a593Smuzhiyun:term:`PN`, 2488*4882a593Smuzhiyun:term:`S`, and 2489*4882a593Smuzhiyun:term:`D` variables in the Yocto Project 2490*4882a593SmuzhiyunReference Manual's variable glossary. 2491*4882a593Smuzhiyun 2492*4882a593Smuzhiyun.. note:: 2493*4882a593Smuzhiyun 2494*4882a593Smuzhiyun - Using :term:`DEPENDS` is a good 2495*4882a593Smuzhiyun idea even for components distributed in binary form, and is often 2496*4882a593Smuzhiyun necessary for shared libraries. For a shared library, listing the 2497*4882a593Smuzhiyun library dependencies in :term:`DEPENDS` makes sure that the libraries 2498*4882a593Smuzhiyun are available in the staging sysroot when other recipes link 2499*4882a593Smuzhiyun against the library, which might be necessary for successful 2500*4882a593Smuzhiyun linking. 2501*4882a593Smuzhiyun 2502*4882a593Smuzhiyun - Using :term:`DEPENDS` also allows runtime dependencies between 2503*4882a593Smuzhiyun packages to be added automatically. See the 2504*4882a593Smuzhiyun ":ref:`overview-manual/concepts:automatically added runtime dependencies`" 2505*4882a593Smuzhiyun section in the Yocto Project Overview and Concepts Manual for more 2506*4882a593Smuzhiyun information. 2507*4882a593Smuzhiyun 2508*4882a593SmuzhiyunIf you cannot use the :ref:`bin_package <ref-classes-bin-package>` class, you need to be sure you are 2509*4882a593Smuzhiyundoing the following: 2510*4882a593Smuzhiyun 2511*4882a593Smuzhiyun- Create a recipe where the 2512*4882a593Smuzhiyun :ref:`ref-tasks-configure` and 2513*4882a593Smuzhiyun :ref:`ref-tasks-compile` tasks do 2514*4882a593Smuzhiyun nothing: It is usually sufficient to just not define these tasks in 2515*4882a593Smuzhiyun the recipe, because the default implementations do nothing unless a 2516*4882a593Smuzhiyun Makefile is found in 2517*4882a593Smuzhiyun ``${``\ :term:`S`\ ``}``. 2518*4882a593Smuzhiyun 2519*4882a593Smuzhiyun If ``${S}`` might contain a Makefile, or if you inherit some class 2520*4882a593Smuzhiyun that replaces ``do_configure`` and ``do_compile`` with custom 2521*4882a593Smuzhiyun versions, then you can use the 2522*4882a593Smuzhiyun ``[``\ :ref:`noexec <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ``]`` 2523*4882a593Smuzhiyun flag to turn the tasks into no-ops, as follows:: 2524*4882a593Smuzhiyun 2525*4882a593Smuzhiyun do_configure[noexec] = "1" 2526*4882a593Smuzhiyun do_compile[noexec] = "1" 2527*4882a593Smuzhiyun 2528*4882a593Smuzhiyun Unlike 2529*4882a593Smuzhiyun :ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:deleting a task`, 2530*4882a593Smuzhiyun using the flag preserves the dependency chain from the 2531*4882a593Smuzhiyun :ref:`ref-tasks-fetch`, 2532*4882a593Smuzhiyun :ref:`ref-tasks-unpack`, and 2533*4882a593Smuzhiyun :ref:`ref-tasks-patch` tasks to the 2534*4882a593Smuzhiyun :ref:`ref-tasks-install` task. 2535*4882a593Smuzhiyun 2536*4882a593Smuzhiyun- Make sure your ``do_install`` task installs the binaries 2537*4882a593Smuzhiyun appropriately. 2538*4882a593Smuzhiyun 2539*4882a593Smuzhiyun- Ensure that you set up :term:`FILES` 2540*4882a593Smuzhiyun (usually 2541*4882a593Smuzhiyun ``FILES:${``\ :term:`PN`\ ``}``) to 2542*4882a593Smuzhiyun point to the files you have installed, which of course depends on 2543*4882a593Smuzhiyun where you have installed them and whether those files are in 2544*4882a593Smuzhiyun different locations than the defaults. 2545*4882a593Smuzhiyun 2546*4882a593SmuzhiyunFollowing Recipe Style Guidelines 2547*4882a593Smuzhiyun--------------------------------- 2548*4882a593Smuzhiyun 2549*4882a593SmuzhiyunWhen writing recipes, it is good to conform to existing style 2550*4882a593Smuzhiyunguidelines. The :oe_wiki:`OpenEmbedded Styleguide </Styleguide>` wiki page 2551*4882a593Smuzhiyunprovides rough guidelines for preferred recipe style. 2552*4882a593Smuzhiyun 2553*4882a593SmuzhiyunIt is common for existing recipes to deviate a bit from this style. 2554*4882a593SmuzhiyunHowever, aiming for at least a consistent style is a good idea. Some 2555*4882a593Smuzhiyunpractices, such as omitting spaces around ``=`` operators in assignments 2556*4882a593Smuzhiyunor ordering recipe components in an erratic way, are widely seen as poor 2557*4882a593Smuzhiyunstyle. 2558*4882a593Smuzhiyun 2559*4882a593SmuzhiyunRecipe Syntax 2560*4882a593Smuzhiyun------------- 2561*4882a593Smuzhiyun 2562*4882a593SmuzhiyunUnderstanding recipe file syntax is important for writing recipes. The 2563*4882a593Smuzhiyunfollowing list overviews the basic items that make up a BitBake recipe 2564*4882a593Smuzhiyunfile. For more complete BitBake syntax descriptions, see the 2565*4882a593Smuzhiyun":doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata`" 2566*4882a593Smuzhiyunchapter of the BitBake User Manual. 2567*4882a593Smuzhiyun 2568*4882a593Smuzhiyun- *Variable Assignments and Manipulations:* Variable assignments allow 2569*4882a593Smuzhiyun a value to be assigned to a variable. The assignment can be static 2570*4882a593Smuzhiyun text or might include the contents of other variables. In addition to 2571*4882a593Smuzhiyun the assignment, appending and prepending operations are also 2572*4882a593Smuzhiyun supported. 2573*4882a593Smuzhiyun 2574*4882a593Smuzhiyun The following example shows some of the ways you can use variables in 2575*4882a593Smuzhiyun recipes:: 2576*4882a593Smuzhiyun 2577*4882a593Smuzhiyun S = "${WORKDIR}/postfix-${PV}" 2578*4882a593Smuzhiyun CFLAGS += "-DNO_ASM" 2579*4882a593Smuzhiyun SRC_URI:append = " file://fixup.patch" 2580*4882a593Smuzhiyun 2581*4882a593Smuzhiyun- *Functions:* Functions provide a series of actions to be performed. 2582*4882a593Smuzhiyun You usually use functions to override the default implementation of a 2583*4882a593Smuzhiyun task function or to complement a default function (i.e. append or 2584*4882a593Smuzhiyun prepend to an existing function). Standard functions use ``sh`` shell 2585*4882a593Smuzhiyun syntax, although access to OpenEmbedded variables and internal 2586*4882a593Smuzhiyun methods are also available. 2587*4882a593Smuzhiyun 2588*4882a593Smuzhiyun Here is an example function from the ``sed`` recipe:: 2589*4882a593Smuzhiyun 2590*4882a593Smuzhiyun do_install () { 2591*4882a593Smuzhiyun autotools_do_install 2592*4882a593Smuzhiyun install -d ${D}${base_bindir} 2593*4882a593Smuzhiyun mv ${D}${bindir}/sed ${D}${base_bindir}/sed 2594*4882a593Smuzhiyun rmdir ${D}${bindir}/ 2595*4882a593Smuzhiyun } 2596*4882a593Smuzhiyun 2597*4882a593Smuzhiyun It is 2598*4882a593Smuzhiyun also possible to implement new functions that are called between 2599*4882a593Smuzhiyun existing tasks as long as the new functions are not replacing or 2600*4882a593Smuzhiyun complementing the default functions. You can implement functions in 2601*4882a593Smuzhiyun Python instead of shell. Both of these options are not seen in the 2602*4882a593Smuzhiyun majority of recipes. 2603*4882a593Smuzhiyun 2604*4882a593Smuzhiyun- *Keywords:* BitBake recipes use only a few keywords. You use keywords 2605*4882a593Smuzhiyun to include common functions (``inherit``), load parts of a recipe 2606*4882a593Smuzhiyun from other files (``include`` and ``require``) and export variables 2607*4882a593Smuzhiyun to the environment (``export``). 2608*4882a593Smuzhiyun 2609*4882a593Smuzhiyun The following example shows the use of some of these keywords:: 2610*4882a593Smuzhiyun 2611*4882a593Smuzhiyun export POSTCONF = "${STAGING_BINDIR}/postconf" 2612*4882a593Smuzhiyun inherit autoconf 2613*4882a593Smuzhiyun require otherfile.inc 2614*4882a593Smuzhiyun 2615*4882a593Smuzhiyun- *Comments (#):* Any lines that begin with the hash character (``#``) 2616*4882a593Smuzhiyun are treated as comment lines and are ignored:: 2617*4882a593Smuzhiyun 2618*4882a593Smuzhiyun # This is a comment 2619*4882a593Smuzhiyun 2620*4882a593SmuzhiyunThis next list summarizes the most important and most commonly used 2621*4882a593Smuzhiyunparts of the recipe syntax. For more information on these parts of the 2622*4882a593Smuzhiyunsyntax, you can reference the 2623*4882a593Smuzhiyun:doc:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata` chapter 2624*4882a593Smuzhiyunin the BitBake User Manual. 2625*4882a593Smuzhiyun 2626*4882a593Smuzhiyun- *Line Continuation (\\):* Use the backward slash (``\``) character to 2627*4882a593Smuzhiyun split a statement over multiple lines. Place the slash character at 2628*4882a593Smuzhiyun the end of the line that is to be continued on the next line:: 2629*4882a593Smuzhiyun 2630*4882a593Smuzhiyun VAR = "A really long \ 2631*4882a593Smuzhiyun line" 2632*4882a593Smuzhiyun 2633*4882a593Smuzhiyun .. note:: 2634*4882a593Smuzhiyun 2635*4882a593Smuzhiyun You cannot have any characters including spaces or tabs after the 2636*4882a593Smuzhiyun slash character. 2637*4882a593Smuzhiyun 2638*4882a593Smuzhiyun- *Using Variables (${VARNAME}):* Use the ``${VARNAME}`` syntax to 2639*4882a593Smuzhiyun access the contents of a variable:: 2640*4882a593Smuzhiyun 2641*4882a593Smuzhiyun SRC_URI = "${SOURCEFORGE_MIRROR}/libpng/zlib-${PV}.tar.gz" 2642*4882a593Smuzhiyun 2643*4882a593Smuzhiyun .. note:: 2644*4882a593Smuzhiyun 2645*4882a593Smuzhiyun It is important to understand that the value of a variable 2646*4882a593Smuzhiyun expressed in this form does not get substituted automatically. The 2647*4882a593Smuzhiyun expansion of these expressions happens on-demand later (e.g. 2648*4882a593Smuzhiyun usually when a function that makes reference to the variable 2649*4882a593Smuzhiyun executes). This behavior ensures that the values are most 2650*4882a593Smuzhiyun appropriate for the context in which they are finally used. On the 2651*4882a593Smuzhiyun rare occasion that you do need the variable expression to be 2652*4882a593Smuzhiyun expanded immediately, you can use the 2653*4882a593Smuzhiyun := 2654*4882a593Smuzhiyun operator instead of 2655*4882a593Smuzhiyun = 2656*4882a593Smuzhiyun when you make the assignment, but this is not generally needed. 2657*4882a593Smuzhiyun 2658*4882a593Smuzhiyun- *Quote All Assignments ("value"):* Use double quotes around values in 2659*4882a593Smuzhiyun all variable assignments (e.g. ``"value"``). Following is an example:: 2660*4882a593Smuzhiyun 2661*4882a593Smuzhiyun VAR1 = "${OTHERVAR}" 2662*4882a593Smuzhiyun VAR2 = "The version is ${PV}" 2663*4882a593Smuzhiyun 2664*4882a593Smuzhiyun- *Conditional Assignment (?=):* Conditional assignment is used to 2665*4882a593Smuzhiyun assign a value to a variable, but only when the variable is currently 2666*4882a593Smuzhiyun unset. Use the question mark followed by the equal sign (``?=``) to 2667*4882a593Smuzhiyun make a "soft" assignment used for conditional assignment. Typically, 2668*4882a593Smuzhiyun "soft" assignments are used in the ``local.conf`` file for variables 2669*4882a593Smuzhiyun that are allowed to come through from the external environment. 2670*4882a593Smuzhiyun 2671*4882a593Smuzhiyun Here is an example where ``VAR1`` is set to "New value" if it is 2672*4882a593Smuzhiyun currently empty. However, if ``VAR1`` has already been set, it 2673*4882a593Smuzhiyun remains unchanged:: 2674*4882a593Smuzhiyun 2675*4882a593Smuzhiyun VAR1 ?= "New value" 2676*4882a593Smuzhiyun 2677*4882a593Smuzhiyun In this next example, ``VAR1`` is left with the value "Original value":: 2678*4882a593Smuzhiyun 2679*4882a593Smuzhiyun VAR1 = "Original value" 2680*4882a593Smuzhiyun VAR1 ?= "New value" 2681*4882a593Smuzhiyun 2682*4882a593Smuzhiyun- *Appending (+=):* Use the plus character followed by the equals sign 2683*4882a593Smuzhiyun (``+=``) to append values to existing variables. 2684*4882a593Smuzhiyun 2685*4882a593Smuzhiyun .. note:: 2686*4882a593Smuzhiyun 2687*4882a593Smuzhiyun This operator adds a space between the existing content of the 2688*4882a593Smuzhiyun variable and the new content. 2689*4882a593Smuzhiyun 2690*4882a593Smuzhiyun Here is an example:: 2691*4882a593Smuzhiyun 2692*4882a593Smuzhiyun SRC_URI += "file://fix-makefile.patch" 2693*4882a593Smuzhiyun 2694*4882a593Smuzhiyun- *Prepending (=+):* Use the equals sign followed by the plus character 2695*4882a593Smuzhiyun (``=+``) to prepend values to existing variables. 2696*4882a593Smuzhiyun 2697*4882a593Smuzhiyun .. note:: 2698*4882a593Smuzhiyun 2699*4882a593Smuzhiyun This operator adds a space between the new content and the 2700*4882a593Smuzhiyun existing content of the variable. 2701*4882a593Smuzhiyun 2702*4882a593Smuzhiyun Here is an example:: 2703*4882a593Smuzhiyun 2704*4882a593Smuzhiyun VAR =+ "Starts" 2705*4882a593Smuzhiyun 2706*4882a593Smuzhiyun- *Appending (:append):* Use the ``:append`` operator to append values 2707*4882a593Smuzhiyun to existing variables. This operator does not add any additional 2708*4882a593Smuzhiyun space. Also, the operator is applied after all the ``+=``, and ``=+`` 2709*4882a593Smuzhiyun operators have been applied and after all ``=`` assignments have 2710*4882a593Smuzhiyun occurred. 2711*4882a593Smuzhiyun 2712*4882a593Smuzhiyun The following example shows the space being explicitly added to the 2713*4882a593Smuzhiyun start to ensure the appended value is not merged with the existing 2714*4882a593Smuzhiyun value:: 2715*4882a593Smuzhiyun 2716*4882a593Smuzhiyun SRC_URI:append = " file://fix-makefile.patch" 2717*4882a593Smuzhiyun 2718*4882a593Smuzhiyun You can also use 2719*4882a593Smuzhiyun the ``:append`` operator with overrides, which results in the actions 2720*4882a593Smuzhiyun only being performed for the specified target or machine:: 2721*4882a593Smuzhiyun 2722*4882a593Smuzhiyun SRC_URI:append:sh4 = " file://fix-makefile.patch" 2723*4882a593Smuzhiyun 2724*4882a593Smuzhiyun- *Prepending (:prepend):* Use the ``:prepend`` operator to prepend 2725*4882a593Smuzhiyun values to existing variables. This operator does not add any 2726*4882a593Smuzhiyun additional space. Also, the operator is applied after all the ``+=``, 2727*4882a593Smuzhiyun and ``=+`` operators have been applied and after all ``=`` 2728*4882a593Smuzhiyun assignments have occurred. 2729*4882a593Smuzhiyun 2730*4882a593Smuzhiyun The following example shows the space being explicitly added to the 2731*4882a593Smuzhiyun end to ensure the prepended value is not merged with the existing 2732*4882a593Smuzhiyun value:: 2733*4882a593Smuzhiyun 2734*4882a593Smuzhiyun CFLAGS:prepend = "-I${S}/myincludes " 2735*4882a593Smuzhiyun 2736*4882a593Smuzhiyun You can also use the 2737*4882a593Smuzhiyun ``:prepend`` operator with overrides, which results in the actions 2738*4882a593Smuzhiyun only being performed for the specified target or machine:: 2739*4882a593Smuzhiyun 2740*4882a593Smuzhiyun CFLAGS:prepend:sh4 = "-I${S}/myincludes " 2741*4882a593Smuzhiyun 2742*4882a593Smuzhiyun- *Overrides:* You can use overrides to set a value conditionally, 2743*4882a593Smuzhiyun typically based on how the recipe is being built. For example, to set 2744*4882a593Smuzhiyun the :term:`KBRANCH` variable's 2745*4882a593Smuzhiyun value to "standard/base" for any target 2746*4882a593Smuzhiyun :term:`MACHINE`, except for 2747*4882a593Smuzhiyun qemuarm where it should be set to "standard/arm-versatile-926ejs", 2748*4882a593Smuzhiyun you would do the following:: 2749*4882a593Smuzhiyun 2750*4882a593Smuzhiyun KBRANCH = "standard/base" 2751*4882a593Smuzhiyun KBRANCH:qemuarm = "standard/arm-versatile-926ejs" 2752*4882a593Smuzhiyun 2753*4882a593Smuzhiyun Overrides are also used to separate 2754*4882a593Smuzhiyun alternate values of a variable in other situations. For example, when 2755*4882a593Smuzhiyun setting variables such as 2756*4882a593Smuzhiyun :term:`FILES` and 2757*4882a593Smuzhiyun :term:`RDEPENDS` that are 2758*4882a593Smuzhiyun specific to individual packages produced by a recipe, you should 2759*4882a593Smuzhiyun always use an override that specifies the name of the package. 2760*4882a593Smuzhiyun 2761*4882a593Smuzhiyun- *Indentation:* Use spaces for indentation rather than tabs. For 2762*4882a593Smuzhiyun shell functions, both currently work. However, it is a policy 2763*4882a593Smuzhiyun decision of the Yocto Project to use tabs in shell functions. Realize 2764*4882a593Smuzhiyun that some layers have a policy to use spaces for all indentation. 2765*4882a593Smuzhiyun 2766*4882a593Smuzhiyun- *Using Python for Complex Operations:* For more advanced processing, 2767*4882a593Smuzhiyun it is possible to use Python code during variable assignments (e.g. 2768*4882a593Smuzhiyun search and replacement on a variable). 2769*4882a593Smuzhiyun 2770*4882a593Smuzhiyun You indicate Python code using the ``${@python_code}`` syntax for the 2771*4882a593Smuzhiyun variable assignment:: 2772*4882a593Smuzhiyun 2773*4882a593Smuzhiyun SRC_URI = "ftp://ftp.info-zip.org/pub/infozip/src/zip${@d.getVar('PV',1).replace('.', '')}.tgz 2774*4882a593Smuzhiyun 2775*4882a593Smuzhiyun- *Shell Function Syntax:* Write shell functions as if you were writing 2776*4882a593Smuzhiyun a shell script when you describe a list of actions to take. You 2777*4882a593Smuzhiyun should ensure that your script works with a generic ``sh`` and that 2778*4882a593Smuzhiyun it does not require any ``bash`` or other shell-specific 2779*4882a593Smuzhiyun functionality. The same considerations apply to various system 2780*4882a593Smuzhiyun utilities (e.g. ``sed``, ``grep``, ``awk``, and so forth) that you 2781*4882a593Smuzhiyun might wish to use. If in doubt, you should check with multiple 2782*4882a593Smuzhiyun implementations - including those from BusyBox. 2783*4882a593Smuzhiyun 2784*4882a593SmuzhiyunAdding a New Machine 2785*4882a593Smuzhiyun==================== 2786*4882a593Smuzhiyun 2787*4882a593SmuzhiyunAdding a new machine to the Yocto Project is a straightforward process. 2788*4882a593SmuzhiyunThis section describes how to add machines that are similar to those 2789*4882a593Smuzhiyunthat the Yocto Project already supports. 2790*4882a593Smuzhiyun 2791*4882a593Smuzhiyun.. note:: 2792*4882a593Smuzhiyun 2793*4882a593Smuzhiyun Although well within the capabilities of the Yocto Project, adding a 2794*4882a593Smuzhiyun totally new architecture might require changes to ``gcc``/``glibc`` 2795*4882a593Smuzhiyun and to the site information, which is beyond the scope of this 2796*4882a593Smuzhiyun manual. 2797*4882a593Smuzhiyun 2798*4882a593SmuzhiyunFor a complete example that shows how to add a new machine, see the 2799*4882a593Smuzhiyun":ref:`bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script`" 2800*4882a593Smuzhiyunsection in the Yocto Project Board Support Package (BSP) Developer's 2801*4882a593SmuzhiyunGuide. 2802*4882a593Smuzhiyun 2803*4882a593SmuzhiyunAdding the Machine Configuration File 2804*4882a593Smuzhiyun------------------------------------- 2805*4882a593Smuzhiyun 2806*4882a593SmuzhiyunTo add a new machine, you need to add a new machine configuration file 2807*4882a593Smuzhiyunto the layer's ``conf/machine`` directory. This configuration file 2808*4882a593Smuzhiyunprovides details about the device you are adding. 2809*4882a593Smuzhiyun 2810*4882a593SmuzhiyunThe OpenEmbedded build system uses the root name of the machine 2811*4882a593Smuzhiyunconfiguration file to reference the new machine. For example, given a 2812*4882a593Smuzhiyunmachine configuration file named ``crownbay.conf``, the build system 2813*4882a593Smuzhiyunrecognizes the machine as "crownbay". 2814*4882a593Smuzhiyun 2815*4882a593SmuzhiyunThe most important variables you must set in your machine configuration 2816*4882a593Smuzhiyunfile or include from a lower-level configuration file are as follows: 2817*4882a593Smuzhiyun 2818*4882a593Smuzhiyun- :term:`TARGET_ARCH` (e.g. "arm") 2819*4882a593Smuzhiyun 2820*4882a593Smuzhiyun- ``PREFERRED_PROVIDER_virtual/kernel`` 2821*4882a593Smuzhiyun 2822*4882a593Smuzhiyun- :term:`MACHINE_FEATURES` (e.g. "apm screen wifi") 2823*4882a593Smuzhiyun 2824*4882a593SmuzhiyunYou might also need these variables: 2825*4882a593Smuzhiyun 2826*4882a593Smuzhiyun- :term:`SERIAL_CONSOLES` (e.g. "115200;ttyS0 115200;ttyS1") 2827*4882a593Smuzhiyun 2828*4882a593Smuzhiyun- :term:`KERNEL_IMAGETYPE` (e.g. "zImage") 2829*4882a593Smuzhiyun 2830*4882a593Smuzhiyun- :term:`IMAGE_FSTYPES` (e.g. "tar.gz jffs2") 2831*4882a593Smuzhiyun 2832*4882a593SmuzhiyunYou can find full details on these variables in the reference section. 2833*4882a593SmuzhiyunYou can leverage existing machine ``.conf`` files from 2834*4882a593Smuzhiyun``meta-yocto-bsp/conf/machine/``. 2835*4882a593Smuzhiyun 2836*4882a593SmuzhiyunAdding a Kernel for the Machine 2837*4882a593Smuzhiyun------------------------------- 2838*4882a593Smuzhiyun 2839*4882a593SmuzhiyunThe OpenEmbedded build system needs to be able to build a kernel for the 2840*4882a593Smuzhiyunmachine. You need to either create a new kernel recipe for this machine, 2841*4882a593Smuzhiyunor extend an existing kernel recipe. You can find several kernel recipe 2842*4882a593Smuzhiyunexamples in the Source Directory at ``meta/recipes-kernel/linux`` that 2843*4882a593Smuzhiyunyou can use as references. 2844*4882a593Smuzhiyun 2845*4882a593SmuzhiyunIf you are creating a new kernel recipe, normal recipe-writing rules 2846*4882a593Smuzhiyunapply for setting up a :term:`SRC_URI`. Thus, you need to specify any 2847*4882a593Smuzhiyunnecessary patches and set :term:`S` to point at the source code. You need to 2848*4882a593Smuzhiyuncreate a ``do_configure`` task that configures the unpacked kernel with 2849*4882a593Smuzhiyuna ``defconfig`` file. You can do this by using a ``make defconfig`` 2850*4882a593Smuzhiyuncommand or, more commonly, by copying in a suitable ``defconfig`` file 2851*4882a593Smuzhiyunand then running ``make oldconfig``. By making use of ``inherit kernel`` 2852*4882a593Smuzhiyunand potentially some of the ``linux-*.inc`` files, most other 2853*4882a593Smuzhiyunfunctionality is centralized and the defaults of the class normally work 2854*4882a593Smuzhiyunwell. 2855*4882a593Smuzhiyun 2856*4882a593SmuzhiyunIf you are extending an existing kernel recipe, it is usually a matter 2857*4882a593Smuzhiyunof adding a suitable ``defconfig`` file. The file needs to be added into 2858*4882a593Smuzhiyuna location similar to ``defconfig`` files used for other machines in a 2859*4882a593Smuzhiyungiven kernel recipe. A possible way to do this is by listing the file in 2860*4882a593Smuzhiyunthe :term:`SRC_URI` and adding the machine to the expression in 2861*4882a593Smuzhiyun:term:`COMPATIBLE_MACHINE`:: 2862*4882a593Smuzhiyun 2863*4882a593Smuzhiyun COMPATIBLE_MACHINE = '(qemux86|qemumips)' 2864*4882a593Smuzhiyun 2865*4882a593SmuzhiyunFor more information on ``defconfig`` files, see the 2866*4882a593Smuzhiyun":ref:`kernel-dev/common:changing the configuration`" 2867*4882a593Smuzhiyunsection in the Yocto Project Linux Kernel Development Manual. 2868*4882a593Smuzhiyun 2869*4882a593SmuzhiyunAdding a Formfactor Configuration File 2870*4882a593Smuzhiyun-------------------------------------- 2871*4882a593Smuzhiyun 2872*4882a593SmuzhiyunA formfactor configuration file provides information about the target 2873*4882a593Smuzhiyunhardware for which the image is being built and information that the 2874*4882a593Smuzhiyunbuild system cannot obtain from other sources such as the kernel. Some 2875*4882a593Smuzhiyunexamples of information contained in a formfactor configuration file 2876*4882a593Smuzhiyuninclude framebuffer orientation, whether or not the system has a 2877*4882a593Smuzhiyunkeyboard, the positioning of the keyboard in relation to the screen, and 2878*4882a593Smuzhiyunthe screen resolution. 2879*4882a593Smuzhiyun 2880*4882a593SmuzhiyunThe build system uses reasonable defaults in most cases. However, if 2881*4882a593Smuzhiyuncustomization is necessary, you need to create a ``machconfig`` file in 2882*4882a593Smuzhiyunthe ``meta/recipes-bsp/formfactor/files`` directory. This directory 2883*4882a593Smuzhiyuncontains directories for specific machines such as ``qemuarm`` and 2884*4882a593Smuzhiyun``qemux86``. For information about the settings available and the 2885*4882a593Smuzhiyundefaults, see the ``meta/recipes-bsp/formfactor/files/config`` file 2886*4882a593Smuzhiyunfound in the same area. 2887*4882a593Smuzhiyun 2888*4882a593SmuzhiyunFollowing is an example for "qemuarm" machine:: 2889*4882a593Smuzhiyun 2890*4882a593Smuzhiyun HAVE_TOUCHSCREEN=1 2891*4882a593Smuzhiyun HAVE_KEYBOARD=1 2892*4882a593Smuzhiyun DISPLAY_CAN_ROTATE=0 2893*4882a593Smuzhiyun DISPLAY_ORIENTATION=0 2894*4882a593Smuzhiyun #DISPLAY_WIDTH_PIXELS=640 2895*4882a593Smuzhiyun #DISPLAY_HEIGHT_PIXELS=480 2896*4882a593Smuzhiyun #DISPLAY_BPP=16 2897*4882a593Smuzhiyun DISPLAY_DPI=150 2898*4882a593Smuzhiyun DISPLAY_SUBPIXEL_ORDER=vrgb 2899*4882a593Smuzhiyun 2900*4882a593SmuzhiyunUpgrading Recipes 2901*4882a593Smuzhiyun================= 2902*4882a593Smuzhiyun 2903*4882a593SmuzhiyunOver time, upstream developers publish new versions for software built 2904*4882a593Smuzhiyunby layer recipes. It is recommended to keep recipes up-to-date with 2905*4882a593Smuzhiyunupstream version releases. 2906*4882a593Smuzhiyun 2907*4882a593SmuzhiyunWhile there are several methods to upgrade a recipe, you might 2908*4882a593Smuzhiyunconsider checking on the upgrade status of a recipe first. You can do so 2909*4882a593Smuzhiyunusing the ``devtool check-upgrade-status`` command. See the 2910*4882a593Smuzhiyun":ref:`devtool-checking-on-the-upgrade-status-of-a-recipe`" 2911*4882a593Smuzhiyunsection in the Yocto Project Reference Manual for more information. 2912*4882a593Smuzhiyun 2913*4882a593SmuzhiyunThe remainder of this section describes three ways you can upgrade a 2914*4882a593Smuzhiyunrecipe. You can use the Automated Upgrade Helper (AUH) to set up 2915*4882a593Smuzhiyunautomatic version upgrades. Alternatively, you can use 2916*4882a593Smuzhiyun``devtool upgrade`` to set up semi-automatic version upgrades. Finally, 2917*4882a593Smuzhiyunyou can manually upgrade a recipe by editing the recipe itself. 2918*4882a593Smuzhiyun 2919*4882a593SmuzhiyunUsing the Auto Upgrade Helper (AUH) 2920*4882a593Smuzhiyun----------------------------------- 2921*4882a593Smuzhiyun 2922*4882a593SmuzhiyunThe AUH utility works in conjunction with the OpenEmbedded build system 2923*4882a593Smuzhiyunin order to automatically generate upgrades for recipes based on new 2924*4882a593Smuzhiyunversions being published upstream. Use AUH when you want to create a 2925*4882a593Smuzhiyunservice that performs the upgrades automatically and optionally sends 2926*4882a593Smuzhiyunyou an email with the results. 2927*4882a593Smuzhiyun 2928*4882a593SmuzhiyunAUH allows you to update several recipes with a single use. You can also 2929*4882a593Smuzhiyunoptionally perform build and integration tests using images with the 2930*4882a593Smuzhiyunresults saved to your hard drive and emails of results optionally sent 2931*4882a593Smuzhiyunto recipe maintainers. Finally, AUH creates Git commits with appropriate 2932*4882a593Smuzhiyuncommit messages in the layer's tree for the changes made to recipes. 2933*4882a593Smuzhiyun 2934*4882a593Smuzhiyun.. note:: 2935*4882a593Smuzhiyun 2936*4882a593Smuzhiyun In some conditions, you should not use AUH to upgrade recipes 2937*4882a593Smuzhiyun and should instead use either ``devtool upgrade`` or upgrade your 2938*4882a593Smuzhiyun recipes manually: 2939*4882a593Smuzhiyun 2940*4882a593Smuzhiyun - When AUH cannot complete the upgrade sequence. This situation 2941*4882a593Smuzhiyun usually results because custom patches carried by the recipe 2942*4882a593Smuzhiyun cannot be automatically rebased to the new version. In this case, 2943*4882a593Smuzhiyun ``devtool upgrade`` allows you to manually resolve conflicts. 2944*4882a593Smuzhiyun 2945*4882a593Smuzhiyun - When for any reason you want fuller control over the upgrade 2946*4882a593Smuzhiyun process. For example, when you want special arrangements for 2947*4882a593Smuzhiyun testing. 2948*4882a593Smuzhiyun 2949*4882a593SmuzhiyunThe following steps describe how to set up the AUH utility: 2950*4882a593Smuzhiyun 2951*4882a593Smuzhiyun1. *Be Sure the Development Host is Set Up:* You need to be sure that 2952*4882a593Smuzhiyun your development host is set up to use the Yocto Project. For 2953*4882a593Smuzhiyun information on how to set up your host, see the 2954*4882a593Smuzhiyun ":ref:`dev-manual/start:Preparing the Build Host`" section. 2955*4882a593Smuzhiyun 2956*4882a593Smuzhiyun2. *Make Sure Git is Configured:* The AUH utility requires Git to be 2957*4882a593Smuzhiyun configured because AUH uses Git to save upgrades. Thus, you must have 2958*4882a593Smuzhiyun Git user and email configured. The following command shows your 2959*4882a593Smuzhiyun configurations:: 2960*4882a593Smuzhiyun 2961*4882a593Smuzhiyun $ git config --list 2962*4882a593Smuzhiyun 2963*4882a593Smuzhiyun If you do not have the user and 2964*4882a593Smuzhiyun email configured, you can use the following commands to do so:: 2965*4882a593Smuzhiyun 2966*4882a593Smuzhiyun $ git config --global user.name some_name 2967*4882a593Smuzhiyun $ git config --global user.email username@domain.com 2968*4882a593Smuzhiyun 2969*4882a593Smuzhiyun3. *Clone the AUH Repository:* To use AUH, you must clone the repository 2970*4882a593Smuzhiyun onto your development host. The following command uses Git to create 2971*4882a593Smuzhiyun a local copy of the repository on your system:: 2972*4882a593Smuzhiyun 2973*4882a593Smuzhiyun $ git clone git://git.yoctoproject.org/auto-upgrade-helper 2974*4882a593Smuzhiyun Cloning into 'auto-upgrade-helper'... remote: Counting objects: 768, done. 2975*4882a593Smuzhiyun remote: Compressing objects: 100% (300/300), done. 2976*4882a593Smuzhiyun remote: Total 768 (delta 499), reused 703 (delta 434) 2977*4882a593Smuzhiyun Receiving objects: 100% (768/768), 191.47 KiB | 98.00 KiB/s, done. 2978*4882a593Smuzhiyun Resolving deltas: 100% (499/499), done. 2979*4882a593Smuzhiyun Checking connectivity... done. 2980*4882a593Smuzhiyun 2981*4882a593Smuzhiyun AUH is not part of the :term:`OpenEmbedded-Core (OE-Core)` or 2982*4882a593Smuzhiyun :term:`Poky` repositories. 2983*4882a593Smuzhiyun 2984*4882a593Smuzhiyun4. *Create a Dedicated Build Directory:* Run the 2985*4882a593Smuzhiyun :ref:`structure-core-script` 2986*4882a593Smuzhiyun script to create a fresh build directory that you use exclusively for 2987*4882a593Smuzhiyun running the AUH utility:: 2988*4882a593Smuzhiyun 2989*4882a593Smuzhiyun $ cd poky 2990*4882a593Smuzhiyun $ source oe-init-build-env your_AUH_build_directory 2991*4882a593Smuzhiyun 2992*4882a593Smuzhiyun Re-using an existing build directory and its configurations is not 2993*4882a593Smuzhiyun recommended as existing settings could cause AUH to fail or behave 2994*4882a593Smuzhiyun undesirably. 2995*4882a593Smuzhiyun 2996*4882a593Smuzhiyun5. *Make Configurations in Your Local Configuration File:* Several 2997*4882a593Smuzhiyun settings are needed in the ``local.conf`` file in the build 2998*4882a593Smuzhiyun directory you just created for AUH. Make these following 2999*4882a593Smuzhiyun configurations: 3000*4882a593Smuzhiyun 3001*4882a593Smuzhiyun - If you want to enable :ref:`Build 3002*4882a593Smuzhiyun History <dev-manual/common-tasks:maintaining build output quality>`, 3003*4882a593Smuzhiyun which is optional, you need the following lines in the 3004*4882a593Smuzhiyun ``conf/local.conf`` file:: 3005*4882a593Smuzhiyun 3006*4882a593Smuzhiyun INHERIT =+ "buildhistory" 3007*4882a593Smuzhiyun BUILDHISTORY_COMMIT = "1" 3008*4882a593Smuzhiyun 3009*4882a593Smuzhiyun With this configuration and a successful 3010*4882a593Smuzhiyun upgrade, a build history "diff" file appears in the 3011*4882a593Smuzhiyun ``upgrade-helper/work/recipe/buildhistory-diff.txt`` file found in 3012*4882a593Smuzhiyun your build directory. 3013*4882a593Smuzhiyun 3014*4882a593Smuzhiyun - If you want to enable testing through the 3015*4882a593Smuzhiyun :ref:`testimage <ref-classes-testimage*>` 3016*4882a593Smuzhiyun class, which is optional, you need to have the following set in 3017*4882a593Smuzhiyun your ``conf/local.conf`` file:: 3018*4882a593Smuzhiyun 3019*4882a593Smuzhiyun INHERIT += "testimage" 3020*4882a593Smuzhiyun 3021*4882a593Smuzhiyun .. note:: 3022*4882a593Smuzhiyun 3023*4882a593Smuzhiyun If your distro does not enable by default ptest, which Poky 3024*4882a593Smuzhiyun does, you need the following in your ``local.conf`` file:: 3025*4882a593Smuzhiyun 3026*4882a593Smuzhiyun DISTRO_FEATURES:append = " ptest" 3027*4882a593Smuzhiyun 3028*4882a593Smuzhiyun 3029*4882a593Smuzhiyun6. *Optionally Start a vncserver:* If you are running in a server 3030*4882a593Smuzhiyun without an X11 session, you need to start a vncserver:: 3031*4882a593Smuzhiyun 3032*4882a593Smuzhiyun $ vncserver :1 3033*4882a593Smuzhiyun $ export DISPLAY=:1 3034*4882a593Smuzhiyun 3035*4882a593Smuzhiyun7. *Create and Edit an AUH Configuration File:* You need to have the 3036*4882a593Smuzhiyun ``upgrade-helper/upgrade-helper.conf`` configuration file in your 3037*4882a593Smuzhiyun build directory. You can find a sample configuration file in the 3038*4882a593Smuzhiyun :yocto_git:`AUH source repository </auto-upgrade-helper/tree/>`. 3039*4882a593Smuzhiyun 3040*4882a593Smuzhiyun Read through the sample file and make configurations as needed. For 3041*4882a593Smuzhiyun example, if you enabled build history in your ``local.conf`` as 3042*4882a593Smuzhiyun described earlier, you must enable it in ``upgrade-helper.conf``. 3043*4882a593Smuzhiyun 3044*4882a593Smuzhiyun Also, if you are using the default ``maintainers.inc`` file supplied 3045*4882a593Smuzhiyun with Poky and located in ``meta-yocto`` and you do not set a 3046*4882a593Smuzhiyun "maintainers_whitelist" or "global_maintainer_override" in the 3047*4882a593Smuzhiyun ``upgrade-helper.conf`` configuration, and you specify "-e all" on 3048*4882a593Smuzhiyun the AUH command-line, the utility automatically sends out emails to 3049*4882a593Smuzhiyun all the default maintainers. Please avoid this. 3050*4882a593Smuzhiyun 3051*4882a593SmuzhiyunThis next set of examples describes how to use the AUH: 3052*4882a593Smuzhiyun 3053*4882a593Smuzhiyun- *Upgrading a Specific Recipe:* To upgrade a specific recipe, use the 3054*4882a593Smuzhiyun following form:: 3055*4882a593Smuzhiyun 3056*4882a593Smuzhiyun $ upgrade-helper.py recipe_name 3057*4882a593Smuzhiyun 3058*4882a593Smuzhiyun For example, this command upgrades the ``xmodmap`` recipe:: 3059*4882a593Smuzhiyun 3060*4882a593Smuzhiyun $ upgrade-helper.py xmodmap 3061*4882a593Smuzhiyun 3062*4882a593Smuzhiyun- *Upgrading a Specific Recipe to a Particular Version:* To upgrade a 3063*4882a593Smuzhiyun specific recipe to a particular version, use the following form:: 3064*4882a593Smuzhiyun 3065*4882a593Smuzhiyun $ upgrade-helper.py recipe_name -t version 3066*4882a593Smuzhiyun 3067*4882a593Smuzhiyun For example, this command upgrades the ``xmodmap`` recipe to version 1.2.3:: 3068*4882a593Smuzhiyun 3069*4882a593Smuzhiyun $ upgrade-helper.py xmodmap -t 1.2.3 3070*4882a593Smuzhiyun 3071*4882a593Smuzhiyun- *Upgrading all Recipes to the Latest Versions and Suppressing Email 3072*4882a593Smuzhiyun Notifications:* To upgrade all recipes to their most recent versions 3073*4882a593Smuzhiyun and suppress the email notifications, use the following command:: 3074*4882a593Smuzhiyun 3075*4882a593Smuzhiyun $ upgrade-helper.py all 3076*4882a593Smuzhiyun 3077*4882a593Smuzhiyun- *Upgrading all Recipes to the Latest Versions and Send Email 3078*4882a593Smuzhiyun Notifications:* To upgrade all recipes to their most recent versions 3079*4882a593Smuzhiyun and send email messages to maintainers for each attempted recipe as 3080*4882a593Smuzhiyun well as a status email, use the following command:: 3081*4882a593Smuzhiyun 3082*4882a593Smuzhiyun $ upgrade-helper.py -e all 3083*4882a593Smuzhiyun 3084*4882a593SmuzhiyunOnce you have run the AUH utility, you can find the results in the AUH 3085*4882a593Smuzhiyunbuild directory:: 3086*4882a593Smuzhiyun 3087*4882a593Smuzhiyun ${BUILDDIR}/upgrade-helper/timestamp 3088*4882a593Smuzhiyun 3089*4882a593SmuzhiyunThe AUH utility 3090*4882a593Smuzhiyunalso creates recipe update commits from successful upgrade attempts in 3091*4882a593Smuzhiyunthe layer tree. 3092*4882a593Smuzhiyun 3093*4882a593SmuzhiyunYou can easily set up to run the AUH utility on a regular basis by using 3094*4882a593Smuzhiyuna cron job. See the 3095*4882a593Smuzhiyun:yocto_git:`weeklyjob.sh </auto-upgrade-helper/tree/weeklyjob.sh>` 3096*4882a593Smuzhiyunfile distributed with the utility for an example. 3097*4882a593Smuzhiyun 3098*4882a593SmuzhiyunUsing ``devtool upgrade`` 3099*4882a593Smuzhiyun------------------------- 3100*4882a593Smuzhiyun 3101*4882a593SmuzhiyunAs mentioned earlier, an alternative method for upgrading recipes to 3102*4882a593Smuzhiyunnewer versions is to use 3103*4882a593Smuzhiyun:doc:`devtool upgrade </ref-manual/devtool-reference>`. 3104*4882a593SmuzhiyunYou can read about ``devtool upgrade`` in general in the 3105*4882a593Smuzhiyun":ref:`sdk-manual/extensible:use \`\`devtool upgrade\`\` to create a version of the recipe that supports a newer version of the software`" 3106*4882a593Smuzhiyunsection in the Yocto Project Application Development and the Extensible 3107*4882a593SmuzhiyunSoftware Development Kit (eSDK) Manual. 3108*4882a593Smuzhiyun 3109*4882a593SmuzhiyunTo see all the command-line options available with ``devtool upgrade``, 3110*4882a593Smuzhiyunuse the following help command:: 3111*4882a593Smuzhiyun 3112*4882a593Smuzhiyun $ devtool upgrade -h 3113*4882a593Smuzhiyun 3114*4882a593SmuzhiyunIf you want to find out what version a recipe is currently at upstream 3115*4882a593Smuzhiyunwithout any attempt to upgrade your local version of the recipe, you can 3116*4882a593Smuzhiyunuse the following command:: 3117*4882a593Smuzhiyun 3118*4882a593Smuzhiyun $ devtool latest-version recipe_name 3119*4882a593Smuzhiyun 3120*4882a593SmuzhiyunAs mentioned in the previous section describing AUH, ``devtool upgrade`` 3121*4882a593Smuzhiyunworks in a less-automated manner than AUH. Specifically, 3122*4882a593Smuzhiyun``devtool upgrade`` only works on a single recipe that you name on the 3123*4882a593Smuzhiyuncommand line, cannot perform build and integration testing using images, 3124*4882a593Smuzhiyunand does not automatically generate commits for changes in the source 3125*4882a593Smuzhiyuntree. Despite all these "limitations", ``devtool upgrade`` updates the 3126*4882a593Smuzhiyunrecipe file to the new upstream version and attempts to rebase custom 3127*4882a593Smuzhiyunpatches contained by the recipe as needed. 3128*4882a593Smuzhiyun 3129*4882a593Smuzhiyun.. note:: 3130*4882a593Smuzhiyun 3131*4882a593Smuzhiyun AUH uses much of ``devtool upgrade`` behind the scenes making AUH somewhat 3132*4882a593Smuzhiyun of a "wrapper" application for ``devtool upgrade``. 3133*4882a593Smuzhiyun 3134*4882a593SmuzhiyunA typical scenario involves having used Git to clone an upstream 3135*4882a593Smuzhiyunrepository that you use during build operations. Because you have built the 3136*4882a593Smuzhiyunrecipe in the past, the layer is likely added to your 3137*4882a593Smuzhiyunconfiguration already. If for some reason, the layer is not added, you 3138*4882a593Smuzhiyuncould add it easily using the 3139*4882a593Smuzhiyun":ref:`bitbake-layers <bsp-guide/bsp:creating a new bsp layer using the \`\`bitbake-layers\`\` script>`" 3140*4882a593Smuzhiyunscript. For example, suppose you use the ``nano.bb`` recipe from the 3141*4882a593Smuzhiyun``meta-oe`` layer in the ``meta-openembedded`` repository. For this 3142*4882a593Smuzhiyunexample, assume that the layer has been cloned into following area:: 3143*4882a593Smuzhiyun 3144*4882a593Smuzhiyun /home/scottrif/meta-openembedded 3145*4882a593Smuzhiyun 3146*4882a593SmuzhiyunThe following command from your 3147*4882a593Smuzhiyun:term:`Build Directory` adds the layer to 3148*4882a593Smuzhiyunyour build configuration (i.e. ``${BUILDDIR}/conf/bblayers.conf``):: 3149*4882a593Smuzhiyun 3150*4882a593Smuzhiyun $ bitbake-layers add-layer /home/scottrif/meta-openembedded/meta-oe 3151*4882a593Smuzhiyun NOTE: Starting bitbake server... 3152*4882a593Smuzhiyun Parsing recipes: 100% |##########################################| Time: 0:00:55 3153*4882a593Smuzhiyun Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. 3154*4882a593Smuzhiyun Removing 12 recipes from the x86_64 sysroot: 100% |##############| Time: 0:00:00 3155*4882a593Smuzhiyun Removing 1 recipes from the x86_64_i586 sysroot: 100% |##########| Time: 0:00:00 3156*4882a593Smuzhiyun Removing 5 recipes from the i586 sysroot: 100% |#################| Time: 0:00:00 3157*4882a593Smuzhiyun Removing 5 recipes from the qemux86 sysroot: 100% |##############| Time: 0:00:00 3158*4882a593Smuzhiyun 3159*4882a593SmuzhiyunFor this example, assume that the ``nano.bb`` recipe that 3160*4882a593Smuzhiyunis upstream has a 2.9.3 version number. However, the version in the 3161*4882a593Smuzhiyunlocal repository is 2.7.4. The following command from your build 3162*4882a593Smuzhiyundirectory automatically upgrades the recipe for you: 3163*4882a593Smuzhiyun 3164*4882a593Smuzhiyun.. note:: 3165*4882a593Smuzhiyun 3166*4882a593Smuzhiyun Using the ``-V`` option is not necessary. Omitting the version number causes 3167*4882a593Smuzhiyun ``devtool upgrade`` to upgrade the recipe to the most recent version. 3168*4882a593Smuzhiyun 3169*4882a593Smuzhiyun:: 3170*4882a593Smuzhiyun 3171*4882a593Smuzhiyun $ devtool upgrade nano -V 2.9.3 3172*4882a593Smuzhiyun NOTE: Starting bitbake server... 3173*4882a593Smuzhiyun NOTE: Creating workspace layer in /home/scottrif/poky/build/workspace 3174*4882a593Smuzhiyun Parsing recipes: 100% |##########################################| Time: 0:00:46 3175*4882a593Smuzhiyun Parsing of 1431 .bb files complete (0 cached, 1431 parsed). 2040 targets, 56 skipped, 0 masked, 0 errors. 3176*4882a593Smuzhiyun NOTE: Extracting current version source... 3177*4882a593Smuzhiyun NOTE: Resolving any missing task queue dependencies 3178*4882a593Smuzhiyun . 3179*4882a593Smuzhiyun . 3180*4882a593Smuzhiyun . 3181*4882a593Smuzhiyun NOTE: Executing SetScene Tasks 3182*4882a593Smuzhiyun NOTE: Executing RunQueue Tasks 3183*4882a593Smuzhiyun NOTE: Tasks Summary: Attempted 74 tasks of which 72 didn't need to be rerun and all succeeded. 3184*4882a593Smuzhiyun Adding changed files: 100% |#####################################| Time: 0:00:00 3185*4882a593Smuzhiyun NOTE: Upgraded source extracted to /home/scottrif/poky/build/workspace/sources/nano 3186*4882a593Smuzhiyun NOTE: New recipe is /home/scottrif/poky/build/workspace/recipes/nano/nano_2.9.3.bb 3187*4882a593Smuzhiyun 3188*4882a593SmuzhiyunContinuing with this example, you can use ``devtool build`` to build the 3189*4882a593Smuzhiyunnewly upgraded recipe:: 3190*4882a593Smuzhiyun 3191*4882a593Smuzhiyun $ devtool build nano 3192*4882a593Smuzhiyun NOTE: Starting bitbake server... 3193*4882a593Smuzhiyun Loading cache: 100% |################################################################################################| Time: 0:00:01 3194*4882a593Smuzhiyun Loaded 2040 entries from dependency cache. 3195*4882a593Smuzhiyun Parsing recipes: 100% |##############################################################################################| Time: 0:00:00 3196*4882a593Smuzhiyun Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. 3197*4882a593Smuzhiyun NOTE: Resolving any missing task queue dependencies 3198*4882a593Smuzhiyun . 3199*4882a593Smuzhiyun . 3200*4882a593Smuzhiyun . 3201*4882a593Smuzhiyun NOTE: Executing SetScene Tasks 3202*4882a593Smuzhiyun NOTE: Executing RunQueue Tasks 3203*4882a593Smuzhiyun NOTE: nano: compiling from external source tree /home/scottrif/poky/build/workspace/sources/nano 3204*4882a593Smuzhiyun NOTE: Tasks Summary: Attempted 520 tasks of which 304 didn't need to be rerun and all succeeded. 3205*4882a593Smuzhiyun 3206*4882a593SmuzhiyunWithin the ``devtool upgrade`` workflow, you can 3207*4882a593Smuzhiyundeploy and test your rebuilt software. For this example, 3208*4882a593Smuzhiyunhowever, running ``devtool finish`` cleans up the workspace once the 3209*4882a593Smuzhiyunsource in your workspace is clean. This usually means using Git to stage 3210*4882a593Smuzhiyunand submit commits for the changes generated by the upgrade process. 3211*4882a593Smuzhiyun 3212*4882a593SmuzhiyunOnce the tree is clean, you can clean things up in this example with the 3213*4882a593Smuzhiyunfollowing command from the ``${BUILDDIR}/workspace/sources/nano`` 3214*4882a593Smuzhiyundirectory:: 3215*4882a593Smuzhiyun 3216*4882a593Smuzhiyun $ devtool finish nano meta-oe 3217*4882a593Smuzhiyun NOTE: Starting bitbake server... 3218*4882a593Smuzhiyun Loading cache: 100% |################################################################################################| Time: 0:00:00 3219*4882a593Smuzhiyun Loaded 2040 entries from dependency cache. 3220*4882a593Smuzhiyun Parsing recipes: 100% |##############################################################################################| Time: 0:00:01 3221*4882a593Smuzhiyun Parsing of 1432 .bb files complete (1431 cached, 1 parsed). 2041 targets, 56 skipped, 0 masked, 0 errors. 3222*4882a593Smuzhiyun NOTE: Adding new patch 0001-nano.bb-Stuff-I-changed-when-upgrading-nano.bb.patch 3223*4882a593Smuzhiyun NOTE: Updating recipe nano_2.9.3.bb 3224*4882a593Smuzhiyun NOTE: Removing file /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano/nano_2.7.4.bb 3225*4882a593Smuzhiyun NOTE: Moving recipe file to /home/scottrif/meta-openembedded/meta-oe/recipes-support/nano 3226*4882a593Smuzhiyun NOTE: Leaving source tree /home/scottrif/poky/build/workspace/sources/nano as-is; if you no longer need it then please delete it manually 3227*4882a593Smuzhiyun 3228*4882a593Smuzhiyun 3229*4882a593SmuzhiyunUsing the ``devtool finish`` command cleans up the workspace and creates a patch 3230*4882a593Smuzhiyunfile based on your commits. The tool puts all patch files back into the 3231*4882a593Smuzhiyunsource directory in a sub-directory named ``nano`` in this case. 3232*4882a593Smuzhiyun 3233*4882a593SmuzhiyunManually Upgrading a Recipe 3234*4882a593Smuzhiyun--------------------------- 3235*4882a593Smuzhiyun 3236*4882a593SmuzhiyunIf for some reason you choose not to upgrade recipes using 3237*4882a593Smuzhiyun:ref:`dev-manual/common-tasks:Using the Auto Upgrade Helper (AUH)` or 3238*4882a593Smuzhiyunby :ref:`dev-manual/common-tasks:Using \`\`devtool upgrade\`\``, 3239*4882a593Smuzhiyunyou can manually edit the recipe files to upgrade the versions. 3240*4882a593Smuzhiyun 3241*4882a593Smuzhiyun.. note:: 3242*4882a593Smuzhiyun 3243*4882a593Smuzhiyun Manually updating multiple recipes scales poorly and involves many 3244*4882a593Smuzhiyun steps. The recommendation to upgrade recipe versions is through AUH 3245*4882a593Smuzhiyun or ``devtool upgrade``, both of which automate some steps and provide 3246*4882a593Smuzhiyun guidance for others needed for the manual process. 3247*4882a593Smuzhiyun 3248*4882a593SmuzhiyunTo manually upgrade recipe versions, follow these general steps: 3249*4882a593Smuzhiyun 3250*4882a593Smuzhiyun1. *Change the Version:* Rename the recipe such that the version (i.e. 3251*4882a593Smuzhiyun the :term:`PV` part of the recipe name) 3252*4882a593Smuzhiyun changes appropriately. If the version is not part of the recipe name, 3253*4882a593Smuzhiyun change the value as it is set for :term:`PV` within the recipe itself. 3254*4882a593Smuzhiyun 3255*4882a593Smuzhiyun2. *Update* :term:`SRCREV` *if Needed*: If the source code your recipe builds 3256*4882a593Smuzhiyun is fetched from Git or some other version control system, update 3257*4882a593Smuzhiyun :term:`SRCREV` to point to the 3258*4882a593Smuzhiyun commit hash that matches the new version. 3259*4882a593Smuzhiyun 3260*4882a593Smuzhiyun3. *Build the Software:* Try to build the recipe using BitBake. Typical 3261*4882a593Smuzhiyun build failures include the following: 3262*4882a593Smuzhiyun 3263*4882a593Smuzhiyun - License statements were updated for the new version. For this 3264*4882a593Smuzhiyun case, you need to review any changes to the license and update the 3265*4882a593Smuzhiyun values of :term:`LICENSE` and 3266*4882a593Smuzhiyun :term:`LIC_FILES_CHKSUM` 3267*4882a593Smuzhiyun as needed. 3268*4882a593Smuzhiyun 3269*4882a593Smuzhiyun .. note:: 3270*4882a593Smuzhiyun 3271*4882a593Smuzhiyun License changes are often inconsequential. For example, the 3272*4882a593Smuzhiyun license text's copyright year might have changed. 3273*4882a593Smuzhiyun 3274*4882a593Smuzhiyun - Custom patches carried by the older version of the recipe might 3275*4882a593Smuzhiyun fail to apply to the new version. For these cases, you need to 3276*4882a593Smuzhiyun review the failures. Patches might not be necessary for the new 3277*4882a593Smuzhiyun version of the software if the upgraded version has fixed those 3278*4882a593Smuzhiyun issues. If a patch is necessary and failing, you need to rebase it 3279*4882a593Smuzhiyun into the new version. 3280*4882a593Smuzhiyun 3281*4882a593Smuzhiyun4. *Optionally Attempt to Build for Several Architectures:* Once you 3282*4882a593Smuzhiyun successfully build the new software for a given architecture, you 3283*4882a593Smuzhiyun could test the build for other architectures by changing the 3284*4882a593Smuzhiyun :term:`MACHINE` variable and 3285*4882a593Smuzhiyun rebuilding the software. This optional step is especially important 3286*4882a593Smuzhiyun if the recipe is to be released publicly. 3287*4882a593Smuzhiyun 3288*4882a593Smuzhiyun5. *Check the Upstream Change Log or Release Notes:* Checking both these 3289*4882a593Smuzhiyun reveals if there are new features that could break 3290*4882a593Smuzhiyun backwards-compatibility. If so, you need to take steps to mitigate or 3291*4882a593Smuzhiyun eliminate that situation. 3292*4882a593Smuzhiyun 3293*4882a593Smuzhiyun6. *Optionally Create a Bootable Image and Test:* If you want, you can 3294*4882a593Smuzhiyun test the new software by booting it onto actual hardware. 3295*4882a593Smuzhiyun 3296*4882a593Smuzhiyun7. *Create a Commit with the Change in the Layer Repository:* After all 3297*4882a593Smuzhiyun builds work and any testing is successful, you can create commits for 3298*4882a593Smuzhiyun any changes in the layer holding your upgraded recipe. 3299*4882a593Smuzhiyun 3300*4882a593SmuzhiyunFinding Temporary Source Code 3301*4882a593Smuzhiyun============================= 3302*4882a593Smuzhiyun 3303*4882a593SmuzhiyunYou might find it helpful during development to modify the temporary 3304*4882a593Smuzhiyunsource code used by recipes to build packages. For example, suppose you 3305*4882a593Smuzhiyunare developing a patch and you need to experiment a bit to figure out 3306*4882a593Smuzhiyunyour solution. After you have initially built the package, you can 3307*4882a593Smuzhiyuniteratively tweak the source code, which is located in the 3308*4882a593Smuzhiyun:term:`Build Directory`, and then you can 3309*4882a593Smuzhiyunforce a re-compile and quickly test your altered code. Once you settle 3310*4882a593Smuzhiyunon a solution, you can then preserve your changes in the form of 3311*4882a593Smuzhiyunpatches. 3312*4882a593Smuzhiyun 3313*4882a593SmuzhiyunDuring a build, the unpacked temporary source code used by recipes to 3314*4882a593Smuzhiyunbuild packages is available in the Build Directory as defined by the 3315*4882a593Smuzhiyun:term:`S` variable. Below is the default 3316*4882a593Smuzhiyunvalue for the :term:`S` variable as defined in the 3317*4882a593Smuzhiyun``meta/conf/bitbake.conf`` configuration file in the 3318*4882a593Smuzhiyun:term:`Source Directory`:: 3319*4882a593Smuzhiyun 3320*4882a593Smuzhiyun S = "${WORKDIR}/${BP}" 3321*4882a593Smuzhiyun 3322*4882a593SmuzhiyunYou should be aware that many recipes override the 3323*4882a593Smuzhiyun:term:`S` variable. For example, recipes that fetch their source from Git 3324*4882a593Smuzhiyunusually set :term:`S` to ``${WORKDIR}/git``. 3325*4882a593Smuzhiyun 3326*4882a593Smuzhiyun.. note:: 3327*4882a593Smuzhiyun 3328*4882a593Smuzhiyun The :term:`BP` represents the base recipe name, which consists of the name 3329*4882a593Smuzhiyun and version:: 3330*4882a593Smuzhiyun 3331*4882a593Smuzhiyun BP = "${BPN}-${PV}" 3332*4882a593Smuzhiyun 3333*4882a593Smuzhiyun 3334*4882a593SmuzhiyunThe path to the work directory for the recipe 3335*4882a593Smuzhiyun(:term:`WORKDIR`) is defined as 3336*4882a593Smuzhiyunfollows:: 3337*4882a593Smuzhiyun 3338*4882a593Smuzhiyun ${TMPDIR}/work/${MULTIMACH_TARGET_SYS}/${PN}/${EXTENDPE}${PV}-${PR} 3339*4882a593Smuzhiyun 3340*4882a593SmuzhiyunThe actual directory depends on several things: 3341*4882a593Smuzhiyun 3342*4882a593Smuzhiyun- :term:`TMPDIR`: The top-level build 3343*4882a593Smuzhiyun output directory. 3344*4882a593Smuzhiyun 3345*4882a593Smuzhiyun- :term:`MULTIMACH_TARGET_SYS`: 3346*4882a593Smuzhiyun The target system identifier. 3347*4882a593Smuzhiyun 3348*4882a593Smuzhiyun- :term:`PN`: The recipe name. 3349*4882a593Smuzhiyun 3350*4882a593Smuzhiyun- :term:`EXTENDPE`: The epoch - (if 3351*4882a593Smuzhiyun :term:`PE` is not specified, which is 3352*4882a593Smuzhiyun usually the case for most recipes, then :term:`EXTENDPE` is blank). 3353*4882a593Smuzhiyun 3354*4882a593Smuzhiyun- :term:`PV`: The recipe version. 3355*4882a593Smuzhiyun 3356*4882a593Smuzhiyun- :term:`PR`: The recipe revision. 3357*4882a593Smuzhiyun 3358*4882a593SmuzhiyunAs an example, assume a Source Directory top-level folder named 3359*4882a593Smuzhiyun``poky``, a default Build Directory at ``poky/build``, and a 3360*4882a593Smuzhiyun``qemux86-poky-linux`` machine target system. Furthermore, suppose your 3361*4882a593Smuzhiyunrecipe is named ``foo_1.3.0.bb``. In this case, the work directory the 3362*4882a593Smuzhiyunbuild system uses to build the package would be as follows:: 3363*4882a593Smuzhiyun 3364*4882a593Smuzhiyun poky/build/tmp/work/qemux86-poky-linux/foo/1.3.0-r0 3365*4882a593Smuzhiyun 3366*4882a593SmuzhiyunUsing Quilt in Your Workflow 3367*4882a593Smuzhiyun============================ 3368*4882a593Smuzhiyun 3369*4882a593Smuzhiyun`Quilt <https://savannah.nongnu.org/projects/quilt>`__ is a powerful tool 3370*4882a593Smuzhiyunthat allows you to capture source code changes without having a clean 3371*4882a593Smuzhiyunsource tree. This section outlines the typical workflow you can use to 3372*4882a593Smuzhiyunmodify source code, test changes, and then preserve the changes in the 3373*4882a593Smuzhiyunform of a patch all using Quilt. 3374*4882a593Smuzhiyun 3375*4882a593Smuzhiyun.. note:: 3376*4882a593Smuzhiyun 3377*4882a593Smuzhiyun With regard to preserving changes to source files, if you clean a 3378*4882a593Smuzhiyun recipe or have ``rm_work`` enabled, the 3379*4882a593Smuzhiyun :ref:`devtool workflow <sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow>` 3380*4882a593Smuzhiyun as described in the Yocto Project Application Development and the 3381*4882a593Smuzhiyun Extensible Software Development Kit (eSDK) manual is a safer 3382*4882a593Smuzhiyun development flow than the flow that uses Quilt. 3383*4882a593Smuzhiyun 3384*4882a593SmuzhiyunFollow these general steps: 3385*4882a593Smuzhiyun 3386*4882a593Smuzhiyun1. *Find the Source Code:* Temporary source code used by the 3387*4882a593Smuzhiyun OpenEmbedded build system is kept in the 3388*4882a593Smuzhiyun :term:`Build Directory`. See the 3389*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:finding temporary source code`" section to 3390*4882a593Smuzhiyun learn how to locate the directory that has the temporary source code for a 3391*4882a593Smuzhiyun particular package. 3392*4882a593Smuzhiyun 3393*4882a593Smuzhiyun2. *Change Your Working Directory:* You need to be in the directory that 3394*4882a593Smuzhiyun has the temporary source code. That directory is defined by the 3395*4882a593Smuzhiyun :term:`S` variable. 3396*4882a593Smuzhiyun 3397*4882a593Smuzhiyun3. *Create a New Patch:* Before modifying source code, you need to 3398*4882a593Smuzhiyun create a new patch. To create a new patch file, use ``quilt new`` as 3399*4882a593Smuzhiyun below:: 3400*4882a593Smuzhiyun 3401*4882a593Smuzhiyun $ quilt new my_changes.patch 3402*4882a593Smuzhiyun 3403*4882a593Smuzhiyun4. *Notify Quilt and Add Files:* After creating the patch, you need to 3404*4882a593Smuzhiyun notify Quilt about the files you plan to edit. You notify Quilt by 3405*4882a593Smuzhiyun adding the files to the patch you just created:: 3406*4882a593Smuzhiyun 3407*4882a593Smuzhiyun $ quilt add file1.c file2.c file3.c 3408*4882a593Smuzhiyun 3409*4882a593Smuzhiyun5. *Edit the Files:* Make your changes in the source code to the files 3410*4882a593Smuzhiyun you added to the patch. 3411*4882a593Smuzhiyun 3412*4882a593Smuzhiyun6. *Test Your Changes:* Once you have modified the source code, the 3413*4882a593Smuzhiyun easiest way to test your changes is by calling the ``do_compile`` 3414*4882a593Smuzhiyun task as shown in the following example:: 3415*4882a593Smuzhiyun 3416*4882a593Smuzhiyun $ bitbake -c compile -f package 3417*4882a593Smuzhiyun 3418*4882a593Smuzhiyun The ``-f`` or ``--force`` option forces the specified task to 3419*4882a593Smuzhiyun execute. If you find problems with your code, you can just keep 3420*4882a593Smuzhiyun editing and re-testing iteratively until things work as expected. 3421*4882a593Smuzhiyun 3422*4882a593Smuzhiyun .. note:: 3423*4882a593Smuzhiyun 3424*4882a593Smuzhiyun All the modifications you make to the temporary source code disappear 3425*4882a593Smuzhiyun once you run the ``do_clean`` or ``do_cleanall`` tasks using BitBake 3426*4882a593Smuzhiyun (i.e. ``bitbake -c clean package`` and ``bitbake -c cleanall package``). 3427*4882a593Smuzhiyun Modifications will also disappear if you use the ``rm_work`` feature as 3428*4882a593Smuzhiyun described in the 3429*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:conserving disk space during builds`" 3430*4882a593Smuzhiyun section. 3431*4882a593Smuzhiyun 3432*4882a593Smuzhiyun7. *Generate the Patch:* Once your changes work as expected, you need to 3433*4882a593Smuzhiyun use Quilt to generate the final patch that contains all your 3434*4882a593Smuzhiyun modifications. 3435*4882a593Smuzhiyun :: 3436*4882a593Smuzhiyun 3437*4882a593Smuzhiyun $ quilt refresh 3438*4882a593Smuzhiyun 3439*4882a593Smuzhiyun At this point, the 3440*4882a593Smuzhiyun ``my_changes.patch`` file has all your edits made to the ``file1.c``, 3441*4882a593Smuzhiyun ``file2.c``, and ``file3.c`` files. 3442*4882a593Smuzhiyun 3443*4882a593Smuzhiyun You can find the resulting patch file in the ``patches/`` 3444*4882a593Smuzhiyun subdirectory of the source (:term:`S`) directory. 3445*4882a593Smuzhiyun 3446*4882a593Smuzhiyun8. *Copy the Patch File:* For simplicity, copy the patch file into a 3447*4882a593Smuzhiyun directory named ``files``, which you can create in the same directory 3448*4882a593Smuzhiyun that holds the recipe (``.bb``) file or the append (``.bbappend``) 3449*4882a593Smuzhiyun file. Placing the patch here guarantees that the OpenEmbedded build 3450*4882a593Smuzhiyun system will find the patch. Next, add the patch into the :term:`SRC_URI` 3451*4882a593Smuzhiyun of the recipe. Here is an example:: 3452*4882a593Smuzhiyun 3453*4882a593Smuzhiyun SRC_URI += "file://my_changes.patch" 3454*4882a593Smuzhiyun 3455*4882a593SmuzhiyunUsing a Development Shell 3456*4882a593Smuzhiyun========================= 3457*4882a593Smuzhiyun 3458*4882a593SmuzhiyunWhen debugging certain commands or even when just editing packages, 3459*4882a593Smuzhiyun``devshell`` can be a useful tool. When you invoke ``devshell``, all 3460*4882a593Smuzhiyuntasks up to and including 3461*4882a593Smuzhiyun:ref:`ref-tasks-patch` are run for the 3462*4882a593Smuzhiyunspecified target. Then, a new terminal is opened and you are placed in 3463*4882a593Smuzhiyun``${``\ :term:`S`\ ``}``, the source 3464*4882a593Smuzhiyundirectory. In the new terminal, all the OpenEmbedded build-related 3465*4882a593Smuzhiyunenvironment variables are still defined so you can use commands such as 3466*4882a593Smuzhiyun``configure`` and ``make``. The commands execute just as if the 3467*4882a593SmuzhiyunOpenEmbedded build system were executing them. Consequently, working 3468*4882a593Smuzhiyunthis way can be helpful when debugging a build or preparing software to 3469*4882a593Smuzhiyunbe used with the OpenEmbedded build system. 3470*4882a593Smuzhiyun 3471*4882a593SmuzhiyunFollowing is an example that uses ``devshell`` on a target named 3472*4882a593Smuzhiyun``matchbox-desktop``:: 3473*4882a593Smuzhiyun 3474*4882a593Smuzhiyun $ bitbake matchbox-desktop -c devshell 3475*4882a593Smuzhiyun 3476*4882a593SmuzhiyunThis command spawns a terminal with a shell prompt within the 3477*4882a593SmuzhiyunOpenEmbedded build environment. The 3478*4882a593Smuzhiyun:term:`OE_TERMINAL` variable 3479*4882a593Smuzhiyuncontrols what type of shell is opened. 3480*4882a593Smuzhiyun 3481*4882a593SmuzhiyunFor spawned terminals, the following occurs: 3482*4882a593Smuzhiyun 3483*4882a593Smuzhiyun- The ``PATH`` variable includes the cross-toolchain. 3484*4882a593Smuzhiyun 3485*4882a593Smuzhiyun- The ``pkgconfig`` variables find the correct ``.pc`` files. 3486*4882a593Smuzhiyun 3487*4882a593Smuzhiyun- The ``configure`` command finds the Yocto Project site files as well 3488*4882a593Smuzhiyun as any other necessary files. 3489*4882a593Smuzhiyun 3490*4882a593SmuzhiyunWithin this environment, you can run configure or compile commands as if 3491*4882a593Smuzhiyunthey were being run by the OpenEmbedded build system itself. As noted 3492*4882a593Smuzhiyunearlier, the working directory also automatically changes to the Source 3493*4882a593SmuzhiyunDirectory (:term:`S`). 3494*4882a593Smuzhiyun 3495*4882a593SmuzhiyunTo manually run a specific task using ``devshell``, run the 3496*4882a593Smuzhiyuncorresponding ``run.*`` script in the 3497*4882a593Smuzhiyun``${``\ :term:`WORKDIR`\ ``}/temp`` 3498*4882a593Smuzhiyundirectory (e.g., ``run.do_configure.``\ `pid`). If a task's script does 3499*4882a593Smuzhiyunnot exist, which would be the case if the task was skipped by way of the 3500*4882a593Smuzhiyunsstate cache, you can create the task by first running it outside of the 3501*4882a593Smuzhiyun``devshell``:: 3502*4882a593Smuzhiyun 3503*4882a593Smuzhiyun $ bitbake -c task 3504*4882a593Smuzhiyun 3505*4882a593Smuzhiyun.. note:: 3506*4882a593Smuzhiyun 3507*4882a593Smuzhiyun - Execution of a task's ``run.*`` script and BitBake's execution of 3508*4882a593Smuzhiyun a task are identical. In other words, running the script re-runs 3509*4882a593Smuzhiyun the task just as it would be run using the ``bitbake -c`` command. 3510*4882a593Smuzhiyun 3511*4882a593Smuzhiyun - Any ``run.*`` file that does not have a ``.pid`` extension is a 3512*4882a593Smuzhiyun symbolic link (symlink) to the most recent version of that file. 3513*4882a593Smuzhiyun 3514*4882a593SmuzhiyunRemember, that the ``devshell`` is a mechanism that allows you to get 3515*4882a593Smuzhiyuninto the BitBake task execution environment. And as such, all commands 3516*4882a593Smuzhiyunmust be called just as BitBake would call them. That means you need to 3517*4882a593Smuzhiyunprovide the appropriate options for cross-compilation and so forth as 3518*4882a593Smuzhiyunapplicable. 3519*4882a593Smuzhiyun 3520*4882a593SmuzhiyunWhen you are finished using ``devshell``, exit the shell or close the 3521*4882a593Smuzhiyunterminal window. 3522*4882a593Smuzhiyun 3523*4882a593Smuzhiyun.. note:: 3524*4882a593Smuzhiyun 3525*4882a593Smuzhiyun - It is worth remembering that when using ``devshell`` you need to 3526*4882a593Smuzhiyun use the full compiler name such as ``arm-poky-linux-gnueabi-gcc`` 3527*4882a593Smuzhiyun instead of just using ``gcc``. The same applies to other 3528*4882a593Smuzhiyun applications such as ``binutils``, ``libtool`` and so forth. 3529*4882a593Smuzhiyun BitBake sets up environment variables such as :term:`CC` to assist 3530*4882a593Smuzhiyun applications, such as ``make`` to find the correct tools. 3531*4882a593Smuzhiyun 3532*4882a593Smuzhiyun - It is also worth noting that ``devshell`` still works over X11 3533*4882a593Smuzhiyun forwarding and similar situations. 3534*4882a593Smuzhiyun 3535*4882a593SmuzhiyunUsing a Python Development Shell 3536*4882a593Smuzhiyun================================ 3537*4882a593Smuzhiyun 3538*4882a593SmuzhiyunSimilar to working within a development shell as described in the 3539*4882a593Smuzhiyunprevious section, you can also spawn and work within an interactive 3540*4882a593SmuzhiyunPython development shell. When debugging certain commands or even when 3541*4882a593Smuzhiyunjust editing packages, ``pydevshell`` can be a useful tool. When you 3542*4882a593Smuzhiyuninvoke the ``pydevshell`` task, all tasks up to and including 3543*4882a593Smuzhiyun:ref:`ref-tasks-patch` are run for the 3544*4882a593Smuzhiyunspecified target. Then a new terminal is opened. Additionally, key 3545*4882a593SmuzhiyunPython objects and code are available in the same way they are to 3546*4882a593SmuzhiyunBitBake tasks, in particular, the data store 'd'. So, commands such as 3547*4882a593Smuzhiyunthe following are useful when exploring the data store and running 3548*4882a593Smuzhiyunfunctions:: 3549*4882a593Smuzhiyun 3550*4882a593Smuzhiyun pydevshell> d.getVar("STAGING_DIR") 3551*4882a593Smuzhiyun '/media/build1/poky/build/tmp/sysroots' 3552*4882a593Smuzhiyun pydevshell> d.getVar("STAGING_DIR", False) 3553*4882a593Smuzhiyun '${TMPDIR}/sysroots' 3554*4882a593Smuzhiyun pydevshell> d.setVar("FOO", "bar") 3555*4882a593Smuzhiyun pydevshell> d.getVar("FOO") 3556*4882a593Smuzhiyun 'bar' 3557*4882a593Smuzhiyun pydevshell> d.delVar("FOO") 3558*4882a593Smuzhiyun pydevshell> d.getVar("FOO") 3559*4882a593Smuzhiyun pydevshell> bb.build.exec_func("do_unpack", d) 3560*4882a593Smuzhiyun pydevshell> 3561*4882a593Smuzhiyun 3562*4882a593SmuzhiyunThe commands execute just as if the OpenEmbedded build 3563*4882a593Smuzhiyunsystem were executing them. Consequently, working this way can be 3564*4882a593Smuzhiyunhelpful when debugging a build or preparing software to be used with the 3565*4882a593SmuzhiyunOpenEmbedded build system. 3566*4882a593Smuzhiyun 3567*4882a593SmuzhiyunFollowing is an example that uses ``pydevshell`` on a target named 3568*4882a593Smuzhiyun``matchbox-desktop``:: 3569*4882a593Smuzhiyun 3570*4882a593Smuzhiyun $ bitbake matchbox-desktop -c pydevshell 3571*4882a593Smuzhiyun 3572*4882a593SmuzhiyunThis command spawns a terminal and places you in an interactive Python 3573*4882a593Smuzhiyuninterpreter within the OpenEmbedded build environment. The 3574*4882a593Smuzhiyun:term:`OE_TERMINAL` variable 3575*4882a593Smuzhiyuncontrols what type of shell is opened. 3576*4882a593Smuzhiyun 3577*4882a593SmuzhiyunWhen you are finished using ``pydevshell``, you can exit the shell 3578*4882a593Smuzhiyuneither by using Ctrl+d or closing the terminal window. 3579*4882a593Smuzhiyun 3580*4882a593SmuzhiyunBuilding 3581*4882a593Smuzhiyun======== 3582*4882a593Smuzhiyun 3583*4882a593SmuzhiyunThis section describes various build procedures, such as the steps 3584*4882a593Smuzhiyunneeded for a simple build, building a target for multiple configurations, 3585*4882a593Smuzhiyungenerating an image for more than one machine, and so forth. 3586*4882a593Smuzhiyun 3587*4882a593SmuzhiyunBuilding a Simple Image 3588*4882a593Smuzhiyun----------------------- 3589*4882a593Smuzhiyun 3590*4882a593SmuzhiyunIn the development environment, you need to build an image whenever you 3591*4882a593Smuzhiyunchange hardware support, add or change system libraries, or add or 3592*4882a593Smuzhiyunchange services that have dependencies. There are several methods that allow 3593*4882a593Smuzhiyunyou to build an image within the Yocto Project. This section presents 3594*4882a593Smuzhiyunthe basic steps you need to build a simple image using BitBake from a 3595*4882a593Smuzhiyunbuild host running Linux. 3596*4882a593Smuzhiyun 3597*4882a593Smuzhiyun.. note:: 3598*4882a593Smuzhiyun 3599*4882a593Smuzhiyun - For information on how to build an image using 3600*4882a593Smuzhiyun :term:`Toaster`, see the 3601*4882a593Smuzhiyun :doc:`/toaster-manual/index`. 3602*4882a593Smuzhiyun 3603*4882a593Smuzhiyun - For information on how to use ``devtool`` to build images, see the 3604*4882a593Smuzhiyun ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`" 3605*4882a593Smuzhiyun section in the Yocto Project Application Development and the 3606*4882a593Smuzhiyun Extensible Software Development Kit (eSDK) manual. 3607*4882a593Smuzhiyun 3608*4882a593Smuzhiyun - For a quick example on how to build an image using the 3609*4882a593Smuzhiyun OpenEmbedded build system, see the 3610*4882a593Smuzhiyun :doc:`/brief-yoctoprojectqs/index` document. 3611*4882a593Smuzhiyun 3612*4882a593SmuzhiyunThe build process creates an entire Linux distribution from source and 3613*4882a593Smuzhiyunplaces it in your :term:`Build Directory` under 3614*4882a593Smuzhiyun``tmp/deploy/images``. For detailed information on the build process 3615*4882a593Smuzhiyunusing BitBake, see the ":ref:`overview-manual/concepts:images`" section in the 3616*4882a593SmuzhiyunYocto Project Overview and Concepts Manual. 3617*4882a593Smuzhiyun 3618*4882a593SmuzhiyunThe following figure and list overviews the build process: 3619*4882a593Smuzhiyun 3620*4882a593Smuzhiyun.. image:: figures/bitbake-build-flow.png 3621*4882a593Smuzhiyun :align: center 3622*4882a593Smuzhiyun 3623*4882a593Smuzhiyun1. *Set up Your Host Development System to Support Development Using the 3624*4882a593Smuzhiyun Yocto Project*: See the ":doc:`start`" section for options on how to get a 3625*4882a593Smuzhiyun build host ready to use the Yocto Project. 3626*4882a593Smuzhiyun 3627*4882a593Smuzhiyun2. *Initialize the Build Environment:* Initialize the build environment 3628*4882a593Smuzhiyun by sourcing the build environment script (i.e. 3629*4882a593Smuzhiyun :ref:`structure-core-script`):: 3630*4882a593Smuzhiyun 3631*4882a593Smuzhiyun $ source oe-init-build-env [build_dir] 3632*4882a593Smuzhiyun 3633*4882a593Smuzhiyun When you use the initialization script, the OpenEmbedded build system 3634*4882a593Smuzhiyun uses ``build`` as the default :term:`Build Directory` in your current work 3635*4882a593Smuzhiyun directory. You can use a `build_dir` argument with the script to 3636*4882a593Smuzhiyun specify a different build directory. 3637*4882a593Smuzhiyun 3638*4882a593Smuzhiyun .. note:: 3639*4882a593Smuzhiyun 3640*4882a593Smuzhiyun A common practice is to use a different Build Directory for 3641*4882a593Smuzhiyun different targets; for example, ``~/build/x86`` for a ``qemux86`` 3642*4882a593Smuzhiyun target, and ``~/build/arm`` for a ``qemuarm`` target. In any 3643*4882a593Smuzhiyun event, it's typically cleaner to locate the build directory 3644*4882a593Smuzhiyun somewhere outside of your source directory. 3645*4882a593Smuzhiyun 3646*4882a593Smuzhiyun3. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the 3647*4882a593Smuzhiyun ``conf/local.conf`` configuration file, which is found in the Build 3648*4882a593Smuzhiyun Directory, is set up how you want it. This file defines many aspects 3649*4882a593Smuzhiyun of the build environment including the target machine architecture 3650*4882a593Smuzhiyun through the :term:`MACHINE` variable, the packaging format used during 3651*4882a593Smuzhiyun the build 3652*4882a593Smuzhiyun (:term:`PACKAGE_CLASSES`), 3653*4882a593Smuzhiyun and a centralized tarball download directory through the 3654*4882a593Smuzhiyun :term:`DL_DIR` variable. 3655*4882a593Smuzhiyun 3656*4882a593Smuzhiyun4. *Build the Image:* Build the image using the ``bitbake`` command:: 3657*4882a593Smuzhiyun 3658*4882a593Smuzhiyun $ bitbake target 3659*4882a593Smuzhiyun 3660*4882a593Smuzhiyun .. note:: 3661*4882a593Smuzhiyun 3662*4882a593Smuzhiyun For information on BitBake, see the :doc:`bitbake:index`. 3663*4882a593Smuzhiyun 3664*4882a593Smuzhiyun The target is the name of the recipe you want to build. Common 3665*4882a593Smuzhiyun targets are the images in ``meta/recipes-core/images``, 3666*4882a593Smuzhiyun ``meta/recipes-sato/images``, and so forth all found in the 3667*4882a593Smuzhiyun :term:`Source Directory`. Alternatively, the target 3668*4882a593Smuzhiyun can be the name of a recipe for a specific piece of software such as 3669*4882a593Smuzhiyun BusyBox. For more details about the images the OpenEmbedded build 3670*4882a593Smuzhiyun system supports, see the 3671*4882a593Smuzhiyun ":ref:`ref-manual/images:Images`" chapter in the Yocto 3672*4882a593Smuzhiyun Project Reference Manual. 3673*4882a593Smuzhiyun 3674*4882a593Smuzhiyun As an example, the following command builds the 3675*4882a593Smuzhiyun ``core-image-minimal`` image:: 3676*4882a593Smuzhiyun 3677*4882a593Smuzhiyun $ bitbake core-image-minimal 3678*4882a593Smuzhiyun 3679*4882a593Smuzhiyun Once an 3680*4882a593Smuzhiyun image has been built, it often needs to be installed. The images and 3681*4882a593Smuzhiyun kernels built by the OpenEmbedded build system are placed in the 3682*4882a593Smuzhiyun Build Directory in ``tmp/deploy/images``. For information on how to 3683*4882a593Smuzhiyun run pre-built images such as ``qemux86`` and ``qemuarm``, see the 3684*4882a593Smuzhiyun :doc:`/sdk-manual/index` manual. For 3685*4882a593Smuzhiyun information about how to install these images, see the documentation 3686*4882a593Smuzhiyun for your particular board or machine. 3687*4882a593Smuzhiyun 3688*4882a593SmuzhiyunBuilding Images for Multiple Targets Using Multiple Configurations 3689*4882a593Smuzhiyun------------------------------------------------------------------ 3690*4882a593Smuzhiyun 3691*4882a593SmuzhiyunYou can use a single ``bitbake`` command to build multiple images or 3692*4882a593Smuzhiyunpackages for different targets where each image or package requires a 3693*4882a593Smuzhiyundifferent configuration (multiple configuration builds). The builds, in 3694*4882a593Smuzhiyunthis scenario, are sometimes referred to as "multiconfigs", and this 3695*4882a593Smuzhiyunsection uses that term throughout. 3696*4882a593Smuzhiyun 3697*4882a593SmuzhiyunThis section describes how to set up for multiple configuration builds 3698*4882a593Smuzhiyunand how to account for cross-build dependencies between the 3699*4882a593Smuzhiyunmulticonfigs. 3700*4882a593Smuzhiyun 3701*4882a593SmuzhiyunSetting Up and Running a Multiple Configuration Build 3702*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3703*4882a593Smuzhiyun 3704*4882a593SmuzhiyunTo accomplish a multiple configuration build, you must define each 3705*4882a593Smuzhiyuntarget's configuration separately using a parallel configuration file in 3706*4882a593Smuzhiyunthe :term:`Build Directory`, and you 3707*4882a593Smuzhiyunmust follow a required file hierarchy. Additionally, you must enable the 3708*4882a593Smuzhiyunmultiple configuration builds in your ``local.conf`` file. 3709*4882a593Smuzhiyun 3710*4882a593SmuzhiyunFollow these steps to set up and execute multiple configuration builds: 3711*4882a593Smuzhiyun 3712*4882a593Smuzhiyun- *Create Separate Configuration Files*: You need to create a single 3713*4882a593Smuzhiyun configuration file for each build target (each multiconfig). 3714*4882a593Smuzhiyun Minimally, each configuration file must define the machine and the 3715*4882a593Smuzhiyun temporary directory BitBake uses for the build. Suggested practice 3716*4882a593Smuzhiyun dictates that you do not overlap the temporary directories used 3717*4882a593Smuzhiyun during the builds. However, it is possible that you can share the 3718*4882a593Smuzhiyun temporary directory 3719*4882a593Smuzhiyun (:term:`TMPDIR`). For example, 3720*4882a593Smuzhiyun consider a scenario with two different multiconfigs for the same 3721*4882a593Smuzhiyun :term:`MACHINE`: "qemux86" built 3722*4882a593Smuzhiyun for two distributions such as "poky" and "poky-lsb". In this case, 3723*4882a593Smuzhiyun you might want to use the same :term:`TMPDIR`. 3724*4882a593Smuzhiyun 3725*4882a593Smuzhiyun Here is an example showing the minimal statements needed in a 3726*4882a593Smuzhiyun configuration file for a "qemux86" target whose temporary build 3727*4882a593Smuzhiyun directory is ``tmpmultix86``:: 3728*4882a593Smuzhiyun 3729*4882a593Smuzhiyun MACHINE = "qemux86" 3730*4882a593Smuzhiyun TMPDIR = "${TOPDIR}/tmpmultix86" 3731*4882a593Smuzhiyun 3732*4882a593Smuzhiyun The location for these multiconfig configuration files is specific. 3733*4882a593Smuzhiyun They must reside in the current build directory in a sub-directory of 3734*4882a593Smuzhiyun ``conf`` named ``multiconfig``. Following is an example that defines 3735*4882a593Smuzhiyun two configuration files for the "x86" and "arm" multiconfigs: 3736*4882a593Smuzhiyun 3737*4882a593Smuzhiyun .. image:: figures/multiconfig_files.png 3738*4882a593Smuzhiyun :align: center 3739*4882a593Smuzhiyun 3740*4882a593Smuzhiyun The reason for this required file hierarchy is because the :term:`BBPATH` 3741*4882a593Smuzhiyun variable is not constructed until the layers are parsed. 3742*4882a593Smuzhiyun Consequently, using the configuration file as a pre-configuration 3743*4882a593Smuzhiyun file is not possible unless it is located in the current working 3744*4882a593Smuzhiyun directory. 3745*4882a593Smuzhiyun 3746*4882a593Smuzhiyun- *Add the BitBake Multi-configuration Variable to the Local 3747*4882a593Smuzhiyun Configuration File*: Use the 3748*4882a593Smuzhiyun :term:`BBMULTICONFIG` 3749*4882a593Smuzhiyun variable in your ``conf/local.conf`` configuration file to specify 3750*4882a593Smuzhiyun each multiconfig. Continuing with the example from the previous 3751*4882a593Smuzhiyun figure, the :term:`BBMULTICONFIG` variable needs to enable two 3752*4882a593Smuzhiyun multiconfigs: "x86" and "arm" by specifying each configuration file:: 3753*4882a593Smuzhiyun 3754*4882a593Smuzhiyun BBMULTICONFIG = "x86 arm" 3755*4882a593Smuzhiyun 3756*4882a593Smuzhiyun .. note:: 3757*4882a593Smuzhiyun 3758*4882a593Smuzhiyun A "default" configuration already exists by definition. This 3759*4882a593Smuzhiyun configuration is named: "" (i.e. empty string) and is defined by 3760*4882a593Smuzhiyun the variables coming from your ``local.conf`` 3761*4882a593Smuzhiyun file. Consequently, the previous example actually adds two 3762*4882a593Smuzhiyun additional configurations to your build: "arm" and "x86" along 3763*4882a593Smuzhiyun with "". 3764*4882a593Smuzhiyun 3765*4882a593Smuzhiyun- *Launch BitBake*: Use the following BitBake command form to launch 3766*4882a593Smuzhiyun the multiple configuration build:: 3767*4882a593Smuzhiyun 3768*4882a593Smuzhiyun $ bitbake [mc:multiconfigname:]target [[[mc:multiconfigname:]target] ... ] 3769*4882a593Smuzhiyun 3770*4882a593Smuzhiyun For the example in this section, the following command applies:: 3771*4882a593Smuzhiyun 3772*4882a593Smuzhiyun $ bitbake mc:x86:core-image-minimal mc:arm:core-image-sato mc::core-image-base 3773*4882a593Smuzhiyun 3774*4882a593Smuzhiyun The previous BitBake command builds a ``core-image-minimal`` image 3775*4882a593Smuzhiyun that is configured through the ``x86.conf`` configuration file, a 3776*4882a593Smuzhiyun ``core-image-sato`` image that is configured through the ``arm.conf`` 3777*4882a593Smuzhiyun configuration file and a ``core-image-base`` that is configured 3778*4882a593Smuzhiyun through your ``local.conf`` configuration file. 3779*4882a593Smuzhiyun 3780*4882a593Smuzhiyun.. note:: 3781*4882a593Smuzhiyun 3782*4882a593Smuzhiyun Support for multiple configuration builds in the Yocto Project &DISTRO; 3783*4882a593Smuzhiyun (&DISTRO_NAME;) Release does not include Shared State (sstate) 3784*4882a593Smuzhiyun optimizations. Consequently, if a build uses the same object twice 3785*4882a593Smuzhiyun in, for example, two different :term:`TMPDIR` 3786*4882a593Smuzhiyun directories, the build either loads from an existing sstate cache for 3787*4882a593Smuzhiyun that build at the start or builds the object fresh. 3788*4882a593Smuzhiyun 3789*4882a593SmuzhiyunEnabling Multiple Configuration Build Dependencies 3790*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3791*4882a593Smuzhiyun 3792*4882a593SmuzhiyunSometimes dependencies can exist between targets (multiconfigs) in a 3793*4882a593Smuzhiyunmultiple configuration build. For example, suppose that in order to 3794*4882a593Smuzhiyunbuild a ``core-image-sato`` image for an "x86" multiconfig, the root 3795*4882a593Smuzhiyunfilesystem of an "arm" multiconfig must exist. This dependency is 3796*4882a593Smuzhiyunessentially that the 3797*4882a593Smuzhiyun:ref:`ref-tasks-image` task in the 3798*4882a593Smuzhiyun``core-image-sato`` recipe depends on the completion of the 3799*4882a593Smuzhiyun:ref:`ref-tasks-rootfs` task of the 3800*4882a593Smuzhiyun``core-image-minimal`` recipe. 3801*4882a593Smuzhiyun 3802*4882a593SmuzhiyunTo enable dependencies in a multiple configuration build, you must 3803*4882a593Smuzhiyundeclare the dependencies in the recipe using the following statement 3804*4882a593Smuzhiyunform:: 3805*4882a593Smuzhiyun 3806*4882a593Smuzhiyun task_or_package[mcdepends] = "mc:from_multiconfig:to_multiconfig:recipe_name:task_on_which_to_depend" 3807*4882a593Smuzhiyun 3808*4882a593SmuzhiyunTo better show how to use this statement, consider the example scenario 3809*4882a593Smuzhiyunfrom the first paragraph of this section. The following statement needs 3810*4882a593Smuzhiyunto be added to the recipe that builds the ``core-image-sato`` image:: 3811*4882a593Smuzhiyun 3812*4882a593Smuzhiyun do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_rootfs" 3813*4882a593Smuzhiyun 3814*4882a593SmuzhiyunIn this example, the `from_multiconfig` is "x86". The `to_multiconfig` is "arm". The 3815*4882a593Smuzhiyuntask on which the ``do_image`` task in the recipe depends is the 3816*4882a593Smuzhiyun``do_rootfs`` task from the ``core-image-minimal`` recipe associated 3817*4882a593Smuzhiyunwith the "arm" multiconfig. 3818*4882a593Smuzhiyun 3819*4882a593SmuzhiyunOnce you set up this dependency, you can build the "x86" multiconfig 3820*4882a593Smuzhiyunusing a BitBake command as follows:: 3821*4882a593Smuzhiyun 3822*4882a593Smuzhiyun $ bitbake mc:x86:core-image-sato 3823*4882a593Smuzhiyun 3824*4882a593SmuzhiyunThis command executes all the tasks needed to create the 3825*4882a593Smuzhiyun``core-image-sato`` image for the "x86" multiconfig. Because of the 3826*4882a593Smuzhiyundependency, BitBake also executes through the ``do_rootfs`` task for the 3827*4882a593Smuzhiyun"arm" multiconfig build. 3828*4882a593Smuzhiyun 3829*4882a593SmuzhiyunHaving a recipe depend on the root filesystem of another build might not 3830*4882a593Smuzhiyunseem that useful. Consider this change to the statement in the 3831*4882a593Smuzhiyun``core-image-sato`` recipe:: 3832*4882a593Smuzhiyun 3833*4882a593Smuzhiyun do_image[mcdepends] = "mc:x86:arm:core-image-minimal:do_image" 3834*4882a593Smuzhiyun 3835*4882a593SmuzhiyunIn this case, BitBake must 3836*4882a593Smuzhiyuncreate the ``core-image-minimal`` image for the "arm" build since the 3837*4882a593Smuzhiyun"x86" build depends on it. 3838*4882a593Smuzhiyun 3839*4882a593SmuzhiyunBecause "x86" and "arm" are enabled for multiple configuration builds 3840*4882a593Smuzhiyunand have separate configuration files, BitBake places the artifacts for 3841*4882a593Smuzhiyuneach build in the respective temporary build directories (i.e. 3842*4882a593Smuzhiyun:term:`TMPDIR`). 3843*4882a593Smuzhiyun 3844*4882a593SmuzhiyunBuilding an Initial RAM Filesystem (initramfs) Image 3845*4882a593Smuzhiyun---------------------------------------------------- 3846*4882a593Smuzhiyun 3847*4882a593SmuzhiyunAn initial RAM filesystem (initramfs) image provides a temporary root 3848*4882a593Smuzhiyunfilesystem used for early system initialization (e.g. loading of modules 3849*4882a593Smuzhiyunneeded to locate and mount the "real" root filesystem). 3850*4882a593Smuzhiyun 3851*4882a593Smuzhiyun.. note:: 3852*4882a593Smuzhiyun 3853*4882a593Smuzhiyun The initramfs image is the successor of initial RAM disk (initrd). It 3854*4882a593Smuzhiyun is a "copy in and out" (cpio) archive of the initial filesystem that 3855*4882a593Smuzhiyun gets loaded into memory during the Linux startup process. Because 3856*4882a593Smuzhiyun Linux uses the contents of the archive during initialization, the 3857*4882a593Smuzhiyun initramfs image needs to contain all of the device drivers and tools 3858*4882a593Smuzhiyun needed to mount the final root filesystem. 3859*4882a593Smuzhiyun 3860*4882a593SmuzhiyunFollow these steps to create an initramfs image: 3861*4882a593Smuzhiyun 3862*4882a593Smuzhiyun1. *Create the initramfs Image Recipe:* You can reference the 3863*4882a593Smuzhiyun ``core-image-minimal-initramfs.bb`` recipe found in the 3864*4882a593Smuzhiyun ``meta/recipes-core`` directory of the :term:`Source Directory` 3865*4882a593Smuzhiyun as an example 3866*4882a593Smuzhiyun from which to work. 3867*4882a593Smuzhiyun 3868*4882a593Smuzhiyun2. *Decide if You Need to Bundle the initramfs Image Into the Kernel 3869*4882a593Smuzhiyun Image:* If you want the initramfs image that is built to be bundled 3870*4882a593Smuzhiyun in with the kernel image, set the 3871*4882a593Smuzhiyun :term:`INITRAMFS_IMAGE_BUNDLE` 3872*4882a593Smuzhiyun variable to "1" in your ``local.conf`` configuration file and set the 3873*4882a593Smuzhiyun :term:`INITRAMFS_IMAGE` 3874*4882a593Smuzhiyun variable in the recipe that builds the kernel image. 3875*4882a593Smuzhiyun 3876*4882a593Smuzhiyun .. note:: 3877*4882a593Smuzhiyun 3878*4882a593Smuzhiyun It is recommended that you bundle the initramfs image with the 3879*4882a593Smuzhiyun kernel image to avoid circular dependencies between the kernel 3880*4882a593Smuzhiyun recipe and the initramfs recipe should the initramfs image include 3881*4882a593Smuzhiyun kernel modules. 3882*4882a593Smuzhiyun 3883*4882a593Smuzhiyun Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the initramfs 3884*4882a593Smuzhiyun image to be unpacked into the ``${B}/usr/`` directory. The unpacked 3885*4882a593Smuzhiyun initramfs image is then passed to the kernel's ``Makefile`` using the 3886*4882a593Smuzhiyun :term:`CONFIG_INITRAMFS_SOURCE` 3887*4882a593Smuzhiyun variable, allowing the initramfs image to be built into the kernel 3888*4882a593Smuzhiyun normally. 3889*4882a593Smuzhiyun 3890*4882a593Smuzhiyun .. note:: 3891*4882a593Smuzhiyun 3892*4882a593Smuzhiyun Bundling the initramfs with the kernel conflates the code in the initramfs 3893*4882a593Smuzhiyun with the GPLv2 licensed Linux kernel binary. Thus only GPLv2 compatible 3894*4882a593Smuzhiyun software may be part of a bundled initramfs. 3895*4882a593Smuzhiyun 3896*4882a593Smuzhiyun .. note:: 3897*4882a593Smuzhiyun 3898*4882a593Smuzhiyun If you choose to not bundle the initramfs image with the kernel 3899*4882a593Smuzhiyun image, you are essentially using an 3900*4882a593Smuzhiyun `Initial RAM Disk (initrd) <https://en.wikipedia.org/wiki/Initrd>`__. 3901*4882a593Smuzhiyun Creating an initrd is handled primarily through the :term:`INITRD_IMAGE`, 3902*4882a593Smuzhiyun ``INITRD_LIVE``, and ``INITRD_IMAGE_LIVE`` variables. For more 3903*4882a593Smuzhiyun information, see the :ref:`ref-classes-image-live` file. 3904*4882a593Smuzhiyun 3905*4882a593Smuzhiyun3. *Optionally Add Items to the initramfs Image Through the initramfs 3906*4882a593Smuzhiyun Image Recipe:* If you add items to the initramfs image by way of its 3907*4882a593Smuzhiyun recipe, you should use 3908*4882a593Smuzhiyun :term:`PACKAGE_INSTALL` 3909*4882a593Smuzhiyun rather than 3910*4882a593Smuzhiyun :term:`IMAGE_INSTALL`. 3911*4882a593Smuzhiyun :term:`PACKAGE_INSTALL` gives more direct control of what is added to the 3912*4882a593Smuzhiyun image as compared to the defaults you might not necessarily want that 3913*4882a593Smuzhiyun are set by the :ref:`image <ref-classes-image>` 3914*4882a593Smuzhiyun or :ref:`core-image <ref-classes-core-image>` 3915*4882a593Smuzhiyun classes. 3916*4882a593Smuzhiyun 3917*4882a593Smuzhiyun4. *Build the Kernel Image and the initramfs Image:* Build your kernel 3918*4882a593Smuzhiyun image using BitBake. Because the initramfs image recipe is a 3919*4882a593Smuzhiyun dependency of the kernel image, the initramfs image is built as well 3920*4882a593Smuzhiyun and bundled with the kernel image if you used the 3921*4882a593Smuzhiyun :term:`INITRAMFS_IMAGE_BUNDLE` 3922*4882a593Smuzhiyun variable described earlier. 3923*4882a593Smuzhiyun 3924*4882a593SmuzhiyunBundling an Initramfs Image From a Separate Multiconfig 3925*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3926*4882a593Smuzhiyun 3927*4882a593SmuzhiyunThere may be a case where we want to build an initramfs image which does not 3928*4882a593Smuzhiyuninherit the same distro policy as our main image, for example, we may want 3929*4882a593Smuzhiyunour main image to use ``TCLIBC="glibc"``, but to use ``TCLIBC="musl"`` in our initramfs 3930*4882a593Smuzhiyunimage to keep a smaller footprint. However, by performing the steps mentioned 3931*4882a593Smuzhiyunabove the initramfs image will inherit ``TCLIBC="glibc"`` without allowing us 3932*4882a593Smuzhiyunto override it. 3933*4882a593Smuzhiyun 3934*4882a593SmuzhiyunTo achieve this, you need to perform some additional steps: 3935*4882a593Smuzhiyun 3936*4882a593Smuzhiyun1. *Create a multiconfig for your initramfs image:* You can perform the steps 3937*4882a593Smuzhiyun on ":ref:`dev-manual/common-tasks:building images for multiple targets using multiple configurations`" to create a separate multiconfig. 3938*4882a593Smuzhiyun For the sake of simplicity let's assume such multiconfig is called: ``initramfscfg.conf`` and 3939*4882a593Smuzhiyun contains the variables:: 3940*4882a593Smuzhiyun 3941*4882a593Smuzhiyun TMPDIR="${TOPDIR}/tmp-initramfscfg" 3942*4882a593Smuzhiyun TCLIBC="musl" 3943*4882a593Smuzhiyun 3944*4882a593Smuzhiyun2. *Set additional initramfs variables on your main configuration:* 3945*4882a593Smuzhiyun Additionally, on your main configuration (``local.conf``) you need to set the 3946*4882a593Smuzhiyun variables:: 3947*4882a593Smuzhiyun 3948*4882a593Smuzhiyun INITRAMFS_MULTICONFIG = "initramfscfg" 3949*4882a593Smuzhiyun INITRAMFS_DEPLOY_DIR_IMAGE = "${TOPDIR}/tmp-initramfscfg/deploy/images/${MACHINE}" 3950*4882a593Smuzhiyun 3951*4882a593Smuzhiyun The variables :term:`INITRAMFS_MULTICONFIG` and :term:`INITRAMFS_DEPLOY_DIR_IMAGE` 3952*4882a593Smuzhiyun are used to create a multiconfig dependency from the kernel to the :term:`INITRAMFS_IMAGE` 3953*4882a593Smuzhiyun to be built coming from the ``initramfscfg`` multiconfig, and to let the 3954*4882a593Smuzhiyun buildsystem know where the :term:`INITRAMFS_IMAGE` will be located. 3955*4882a593Smuzhiyun 3956*4882a593Smuzhiyun Building a system with such configuration will build the kernel using the 3957*4882a593Smuzhiyun main configuration but the ``do_bundle_initramfs`` task will grab the 3958*4882a593Smuzhiyun selected :term:`INITRAMFS_IMAGE` from :term:`INITRAMFS_DEPLOY_DIR_IMAGE` 3959*4882a593Smuzhiyun instead, resulting in a musl based initramfs image bundled in the kernel 3960*4882a593Smuzhiyun but a glibc based main image. 3961*4882a593Smuzhiyun 3962*4882a593Smuzhiyun The same is applicable to avoid inheriting :term:`DISTRO_FEATURES` on :term:`INITRAMFS_IMAGE` 3963*4882a593Smuzhiyun or to build a different :term:`DISTRO` for it such as ``poky-tiny``. 3964*4882a593Smuzhiyun 3965*4882a593Smuzhiyun 3966*4882a593SmuzhiyunBuilding a Tiny System 3967*4882a593Smuzhiyun---------------------- 3968*4882a593Smuzhiyun 3969*4882a593SmuzhiyunVery small distributions have some significant advantages such as 3970*4882a593Smuzhiyunrequiring less on-die or in-package memory (cheaper), better performance 3971*4882a593Smuzhiyunthrough efficient cache usage, lower power requirements due to less 3972*4882a593Smuzhiyunmemory, faster boot times, and reduced development overhead. Some 3973*4882a593Smuzhiyunreal-world examples where a very small distribution gives you distinct 3974*4882a593Smuzhiyunadvantages are digital cameras, medical devices, and small headless 3975*4882a593Smuzhiyunsystems. 3976*4882a593Smuzhiyun 3977*4882a593SmuzhiyunThis section presents information that shows you how you can trim your 3978*4882a593Smuzhiyundistribution to even smaller sizes than the ``poky-tiny`` distribution, 3979*4882a593Smuzhiyunwhich is around 5 Mbytes, that can be built out-of-the-box using the 3980*4882a593SmuzhiyunYocto Project. 3981*4882a593Smuzhiyun 3982*4882a593SmuzhiyunTiny System Overview 3983*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~ 3984*4882a593Smuzhiyun 3985*4882a593SmuzhiyunThe following list presents the overall steps you need to consider and 3986*4882a593Smuzhiyunperform to create distributions with smaller root filesystems, achieve 3987*4882a593Smuzhiyunfaster boot times, maintain your critical functionality, and avoid 3988*4882a593Smuzhiyuninitial RAM disks: 3989*4882a593Smuzhiyun 3990*4882a593Smuzhiyun- :ref:`Determine your goals and guiding principles 3991*4882a593Smuzhiyun <dev-manual/common-tasks:goals and guiding principles>` 3992*4882a593Smuzhiyun 3993*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:understand what contributes to your image size` 3994*4882a593Smuzhiyun 3995*4882a593Smuzhiyun- :ref:`Reduce the size of the root filesystem 3996*4882a593Smuzhiyun <dev-manual/common-tasks:trim the root filesystem>` 3997*4882a593Smuzhiyun 3998*4882a593Smuzhiyun- :ref:`Reduce the size of the kernel <dev-manual/common-tasks:trim the kernel>` 3999*4882a593Smuzhiyun 4000*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:remove package management requirements` 4001*4882a593Smuzhiyun 4002*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:look for other ways to minimize size` 4003*4882a593Smuzhiyun 4004*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:iterate on the process` 4005*4882a593Smuzhiyun 4006*4882a593SmuzhiyunGoals and Guiding Principles 4007*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4008*4882a593Smuzhiyun 4009*4882a593SmuzhiyunBefore you can reach your destination, you need to know where you are 4010*4882a593Smuzhiyungoing. Here is an example list that you can use as a guide when creating 4011*4882a593Smuzhiyunvery small distributions: 4012*4882a593Smuzhiyun 4013*4882a593Smuzhiyun- Determine how much space you need (e.g. a kernel that is 1 Mbyte or 4014*4882a593Smuzhiyun less and a root filesystem that is 3 Mbytes or less). 4015*4882a593Smuzhiyun 4016*4882a593Smuzhiyun- Find the areas that are currently taking 90% of the space and 4017*4882a593Smuzhiyun concentrate on reducing those areas. 4018*4882a593Smuzhiyun 4019*4882a593Smuzhiyun- Do not create any difficult "hacks" to achieve your goals. 4020*4882a593Smuzhiyun 4021*4882a593Smuzhiyun- Leverage the device-specific options. 4022*4882a593Smuzhiyun 4023*4882a593Smuzhiyun- Work in a separate layer so that you keep changes isolated. For 4024*4882a593Smuzhiyun information on how to create layers, see the 4025*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:understanding and creating layers`" section. 4026*4882a593Smuzhiyun 4027*4882a593SmuzhiyunUnderstand What Contributes to Your Image Size 4028*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4029*4882a593Smuzhiyun 4030*4882a593SmuzhiyunIt is easiest to have something to start with when creating your own 4031*4882a593Smuzhiyundistribution. You can use the Yocto Project out-of-the-box to create the 4032*4882a593Smuzhiyun``poky-tiny`` distribution. Ultimately, you will want to make changes in 4033*4882a593Smuzhiyunyour own distribution that are likely modeled after ``poky-tiny``. 4034*4882a593Smuzhiyun 4035*4882a593Smuzhiyun.. note:: 4036*4882a593Smuzhiyun 4037*4882a593Smuzhiyun To use ``poky-tiny`` in your build, set the :term:`DISTRO` variable in your 4038*4882a593Smuzhiyun ``local.conf`` file to "poky-tiny" as described in the 4039*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:creating your own distribution`" 4040*4882a593Smuzhiyun section. 4041*4882a593Smuzhiyun 4042*4882a593SmuzhiyunUnderstanding some memory concepts will help you reduce the system size. 4043*4882a593SmuzhiyunMemory consists of static, dynamic, and temporary memory. Static memory 4044*4882a593Smuzhiyunis the TEXT (code), DATA (initialized data in the code), and BSS 4045*4882a593Smuzhiyun(uninitialized data) sections. Dynamic memory represents memory that is 4046*4882a593Smuzhiyunallocated at runtime: stacks, hash tables, and so forth. Temporary 4047*4882a593Smuzhiyunmemory is recovered after the boot process. This memory consists of 4048*4882a593Smuzhiyunmemory used for decompressing the kernel and for the ``__init__`` 4049*4882a593Smuzhiyunfunctions. 4050*4882a593Smuzhiyun 4051*4882a593SmuzhiyunTo help you see where you currently are with kernel and root filesystem 4052*4882a593Smuzhiyunsizes, you can use two tools found in the :term:`Source Directory` 4053*4882a593Smuzhiyunin the 4054*4882a593Smuzhiyun``scripts/tiny/`` directory: 4055*4882a593Smuzhiyun 4056*4882a593Smuzhiyun- ``ksize.py``: Reports component sizes for the kernel build objects. 4057*4882a593Smuzhiyun 4058*4882a593Smuzhiyun- ``dirsize.py``: Reports component sizes for the root filesystem. 4059*4882a593Smuzhiyun 4060*4882a593SmuzhiyunThis next tool and command help you organize configuration fragments and 4061*4882a593Smuzhiyunview file dependencies in a human-readable form: 4062*4882a593Smuzhiyun 4063*4882a593Smuzhiyun- ``merge_config.sh``: Helps you manage configuration files and 4064*4882a593Smuzhiyun fragments within the kernel. With this tool, you can merge individual 4065*4882a593Smuzhiyun configuration fragments together. The tool allows you to make 4066*4882a593Smuzhiyun overrides and warns you of any missing configuration options. The 4067*4882a593Smuzhiyun tool is ideal for allowing you to iterate on configurations, create 4068*4882a593Smuzhiyun minimal configurations, and create configuration files for different 4069*4882a593Smuzhiyun machines without having to duplicate your process. 4070*4882a593Smuzhiyun 4071*4882a593Smuzhiyun The ``merge_config.sh`` script is part of the Linux Yocto kernel Git 4072*4882a593Smuzhiyun repositories (i.e. ``linux-yocto-3.14``, ``linux-yocto-3.10``, 4073*4882a593Smuzhiyun ``linux-yocto-3.8``, and so forth) in the ``scripts/kconfig`` 4074*4882a593Smuzhiyun directory. 4075*4882a593Smuzhiyun 4076*4882a593Smuzhiyun For more information on configuration fragments, see the 4077*4882a593Smuzhiyun ":ref:`kernel-dev/common:creating configuration fragments`" 4078*4882a593Smuzhiyun section in the Yocto Project Linux Kernel Development Manual. 4079*4882a593Smuzhiyun 4080*4882a593Smuzhiyun- ``bitbake -u taskexp -g bitbake_target``: Using the BitBake command 4081*4882a593Smuzhiyun with these options brings up a Dependency Explorer from which you can 4082*4882a593Smuzhiyun view file dependencies. Understanding these dependencies allows you 4083*4882a593Smuzhiyun to make informed decisions when cutting out various pieces of the 4084*4882a593Smuzhiyun kernel and root filesystem. 4085*4882a593Smuzhiyun 4086*4882a593SmuzhiyunTrim the Root Filesystem 4087*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~ 4088*4882a593Smuzhiyun 4089*4882a593SmuzhiyunThe root filesystem is made up of packages for booting, libraries, and 4090*4882a593Smuzhiyunapplications. To change things, you can configure how the packaging 4091*4882a593Smuzhiyunhappens, which changes the way you build them. You can also modify the 4092*4882a593Smuzhiyunfilesystem itself or select a different filesystem. 4093*4882a593Smuzhiyun 4094*4882a593SmuzhiyunFirst, find out what is hogging your root filesystem by running the 4095*4882a593Smuzhiyun``dirsize.py`` script from your root directory:: 4096*4882a593Smuzhiyun 4097*4882a593Smuzhiyun $ cd root-directory-of-image 4098*4882a593Smuzhiyun $ dirsize.py 100000 > dirsize-100k.log 4099*4882a593Smuzhiyun $ cat dirsize-100k.log 4100*4882a593Smuzhiyun 4101*4882a593SmuzhiyunYou can apply a filter to the script to ignore files 4102*4882a593Smuzhiyununder a certain size. The previous example filters out any files below 4103*4882a593Smuzhiyun100 Kbytes. The sizes reported by the tool are uncompressed, and thus 4104*4882a593Smuzhiyunwill be smaller by a relatively constant factor in a compressed root 4105*4882a593Smuzhiyunfilesystem. When you examine your log file, you can focus on areas of 4106*4882a593Smuzhiyunthe root filesystem that take up large amounts of memory. 4107*4882a593Smuzhiyun 4108*4882a593SmuzhiyunYou need to be sure that what you eliminate does not cripple the 4109*4882a593Smuzhiyunfunctionality you need. One way to see how packages relate to each other 4110*4882a593Smuzhiyunis by using the Dependency Explorer UI with the BitBake command:: 4111*4882a593Smuzhiyun 4112*4882a593Smuzhiyun $ cd image-directory 4113*4882a593Smuzhiyun $ bitbake -u taskexp -g image 4114*4882a593Smuzhiyun 4115*4882a593SmuzhiyunUse the interface to 4116*4882a593Smuzhiyunselect potential packages you wish to eliminate and see their dependency 4117*4882a593Smuzhiyunrelationships. 4118*4882a593Smuzhiyun 4119*4882a593SmuzhiyunWhen deciding how to reduce the size, get rid of packages that result in 4120*4882a593Smuzhiyunminimal impact on the feature set. For example, you might not need a VGA 4121*4882a593Smuzhiyundisplay. Or, you might be able to get by with ``devtmpfs`` and ``mdev`` 4122*4882a593Smuzhiyuninstead of ``udev``. 4123*4882a593Smuzhiyun 4124*4882a593SmuzhiyunUse your ``local.conf`` file to make changes. For example, to eliminate 4125*4882a593Smuzhiyun``udev`` and ``glib``, set the following in the local configuration 4126*4882a593Smuzhiyunfile:: 4127*4882a593Smuzhiyun 4128*4882a593Smuzhiyun VIRTUAL-RUNTIME_dev_manager = "" 4129*4882a593Smuzhiyun 4130*4882a593SmuzhiyunFinally, you should consider exactly the type of root filesystem you 4131*4882a593Smuzhiyunneed to meet your needs while also reducing its size. For example, 4132*4882a593Smuzhiyunconsider ``cramfs``, ``squashfs``, ``ubifs``, ``ext2``, or an 4133*4882a593Smuzhiyun``initramfs`` using ``initramfs``. Be aware that ``ext3`` requires a 1 4134*4882a593SmuzhiyunMbyte journal. If you are okay with running read-only, you do not need 4135*4882a593Smuzhiyunthis journal. 4136*4882a593Smuzhiyun 4137*4882a593Smuzhiyun.. note:: 4138*4882a593Smuzhiyun 4139*4882a593Smuzhiyun After each round of elimination, you need to rebuild your system and 4140*4882a593Smuzhiyun then use the tools to see the effects of your reductions. 4141*4882a593Smuzhiyun 4142*4882a593SmuzhiyunTrim the Kernel 4143*4882a593Smuzhiyun~~~~~~~~~~~~~~~ 4144*4882a593Smuzhiyun 4145*4882a593SmuzhiyunThe kernel is built by including policies for hardware-independent 4146*4882a593Smuzhiyunaspects. What subsystems do you enable? For what architecture are you 4147*4882a593Smuzhiyunbuilding? Which drivers do you build by default? 4148*4882a593Smuzhiyun 4149*4882a593Smuzhiyun.. note:: 4150*4882a593Smuzhiyun 4151*4882a593Smuzhiyun You can modify the kernel source if you want to help with boot time. 4152*4882a593Smuzhiyun 4153*4882a593SmuzhiyunRun the ``ksize.py`` script from the top-level Linux build directory to 4154*4882a593Smuzhiyunget an idea of what is making up the kernel:: 4155*4882a593Smuzhiyun 4156*4882a593Smuzhiyun $ cd top-level-linux-build-directory 4157*4882a593Smuzhiyun $ ksize.py > ksize.log 4158*4882a593Smuzhiyun $ cat ksize.log 4159*4882a593Smuzhiyun 4160*4882a593SmuzhiyunWhen you examine the log, you will see how much space is taken up with 4161*4882a593Smuzhiyunthe built-in ``.o`` files for drivers, networking, core kernel files, 4162*4882a593Smuzhiyunfilesystem, sound, and so forth. The sizes reported by the tool are 4163*4882a593Smuzhiyununcompressed, and thus will be smaller by a relatively constant factor 4164*4882a593Smuzhiyunin a compressed kernel image. Look to reduce the areas that are large 4165*4882a593Smuzhiyunand taking up around the "90% rule." 4166*4882a593Smuzhiyun 4167*4882a593SmuzhiyunTo examine, or drill down, into any particular area, use the ``-d`` 4168*4882a593Smuzhiyunoption with the script:: 4169*4882a593Smuzhiyun 4170*4882a593Smuzhiyun $ ksize.py -d > ksize.log 4171*4882a593Smuzhiyun 4172*4882a593SmuzhiyunUsing this option 4173*4882a593Smuzhiyunbreaks out the individual file information for each area of the kernel 4174*4882a593Smuzhiyun(e.g. drivers, networking, and so forth). 4175*4882a593Smuzhiyun 4176*4882a593SmuzhiyunUse your log file to see what you can eliminate from the kernel based on 4177*4882a593Smuzhiyunfeatures you can let go. For example, if you are not going to need 4178*4882a593Smuzhiyunsound, you do not need any drivers that support sound. 4179*4882a593Smuzhiyun 4180*4882a593SmuzhiyunAfter figuring out what to eliminate, you need to reconfigure the kernel 4181*4882a593Smuzhiyunto reflect those changes during the next build. You could run 4182*4882a593Smuzhiyun``menuconfig`` and make all your changes at once. However, that makes it 4183*4882a593Smuzhiyundifficult to see the effects of your individual eliminations and also 4184*4882a593Smuzhiyunmakes it difficult to replicate the changes for perhaps another target 4185*4882a593Smuzhiyundevice. A better method is to start with no configurations using 4186*4882a593Smuzhiyun``allnoconfig``, create configuration fragments for individual changes, 4187*4882a593Smuzhiyunand then manage the fragments into a single configuration file using 4188*4882a593Smuzhiyun``merge_config.sh``. The tool makes it easy for you to iterate using the 4189*4882a593Smuzhiyunconfiguration change and build cycle. 4190*4882a593Smuzhiyun 4191*4882a593SmuzhiyunEach time you make configuration changes, you need to rebuild the kernel 4192*4882a593Smuzhiyunand check to see what impact your changes had on the overall size. 4193*4882a593Smuzhiyun 4194*4882a593SmuzhiyunRemove Package Management Requirements 4195*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4196*4882a593Smuzhiyun 4197*4882a593SmuzhiyunPackaging requirements add size to the image. One way to reduce the size 4198*4882a593Smuzhiyunof the image is to remove all the packaging requirements from the image. 4199*4882a593SmuzhiyunThis reduction includes both removing the package manager and its unique 4200*4882a593Smuzhiyundependencies as well as removing the package management data itself. 4201*4882a593Smuzhiyun 4202*4882a593SmuzhiyunTo eliminate all the packaging requirements for an image, be sure that 4203*4882a593Smuzhiyun"package-management" is not part of your 4204*4882a593Smuzhiyun:term:`IMAGE_FEATURES` 4205*4882a593Smuzhiyunstatement for the image. When you remove this feature, you are removing 4206*4882a593Smuzhiyunthe package manager as well as its dependencies from the root 4207*4882a593Smuzhiyunfilesystem. 4208*4882a593Smuzhiyun 4209*4882a593SmuzhiyunLook for Other Ways to Minimize Size 4210*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4211*4882a593Smuzhiyun 4212*4882a593SmuzhiyunDepending on your particular circumstances, other areas that you can 4213*4882a593Smuzhiyuntrim likely exist. The key to finding these areas is through tools and 4214*4882a593Smuzhiyunmethods described here combined with experimentation and iteration. Here 4215*4882a593Smuzhiyunare a couple of areas to experiment with: 4216*4882a593Smuzhiyun 4217*4882a593Smuzhiyun- ``glibc``: In general, follow this process: 4218*4882a593Smuzhiyun 4219*4882a593Smuzhiyun 1. Remove ``glibc`` features from 4220*4882a593Smuzhiyun :term:`DISTRO_FEATURES` 4221*4882a593Smuzhiyun that you think you do not need. 4222*4882a593Smuzhiyun 4223*4882a593Smuzhiyun 2. Build your distribution. 4224*4882a593Smuzhiyun 4225*4882a593Smuzhiyun 3. If the build fails due to missing symbols in a package, determine 4226*4882a593Smuzhiyun if you can reconfigure the package to not need those features. For 4227*4882a593Smuzhiyun example, change the configuration to not support wide character 4228*4882a593Smuzhiyun support as is done for ``ncurses``. Or, if support for those 4229*4882a593Smuzhiyun characters is needed, determine what ``glibc`` features provide 4230*4882a593Smuzhiyun the support and restore the configuration. 4231*4882a593Smuzhiyun 4232*4882a593Smuzhiyun 4. Rebuild and repeat the process. 4233*4882a593Smuzhiyun 4234*4882a593Smuzhiyun- ``busybox``: For BusyBox, use a process similar as described for 4235*4882a593Smuzhiyun ``glibc``. A difference is you will need to boot the resulting system 4236*4882a593Smuzhiyun to see if you are able to do everything you expect from the running 4237*4882a593Smuzhiyun system. You need to be sure to integrate configuration fragments into 4238*4882a593Smuzhiyun Busybox because BusyBox handles its own core features and then allows 4239*4882a593Smuzhiyun you to add configuration fragments on top. 4240*4882a593Smuzhiyun 4241*4882a593SmuzhiyunIterate on the Process 4242*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~ 4243*4882a593Smuzhiyun 4244*4882a593SmuzhiyunIf you have not reached your goals on system size, you need to iterate 4245*4882a593Smuzhiyunon the process. The process is the same. Use the tools and see just what 4246*4882a593Smuzhiyunis taking up 90% of the root filesystem and the kernel. Decide what you 4247*4882a593Smuzhiyuncan eliminate without limiting your device beyond what you need. 4248*4882a593Smuzhiyun 4249*4882a593SmuzhiyunDepending on your system, a good place to look might be Busybox, which 4250*4882a593Smuzhiyunprovides a stripped down version of Unix tools in a single, executable 4251*4882a593Smuzhiyunfile. You might be able to drop virtual terminal services or perhaps 4252*4882a593Smuzhiyunipv6. 4253*4882a593Smuzhiyun 4254*4882a593SmuzhiyunBuilding Images for More than One Machine 4255*4882a593Smuzhiyun----------------------------------------- 4256*4882a593Smuzhiyun 4257*4882a593SmuzhiyunA common scenario developers face is creating images for several 4258*4882a593Smuzhiyundifferent machines that use the same software environment. In this 4259*4882a593Smuzhiyunsituation, it is tempting to set the tunings and optimization flags for 4260*4882a593Smuzhiyuneach build specifically for the targeted hardware (i.e. "maxing out" the 4261*4882a593Smuzhiyuntunings). Doing so can considerably add to build times and package feed 4262*4882a593Smuzhiyunmaintenance collectively for the machines. For example, selecting tunes 4263*4882a593Smuzhiyunthat are extremely specific to a CPU core used in a system might enable 4264*4882a593Smuzhiyunsome micro optimizations in GCC for that particular system but would 4265*4882a593Smuzhiyunotherwise not gain you much of a performance difference across the other 4266*4882a593Smuzhiyunsystems as compared to using a more general tuning across all the builds 4267*4882a593Smuzhiyun(e.g. setting :term:`DEFAULTTUNE` 4268*4882a593Smuzhiyunspecifically for each machine's build). Rather than "max out" each 4269*4882a593Smuzhiyunbuild's tunings, you can take steps that cause the OpenEmbedded build 4270*4882a593Smuzhiyunsystem to reuse software across the various machines where it makes 4271*4882a593Smuzhiyunsense. 4272*4882a593Smuzhiyun 4273*4882a593SmuzhiyunIf build speed and package feed maintenance are considerations, you 4274*4882a593Smuzhiyunshould consider the points in this section that can help you optimize 4275*4882a593Smuzhiyunyour tunings to best consider build times and package feed maintenance. 4276*4882a593Smuzhiyun 4277*4882a593Smuzhiyun- *Share the Build Directory:* If at all possible, share the 4278*4882a593Smuzhiyun :term:`TMPDIR` across builds. The 4279*4882a593Smuzhiyun Yocto Project supports switching between different 4280*4882a593Smuzhiyun :term:`MACHINE` values in the same 4281*4882a593Smuzhiyun :term:`TMPDIR`. This practice is well supported and regularly used by 4282*4882a593Smuzhiyun developers when building for multiple machines. When you use the same 4283*4882a593Smuzhiyun :term:`TMPDIR` for multiple machine builds, the OpenEmbedded build system 4284*4882a593Smuzhiyun can reuse the existing native and often cross-recipes for multiple 4285*4882a593Smuzhiyun machines. Thus, build time decreases. 4286*4882a593Smuzhiyun 4287*4882a593Smuzhiyun .. note:: 4288*4882a593Smuzhiyun 4289*4882a593Smuzhiyun If :term:`DISTRO` settings change or fundamental configuration settings 4290*4882a593Smuzhiyun such as the filesystem layout, you need to work with a clean :term:`TMPDIR`. 4291*4882a593Smuzhiyun Sharing :term:`TMPDIR` under these circumstances might work but since it is 4292*4882a593Smuzhiyun not guaranteed, you should use a clean :term:`TMPDIR`. 4293*4882a593Smuzhiyun 4294*4882a593Smuzhiyun- *Enable the Appropriate Package Architecture:* By default, the 4295*4882a593Smuzhiyun OpenEmbedded build system enables three levels of package 4296*4882a593Smuzhiyun architectures: "all", "tune" or "package", and "machine". Any given 4297*4882a593Smuzhiyun recipe usually selects one of these package architectures (types) for 4298*4882a593Smuzhiyun its output. Depending for what a given recipe creates packages, 4299*4882a593Smuzhiyun making sure you enable the appropriate package architecture can 4300*4882a593Smuzhiyun directly impact the build time. 4301*4882a593Smuzhiyun 4302*4882a593Smuzhiyun A recipe that just generates scripts can enable "all" architecture 4303*4882a593Smuzhiyun because there are no binaries to build. To specifically enable "all" 4304*4882a593Smuzhiyun architecture, be sure your recipe inherits the 4305*4882a593Smuzhiyun :ref:`allarch <ref-classes-allarch>` class. 4306*4882a593Smuzhiyun This class is useful for "all" architectures because it configures 4307*4882a593Smuzhiyun many variables so packages can be used across multiple architectures. 4308*4882a593Smuzhiyun 4309*4882a593Smuzhiyun If your recipe needs to generate packages that are machine-specific 4310*4882a593Smuzhiyun or when one of the build or runtime dependencies is already 4311*4882a593Smuzhiyun machine-architecture dependent, which makes your recipe also 4312*4882a593Smuzhiyun machine-architecture dependent, make sure your recipe enables the 4313*4882a593Smuzhiyun "machine" package architecture through the 4314*4882a593Smuzhiyun :term:`MACHINE_ARCH` 4315*4882a593Smuzhiyun variable:: 4316*4882a593Smuzhiyun 4317*4882a593Smuzhiyun PACKAGE_ARCH = "${MACHINE_ARCH}" 4318*4882a593Smuzhiyun 4319*4882a593Smuzhiyun When you do not 4320*4882a593Smuzhiyun specifically enable a package architecture through the 4321*4882a593Smuzhiyun :term:`PACKAGE_ARCH`, The 4322*4882a593Smuzhiyun OpenEmbedded build system defaults to the 4323*4882a593Smuzhiyun :term:`TUNE_PKGARCH` setting:: 4324*4882a593Smuzhiyun 4325*4882a593Smuzhiyun PACKAGE_ARCH = "${TUNE_PKGARCH}" 4326*4882a593Smuzhiyun 4327*4882a593Smuzhiyun- *Choose a Generic Tuning File if Possible:* Some tunes are more 4328*4882a593Smuzhiyun generic and can run on multiple targets (e.g. an ``armv5`` set of 4329*4882a593Smuzhiyun packages could run on ``armv6`` and ``armv7`` processors in most 4330*4882a593Smuzhiyun cases). Similarly, ``i486`` binaries could work on ``i586`` and 4331*4882a593Smuzhiyun higher processors. You should realize, however, that advances on 4332*4882a593Smuzhiyun newer processor versions would not be used. 4333*4882a593Smuzhiyun 4334*4882a593Smuzhiyun If you select the same tune for several different machines, the 4335*4882a593Smuzhiyun OpenEmbedded build system reuses software previously built, thus 4336*4882a593Smuzhiyun speeding up the overall build time. Realize that even though a new 4337*4882a593Smuzhiyun sysroot for each machine is generated, the software is not recompiled 4338*4882a593Smuzhiyun and only one package feed exists. 4339*4882a593Smuzhiyun 4340*4882a593Smuzhiyun- *Manage Granular Level Packaging:* Sometimes there are cases where 4341*4882a593Smuzhiyun injecting another level of package architecture beyond the three 4342*4882a593Smuzhiyun higher levels noted earlier can be useful. For example, consider how 4343*4882a593Smuzhiyun NXP (formerly Freescale) allows for the easy reuse of binary packages 4344*4882a593Smuzhiyun in their layer 4345*4882a593Smuzhiyun :yocto_git:`meta-freescale </meta-freescale/>`. 4346*4882a593Smuzhiyun In this example, the 4347*4882a593Smuzhiyun :yocto_git:`fsl-dynamic-packagearch </meta-freescale/tree/classes/fsl-dynamic-packagearch.bbclass>` 4348*4882a593Smuzhiyun class shares GPU packages for i.MX53 boards because all boards share 4349*4882a593Smuzhiyun the AMD GPU. The i.MX6-based boards can do the same because all 4350*4882a593Smuzhiyun boards share the Vivante GPU. This class inspects the BitBake 4351*4882a593Smuzhiyun datastore to identify if the package provides or depends on one of 4352*4882a593Smuzhiyun the sub-architecture values. If so, the class sets the 4353*4882a593Smuzhiyun :term:`PACKAGE_ARCH` value 4354*4882a593Smuzhiyun based on the ``MACHINE_SUBARCH`` value. If the package does not 4355*4882a593Smuzhiyun provide or depend on one of the sub-architecture values but it 4356*4882a593Smuzhiyun matches a value in the machine-specific filter, it sets 4357*4882a593Smuzhiyun :term:`MACHINE_ARCH`. This 4358*4882a593Smuzhiyun behavior reduces the number of packages built and saves build time by 4359*4882a593Smuzhiyun reusing binaries. 4360*4882a593Smuzhiyun 4361*4882a593Smuzhiyun- *Use Tools to Debug Issues:* Sometimes you can run into situations 4362*4882a593Smuzhiyun where software is being rebuilt when you think it should not be. For 4363*4882a593Smuzhiyun example, the OpenEmbedded build system might not be using shared 4364*4882a593Smuzhiyun state between machines when you think it should be. These types of 4365*4882a593Smuzhiyun situations are usually due to references to machine-specific 4366*4882a593Smuzhiyun variables such as :term:`MACHINE`, 4367*4882a593Smuzhiyun :term:`SERIAL_CONSOLES`, 4368*4882a593Smuzhiyun :term:`XSERVER`, 4369*4882a593Smuzhiyun :term:`MACHINE_FEATURES`, 4370*4882a593Smuzhiyun and so forth in code that is supposed to only be tune-specific or 4371*4882a593Smuzhiyun when the recipe depends 4372*4882a593Smuzhiyun (:term:`DEPENDS`, 4373*4882a593Smuzhiyun :term:`RDEPENDS`, 4374*4882a593Smuzhiyun :term:`RRECOMMENDS`, 4375*4882a593Smuzhiyun :term:`RSUGGESTS`, and so forth) 4376*4882a593Smuzhiyun on some other recipe that already has 4377*4882a593Smuzhiyun :term:`PACKAGE_ARCH` defined 4378*4882a593Smuzhiyun as "${MACHINE_ARCH}". 4379*4882a593Smuzhiyun 4380*4882a593Smuzhiyun .. note:: 4381*4882a593Smuzhiyun 4382*4882a593Smuzhiyun Patches to fix any issues identified are most welcome as these 4383*4882a593Smuzhiyun issues occasionally do occur. 4384*4882a593Smuzhiyun 4385*4882a593Smuzhiyun For such cases, you can use some tools to help you sort out the 4386*4882a593Smuzhiyun situation: 4387*4882a593Smuzhiyun 4388*4882a593Smuzhiyun - ``state-diff-machines.sh``*:* You can find this tool in the 4389*4882a593Smuzhiyun ``scripts`` directory of the Source Repositories. See the comments 4390*4882a593Smuzhiyun in the script for information on how to use the tool. 4391*4882a593Smuzhiyun 4392*4882a593Smuzhiyun - *BitBake's "-S printdiff" Option:* Using this option causes 4393*4882a593Smuzhiyun BitBake to try to establish the closest signature match it can 4394*4882a593Smuzhiyun (e.g. in the shared state cache) and then run ``bitbake-diffsigs`` 4395*4882a593Smuzhiyun over the matches to determine the stamps and delta where these two 4396*4882a593Smuzhiyun stamp trees diverge. 4397*4882a593Smuzhiyun 4398*4882a593SmuzhiyunBuilding Software from an External Source 4399*4882a593Smuzhiyun----------------------------------------- 4400*4882a593Smuzhiyun 4401*4882a593SmuzhiyunBy default, the OpenEmbedded build system uses the 4402*4882a593Smuzhiyun:term:`Build Directory` when building source 4403*4882a593Smuzhiyuncode. The build process involves fetching the source files, unpacking 4404*4882a593Smuzhiyunthem, and then patching them if necessary before the build takes place. 4405*4882a593Smuzhiyun 4406*4882a593SmuzhiyunThere are situations where you might want to build software from source 4407*4882a593Smuzhiyunfiles that are external to and thus outside of the OpenEmbedded build 4408*4882a593Smuzhiyunsystem. For example, suppose you have a project that includes a new BSP 4409*4882a593Smuzhiyunwith a heavily customized kernel. And, you want to minimize exposing the 4410*4882a593Smuzhiyunbuild system to the development team so that they can focus on their 4411*4882a593Smuzhiyunproject and maintain everyone's workflow as much as possible. In this 4412*4882a593Smuzhiyuncase, you want a kernel source directory on the development machine 4413*4882a593Smuzhiyunwhere the development occurs. You want the recipe's 4414*4882a593Smuzhiyun:term:`SRC_URI` variable to point to 4415*4882a593Smuzhiyunthe external directory and use it as is, not copy it. 4416*4882a593Smuzhiyun 4417*4882a593SmuzhiyunTo build from software that comes from an external source, all you need 4418*4882a593Smuzhiyunto do is inherit the 4419*4882a593Smuzhiyun:ref:`externalsrc <ref-classes-externalsrc>` class 4420*4882a593Smuzhiyunand then set the 4421*4882a593Smuzhiyun:term:`EXTERNALSRC` variable to 4422*4882a593Smuzhiyunpoint to your external source code. Here are the statements to put in 4423*4882a593Smuzhiyunyour ``local.conf`` file:: 4424*4882a593Smuzhiyun 4425*4882a593Smuzhiyun INHERIT += "externalsrc" 4426*4882a593Smuzhiyun EXTERNALSRC:pn-myrecipe = "path-to-your-source-tree" 4427*4882a593Smuzhiyun 4428*4882a593SmuzhiyunThis next example shows how to accomplish the same thing by setting 4429*4882a593Smuzhiyun:term:`EXTERNALSRC` in the recipe itself or in the recipe's append file:: 4430*4882a593Smuzhiyun 4431*4882a593Smuzhiyun EXTERNALSRC = "path" 4432*4882a593Smuzhiyun EXTERNALSRC_BUILD = "path" 4433*4882a593Smuzhiyun 4434*4882a593Smuzhiyun.. note:: 4435*4882a593Smuzhiyun 4436*4882a593Smuzhiyun In order for these settings to take effect, you must globally or 4437*4882a593Smuzhiyun locally inherit the :ref:`externalsrc <ref-classes-externalsrc>` 4438*4882a593Smuzhiyun class. 4439*4882a593Smuzhiyun 4440*4882a593SmuzhiyunBy default, :ref:`ref-classes-externalsrc` builds the source code in a 4441*4882a593Smuzhiyundirectory separate from the external source directory as specified by 4442*4882a593Smuzhiyun:term:`EXTERNALSRC`. If you need 4443*4882a593Smuzhiyunto have the source built in the same directory in which it resides, or 4444*4882a593Smuzhiyunsome other nominated directory, you can set 4445*4882a593Smuzhiyun:term:`EXTERNALSRC_BUILD` 4446*4882a593Smuzhiyunto point to that directory:: 4447*4882a593Smuzhiyun 4448*4882a593Smuzhiyun EXTERNALSRC_BUILD:pn-myrecipe = "path-to-your-source-tree" 4449*4882a593Smuzhiyun 4450*4882a593SmuzhiyunReplicating a Build Offline 4451*4882a593Smuzhiyun--------------------------- 4452*4882a593Smuzhiyun 4453*4882a593SmuzhiyunIt can be useful to take a "snapshot" of upstream sources used in a 4454*4882a593Smuzhiyunbuild and then use that "snapshot" later to replicate the build offline. 4455*4882a593SmuzhiyunTo do so, you need to first prepare and populate your downloads 4456*4882a593Smuzhiyundirectory your "snapshot" of files. Once your downloads directory is 4457*4882a593Smuzhiyunready, you can use it at any time and from any machine to replicate your 4458*4882a593Smuzhiyunbuild. 4459*4882a593Smuzhiyun 4460*4882a593SmuzhiyunFollow these steps to populate your Downloads directory: 4461*4882a593Smuzhiyun 4462*4882a593Smuzhiyun1. *Create a Clean Downloads Directory:* Start with an empty downloads 4463*4882a593Smuzhiyun directory (:term:`DL_DIR`). You 4464*4882a593Smuzhiyun start with an empty downloads directory by either removing the files 4465*4882a593Smuzhiyun in the existing directory or by setting :term:`DL_DIR` to point to either 4466*4882a593Smuzhiyun an empty location or one that does not yet exist. 4467*4882a593Smuzhiyun 4468*4882a593Smuzhiyun2. *Generate Tarballs of the Source Git Repositories:* Edit your 4469*4882a593Smuzhiyun ``local.conf`` configuration file as follows:: 4470*4882a593Smuzhiyun 4471*4882a593Smuzhiyun DL_DIR = "/home/your-download-dir/" 4472*4882a593Smuzhiyun BB_GENERATE_MIRROR_TARBALLS = "1" 4473*4882a593Smuzhiyun 4474*4882a593Smuzhiyun During 4475*4882a593Smuzhiyun the fetch process in the next step, BitBake gathers the source files 4476*4882a593Smuzhiyun and creates tarballs in the directory pointed to by :term:`DL_DIR`. See 4477*4882a593Smuzhiyun the 4478*4882a593Smuzhiyun :term:`BB_GENERATE_MIRROR_TARBALLS` 4479*4882a593Smuzhiyun variable for more information. 4480*4882a593Smuzhiyun 4481*4882a593Smuzhiyun3. *Populate Your Downloads Directory Without Building:* Use BitBake to 4482*4882a593Smuzhiyun fetch your sources but inhibit the build:: 4483*4882a593Smuzhiyun 4484*4882a593Smuzhiyun $ bitbake target --runonly=fetch 4485*4882a593Smuzhiyun 4486*4882a593Smuzhiyun The downloads directory (i.e. ``${DL_DIR}``) now has 4487*4882a593Smuzhiyun a "snapshot" of the source files in the form of tarballs, which can 4488*4882a593Smuzhiyun be used for the build. 4489*4882a593Smuzhiyun 4490*4882a593Smuzhiyun4. *Optionally Remove Any Git or other SCM Subdirectories From the 4491*4882a593Smuzhiyun Downloads Directory:* If you want, you can clean up your downloads 4492*4882a593Smuzhiyun directory by removing any Git or other Source Control Management 4493*4882a593Smuzhiyun (SCM) subdirectories such as ``${DL_DIR}/git2/*``. The tarballs 4494*4882a593Smuzhiyun already contain these subdirectories. 4495*4882a593Smuzhiyun 4496*4882a593SmuzhiyunOnce your downloads directory has everything it needs regarding source 4497*4882a593Smuzhiyunfiles, you can create your "own-mirror" and build your target. 4498*4882a593SmuzhiyunUnderstand that you can use the files to build the target offline from 4499*4882a593Smuzhiyunany machine and at any time. 4500*4882a593Smuzhiyun 4501*4882a593SmuzhiyunFollow these steps to build your target using the files in the downloads 4502*4882a593Smuzhiyundirectory: 4503*4882a593Smuzhiyun 4504*4882a593Smuzhiyun1. *Using Local Files Only:* Inside your ``local.conf`` file, add the 4505*4882a593Smuzhiyun :term:`SOURCE_MIRROR_URL` variable, inherit the 4506*4882a593Smuzhiyun :ref:`own-mirrors <ref-classes-own-mirrors>` class, and use the 4507*4882a593Smuzhiyun :term:`BB_NO_NETWORK` variable to your ``local.conf``. 4508*4882a593Smuzhiyun :: 4509*4882a593Smuzhiyun 4510*4882a593Smuzhiyun SOURCE_MIRROR_URL ?= "file:///home/your-download-dir/" 4511*4882a593Smuzhiyun INHERIT += "own-mirrors" 4512*4882a593Smuzhiyun BB_NO_NETWORK = "1" 4513*4882a593Smuzhiyun 4514*4882a593Smuzhiyun The :term:`SOURCE_MIRROR_URL` and :ref:`own-mirrors <ref-classes-own-mirrors>` 4515*4882a593Smuzhiyun class set up the system to use the downloads directory as your "own 4516*4882a593Smuzhiyun mirror". Using the :term:`BB_NO_NETWORK` variable makes sure that 4517*4882a593Smuzhiyun BitBake's fetching process in step 3 stays local, which means files 4518*4882a593Smuzhiyun from your "own-mirror" are used. 4519*4882a593Smuzhiyun 4520*4882a593Smuzhiyun2. *Start With a Clean Build:* You can start with a clean build by 4521*4882a593Smuzhiyun removing the 4522*4882a593Smuzhiyun ``${``\ :term:`TMPDIR`\ ``}`` 4523*4882a593Smuzhiyun directory or using a new :term:`Build Directory`. 4524*4882a593Smuzhiyun 4525*4882a593Smuzhiyun3. *Build Your Target:* Use BitBake to build your target:: 4526*4882a593Smuzhiyun 4527*4882a593Smuzhiyun $ bitbake target 4528*4882a593Smuzhiyun 4529*4882a593Smuzhiyun The build completes using the known local "snapshot" of source 4530*4882a593Smuzhiyun files from your mirror. The resulting tarballs for your "snapshot" of 4531*4882a593Smuzhiyun source files are in the downloads directory. 4532*4882a593Smuzhiyun 4533*4882a593Smuzhiyun .. note:: 4534*4882a593Smuzhiyun 4535*4882a593Smuzhiyun The offline build does not work if recipes attempt to find the 4536*4882a593Smuzhiyun latest version of software by setting 4537*4882a593Smuzhiyun :term:`SRCREV` to 4538*4882a593Smuzhiyun ``${``\ :term:`AUTOREV`\ ``}``:: 4539*4882a593Smuzhiyun 4540*4882a593Smuzhiyun SRCREV = "${AUTOREV}" 4541*4882a593Smuzhiyun 4542*4882a593Smuzhiyun When a recipe sets :term:`SRCREV` to 4543*4882a593Smuzhiyun ``${``\ :term:`AUTOREV`\ ``}``, the build system accesses the network in an 4544*4882a593Smuzhiyun attempt to determine the latest version of software from the SCM. 4545*4882a593Smuzhiyun Typically, recipes that use :term:`AUTOREV` are custom or modified 4546*4882a593Smuzhiyun recipes. Recipes that reside in public repositories usually do not 4547*4882a593Smuzhiyun use :term:`AUTOREV`. 4548*4882a593Smuzhiyun 4549*4882a593Smuzhiyun If you do have recipes that use :term:`AUTOREV`, you can take steps to 4550*4882a593Smuzhiyun still use the recipes in an offline build. Do the following: 4551*4882a593Smuzhiyun 4552*4882a593Smuzhiyun 1. Use a configuration generated by enabling :ref:`build 4553*4882a593Smuzhiyun history <dev-manual/common-tasks:maintaining build output quality>`. 4554*4882a593Smuzhiyun 4555*4882a593Smuzhiyun 2. Use the ``buildhistory-collect-srcrevs`` command to collect the 4556*4882a593Smuzhiyun stored :term:`SRCREV` values from the build's history. For more 4557*4882a593Smuzhiyun information on collecting these values, see the 4558*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:build history package information`" 4559*4882a593Smuzhiyun section. 4560*4882a593Smuzhiyun 4561*4882a593Smuzhiyun 3. Once you have the correct source revisions, you can modify 4562*4882a593Smuzhiyun those recipes to set :term:`SRCREV` to specific versions of the 4563*4882a593Smuzhiyun software. 4564*4882a593Smuzhiyun 4565*4882a593SmuzhiyunSpeeding Up a Build 4566*4882a593Smuzhiyun=================== 4567*4882a593Smuzhiyun 4568*4882a593SmuzhiyunBuild time can be an issue. By default, the build system uses simple 4569*4882a593Smuzhiyuncontrols to try and maximize build efficiency. In general, the default 4570*4882a593Smuzhiyunsettings for all the following variables result in the most efficient 4571*4882a593Smuzhiyunbuild times when dealing with single socket systems (i.e. a single CPU). 4572*4882a593SmuzhiyunIf you have multiple CPUs, you might try increasing the default values 4573*4882a593Smuzhiyunto gain more speed. See the descriptions in the glossary for each 4574*4882a593Smuzhiyunvariable for more information: 4575*4882a593Smuzhiyun 4576*4882a593Smuzhiyun- :term:`BB_NUMBER_THREADS`: 4577*4882a593Smuzhiyun The maximum number of threads BitBake simultaneously executes. 4578*4882a593Smuzhiyun 4579*4882a593Smuzhiyun- :term:`BB_NUMBER_PARSE_THREADS`: 4580*4882a593Smuzhiyun The number of threads BitBake uses during parsing. 4581*4882a593Smuzhiyun 4582*4882a593Smuzhiyun- :term:`PARALLEL_MAKE`: Extra 4583*4882a593Smuzhiyun options passed to the ``make`` command during the 4584*4882a593Smuzhiyun :ref:`ref-tasks-compile` task in 4585*4882a593Smuzhiyun order to specify parallel compilation on the local build host. 4586*4882a593Smuzhiyun 4587*4882a593Smuzhiyun- :term:`PARALLEL_MAKEINST`: 4588*4882a593Smuzhiyun Extra options passed to the ``make`` command during the 4589*4882a593Smuzhiyun :ref:`ref-tasks-install` task in 4590*4882a593Smuzhiyun order to specify parallel installation on the local build host. 4591*4882a593Smuzhiyun 4592*4882a593SmuzhiyunAs mentioned, these variables all scale to the number of processor cores 4593*4882a593Smuzhiyunavailable on the build system. For single socket systems, this 4594*4882a593Smuzhiyunauto-scaling ensures that the build system fundamentally takes advantage 4595*4882a593Smuzhiyunof potential parallel operations during the build based on the build 4596*4882a593Smuzhiyunmachine's capabilities. 4597*4882a593Smuzhiyun 4598*4882a593SmuzhiyunFollowing are additional factors that can affect build speed: 4599*4882a593Smuzhiyun 4600*4882a593Smuzhiyun- File system type: The file system type that the build is being 4601*4882a593Smuzhiyun performed on can also influence performance. Using ``ext4`` is 4602*4882a593Smuzhiyun recommended as compared to ``ext2`` and ``ext3`` due to ``ext4`` 4603*4882a593Smuzhiyun improved features such as extents. 4604*4882a593Smuzhiyun 4605*4882a593Smuzhiyun- Disabling the updating of access time using ``noatime``: The 4606*4882a593Smuzhiyun ``noatime`` mount option prevents the build system from updating file 4607*4882a593Smuzhiyun and directory access times. 4608*4882a593Smuzhiyun 4609*4882a593Smuzhiyun- Setting a longer commit: Using the "commit=" mount option increases 4610*4882a593Smuzhiyun the interval in seconds between disk cache writes. Changing this 4611*4882a593Smuzhiyun interval from the five second default to something longer increases 4612*4882a593Smuzhiyun the risk of data loss but decreases the need to write to the disk, 4613*4882a593Smuzhiyun thus increasing the build performance. 4614*4882a593Smuzhiyun 4615*4882a593Smuzhiyun- Choosing the packaging backend: Of the available packaging backends, 4616*4882a593Smuzhiyun IPK is the fastest. Additionally, selecting a singular packaging 4617*4882a593Smuzhiyun backend also helps. 4618*4882a593Smuzhiyun 4619*4882a593Smuzhiyun- Using ``tmpfs`` for :term:`TMPDIR` 4620*4882a593Smuzhiyun as a temporary file system: While this can help speed up the build, 4621*4882a593Smuzhiyun the benefits are limited due to the compiler using ``-pipe``. The 4622*4882a593Smuzhiyun build system goes to some lengths to avoid ``sync()`` calls into the 4623*4882a593Smuzhiyun file system on the principle that if there was a significant failure, 4624*4882a593Smuzhiyun the :term:`Build Directory` 4625*4882a593Smuzhiyun contents could easily be rebuilt. 4626*4882a593Smuzhiyun 4627*4882a593Smuzhiyun- Inheriting the 4628*4882a593Smuzhiyun :ref:`rm_work <ref-classes-rm-work>` class: 4629*4882a593Smuzhiyun Inheriting this class has shown to speed up builds due to 4630*4882a593Smuzhiyun significantly lower amounts of data stored in the data cache as well 4631*4882a593Smuzhiyun as on disk. Inheriting this class also makes cleanup of 4632*4882a593Smuzhiyun :term:`TMPDIR` faster, at the 4633*4882a593Smuzhiyun expense of being easily able to dive into the source code. File 4634*4882a593Smuzhiyun system maintainers have recommended that the fastest way to clean up 4635*4882a593Smuzhiyun large numbers of files is to reformat partitions rather than delete 4636*4882a593Smuzhiyun files due to the linear nature of partitions. This, of course, 4637*4882a593Smuzhiyun assumes you structure the disk partitions and file systems in a way 4638*4882a593Smuzhiyun that this is practical. 4639*4882a593Smuzhiyun 4640*4882a593SmuzhiyunAside from the previous list, you should keep some trade offs in mind 4641*4882a593Smuzhiyunthat can help you speed up the build: 4642*4882a593Smuzhiyun 4643*4882a593Smuzhiyun- Remove items from 4644*4882a593Smuzhiyun :term:`DISTRO_FEATURES` 4645*4882a593Smuzhiyun that you might not need. 4646*4882a593Smuzhiyun 4647*4882a593Smuzhiyun- Exclude debug symbols and other debug information: If you do not need 4648*4882a593Smuzhiyun these symbols and other debug information, disabling the ``*-dbg`` 4649*4882a593Smuzhiyun package generation can speed up the build. You can disable this 4650*4882a593Smuzhiyun generation by setting the 4651*4882a593Smuzhiyun :term:`INHIBIT_PACKAGE_DEBUG_SPLIT` 4652*4882a593Smuzhiyun variable to "1". 4653*4882a593Smuzhiyun 4654*4882a593Smuzhiyun- Disable static library generation for recipes derived from 4655*4882a593Smuzhiyun ``autoconf`` or ``libtool``: Following is an example showing how to 4656*4882a593Smuzhiyun disable static libraries and still provide an override to handle 4657*4882a593Smuzhiyun exceptions:: 4658*4882a593Smuzhiyun 4659*4882a593Smuzhiyun STATICLIBCONF = "--disable-static" 4660*4882a593Smuzhiyun STATICLIBCONF:sqlite3-native = "" 4661*4882a593Smuzhiyun EXTRA_OECONF += "${STATICLIBCONF}" 4662*4882a593Smuzhiyun 4663*4882a593Smuzhiyun .. note:: 4664*4882a593Smuzhiyun 4665*4882a593Smuzhiyun - Some recipes need static libraries in order to work correctly 4666*4882a593Smuzhiyun (e.g. ``pseudo-native`` needs ``sqlite3-native``). Overrides, 4667*4882a593Smuzhiyun as in the previous example, account for these kinds of 4668*4882a593Smuzhiyun exceptions. 4669*4882a593Smuzhiyun 4670*4882a593Smuzhiyun - Some packages have packaging code that assumes the presence of 4671*4882a593Smuzhiyun the static libraries. If so, you might need to exclude them as 4672*4882a593Smuzhiyun well. 4673*4882a593Smuzhiyun 4674*4882a593SmuzhiyunWorking With Libraries 4675*4882a593Smuzhiyun====================== 4676*4882a593Smuzhiyun 4677*4882a593SmuzhiyunLibraries are an integral part of your system. This section describes 4678*4882a593Smuzhiyunsome common practices you might find helpful when working with libraries 4679*4882a593Smuzhiyunto build your system: 4680*4882a593Smuzhiyun 4681*4882a593Smuzhiyun- :ref:`How to include static library files 4682*4882a593Smuzhiyun <dev-manual/common-tasks:including static library files>` 4683*4882a593Smuzhiyun 4684*4882a593Smuzhiyun- :ref:`How to use the Multilib feature to combine multiple versions of 4685*4882a593Smuzhiyun library files into a single image 4686*4882a593Smuzhiyun <dev-manual/common-tasks:combining multiple versions of library files into one image>` 4687*4882a593Smuzhiyun 4688*4882a593Smuzhiyun- :ref:`How to install multiple versions of the same library in parallel on 4689*4882a593Smuzhiyun the same system 4690*4882a593Smuzhiyun <dev-manual/common-tasks:installing multiple versions of the same library>` 4691*4882a593Smuzhiyun 4692*4882a593SmuzhiyunIncluding Static Library Files 4693*4882a593Smuzhiyun------------------------------ 4694*4882a593Smuzhiyun 4695*4882a593SmuzhiyunIf you are building a library and the library offers static linking, you 4696*4882a593Smuzhiyuncan control which static library files (``*.a`` files) get included in 4697*4882a593Smuzhiyunthe built library. 4698*4882a593Smuzhiyun 4699*4882a593SmuzhiyunThe :term:`PACKAGES` and 4700*4882a593Smuzhiyun:term:`FILES:* <FILES>` variables in the 4701*4882a593Smuzhiyun``meta/conf/bitbake.conf`` configuration file define how files installed 4702*4882a593Smuzhiyunby the ``do_install`` task are packaged. By default, the :term:`PACKAGES` 4703*4882a593Smuzhiyunvariable includes ``${PN}-staticdev``, which represents all static 4704*4882a593Smuzhiyunlibrary files. 4705*4882a593Smuzhiyun 4706*4882a593Smuzhiyun.. note:: 4707*4882a593Smuzhiyun 4708*4882a593Smuzhiyun Some previously released versions of the Yocto Project defined the 4709*4882a593Smuzhiyun static library files through ``${PN}-dev``. 4710*4882a593Smuzhiyun 4711*4882a593SmuzhiyunFollowing is part of the BitBake configuration file, where you can see 4712*4882a593Smuzhiyunhow the static library files are defined:: 4713*4882a593Smuzhiyun 4714*4882a593Smuzhiyun PACKAGE_BEFORE_PN ?= "" 4715*4882a593Smuzhiyun PACKAGES = "${PN}-src ${PN}-dbg ${PN}-staticdev ${PN}-dev ${PN}-doc ${PN}-locale ${PACKAGE_BEFORE_PN} ${PN}" 4716*4882a593Smuzhiyun PACKAGES_DYNAMIC = "^${PN}-locale-.*" 4717*4882a593Smuzhiyun FILES = "" 4718*4882a593Smuzhiyun 4719*4882a593Smuzhiyun FILES:${PN} = "${bindir}/* ${sbindir}/* ${libexecdir}/* ${libdir}/lib*${SOLIBS} \ 4720*4882a593Smuzhiyun ${sysconfdir} ${sharedstatedir} ${localstatedir} \ 4721*4882a593Smuzhiyun ${base_bindir}/* ${base_sbindir}/* \ 4722*4882a593Smuzhiyun ${base_libdir}/*${SOLIBS} \ 4723*4882a593Smuzhiyun ${base_prefix}/lib/udev ${prefix}/lib/udev \ 4724*4882a593Smuzhiyun ${base_libdir}/udev ${libdir}/udev \ 4725*4882a593Smuzhiyun ${datadir}/${BPN} ${libdir}/${BPN}/* \ 4726*4882a593Smuzhiyun ${datadir}/pixmaps ${datadir}/applications \ 4727*4882a593Smuzhiyun ${datadir}/idl ${datadir}/omf ${datadir}/sounds \ 4728*4882a593Smuzhiyun ${libdir}/bonobo/servers" 4729*4882a593Smuzhiyun 4730*4882a593Smuzhiyun FILES:${PN}-bin = "${bindir}/* ${sbindir}/*" 4731*4882a593Smuzhiyun 4732*4882a593Smuzhiyun FILES:${PN}-doc = "${docdir} ${mandir} ${infodir} ${datadir}/gtk-doc \ 4733*4882a593Smuzhiyun ${datadir}/gnome/help" 4734*4882a593Smuzhiyun SECTION:${PN}-doc = "doc" 4735*4882a593Smuzhiyun 4736*4882a593Smuzhiyun FILES_SOLIBSDEV ?= "${base_libdir}/lib*${SOLIBSDEV} ${libdir}/lib*${SOLIBSDEV}" 4737*4882a593Smuzhiyun FILES:${PN}-dev = "${includedir} ${FILES_SOLIBSDEV} ${libdir}/*.la \ 4738*4882a593Smuzhiyun ${libdir}/*.o ${libdir}/pkgconfig ${datadir}/pkgconfig \ 4739*4882a593Smuzhiyun ${datadir}/aclocal ${base_libdir}/*.o \ 4740*4882a593Smuzhiyun ${libdir}/${BPN}/*.la ${base_libdir}/*.la \ 4741*4882a593Smuzhiyun ${libdir}/cmake ${datadir}/cmake" 4742*4882a593Smuzhiyun SECTION:${PN}-dev = "devel" 4743*4882a593Smuzhiyun ALLOW_EMPTY:${PN}-dev = "1" 4744*4882a593Smuzhiyun RDEPENDS:${PN}-dev = "${PN} (= ${EXTENDPKGV})" 4745*4882a593Smuzhiyun 4746*4882a593Smuzhiyun FILES:${PN}-staticdev = "${libdir}/*.a ${base_libdir}/*.a ${libdir}/${BPN}/*.a" 4747*4882a593Smuzhiyun SECTION:${PN}-staticdev = "devel" 4748*4882a593Smuzhiyun RDEPENDS:${PN}-staticdev = "${PN}-dev (= ${EXTENDPKGV})" 4749*4882a593Smuzhiyun 4750*4882a593SmuzhiyunCombining Multiple Versions of Library Files into One Image 4751*4882a593Smuzhiyun----------------------------------------------------------- 4752*4882a593Smuzhiyun 4753*4882a593SmuzhiyunThe build system offers the ability to build libraries with different 4754*4882a593Smuzhiyuntarget optimizations or architecture formats and combine these together 4755*4882a593Smuzhiyuninto one system image. You can link different binaries in the image 4756*4882a593Smuzhiyunagainst the different libraries as needed for specific use cases. This 4757*4882a593Smuzhiyunfeature is called "Multilib". 4758*4882a593Smuzhiyun 4759*4882a593SmuzhiyunAn example would be where you have most of a system compiled in 32-bit 4760*4882a593Smuzhiyunmode using 32-bit libraries, but you have something large, like a 4761*4882a593Smuzhiyundatabase engine, that needs to be a 64-bit application and uses 64-bit 4762*4882a593Smuzhiyunlibraries. Multilib allows you to get the best of both 32-bit and 64-bit 4763*4882a593Smuzhiyunlibraries. 4764*4882a593Smuzhiyun 4765*4882a593SmuzhiyunWhile the Multilib feature is most commonly used for 32 and 64-bit 4766*4882a593Smuzhiyundifferences, the approach the build system uses facilitates different 4767*4882a593Smuzhiyuntarget optimizations. You could compile some binaries to use one set of 4768*4882a593Smuzhiyunlibraries and other binaries to use a different set of libraries. The 4769*4882a593Smuzhiyunlibraries could differ in architecture, compiler options, or other 4770*4882a593Smuzhiyunoptimizations. 4771*4882a593Smuzhiyun 4772*4882a593SmuzhiyunThere are several examples in the ``meta-skeleton`` layer found in the 4773*4882a593Smuzhiyun:term:`Source Directory`: 4774*4882a593Smuzhiyun 4775*4882a593Smuzhiyun- :oe_git:`conf/multilib-example.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example.conf>` 4776*4882a593Smuzhiyun configuration file. 4777*4882a593Smuzhiyun 4778*4882a593Smuzhiyun- :oe_git:`conf/multilib-example2.conf </openembedded-core/tree/meta-skeleton/conf/multilib-example2.conf>` 4779*4882a593Smuzhiyun configuration file. 4780*4882a593Smuzhiyun 4781*4882a593Smuzhiyun- :oe_git:`recipes-multilib/images/core-image-multilib-example.bb </openembedded-core/tree/meta-skeleton/recipes-multilib/images/core-image-multilib-example.bb>` 4782*4882a593Smuzhiyun recipe 4783*4882a593Smuzhiyun 4784*4882a593SmuzhiyunPreparing to Use Multilib 4785*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~ 4786*4882a593Smuzhiyun 4787*4882a593SmuzhiyunUser-specific requirements drive the Multilib feature. Consequently, 4788*4882a593Smuzhiyunthere is no one "out-of-the-box" configuration that would 4789*4882a593Smuzhiyunmeet your needs. 4790*4882a593Smuzhiyun 4791*4882a593SmuzhiyunIn order to enable Multilib, you first need to ensure your recipe is 4792*4882a593Smuzhiyunextended to support multiple libraries. Many standard recipes are 4793*4882a593Smuzhiyunalready extended and support multiple libraries. You can check in the 4794*4882a593Smuzhiyun``meta/conf/multilib.conf`` configuration file in the 4795*4882a593Smuzhiyun:term:`Source Directory` to see how this is 4796*4882a593Smuzhiyundone using the 4797*4882a593Smuzhiyun:term:`BBCLASSEXTEND` variable. 4798*4882a593SmuzhiyunEventually, all recipes will be covered and this list will not be 4799*4882a593Smuzhiyunneeded. 4800*4882a593Smuzhiyun 4801*4882a593SmuzhiyunFor the most part, the :ref:`Multilib <ref-classes-multilib*>` 4802*4882a593Smuzhiyunclass extension works automatically to 4803*4882a593Smuzhiyunextend the package name from ``${PN}`` to ``${MLPREFIX}${PN}``, where 4804*4882a593Smuzhiyun:term:`MLPREFIX` is the particular multilib (e.g. "lib32-" or "lib64-"). 4805*4882a593SmuzhiyunStandard variables such as 4806*4882a593Smuzhiyun:term:`DEPENDS`, 4807*4882a593Smuzhiyun:term:`RDEPENDS`, 4808*4882a593Smuzhiyun:term:`RPROVIDES`, 4809*4882a593Smuzhiyun:term:`RRECOMMENDS`, 4810*4882a593Smuzhiyun:term:`PACKAGES`, and 4811*4882a593Smuzhiyun:term:`PACKAGES_DYNAMIC` are 4812*4882a593Smuzhiyunautomatically extended by the system. If you are extending any manual 4813*4882a593Smuzhiyuncode in the recipe, you can use the ``${MLPREFIX}`` variable to ensure 4814*4882a593Smuzhiyunthose names are extended correctly. 4815*4882a593Smuzhiyun 4816*4882a593SmuzhiyunUsing Multilib 4817*4882a593Smuzhiyun~~~~~~~~~~~~~~ 4818*4882a593Smuzhiyun 4819*4882a593SmuzhiyunAfter you have set up the recipes, you need to define the actual 4820*4882a593Smuzhiyuncombination of multiple libraries you want to build. You accomplish this 4821*4882a593Smuzhiyunthrough your ``local.conf`` configuration file in the 4822*4882a593Smuzhiyun:term:`Build Directory`. An example 4823*4882a593Smuzhiyunconfiguration would be as follows:: 4824*4882a593Smuzhiyun 4825*4882a593Smuzhiyun MACHINE = "qemux86-64" 4826*4882a593Smuzhiyun require conf/multilib.conf 4827*4882a593Smuzhiyun MULTILIBS = "multilib:lib32" 4828*4882a593Smuzhiyun DEFAULTTUNE:virtclass-multilib-lib32 = "x86" 4829*4882a593Smuzhiyun IMAGE_INSTALL:append = "lib32-glib-2.0" 4830*4882a593Smuzhiyun 4831*4882a593SmuzhiyunThis example enables an additional library named 4832*4882a593Smuzhiyun``lib32`` alongside the normal target packages. When combining these 4833*4882a593Smuzhiyun"lib32" alternatives, the example uses "x86" for tuning. For information 4834*4882a593Smuzhiyunon this particular tuning, see 4835*4882a593Smuzhiyun``meta/conf/machine/include/ia32/arch-ia32.inc``. 4836*4882a593Smuzhiyun 4837*4882a593SmuzhiyunThe example then includes ``lib32-glib-2.0`` in all the images, which 4838*4882a593Smuzhiyunillustrates one method of including a multiple library dependency. You 4839*4882a593Smuzhiyuncan use a normal image build to include this dependency, for example:: 4840*4882a593Smuzhiyun 4841*4882a593Smuzhiyun $ bitbake core-image-sato 4842*4882a593Smuzhiyun 4843*4882a593SmuzhiyunYou can also build Multilib packages 4844*4882a593Smuzhiyunspecifically with a command like this:: 4845*4882a593Smuzhiyun 4846*4882a593Smuzhiyun $ bitbake lib32-glib-2.0 4847*4882a593Smuzhiyun 4848*4882a593SmuzhiyunAdditional Implementation Details 4849*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4850*4882a593Smuzhiyun 4851*4882a593SmuzhiyunThere are generic implementation details as well as details that are specific to 4852*4882a593Smuzhiyunpackage management systems. Following are implementation details 4853*4882a593Smuzhiyunthat exist regardless of the package management system: 4854*4882a593Smuzhiyun 4855*4882a593Smuzhiyun- The typical convention used for the class extension code as used by 4856*4882a593Smuzhiyun Multilib assumes that all package names specified in 4857*4882a593Smuzhiyun :term:`PACKAGES` that contain 4858*4882a593Smuzhiyun ``${PN}`` have ``${PN}`` at the start of the name. When that 4859*4882a593Smuzhiyun convention is not followed and ``${PN}`` appears at the middle or the 4860*4882a593Smuzhiyun end of a name, problems occur. 4861*4882a593Smuzhiyun 4862*4882a593Smuzhiyun- The :term:`TARGET_VENDOR` 4863*4882a593Smuzhiyun value under Multilib will be extended to "-vendormlmultilib" (e.g. 4864*4882a593Smuzhiyun "-pokymllib32" for a "lib32" Multilib with Poky). The reason for this 4865*4882a593Smuzhiyun slightly unwieldy contraction is that any "-" characters in the 4866*4882a593Smuzhiyun vendor string presently break Autoconf's ``config.sub``, and other 4867*4882a593Smuzhiyun separators are problematic for different reasons. 4868*4882a593Smuzhiyun 4869*4882a593SmuzhiyunHere are the implementation details for the RPM Package Management System: 4870*4882a593Smuzhiyun 4871*4882a593Smuzhiyun- A unique architecture is defined for the Multilib packages, along 4872*4882a593Smuzhiyun with creating a unique deploy folder under ``tmp/deploy/rpm`` in the 4873*4882a593Smuzhiyun :term:`Build Directory`. For 4874*4882a593Smuzhiyun example, consider ``lib32`` in a ``qemux86-64`` image. The possible 4875*4882a593Smuzhiyun architectures in the system are "all", "qemux86_64", 4876*4882a593Smuzhiyun "lib32:qemux86_64", and "lib32:x86". 4877*4882a593Smuzhiyun 4878*4882a593Smuzhiyun- The ``${MLPREFIX}`` variable is stripped from ``${PN}`` during RPM 4879*4882a593Smuzhiyun packaging. The naming for a normal RPM package and a Multilib RPM 4880*4882a593Smuzhiyun package in a ``qemux86-64`` system resolves to something similar to 4881*4882a593Smuzhiyun ``bash-4.1-r2.x86_64.rpm`` and ``bash-4.1.r2.lib32_x86.rpm``, 4882*4882a593Smuzhiyun respectively. 4883*4882a593Smuzhiyun 4884*4882a593Smuzhiyun- When installing a Multilib image, the RPM backend first installs the 4885*4882a593Smuzhiyun base image and then installs the Multilib libraries. 4886*4882a593Smuzhiyun 4887*4882a593Smuzhiyun- The build system relies on RPM to resolve the identical files in the 4888*4882a593Smuzhiyun two (or more) Multilib packages. 4889*4882a593Smuzhiyun 4890*4882a593SmuzhiyunHere are the implementation details for the IPK Package Management System: 4891*4882a593Smuzhiyun 4892*4882a593Smuzhiyun- The ``${MLPREFIX}`` is not stripped from ``${PN}`` during IPK 4893*4882a593Smuzhiyun packaging. The naming for a normal RPM package and a Multilib IPK 4894*4882a593Smuzhiyun package in a ``qemux86-64`` system resolves to something like 4895*4882a593Smuzhiyun ``bash_4.1-r2.x86_64.ipk`` and ``lib32-bash_4.1-rw:x86.ipk``, 4896*4882a593Smuzhiyun respectively. 4897*4882a593Smuzhiyun 4898*4882a593Smuzhiyun- The IPK deploy folder is not modified with ``${MLPREFIX}`` because 4899*4882a593Smuzhiyun packages with and without the Multilib feature can exist in the same 4900*4882a593Smuzhiyun folder due to the ``${PN}`` differences. 4901*4882a593Smuzhiyun 4902*4882a593Smuzhiyun- IPK defines a sanity check for Multilib installation using certain 4903*4882a593Smuzhiyun rules for file comparison, overridden, etc. 4904*4882a593Smuzhiyun 4905*4882a593SmuzhiyunInstalling Multiple Versions of the Same Library 4906*4882a593Smuzhiyun------------------------------------------------ 4907*4882a593Smuzhiyun 4908*4882a593SmuzhiyunThere are be situations where you need to install and use multiple versions 4909*4882a593Smuzhiyunof the same library on the same system at the same time. This 4910*4882a593Smuzhiyunalmost always happens when a library API changes and you have 4911*4882a593Smuzhiyunmultiple pieces of software that depend on the separate versions of the 4912*4882a593Smuzhiyunlibrary. To accommodate these situations, you can install multiple 4913*4882a593Smuzhiyunversions of the same library in parallel on the same system. 4914*4882a593Smuzhiyun 4915*4882a593SmuzhiyunThe process is straightforward as long as the libraries use proper 4916*4882a593Smuzhiyunversioning. With properly versioned libraries, all you need to do to 4917*4882a593Smuzhiyunindividually specify the libraries is create separate, appropriately 4918*4882a593Smuzhiyunnamed recipes where the :term:`PN` part of 4919*4882a593Smuzhiyunthe name includes a portion that differentiates each library version 4920*4882a593Smuzhiyun(e.g. the major part of the version number). Thus, instead of having a 4921*4882a593Smuzhiyunsingle recipe that loads one version of a library (e.g. ``clutter``), 4922*4882a593Smuzhiyunyou provide multiple recipes that result in different versions of the 4923*4882a593Smuzhiyunlibraries you want. As an example, the following two recipes would allow 4924*4882a593Smuzhiyunthe two separate versions of the ``clutter`` library to co-exist on the 4925*4882a593Smuzhiyunsame system: 4926*4882a593Smuzhiyun 4927*4882a593Smuzhiyun.. code-block:: none 4928*4882a593Smuzhiyun 4929*4882a593Smuzhiyun clutter-1.6_1.6.20.bb 4930*4882a593Smuzhiyun clutter-1.8_1.8.4.bb 4931*4882a593Smuzhiyun 4932*4882a593SmuzhiyunAdditionally, if 4933*4882a593Smuzhiyunyou have other recipes that depend on a given library, you need to use 4934*4882a593Smuzhiyunthe :term:`DEPENDS` variable to 4935*4882a593Smuzhiyuncreate the dependency. Continuing with the same example, if you want to 4936*4882a593Smuzhiyunhave a recipe depend on the 1.8 version of the ``clutter`` library, use 4937*4882a593Smuzhiyunthe following in your recipe:: 4938*4882a593Smuzhiyun 4939*4882a593Smuzhiyun DEPENDS = "clutter-1.8" 4940*4882a593Smuzhiyun 4941*4882a593SmuzhiyunWorking with Pre-Built Libraries 4942*4882a593Smuzhiyun================================ 4943*4882a593Smuzhiyun 4944*4882a593SmuzhiyunIntroduction 4945*4882a593Smuzhiyun------------- 4946*4882a593Smuzhiyun 4947*4882a593SmuzhiyunSome library vendors do not release source code for their software but do 4948*4882a593Smuzhiyunrelease pre-built binaries. When shared libraries are built, they should 4949*4882a593Smuzhiyunbe versioned (see `this article 4950*4882a593Smuzhiyun<https://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html>`__ 4951*4882a593Smuzhiyunfor some background), but sometimes this is not done. 4952*4882a593Smuzhiyun 4953*4882a593SmuzhiyunTo summarize, a versioned library must meet two conditions: 4954*4882a593Smuzhiyun 4955*4882a593Smuzhiyun#. The filename must have the version appended, for example: ``libfoo.so.1.2.3``. 4956*4882a593Smuzhiyun#. The library must have the ELF tag ``SONAME`` set to the major version 4957*4882a593Smuzhiyun of the library, for example: ``libfoo.so.1``. You can check this by 4958*4882a593Smuzhiyun running ``readelf -d filename | grep SONAME``. 4959*4882a593Smuzhiyun 4960*4882a593SmuzhiyunThis section shows how to deal with both versioned and unversioned 4961*4882a593Smuzhiyunpre-built libraries. 4962*4882a593Smuzhiyun 4963*4882a593SmuzhiyunVersioned Libraries 4964*4882a593Smuzhiyun------------------- 4965*4882a593Smuzhiyun 4966*4882a593SmuzhiyunIn this example we work with pre-built libraries for the FT4222H USB I/O chip. 4967*4882a593SmuzhiyunLibraries are built for several target architecture variants and packaged in 4968*4882a593Smuzhiyunan archive as follows:: 4969*4882a593Smuzhiyun 4970*4882a593Smuzhiyun ├── build-arm-hisiv300 4971*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4972*4882a593Smuzhiyun ├── build-arm-v5-sf 4973*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4974*4882a593Smuzhiyun ├── build-arm-v6-hf 4975*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4976*4882a593Smuzhiyun ├── build-arm-v7-hf 4977*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4978*4882a593Smuzhiyun ├── build-arm-v8 4979*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4980*4882a593Smuzhiyun ├── build-i386 4981*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4982*4882a593Smuzhiyun ├── build-i486 4983*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4984*4882a593Smuzhiyun ├── build-mips-eglibc-hf 4985*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4986*4882a593Smuzhiyun ├── build-pentium 4987*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4988*4882a593Smuzhiyun ├── build-x86_64 4989*4882a593Smuzhiyun │ └── libft4222.so.1.4.4.44 4990*4882a593Smuzhiyun ├── examples 4991*4882a593Smuzhiyun │ ├── get-version.c 4992*4882a593Smuzhiyun │ ├── i2cm.c 4993*4882a593Smuzhiyun │ ├── spim.c 4994*4882a593Smuzhiyun │ └── spis.c 4995*4882a593Smuzhiyun ├── ftd2xx.h 4996*4882a593Smuzhiyun ├── install4222.sh 4997*4882a593Smuzhiyun ├── libft4222.h 4998*4882a593Smuzhiyun ├── ReadMe.txt 4999*4882a593Smuzhiyun └── WinTypes.h 5000*4882a593Smuzhiyun 5001*4882a593SmuzhiyunTo write a recipe to use such a library in your system: 5002*4882a593Smuzhiyun 5003*4882a593Smuzhiyun- The vendor will probably have a proprietary licence, so set 5004*4882a593Smuzhiyun :term:`LICENSE_FLAGS` in your recipe. 5005*4882a593Smuzhiyun- The vendor provides a tarball containing libraries so set :term:`SRC_URI` 5006*4882a593Smuzhiyun appropriately. 5007*4882a593Smuzhiyun- Set :term:`COMPATIBLE_HOST` so that the recipe cannot be used with an 5008*4882a593Smuzhiyun unsupported architecture. In the following example, we only support the 32 5009*4882a593Smuzhiyun and 64 bit variants of the ``x86`` architecture. 5010*4882a593Smuzhiyun- As the vendor provides versioned libraries, we can use ``oe_soinstall`` 5011*4882a593Smuzhiyun from :ref:`ref-classes-utils` to install the shared library and create 5012*4882a593Smuzhiyun symbolic links. If the vendor does not do this, we need to follow the 5013*4882a593Smuzhiyun non-versioned library guidelines in the next section. 5014*4882a593Smuzhiyun- As the vendor likely used :term:`LDFLAGS` different from those in your Yocto 5015*4882a593Smuzhiyun Project build, disable the corresponding checks by adding ``ldflags`` 5016*4882a593Smuzhiyun to :term:`INSANE_SKIP`. 5017*4882a593Smuzhiyun- The vendor will typically ship release builds without debugging symbols. 5018*4882a593Smuzhiyun Avoid errors by preventing the packaging task from stripping out the symbols 5019*4882a593Smuzhiyun and adding them to a separate debug package. This is done by setting the 5020*4882a593Smuzhiyun ``INHIBIT_`` flags shown below. 5021*4882a593Smuzhiyun 5022*4882a593SmuzhiyunThe complete recipe would look like this:: 5023*4882a593Smuzhiyun 5024*4882a593Smuzhiyun SUMMARY = "FTDI FT4222H Library" 5025*4882a593Smuzhiyun SECTION = "libs" 5026*4882a593Smuzhiyun LICENSE_FLAGS = "ftdi" 5027*4882a593Smuzhiyun LICENSE = "CLOSED" 5028*4882a593Smuzhiyun 5029*4882a593Smuzhiyun COMPATIBLE_HOST = "(i.86|x86_64).*-linux" 5030*4882a593Smuzhiyun 5031*4882a593Smuzhiyun # Sources available in a .tgz file in .zip archive 5032*4882a593Smuzhiyun # at https://ftdichip.com/wp-content/uploads/2021/01/libft4222-linux-1.4.4.44.zip 5033*4882a593Smuzhiyun # Found on https://ftdichip.com/software-examples/ft4222h-software-examples/ 5034*4882a593Smuzhiyun # Since dealing with this particular type of archive is out of topic here, 5035*4882a593Smuzhiyun # we use a local link. 5036*4882a593Smuzhiyun SRC_URI = "file://libft4222-linux-${PV}.tgz" 5037*4882a593Smuzhiyun 5038*4882a593Smuzhiyun S = "${WORKDIR}" 5039*4882a593Smuzhiyun 5040*4882a593Smuzhiyun ARCH_DIR:x86-64 = "build-x86_64" 5041*4882a593Smuzhiyun ARCH_DIR:i586 = "build-i386" 5042*4882a593Smuzhiyun ARCH_DIR:i686 = "build-i386" 5043*4882a593Smuzhiyun 5044*4882a593Smuzhiyun INSANE_SKIP:${PN} = "ldflags" 5045*4882a593Smuzhiyun INHIBIT_PACKAGE_STRIP = "1" 5046*4882a593Smuzhiyun INHIBIT_SYSROOT_STRIP = "1" 5047*4882a593Smuzhiyun INHIBIT_PACKAGE_DEBUG_SPLIT = "1" 5048*4882a593Smuzhiyun 5049*4882a593Smuzhiyun do_install () { 5050*4882a593Smuzhiyun install -m 0755 -d ${D}${libdir} 5051*4882a593Smuzhiyun oe_soinstall ${S}/${ARCH_DIR}/libft4222.so.${PV} ${D}${libdir} 5052*4882a593Smuzhiyun install -d ${D}${includedir} 5053*4882a593Smuzhiyun install -m 0755 ${S}/*.h ${D}${includedir} 5054*4882a593Smuzhiyun } 5055*4882a593Smuzhiyun 5056*4882a593SmuzhiyunIf the precompiled binaries are not statically linked and have dependencies on 5057*4882a593Smuzhiyunother libraries, then by adding those libraries to :term:`DEPENDS`, the linking 5058*4882a593Smuzhiyuncan be examined and the appropriate :term:`RDEPENDS` automatically added. 5059*4882a593Smuzhiyun 5060*4882a593SmuzhiyunNon-Versioned Libraries 5061*4882a593Smuzhiyun----------------------- 5062*4882a593Smuzhiyun 5063*4882a593SmuzhiyunSome Background 5064*4882a593Smuzhiyun~~~~~~~~~~~~~~~ 5065*4882a593Smuzhiyun 5066*4882a593SmuzhiyunLibraries in Linux systems are generally versioned so that it is possible 5067*4882a593Smuzhiyunto have multiple versions of the same library installed, which eases upgrades 5068*4882a593Smuzhiyunand support for older software. For example, suppose that in a versioned 5069*4882a593Smuzhiyunlibrary, an actual library is called ``libfoo.so.1.2``, a symbolic link named 5070*4882a593Smuzhiyun``libfoo.so.1`` points to ``libfoo.so.1.2``, and a symbolic link named 5071*4882a593Smuzhiyun``libfoo.so`` points to ``libfoo.so.1.2``. Given these conditions, when you 5072*4882a593Smuzhiyunlink a binary against a library, you typically provide the unversioned file 5073*4882a593Smuzhiyunname (i.e. ``-lfoo`` to the linker). However, the linker follows the symbolic 5074*4882a593Smuzhiyunlink and actually links against the versioned filename. The unversioned symbolic 5075*4882a593Smuzhiyunlink is only used at development time. Consequently, the library is packaged 5076*4882a593Smuzhiyunalong with the headers in the development package ``${PN}-dev`` along with the 5077*4882a593Smuzhiyunactual library and versioned symbolic links in ``${PN}``. Because versioned 5078*4882a593Smuzhiyunlibraries are far more common than unversioned libraries, the default packaging 5079*4882a593Smuzhiyunrules assume versioned libraries. 5080*4882a593Smuzhiyun 5081*4882a593SmuzhiyunYocto Library Packaging Overview 5082*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5083*4882a593Smuzhiyun 5084*4882a593SmuzhiyunIt follows that packaging an unversioned library requires a bit of work in the 5085*4882a593Smuzhiyunrecipe. By default, ``libfoo.so`` gets packaged into ``${PN}-dev``, which 5086*4882a593Smuzhiyuntriggers a QA warning that a non-symlink library is in a ``-dev`` package, 5087*4882a593Smuzhiyunand binaries in the same recipe link to the library in ``${PN}-dev``, 5088*4882a593Smuzhiyunwhich triggers more QA warnings. To solve this problem, you need to package the 5089*4882a593Smuzhiyununversioned library into ``${PN}`` where it belongs. The following are the abridged 5090*4882a593Smuzhiyundefault :term:`FILES` variables in ``bitbake.conf``:: 5091*4882a593Smuzhiyun 5092*4882a593Smuzhiyun SOLIBS = ".so.*" 5093*4882a593Smuzhiyun SOLIBSDEV = ".so" 5094*4882a593Smuzhiyun FILES:${PN} = "... ${libdir}/lib*${SOLIBS} ..." 5095*4882a593Smuzhiyun FILES_SOLIBSDEV ?= "... ${libdir}/lib*${SOLIBSDEV} ..." 5096*4882a593Smuzhiyun FILES:${PN}-dev = "... ${FILES_SOLIBSDEV} ..." 5097*4882a593Smuzhiyun 5098*4882a593Smuzhiyun:term:`SOLIBS` defines a pattern that matches real shared object libraries. 5099*4882a593Smuzhiyun:term:`SOLIBSDEV` matches the development form (unversioned symlink). These two 5100*4882a593Smuzhiyunvariables are then used in ``FILES:${PN}`` and ``FILES:${PN}-dev``, which puts 5101*4882a593Smuzhiyunthe real libraries into ``${PN}`` and the unversioned symbolic link into ``${PN}-dev``. 5102*4882a593SmuzhiyunTo package unversioned libraries, you need to modify the variables in the recipe 5103*4882a593Smuzhiyunas follows:: 5104*4882a593Smuzhiyun 5105*4882a593Smuzhiyun SOLIBS = ".so" 5106*4882a593Smuzhiyun FILES_SOLIBSDEV = "" 5107*4882a593Smuzhiyun 5108*4882a593SmuzhiyunThe modifications cause the ``.so`` file to be the real library 5109*4882a593Smuzhiyunand unset :term:`FILES_SOLIBSDEV` so that no libraries get packaged into 5110*4882a593Smuzhiyun``${PN}-dev``. The changes are required because unless :term:`PACKAGES` is changed, 5111*4882a593Smuzhiyun``${PN}-dev`` collects files before `${PN}`. ``${PN}-dev`` must not collect any of 5112*4882a593Smuzhiyunthe files you want in ``${PN}``. 5113*4882a593Smuzhiyun 5114*4882a593SmuzhiyunFinally, loadable modules, essentially unversioned libraries that are linked 5115*4882a593Smuzhiyunat runtime using ``dlopen()`` instead of at build time, should generally be 5116*4882a593Smuzhiyuninstalled in a private directory. However, if they are installed in ``${libdir}``, 5117*4882a593Smuzhiyunthen the modules can be treated as unversioned libraries. 5118*4882a593Smuzhiyun 5119*4882a593SmuzhiyunExample 5120*4882a593Smuzhiyun~~~~~~~ 5121*4882a593Smuzhiyun 5122*4882a593SmuzhiyunThe example below installs an unversioned x86-64 pre-built library named 5123*4882a593Smuzhiyun``libfoo.so``. The :term:`COMPATIBLE_HOST` variable limits recipes to the 5124*4882a593Smuzhiyunx86-64 architecture while the :term:`INSANE_SKIP`, :term:`INHIBIT_PACKAGE_STRIP` 5125*4882a593Smuzhiyunand :term:`INHIBIT_SYSROOT_STRIP` variables are all set as in the above 5126*4882a593Smuzhiyunversioned library example. The "magic" is setting the :term:`SOLIBS` and 5127*4882a593Smuzhiyun:term:`FILES_SOLIBSDEV` variables as explained above:: 5128*4882a593Smuzhiyun 5129*4882a593Smuzhiyun SUMMARY = "libfoo sample recipe" 5130*4882a593Smuzhiyun SECTION = "libs" 5131*4882a593Smuzhiyun LICENSE = "CLOSED" 5132*4882a593Smuzhiyun 5133*4882a593Smuzhiyun SRC_URI = "file://libfoo.so" 5134*4882a593Smuzhiyun 5135*4882a593Smuzhiyun COMPATIBLE_HOST = "x86_64.*-linux" 5136*4882a593Smuzhiyun 5137*4882a593Smuzhiyun INSANE_SKIP:${PN} = "ldflags" 5138*4882a593Smuzhiyun INHIBIT_PACKAGE_STRIP = "1" 5139*4882a593Smuzhiyun INHIBIT_SYSROOT_STRIP = "1" 5140*4882a593Smuzhiyun SOLIBS = ".so" 5141*4882a593Smuzhiyun FILES_SOLIBSDEV = "" 5142*4882a593Smuzhiyun 5143*4882a593Smuzhiyun do_install () { 5144*4882a593Smuzhiyun install -d ${D}${libdir} 5145*4882a593Smuzhiyun install -m 0755 ${WORKDIR}/libfoo.so ${D}${libdir} 5146*4882a593Smuzhiyun } 5147*4882a593Smuzhiyun 5148*4882a593SmuzhiyunUsing x32 psABI 5149*4882a593Smuzhiyun=============== 5150*4882a593Smuzhiyun 5151*4882a593Smuzhiyunx32 processor-specific Application Binary Interface (`x32 5152*4882a593SmuzhiyunpsABI <https://software.intel.com/en-us/node/628948>`__) is a native 5153*4882a593Smuzhiyun32-bit processor-specific ABI for Intel 64 (x86-64) architectures. An 5154*4882a593SmuzhiyunABI defines the calling conventions between functions in a processing 5155*4882a593Smuzhiyunenvironment. The interface determines what registers are used and what 5156*4882a593Smuzhiyunthe sizes are for various C data types. 5157*4882a593Smuzhiyun 5158*4882a593SmuzhiyunSome processing environments prefer using 32-bit applications even when 5159*4882a593Smuzhiyunrunning on Intel 64-bit platforms. Consider the i386 psABI, which is a 5160*4882a593Smuzhiyunvery old 32-bit ABI for Intel 64-bit platforms. The i386 psABI does not 5161*4882a593Smuzhiyunprovide efficient use and access of the Intel 64-bit processor 5162*4882a593Smuzhiyunresources, leaving the system underutilized. Now consider the x86_64 5163*4882a593SmuzhiyunpsABI. This ABI is newer and uses 64-bits for data sizes and program 5164*4882a593Smuzhiyunpointers. The extra bits increase the footprint size of the programs, 5165*4882a593Smuzhiyunlibraries, and also increases the memory and file system size 5166*4882a593Smuzhiyunrequirements. Executing under the x32 psABI enables user programs to 5167*4882a593Smuzhiyunutilize CPU and system resources more efficiently while keeping the 5168*4882a593Smuzhiyunmemory footprint of the applications low. Extra bits are used for 5169*4882a593Smuzhiyunregisters but not for addressing mechanisms. 5170*4882a593Smuzhiyun 5171*4882a593SmuzhiyunThe Yocto Project supports the final specifications of x32 psABI as 5172*4882a593Smuzhiyunfollows: 5173*4882a593Smuzhiyun 5174*4882a593Smuzhiyun- You can create packages and images in x32 psABI format on x86_64 5175*4882a593Smuzhiyun architecture targets. 5176*4882a593Smuzhiyun 5177*4882a593Smuzhiyun- You can successfully build recipes with the x32 toolchain. 5178*4882a593Smuzhiyun 5179*4882a593Smuzhiyun- You can create and boot ``core-image-minimal`` and 5180*4882a593Smuzhiyun ``core-image-sato`` images. 5181*4882a593Smuzhiyun 5182*4882a593Smuzhiyun- There is RPM Package Manager (RPM) support for x32 binaries. 5183*4882a593Smuzhiyun 5184*4882a593Smuzhiyun- There is support for large images. 5185*4882a593Smuzhiyun 5186*4882a593SmuzhiyunTo use the x32 psABI, you need to edit your ``conf/local.conf`` 5187*4882a593Smuzhiyunconfiguration file as follows:: 5188*4882a593Smuzhiyun 5189*4882a593Smuzhiyun MACHINE = "qemux86-64" 5190*4882a593Smuzhiyun DEFAULTTUNE = "x86-64-x32" 5191*4882a593Smuzhiyun baselib = "${@d.getVar('BASE_LIB:tune-' + (d.getVar('DEFAULTTUNE') \ 5192*4882a593Smuzhiyun or 'INVALID')) or 'lib'}" 5193*4882a593Smuzhiyun 5194*4882a593SmuzhiyunOnce you have set 5195*4882a593Smuzhiyunup your configuration file, use BitBake to build an image that supports 5196*4882a593Smuzhiyunthe x32 psABI. Here is an example:: 5197*4882a593Smuzhiyun 5198*4882a593Smuzhiyun $ bitbake core-image-sato 5199*4882a593Smuzhiyun 5200*4882a593SmuzhiyunEnabling GObject Introspection Support 5201*4882a593Smuzhiyun====================================== 5202*4882a593Smuzhiyun 5203*4882a593Smuzhiyun`GObject introspection <https://gi.readthedocs.io/en/latest/>`__ 5204*4882a593Smuzhiyunis the standard mechanism for accessing GObject-based software from 5205*4882a593Smuzhiyunruntime environments. GObject is a feature of the GLib library that 5206*4882a593Smuzhiyunprovides an object framework for the GNOME desktop and related software. 5207*4882a593SmuzhiyunGObject Introspection adds information to GObject that allows objects 5208*4882a593Smuzhiyuncreated within it to be represented across different programming 5209*4882a593Smuzhiyunlanguages. If you want to construct GStreamer pipelines using Python, or 5210*4882a593Smuzhiyuncontrol UPnP infrastructure using Javascript and GUPnP, GObject 5211*4882a593Smuzhiyunintrospection is the only way to do it. 5212*4882a593Smuzhiyun 5213*4882a593SmuzhiyunThis section describes the Yocto Project support for generating and 5214*4882a593Smuzhiyunpackaging GObject introspection data. GObject introspection data is a 5215*4882a593Smuzhiyundescription of the API provided by libraries built on top of the GLib 5216*4882a593Smuzhiyunframework, and, in particular, that framework's GObject mechanism. 5217*4882a593SmuzhiyunGObject Introspection Repository (GIR) files go to ``-dev`` packages, 5218*4882a593Smuzhiyun``typelib`` files go to main packages as they are packaged together with 5219*4882a593Smuzhiyunlibraries that are introspected. 5220*4882a593Smuzhiyun 5221*4882a593SmuzhiyunThe data is generated when building such a library, by linking the 5222*4882a593Smuzhiyunlibrary with a small executable binary that asks the library to describe 5223*4882a593Smuzhiyunitself, and then executing the binary and processing its output. 5224*4882a593Smuzhiyun 5225*4882a593SmuzhiyunGenerating this data in a cross-compilation environment is difficult 5226*4882a593Smuzhiyunbecause the library is produced for the target architecture, but its 5227*4882a593Smuzhiyuncode needs to be executed on the build host. This problem is solved with 5228*4882a593Smuzhiyunthe OpenEmbedded build system by running the code through QEMU, which 5229*4882a593Smuzhiyunallows precisely that. Unfortunately, QEMU does not always work 5230*4882a593Smuzhiyunperfectly as mentioned in the ":ref:`dev-manual/common-tasks:known issues`" 5231*4882a593Smuzhiyunsection. 5232*4882a593Smuzhiyun 5233*4882a593SmuzhiyunEnabling the Generation of Introspection Data 5234*4882a593Smuzhiyun--------------------------------------------- 5235*4882a593Smuzhiyun 5236*4882a593SmuzhiyunEnabling the generation of introspection data (GIR files) in your 5237*4882a593Smuzhiyunlibrary package involves the following: 5238*4882a593Smuzhiyun 5239*4882a593Smuzhiyun1. Inherit the 5240*4882a593Smuzhiyun :ref:`gobject-introspection <ref-classes-gobject-introspection>` 5241*4882a593Smuzhiyun class. 5242*4882a593Smuzhiyun 5243*4882a593Smuzhiyun2. Make sure introspection is not disabled anywhere in the recipe or 5244*4882a593Smuzhiyun from anything the recipe includes. Also, make sure that 5245*4882a593Smuzhiyun "gobject-introspection-data" is not in 5246*4882a593Smuzhiyun :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` 5247*4882a593Smuzhiyun and that "qemu-usermode" is not in 5248*4882a593Smuzhiyun :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. 5249*4882a593Smuzhiyun In either of these conditions, nothing will happen. 5250*4882a593Smuzhiyun 5251*4882a593Smuzhiyun3. Try to build the recipe. If you encounter build errors that look like 5252*4882a593Smuzhiyun something is unable to find ``.so`` libraries, check where these 5253*4882a593Smuzhiyun libraries are located in the source tree and add the following to the 5254*4882a593Smuzhiyun recipe:: 5255*4882a593Smuzhiyun 5256*4882a593Smuzhiyun GIR_EXTRA_LIBS_PATH = "${B}/something/.libs" 5257*4882a593Smuzhiyun 5258*4882a593Smuzhiyun .. note:: 5259*4882a593Smuzhiyun 5260*4882a593Smuzhiyun See recipes in the ``oe-core`` repository that use that 5261*4882a593Smuzhiyun :term:`GIR_EXTRA_LIBS_PATH` variable as an example. 5262*4882a593Smuzhiyun 5263*4882a593Smuzhiyun4. Look for any other errors, which probably mean that introspection 5264*4882a593Smuzhiyun support in a package is not entirely standard, and thus breaks down 5265*4882a593Smuzhiyun in a cross-compilation environment. For such cases, custom-made fixes 5266*4882a593Smuzhiyun are needed. A good place to ask and receive help in these cases is 5267*4882a593Smuzhiyun the :ref:`Yocto Project mailing 5268*4882a593Smuzhiyun lists <resources-mailinglist>`. 5269*4882a593Smuzhiyun 5270*4882a593Smuzhiyun.. note:: 5271*4882a593Smuzhiyun 5272*4882a593Smuzhiyun Using a library that no longer builds against the latest Yocto 5273*4882a593Smuzhiyun Project release and prints introspection related errors is a good 5274*4882a593Smuzhiyun candidate for the previous procedure. 5275*4882a593Smuzhiyun 5276*4882a593SmuzhiyunDisabling the Generation of Introspection Data 5277*4882a593Smuzhiyun---------------------------------------------- 5278*4882a593Smuzhiyun 5279*4882a593SmuzhiyunYou might find that you do not want to generate introspection data. Or, 5280*4882a593Smuzhiyunperhaps QEMU does not work on your build host and target architecture 5281*4882a593Smuzhiyuncombination. If so, you can use either of the following methods to 5282*4882a593Smuzhiyundisable GIR file generations: 5283*4882a593Smuzhiyun 5284*4882a593Smuzhiyun- Add the following to your distro configuration:: 5285*4882a593Smuzhiyun 5286*4882a593Smuzhiyun DISTRO_FEATURES_BACKFILL_CONSIDERED = "gobject-introspection-data" 5287*4882a593Smuzhiyun 5288*4882a593Smuzhiyun Adding this statement disables generating introspection data using 5289*4882a593Smuzhiyun QEMU but will still enable building introspection tools and libraries 5290*4882a593Smuzhiyun (i.e. building them does not require the use of QEMU). 5291*4882a593Smuzhiyun 5292*4882a593Smuzhiyun- Add the following to your machine configuration:: 5293*4882a593Smuzhiyun 5294*4882a593Smuzhiyun MACHINE_FEATURES_BACKFILL_CONSIDERED = "qemu-usermode" 5295*4882a593Smuzhiyun 5296*4882a593Smuzhiyun Adding this statement disables the use of QEMU when building packages for your 5297*4882a593Smuzhiyun machine. Currently, this feature is used only by introspection 5298*4882a593Smuzhiyun recipes and has the same effect as the previously described option. 5299*4882a593Smuzhiyun 5300*4882a593Smuzhiyun .. note:: 5301*4882a593Smuzhiyun 5302*4882a593Smuzhiyun Future releases of the Yocto Project might have other features 5303*4882a593Smuzhiyun affected by this option. 5304*4882a593Smuzhiyun 5305*4882a593SmuzhiyunIf you disable introspection data, you can still obtain it through other 5306*4882a593Smuzhiyunmeans such as copying the data from a suitable sysroot, or by generating 5307*4882a593Smuzhiyunit on the target hardware. The OpenEmbedded build system does not 5308*4882a593Smuzhiyuncurrently provide specific support for these techniques. 5309*4882a593Smuzhiyun 5310*4882a593SmuzhiyunTesting that Introspection Works in an Image 5311*4882a593Smuzhiyun-------------------------------------------- 5312*4882a593Smuzhiyun 5313*4882a593SmuzhiyunUse the following procedure to test if generating introspection data is 5314*4882a593Smuzhiyunworking in an image: 5315*4882a593Smuzhiyun 5316*4882a593Smuzhiyun1. Make sure that "gobject-introspection-data" is not in 5317*4882a593Smuzhiyun :term:`DISTRO_FEATURES_BACKFILL_CONSIDERED` 5318*4882a593Smuzhiyun and that "qemu-usermode" is not in 5319*4882a593Smuzhiyun :term:`MACHINE_FEATURES_BACKFILL_CONSIDERED`. 5320*4882a593Smuzhiyun 5321*4882a593Smuzhiyun2. Build ``core-image-sato``. 5322*4882a593Smuzhiyun 5323*4882a593Smuzhiyun3. Launch a Terminal and then start Python in the terminal. 5324*4882a593Smuzhiyun 5325*4882a593Smuzhiyun4. Enter the following in the terminal:: 5326*4882a593Smuzhiyun 5327*4882a593Smuzhiyun >>> from gi.repository import GLib 5328*4882a593Smuzhiyun >>> GLib.get_host_name() 5329*4882a593Smuzhiyun 5330*4882a593Smuzhiyun5. For something a little more advanced, enter the following see: 5331*4882a593Smuzhiyun https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html 5332*4882a593Smuzhiyun 5333*4882a593SmuzhiyunKnown Issues 5334*4882a593Smuzhiyun------------ 5335*4882a593Smuzhiyun 5336*4882a593SmuzhiyunHere are know issues in GObject Introspection Support: 5337*4882a593Smuzhiyun 5338*4882a593Smuzhiyun- ``qemu-ppc64`` immediately crashes. Consequently, you cannot build 5339*4882a593Smuzhiyun introspection data on that architecture. 5340*4882a593Smuzhiyun 5341*4882a593Smuzhiyun- x32 is not supported by QEMU. Consequently, introspection data is 5342*4882a593Smuzhiyun disabled. 5343*4882a593Smuzhiyun 5344*4882a593Smuzhiyun- musl causes transient GLib binaries to crash on assertion failures. 5345*4882a593Smuzhiyun Consequently, generating introspection data is disabled. 5346*4882a593Smuzhiyun 5347*4882a593Smuzhiyun- Because QEMU is not able to run the binaries correctly, introspection 5348*4882a593Smuzhiyun is disabled for some specific packages under specific architectures 5349*4882a593Smuzhiyun (e.g. ``gcr``, ``libsecret``, and ``webkit``). 5350*4882a593Smuzhiyun 5351*4882a593Smuzhiyun- QEMU usermode might not work properly when running 64-bit binaries 5352*4882a593Smuzhiyun under 32-bit host machines. In particular, "qemumips64" is known to 5353*4882a593Smuzhiyun not work under i686. 5354*4882a593Smuzhiyun 5355*4882a593SmuzhiyunOptionally Using an External Toolchain 5356*4882a593Smuzhiyun====================================== 5357*4882a593Smuzhiyun 5358*4882a593SmuzhiyunYou might want to use an external toolchain as part of your development. 5359*4882a593SmuzhiyunIf this is the case, the fundamental steps you need to accomplish are as 5360*4882a593Smuzhiyunfollows: 5361*4882a593Smuzhiyun 5362*4882a593Smuzhiyun- Understand where the installed toolchain resides. For cases where you 5363*4882a593Smuzhiyun need to build the external toolchain, you would need to take separate 5364*4882a593Smuzhiyun steps to build and install the toolchain. 5365*4882a593Smuzhiyun 5366*4882a593Smuzhiyun- Make sure you add the layer that contains the toolchain to your 5367*4882a593Smuzhiyun ``bblayers.conf`` file through the 5368*4882a593Smuzhiyun :term:`BBLAYERS` variable. 5369*4882a593Smuzhiyun 5370*4882a593Smuzhiyun- Set the ``EXTERNAL_TOOLCHAIN`` variable in your ``local.conf`` file 5371*4882a593Smuzhiyun to the location in which you installed the toolchain. 5372*4882a593Smuzhiyun 5373*4882a593SmuzhiyunA good example of an external toolchain used with the Yocto Project is 5374*4882a593SmuzhiyunMentor Graphics Sourcery G++ Toolchain. You can see information on how 5375*4882a593Smuzhiyunto use that particular layer in the ``README`` file at 5376*4882a593Smuzhiyunhttps://github.com/MentorEmbedded/meta-sourcery/. You can find 5377*4882a593Smuzhiyunfurther information by reading about the 5378*4882a593Smuzhiyun:term:`TCMODE` variable in the Yocto 5379*4882a593SmuzhiyunProject Reference Manual's variable glossary. 5380*4882a593Smuzhiyun 5381*4882a593SmuzhiyunCreating Partitioned Images Using Wic 5382*4882a593Smuzhiyun===================================== 5383*4882a593Smuzhiyun 5384*4882a593SmuzhiyunCreating an image for a particular hardware target using the 5385*4882a593SmuzhiyunOpenEmbedded build system does not necessarily mean you can boot that 5386*4882a593Smuzhiyunimage as is on your device. Physical devices accept and boot images in 5387*4882a593Smuzhiyunvarious ways depending on the specifics of the device. Usually, 5388*4882a593Smuzhiyuninformation about the hardware can tell you what image format the device 5389*4882a593Smuzhiyunrequires. Should your device require multiple partitions on an SD card, 5390*4882a593Smuzhiyunflash, or an HDD, you can use the OpenEmbedded Image Creator, Wic, to 5391*4882a593Smuzhiyuncreate the properly partitioned image. 5392*4882a593Smuzhiyun 5393*4882a593SmuzhiyunThe ``wic`` command generates partitioned images from existing 5394*4882a593SmuzhiyunOpenEmbedded build artifacts. Image generation is driven by partitioning 5395*4882a593Smuzhiyuncommands contained in an Openembedded kickstart file (``.wks``) 5396*4882a593Smuzhiyunspecified either directly on the command line or as one of a selection 5397*4882a593Smuzhiyunof canned kickstart files as shown with the ``wic list images`` command 5398*4882a593Smuzhiyunin the 5399*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:generate an image using an existing kickstart file`" 5400*4882a593Smuzhiyunsection. When you apply the command to a given set of build artifacts, the 5401*4882a593Smuzhiyunresult is an image or set of images that can be directly written onto media and 5402*4882a593Smuzhiyunused on a particular system. 5403*4882a593Smuzhiyun 5404*4882a593Smuzhiyun.. note:: 5405*4882a593Smuzhiyun 5406*4882a593Smuzhiyun For a kickstart file reference, see the 5407*4882a593Smuzhiyun ":ref:`ref-manual/kickstart:openembedded kickstart (\`\`.wks\`\`) reference`" 5408*4882a593Smuzhiyun Chapter in the Yocto Project Reference Manual. 5409*4882a593Smuzhiyun 5410*4882a593SmuzhiyunThe ``wic`` command and the infrastructure it is based on is by 5411*4882a593Smuzhiyundefinition incomplete. The purpose of the command is to allow the 5412*4882a593Smuzhiyungeneration of customized images, and as such, was designed to be 5413*4882a593Smuzhiyuncompletely extensible through a plugin interface. See the 5414*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:using the wic plugin interface`" section 5415*4882a593Smuzhiyunfor information on these plugins. 5416*4882a593Smuzhiyun 5417*4882a593SmuzhiyunThis section provides some background information on Wic, describes what 5418*4882a593Smuzhiyunyou need to have in place to run the tool, provides instruction on how 5419*4882a593Smuzhiyunto use the Wic utility, provides information on using the Wic plugins 5420*4882a593Smuzhiyuninterface, and provides several examples that show how to use Wic. 5421*4882a593Smuzhiyun 5422*4882a593SmuzhiyunBackground 5423*4882a593Smuzhiyun---------- 5424*4882a593Smuzhiyun 5425*4882a593SmuzhiyunThis section provides some background on the Wic utility. While none of 5426*4882a593Smuzhiyunthis information is required to use Wic, you might find it interesting. 5427*4882a593Smuzhiyun 5428*4882a593Smuzhiyun- The name "Wic" is derived from OpenEmbedded Image Creator (oeic). The 5429*4882a593Smuzhiyun "oe" diphthong in "oeic" was promoted to the letter "w", because 5430*4882a593Smuzhiyun "oeic" is both difficult to remember and to pronounce. 5431*4882a593Smuzhiyun 5432*4882a593Smuzhiyun- Wic is loosely based on the Meego Image Creator (``mic``) framework. 5433*4882a593Smuzhiyun The Wic implementation has been heavily modified to make direct use 5434*4882a593Smuzhiyun of OpenEmbedded build artifacts instead of package installation and 5435*4882a593Smuzhiyun configuration, which are already incorporated within the OpenEmbedded 5436*4882a593Smuzhiyun artifacts. 5437*4882a593Smuzhiyun 5438*4882a593Smuzhiyun- Wic is a completely independent standalone utility that initially 5439*4882a593Smuzhiyun provides easier-to-use and more flexible replacements for an existing 5440*4882a593Smuzhiyun functionality in OE-Core's 5441*4882a593Smuzhiyun :ref:`image-live <ref-classes-image-live>` 5442*4882a593Smuzhiyun class. The difference between Wic and those examples is that with Wic 5443*4882a593Smuzhiyun the functionality of those scripts is implemented by a 5444*4882a593Smuzhiyun general-purpose partitioning language, which is based on Redhat 5445*4882a593Smuzhiyun kickstart syntax. 5446*4882a593Smuzhiyun 5447*4882a593SmuzhiyunRequirements 5448*4882a593Smuzhiyun------------ 5449*4882a593Smuzhiyun 5450*4882a593SmuzhiyunIn order to use the Wic utility with the OpenEmbedded Build system, your 5451*4882a593Smuzhiyunsystem needs to meet the following requirements: 5452*4882a593Smuzhiyun 5453*4882a593Smuzhiyun- The Linux distribution on your development host must support the 5454*4882a593Smuzhiyun Yocto Project. See the ":ref:`detailed-supported-distros`" 5455*4882a593Smuzhiyun section in the Yocto Project Reference Manual for the list of 5456*4882a593Smuzhiyun distributions that support the Yocto Project. 5457*4882a593Smuzhiyun 5458*4882a593Smuzhiyun- The standard system utilities, such as ``cp``, must be installed on 5459*4882a593Smuzhiyun your development host system. 5460*4882a593Smuzhiyun 5461*4882a593Smuzhiyun- You must have sourced the build environment setup script (i.e. 5462*4882a593Smuzhiyun :ref:`structure-core-script`) found in the 5463*4882a593Smuzhiyun :term:`Build Directory`. 5464*4882a593Smuzhiyun 5465*4882a593Smuzhiyun- You need to have the build artifacts already available, which 5466*4882a593Smuzhiyun typically means that you must have already created an image using the 5467*4882a593Smuzhiyun Openembedded build system (e.g. ``core-image-minimal``). While it 5468*4882a593Smuzhiyun might seem redundant to generate an image in order to create an image 5469*4882a593Smuzhiyun using Wic, the current version of Wic requires the artifacts in the 5470*4882a593Smuzhiyun form generated by the OpenEmbedded build system. 5471*4882a593Smuzhiyun 5472*4882a593Smuzhiyun- You must build several native tools, which are built to run on the 5473*4882a593Smuzhiyun build system:: 5474*4882a593Smuzhiyun 5475*4882a593Smuzhiyun $ bitbake parted-native dosfstools-native mtools-native 5476*4882a593Smuzhiyun 5477*4882a593Smuzhiyun- Include "wic" as part of the 5478*4882a593Smuzhiyun :term:`IMAGE_FSTYPES` 5479*4882a593Smuzhiyun variable. 5480*4882a593Smuzhiyun 5481*4882a593Smuzhiyun- Include the name of the :ref:`wic kickstart file <openembedded-kickstart-wks-reference>` 5482*4882a593Smuzhiyun as part of the :term:`WKS_FILE` variable 5483*4882a593Smuzhiyun 5484*4882a593SmuzhiyunGetting Help 5485*4882a593Smuzhiyun------------ 5486*4882a593Smuzhiyun 5487*4882a593SmuzhiyunYou can get general help for the ``wic`` command by entering the ``wic`` 5488*4882a593Smuzhiyuncommand by itself or by entering the command with a help argument as 5489*4882a593Smuzhiyunfollows:: 5490*4882a593Smuzhiyun 5491*4882a593Smuzhiyun $ wic -h 5492*4882a593Smuzhiyun $ wic --help 5493*4882a593Smuzhiyun $ wic help 5494*4882a593Smuzhiyun 5495*4882a593SmuzhiyunCurrently, Wic supports seven commands: ``cp``, ``create``, ``help``, 5496*4882a593Smuzhiyun``list``, ``ls``, ``rm``, and ``write``. You can get help for all these 5497*4882a593Smuzhiyuncommands except "help" by using the following form:: 5498*4882a593Smuzhiyun 5499*4882a593Smuzhiyun $ wic help command 5500*4882a593Smuzhiyun 5501*4882a593SmuzhiyunFor example, the following command returns help for the ``write`` 5502*4882a593Smuzhiyuncommand:: 5503*4882a593Smuzhiyun 5504*4882a593Smuzhiyun $ wic help write 5505*4882a593Smuzhiyun 5506*4882a593SmuzhiyunWic supports help for three topics: ``overview``, ``plugins``, and 5507*4882a593Smuzhiyun``kickstart``. You can get help for any topic using the following form:: 5508*4882a593Smuzhiyun 5509*4882a593Smuzhiyun $ wic help topic 5510*4882a593Smuzhiyun 5511*4882a593SmuzhiyunFor example, the following returns overview help for Wic:: 5512*4882a593Smuzhiyun 5513*4882a593Smuzhiyun $ wic help overview 5514*4882a593Smuzhiyun 5515*4882a593SmuzhiyunThere is one additional level of help for Wic. You can get help on 5516*4882a593Smuzhiyunindividual images through the ``list`` command. You can use the ``list`` 5517*4882a593Smuzhiyuncommand to return the available Wic images as follows:: 5518*4882a593Smuzhiyun 5519*4882a593Smuzhiyun $ wic list images 5520*4882a593Smuzhiyun genericx86 Create an EFI disk image for genericx86* 5521*4882a593Smuzhiyun edgerouter Create SD card image for Edgerouter 5522*4882a593Smuzhiyun beaglebone-yocto Create SD card image for Beaglebone 5523*4882a593Smuzhiyun qemux86-directdisk Create a qemu machine 'pcbios' direct disk image 5524*4882a593Smuzhiyun systemd-bootdisk Create an EFI disk image with systemd-boot 5525*4882a593Smuzhiyun mkhybridiso Create a hybrid ISO image 5526*4882a593Smuzhiyun mkefidisk Create an EFI disk image 5527*4882a593Smuzhiyun sdimage-bootpart Create SD card image with a boot partition 5528*4882a593Smuzhiyun directdisk-multi-rootfs Create multi rootfs image using rootfs plugin 5529*4882a593Smuzhiyun directdisk Create a 'pcbios' direct disk image 5530*4882a593Smuzhiyun directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config 5531*4882a593Smuzhiyun qemuriscv Create qcow2 image for RISC-V QEMU machines 5532*4882a593Smuzhiyun directdisk-gpt Create a 'pcbios' direct disk image 5533*4882a593Smuzhiyun efi-bootdisk 5534*4882a593Smuzhiyun 5535*4882a593SmuzhiyunOnce you know the list of available 5536*4882a593SmuzhiyunWic images, you can use ``help`` with the command to get help on a 5537*4882a593Smuzhiyunparticular image. For example, the following command returns help on the 5538*4882a593Smuzhiyun"beaglebone-yocto" image:: 5539*4882a593Smuzhiyun 5540*4882a593Smuzhiyun $ wic list beaglebone-yocto help 5541*4882a593Smuzhiyun 5542*4882a593Smuzhiyun Creates a partitioned SD card image for Beaglebone. 5543*4882a593Smuzhiyun Boot files are located in the first vfat partition. 5544*4882a593Smuzhiyun 5545*4882a593SmuzhiyunOperational Modes 5546*4882a593Smuzhiyun----------------- 5547*4882a593Smuzhiyun 5548*4882a593SmuzhiyunYou can use Wic in two different modes, depending on how much control 5549*4882a593Smuzhiyunyou need for specifying the Openembedded build artifacts that are used 5550*4882a593Smuzhiyunfor creating the image: Raw and Cooked: 5551*4882a593Smuzhiyun 5552*4882a593Smuzhiyun- *Raw Mode:* You explicitly specify build artifacts through Wic 5553*4882a593Smuzhiyun command-line arguments. 5554*4882a593Smuzhiyun 5555*4882a593Smuzhiyun- *Cooked Mode:* The current 5556*4882a593Smuzhiyun :term:`MACHINE` setting and image 5557*4882a593Smuzhiyun name are used to automatically locate and provide the build 5558*4882a593Smuzhiyun artifacts. You just supply a kickstart file and the name of the image 5559*4882a593Smuzhiyun from which to use artifacts. 5560*4882a593Smuzhiyun 5561*4882a593SmuzhiyunRegardless of the mode you use, you need to have the build artifacts 5562*4882a593Smuzhiyunready and available. 5563*4882a593Smuzhiyun 5564*4882a593SmuzhiyunRaw Mode 5565*4882a593Smuzhiyun~~~~~~~~ 5566*4882a593Smuzhiyun 5567*4882a593SmuzhiyunRunning Wic in raw mode allows you to specify all the partitions through 5568*4882a593Smuzhiyunthe ``wic`` command line. The primary use for raw mode is if you have 5569*4882a593Smuzhiyunbuilt your kernel outside of the Yocto Project 5570*4882a593Smuzhiyun:term:`Build Directory`. In other words, you 5571*4882a593Smuzhiyuncan point to arbitrary kernel, root filesystem locations, and so forth. 5572*4882a593SmuzhiyunContrast this behavior with cooked mode where Wic looks in the Build 5573*4882a593SmuzhiyunDirectory (e.g. ``tmp/deploy/images/``\ machine). 5574*4882a593Smuzhiyun 5575*4882a593SmuzhiyunThe general form of the ``wic`` command in raw mode is:: 5576*4882a593Smuzhiyun 5577*4882a593Smuzhiyun $ wic create wks_file options ... 5578*4882a593Smuzhiyun 5579*4882a593Smuzhiyun Where: 5580*4882a593Smuzhiyun 5581*4882a593Smuzhiyun wks_file: 5582*4882a593Smuzhiyun An OpenEmbedded kickstart file. You can provide 5583*4882a593Smuzhiyun your own custom file or use a file from a set of 5584*4882a593Smuzhiyun existing files as described by further options. 5585*4882a593Smuzhiyun 5586*4882a593Smuzhiyun optional arguments: 5587*4882a593Smuzhiyun -h, --help show this help message and exit 5588*4882a593Smuzhiyun -o OUTDIR, --outdir OUTDIR 5589*4882a593Smuzhiyun name of directory to create image in 5590*4882a593Smuzhiyun -e IMAGE_NAME, --image-name IMAGE_NAME 5591*4882a593Smuzhiyun name of the image to use the artifacts from e.g. core- 5592*4882a593Smuzhiyun image-sato 5593*4882a593Smuzhiyun -r ROOTFS_DIR, --rootfs-dir ROOTFS_DIR 5594*4882a593Smuzhiyun path to the /rootfs dir to use as the .wks rootfs 5595*4882a593Smuzhiyun source 5596*4882a593Smuzhiyun -b BOOTIMG_DIR, --bootimg-dir BOOTIMG_DIR 5597*4882a593Smuzhiyun path to the dir containing the boot artifacts (e.g. 5598*4882a593Smuzhiyun /EFI or /syslinux dirs) to use as the .wks bootimg 5599*4882a593Smuzhiyun source 5600*4882a593Smuzhiyun -k KERNEL_DIR, --kernel-dir KERNEL_DIR 5601*4882a593Smuzhiyun path to the dir containing the kernel to use in the 5602*4882a593Smuzhiyun .wks bootimg 5603*4882a593Smuzhiyun -n NATIVE_SYSROOT, --native-sysroot NATIVE_SYSROOT 5604*4882a593Smuzhiyun path to the native sysroot containing the tools to use 5605*4882a593Smuzhiyun to build the image 5606*4882a593Smuzhiyun -s, --skip-build-check 5607*4882a593Smuzhiyun skip the build check 5608*4882a593Smuzhiyun -f, --build-rootfs build rootfs 5609*4882a593Smuzhiyun -c {gzip,bzip2,xz}, --compress-with {gzip,bzip2,xz} 5610*4882a593Smuzhiyun compress image with specified compressor 5611*4882a593Smuzhiyun -m, --bmap generate .bmap 5612*4882a593Smuzhiyun --no-fstab-update Do not change fstab file. 5613*4882a593Smuzhiyun -v VARS_DIR, --vars VARS_DIR 5614*4882a593Smuzhiyun directory with <image>.env files that store bitbake 5615*4882a593Smuzhiyun variables 5616*4882a593Smuzhiyun -D, --debug output debug information 5617*4882a593Smuzhiyun 5618*4882a593Smuzhiyun.. note:: 5619*4882a593Smuzhiyun 5620*4882a593Smuzhiyun You do not need root privileges to run Wic. In fact, you should not 5621*4882a593Smuzhiyun run as root when using the utility. 5622*4882a593Smuzhiyun 5623*4882a593SmuzhiyunCooked Mode 5624*4882a593Smuzhiyun~~~~~~~~~~~ 5625*4882a593Smuzhiyun 5626*4882a593SmuzhiyunRunning Wic in cooked mode leverages off artifacts in the Build 5627*4882a593SmuzhiyunDirectory. In other words, you do not have to specify kernel or root 5628*4882a593Smuzhiyunfilesystem locations as part of the command. All you need to provide is 5629*4882a593Smuzhiyuna kickstart file and the name of the image from which to use artifacts 5630*4882a593Smuzhiyunby using the "-e" option. Wic looks in the Build Directory (e.g. 5631*4882a593Smuzhiyun``tmp/deploy/images/``\ machine) for artifacts. 5632*4882a593Smuzhiyun 5633*4882a593SmuzhiyunThe general form of the ``wic`` command using Cooked Mode is as follows:: 5634*4882a593Smuzhiyun 5635*4882a593Smuzhiyun $ wic create wks_file -e IMAGE_NAME 5636*4882a593Smuzhiyun 5637*4882a593Smuzhiyun Where: 5638*4882a593Smuzhiyun 5639*4882a593Smuzhiyun wks_file: 5640*4882a593Smuzhiyun An OpenEmbedded kickstart file. You can provide 5641*4882a593Smuzhiyun your own custom file or use a file from a set of 5642*4882a593Smuzhiyun existing files provided with the Yocto Project 5643*4882a593Smuzhiyun release. 5644*4882a593Smuzhiyun 5645*4882a593Smuzhiyun required argument: 5646*4882a593Smuzhiyun -e IMAGE_NAME, --image-name IMAGE_NAME 5647*4882a593Smuzhiyun name of the image to use the artifacts from e.g. core- 5648*4882a593Smuzhiyun image-sato 5649*4882a593Smuzhiyun 5650*4882a593SmuzhiyunUsing an Existing Kickstart File 5651*4882a593Smuzhiyun-------------------------------- 5652*4882a593Smuzhiyun 5653*4882a593SmuzhiyunIf you do not want to create your own kickstart file, you can use an 5654*4882a593Smuzhiyunexisting file provided by the Wic installation. As shipped, kickstart 5655*4882a593Smuzhiyunfiles can be found in the :ref:`overview-manual/development-environment:yocto project source repositories` in the 5656*4882a593Smuzhiyunfollowing two locations:: 5657*4882a593Smuzhiyun 5658*4882a593Smuzhiyun poky/meta-yocto-bsp/wic 5659*4882a593Smuzhiyun poky/scripts/lib/wic/canned-wks 5660*4882a593Smuzhiyun 5661*4882a593SmuzhiyunUse the following command to list the available kickstart files:: 5662*4882a593Smuzhiyun 5663*4882a593Smuzhiyun $ wic list images 5664*4882a593Smuzhiyun genericx86 Create an EFI disk image for genericx86* 5665*4882a593Smuzhiyun beaglebone-yocto Create SD card image for Beaglebone 5666*4882a593Smuzhiyun edgerouter Create SD card image for Edgerouter 5667*4882a593Smuzhiyun qemux86-directdisk Create a QEMU machine 'pcbios' direct disk image 5668*4882a593Smuzhiyun directdisk-gpt Create a 'pcbios' direct disk image 5669*4882a593Smuzhiyun mkefidisk Create an EFI disk image 5670*4882a593Smuzhiyun directdisk Create a 'pcbios' direct disk image 5671*4882a593Smuzhiyun systemd-bootdisk Create an EFI disk image with systemd-boot 5672*4882a593Smuzhiyun mkhybridiso Create a hybrid ISO image 5673*4882a593Smuzhiyun sdimage-bootpart Create SD card image with a boot partition 5674*4882a593Smuzhiyun directdisk-multi-rootfs Create multi rootfs image using rootfs plugin 5675*4882a593Smuzhiyun directdisk-bootloader-config Create a 'pcbios' direct disk image with custom bootloader config 5676*4882a593Smuzhiyun 5677*4882a593SmuzhiyunWhen you use an existing file, you 5678*4882a593Smuzhiyundo not have to use the ``.wks`` extension. Here is an example in Raw 5679*4882a593SmuzhiyunMode that uses the ``directdisk`` file:: 5680*4882a593Smuzhiyun 5681*4882a593Smuzhiyun $ wic create directdisk -r rootfs_dir -b bootimg_dir \ 5682*4882a593Smuzhiyun -k kernel_dir -n native_sysroot 5683*4882a593Smuzhiyun 5684*4882a593SmuzhiyunHere are the actual partition language commands used in the 5685*4882a593Smuzhiyun``genericx86.wks`` file to generate an image:: 5686*4882a593Smuzhiyun 5687*4882a593Smuzhiyun # short-description: Create an EFI disk image for genericx86* 5688*4882a593Smuzhiyun # long-description: Creates a partitioned EFI disk image for genericx86* machines 5689*4882a593Smuzhiyun part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024 5690*4882a593Smuzhiyun part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid 5691*4882a593Smuzhiyun part swap --ondisk sda --size 44 --label swap1 --fstype=swap 5692*4882a593Smuzhiyun 5693*4882a593Smuzhiyun bootloader --ptable gpt --timeout=5 --append="rootfstype=ext4 console=ttyS0,115200 console=tty0" 5694*4882a593Smuzhiyun 5695*4882a593SmuzhiyunUsing the Wic Plugin Interface 5696*4882a593Smuzhiyun------------------------------ 5697*4882a593Smuzhiyun 5698*4882a593SmuzhiyunYou can extend and specialize Wic functionality by using Wic plugins. 5699*4882a593SmuzhiyunThis section explains the Wic plugin interface. 5700*4882a593Smuzhiyun 5701*4882a593Smuzhiyun.. note:: 5702*4882a593Smuzhiyun 5703*4882a593Smuzhiyun Wic plugins consist of "source" and "imager" plugins. Imager plugins 5704*4882a593Smuzhiyun are beyond the scope of this section. 5705*4882a593Smuzhiyun 5706*4882a593SmuzhiyunSource plugins provide a mechanism to customize partition content during 5707*4882a593Smuzhiyunthe Wic image generation process. You can use source plugins to map 5708*4882a593Smuzhiyunvalues that you specify using ``--source`` commands in kickstart files 5709*4882a593Smuzhiyun(i.e. ``*.wks``) to a plugin implementation used to populate a given 5710*4882a593Smuzhiyunpartition. 5711*4882a593Smuzhiyun 5712*4882a593Smuzhiyun.. note:: 5713*4882a593Smuzhiyun 5714*4882a593Smuzhiyun If you use plugins that have build-time dependencies (e.g. native 5715*4882a593Smuzhiyun tools, bootloaders, and so forth) when building a Wic image, you need 5716*4882a593Smuzhiyun to specify those dependencies using the :term:`WKS_FILE_DEPENDS` 5717*4882a593Smuzhiyun variable. 5718*4882a593Smuzhiyun 5719*4882a593SmuzhiyunSource plugins are subclasses defined in plugin files. As shipped, the 5720*4882a593SmuzhiyunYocto Project provides several plugin files. You can see the source 5721*4882a593Smuzhiyunplugin files that ship with the Yocto Project 5722*4882a593Smuzhiyun:yocto_git:`here </poky/tree/scripts/lib/wic/plugins/source>`. 5723*4882a593SmuzhiyunEach of these plugin files contains source plugins that are designed to 5724*4882a593Smuzhiyunpopulate a specific Wic image partition. 5725*4882a593Smuzhiyun 5726*4882a593SmuzhiyunSource plugins are subclasses of the ``SourcePlugin`` class, which is 5727*4882a593Smuzhiyundefined in the ``poky/scripts/lib/wic/pluginbase.py`` file. For example, 5728*4882a593Smuzhiyunthe ``BootimgEFIPlugin`` source plugin found in the ``bootimg-efi.py`` 5729*4882a593Smuzhiyunfile is a subclass of the ``SourcePlugin`` class, which is found in the 5730*4882a593Smuzhiyun``pluginbase.py`` file. 5731*4882a593Smuzhiyun 5732*4882a593SmuzhiyunYou can also implement source plugins in a layer outside of the Source 5733*4882a593SmuzhiyunRepositories (external layer). To do so, be sure that your plugin files 5734*4882a593Smuzhiyunare located in a directory whose path is 5735*4882a593Smuzhiyun``scripts/lib/wic/plugins/source/`` within your external layer. When the 5736*4882a593Smuzhiyunplugin files are located there, the source plugins they contain are made 5737*4882a593Smuzhiyunavailable to Wic. 5738*4882a593Smuzhiyun 5739*4882a593SmuzhiyunWhen the Wic implementation needs to invoke a partition-specific 5740*4882a593Smuzhiyunimplementation, it looks for the plugin with the same name as the 5741*4882a593Smuzhiyun``--source`` parameter used in the kickstart file given to that 5742*4882a593Smuzhiyunpartition. For example, if the partition is set up using the following 5743*4882a593Smuzhiyuncommand in a kickstart file:: 5744*4882a593Smuzhiyun 5745*4882a593Smuzhiyun part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 5746*4882a593Smuzhiyun 5747*4882a593SmuzhiyunThe methods defined as class 5748*4882a593Smuzhiyunmembers of the matching source plugin (i.e. ``bootimg-pcbios``) in the 5749*4882a593Smuzhiyun``bootimg-pcbios.py`` plugin file are used. 5750*4882a593Smuzhiyun 5751*4882a593SmuzhiyunTo be more concrete, here is the corresponding plugin definition from 5752*4882a593Smuzhiyunthe ``bootimg-pcbios.py`` file for the previous command along with an 5753*4882a593Smuzhiyunexample method called by the Wic implementation when it needs to prepare 5754*4882a593Smuzhiyuna partition using an implementation-specific function:: 5755*4882a593Smuzhiyun 5756*4882a593Smuzhiyun . 5757*4882a593Smuzhiyun . 5758*4882a593Smuzhiyun . 5759*4882a593Smuzhiyun class BootimgPcbiosPlugin(SourcePlugin): 5760*4882a593Smuzhiyun """ 5761*4882a593Smuzhiyun Create MBR boot partition and install syslinux on it. 5762*4882a593Smuzhiyun """ 5763*4882a593Smuzhiyun 5764*4882a593Smuzhiyun name = 'bootimg-pcbios' 5765*4882a593Smuzhiyun . 5766*4882a593Smuzhiyun . 5767*4882a593Smuzhiyun . 5768*4882a593Smuzhiyun @classmethod 5769*4882a593Smuzhiyun def do_prepare_partition(cls, part, source_params, creator, cr_workdir, 5770*4882a593Smuzhiyun oe_builddir, bootimg_dir, kernel_dir, 5771*4882a593Smuzhiyun rootfs_dir, native_sysroot): 5772*4882a593Smuzhiyun """ 5773*4882a593Smuzhiyun Called to do the actual content population for a partition i.e. it 5774*4882a593Smuzhiyun 'prepares' the partition to be incorporated into the image. 5775*4882a593Smuzhiyun In this case, prepare content for legacy bios boot partition. 5776*4882a593Smuzhiyun """ 5777*4882a593Smuzhiyun . 5778*4882a593Smuzhiyun . 5779*4882a593Smuzhiyun . 5780*4882a593Smuzhiyun 5781*4882a593SmuzhiyunIf a 5782*4882a593Smuzhiyunsubclass (plugin) itself does not implement a particular function, Wic 5783*4882a593Smuzhiyunlocates and uses the default version in the superclass. It is for this 5784*4882a593Smuzhiyunreason that all source plugins are derived from the ``SourcePlugin`` 5785*4882a593Smuzhiyunclass. 5786*4882a593Smuzhiyun 5787*4882a593SmuzhiyunThe ``SourcePlugin`` class defined in the ``pluginbase.py`` file defines 5788*4882a593Smuzhiyuna set of methods that source plugins can implement or override. Any 5789*4882a593Smuzhiyunplugins (subclass of ``SourcePlugin``) that do not implement a 5790*4882a593Smuzhiyunparticular method inherit the implementation of the method from the 5791*4882a593Smuzhiyun``SourcePlugin`` class. For more information, see the ``SourcePlugin`` 5792*4882a593Smuzhiyunclass in the ``pluginbase.py`` file for details: 5793*4882a593Smuzhiyun 5794*4882a593SmuzhiyunThe following list describes the methods implemented in the 5795*4882a593Smuzhiyun``SourcePlugin`` class: 5796*4882a593Smuzhiyun 5797*4882a593Smuzhiyun- ``do_prepare_partition()``: Called to populate a partition with 5798*4882a593Smuzhiyun actual content. In other words, the method prepares the final 5799*4882a593Smuzhiyun partition image that is incorporated into the disk image. 5800*4882a593Smuzhiyun 5801*4882a593Smuzhiyun- ``do_configure_partition()``: Called before 5802*4882a593Smuzhiyun ``do_prepare_partition()`` to create custom configuration files for a 5803*4882a593Smuzhiyun partition (e.g. syslinux or grub configuration files). 5804*4882a593Smuzhiyun 5805*4882a593Smuzhiyun- ``do_install_disk()``: Called after all partitions have been 5806*4882a593Smuzhiyun prepared and assembled into a disk image. This method provides a hook 5807*4882a593Smuzhiyun to allow finalization of a disk image (e.g. writing an MBR). 5808*4882a593Smuzhiyun 5809*4882a593Smuzhiyun- ``do_stage_partition()``: Special content-staging hook called 5810*4882a593Smuzhiyun before ``do_prepare_partition()``. This method is normally empty. 5811*4882a593Smuzhiyun 5812*4882a593Smuzhiyun Typically, a partition just uses the passed-in parameters (e.g. the 5813*4882a593Smuzhiyun unmodified value of ``bootimg_dir``). However, in some cases, things 5814*4882a593Smuzhiyun might need to be more tailored. As an example, certain files might 5815*4882a593Smuzhiyun additionally need to be taken from ``bootimg_dir + /boot``. This hook 5816*4882a593Smuzhiyun allows those files to be staged in a customized fashion. 5817*4882a593Smuzhiyun 5818*4882a593Smuzhiyun .. note:: 5819*4882a593Smuzhiyun 5820*4882a593Smuzhiyun ``get_bitbake_var()`` allows you to access non-standard variables that 5821*4882a593Smuzhiyun you might want to use for this behavior. 5822*4882a593Smuzhiyun 5823*4882a593SmuzhiyunYou can extend the source plugin mechanism. To add more hooks, create 5824*4882a593Smuzhiyunmore source plugin methods within ``SourcePlugin`` and the corresponding 5825*4882a593Smuzhiyunderived subclasses. The code that calls the plugin methods uses the 5826*4882a593Smuzhiyun``plugin.get_source_plugin_methods()`` function to find the method or 5827*4882a593Smuzhiyunmethods needed by the call. Retrieval of those methods is accomplished 5828*4882a593Smuzhiyunby filling up a dict with keys that contain the method names of 5829*4882a593Smuzhiyuninterest. On success, these will be filled in with the actual methods. 5830*4882a593SmuzhiyunSee the Wic implementation for examples and details. 5831*4882a593Smuzhiyun 5832*4882a593SmuzhiyunWic Examples 5833*4882a593Smuzhiyun------------ 5834*4882a593Smuzhiyun 5835*4882a593SmuzhiyunThis section provides several examples that show how to use the Wic 5836*4882a593Smuzhiyunutility. All the examples assume the list of requirements in the 5837*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:requirements`" section have been met. The 5838*4882a593Smuzhiyunexamples assume the previously generated image is 5839*4882a593Smuzhiyun``core-image-minimal``. 5840*4882a593Smuzhiyun 5841*4882a593SmuzhiyunGenerate an Image using an Existing Kickstart File 5842*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5843*4882a593Smuzhiyun 5844*4882a593SmuzhiyunThis example runs in Cooked Mode and uses the ``mkefidisk`` kickstart 5845*4882a593Smuzhiyunfile:: 5846*4882a593Smuzhiyun 5847*4882a593Smuzhiyun $ wic create mkefidisk -e core-image-minimal 5848*4882a593Smuzhiyun INFO: Building wic-tools... 5849*4882a593Smuzhiyun . 5850*4882a593Smuzhiyun . 5851*4882a593Smuzhiyun . 5852*4882a593Smuzhiyun INFO: The new image(s) can be found here: 5853*4882a593Smuzhiyun ./mkefidisk-201804191017-sda.direct 5854*4882a593Smuzhiyun 5855*4882a593Smuzhiyun The following build artifacts were used to create the image(s): 5856*4882a593Smuzhiyun ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs 5857*4882a593Smuzhiyun BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share 5858*4882a593Smuzhiyun KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 5859*4882a593Smuzhiyun NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native 5860*4882a593Smuzhiyun 5861*4882a593Smuzhiyun INFO: The image(s) were created using OE kickstart file: 5862*4882a593Smuzhiyun /home/stephano/yocto/openembedded-core/scripts/lib/wic/canned-wks/mkefidisk.wks 5863*4882a593Smuzhiyun 5864*4882a593SmuzhiyunThe previous example shows the easiest way to create an image by running 5865*4882a593Smuzhiyunin cooked mode and supplying a kickstart file and the "-e" option to 5866*4882a593Smuzhiyunpoint to the existing build artifacts. Your ``local.conf`` file needs to 5867*4882a593Smuzhiyunhave the :term:`MACHINE` variable set 5868*4882a593Smuzhiyunto the machine you are using, which is "qemux86" in this example. 5869*4882a593Smuzhiyun 5870*4882a593SmuzhiyunOnce the image builds, the output provides image location, artifact use, 5871*4882a593Smuzhiyunand kickstart file information. 5872*4882a593Smuzhiyun 5873*4882a593Smuzhiyun.. note:: 5874*4882a593Smuzhiyun 5875*4882a593Smuzhiyun You should always verify the details provided in the output to make 5876*4882a593Smuzhiyun sure that the image was indeed created exactly as expected. 5877*4882a593Smuzhiyun 5878*4882a593SmuzhiyunContinuing with the example, you can now write the image from the Build 5879*4882a593SmuzhiyunDirectory onto a USB stick, or whatever media for which you built your 5880*4882a593Smuzhiyunimage, and boot from the media. You can write the image by using 5881*4882a593Smuzhiyun``bmaptool`` or ``dd``:: 5882*4882a593Smuzhiyun 5883*4882a593Smuzhiyun $ oe-run-native bmaptool copy mkefidisk-201804191017-sda.direct /dev/sdX 5884*4882a593Smuzhiyun 5885*4882a593Smuzhiyunor :: 5886*4882a593Smuzhiyun 5887*4882a593Smuzhiyun $ sudo dd if=mkefidisk-201804191017-sda.direct of=/dev/sdX 5888*4882a593Smuzhiyun 5889*4882a593Smuzhiyun.. note:: 5890*4882a593Smuzhiyun 5891*4882a593Smuzhiyun For more information on how to use the ``bmaptool`` 5892*4882a593Smuzhiyun to flash a device with an image, see the 5893*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:flashing images using \`\`bmaptool\`\``" 5894*4882a593Smuzhiyun section. 5895*4882a593Smuzhiyun 5896*4882a593SmuzhiyunUsing a Modified Kickstart File 5897*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5898*4882a593Smuzhiyun 5899*4882a593SmuzhiyunBecause partitioned image creation is driven by the kickstart file, it 5900*4882a593Smuzhiyunis easy to affect image creation by changing the parameters in the file. 5901*4882a593SmuzhiyunThis next example demonstrates that through modification of the 5902*4882a593Smuzhiyun``directdisk-gpt`` kickstart file. 5903*4882a593Smuzhiyun 5904*4882a593SmuzhiyunAs mentioned earlier, you can use the command ``wic list images`` to 5905*4882a593Smuzhiyunshow the list of existing kickstart files. The directory in which the 5906*4882a593Smuzhiyun``directdisk-gpt.wks`` file resides is 5907*4882a593Smuzhiyun``scripts/lib/image/canned-wks/``, which is located in the 5908*4882a593Smuzhiyun:term:`Source Directory` (e.g. ``poky``). 5909*4882a593SmuzhiyunBecause available files reside in this directory, you can create and add 5910*4882a593Smuzhiyunyour own custom files to the directory. Subsequent use of the 5911*4882a593Smuzhiyun``wic list images`` command would then include your kickstart files. 5912*4882a593Smuzhiyun 5913*4882a593SmuzhiyunIn this example, the existing ``directdisk-gpt`` file already does most 5914*4882a593Smuzhiyunof what is needed. However, for the hardware in this example, the image 5915*4882a593Smuzhiyunwill need to boot from ``sdb`` instead of ``sda``, which is what the 5916*4882a593Smuzhiyun``directdisk-gpt`` kickstart file uses. 5917*4882a593Smuzhiyun 5918*4882a593SmuzhiyunThe example begins by making a copy of the ``directdisk-gpt.wks`` file 5919*4882a593Smuzhiyunin the ``scripts/lib/image/canned-wks`` directory and then by changing 5920*4882a593Smuzhiyunthe lines that specify the target disk from which to boot. 5921*4882a593Smuzhiyun:: 5922*4882a593Smuzhiyun 5923*4882a593Smuzhiyun $ cp /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisk-gpt.wks \ 5924*4882a593Smuzhiyun /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks 5925*4882a593Smuzhiyun 5926*4882a593SmuzhiyunNext, the example modifies the ``directdisksdb-gpt.wks`` file and 5927*4882a593Smuzhiyunchanges all instances of "``--ondisk sda``" to "``--ondisk sdb``". The 5928*4882a593Smuzhiyunexample changes the following two lines and leaves the remaining lines 5929*4882a593Smuzhiyununtouched:: 5930*4882a593Smuzhiyun 5931*4882a593Smuzhiyun part /boot --source bootimg-pcbios --ondisk sdb --label boot --active --align 1024 5932*4882a593Smuzhiyun part / --source rootfs --ondisk sdb --fstype=ext4 --label platform --align 1024 --use-uuid 5933*4882a593Smuzhiyun 5934*4882a593SmuzhiyunOnce the lines are changed, the 5935*4882a593Smuzhiyunexample generates the ``directdisksdb-gpt`` image. The command points 5936*4882a593Smuzhiyunthe process at the ``core-image-minimal`` artifacts for the Next Unit of 5937*4882a593SmuzhiyunComputing (nuc) :term:`MACHINE` the 5938*4882a593Smuzhiyun``local.conf``. 5939*4882a593Smuzhiyun:: 5940*4882a593Smuzhiyun 5941*4882a593Smuzhiyun $ wic create directdisksdb-gpt -e core-image-minimal 5942*4882a593Smuzhiyun INFO: Building wic-tools... 5943*4882a593Smuzhiyun . 5944*4882a593Smuzhiyun . 5945*4882a593Smuzhiyun . 5946*4882a593Smuzhiyun Initialising tasks: 100% |#######################################| Time: 0:00:01 5947*4882a593Smuzhiyun NOTE: Executing SetScene Tasks 5948*4882a593Smuzhiyun NOTE: Executing RunQueue Tasks 5949*4882a593Smuzhiyun NOTE: Tasks Summary: Attempted 1161 tasks of which 1157 didn't need to be rerun and all succeeded. 5950*4882a593Smuzhiyun INFO: Creating image(s)... 5951*4882a593Smuzhiyun 5952*4882a593Smuzhiyun INFO: The new image(s) can be found here: 5953*4882a593Smuzhiyun ./directdisksdb-gpt-201710090938-sdb.direct 5954*4882a593Smuzhiyun 5955*4882a593Smuzhiyun The following build artifacts were used to create the image(s): 5956*4882a593Smuzhiyun ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs 5957*4882a593Smuzhiyun BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share 5958*4882a593Smuzhiyun KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 5959*4882a593Smuzhiyun NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native 5960*4882a593Smuzhiyun 5961*4882a593Smuzhiyun INFO: The image(s) were created using OE kickstart file: 5962*4882a593Smuzhiyun /home/stephano/yocto/poky/scripts/lib/wic/canned-wks/directdisksdb-gpt.wks 5963*4882a593Smuzhiyun 5964*4882a593SmuzhiyunContinuing with the example, you can now directly ``dd`` the image to a 5965*4882a593SmuzhiyunUSB stick, or whatever media for which you built your image, and boot 5966*4882a593Smuzhiyunthe resulting media:: 5967*4882a593Smuzhiyun 5968*4882a593Smuzhiyun $ sudo dd if=directdisksdb-gpt-201710090938-sdb.direct of=/dev/sdb 5969*4882a593Smuzhiyun 140966+0 records in 5970*4882a593Smuzhiyun 140966+0 records out 5971*4882a593Smuzhiyun 72174592 bytes (72 MB, 69 MiB) copied, 78.0282 s, 925 kB/s 5972*4882a593Smuzhiyun $ sudo eject /dev/sdb 5973*4882a593Smuzhiyun 5974*4882a593SmuzhiyunUsing a Modified Kickstart File and Running in Raw Mode 5975*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5976*4882a593Smuzhiyun 5977*4882a593SmuzhiyunThis next example manually specifies each build artifact (runs in Raw 5978*4882a593SmuzhiyunMode) and uses a modified kickstart file. The example also uses the 5979*4882a593Smuzhiyun``-o`` option to cause Wic to create the output somewhere other than the 5980*4882a593Smuzhiyundefault output directory, which is the current directory:: 5981*4882a593Smuzhiyun 5982*4882a593Smuzhiyun $ wic create test.wks -o /home/stephano/testwic \ 5983*4882a593Smuzhiyun --rootfs-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/rootfs \ 5984*4882a593Smuzhiyun --bootimg-dir /home/stephano/yocto/build/tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share \ 5985*4882a593Smuzhiyun --kernel-dir /home/stephano/yocto/build/tmp/deploy/images/qemux86 \ 5986*4882a593Smuzhiyun --native-sysroot /home/stephano/yocto/build/tmp/work/i586-poky-linux/wic-tools/1.0-r0/recipe-sysroot-native 5987*4882a593Smuzhiyun 5988*4882a593Smuzhiyun INFO: Creating image(s)... 5989*4882a593Smuzhiyun 5990*4882a593Smuzhiyun INFO: The new image(s) can be found here: 5991*4882a593Smuzhiyun /home/stephano/testwic/test-201710091445-sdb.direct 5992*4882a593Smuzhiyun 5993*4882a593Smuzhiyun The following build artifacts were used to create the image(s): 5994*4882a593Smuzhiyun ROOTFS_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/rootfs 5995*4882a593Smuzhiyun BOOTIMG_DIR: /home/stephano/yocto/build/tmp-glibc/work/qemux86-oe-linux/core-image-minimal/1.0-r0/recipe-sysroot/usr/share 5996*4882a593Smuzhiyun KERNEL_DIR: /home/stephano/yocto/build/tmp-glibc/deploy/images/qemux86 5997*4882a593Smuzhiyun NATIVE_SYSROOT: /home/stephano/yocto/build/tmp-glibc/work/i586-oe-linux/wic-tools/1.0-r0/recipe-sysroot-native 5998*4882a593Smuzhiyun 5999*4882a593Smuzhiyun INFO: The image(s) were created using OE kickstart file: 6000*4882a593Smuzhiyun test.wks 6001*4882a593Smuzhiyun 6002*4882a593SmuzhiyunFor this example, 6003*4882a593Smuzhiyun:term:`MACHINE` did not have to be 6004*4882a593Smuzhiyunspecified in the ``local.conf`` file since the artifact is manually 6005*4882a593Smuzhiyunspecified. 6006*4882a593Smuzhiyun 6007*4882a593SmuzhiyunUsing Wic to Manipulate an Image 6008*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6009*4882a593Smuzhiyun 6010*4882a593SmuzhiyunWic image manipulation allows you to shorten turnaround time during 6011*4882a593Smuzhiyunimage development. For example, you can use Wic to delete the kernel 6012*4882a593Smuzhiyunpartition of a Wic image and then insert a newly built kernel. This 6013*4882a593Smuzhiyunsaves you time from having to rebuild the entire image each time you 6014*4882a593Smuzhiyunmodify the kernel. 6015*4882a593Smuzhiyun 6016*4882a593Smuzhiyun.. note:: 6017*4882a593Smuzhiyun 6018*4882a593Smuzhiyun In order to use Wic to manipulate a Wic image as in this example, 6019*4882a593Smuzhiyun your development machine must have the ``mtools`` package installed. 6020*4882a593Smuzhiyun 6021*4882a593SmuzhiyunThe following example examines the contents of the Wic image, deletes 6022*4882a593Smuzhiyunthe existing kernel, and then inserts a new kernel: 6023*4882a593Smuzhiyun 6024*4882a593Smuzhiyun1. *List the Partitions:* Use the ``wic ls`` command to list all the 6025*4882a593Smuzhiyun partitions in the Wic image:: 6026*4882a593Smuzhiyun 6027*4882a593Smuzhiyun $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic 6028*4882a593Smuzhiyun Num Start End Size Fstype 6029*4882a593Smuzhiyun 1 1048576 25041919 23993344 fat16 6030*4882a593Smuzhiyun 2 25165824 72157183 46991360 ext4 6031*4882a593Smuzhiyun 6032*4882a593Smuzhiyun The previous output shows two partitions in the 6033*4882a593Smuzhiyun ``core-image-minimal-qemux86.wic`` image. 6034*4882a593Smuzhiyun 6035*4882a593Smuzhiyun2. *Examine a Particular Partition:* Use the ``wic ls`` command again 6036*4882a593Smuzhiyun but in a different form to examine a particular partition. 6037*4882a593Smuzhiyun 6038*4882a593Smuzhiyun .. note:: 6039*4882a593Smuzhiyun 6040*4882a593Smuzhiyun You can get command usage on any Wic command using the following 6041*4882a593Smuzhiyun form:: 6042*4882a593Smuzhiyun 6043*4882a593Smuzhiyun $ wic help command 6044*4882a593Smuzhiyun 6045*4882a593Smuzhiyun 6046*4882a593Smuzhiyun For example, the following command shows you the various ways to 6047*4882a593Smuzhiyun use the 6048*4882a593Smuzhiyun wic ls 6049*4882a593Smuzhiyun command:: 6050*4882a593Smuzhiyun 6051*4882a593Smuzhiyun $ wic help ls 6052*4882a593Smuzhiyun 6053*4882a593Smuzhiyun 6054*4882a593Smuzhiyun The following command shows what is in partition one:: 6055*4882a593Smuzhiyun 6056*4882a593Smuzhiyun $ wic ls tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1 6057*4882a593Smuzhiyun Volume in drive : is boot 6058*4882a593Smuzhiyun Volume Serial Number is E894-1809 6059*4882a593Smuzhiyun Directory for ::/ 6060*4882a593Smuzhiyun 6061*4882a593Smuzhiyun libcom32 c32 186500 2017-10-09 16:06 6062*4882a593Smuzhiyun libutil c32 24148 2017-10-09 16:06 6063*4882a593Smuzhiyun syslinux cfg 220 2017-10-09 16:06 6064*4882a593Smuzhiyun vesamenu c32 27104 2017-10-09 16:06 6065*4882a593Smuzhiyun vmlinuz 6904608 2017-10-09 16:06 6066*4882a593Smuzhiyun 5 files 7 142 580 bytes 6067*4882a593Smuzhiyun 16 582 656 bytes free 6068*4882a593Smuzhiyun 6069*4882a593Smuzhiyun The previous output shows five files, with the 6070*4882a593Smuzhiyun ``vmlinuz`` being the kernel. 6071*4882a593Smuzhiyun 6072*4882a593Smuzhiyun .. note:: 6073*4882a593Smuzhiyun 6074*4882a593Smuzhiyun If you see the following error, you need to update or create a 6075*4882a593Smuzhiyun ``~/.mtoolsrc`` file and be sure to have the line "mtools_skip_check=1" 6076*4882a593Smuzhiyun in the file. Then, run the Wic command again:: 6077*4882a593Smuzhiyun 6078*4882a593Smuzhiyun ERROR: _exec_cmd: /usr/bin/mdir -i /tmp/wic-parttfokuwra ::/ returned '1' instead of 0 6079*4882a593Smuzhiyun output: Total number of sectors (47824) not a multiple of sectors per track (32)! 6080*4882a593Smuzhiyun Add mtools_skip_check=1 to your .mtoolsrc file to skip this test 6081*4882a593Smuzhiyun 6082*4882a593Smuzhiyun 6083*4882a593Smuzhiyun3. *Remove the Old Kernel:* Use the ``wic rm`` command to remove the 6084*4882a593Smuzhiyun ``vmlinuz`` file (kernel):: 6085*4882a593Smuzhiyun 6086*4882a593Smuzhiyun $ wic rm tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz 6087*4882a593Smuzhiyun 6088*4882a593Smuzhiyun4. *Add In the New Kernel:* Use the ``wic cp`` command to add the 6089*4882a593Smuzhiyun updated kernel to the Wic image. Depending on how you built your 6090*4882a593Smuzhiyun kernel, it could be in different places. If you used ``devtool`` and 6091*4882a593Smuzhiyun an SDK to build your kernel, it resides in the ``tmp/work`` directory 6092*4882a593Smuzhiyun of the extensible SDK. If you used ``make`` to build the kernel, the 6093*4882a593Smuzhiyun kernel will be in the ``workspace/sources`` area. 6094*4882a593Smuzhiyun 6095*4882a593Smuzhiyun The following example assumes ``devtool`` was used to build the 6096*4882a593Smuzhiyun kernel:: 6097*4882a593Smuzhiyun 6098*4882a593Smuzhiyun $ wic cp poky_sdk/tmp/work/qemux86-poky-linux/linux-yocto/4.12.12+git999-r0/linux-yocto-4.12.12+git999/arch/x86/boot/bzImage \ 6099*4882a593Smuzhiyun poky/build/tmp/deploy/images/qemux86/core-image-minimal-qemux86.wic:1/vmlinuz 6100*4882a593Smuzhiyun 6101*4882a593Smuzhiyun Once the new kernel is added back into the image, you can use the 6102*4882a593Smuzhiyun ``dd`` command or :ref:`bmaptool 6103*4882a593Smuzhiyun <dev-manual/common-tasks:flashing images using \`\`bmaptool\`\`>` 6104*4882a593Smuzhiyun to flash your wic image onto an SD card or USB stick and test your 6105*4882a593Smuzhiyun target. 6106*4882a593Smuzhiyun 6107*4882a593Smuzhiyun .. note:: 6108*4882a593Smuzhiyun 6109*4882a593Smuzhiyun Using ``bmaptool`` is generally 10 to 20 times faster than using ``dd``. 6110*4882a593Smuzhiyun 6111*4882a593SmuzhiyunFlashing Images Using ``bmaptool`` 6112*4882a593Smuzhiyun================================== 6113*4882a593Smuzhiyun 6114*4882a593SmuzhiyunA fast and easy way to flash an image to a bootable device is to use 6115*4882a593SmuzhiyunBmaptool, which is integrated into the OpenEmbedded build system. 6116*4882a593SmuzhiyunBmaptool is a generic tool that creates a file's block map (bmap) and 6117*4882a593Smuzhiyunthen uses that map to copy the file. As compared to traditional tools 6118*4882a593Smuzhiyunsuch as dd or cp, Bmaptool can copy (or flash) large files like raw 6119*4882a593Smuzhiyunsystem image files much faster. 6120*4882a593Smuzhiyun 6121*4882a593Smuzhiyun.. note:: 6122*4882a593Smuzhiyun 6123*4882a593Smuzhiyun - If you are using Ubuntu or Debian distributions, you can install 6124*4882a593Smuzhiyun the ``bmap-tools`` package using the following command and then 6125*4882a593Smuzhiyun use the tool without specifying ``PATH`` even from the root 6126*4882a593Smuzhiyun account:: 6127*4882a593Smuzhiyun 6128*4882a593Smuzhiyun $ sudo apt install bmap-tools 6129*4882a593Smuzhiyun 6130*4882a593Smuzhiyun - If you are unable to install the ``bmap-tools`` package, you will 6131*4882a593Smuzhiyun need to build Bmaptool before using it. Use the following command:: 6132*4882a593Smuzhiyun 6133*4882a593Smuzhiyun $ bitbake bmap-tools-native 6134*4882a593Smuzhiyun 6135*4882a593SmuzhiyunFollowing, is an example that shows how to flash a Wic image. Realize 6136*4882a593Smuzhiyunthat while this example uses a Wic image, you can use Bmaptool to flash 6137*4882a593Smuzhiyunany type of image. Use these steps to flash an image using Bmaptool: 6138*4882a593Smuzhiyun 6139*4882a593Smuzhiyun1. *Update your local.conf File:* You need to have the following set 6140*4882a593Smuzhiyun in your ``local.conf`` file before building your image:: 6141*4882a593Smuzhiyun 6142*4882a593Smuzhiyun IMAGE_FSTYPES += "wic wic.bmap" 6143*4882a593Smuzhiyun 6144*4882a593Smuzhiyun2. *Get Your Image:* Either have your image ready (pre-built with the 6145*4882a593Smuzhiyun :term:`IMAGE_FSTYPES` 6146*4882a593Smuzhiyun setting previously mentioned) or take the step to build the image:: 6147*4882a593Smuzhiyun 6148*4882a593Smuzhiyun $ bitbake image 6149*4882a593Smuzhiyun 6150*4882a593Smuzhiyun3. *Flash the Device:* Flash the device with the image by using Bmaptool 6151*4882a593Smuzhiyun depending on your particular setup. The following commands assume the 6152*4882a593Smuzhiyun image resides in the Build Directory's ``deploy/images/`` area: 6153*4882a593Smuzhiyun 6154*4882a593Smuzhiyun - If you have write access to the media, use this command form:: 6155*4882a593Smuzhiyun 6156*4882a593Smuzhiyun $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX 6157*4882a593Smuzhiyun 6158*4882a593Smuzhiyun - If you do not have write access to the media, set your permissions 6159*4882a593Smuzhiyun first and then use the same command form:: 6160*4882a593Smuzhiyun 6161*4882a593Smuzhiyun $ sudo chmod 666 /dev/sdX 6162*4882a593Smuzhiyun $ oe-run-native bmap-tools-native bmaptool copy build-directory/tmp/deploy/images/machine/image.wic /dev/sdX 6163*4882a593Smuzhiyun 6164*4882a593SmuzhiyunFor help on the ``bmaptool`` command, use the following command:: 6165*4882a593Smuzhiyun 6166*4882a593Smuzhiyun $ bmaptool --help 6167*4882a593Smuzhiyun 6168*4882a593SmuzhiyunMaking Images More Secure 6169*4882a593Smuzhiyun========================= 6170*4882a593Smuzhiyun 6171*4882a593SmuzhiyunSecurity is of increasing concern for embedded devices. Consider the 6172*4882a593Smuzhiyunissues and problems discussed in just this sampling of work found across 6173*4882a593Smuzhiyunthe Internet: 6174*4882a593Smuzhiyun 6175*4882a593Smuzhiyun- *"*\ `Security Risks of Embedded 6176*4882a593Smuzhiyun Systems <https://www.schneier.com/blog/archives/2014/01/security_risks_9.html>`__\ *"* 6177*4882a593Smuzhiyun by Bruce Schneier 6178*4882a593Smuzhiyun 6179*4882a593Smuzhiyun- *"*\ `Internet Census 6180*4882a593Smuzhiyun 2012 <http://census2012.sourceforge.net/paper.html>`__\ *"* by Carna 6181*4882a593Smuzhiyun Botnet 6182*4882a593Smuzhiyun 6183*4882a593Smuzhiyun- *"*\ `Security Issues for Embedded 6184*4882a593Smuzhiyun Devices <https://elinux.org/images/6/6f/Security-issues.pdf>`__\ *"* 6185*4882a593Smuzhiyun by Jake Edge 6186*4882a593Smuzhiyun 6187*4882a593SmuzhiyunWhen securing your image is of concern, there are steps, tools, and 6188*4882a593Smuzhiyunvariables that you can consider to help you reach the security goals you 6189*4882a593Smuzhiyunneed for your particular device. Not all situations are identical when 6190*4882a593Smuzhiyunit comes to making an image secure. Consequently, this section provides 6191*4882a593Smuzhiyunsome guidance and suggestions for consideration when you want to make 6192*4882a593Smuzhiyunyour image more secure. 6193*4882a593Smuzhiyun 6194*4882a593Smuzhiyun.. note:: 6195*4882a593Smuzhiyun 6196*4882a593Smuzhiyun Because the security requirements and risks are different for every 6197*4882a593Smuzhiyun type of device, this section cannot provide a complete reference on 6198*4882a593Smuzhiyun securing your custom OS. It is strongly recommended that you also 6199*4882a593Smuzhiyun consult other sources of information on embedded Linux system 6200*4882a593Smuzhiyun hardening and on security. 6201*4882a593Smuzhiyun 6202*4882a593SmuzhiyunGeneral Considerations 6203*4882a593Smuzhiyun---------------------- 6204*4882a593Smuzhiyun 6205*4882a593SmuzhiyunThere are general considerations that help you create more secure images. 6206*4882a593SmuzhiyunYou should consider the following suggestions to make your device 6207*4882a593Smuzhiyunmore secure: 6208*4882a593Smuzhiyun 6209*4882a593Smuzhiyun- Scan additional code you are adding to the system (e.g. application 6210*4882a593Smuzhiyun code) by using static analysis tools. Look for buffer overflows and 6211*4882a593Smuzhiyun other potential security problems. 6212*4882a593Smuzhiyun 6213*4882a593Smuzhiyun- Pay particular attention to the security for any web-based 6214*4882a593Smuzhiyun administration interface. 6215*4882a593Smuzhiyun 6216*4882a593Smuzhiyun Web interfaces typically need to perform administrative functions and 6217*4882a593Smuzhiyun tend to need to run with elevated privileges. Thus, the consequences 6218*4882a593Smuzhiyun resulting from the interface's security becoming compromised can be 6219*4882a593Smuzhiyun serious. Look for common web vulnerabilities such as 6220*4882a593Smuzhiyun cross-site-scripting (XSS), unvalidated inputs, and so forth. 6221*4882a593Smuzhiyun 6222*4882a593Smuzhiyun As with system passwords, the default credentials for accessing a 6223*4882a593Smuzhiyun web-based interface should not be the same across all devices. This 6224*4882a593Smuzhiyun is particularly true if the interface is enabled by default as it can 6225*4882a593Smuzhiyun be assumed that many end-users will not change the credentials. 6226*4882a593Smuzhiyun 6227*4882a593Smuzhiyun- Ensure you can update the software on the device to mitigate 6228*4882a593Smuzhiyun vulnerabilities discovered in the future. This consideration 6229*4882a593Smuzhiyun especially applies when your device is network-enabled. 6230*4882a593Smuzhiyun 6231*4882a593Smuzhiyun- Ensure you remove or disable debugging functionality before producing 6232*4882a593Smuzhiyun the final image. For information on how to do this, see the 6233*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:considerations specific to the openembedded build system`" 6234*4882a593Smuzhiyun section. 6235*4882a593Smuzhiyun 6236*4882a593Smuzhiyun- Ensure you have no network services listening that are not needed. 6237*4882a593Smuzhiyun 6238*4882a593Smuzhiyun- Remove any software from the image that is not needed. 6239*4882a593Smuzhiyun 6240*4882a593Smuzhiyun- Enable hardware support for secure boot functionality when your 6241*4882a593Smuzhiyun device supports this functionality. 6242*4882a593Smuzhiyun 6243*4882a593SmuzhiyunSecurity Flags 6244*4882a593Smuzhiyun-------------- 6245*4882a593Smuzhiyun 6246*4882a593SmuzhiyunThe Yocto Project has security flags that you can enable that help make 6247*4882a593Smuzhiyunyour build output more secure. The security flags are in the 6248*4882a593Smuzhiyun``meta/conf/distro/include/security_flags.inc`` file in your 6249*4882a593Smuzhiyun:term:`Source Directory` (e.g. ``poky``). 6250*4882a593Smuzhiyun 6251*4882a593Smuzhiyun.. note:: 6252*4882a593Smuzhiyun 6253*4882a593Smuzhiyun Depending on the recipe, certain security flags are enabled and 6254*4882a593Smuzhiyun disabled by default. 6255*4882a593Smuzhiyun 6256*4882a593SmuzhiyunUse the following line in your ``local.conf`` file or in your custom 6257*4882a593Smuzhiyundistribution configuration file to enable the security compiler and 6258*4882a593Smuzhiyunlinker flags for your build:: 6259*4882a593Smuzhiyun 6260*4882a593Smuzhiyun require conf/distro/include/security_flags.inc 6261*4882a593Smuzhiyun 6262*4882a593SmuzhiyunConsiderations Specific to the OpenEmbedded Build System 6263*4882a593Smuzhiyun-------------------------------------------------------- 6264*4882a593Smuzhiyun 6265*4882a593SmuzhiyunYou can take some steps that are specific to the OpenEmbedded build 6266*4882a593Smuzhiyunsystem to make your images more secure: 6267*4882a593Smuzhiyun 6268*4882a593Smuzhiyun- Ensure "debug-tweaks" is not one of your selected 6269*4882a593Smuzhiyun :term:`IMAGE_FEATURES`. 6270*4882a593Smuzhiyun When creating a new project, the default is to provide you with an 6271*4882a593Smuzhiyun initial ``local.conf`` file that enables this feature using the 6272*4882a593Smuzhiyun :term:`EXTRA_IMAGE_FEATURES` 6273*4882a593Smuzhiyun variable with the line:: 6274*4882a593Smuzhiyun 6275*4882a593Smuzhiyun EXTRA_IMAGE_FEATURES = "debug-tweaks" 6276*4882a593Smuzhiyun 6277*4882a593Smuzhiyun To disable that feature, simply comment out that line in your 6278*4882a593Smuzhiyun ``local.conf`` file, or make sure :term:`IMAGE_FEATURES` does not contain 6279*4882a593Smuzhiyun "debug-tweaks" before producing your final image. Among other things, 6280*4882a593Smuzhiyun leaving this in place sets the root password as blank, which makes 6281*4882a593Smuzhiyun logging in for debugging or inspection easy during development but 6282*4882a593Smuzhiyun also means anyone can easily log in during production. 6283*4882a593Smuzhiyun 6284*4882a593Smuzhiyun- It is possible to set a root password for the image and also to set 6285*4882a593Smuzhiyun passwords for any extra users you might add (e.g. administrative or 6286*4882a593Smuzhiyun service type users). When you set up passwords for multiple images or 6287*4882a593Smuzhiyun users, you should not duplicate passwords. 6288*4882a593Smuzhiyun 6289*4882a593Smuzhiyun To set up passwords, use the 6290*4882a593Smuzhiyun :ref:`extrausers <ref-classes-extrausers>` 6291*4882a593Smuzhiyun class, which is the preferred method. For an example on how to set up 6292*4882a593Smuzhiyun both root and user passwords, see the 6293*4882a593Smuzhiyun ":ref:`ref-classes-extrausers`" section. 6294*4882a593Smuzhiyun 6295*4882a593Smuzhiyun .. note:: 6296*4882a593Smuzhiyun 6297*4882a593Smuzhiyun When adding extra user accounts or setting a root password, be 6298*4882a593Smuzhiyun cautious about setting the same password on every device. If you 6299*4882a593Smuzhiyun do this, and the password you have set is exposed, then every 6300*4882a593Smuzhiyun device is now potentially compromised. If you need this access but 6301*4882a593Smuzhiyun want to ensure security, consider setting a different, random 6302*4882a593Smuzhiyun password for each device. Typically, you do this as a separate 6303*4882a593Smuzhiyun step after you deploy the image onto the device. 6304*4882a593Smuzhiyun 6305*4882a593Smuzhiyun- Consider enabling a Mandatory Access Control (MAC) framework such as 6306*4882a593Smuzhiyun SMACK or SELinux and tuning it appropriately for your device's usage. 6307*4882a593Smuzhiyun You can find more information in the 6308*4882a593Smuzhiyun :yocto_git:`meta-selinux </meta-selinux/>` layer. 6309*4882a593Smuzhiyun 6310*4882a593SmuzhiyunTools for Hardening Your Image 6311*4882a593Smuzhiyun------------------------------ 6312*4882a593Smuzhiyun 6313*4882a593SmuzhiyunThe Yocto Project provides tools for making your image more secure. You 6314*4882a593Smuzhiyuncan find these tools in the ``meta-security`` layer of the 6315*4882a593Smuzhiyun:yocto_git:`Yocto Project Source Repositories <>`. 6316*4882a593Smuzhiyun 6317*4882a593SmuzhiyunCreating Your Own Distribution 6318*4882a593Smuzhiyun============================== 6319*4882a593Smuzhiyun 6320*4882a593SmuzhiyunWhen you build an image using the Yocto Project and do not alter any 6321*4882a593Smuzhiyundistribution :term:`Metadata`, you are 6322*4882a593Smuzhiyuncreating a Poky distribution. If you wish to gain more control over 6323*4882a593Smuzhiyunpackage alternative selections, compile-time options, and other 6324*4882a593Smuzhiyunlow-level configurations, you can create your own distribution. 6325*4882a593Smuzhiyun 6326*4882a593SmuzhiyunTo create your own distribution, the basic steps consist of creating 6327*4882a593Smuzhiyunyour own distribution layer, creating your own distribution 6328*4882a593Smuzhiyunconfiguration file, and then adding any needed code and Metadata to the 6329*4882a593Smuzhiyunlayer. The following steps provide some more detail: 6330*4882a593Smuzhiyun 6331*4882a593Smuzhiyun- *Create a layer for your new distro:* Create your distribution layer 6332*4882a593Smuzhiyun so that you can keep your Metadata and code for the distribution 6333*4882a593Smuzhiyun separate. It is strongly recommended that you create and use your own 6334*4882a593Smuzhiyun layer for configuration and code. Using your own layer as compared to 6335*4882a593Smuzhiyun just placing configurations in a ``local.conf`` configuration file 6336*4882a593Smuzhiyun makes it easier to reproduce the same build configuration when using 6337*4882a593Smuzhiyun multiple build machines. See the 6338*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:creating a general layer using the \`\`bitbake-layers\`\` script`" 6339*4882a593Smuzhiyun section for information on how to quickly set up a layer. 6340*4882a593Smuzhiyun 6341*4882a593Smuzhiyun- *Create the distribution configuration file:* The distribution 6342*4882a593Smuzhiyun configuration file needs to be created in the ``conf/distro`` 6343*4882a593Smuzhiyun directory of your layer. You need to name it using your distribution 6344*4882a593Smuzhiyun name (e.g. ``mydistro.conf``). 6345*4882a593Smuzhiyun 6346*4882a593Smuzhiyun .. note:: 6347*4882a593Smuzhiyun 6348*4882a593Smuzhiyun The :term:`DISTRO` variable in your ``local.conf`` file determines the 6349*4882a593Smuzhiyun name of your distribution. 6350*4882a593Smuzhiyun 6351*4882a593Smuzhiyun You can split out parts of your configuration file into include files 6352*4882a593Smuzhiyun and then "require" them from within your distribution configuration 6353*4882a593Smuzhiyun file. Be sure to place the include files in the 6354*4882a593Smuzhiyun ``conf/distro/include`` directory of your layer. A common example 6355*4882a593Smuzhiyun usage of include files would be to separate out the selection of 6356*4882a593Smuzhiyun desired version and revisions for individual recipes. 6357*4882a593Smuzhiyun 6358*4882a593Smuzhiyun Your configuration file needs to set the following required 6359*4882a593Smuzhiyun variables: 6360*4882a593Smuzhiyun 6361*4882a593Smuzhiyun - :term:`DISTRO_NAME` 6362*4882a593Smuzhiyun 6363*4882a593Smuzhiyun - :term:`DISTRO_VERSION` 6364*4882a593Smuzhiyun 6365*4882a593Smuzhiyun These following variables are optional and you typically set them 6366*4882a593Smuzhiyun from the distribution configuration file: 6367*4882a593Smuzhiyun 6368*4882a593Smuzhiyun - :term:`DISTRO_FEATURES` 6369*4882a593Smuzhiyun 6370*4882a593Smuzhiyun - :term:`DISTRO_EXTRA_RDEPENDS` 6371*4882a593Smuzhiyun 6372*4882a593Smuzhiyun - :term:`DISTRO_EXTRA_RRECOMMENDS` 6373*4882a593Smuzhiyun 6374*4882a593Smuzhiyun - :term:`TCLIBC` 6375*4882a593Smuzhiyun 6376*4882a593Smuzhiyun .. tip:: 6377*4882a593Smuzhiyun 6378*4882a593Smuzhiyun If you want to base your distribution configuration file on the 6379*4882a593Smuzhiyun very basic configuration from OE-Core, you can use 6380*4882a593Smuzhiyun ``conf/distro/defaultsetup.conf`` as a reference and just include 6381*4882a593Smuzhiyun variables that differ as compared to ``defaultsetup.conf``. 6382*4882a593Smuzhiyun Alternatively, you can create a distribution configuration file 6383*4882a593Smuzhiyun from scratch using the ``defaultsetup.conf`` file or configuration files 6384*4882a593Smuzhiyun from another distribution such as Poky as a reference. 6385*4882a593Smuzhiyun 6386*4882a593Smuzhiyun- *Provide miscellaneous variables:* Be sure to define any other 6387*4882a593Smuzhiyun variables for which you want to create a default or enforce as part 6388*4882a593Smuzhiyun of the distribution configuration. You can include nearly any 6389*4882a593Smuzhiyun variable from the ``local.conf`` file. The variables you use are not 6390*4882a593Smuzhiyun limited to the list in the previous bulleted item. 6391*4882a593Smuzhiyun 6392*4882a593Smuzhiyun- *Point to Your distribution configuration file:* In your 6393*4882a593Smuzhiyun ``local.conf`` file in the :term:`Build Directory`, 6394*4882a593Smuzhiyun set your 6395*4882a593Smuzhiyun :term:`DISTRO` variable to point to 6396*4882a593Smuzhiyun your distribution's configuration file. For example, if your 6397*4882a593Smuzhiyun distribution's configuration file is named ``mydistro.conf``, then 6398*4882a593Smuzhiyun you point to it as follows:: 6399*4882a593Smuzhiyun 6400*4882a593Smuzhiyun DISTRO = "mydistro" 6401*4882a593Smuzhiyun 6402*4882a593Smuzhiyun- *Add more to the layer if necessary:* Use your layer to hold other 6403*4882a593Smuzhiyun information needed for the distribution: 6404*4882a593Smuzhiyun 6405*4882a593Smuzhiyun - Add recipes for installing distro-specific configuration files 6406*4882a593Smuzhiyun that are not already installed by another recipe. If you have 6407*4882a593Smuzhiyun distro-specific configuration files that are included by an 6408*4882a593Smuzhiyun existing recipe, you should add an append file (``.bbappend``) for 6409*4882a593Smuzhiyun those. For general information and recommendations on how to add 6410*4882a593Smuzhiyun recipes to your layer, see the 6411*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:creating your own layer`" and 6412*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:following best practices when creating layers`" 6413*4882a593Smuzhiyun sections. 6414*4882a593Smuzhiyun 6415*4882a593Smuzhiyun - Add any image recipes that are specific to your distribution. 6416*4882a593Smuzhiyun 6417*4882a593Smuzhiyun - Add a ``psplash`` append file for a branded splash screen. For 6418*4882a593Smuzhiyun information on append files, see the 6419*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:appending other layers metadata with your layer`" 6420*4882a593Smuzhiyun section. 6421*4882a593Smuzhiyun 6422*4882a593Smuzhiyun - Add any other append files to make custom changes that are 6423*4882a593Smuzhiyun specific to individual recipes. 6424*4882a593Smuzhiyun 6425*4882a593SmuzhiyunCreating a Custom Template Configuration Directory 6426*4882a593Smuzhiyun================================================== 6427*4882a593Smuzhiyun 6428*4882a593SmuzhiyunIf you are producing your own customized version of the build system for 6429*4882a593Smuzhiyunuse by other users, you might want to customize the message shown by the 6430*4882a593Smuzhiyunsetup script or you might want to change the template configuration 6431*4882a593Smuzhiyunfiles (i.e. ``local.conf`` and ``bblayers.conf``) that are created in a 6432*4882a593Smuzhiyunnew build directory. 6433*4882a593Smuzhiyun 6434*4882a593SmuzhiyunThe OpenEmbedded build system uses the environment variable 6435*4882a593Smuzhiyun``TEMPLATECONF`` to locate the directory from which it gathers 6436*4882a593Smuzhiyunconfiguration information that ultimately ends up in the 6437*4882a593Smuzhiyun:term:`Build Directory` ``conf`` directory. 6438*4882a593SmuzhiyunBy default, ``TEMPLATECONF`` is set as follows in the ``poky`` 6439*4882a593Smuzhiyunrepository:: 6440*4882a593Smuzhiyun 6441*4882a593Smuzhiyun TEMPLATECONF=${TEMPLATECONF:-meta-poky/conf} 6442*4882a593Smuzhiyun 6443*4882a593SmuzhiyunThis is the 6444*4882a593Smuzhiyundirectory used by the build system to find templates from which to build 6445*4882a593Smuzhiyunsome key configuration files. If you look at this directory, you will 6446*4882a593Smuzhiyunsee the ``bblayers.conf.sample``, ``local.conf.sample``, and 6447*4882a593Smuzhiyun``conf-notes.txt`` files. The build system uses these files to form the 6448*4882a593Smuzhiyunrespective ``bblayers.conf`` file, ``local.conf`` file, and display the 6449*4882a593Smuzhiyunlist of BitBake targets when running the setup script. 6450*4882a593Smuzhiyun 6451*4882a593SmuzhiyunTo override these default configuration files with configurations you 6452*4882a593Smuzhiyunwant used within every new Build Directory, simply set the 6453*4882a593Smuzhiyun``TEMPLATECONF`` variable to your directory. The ``TEMPLATECONF`` 6454*4882a593Smuzhiyunvariable is set in the ``.templateconf`` file, which is in the top-level 6455*4882a593Smuzhiyun:term:`Source Directory` folder 6456*4882a593Smuzhiyun(e.g. ``poky``). Edit the ``.templateconf`` so that it can locate your 6457*4882a593Smuzhiyundirectory. 6458*4882a593Smuzhiyun 6459*4882a593SmuzhiyunBest practices dictate that you should keep your template configuration 6460*4882a593Smuzhiyundirectory in your custom distribution layer. For example, suppose you 6461*4882a593Smuzhiyunhave a layer named ``meta-mylayer`` located in your home directory and 6462*4882a593Smuzhiyunyou want your template configuration directory named ``myconf``. 6463*4882a593SmuzhiyunChanging the ``.templateconf`` as follows causes the OpenEmbedded build 6464*4882a593Smuzhiyunsystem to look in your directory and base its configuration files on the 6465*4882a593Smuzhiyun``*.sample`` configuration files it finds. The final configuration files 6466*4882a593Smuzhiyun(i.e. ``local.conf`` and ``bblayers.conf`` ultimately still end up in 6467*4882a593Smuzhiyunyour Build Directory, but they are based on your ``*.sample`` files. 6468*4882a593Smuzhiyun:: 6469*4882a593Smuzhiyun 6470*4882a593Smuzhiyun TEMPLATECONF=${TEMPLATECONF:-meta-mylayer/myconf} 6471*4882a593Smuzhiyun 6472*4882a593SmuzhiyunAside from the ``*.sample`` configuration files, the ``conf-notes.txt`` 6473*4882a593Smuzhiyunalso resides in the default ``meta-poky/conf`` directory. The script 6474*4882a593Smuzhiyunthat sets up the build environment (i.e. 6475*4882a593Smuzhiyun:ref:`structure-core-script`) uses this file to 6476*4882a593Smuzhiyundisplay BitBake targets as part of the script output. Customizing this 6477*4882a593Smuzhiyun``conf-notes.txt`` file is a good way to make sure your list of custom 6478*4882a593Smuzhiyuntargets appears as part of the script's output. 6479*4882a593Smuzhiyun 6480*4882a593SmuzhiyunHere is the default list of targets displayed as a result of running 6481*4882a593Smuzhiyuneither of the setup scripts:: 6482*4882a593Smuzhiyun 6483*4882a593Smuzhiyun You can now run 'bitbake <target>' 6484*4882a593Smuzhiyun 6485*4882a593Smuzhiyun Common targets are: 6486*4882a593Smuzhiyun core-image-minimal 6487*4882a593Smuzhiyun core-image-sato 6488*4882a593Smuzhiyun meta-toolchain 6489*4882a593Smuzhiyun meta-ide-support 6490*4882a593Smuzhiyun 6491*4882a593SmuzhiyunChanging the listed common targets is as easy as editing your version of 6492*4882a593Smuzhiyun``conf-notes.txt`` in your custom template configuration directory and 6493*4882a593Smuzhiyunmaking sure you have ``TEMPLATECONF`` set to your directory. 6494*4882a593Smuzhiyun 6495*4882a593SmuzhiyunConserving Disk Space 6496*4882a593Smuzhiyun===================== 6497*4882a593Smuzhiyun 6498*4882a593SmuzhiyunConserving Disk Space During Builds 6499*4882a593Smuzhiyun----------------------------------- 6500*4882a593Smuzhiyun 6501*4882a593SmuzhiyunTo help conserve disk space during builds, you can add the following 6502*4882a593Smuzhiyunstatement to your project's ``local.conf`` configuration file found in 6503*4882a593Smuzhiyunthe :term:`Build Directory`:: 6504*4882a593Smuzhiyun 6505*4882a593Smuzhiyun INHERIT += "rm_work" 6506*4882a593Smuzhiyun 6507*4882a593SmuzhiyunAdding this statement deletes the work directory used for 6508*4882a593Smuzhiyunbuilding a recipe once the recipe is built. For more information on 6509*4882a593Smuzhiyun"rm_work", see the 6510*4882a593Smuzhiyun:ref:`rm_work <ref-classes-rm-work>` class in the 6511*4882a593SmuzhiyunYocto Project Reference Manual. 6512*4882a593Smuzhiyun 6513*4882a593SmuzhiyunPurging Duplicate Shared State Cache Files 6514*4882a593Smuzhiyun------------------------------------------- 6515*4882a593Smuzhiyun 6516*4882a593SmuzhiyunAfter multiple build iterations, the Shared State (sstate) cache can contain 6517*4882a593Smuzhiyunduplicate cache files for a given package, while only the most recent one 6518*4882a593Smuzhiyunis likely to be reusable. The following command purges all but the 6519*4882a593Smuzhiyunnewest sstate cache file for each package:: 6520*4882a593Smuzhiyun 6521*4882a593Smuzhiyun sstate-cache-management.sh --remove-duplicated --cache-dir=build/sstate-cache 6522*4882a593Smuzhiyun 6523*4882a593SmuzhiyunThis command will ask you to confirm the deletions it identifies. 6524*4882a593Smuzhiyun 6525*4882a593SmuzhiyunNote:: 6526*4882a593Smuzhiyun 6527*4882a593Smuzhiyun The duplicated sstate cache files of one package must have the same 6528*4882a593Smuzhiyun architecture, which means that sstate cache files with multiple 6529*4882a593Smuzhiyun architectures are not considered as duplicate. 6530*4882a593Smuzhiyun 6531*4882a593SmuzhiyunRun ``sstate-cache-management.sh`` for more details about this script. 6532*4882a593Smuzhiyun 6533*4882a593SmuzhiyunWorking with Packages 6534*4882a593Smuzhiyun===================== 6535*4882a593Smuzhiyun 6536*4882a593SmuzhiyunThis section describes a few tasks that involve packages: 6537*4882a593Smuzhiyun 6538*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:excluding packages from an image` 6539*4882a593Smuzhiyun 6540*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:incrementing a package version` 6541*4882a593Smuzhiyun 6542*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:handling optional module packaging` 6543*4882a593Smuzhiyun 6544*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:using runtime package management` 6545*4882a593Smuzhiyun 6546*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:generating and using signed packages` 6547*4882a593Smuzhiyun 6548*4882a593Smuzhiyun- :ref:`Setting up and running package test 6549*4882a593Smuzhiyun (ptest) <dev-manual/common-tasks:testing packages with ptest>` 6550*4882a593Smuzhiyun 6551*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:creating node package manager (npm) packages` 6552*4882a593Smuzhiyun 6553*4882a593Smuzhiyun- :ref:`dev-manual/common-tasks:adding custom metadata to packages` 6554*4882a593Smuzhiyun 6555*4882a593SmuzhiyunExcluding Packages from an Image 6556*4882a593Smuzhiyun-------------------------------- 6557*4882a593Smuzhiyun 6558*4882a593SmuzhiyunYou might find it necessary to prevent specific packages from being 6559*4882a593Smuzhiyuninstalled into an image. If so, you can use several variables to direct 6560*4882a593Smuzhiyunthe build system to essentially ignore installing recommended packages 6561*4882a593Smuzhiyunor to not install a package at all. 6562*4882a593Smuzhiyun 6563*4882a593SmuzhiyunThe following list introduces variables you can use to prevent packages 6564*4882a593Smuzhiyunfrom being installed into your image. Each of these variables only works 6565*4882a593Smuzhiyunwith IPK and RPM package types, not for Debian packages. 6566*4882a593SmuzhiyunAlso, you can use these variables from your ``local.conf`` file 6567*4882a593Smuzhiyunor attach them to a specific image recipe by using a recipe name 6568*4882a593Smuzhiyunoverride. For more detail on the variables, see the descriptions in the 6569*4882a593SmuzhiyunYocto Project Reference Manual's glossary chapter. 6570*4882a593Smuzhiyun 6571*4882a593Smuzhiyun- :term:`BAD_RECOMMENDATIONS`: 6572*4882a593Smuzhiyun Use this variable to specify "recommended-only" packages that you do 6573*4882a593Smuzhiyun not want installed. 6574*4882a593Smuzhiyun 6575*4882a593Smuzhiyun- :term:`NO_RECOMMENDATIONS`: 6576*4882a593Smuzhiyun Use this variable to prevent all "recommended-only" packages from 6577*4882a593Smuzhiyun being installed. 6578*4882a593Smuzhiyun 6579*4882a593Smuzhiyun- :term:`PACKAGE_EXCLUDE`: 6580*4882a593Smuzhiyun Use this variable to prevent specific packages from being installed 6581*4882a593Smuzhiyun regardless of whether they are "recommended-only" or not. You need to 6582*4882a593Smuzhiyun realize that the build process could fail with an error when you 6583*4882a593Smuzhiyun prevent the installation of a package whose presence is required by 6584*4882a593Smuzhiyun an installed package. 6585*4882a593Smuzhiyun 6586*4882a593SmuzhiyunIncrementing a Package Version 6587*4882a593Smuzhiyun------------------------------ 6588*4882a593Smuzhiyun 6589*4882a593SmuzhiyunThis section provides some background on how binary package versioning 6590*4882a593Smuzhiyunis accomplished and presents some of the services, variables, and 6591*4882a593Smuzhiyunterminology involved. 6592*4882a593Smuzhiyun 6593*4882a593SmuzhiyunIn order to understand binary package versioning, you need to consider 6594*4882a593Smuzhiyunthe following: 6595*4882a593Smuzhiyun 6596*4882a593Smuzhiyun- Binary Package: The binary package that is eventually built and 6597*4882a593Smuzhiyun installed into an image. 6598*4882a593Smuzhiyun 6599*4882a593Smuzhiyun- Binary Package Version: The binary package version is composed of two 6600*4882a593Smuzhiyun components - a version and a revision. 6601*4882a593Smuzhiyun 6602*4882a593Smuzhiyun .. note:: 6603*4882a593Smuzhiyun 6604*4882a593Smuzhiyun Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved 6605*4882a593Smuzhiyun but this discussion for the most part ignores :term:`PE`. 6606*4882a593Smuzhiyun 6607*4882a593Smuzhiyun The version and revision are taken from the 6608*4882a593Smuzhiyun :term:`PV` and 6609*4882a593Smuzhiyun :term:`PR` variables, respectively. 6610*4882a593Smuzhiyun 6611*4882a593Smuzhiyun- :term:`PV`: The recipe version. :term:`PV` represents the version of the 6612*4882a593Smuzhiyun software being packaged. Do not confuse :term:`PV` with the binary 6613*4882a593Smuzhiyun package version. 6614*4882a593Smuzhiyun 6615*4882a593Smuzhiyun- :term:`PR`: The recipe revision. 6616*4882a593Smuzhiyun 6617*4882a593Smuzhiyun- :term:`SRCPV`: The OpenEmbedded 6618*4882a593Smuzhiyun build system uses this string to help define the value of :term:`PV` when 6619*4882a593Smuzhiyun the source code revision needs to be included in it. 6620*4882a593Smuzhiyun 6621*4882a593Smuzhiyun- :yocto_wiki:`PR Service </PR_Service>`: A 6622*4882a593Smuzhiyun network-based service that helps automate keeping package feeds 6623*4882a593Smuzhiyun compatible with existing package manager applications such as RPM, 6624*4882a593Smuzhiyun APT, and OPKG. 6625*4882a593Smuzhiyun 6626*4882a593SmuzhiyunWhenever the binary package content changes, the binary package version 6627*4882a593Smuzhiyunmust change. Changing the binary package version is accomplished by 6628*4882a593Smuzhiyunchanging or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these 6629*4882a593Smuzhiyunvalues occurs one of two ways: 6630*4882a593Smuzhiyun 6631*4882a593Smuzhiyun- Automatically using a Package Revision Service (PR Service). 6632*4882a593Smuzhiyun 6633*4882a593Smuzhiyun- Manually incrementing the :term:`PR` and/or :term:`PV` variables. 6634*4882a593Smuzhiyun 6635*4882a593SmuzhiyunGiven a primary challenge of any build system and its users is how to 6636*4882a593Smuzhiyunmaintain a package feed that is compatible with existing package manager 6637*4882a593Smuzhiyunapplications such as RPM, APT, and OPKG, using an automated system is 6638*4882a593Smuzhiyunmuch preferred over a manual system. In either system, the main 6639*4882a593Smuzhiyunrequirement is that binary package version numbering increases in a 6640*4882a593Smuzhiyunlinear fashion and that there is a number of version components that 6641*4882a593Smuzhiyunsupport that linear progression. For information on how to ensure 6642*4882a593Smuzhiyunpackage revisioning remains linear, see the 6643*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:automatically incrementing a package version number`" 6644*4882a593Smuzhiyunsection. 6645*4882a593Smuzhiyun 6646*4882a593SmuzhiyunThe following three sections provide related information on the PR 6647*4882a593SmuzhiyunService, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on 6648*4882a593Smuzhiyunhow to ensure binary package revisioning remains linear. 6649*4882a593Smuzhiyun 6650*4882a593SmuzhiyunWorking With a PR Service 6651*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~ 6652*4882a593Smuzhiyun 6653*4882a593SmuzhiyunAs mentioned, attempting to maintain revision numbers in the 6654*4882a593Smuzhiyun:term:`Metadata` is error prone, inaccurate, 6655*4882a593Smuzhiyunand causes problems for people submitting recipes. Conversely, the PR 6656*4882a593SmuzhiyunService automatically generates increasing numbers, particularly the 6657*4882a593Smuzhiyunrevision field, which removes the human element. 6658*4882a593Smuzhiyun 6659*4882a593Smuzhiyun.. note:: 6660*4882a593Smuzhiyun 6661*4882a593Smuzhiyun For additional information on using a PR Service, you can see the 6662*4882a593Smuzhiyun :yocto_wiki:`PR Service </PR_Service>` wiki page. 6663*4882a593Smuzhiyun 6664*4882a593SmuzhiyunThe Yocto Project uses variables in order of decreasing priority to 6665*4882a593Smuzhiyunfacilitate revision numbering (i.e. 6666*4882a593Smuzhiyun:term:`PE`, 6667*4882a593Smuzhiyun:term:`PV`, and 6668*4882a593Smuzhiyun:term:`PR` for epoch, version, and 6669*4882a593Smuzhiyunrevision, respectively). The values are highly dependent on the policies 6670*4882a593Smuzhiyunand procedures of a given distribution and package feed. 6671*4882a593Smuzhiyun 6672*4882a593SmuzhiyunBecause the OpenEmbedded build system uses 6673*4882a593Smuzhiyun":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are 6674*4882a593Smuzhiyununique to a given build, the build system knows when to rebuild 6675*4882a593Smuzhiyunpackages. All the inputs into a given task are represented by a 6676*4882a593Smuzhiyunsignature, which can trigger a rebuild when different. Thus, the build 6677*4882a593Smuzhiyunsystem itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to 6678*4882a593Smuzhiyuntrigger a rebuild. The signatures, however, can be used to generate 6679*4882a593Smuzhiyunthese values. 6680*4882a593Smuzhiyun 6681*4882a593SmuzhiyunThe PR Service works with both ``OEBasic`` and ``OEBasicHash`` 6682*4882a593Smuzhiyungenerators. The value of :term:`PR` bumps when the checksum changes and the 6683*4882a593Smuzhiyundifferent generator mechanisms change signatures under different 6684*4882a593Smuzhiyuncircumstances. 6685*4882a593Smuzhiyun 6686*4882a593SmuzhiyunAs implemented, the build system includes values from the PR Service 6687*4882a593Smuzhiyuninto the :term:`PR` field as an addition using the form "``.x``" so ``r0`` 6688*4882a593Smuzhiyunbecomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing 6689*4882a593Smuzhiyun:term:`PR` values to be used for whatever reasons, which include manual 6690*4882a593Smuzhiyun:term:`PR` bumps, should it be necessary. 6691*4882a593Smuzhiyun 6692*4882a593SmuzhiyunBy default, the PR Service is not enabled or running. Thus, the packages 6693*4882a593Smuzhiyungenerated are just "self consistent". The build system adds and removes 6694*4882a593Smuzhiyunpackages and there are no guarantees about upgrade paths but images will 6695*4882a593Smuzhiyunbe consistent and correct with the latest changes. 6696*4882a593Smuzhiyun 6697*4882a593SmuzhiyunThe simplest form for a PR Service is for a single host 6698*4882a593Smuzhiyundevelopment system that builds the package feed (building system). For 6699*4882a593Smuzhiyunthis scenario, you can enable a local PR Service by setting 6700*4882a593Smuzhiyun:term:`PRSERV_HOST` in your 6701*4882a593Smuzhiyun``local.conf`` file in the :term:`Build Directory`:: 6702*4882a593Smuzhiyun 6703*4882a593Smuzhiyun PRSERV_HOST = "localhost:0" 6704*4882a593Smuzhiyun 6705*4882a593SmuzhiyunOnce the service is started, packages will automatically 6706*4882a593Smuzhiyunget increasing :term:`PR` values and BitBake takes care of starting and 6707*4882a593Smuzhiyunstopping the server. 6708*4882a593Smuzhiyun 6709*4882a593SmuzhiyunIf you have a more complex setup where multiple host development systems 6710*4882a593Smuzhiyunwork against a common, shared package feed, you have a single PR Service 6711*4882a593Smuzhiyunrunning and it is connected to each building system. For this scenario, 6712*4882a593Smuzhiyunyou need to start the PR Service using the ``bitbake-prserv`` command:: 6713*4882a593Smuzhiyun 6714*4882a593Smuzhiyun bitbake-prserv --host ip --port port --start 6715*4882a593Smuzhiyun 6716*4882a593SmuzhiyunIn addition to 6717*4882a593Smuzhiyunhand-starting the service, you need to update the ``local.conf`` file of 6718*4882a593Smuzhiyuneach building system as described earlier so each system points to the 6719*4882a593Smuzhiyunserver and port. 6720*4882a593Smuzhiyun 6721*4882a593SmuzhiyunIt is also recommended you use build history, which adds some sanity 6722*4882a593Smuzhiyunchecks to binary package versions, in conjunction with the server that 6723*4882a593Smuzhiyunis running the PR Service. To enable build history, add the following to 6724*4882a593Smuzhiyuneach building system's ``local.conf`` file:: 6725*4882a593Smuzhiyun 6726*4882a593Smuzhiyun # It is recommended to activate "buildhistory" for testing the PR service 6727*4882a593Smuzhiyun INHERIT += "buildhistory" 6728*4882a593Smuzhiyun BUILDHISTORY_COMMIT = "1" 6729*4882a593Smuzhiyun 6730*4882a593SmuzhiyunFor information on build 6731*4882a593Smuzhiyunhistory, see the 6732*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:maintaining build output quality`" section. 6733*4882a593Smuzhiyun 6734*4882a593Smuzhiyun.. note:: 6735*4882a593Smuzhiyun 6736*4882a593Smuzhiyun The OpenEmbedded build system does not maintain :term:`PR` information as 6737*4882a593Smuzhiyun part of the shared state (sstate) packages. If you maintain an sstate 6738*4882a593Smuzhiyun feed, it's expected that either all your building systems that 6739*4882a593Smuzhiyun contribute to the sstate feed use a shared PR Service, or you do not 6740*4882a593Smuzhiyun run a PR Service on any of your building systems. Having some systems 6741*4882a593Smuzhiyun use a PR Service while others do not leads to obvious problems. 6742*4882a593Smuzhiyun 6743*4882a593Smuzhiyun For more information on shared state, see the 6744*4882a593Smuzhiyun ":ref:`overview-manual/concepts:shared state cache`" 6745*4882a593Smuzhiyun section in the Yocto Project Overview and Concepts Manual. 6746*4882a593Smuzhiyun 6747*4882a593SmuzhiyunManually Bumping PR 6748*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~ 6749*4882a593Smuzhiyun 6750*4882a593SmuzhiyunThe alternative to setting up a PR Service is to manually "bump" the 6751*4882a593Smuzhiyun:term:`PR` variable. 6752*4882a593Smuzhiyun 6753*4882a593SmuzhiyunIf a committed change results in changing the package output, then the 6754*4882a593Smuzhiyunvalue of the PR variable needs to be increased (or "bumped") as part of 6755*4882a593Smuzhiyunthat commit. For new recipes you should add the :term:`PR` variable and set 6756*4882a593Smuzhiyunits initial value equal to "r0", which is the default. Even though the 6757*4882a593Smuzhiyundefault value is "r0", the practice of adding it to a new recipe makes 6758*4882a593Smuzhiyunit harder to forget to bump the variable when you make changes to the 6759*4882a593Smuzhiyunrecipe in future. 6760*4882a593Smuzhiyun 6761*4882a593SmuzhiyunIf you are sharing a common ``.inc`` file with multiple recipes, you can 6762*4882a593Smuzhiyunalso use the :term:`INC_PR` variable to ensure that the recipes sharing the 6763*4882a593Smuzhiyun``.inc`` file are rebuilt when the ``.inc`` file itself is changed. The 6764*4882a593Smuzhiyun``.inc`` file must set :term:`INC_PR` (initially to "r0"), and all recipes 6765*4882a593Smuzhiyunreferring to it should set :term:`PR` to "${INC_PR}.0" initially, 6766*4882a593Smuzhiyunincrementing the last number when the recipe is changed. If the ``.inc`` 6767*4882a593Smuzhiyunfile is changed then its :term:`INC_PR` should be incremented. 6768*4882a593Smuzhiyun 6769*4882a593SmuzhiyunWhen upgrading the version of a binary package, assuming the :term:`PV` 6770*4882a593Smuzhiyunchanges, the :term:`PR` variable should be reset to "r0" (or "${INC_PR}.0" 6771*4882a593Smuzhiyunif you are using :term:`INC_PR`). 6772*4882a593Smuzhiyun 6773*4882a593SmuzhiyunUsually, version increases occur only to binary packages. However, if 6774*4882a593Smuzhiyunfor some reason :term:`PV` changes but does not increase, you can increase 6775*4882a593Smuzhiyunthe :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to 6776*4882a593Smuzhiyun"0". 6777*4882a593Smuzhiyun 6778*4882a593SmuzhiyunBinary package version numbering strives to follow the `Debian Version 6779*4882a593SmuzhiyunField Policy 6780*4882a593SmuzhiyunGuidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__. 6781*4882a593SmuzhiyunThese guidelines define how versions are compared and what "increasing" 6782*4882a593Smuzhiyuna version means. 6783*4882a593Smuzhiyun 6784*4882a593SmuzhiyunAutomatically Incrementing a Package Version Number 6785*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6786*4882a593Smuzhiyun 6787*4882a593SmuzhiyunWhen fetching a repository, BitBake uses the 6788*4882a593Smuzhiyun:term:`SRCREV` variable to determine 6789*4882a593Smuzhiyunthe specific source code revision from which to build. You set the 6790*4882a593Smuzhiyun:term:`SRCREV` variable to 6791*4882a593Smuzhiyun:term:`AUTOREV` to cause the 6792*4882a593SmuzhiyunOpenEmbedded build system to automatically use the latest revision of 6793*4882a593Smuzhiyunthe software:: 6794*4882a593Smuzhiyun 6795*4882a593Smuzhiyun SRCREV = "${AUTOREV}" 6796*4882a593Smuzhiyun 6797*4882a593SmuzhiyunFurthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to 6798*4882a593Smuzhiyunautomatically update the version whenever the revision of the source 6799*4882a593Smuzhiyuncode changes. Here is an example:: 6800*4882a593Smuzhiyun 6801*4882a593Smuzhiyun PV = "1.0+git${SRCPV}" 6802*4882a593Smuzhiyun 6803*4882a593SmuzhiyunThe OpenEmbedded build system substitutes :term:`SRCPV` with the following: 6804*4882a593Smuzhiyun 6805*4882a593Smuzhiyun.. code-block:: none 6806*4882a593Smuzhiyun 6807*4882a593Smuzhiyun AUTOINC+source_code_revision 6808*4882a593Smuzhiyun 6809*4882a593SmuzhiyunThe build system replaces the ``AUTOINC`` 6810*4882a593Smuzhiyunwith a number. The number used depends on the state of the PR Service: 6811*4882a593Smuzhiyun 6812*4882a593Smuzhiyun- If PR Service is enabled, the build system increments the number, 6813*4882a593Smuzhiyun which is similar to the behavior of 6814*4882a593Smuzhiyun :term:`PR`. This behavior results in 6815*4882a593Smuzhiyun linearly increasing package versions, which is desirable. Here is an 6816*4882a593Smuzhiyun example: 6817*4882a593Smuzhiyun 6818*4882a593Smuzhiyun .. code-block:: none 6819*4882a593Smuzhiyun 6820*4882a593Smuzhiyun hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk 6821*4882a593Smuzhiyun hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk 6822*4882a593Smuzhiyun 6823*4882a593Smuzhiyun- If PR Service is not enabled, the build system replaces the 6824*4882a593Smuzhiyun ``AUTOINC`` placeholder with zero (i.e. "0"). This results in 6825*4882a593Smuzhiyun changing the package version since the source revision is included. 6826*4882a593Smuzhiyun However, package versions are not increased linearly. Here is an 6827*4882a593Smuzhiyun example: 6828*4882a593Smuzhiyun 6829*4882a593Smuzhiyun .. code-block:: none 6830*4882a593Smuzhiyun 6831*4882a593Smuzhiyun hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk 6832*4882a593Smuzhiyun hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk 6833*4882a593Smuzhiyun 6834*4882a593SmuzhiyunIn summary, the OpenEmbedded build system does not track the history of 6835*4882a593Smuzhiyunbinary package versions for this purpose. ``AUTOINC``, in this case, is 6836*4882a593Smuzhiyuncomparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the 6837*4882a593Smuzhiyunpackage version is simply replaced by "0". If PR server is enabled, the 6838*4882a593Smuzhiyunbuild system keeps track of the package versions and bumps the number 6839*4882a593Smuzhiyunwhen the package revision changes. 6840*4882a593Smuzhiyun 6841*4882a593SmuzhiyunHandling Optional Module Packaging 6842*4882a593Smuzhiyun---------------------------------- 6843*4882a593Smuzhiyun 6844*4882a593SmuzhiyunMany pieces of software split functionality into optional modules (or 6845*4882a593Smuzhiyunplugins) and the plugins that are built might depend on configuration 6846*4882a593Smuzhiyunoptions. To avoid having to duplicate the logic that determines what 6847*4882a593Smuzhiyunmodules are available in your recipe or to avoid having to package each 6848*4882a593Smuzhiyunmodule by hand, the OpenEmbedded build system provides functionality to 6849*4882a593Smuzhiyunhandle module packaging dynamically. 6850*4882a593Smuzhiyun 6851*4882a593SmuzhiyunTo handle optional module packaging, you need to do two things: 6852*4882a593Smuzhiyun 6853*4882a593Smuzhiyun- Ensure the module packaging is actually done. 6854*4882a593Smuzhiyun 6855*4882a593Smuzhiyun- Ensure that any dependencies on optional modules from other recipes 6856*4882a593Smuzhiyun are satisfied by your recipe. 6857*4882a593Smuzhiyun 6858*4882a593SmuzhiyunMaking Sure the Packaging is Done 6859*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6860*4882a593Smuzhiyun 6861*4882a593SmuzhiyunTo ensure the module packaging actually gets done, you use the 6862*4882a593Smuzhiyun``do_split_packages`` function within the ``populate_packages`` Python 6863*4882a593Smuzhiyunfunction in your recipe. The ``do_split_packages`` function searches for 6864*4882a593Smuzhiyuna pattern of files or directories under a specified path and creates a 6865*4882a593Smuzhiyunpackage for each one it finds by appending to the 6866*4882a593Smuzhiyun:term:`PACKAGES` variable and 6867*4882a593Smuzhiyunsetting the appropriate values for ``FILES:packagename``, 6868*4882a593Smuzhiyun``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth. 6869*4882a593SmuzhiyunHere is an example from the ``lighttpd`` recipe:: 6870*4882a593Smuzhiyun 6871*4882a593Smuzhiyun python populate_packages:prepend () { 6872*4882a593Smuzhiyun lighttpd_libdir = d.expand('${libdir}') 6873*4882a593Smuzhiyun do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$', 6874*4882a593Smuzhiyun 'lighttpd-module-%s', 'Lighttpd module for %s', 6875*4882a593Smuzhiyun extra_depends='') 6876*4882a593Smuzhiyun } 6877*4882a593Smuzhiyun 6878*4882a593SmuzhiyunThe previous example specifies a number of things in the call to 6879*4882a593Smuzhiyun``do_split_packages``. 6880*4882a593Smuzhiyun 6881*4882a593Smuzhiyun- A directory within the files installed by your recipe through 6882*4882a593Smuzhiyun ``do_install`` in which to search. 6883*4882a593Smuzhiyun 6884*4882a593Smuzhiyun- A regular expression used to match module files in that directory. In 6885*4882a593Smuzhiyun the example, note the parentheses () that mark the part of the 6886*4882a593Smuzhiyun expression from which the module name should be derived. 6887*4882a593Smuzhiyun 6888*4882a593Smuzhiyun- A pattern to use for the package names. 6889*4882a593Smuzhiyun 6890*4882a593Smuzhiyun- A description for each package. 6891*4882a593Smuzhiyun 6892*4882a593Smuzhiyun- An empty string for ``extra_depends``, which disables the default 6893*4882a593Smuzhiyun dependency on the main ``lighttpd`` package. Thus, if a file in 6894*4882a593Smuzhiyun ``${libdir}`` called ``mod_alias.so`` is found, a package called 6895*4882a593Smuzhiyun ``lighttpd-module-alias`` is created for it and the 6896*4882a593Smuzhiyun :term:`DESCRIPTION` is set to 6897*4882a593Smuzhiyun "Lighttpd module for alias". 6898*4882a593Smuzhiyun 6899*4882a593SmuzhiyunOften, packaging modules is as simple as the previous example. However, 6900*4882a593Smuzhiyunthere are more advanced options that you can use within 6901*4882a593Smuzhiyun``do_split_packages`` to modify its behavior. And, if you need to, you 6902*4882a593Smuzhiyuncan add more logic by specifying a hook function that is called for each 6903*4882a593Smuzhiyunpackage. It is also perfectly acceptable to call ``do_split_packages`` 6904*4882a593Smuzhiyunmultiple times if you have more than one set of modules to package. 6905*4882a593Smuzhiyun 6906*4882a593SmuzhiyunFor more examples that show how to use ``do_split_packages``, see the 6907*4882a593Smuzhiyun``connman.inc`` file in the ``meta/recipes-connectivity/connman/`` 6908*4882a593Smuzhiyundirectory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can 6909*4882a593Smuzhiyunalso find examples in ``meta/classes/kernel.bbclass``. 6910*4882a593Smuzhiyun 6911*4882a593SmuzhiyunFollowing is a reference that shows ``do_split_packages`` mandatory and 6912*4882a593Smuzhiyunoptional arguments:: 6913*4882a593Smuzhiyun 6914*4882a593Smuzhiyun Mandatory arguments 6915*4882a593Smuzhiyun 6916*4882a593Smuzhiyun root 6917*4882a593Smuzhiyun The path in which to search 6918*4882a593Smuzhiyun file_regex 6919*4882a593Smuzhiyun Regular expression to match searched files. 6920*4882a593Smuzhiyun Use parentheses () to mark the part of this 6921*4882a593Smuzhiyun expression that should be used to derive the 6922*4882a593Smuzhiyun module name (to be substituted where %s is 6923*4882a593Smuzhiyun used in other function arguments as noted below) 6924*4882a593Smuzhiyun output_pattern 6925*4882a593Smuzhiyun Pattern to use for the package names. Must 6926*4882a593Smuzhiyun include %s. 6927*4882a593Smuzhiyun description 6928*4882a593Smuzhiyun Description to set for each package. Must 6929*4882a593Smuzhiyun include %s. 6930*4882a593Smuzhiyun 6931*4882a593Smuzhiyun Optional arguments 6932*4882a593Smuzhiyun 6933*4882a593Smuzhiyun postinst 6934*4882a593Smuzhiyun Postinstall script to use for all packages 6935*4882a593Smuzhiyun (as a string) 6936*4882a593Smuzhiyun recursive 6937*4882a593Smuzhiyun True to perform a recursive search - default 6938*4882a593Smuzhiyun False 6939*4882a593Smuzhiyun hook 6940*4882a593Smuzhiyun A hook function to be called for every match. 6941*4882a593Smuzhiyun The function will be called with the following 6942*4882a593Smuzhiyun arguments (in the order listed): 6943*4882a593Smuzhiyun 6944*4882a593Smuzhiyun f 6945*4882a593Smuzhiyun Full path to the file/directory match 6946*4882a593Smuzhiyun pkg 6947*4882a593Smuzhiyun The package name 6948*4882a593Smuzhiyun file_regex 6949*4882a593Smuzhiyun As above 6950*4882a593Smuzhiyun output_pattern 6951*4882a593Smuzhiyun As above 6952*4882a593Smuzhiyun modulename 6953*4882a593Smuzhiyun The module name derived using file_regex 6954*4882a593Smuzhiyun extra_depends 6955*4882a593Smuzhiyun Extra runtime dependencies (RDEPENDS) to be 6956*4882a593Smuzhiyun set for all packages. The default value of None 6957*4882a593Smuzhiyun causes a dependency on the main package 6958*4882a593Smuzhiyun (${PN}) - if you do not want this, pass empty 6959*4882a593Smuzhiyun string '' for this parameter. 6960*4882a593Smuzhiyun aux_files_pattern 6961*4882a593Smuzhiyun Extra item(s) to be added to FILES for each 6962*4882a593Smuzhiyun package. Can be a single string item or a list 6963*4882a593Smuzhiyun of strings for multiple items. Must include %s. 6964*4882a593Smuzhiyun postrm 6965*4882a593Smuzhiyun postrm script to use for all packages (as a 6966*4882a593Smuzhiyun string) 6967*4882a593Smuzhiyun allow_dirs 6968*4882a593Smuzhiyun True to allow directories to be matched - 6969*4882a593Smuzhiyun default False 6970*4882a593Smuzhiyun prepend 6971*4882a593Smuzhiyun If True, prepend created packages to PACKAGES 6972*4882a593Smuzhiyun instead of the default False which appends them 6973*4882a593Smuzhiyun match_path 6974*4882a593Smuzhiyun match file_regex on the whole relative path to 6975*4882a593Smuzhiyun the root rather than just the filename 6976*4882a593Smuzhiyun aux_files_pattern_verbatim 6977*4882a593Smuzhiyun Extra item(s) to be added to FILES for each 6978*4882a593Smuzhiyun package, using the actual derived module name 6979*4882a593Smuzhiyun rather than converting it to something legal 6980*4882a593Smuzhiyun for a package name. Can be a single string item 6981*4882a593Smuzhiyun or a list of strings for multiple items. Must 6982*4882a593Smuzhiyun include %s. 6983*4882a593Smuzhiyun allow_links 6984*4882a593Smuzhiyun True to allow symlinks to be matched - default 6985*4882a593Smuzhiyun False 6986*4882a593Smuzhiyun summary 6987*4882a593Smuzhiyun Summary to set for each package. Must include %s; 6988*4882a593Smuzhiyun defaults to description if not set. 6989*4882a593Smuzhiyun 6990*4882a593Smuzhiyun 6991*4882a593Smuzhiyun 6992*4882a593SmuzhiyunSatisfying Dependencies 6993*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~ 6994*4882a593Smuzhiyun 6995*4882a593SmuzhiyunThe second part for handling optional module packaging is to ensure that 6996*4882a593Smuzhiyunany dependencies on optional modules from other recipes are satisfied by 6997*4882a593Smuzhiyunyour recipe. You can be sure these dependencies are satisfied by using 6998*4882a593Smuzhiyunthe :term:`PACKAGES_DYNAMIC` 6999*4882a593Smuzhiyunvariable. Here is an example that continues with the ``lighttpd`` recipe 7000*4882a593Smuzhiyunshown earlier:: 7001*4882a593Smuzhiyun 7002*4882a593Smuzhiyun PACKAGES_DYNAMIC = "lighttpd-module-.*" 7003*4882a593Smuzhiyun 7004*4882a593SmuzhiyunThe name 7005*4882a593Smuzhiyunspecified in the regular expression can of course be anything. In this 7006*4882a593Smuzhiyunexample, it is ``lighttpd-module-`` and is specified as the prefix to 7007*4882a593Smuzhiyunensure that any :term:`RDEPENDS` and 7008*4882a593Smuzhiyun:term:`RRECOMMENDS` on a package 7009*4882a593Smuzhiyunname starting with the prefix are satisfied during build time. If you 7010*4882a593Smuzhiyunare using ``do_split_packages`` as described in the previous section, 7011*4882a593Smuzhiyunthe value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name 7012*4882a593Smuzhiyunpattern specified in the call to ``do_split_packages``. 7013*4882a593Smuzhiyun 7014*4882a593SmuzhiyunUsing Runtime Package Management 7015*4882a593Smuzhiyun-------------------------------- 7016*4882a593Smuzhiyun 7017*4882a593SmuzhiyunDuring a build, BitBake always transforms a recipe into one or more 7018*4882a593Smuzhiyunpackages. For example, BitBake takes the ``bash`` recipe and produces a 7019*4882a593Smuzhiyunnumber of packages (e.g. ``bash``, ``bash-bashbug``, 7020*4882a593Smuzhiyun``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``, 7021*4882a593Smuzhiyun``bash-completion-extra``, ``bash-dbg``, and so forth). Not all 7022*4882a593Smuzhiyungenerated packages are included in an image. 7023*4882a593Smuzhiyun 7024*4882a593SmuzhiyunIn several situations, you might need to update, add, remove, or query 7025*4882a593Smuzhiyunthe packages on a target device at runtime (i.e. without having to 7026*4882a593Smuzhiyungenerate a new image). Examples of such situations include: 7027*4882a593Smuzhiyun 7028*4882a593Smuzhiyun- You want to provide in-the-field updates to deployed devices (e.g. 7029*4882a593Smuzhiyun security updates). 7030*4882a593Smuzhiyun 7031*4882a593Smuzhiyun- You want to have a fast turn-around development cycle for one or more 7032*4882a593Smuzhiyun applications that run on your device. 7033*4882a593Smuzhiyun 7034*4882a593Smuzhiyun- You want to temporarily install the "debug" packages of various 7035*4882a593Smuzhiyun applications on your device so that debugging can be greatly improved 7036*4882a593Smuzhiyun by allowing access to symbols and source debugging. 7037*4882a593Smuzhiyun 7038*4882a593Smuzhiyun- You want to deploy a more minimal package selection of your device 7039*4882a593Smuzhiyun but allow in-the-field updates to add a larger selection for 7040*4882a593Smuzhiyun customization. 7041*4882a593Smuzhiyun 7042*4882a593SmuzhiyunIn all these situations, you have something similar to a more 7043*4882a593Smuzhiyuntraditional Linux distribution in that in-field devices are able to 7044*4882a593Smuzhiyunreceive pre-compiled packages from a server for installation or update. 7045*4882a593SmuzhiyunBeing able to install these packages on a running, in-field device is 7046*4882a593Smuzhiyunwhat is termed "runtime package management". 7047*4882a593Smuzhiyun 7048*4882a593SmuzhiyunIn order to use runtime package management, you need a host or server 7049*4882a593Smuzhiyunmachine that serves up the pre-compiled packages plus the required 7050*4882a593Smuzhiyunmetadata. You also need package manipulation tools on the target. The 7051*4882a593Smuzhiyunbuild machine is a likely candidate to act as the server. However, that 7052*4882a593Smuzhiyunmachine does not necessarily have to be the package server. The build 7053*4882a593Smuzhiyunmachine could push its artifacts to another machine that acts as the 7054*4882a593Smuzhiyunserver (e.g. Internet-facing). In fact, doing so is advantageous for a 7055*4882a593Smuzhiyunproduction environment as getting the packages away from the development 7056*4882a593Smuzhiyunsystem's build directory prevents accidental overwrites. 7057*4882a593Smuzhiyun 7058*4882a593SmuzhiyunA simple build that targets just one device produces more than one 7059*4882a593Smuzhiyunpackage database. In other words, the packages produced by a build are 7060*4882a593Smuzhiyunseparated out into a couple of different package groupings based on 7061*4882a593Smuzhiyuncriteria such as the target's CPU architecture, the target board, or the 7062*4882a593SmuzhiyunC library used on the target. For example, a build targeting the 7063*4882a593Smuzhiyun``qemux86`` device produces the following three package databases: 7064*4882a593Smuzhiyun``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86`` 7065*4882a593Smuzhiyundevice to be aware of all the packages that were available to it, you 7066*4882a593Smuzhiyunwould need to point it to each of these databases individually. In a 7067*4882a593Smuzhiyunsimilar way, a traditional Linux distribution usually is configured to 7068*4882a593Smuzhiyunbe aware of a number of software repositories from which it retrieves 7069*4882a593Smuzhiyunpackages. 7070*4882a593Smuzhiyun 7071*4882a593SmuzhiyunUsing runtime package management is completely optional and not required 7072*4882a593Smuzhiyunfor a successful build or deployment in any way. But if you want to make 7073*4882a593Smuzhiyunuse of runtime package management, you need to do a couple things above 7074*4882a593Smuzhiyunand beyond the basics. The remainder of this section describes what you 7075*4882a593Smuzhiyunneed to do. 7076*4882a593Smuzhiyun 7077*4882a593SmuzhiyunBuild Considerations 7078*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~ 7079*4882a593Smuzhiyun 7080*4882a593SmuzhiyunThis section describes build considerations of which you need to be 7081*4882a593Smuzhiyunaware in order to provide support for runtime package management. 7082*4882a593Smuzhiyun 7083*4882a593SmuzhiyunWhen BitBake generates packages, it needs to know what format or formats 7084*4882a593Smuzhiyunto use. In your configuration, you use the 7085*4882a593Smuzhiyun:term:`PACKAGE_CLASSES` 7086*4882a593Smuzhiyunvariable to specify the format: 7087*4882a593Smuzhiyun 7088*4882a593Smuzhiyun1. Open the ``local.conf`` file inside your 7089*4882a593Smuzhiyun :term:`Build Directory` (e.g. 7090*4882a593Smuzhiyun ``poky/build/conf/local.conf``). 7091*4882a593Smuzhiyun 7092*4882a593Smuzhiyun2. Select the desired package format as follows:: 7093*4882a593Smuzhiyun 7094*4882a593Smuzhiyun PACKAGE_CLASSES ?= "package_packageformat" 7095*4882a593Smuzhiyun 7096*4882a593Smuzhiyun where packageformat can be "ipk", "rpm", 7097*4882a593Smuzhiyun "deb", or "tar" which are the supported package formats. 7098*4882a593Smuzhiyun 7099*4882a593Smuzhiyun .. note:: 7100*4882a593Smuzhiyun 7101*4882a593Smuzhiyun Because the Yocto Project supports four different package formats, 7102*4882a593Smuzhiyun you can set the variable with more than one argument. However, the 7103*4882a593Smuzhiyun OpenEmbedded build system only uses the first argument when 7104*4882a593Smuzhiyun creating an image or Software Development Kit (SDK). 7105*4882a593Smuzhiyun 7106*4882a593SmuzhiyunIf you would like your image to start off with a basic package database 7107*4882a593Smuzhiyuncontaining the packages in your current build as well as to have the 7108*4882a593Smuzhiyunrelevant tools available on the target for runtime package management, 7109*4882a593Smuzhiyunyou can include "package-management" in the 7110*4882a593Smuzhiyun:term:`IMAGE_FEATURES` 7111*4882a593Smuzhiyunvariable. Including "package-management" in this configuration variable 7112*4882a593Smuzhiyunensures that when the image is assembled for your target, the image 7113*4882a593Smuzhiyunincludes the currently-known package databases as well as the 7114*4882a593Smuzhiyuntarget-specific tools required for runtime package management to be 7115*4882a593Smuzhiyunperformed on the target. However, this is not strictly necessary. You 7116*4882a593Smuzhiyuncould start your image off without any databases but only include the 7117*4882a593Smuzhiyunrequired on-target package tool(s). As an example, you could include 7118*4882a593Smuzhiyun"opkg" in your 7119*4882a593Smuzhiyun:term:`IMAGE_INSTALL` variable 7120*4882a593Smuzhiyunif you are using the IPK package format. You can then initialize your 7121*4882a593Smuzhiyuntarget's package database(s) later once your image is up and running. 7122*4882a593Smuzhiyun 7123*4882a593SmuzhiyunWhenever you perform any sort of build step that can potentially 7124*4882a593Smuzhiyungenerate a package or modify existing package, it is always a good idea 7125*4882a593Smuzhiyunto re-generate the package index after the build by using the following 7126*4882a593Smuzhiyuncommand:: 7127*4882a593Smuzhiyun 7128*4882a593Smuzhiyun $ bitbake package-index 7129*4882a593Smuzhiyun 7130*4882a593SmuzhiyunIt might be tempting to build the 7131*4882a593Smuzhiyunpackage and the package index at the same time with a command such as 7132*4882a593Smuzhiyunthe following:: 7133*4882a593Smuzhiyun 7134*4882a593Smuzhiyun $ bitbake some-package package-index 7135*4882a593Smuzhiyun 7136*4882a593SmuzhiyunDo not do this as 7137*4882a593SmuzhiyunBitBake does not schedule the package index for after the completion of 7138*4882a593Smuzhiyunthe package you are building. Consequently, you cannot be sure of the 7139*4882a593Smuzhiyunpackage index including information for the package you just built. 7140*4882a593SmuzhiyunThus, be sure to run the package update step separately after building 7141*4882a593Smuzhiyunany packages. 7142*4882a593Smuzhiyun 7143*4882a593SmuzhiyunYou can use the 7144*4882a593Smuzhiyun:term:`PACKAGE_FEED_ARCHS`, 7145*4882a593Smuzhiyun:term:`PACKAGE_FEED_BASE_PATHS`, 7146*4882a593Smuzhiyunand 7147*4882a593Smuzhiyun:term:`PACKAGE_FEED_URIS` 7148*4882a593Smuzhiyunvariables to pre-configure target images to use a package feed. If you 7149*4882a593Smuzhiyundo not define these variables, then manual steps as described in the 7150*4882a593Smuzhiyunsubsequent sections are necessary to configure the target. You should 7151*4882a593Smuzhiyunset these variables before building the image in order to produce a 7152*4882a593Smuzhiyuncorrectly configured image. 7153*4882a593Smuzhiyun 7154*4882a593SmuzhiyunWhen your build is complete, your packages reside in the 7155*4882a593Smuzhiyun``${TMPDIR}/deploy/packageformat`` directory. For example, if 7156*4882a593Smuzhiyun``${``\ :term:`TMPDIR`\ ``}`` is 7157*4882a593Smuzhiyun``tmp`` and your selected package type is RPM, then your RPM packages 7158*4882a593Smuzhiyunare available in ``tmp/deploy/rpm``. 7159*4882a593Smuzhiyun 7160*4882a593SmuzhiyunHost or Server Machine Setup 7161*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7162*4882a593Smuzhiyun 7163*4882a593SmuzhiyunAlthough other protocols are possible, a server using HTTP typically 7164*4882a593Smuzhiyunserves packages. If you want to use HTTP, then set up and configure a 7165*4882a593Smuzhiyunweb server such as Apache 2, lighttpd, or Python web server on the 7166*4882a593Smuzhiyunmachine serving the packages. 7167*4882a593Smuzhiyun 7168*4882a593SmuzhiyunTo keep things simple, this section describes how to set up a 7169*4882a593SmuzhiyunPython web server to share package feeds from the developer's 7170*4882a593Smuzhiyunmachine. Although this server might not be the best for a production 7171*4882a593Smuzhiyunenvironment, the setup is simple and straight forward. Should you want 7172*4882a593Smuzhiyunto use a different server more suited for production (e.g. Apache 2, 7173*4882a593SmuzhiyunLighttpd, or Nginx), take the appropriate steps to do so. 7174*4882a593Smuzhiyun 7175*4882a593SmuzhiyunFrom within the build directory where you have built an image based on 7176*4882a593Smuzhiyunyour packaging choice (i.e. the 7177*4882a593Smuzhiyun:term:`PACKAGE_CLASSES` 7178*4882a593Smuzhiyunsetting), simply start the server. The following example assumes a build 7179*4882a593Smuzhiyundirectory of ``poky/build/tmp/deploy/rpm`` and a :term:`PACKAGE_CLASSES` 7180*4882a593Smuzhiyunsetting of "package_rpm":: 7181*4882a593Smuzhiyun 7182*4882a593Smuzhiyun $ cd poky/build/tmp/deploy/rpm 7183*4882a593Smuzhiyun $ python3 -m http.server 7184*4882a593Smuzhiyun 7185*4882a593SmuzhiyunTarget Setup 7186*4882a593Smuzhiyun~~~~~~~~~~~~ 7187*4882a593Smuzhiyun 7188*4882a593SmuzhiyunSetting up the target differs depending on the package management 7189*4882a593Smuzhiyunsystem. This section provides information for RPM, IPK, and DEB. 7190*4882a593Smuzhiyun 7191*4882a593SmuzhiyunUsing RPM 7192*4882a593Smuzhiyun^^^^^^^^^ 7193*4882a593Smuzhiyun 7194*4882a593SmuzhiyunThe `Dandified Packaging 7195*4882a593SmuzhiyunTool <https://en.wikipedia.org/wiki/DNF_(software)>`__ (DNF) performs 7196*4882a593Smuzhiyunruntime package management of RPM packages. In order to use DNF for 7197*4882a593Smuzhiyunruntime package management, you must perform an initial setup on the 7198*4882a593Smuzhiyuntarget machine for cases where the ``PACKAGE_FEED_*`` variables were not 7199*4882a593Smuzhiyunset as part of the image that is running on the target. This means if 7200*4882a593Smuzhiyunyou built your image and did not use these variables as part of the 7201*4882a593Smuzhiyunbuild and your image is now running on the target, you need to perform 7202*4882a593Smuzhiyunthe steps in this section if you want to use runtime package management. 7203*4882a593Smuzhiyun 7204*4882a593Smuzhiyun.. note:: 7205*4882a593Smuzhiyun 7206*4882a593Smuzhiyun For information on the ``PACKAGE_FEED_*`` variables, see 7207*4882a593Smuzhiyun :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and 7208*4882a593Smuzhiyun :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables 7209*4882a593Smuzhiyun glossary. 7210*4882a593Smuzhiyun 7211*4882a593SmuzhiyunOn the target, you must inform DNF that package databases are available. 7212*4882a593SmuzhiyunYou do this by creating a file named 7213*4882a593Smuzhiyun``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``. 7214*4882a593Smuzhiyun 7215*4882a593SmuzhiyunAs an example, assume the target is able to use the following package 7216*4882a593Smuzhiyundatabases: ``all``, ``i586``, and ``qemux86`` from a server named 7217*4882a593Smuzhiyun``my.server``. The specifics for setting up the web server are up to 7218*4882a593Smuzhiyunyou. The critical requirement is that the URIs in the target repository 7219*4882a593Smuzhiyunconfiguration point to the correct remote location for the feeds. 7220*4882a593Smuzhiyun 7221*4882a593Smuzhiyun.. note:: 7222*4882a593Smuzhiyun 7223*4882a593Smuzhiyun For development purposes, you can point the web server to the build 7224*4882a593Smuzhiyun system's ``deploy`` directory. However, for production use, it is better to 7225*4882a593Smuzhiyun copy the package directories to a location outside of the build area and use 7226*4882a593Smuzhiyun that location. Doing so avoids situations where the build system 7227*4882a593Smuzhiyun overwrites or changes the ``deploy`` directory. 7228*4882a593Smuzhiyun 7229*4882a593SmuzhiyunWhen telling DNF where to look for the package databases, you must 7230*4882a593Smuzhiyundeclare individual locations per architecture or a single location used 7231*4882a593Smuzhiyunfor all architectures. You cannot do both: 7232*4882a593Smuzhiyun 7233*4882a593Smuzhiyun- *Create an Explicit List of Architectures:* Define individual base 7234*4882a593Smuzhiyun URLs to identify where each package database is located: 7235*4882a593Smuzhiyun 7236*4882a593Smuzhiyun .. code-block:: none 7237*4882a593Smuzhiyun 7238*4882a593Smuzhiyun [oe-packages] 7239*4882a593Smuzhiyun baseurl=http://my.server/rpm/i586 http://my.server/rpm/qemux86 http://my.server/rpm/all 7240*4882a593Smuzhiyun 7241*4882a593Smuzhiyun This example 7242*4882a593Smuzhiyun informs DNF about individual package databases for all three 7243*4882a593Smuzhiyun architectures. 7244*4882a593Smuzhiyun 7245*4882a593Smuzhiyun- *Create a Single (Full) Package Index:* Define a single base URL that 7246*4882a593Smuzhiyun identifies where a full package database is located:: 7247*4882a593Smuzhiyun 7248*4882a593Smuzhiyun [oe-packages] 7249*4882a593Smuzhiyun baseurl=http://my.server/rpm 7250*4882a593Smuzhiyun 7251*4882a593Smuzhiyun This example informs DNF about a single 7252*4882a593Smuzhiyun package database that contains all the package index information for 7253*4882a593Smuzhiyun all supported architectures. 7254*4882a593Smuzhiyun 7255*4882a593SmuzhiyunOnce you have informed DNF where to find the package databases, you need 7256*4882a593Smuzhiyunto fetch them: 7257*4882a593Smuzhiyun 7258*4882a593Smuzhiyun.. code-block:: none 7259*4882a593Smuzhiyun 7260*4882a593Smuzhiyun # dnf makecache 7261*4882a593Smuzhiyun 7262*4882a593SmuzhiyunDNF is now able to find, install, and 7263*4882a593Smuzhiyunupgrade packages from the specified repository or repositories. 7264*4882a593Smuzhiyun 7265*4882a593Smuzhiyun.. note:: 7266*4882a593Smuzhiyun 7267*4882a593Smuzhiyun See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for 7268*4882a593Smuzhiyun additional information. 7269*4882a593Smuzhiyun 7270*4882a593SmuzhiyunUsing IPK 7271*4882a593Smuzhiyun^^^^^^^^^ 7272*4882a593Smuzhiyun 7273*4882a593SmuzhiyunThe ``opkg`` application performs runtime package management of IPK 7274*4882a593Smuzhiyunpackages. You must perform an initial setup for ``opkg`` on the target 7275*4882a593Smuzhiyunmachine if the 7276*4882a593Smuzhiyun:term:`PACKAGE_FEED_ARCHS`, 7277*4882a593Smuzhiyun:term:`PACKAGE_FEED_BASE_PATHS`, 7278*4882a593Smuzhiyunand 7279*4882a593Smuzhiyun:term:`PACKAGE_FEED_URIS` 7280*4882a593Smuzhiyunvariables have not been set or the target image was built before the 7281*4882a593Smuzhiyunvariables were set. 7282*4882a593Smuzhiyun 7283*4882a593SmuzhiyunThe ``opkg`` application uses configuration files to find available 7284*4882a593Smuzhiyunpackage databases. Thus, you need to create a configuration file inside 7285*4882a593Smuzhiyunthe ``/etc/opkg/`` directory, which informs ``opkg`` of any repository 7286*4882a593Smuzhiyunyou want to use. 7287*4882a593Smuzhiyun 7288*4882a593SmuzhiyunAs an example, suppose you are serving packages from a ``ipk/`` 7289*4882a593Smuzhiyundirectory containing the ``i586``, ``all``, and ``qemux86`` databases 7290*4882a593Smuzhiyunthrough an HTTP server named ``my.server``. On the target, create a 7291*4882a593Smuzhiyunconfiguration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/`` 7292*4882a593Smuzhiyundirectory containing the following: 7293*4882a593Smuzhiyun 7294*4882a593Smuzhiyun.. code-block:: none 7295*4882a593Smuzhiyun 7296*4882a593Smuzhiyun src/gz all http://my.server/ipk/all 7297*4882a593Smuzhiyun src/gz i586 http://my.server/ipk/i586 7298*4882a593Smuzhiyun src/gz qemux86 http://my.server/ipk/qemux86 7299*4882a593Smuzhiyun 7300*4882a593SmuzhiyunNext, instruct ``opkg`` to fetch the 7301*4882a593Smuzhiyunrepository information: 7302*4882a593Smuzhiyun 7303*4882a593Smuzhiyun.. code-block:: none 7304*4882a593Smuzhiyun 7305*4882a593Smuzhiyun # opkg update 7306*4882a593Smuzhiyun 7307*4882a593SmuzhiyunThe ``opkg`` application is now able to find, install, and upgrade packages 7308*4882a593Smuzhiyunfrom the specified repository. 7309*4882a593Smuzhiyun 7310*4882a593SmuzhiyunUsing DEB 7311*4882a593Smuzhiyun^^^^^^^^^ 7312*4882a593Smuzhiyun 7313*4882a593SmuzhiyunThe ``apt`` application performs runtime package management of DEB 7314*4882a593Smuzhiyunpackages. This application uses a source list file to find available 7315*4882a593Smuzhiyunpackage databases. You must perform an initial setup for ``apt`` on the 7316*4882a593Smuzhiyuntarget machine if the 7317*4882a593Smuzhiyun:term:`PACKAGE_FEED_ARCHS`, 7318*4882a593Smuzhiyun:term:`PACKAGE_FEED_BASE_PATHS`, 7319*4882a593Smuzhiyunand 7320*4882a593Smuzhiyun:term:`PACKAGE_FEED_URIS` 7321*4882a593Smuzhiyunvariables have not been set or the target image was built before the 7322*4882a593Smuzhiyunvariables were set. 7323*4882a593Smuzhiyun 7324*4882a593SmuzhiyunTo inform ``apt`` of the repository you want to use, you might create a 7325*4882a593Smuzhiyunlist file (e.g. ``my_repo.list``) inside the 7326*4882a593Smuzhiyun``/etc/apt/sources.list.d/`` directory. As an example, suppose you are 7327*4882a593Smuzhiyunserving packages from a ``deb/`` directory containing the ``i586``, 7328*4882a593Smuzhiyun``all``, and ``qemux86`` databases through an HTTP server named 7329*4882a593Smuzhiyun``my.server``. The list file should contain: 7330*4882a593Smuzhiyun 7331*4882a593Smuzhiyun.. code-block:: none 7332*4882a593Smuzhiyun 7333*4882a593Smuzhiyun deb http://my.server/deb/all ./ 7334*4882a593Smuzhiyun deb http://my.server/deb/i586 ./ 7335*4882a593Smuzhiyun deb http://my.server/deb/qemux86 ./ 7336*4882a593Smuzhiyun 7337*4882a593SmuzhiyunNext, instruct the ``apt`` application 7338*4882a593Smuzhiyunto fetch the repository information: 7339*4882a593Smuzhiyun 7340*4882a593Smuzhiyun.. code-block:: none 7341*4882a593Smuzhiyun 7342*4882a593Smuzhiyun $ sudo apt update 7343*4882a593Smuzhiyun 7344*4882a593SmuzhiyunAfter this step, 7345*4882a593Smuzhiyun``apt`` is able to find, install, and upgrade packages from the 7346*4882a593Smuzhiyunspecified repository. 7347*4882a593Smuzhiyun 7348*4882a593SmuzhiyunGenerating and Using Signed Packages 7349*4882a593Smuzhiyun------------------------------------ 7350*4882a593Smuzhiyun 7351*4882a593SmuzhiyunIn order to add security to RPM packages used during a build, you can 7352*4882a593Smuzhiyuntake steps to securely sign them. Once a signature is verified, the 7353*4882a593SmuzhiyunOpenEmbedded build system can use the package in the build. If security 7354*4882a593Smuzhiyunfails for a signed package, the build system stops the build. 7355*4882a593Smuzhiyun 7356*4882a593SmuzhiyunThis section describes how to sign RPM packages during a build and how 7357*4882a593Smuzhiyunto use signed package feeds (repositories) when doing a build. 7358*4882a593Smuzhiyun 7359*4882a593SmuzhiyunSigning RPM Packages 7360*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~ 7361*4882a593Smuzhiyun 7362*4882a593SmuzhiyunTo enable signing RPM packages, you must set up the following 7363*4882a593Smuzhiyunconfigurations in either your ``local.config`` or ``distro.config`` 7364*4882a593Smuzhiyunfile:: 7365*4882a593Smuzhiyun 7366*4882a593Smuzhiyun # Inherit sign_rpm.bbclass to enable signing functionality 7367*4882a593Smuzhiyun INHERIT += " sign_rpm" 7368*4882a593Smuzhiyun # Define the GPG key that will be used for signing. 7369*4882a593Smuzhiyun RPM_GPG_NAME = "key_name" 7370*4882a593Smuzhiyun # Provide passphrase for the key 7371*4882a593Smuzhiyun RPM_GPG_PASSPHRASE = "passphrase" 7372*4882a593Smuzhiyun 7373*4882a593Smuzhiyun.. note:: 7374*4882a593Smuzhiyun 7375*4882a593Smuzhiyun Be sure to supply appropriate values for both `key_name` and 7376*4882a593Smuzhiyun `passphrase`. 7377*4882a593Smuzhiyun 7378*4882a593SmuzhiyunAside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in 7379*4882a593Smuzhiyunthe previous example, two optional variables related to signing are available: 7380*4882a593Smuzhiyun 7381*4882a593Smuzhiyun- *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed 7382*4882a593Smuzhiyun when the package is signed. 7383*4882a593Smuzhiyun 7384*4882a593Smuzhiyun- *GPG_PATH:* Specifies the ``gpg`` home directory used when the 7385*4882a593Smuzhiyun package is signed. 7386*4882a593Smuzhiyun 7387*4882a593SmuzhiyunProcessing Package Feeds 7388*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~ 7389*4882a593Smuzhiyun 7390*4882a593SmuzhiyunIn addition to being able to sign RPM packages, you can also enable 7391*4882a593Smuzhiyunsigned package feeds for IPK and RPM packages. 7392*4882a593Smuzhiyun 7393*4882a593SmuzhiyunThe steps you need to take to enable signed package feed use are similar 7394*4882a593Smuzhiyunto the steps used to sign RPM packages. You must define the following in 7395*4882a593Smuzhiyunyour ``local.config`` or ``distro.config`` file:: 7396*4882a593Smuzhiyun 7397*4882a593Smuzhiyun INHERIT += "sign_package_feed" 7398*4882a593Smuzhiyun PACKAGE_FEED_GPG_NAME = "key_name" 7399*4882a593Smuzhiyun PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase" 7400*4882a593Smuzhiyun 7401*4882a593SmuzhiyunFor signed package feeds, the passphrase must be specified in a separate file, 7402*4882a593Smuzhiyunwhich is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` 7403*4882a593Smuzhiyunvariable. Regarding security, keeping a plain text passphrase out of the 7404*4882a593Smuzhiyunconfiguration is more secure. 7405*4882a593Smuzhiyun 7406*4882a593SmuzhiyunAside from the ``PACKAGE_FEED_GPG_NAME`` and 7407*4882a593Smuzhiyun``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables 7408*4882a593Smuzhiyunrelated to signed package feeds are available: 7409*4882a593Smuzhiyun 7410*4882a593Smuzhiyun- *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed 7411*4882a593Smuzhiyun when the package is signed. 7412*4882a593Smuzhiyun 7413*4882a593Smuzhiyun- *GPG_PATH:* Specifies the ``gpg`` home directory used when the 7414*4882a593Smuzhiyun package is signed. 7415*4882a593Smuzhiyun 7416*4882a593Smuzhiyun- *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg`` 7417*4882a593Smuzhiyun signature. This variable applies only to RPM and IPK package feeds. 7418*4882a593Smuzhiyun Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are 7419*4882a593Smuzhiyun "ASC", which is the default and specifies ascii armored, and "BIN", 7420*4882a593Smuzhiyun which specifies binary. 7421*4882a593Smuzhiyun 7422*4882a593SmuzhiyunTesting Packages With ptest 7423*4882a593Smuzhiyun--------------------------- 7424*4882a593Smuzhiyun 7425*4882a593SmuzhiyunA Package Test (ptest) runs tests against packages built by the 7426*4882a593SmuzhiyunOpenEmbedded build system on the target machine. A ptest contains at 7427*4882a593Smuzhiyunleast two items: the actual test, and a shell script (``run-ptest``) 7428*4882a593Smuzhiyunthat starts the test. The shell script that starts the test must not 7429*4882a593Smuzhiyuncontain the actual test - the script only starts the test. On the other 7430*4882a593Smuzhiyunhand, the test can be anything from a simple shell script that runs a 7431*4882a593Smuzhiyunbinary and checks the output to an elaborate system of test binaries and 7432*4882a593Smuzhiyundata files. 7433*4882a593Smuzhiyun 7434*4882a593SmuzhiyunThe test generates output in the format used by Automake:: 7435*4882a593Smuzhiyun 7436*4882a593Smuzhiyun result: testname 7437*4882a593Smuzhiyun 7438*4882a593Smuzhiyunwhere the result can be ``PASS``, ``FAIL``, or ``SKIP``, and 7439*4882a593Smuzhiyunthe testname can be any identifying string. 7440*4882a593Smuzhiyun 7441*4882a593SmuzhiyunFor a list of Yocto Project recipes that are already enabled with ptest, 7442*4882a593Smuzhiyunsee the :yocto_wiki:`Ptest </Ptest>` wiki page. 7443*4882a593Smuzhiyun 7444*4882a593Smuzhiyun.. note:: 7445*4882a593Smuzhiyun 7446*4882a593Smuzhiyun A recipe is "ptest-enabled" if it inherits the 7447*4882a593Smuzhiyun :ref:`ptest <ref-classes-ptest>` class. 7448*4882a593Smuzhiyun 7449*4882a593SmuzhiyunAdding ptest to Your Build 7450*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~ 7451*4882a593Smuzhiyun 7452*4882a593SmuzhiyunTo add package testing to your build, add the 7453*4882a593Smuzhiyun:term:`DISTRO_FEATURES` and 7454*4882a593Smuzhiyun:term:`EXTRA_IMAGE_FEATURES` 7455*4882a593Smuzhiyunvariables to your ``local.conf`` file, which is found in the 7456*4882a593Smuzhiyun:term:`Build Directory`:: 7457*4882a593Smuzhiyun 7458*4882a593Smuzhiyun DISTRO_FEATURES:append = " ptest" 7459*4882a593Smuzhiyun EXTRA_IMAGE_FEATURES += "ptest-pkgs" 7460*4882a593Smuzhiyun 7461*4882a593SmuzhiyunOnce your build is complete, the ptest files are installed into the 7462*4882a593Smuzhiyun``/usr/lib/package/ptest`` directory within the image, where ``package`` 7463*4882a593Smuzhiyunis the name of the package. 7464*4882a593Smuzhiyun 7465*4882a593SmuzhiyunRunning ptest 7466*4882a593Smuzhiyun~~~~~~~~~~~~~ 7467*4882a593Smuzhiyun 7468*4882a593SmuzhiyunThe ``ptest-runner`` package installs a shell script that loops through 7469*4882a593Smuzhiyunall installed ptest test suites and runs them in sequence. Consequently, 7470*4882a593Smuzhiyunyou might want to add this package to your image. 7471*4882a593Smuzhiyun 7472*4882a593SmuzhiyunGetting Your Package Ready 7473*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~ 7474*4882a593Smuzhiyun 7475*4882a593SmuzhiyunIn order to enable a recipe to run installed ptests on target hardware, 7476*4882a593Smuzhiyunyou need to prepare the recipes that build the packages you want to 7477*4882a593Smuzhiyuntest. Here is what you have to do for each recipe: 7478*4882a593Smuzhiyun 7479*4882a593Smuzhiyun- *Be sure the recipe inherits 7480*4882a593Smuzhiyun the* :ref:`ptest <ref-classes-ptest>` *class:* 7481*4882a593Smuzhiyun Include the following line in each recipe:: 7482*4882a593Smuzhiyun 7483*4882a593Smuzhiyun inherit ptest 7484*4882a593Smuzhiyun 7485*4882a593Smuzhiyun- *Create run-ptest:* This script starts your test. Locate the 7486*4882a593Smuzhiyun script where you will refer to it using 7487*4882a593Smuzhiyun :term:`SRC_URI`. Here is an 7488*4882a593Smuzhiyun example that starts a test for ``dbus``:: 7489*4882a593Smuzhiyun 7490*4882a593Smuzhiyun #!/bin/sh 7491*4882a593Smuzhiyun cd test 7492*4882a593Smuzhiyun make -k runtest-TESTS 7493*4882a593Smuzhiyun 7494*4882a593Smuzhiyun- *Ensure dependencies are met:* If the test adds build or runtime 7495*4882a593Smuzhiyun dependencies that normally do not exist for the package (such as 7496*4882a593Smuzhiyun requiring "make" to run the test suite), use the 7497*4882a593Smuzhiyun :term:`DEPENDS` and 7498*4882a593Smuzhiyun :term:`RDEPENDS` variables in 7499*4882a593Smuzhiyun your recipe in order for the package to meet the dependencies. Here 7500*4882a593Smuzhiyun is an example where the package has a runtime dependency on "make":: 7501*4882a593Smuzhiyun 7502*4882a593Smuzhiyun RDEPENDS:${PN}-ptest += "make" 7503*4882a593Smuzhiyun 7504*4882a593Smuzhiyun- *Add a function to build the test suite:* Not many packages support 7505*4882a593Smuzhiyun cross-compilation of their test suites. Consequently, you usually 7506*4882a593Smuzhiyun need to add a cross-compilation function to the package. 7507*4882a593Smuzhiyun 7508*4882a593Smuzhiyun Many packages based on Automake compile and run the test suite by 7509*4882a593Smuzhiyun using a single command such as ``make check``. However, the host 7510*4882a593Smuzhiyun ``make check`` builds and runs on the same computer, while 7511*4882a593Smuzhiyun cross-compiling requires that the package is built on the host but 7512*4882a593Smuzhiyun executed for the target architecture (though often, as in the case 7513*4882a593Smuzhiyun for ptest, the execution occurs on the host). The built version of 7514*4882a593Smuzhiyun Automake that ships with the Yocto Project includes a patch that 7515*4882a593Smuzhiyun separates building and execution. Consequently, packages that use the 7516*4882a593Smuzhiyun unaltered, patched version of ``make check`` automatically 7517*4882a593Smuzhiyun cross-compiles. 7518*4882a593Smuzhiyun 7519*4882a593Smuzhiyun Regardless, you still must add a ``do_compile_ptest`` function to 7520*4882a593Smuzhiyun build the test suite. Add a function similar to the following to your 7521*4882a593Smuzhiyun recipe:: 7522*4882a593Smuzhiyun 7523*4882a593Smuzhiyun do_compile_ptest() { 7524*4882a593Smuzhiyun oe_runmake buildtest-TESTS 7525*4882a593Smuzhiyun } 7526*4882a593Smuzhiyun 7527*4882a593Smuzhiyun- *Ensure special configurations are set:* If the package requires 7528*4882a593Smuzhiyun special configurations prior to compiling the test code, you must 7529*4882a593Smuzhiyun insert a ``do_configure_ptest`` function into the recipe. 7530*4882a593Smuzhiyun 7531*4882a593Smuzhiyun- *Install the test suite:* The ``ptest`` class automatically copies 7532*4882a593Smuzhiyun the file ``run-ptest`` to the target and then runs make 7533*4882a593Smuzhiyun ``install-ptest`` to run the tests. If this is not enough, you need 7534*4882a593Smuzhiyun to create a ``do_install_ptest`` function and make sure it gets 7535*4882a593Smuzhiyun called after the "make install-ptest" completes. 7536*4882a593Smuzhiyun 7537*4882a593SmuzhiyunCreating Node Package Manager (NPM) Packages 7538*4882a593Smuzhiyun-------------------------------------------- 7539*4882a593Smuzhiyun 7540*4882a593Smuzhiyun`NPM <https://en.wikipedia.org/wiki/Npm_(software)>`__ is a package 7541*4882a593Smuzhiyunmanager for the JavaScript programming language. The Yocto Project 7542*4882a593Smuzhiyunsupports the NPM :ref:`fetcher <bitbake:bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. You can 7543*4882a593Smuzhiyunuse this fetcher in combination with 7544*4882a593Smuzhiyun:doc:`devtool </ref-manual/devtool-reference>` to create 7545*4882a593Smuzhiyunrecipes that produce NPM packages. 7546*4882a593Smuzhiyun 7547*4882a593SmuzhiyunThere are two workflows that allow you to create NPM packages using 7548*4882a593Smuzhiyun``devtool``: the NPM registry modules method and the NPM project code 7549*4882a593Smuzhiyunmethod. 7550*4882a593Smuzhiyun 7551*4882a593Smuzhiyun.. note:: 7552*4882a593Smuzhiyun 7553*4882a593Smuzhiyun While it is possible to create NPM recipes manually, using 7554*4882a593Smuzhiyun ``devtool`` is far simpler. 7555*4882a593Smuzhiyun 7556*4882a593SmuzhiyunAdditionally, some requirements and caveats exist. 7557*4882a593Smuzhiyun 7558*4882a593SmuzhiyunRequirements and Caveats 7559*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~ 7560*4882a593Smuzhiyun 7561*4882a593SmuzhiyunYou need to be aware of the following before using ``devtool`` to create 7562*4882a593SmuzhiyunNPM packages: 7563*4882a593Smuzhiyun 7564*4882a593Smuzhiyun- Of the two methods that you can use ``devtool`` to create NPM 7565*4882a593Smuzhiyun packages, the registry approach is slightly simpler. However, you 7566*4882a593Smuzhiyun might consider the project approach because you do not have to 7567*4882a593Smuzhiyun publish your module in the NPM registry 7568*4882a593Smuzhiyun (`npm-registry <https://docs.npmjs.com/misc/registry>`_), which 7569*4882a593Smuzhiyun is NPM's public registry. 7570*4882a593Smuzhiyun 7571*4882a593Smuzhiyun- Be familiar with 7572*4882a593Smuzhiyun :doc:`devtool </ref-manual/devtool-reference>`. 7573*4882a593Smuzhiyun 7574*4882a593Smuzhiyun- The NPM host tools need the native ``nodejs-npm`` package, which is 7575*4882a593Smuzhiyun part of the OpenEmbedded environment. You need to get the package by 7576*4882a593Smuzhiyun cloning the https://github.com/openembedded/meta-openembedded 7577*4882a593Smuzhiyun repository out of GitHub. Be sure to add the path to your local copy 7578*4882a593Smuzhiyun to your ``bblayers.conf`` file. 7579*4882a593Smuzhiyun 7580*4882a593Smuzhiyun- ``devtool`` cannot detect native libraries in module dependencies. 7581*4882a593Smuzhiyun Consequently, you must manually add packages to your recipe. 7582*4882a593Smuzhiyun 7583*4882a593Smuzhiyun- While deploying NPM packages, ``devtool`` cannot determine which 7584*4882a593Smuzhiyun dependent packages are missing on the target (e.g. the node runtime 7585*4882a593Smuzhiyun ``nodejs``). Consequently, you need to find out what files are 7586*4882a593Smuzhiyun missing and be sure they are on the target. 7587*4882a593Smuzhiyun 7588*4882a593Smuzhiyun- Although you might not need NPM to run your node package, it is 7589*4882a593Smuzhiyun useful to have NPM on your target. The NPM package name is 7590*4882a593Smuzhiyun ``nodejs-npm``. 7591*4882a593Smuzhiyun 7592*4882a593SmuzhiyunUsing the Registry Modules Method 7593*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7594*4882a593Smuzhiyun 7595*4882a593SmuzhiyunThis section presents an example that uses the ``cute-files`` module, 7596*4882a593Smuzhiyunwhich is a file browser web application. 7597*4882a593Smuzhiyun 7598*4882a593Smuzhiyun.. note:: 7599*4882a593Smuzhiyun 7600*4882a593Smuzhiyun You must know the ``cute-files`` module version. 7601*4882a593Smuzhiyun 7602*4882a593SmuzhiyunThe first thing you need to do is use ``devtool`` and the NPM fetcher to 7603*4882a593Smuzhiyuncreate the recipe:: 7604*4882a593Smuzhiyun 7605*4882a593Smuzhiyun $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2" 7606*4882a593Smuzhiyun 7607*4882a593SmuzhiyunThe 7608*4882a593Smuzhiyun``devtool add`` command runs ``recipetool create`` and uses the same 7609*4882a593Smuzhiyunfetch URI to download each dependency and capture license details where 7610*4882a593Smuzhiyunpossible. The result is a generated recipe. 7611*4882a593Smuzhiyun 7612*4882a593SmuzhiyunThe recipe file is fairly simple and contains every license that 7613*4882a593Smuzhiyun``recipetool`` finds and includes the licenses in the recipe's 7614*4882a593Smuzhiyun:term:`LIC_FILES_CHKSUM` 7615*4882a593Smuzhiyunvariables. You need to examine the variables and look for those with 7616*4882a593Smuzhiyun"unknown" in the :term:`LICENSE` 7617*4882a593Smuzhiyunfield. You need to track down the license information for "unknown" 7618*4882a593Smuzhiyunmodules and manually add the information to the recipe. 7619*4882a593Smuzhiyun 7620*4882a593Smuzhiyun``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap 7621*4882a593Smuzhiyunfiles capture the version of all dependent modules. Many packages do not 7622*4882a593Smuzhiyunprovide shrinkwrap files. ``recipetool`` create a shrinkwrap file as it 7623*4882a593Smuzhiyunruns. 7624*4882a593Smuzhiyun 7625*4882a593Smuzhiyun.. note:: 7626*4882a593Smuzhiyun 7627*4882a593Smuzhiyun A package is created for each sub-module. This policy is the only 7628*4882a593Smuzhiyun practical way to have the licenses for all of the dependencies 7629*4882a593Smuzhiyun represented in the license manifest of the image. 7630*4882a593Smuzhiyun 7631*4882a593SmuzhiyunThe ``devtool edit-recipe`` command lets you take a look at the recipe:: 7632*4882a593Smuzhiyun 7633*4882a593Smuzhiyun $ devtool edit-recipe cute-files 7634*4882a593Smuzhiyun SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." 7635*4882a593Smuzhiyun LICENSE = "MIT & ISC & Unknown" 7636*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \ 7637*4882a593Smuzhiyun file://node_modules/toidentifier/LICENSE;md5=1a261071a044d02eb6f2bb47f51a3502 \ 7638*4882a593Smuzhiyun file://node_modules/debug/LICENSE;md5=ddd815a475e7338b0be7a14d8ee35a99 \ 7639*4882a593Smuzhiyun ... 7640*4882a593Smuzhiyun SRC_URI = " \ 7641*4882a593Smuzhiyun npm://registry.npmjs.org/;package=cute-files;version=${PV} \ 7642*4882a593Smuzhiyun npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ 7643*4882a593Smuzhiyun " 7644*4882a593Smuzhiyun S = "${WORKDIR}/npm" 7645*4882a593Smuzhiyun inherit npm 7646*4882a593Smuzhiyun LICENSE:${PN} = "MIT" 7647*4882a593Smuzhiyun LICENSE:${PN}-accepts = "MIT" 7648*4882a593Smuzhiyun LICENSE:${PN}-array-flatten = "MIT" 7649*4882a593Smuzhiyun ... 7650*4882a593Smuzhiyun LICENSE:${PN}-vary = "MIT" 7651*4882a593Smuzhiyun 7652*4882a593SmuzhiyunHere are three key points in the previous example: 7653*4882a593Smuzhiyun 7654*4882a593Smuzhiyun- :term:`SRC_URI` uses the NPM 7655*4882a593Smuzhiyun scheme so that the NPM fetcher is used. 7656*4882a593Smuzhiyun 7657*4882a593Smuzhiyun- ``recipetool`` collects all the license information. If a 7658*4882a593Smuzhiyun sub-module's license is unavailable, the sub-module's name appears in 7659*4882a593Smuzhiyun the comments. 7660*4882a593Smuzhiyun 7661*4882a593Smuzhiyun- The ``inherit npm`` statement causes the 7662*4882a593Smuzhiyun :ref:`npm <ref-classes-npm>` class to package 7663*4882a593Smuzhiyun up all the modules. 7664*4882a593Smuzhiyun 7665*4882a593SmuzhiyunYou can run the following command to build the ``cute-files`` package:: 7666*4882a593Smuzhiyun 7667*4882a593Smuzhiyun $ devtool build cute-files 7668*4882a593Smuzhiyun 7669*4882a593SmuzhiyunRemember that ``nodejs`` must be installed on 7670*4882a593Smuzhiyunthe target before your package. 7671*4882a593Smuzhiyun 7672*4882a593SmuzhiyunAssuming 192.168.7.2 for the target's IP address, use the following 7673*4882a593Smuzhiyuncommand to deploy your package:: 7674*4882a593Smuzhiyun 7675*4882a593Smuzhiyun $ devtool deploy-target -s cute-files root@192.168.7.2 7676*4882a593Smuzhiyun 7677*4882a593SmuzhiyunOnce the package is installed on the target, you can 7678*4882a593Smuzhiyuntest the application: 7679*4882a593Smuzhiyun 7680*4882a593Smuzhiyun.. note:: 7681*4882a593Smuzhiyun 7682*4882a593Smuzhiyun Because of a known issue, you cannot simply run ``cute-files`` as you would 7683*4882a593Smuzhiyun if you had run ``npm install``. 7684*4882a593Smuzhiyun 7685*4882a593Smuzhiyun:: 7686*4882a593Smuzhiyun 7687*4882a593Smuzhiyun $ cd /usr/lib/node_modules/cute-files 7688*4882a593Smuzhiyun $ node cute-files.js 7689*4882a593Smuzhiyun 7690*4882a593SmuzhiyunOn a browser, 7691*4882a593Smuzhiyungo to ``http://192.168.7.2:3000`` and you see the following: 7692*4882a593Smuzhiyun 7693*4882a593Smuzhiyun.. image:: figures/cute-files-npm-example.png 7694*4882a593Smuzhiyun :align: center 7695*4882a593Smuzhiyun 7696*4882a593SmuzhiyunYou can find the recipe in ``workspace/recipes/cute-files``. You can use 7697*4882a593Smuzhiyunthe recipe in any layer you choose. 7698*4882a593Smuzhiyun 7699*4882a593SmuzhiyunUsing the NPM Projects Code Method 7700*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 7701*4882a593Smuzhiyun 7702*4882a593SmuzhiyunAlthough it is useful to package modules already in the NPM registry, 7703*4882a593Smuzhiyunadding ``node.js`` projects under development is a more common developer 7704*4882a593Smuzhiyunuse case. 7705*4882a593Smuzhiyun 7706*4882a593SmuzhiyunThis section covers the NPM projects code method, which is very similar 7707*4882a593Smuzhiyunto the "registry" approach described in the previous section. In the NPM 7708*4882a593Smuzhiyunprojects method, you provide ``devtool`` with an URL that points to the 7709*4882a593Smuzhiyunsource files. 7710*4882a593Smuzhiyun 7711*4882a593SmuzhiyunReplicating the same example, (i.e. ``cute-files``) use the following 7712*4882a593Smuzhiyuncommand:: 7713*4882a593Smuzhiyun 7714*4882a593Smuzhiyun $ devtool add https://github.com/martinaglv/cute-files.git 7715*4882a593Smuzhiyun 7716*4882a593SmuzhiyunThe 7717*4882a593Smuzhiyunrecipe this command generates is very similar to the recipe created in 7718*4882a593Smuzhiyunthe previous section. However, the :term:`SRC_URI` looks like the following:: 7719*4882a593Smuzhiyun 7720*4882a593Smuzhiyun SRC_URI = " \ 7721*4882a593Smuzhiyun git://github.com/martinaglv/cute-files.git;protocol=https \ 7722*4882a593Smuzhiyun npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ 7723*4882a593Smuzhiyun " 7724*4882a593Smuzhiyun 7725*4882a593SmuzhiyunIn this example, 7726*4882a593Smuzhiyunthe main module is taken from the Git repository and dependencies are 7727*4882a593Smuzhiyuntaken from the NPM registry. Other than those differences, the recipe is 7728*4882a593Smuzhiyunbasically the same between the two methods. You can build and deploy the 7729*4882a593Smuzhiyunpackage exactly as described in the previous section that uses the 7730*4882a593Smuzhiyunregistry modules method. 7731*4882a593Smuzhiyun 7732*4882a593SmuzhiyunAdding custom metadata to packages 7733*4882a593Smuzhiyun---------------------------------- 7734*4882a593Smuzhiyun 7735*4882a593SmuzhiyunThe variable 7736*4882a593Smuzhiyun:term:`PACKAGE_ADD_METADATA` 7737*4882a593Smuzhiyuncan be used to add additional metadata to packages. This is reflected in 7738*4882a593Smuzhiyunthe package control/spec file. To take the ipk format for example, the 7739*4882a593SmuzhiyunCONTROL file stored inside would contain the additional metadata as 7740*4882a593Smuzhiyunadditional lines. 7741*4882a593Smuzhiyun 7742*4882a593SmuzhiyunThe variable can be used in multiple ways, including using suffixes to 7743*4882a593Smuzhiyunset it for a specific package type and/or package. Note that the order 7744*4882a593Smuzhiyunof precedence is the same as this list: 7745*4882a593Smuzhiyun 7746*4882a593Smuzhiyun- ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>`` 7747*4882a593Smuzhiyun 7748*4882a593Smuzhiyun- ``PACKAGE_ADD_METADATA_<PKGTYPE>`` 7749*4882a593Smuzhiyun 7750*4882a593Smuzhiyun- ``PACKAGE_ADD_METADATA:<PN>`` 7751*4882a593Smuzhiyun 7752*4882a593Smuzhiyun- :term:`PACKAGE_ADD_METADATA` 7753*4882a593Smuzhiyun 7754*4882a593Smuzhiyun`<PKGTYPE>` is a parameter and expected to be a distinct name of specific 7755*4882a593Smuzhiyunpackage type: 7756*4882a593Smuzhiyun 7757*4882a593Smuzhiyun- IPK for .ipk packages 7758*4882a593Smuzhiyun 7759*4882a593Smuzhiyun- DEB for .deb packages 7760*4882a593Smuzhiyun 7761*4882a593Smuzhiyun- RPM for .rpm packages 7762*4882a593Smuzhiyun 7763*4882a593Smuzhiyun`<PN>` is a parameter and expected to be a package name. 7764*4882a593Smuzhiyun 7765*4882a593SmuzhiyunThe variable can contain multiple [one-line] metadata fields separated 7766*4882a593Smuzhiyunby the literal sequence '\\n'. The separator can be redefined using the 7767*4882a593Smuzhiyunvariable flag ``separator``. 7768*4882a593Smuzhiyun 7769*4882a593SmuzhiyunHere is an example that adds two custom fields for ipk 7770*4882a593Smuzhiyunpackages:: 7771*4882a593Smuzhiyun 7772*4882a593Smuzhiyun PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets" 7773*4882a593Smuzhiyun 7774*4882a593SmuzhiyunEfficiently Fetching Source Files During a Build 7775*4882a593Smuzhiyun================================================ 7776*4882a593Smuzhiyun 7777*4882a593SmuzhiyunThe OpenEmbedded build system works with source files located through 7778*4882a593Smuzhiyunthe :term:`SRC_URI` variable. When 7779*4882a593Smuzhiyunyou build something using BitBake, a big part of the operation is 7780*4882a593Smuzhiyunlocating and downloading all the source tarballs. For images, 7781*4882a593Smuzhiyundownloading all the source for various packages can take a significant 7782*4882a593Smuzhiyunamount of time. 7783*4882a593Smuzhiyun 7784*4882a593SmuzhiyunThis section shows you how you can use mirrors to speed up fetching 7785*4882a593Smuzhiyunsource files and how you can pre-fetch files all of which leads to more 7786*4882a593Smuzhiyunefficient use of resources and time. 7787*4882a593Smuzhiyun 7788*4882a593SmuzhiyunSetting up Effective Mirrors 7789*4882a593Smuzhiyun---------------------------- 7790*4882a593Smuzhiyun 7791*4882a593SmuzhiyunA good deal that goes into a Yocto Project build is simply downloading 7792*4882a593Smuzhiyunall of the source tarballs. Maybe you have been working with another 7793*4882a593Smuzhiyunbuild system for which you have built up a 7794*4882a593Smuzhiyunsizable directory of source tarballs. Or, perhaps someone else has such 7795*4882a593Smuzhiyuna directory for which you have read access. If so, you can save time by 7796*4882a593Smuzhiyunadding statements to your configuration file so that the build process 7797*4882a593Smuzhiyunchecks local directories first for existing tarballs before checking the 7798*4882a593SmuzhiyunInternet. 7799*4882a593Smuzhiyun 7800*4882a593SmuzhiyunHere is an efficient way to set it up in your ``local.conf`` file:: 7801*4882a593Smuzhiyun 7802*4882a593Smuzhiyun SOURCE_MIRROR_URL ?= "file:///home/you/your-download-dir/" 7803*4882a593Smuzhiyun INHERIT += "own-mirrors" 7804*4882a593Smuzhiyun BB_GENERATE_MIRROR_TARBALLS = "1" 7805*4882a593Smuzhiyun # BB_NO_NETWORK = "1" 7806*4882a593Smuzhiyun 7807*4882a593SmuzhiyunIn the previous example, the 7808*4882a593Smuzhiyun:term:`BB_GENERATE_MIRROR_TARBALLS` 7809*4882a593Smuzhiyunvariable causes the OpenEmbedded build system to generate tarballs of 7810*4882a593Smuzhiyunthe Git repositories and store them in the 7811*4882a593Smuzhiyun:term:`DL_DIR` directory. Due to 7812*4882a593Smuzhiyunperformance reasons, generating and storing these tarballs is not the 7813*4882a593Smuzhiyunbuild system's default behavior. 7814*4882a593Smuzhiyun 7815*4882a593SmuzhiyunYou can also use the 7816*4882a593Smuzhiyun:term:`PREMIRRORS` variable. For 7817*4882a593Smuzhiyunan example, see the variable's glossary entry in the Yocto Project 7818*4882a593SmuzhiyunReference Manual. 7819*4882a593Smuzhiyun 7820*4882a593SmuzhiyunGetting Source Files and Suppressing the Build 7821*4882a593Smuzhiyun---------------------------------------------- 7822*4882a593Smuzhiyun 7823*4882a593SmuzhiyunAnother technique you can use to ready yourself for a successive string 7824*4882a593Smuzhiyunof build operations, is to pre-fetch all the source files without 7825*4882a593Smuzhiyunactually starting a build. This technique lets you work through any 7826*4882a593Smuzhiyundownload issues and ultimately gathers all the source files into your 7827*4882a593Smuzhiyundownload directory :ref:`structure-build-downloads`, 7828*4882a593Smuzhiyunwhich is located with :term:`DL_DIR`. 7829*4882a593Smuzhiyun 7830*4882a593SmuzhiyunUse the following BitBake command form to fetch all the necessary 7831*4882a593Smuzhiyunsources without starting the build:: 7832*4882a593Smuzhiyun 7833*4882a593Smuzhiyun $ bitbake target --runall=fetch 7834*4882a593Smuzhiyun 7835*4882a593SmuzhiyunThis 7836*4882a593Smuzhiyunvariation of the BitBake command guarantees that you have all the 7837*4882a593Smuzhiyunsources for that BitBake target should you disconnect from the Internet 7838*4882a593Smuzhiyunand want to do the build later offline. 7839*4882a593Smuzhiyun 7840*4882a593SmuzhiyunSelecting an Initialization Manager 7841*4882a593Smuzhiyun=================================== 7842*4882a593Smuzhiyun 7843*4882a593SmuzhiyunBy default, the Yocto Project uses SysVinit as the initialization 7844*4882a593Smuzhiyunmanager. However, there is also support for systemd, which is a full 7845*4882a593Smuzhiyunreplacement for init with parallel starting of services, reduced shell 7846*4882a593Smuzhiyunoverhead and other features that are used by many distributions. 7847*4882a593Smuzhiyun 7848*4882a593SmuzhiyunWithin the system, SysVinit treats system components as services. These 7849*4882a593Smuzhiyunservices are maintained as shell scripts stored in the ``/etc/init.d/`` 7850*4882a593Smuzhiyundirectory. Services organize into different run levels. This 7851*4882a593Smuzhiyunorganization is maintained by putting links to the services in the 7852*4882a593Smuzhiyun``/etc/rcN.d/`` directories, where `N/` is one of the following options: 7853*4882a593Smuzhiyun"S", "0", "1", "2", "3", "4", "5", or "6". 7854*4882a593Smuzhiyun 7855*4882a593Smuzhiyun.. note:: 7856*4882a593Smuzhiyun 7857*4882a593Smuzhiyun Each runlevel has a dependency on the previous runlevel. This 7858*4882a593Smuzhiyun dependency allows the services to work properly. 7859*4882a593Smuzhiyun 7860*4882a593SmuzhiyunIn comparison, systemd treats components as units. Using units is a 7861*4882a593Smuzhiyunbroader concept as compared to using a service. A unit includes several 7862*4882a593Smuzhiyundifferent types of entities. Service is one of the types of entities. 7863*4882a593SmuzhiyunThe runlevel concept in SysVinit corresponds to the concept of a target 7864*4882a593Smuzhiyunin systemd, where target is also a type of supported unit. 7865*4882a593Smuzhiyun 7866*4882a593SmuzhiyunIn a SysVinit-based system, services load sequentially (i.e. one by one) 7867*4882a593Smuzhiyunduring init and parallelization is not supported. With systemd, services 7868*4882a593Smuzhiyunstart in parallel. Needless to say, the method can have an impact on 7869*4882a593Smuzhiyunsystem startup performance. 7870*4882a593Smuzhiyun 7871*4882a593SmuzhiyunIf you want to use SysVinit, you do not have to do anything. But, if you 7872*4882a593Smuzhiyunwant to use systemd, you must take some steps as described in the 7873*4882a593Smuzhiyunfollowing sections. 7874*4882a593Smuzhiyun 7875*4882a593SmuzhiyunUsing systemd Exclusively 7876*4882a593Smuzhiyun------------------------- 7877*4882a593Smuzhiyun 7878*4882a593SmuzhiyunSet these variables in your distribution configuration file as follows:: 7879*4882a593Smuzhiyun 7880*4882a593Smuzhiyun DISTRO_FEATURES:append = " systemd" 7881*4882a593Smuzhiyun VIRTUAL-RUNTIME_init_manager = "systemd" 7882*4882a593Smuzhiyun 7883*4882a593SmuzhiyunYou can also prevent the SysVinit distribution feature from 7884*4882a593Smuzhiyunbeing automatically enabled as follows:: 7885*4882a593Smuzhiyun 7886*4882a593Smuzhiyun DISTRO_FEATURES_BACKFILL_CONSIDERED = "sysvinit" 7887*4882a593Smuzhiyun 7888*4882a593SmuzhiyunDoing so removes any 7889*4882a593Smuzhiyunredundant SysVinit scripts. 7890*4882a593Smuzhiyun 7891*4882a593SmuzhiyunTo remove initscripts from your image altogether, set this variable 7892*4882a593Smuzhiyunalso:: 7893*4882a593Smuzhiyun 7894*4882a593Smuzhiyun VIRTUAL-RUNTIME_initscripts = "" 7895*4882a593Smuzhiyun 7896*4882a593SmuzhiyunFor information on the backfill variable, see 7897*4882a593Smuzhiyun:term:`DISTRO_FEATURES_BACKFILL_CONSIDERED`. 7898*4882a593Smuzhiyun 7899*4882a593SmuzhiyunUsing systemd for the Main Image and Using SysVinit for the Rescue Image 7900*4882a593Smuzhiyun------------------------------------------------------------------------ 7901*4882a593Smuzhiyun 7902*4882a593SmuzhiyunSet these variables in your distribution configuration file as follows:: 7903*4882a593Smuzhiyun 7904*4882a593Smuzhiyun DISTRO_FEATURES:append = " systemd" 7905*4882a593Smuzhiyun VIRTUAL-RUNTIME_init_manager = "systemd" 7906*4882a593Smuzhiyun 7907*4882a593SmuzhiyunDoing so causes your main image to use the 7908*4882a593Smuzhiyun``packagegroup-core-boot.bb`` recipe and systemd. The rescue/minimal 7909*4882a593Smuzhiyunimage cannot use this package group. However, it can install SysVinit 7910*4882a593Smuzhiyunand the appropriate packages will have support for both systemd and 7911*4882a593SmuzhiyunSysVinit. 7912*4882a593Smuzhiyun 7913*4882a593SmuzhiyunUsing systemd-journald without a traditional syslog daemon 7914*4882a593Smuzhiyun---------------------------------------------------------- 7915*4882a593Smuzhiyun 7916*4882a593SmuzhiyunCounter-intuitively, ``systemd-journald`` is not a syslog runtime or provider, 7917*4882a593Smuzhiyunand the proper way to use systemd-journald as your sole logging mechanism is to 7918*4882a593Smuzhiyuneffectively disable syslog entirely by setting these variables in your distribution 7919*4882a593Smuzhiyunconfiguration file:: 7920*4882a593Smuzhiyun 7921*4882a593Smuzhiyun VIRTUAL-RUNTIME_syslog = "" 7922*4882a593Smuzhiyun VIRTUAL-RUNTIME_base-utils-syslog = "" 7923*4882a593Smuzhiyun 7924*4882a593SmuzhiyunDoing so will prevent ``rsyslog`` / ``busybox-syslog`` from being pulled in by 7925*4882a593Smuzhiyundefault, leaving only ``journald``. 7926*4882a593Smuzhiyun 7927*4882a593SmuzhiyunSelecting a Device Manager 7928*4882a593Smuzhiyun========================== 7929*4882a593Smuzhiyun 7930*4882a593SmuzhiyunThe Yocto Project provides multiple ways to manage the device manager 7931*4882a593Smuzhiyun(``/dev``): 7932*4882a593Smuzhiyun 7933*4882a593Smuzhiyun- Persistent and Pre-Populated ``/dev``: For this case, the ``/dev`` 7934*4882a593Smuzhiyun directory is persistent and the required device nodes are created 7935*4882a593Smuzhiyun during the build. 7936*4882a593Smuzhiyun 7937*4882a593Smuzhiyun- Use ``devtmpfs`` with a Device Manager: For this case, the ``/dev`` 7938*4882a593Smuzhiyun directory is provided by the kernel as an in-memory file system and 7939*4882a593Smuzhiyun is automatically populated by the kernel at runtime. Additional 7940*4882a593Smuzhiyun configuration of device nodes is done in user space by a device 7941*4882a593Smuzhiyun manager like ``udev`` or ``busybox-mdev``. 7942*4882a593Smuzhiyun 7943*4882a593SmuzhiyunUsing Persistent and Pre-Populated ``/dev`` 7944*4882a593Smuzhiyun-------------------------------------------- 7945*4882a593Smuzhiyun 7946*4882a593SmuzhiyunTo use the static method for device population, you need to set the 7947*4882a593Smuzhiyun:term:`USE_DEVFS` variable to "0" 7948*4882a593Smuzhiyunas follows:: 7949*4882a593Smuzhiyun 7950*4882a593Smuzhiyun USE_DEVFS = "0" 7951*4882a593Smuzhiyun 7952*4882a593SmuzhiyunThe content of the resulting ``/dev`` directory is defined in a Device 7953*4882a593SmuzhiyunTable file. The 7954*4882a593Smuzhiyun:term:`IMAGE_DEVICE_TABLES` 7955*4882a593Smuzhiyunvariable defines the Device Table to use and should be set in the 7956*4882a593Smuzhiyunmachine or distro configuration file. Alternatively, you can set this 7957*4882a593Smuzhiyunvariable in your ``local.conf`` configuration file. 7958*4882a593Smuzhiyun 7959*4882a593SmuzhiyunIf you do not define the :term:`IMAGE_DEVICE_TABLES` variable, the default 7960*4882a593Smuzhiyun``device_table-minimal.txt`` is used:: 7961*4882a593Smuzhiyun 7962*4882a593Smuzhiyun IMAGE_DEVICE_TABLES = "device_table-mymachine.txt" 7963*4882a593Smuzhiyun 7964*4882a593SmuzhiyunThe population is handled by the ``makedevs`` utility during image 7965*4882a593Smuzhiyuncreation: 7966*4882a593Smuzhiyun 7967*4882a593SmuzhiyunUsing ``devtmpfs`` and a Device Manager 7968*4882a593Smuzhiyun--------------------------------------- 7969*4882a593Smuzhiyun 7970*4882a593SmuzhiyunTo use the dynamic method for device population, you need to use (or be 7971*4882a593Smuzhiyunsure to set) the :term:`USE_DEVFS` 7972*4882a593Smuzhiyunvariable to "1", which is the default:: 7973*4882a593Smuzhiyun 7974*4882a593Smuzhiyun USE_DEVFS = "1" 7975*4882a593Smuzhiyun 7976*4882a593SmuzhiyunWith this 7977*4882a593Smuzhiyunsetting, the resulting ``/dev`` directory is populated by the kernel 7978*4882a593Smuzhiyunusing ``devtmpfs``. Make sure the corresponding kernel configuration 7979*4882a593Smuzhiyunvariable ``CONFIG_DEVTMPFS`` is set when building you build a Linux 7980*4882a593Smuzhiyunkernel. 7981*4882a593Smuzhiyun 7982*4882a593SmuzhiyunAll devices created by ``devtmpfs`` will be owned by ``root`` and have 7983*4882a593Smuzhiyunpermissions ``0600``. 7984*4882a593Smuzhiyun 7985*4882a593SmuzhiyunTo have more control over the device nodes, you can use a device manager 7986*4882a593Smuzhiyunlike ``udev`` or ``busybox-mdev``. You choose the device manager by 7987*4882a593Smuzhiyundefining the ``VIRTUAL-RUNTIME_dev_manager`` variable in your machine or 7988*4882a593Smuzhiyundistro configuration file. Alternatively, you can set this variable in 7989*4882a593Smuzhiyunyour ``local.conf`` configuration file:: 7990*4882a593Smuzhiyun 7991*4882a593Smuzhiyun VIRTUAL-RUNTIME_dev_manager = "udev" 7992*4882a593Smuzhiyun 7993*4882a593Smuzhiyun # Some alternative values 7994*4882a593Smuzhiyun # VIRTUAL-RUNTIME_dev_manager = "busybox-mdev" 7995*4882a593Smuzhiyun # VIRTUAL-RUNTIME_dev_manager = "systemd" 7996*4882a593Smuzhiyun 7997*4882a593SmuzhiyunUsing an External SCM 7998*4882a593Smuzhiyun===================== 7999*4882a593Smuzhiyun 8000*4882a593SmuzhiyunIf you're working on a recipe that pulls from an external Source Code 8001*4882a593SmuzhiyunManager (SCM), it is possible to have the OpenEmbedded build system 8002*4882a593Smuzhiyunnotice new recipe changes added to the SCM and then build the resulting 8003*4882a593Smuzhiyunpackages that depend on the new recipes by using the latest versions. 8004*4882a593SmuzhiyunThis only works for SCMs from which it is possible to get a sensible 8005*4882a593Smuzhiyunrevision number for changes. Currently, you can do this with Apache 8006*4882a593SmuzhiyunSubversion (SVN), Git, and Bazaar (BZR) repositories. 8007*4882a593Smuzhiyun 8008*4882a593SmuzhiyunTo enable this behavior, the :term:`PV` of 8009*4882a593Smuzhiyunthe recipe needs to reference 8010*4882a593Smuzhiyun:term:`SRCPV`. Here is an example:: 8011*4882a593Smuzhiyun 8012*4882a593Smuzhiyun PV = "1.2.3+git${SRCPV}" 8013*4882a593Smuzhiyun 8014*4882a593SmuzhiyunThen, you can add the following to your 8015*4882a593Smuzhiyun``local.conf``:: 8016*4882a593Smuzhiyun 8017*4882a593Smuzhiyun SRCREV:pn-PN = "${AUTOREV}" 8018*4882a593Smuzhiyun 8019*4882a593Smuzhiyun:term:`PN` is the name of the recipe for 8020*4882a593Smuzhiyunwhich you want to enable automatic source revision updating. 8021*4882a593Smuzhiyun 8022*4882a593SmuzhiyunIf you do not want to update your local configuration file, you can add 8023*4882a593Smuzhiyunthe following directly to the recipe to finish enabling the feature:: 8024*4882a593Smuzhiyun 8025*4882a593Smuzhiyun SRCREV = "${AUTOREV}" 8026*4882a593Smuzhiyun 8027*4882a593SmuzhiyunThe Yocto Project provides a distribution named ``poky-bleeding``, whose 8028*4882a593Smuzhiyunconfiguration file contains the line:: 8029*4882a593Smuzhiyun 8030*4882a593Smuzhiyun require conf/distro/include/poky-floating-revisions.inc 8031*4882a593Smuzhiyun 8032*4882a593SmuzhiyunThis line pulls in the 8033*4882a593Smuzhiyunlisted include file that contains numerous lines of exactly that form:: 8034*4882a593Smuzhiyun 8035*4882a593Smuzhiyun #SRCREV:pn-opkg-native ?= "${AUTOREV}" 8036*4882a593Smuzhiyun #SRCREV:pn-opkg-sdk ?= "${AUTOREV}" 8037*4882a593Smuzhiyun #SRCREV:pn-opkg ?= "${AUTOREV}" 8038*4882a593Smuzhiyun #SRCREV:pn-opkg-utils-native ?= "${AUTOREV}" 8039*4882a593Smuzhiyun #SRCREV:pn-opkg-utils ?= "${AUTOREV}" 8040*4882a593Smuzhiyun SRCREV:pn-gconf-dbus ?= "${AUTOREV}" 8041*4882a593Smuzhiyun SRCREV:pn-matchbox-common ?= "${AUTOREV}" 8042*4882a593Smuzhiyun SRCREV:pn-matchbox-config-gtk ?= "${AUTOREV}" 8043*4882a593Smuzhiyun SRCREV:pn-matchbox-desktop ?= "${AUTOREV}" 8044*4882a593Smuzhiyun SRCREV:pn-matchbox-keyboard ?= "${AUTOREV}" 8045*4882a593Smuzhiyun SRCREV:pn-matchbox-panel-2 ?= "${AUTOREV}" 8046*4882a593Smuzhiyun SRCREV:pn-matchbox-themes-extra ?= "${AUTOREV}" 8047*4882a593Smuzhiyun SRCREV:pn-matchbox-terminal ?= "${AUTOREV}" 8048*4882a593Smuzhiyun SRCREV:pn-matchbox-wm ?= "${AUTOREV}" 8049*4882a593Smuzhiyun SRCREV:pn-settings-daemon ?= "${AUTOREV}" 8050*4882a593Smuzhiyun SRCREV:pn-screenshot ?= "${AUTOREV}" 8051*4882a593Smuzhiyun . . . 8052*4882a593Smuzhiyun 8053*4882a593SmuzhiyunThese lines allow you to 8054*4882a593Smuzhiyunexperiment with building a distribution that tracks the latest 8055*4882a593Smuzhiyundevelopment source for numerous packages. 8056*4882a593Smuzhiyun 8057*4882a593Smuzhiyun.. note:: 8058*4882a593Smuzhiyun 8059*4882a593Smuzhiyun The ``poky-bleeding`` distribution is not tested on a regular basis. Keep 8060*4882a593Smuzhiyun this in mind if you use it. 8061*4882a593Smuzhiyun 8062*4882a593SmuzhiyunCreating a Read-Only Root Filesystem 8063*4882a593Smuzhiyun==================================== 8064*4882a593Smuzhiyun 8065*4882a593SmuzhiyunSuppose, for security reasons, you need to disable your target device's 8066*4882a593Smuzhiyunroot filesystem's write permissions (i.e. you need a read-only root 8067*4882a593Smuzhiyunfilesystem). Or, perhaps you are running the device's operating system 8068*4882a593Smuzhiyunfrom a read-only storage device. For either case, you can customize your 8069*4882a593Smuzhiyunimage for that behavior. 8070*4882a593Smuzhiyun 8071*4882a593Smuzhiyun.. note:: 8072*4882a593Smuzhiyun 8073*4882a593Smuzhiyun Supporting a read-only root filesystem requires that the system and 8074*4882a593Smuzhiyun applications do not try to write to the root filesystem. You must 8075*4882a593Smuzhiyun configure all parts of the target system to write elsewhere, or to 8076*4882a593Smuzhiyun gracefully fail in the event of attempting to write to the root 8077*4882a593Smuzhiyun filesystem. 8078*4882a593Smuzhiyun 8079*4882a593SmuzhiyunCreating the Root Filesystem 8080*4882a593Smuzhiyun---------------------------- 8081*4882a593Smuzhiyun 8082*4882a593SmuzhiyunTo create the read-only root filesystem, simply add the 8083*4882a593Smuzhiyun"read-only-rootfs" feature to your image, normally in one of two ways. 8084*4882a593SmuzhiyunThe first way is to add the "read-only-rootfs" image feature in the 8085*4882a593Smuzhiyunimage's recipe file via the :term:`IMAGE_FEATURES` variable:: 8086*4882a593Smuzhiyun 8087*4882a593Smuzhiyun IMAGE_FEATURES += "read-only-rootfs" 8088*4882a593Smuzhiyun 8089*4882a593SmuzhiyunAs an alternative, you can add the same feature 8090*4882a593Smuzhiyunfrom within your build directory's ``local.conf`` file with the 8091*4882a593Smuzhiyunassociated :term:`EXTRA_IMAGE_FEATURES` variable, as in:: 8092*4882a593Smuzhiyun 8093*4882a593Smuzhiyun EXTRA_IMAGE_FEATURES = "read-only-rootfs" 8094*4882a593Smuzhiyun 8095*4882a593SmuzhiyunFor more information on how to use these variables, see the 8096*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:Customizing Images Using Custom \`\`IMAGE_FEATURES\`\` and \`\`EXTRA_IMAGE_FEATURES\`\``" 8097*4882a593Smuzhiyunsection. For information on the variables, see 8098*4882a593Smuzhiyun:term:`IMAGE_FEATURES` and 8099*4882a593Smuzhiyun:term:`EXTRA_IMAGE_FEATURES`. 8100*4882a593Smuzhiyun 8101*4882a593SmuzhiyunPost-Installation Scripts and Read-Only Root Filesystem 8102*4882a593Smuzhiyun------------------------------------------------------- 8103*4882a593Smuzhiyun 8104*4882a593SmuzhiyunIt is very important that you make sure all post-Installation 8105*4882a593Smuzhiyun(``pkg_postinst``) scripts for packages that are installed into the 8106*4882a593Smuzhiyunimage can be run at the time when the root filesystem is created during 8107*4882a593Smuzhiyunthe build on the host system. These scripts cannot attempt to run during 8108*4882a593Smuzhiyunthe first boot on the target device. With the "read-only-rootfs" feature 8109*4882a593Smuzhiyunenabled, the build system makes sure that all post-installation scripts 8110*4882a593Smuzhiyunsucceed at file system creation time. If any of these scripts 8111*4882a593Smuzhiyunstill need to be run after the root filesystem is created, the build 8112*4882a593Smuzhiyunimmediately fails. These build-time checks ensure that the build fails 8113*4882a593Smuzhiyunrather than the target device fails later during its initial boot 8114*4882a593Smuzhiyunoperation. 8115*4882a593Smuzhiyun 8116*4882a593SmuzhiyunMost of the common post-installation scripts generated by the build 8117*4882a593Smuzhiyunsystem for the out-of-the-box Yocto Project are engineered so that they 8118*4882a593Smuzhiyuncan run during root filesystem creation (e.g. post-installation scripts 8119*4882a593Smuzhiyunfor caching fonts). However, if you create and add custom scripts, you 8120*4882a593Smuzhiyunneed to be sure they can be run during this file system creation. 8121*4882a593Smuzhiyun 8122*4882a593SmuzhiyunHere are some common problems that prevent post-installation scripts 8123*4882a593Smuzhiyunfrom running during root filesystem creation: 8124*4882a593Smuzhiyun 8125*4882a593Smuzhiyun- *Not using $D in front of absolute paths:* The build system defines 8126*4882a593Smuzhiyun ``$``\ :term:`D` when the root 8127*4882a593Smuzhiyun filesystem is created. Furthermore, ``$D`` is blank when the script 8128*4882a593Smuzhiyun is run on the target device. This implies two purposes for ``$D``: 8129*4882a593Smuzhiyun ensuring paths are valid in both the host and target environments, 8130*4882a593Smuzhiyun and checking to determine which environment is being used as a method 8131*4882a593Smuzhiyun for taking appropriate actions. 8132*4882a593Smuzhiyun 8133*4882a593Smuzhiyun- *Attempting to run processes that are specific to or dependent on the 8134*4882a593Smuzhiyun target architecture:* You can work around these attempts by using 8135*4882a593Smuzhiyun native tools, which run on the host system, to accomplish the same 8136*4882a593Smuzhiyun tasks, or by alternatively running the processes under QEMU, which 8137*4882a593Smuzhiyun has the ``qemu_run_binary`` function. For more information, see the 8138*4882a593Smuzhiyun :ref:`qemu <ref-classes-qemu>` class. 8139*4882a593Smuzhiyun 8140*4882a593SmuzhiyunAreas With Write Access 8141*4882a593Smuzhiyun----------------------- 8142*4882a593Smuzhiyun 8143*4882a593SmuzhiyunWith the "read-only-rootfs" feature enabled, any attempt by the target 8144*4882a593Smuzhiyunto write to the root filesystem at runtime fails. Consequently, you must 8145*4882a593Smuzhiyunmake sure that you configure processes and applications that attempt 8146*4882a593Smuzhiyunthese types of writes do so to directories with write access (e.g. 8147*4882a593Smuzhiyun``/tmp`` or ``/var/run``). 8148*4882a593Smuzhiyun 8149*4882a593SmuzhiyunMaintaining Build Output Quality 8150*4882a593Smuzhiyun================================ 8151*4882a593Smuzhiyun 8152*4882a593SmuzhiyunMany factors can influence the quality of a build. For example, if you 8153*4882a593Smuzhiyunupgrade a recipe to use a new version of an upstream software package or 8154*4882a593Smuzhiyunyou experiment with some new configuration options, subtle changes can 8155*4882a593Smuzhiyunoccur that you might not detect until later. Consider the case where 8156*4882a593Smuzhiyunyour recipe is using a newer version of an upstream package. In this 8157*4882a593Smuzhiyuncase, a new version of a piece of software might introduce an optional 8158*4882a593Smuzhiyundependency on another library, which is auto-detected. If that library 8159*4882a593Smuzhiyunhas already been built when the software is building, the software will 8160*4882a593Smuzhiyunlink to the built library and that library will be pulled into your 8161*4882a593Smuzhiyunimage along with the new software even if you did not want the library. 8162*4882a593Smuzhiyun 8163*4882a593SmuzhiyunThe :ref:`buildhistory <ref-classes-buildhistory>` 8164*4882a593Smuzhiyunclass helps you maintain the quality of your build output. You 8165*4882a593Smuzhiyuncan use the class to highlight unexpected and possibly unwanted changes 8166*4882a593Smuzhiyunin the build output. When you enable build history, it records 8167*4882a593Smuzhiyuninformation about the contents of each package and image and then 8168*4882a593Smuzhiyuncommits that information to a local Git repository where you can examine 8169*4882a593Smuzhiyunthe information. 8170*4882a593Smuzhiyun 8171*4882a593SmuzhiyunThe remainder of this section describes the following: 8172*4882a593Smuzhiyun 8173*4882a593Smuzhiyun- :ref:`How you can enable and disable build history <dev-manual/common-tasks:enabling and disabling build history>` 8174*4882a593Smuzhiyun 8175*4882a593Smuzhiyun- :ref:`How to understand what the build history contains <dev-manual/common-tasks:understanding what the build history contains>` 8176*4882a593Smuzhiyun 8177*4882a593Smuzhiyun- :ref:`How to limit the information used for build history <dev-manual/common-tasks:using build history to gather image information only>` 8178*4882a593Smuzhiyun 8179*4882a593Smuzhiyun- :ref:`How to examine the build history from both a command-line and web interface <dev-manual/common-tasks:examining build history information>` 8180*4882a593Smuzhiyun 8181*4882a593SmuzhiyunEnabling and Disabling Build History 8182*4882a593Smuzhiyun------------------------------------ 8183*4882a593Smuzhiyun 8184*4882a593SmuzhiyunBuild history is disabled by default. To enable it, add the following 8185*4882a593Smuzhiyun:term:`INHERIT` statement and set the 8186*4882a593Smuzhiyun:term:`BUILDHISTORY_COMMIT` 8187*4882a593Smuzhiyunvariable to "1" at the end of your ``conf/local.conf`` file found in the 8188*4882a593Smuzhiyun:term:`Build Directory`:: 8189*4882a593Smuzhiyun 8190*4882a593Smuzhiyun INHERIT += "buildhistory" 8191*4882a593Smuzhiyun BUILDHISTORY_COMMIT = "1" 8192*4882a593Smuzhiyun 8193*4882a593SmuzhiyunEnabling build history as 8194*4882a593Smuzhiyunpreviously described causes the OpenEmbedded build system to collect 8195*4882a593Smuzhiyunbuild output information and commit it as a single commit to a local 8196*4882a593Smuzhiyun:ref:`overview-manual/development-environment:git` repository. 8197*4882a593Smuzhiyun 8198*4882a593Smuzhiyun.. note:: 8199*4882a593Smuzhiyun 8200*4882a593Smuzhiyun Enabling build history increases your build times slightly, 8201*4882a593Smuzhiyun particularly for images, and increases the amount of disk space used 8202*4882a593Smuzhiyun during the build. 8203*4882a593Smuzhiyun 8204*4882a593SmuzhiyunYou can disable build history by removing the previous statements from 8205*4882a593Smuzhiyunyour ``conf/local.conf`` file. 8206*4882a593Smuzhiyun 8207*4882a593SmuzhiyunUnderstanding What the Build History Contains 8208*4882a593Smuzhiyun--------------------------------------------- 8209*4882a593Smuzhiyun 8210*4882a593SmuzhiyunBuild history information is kept in 8211*4882a593Smuzhiyun``${``\ :term:`TOPDIR`\ ``}/buildhistory`` 8212*4882a593Smuzhiyunin the Build Directory as defined by the 8213*4882a593Smuzhiyun:term:`BUILDHISTORY_DIR` 8214*4882a593Smuzhiyunvariable. Here is an example abbreviated listing: 8215*4882a593Smuzhiyun 8216*4882a593Smuzhiyun.. image:: figures/buildhistory.png 8217*4882a593Smuzhiyun :align: center 8218*4882a593Smuzhiyun 8219*4882a593SmuzhiyunAt the top level, there is a ``metadata-revs`` file that lists the 8220*4882a593Smuzhiyunrevisions of the repositories for the enabled layers when the build was 8221*4882a593Smuzhiyunproduced. The rest of the data splits into separate ``packages``, 8222*4882a593Smuzhiyun``images`` and ``sdk`` directories, the contents of which are described 8223*4882a593Smuzhiyunas follows. 8224*4882a593Smuzhiyun 8225*4882a593SmuzhiyunBuild History Package Information 8226*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8227*4882a593Smuzhiyun 8228*4882a593SmuzhiyunThe history for each package contains a text file that has name-value 8229*4882a593Smuzhiyunpairs with information about the package. For example, 8230*4882a593Smuzhiyun``buildhistory/packages/i586-poky-linux/busybox/busybox/latest`` 8231*4882a593Smuzhiyuncontains the following: 8232*4882a593Smuzhiyun 8233*4882a593Smuzhiyun.. code-block:: none 8234*4882a593Smuzhiyun 8235*4882a593Smuzhiyun PV = 1.22.1 8236*4882a593Smuzhiyun PR = r32 8237*4882a593Smuzhiyun RPROVIDES = 8238*4882a593Smuzhiyun RDEPENDS = glibc (>= 2.20) update-alternatives-opkg 8239*4882a593Smuzhiyun RRECOMMENDS = busybox-syslog busybox-udhcpc update-rc.d 8240*4882a593Smuzhiyun PKGSIZE = 540168 8241*4882a593Smuzhiyun FILES = /usr/bin/* /usr/sbin/* /usr/lib/busybox/* /usr/lib/lib*.so.* \ 8242*4882a593Smuzhiyun /etc /com /var /bin/* /sbin/* /lib/*.so.* /lib/udev/rules.d \ 8243*4882a593Smuzhiyun /usr/lib/udev/rules.d /usr/share/busybox /usr/lib/busybox/* \ 8244*4882a593Smuzhiyun /usr/share/pixmaps /usr/share/applications /usr/share/idl \ 8245*4882a593Smuzhiyun /usr/share/omf /usr/share/sounds /usr/lib/bonobo/servers 8246*4882a593Smuzhiyun FILELIST = /bin/busybox /bin/busybox.nosuid /bin/busybox.suid /bin/sh \ 8247*4882a593Smuzhiyun /etc/busybox.links.nosuid /etc/busybox.links.suid 8248*4882a593Smuzhiyun 8249*4882a593SmuzhiyunMost of these 8250*4882a593Smuzhiyunname-value pairs correspond to variables used to produce the package. 8251*4882a593SmuzhiyunThe exceptions are ``FILELIST``, which is the actual list of files in 8252*4882a593Smuzhiyunthe package, and ``PKGSIZE``, which is the total size of files in the 8253*4882a593Smuzhiyunpackage in bytes. 8254*4882a593Smuzhiyun 8255*4882a593SmuzhiyunThere is also a file that corresponds to the recipe from which the package 8256*4882a593Smuzhiyuncame (e.g. ``buildhistory/packages/i586-poky-linux/busybox/latest``): 8257*4882a593Smuzhiyun 8258*4882a593Smuzhiyun.. code-block:: none 8259*4882a593Smuzhiyun 8260*4882a593Smuzhiyun PV = 1.22.1 8261*4882a593Smuzhiyun PR = r32 8262*4882a593Smuzhiyun DEPENDS = initscripts kern-tools-native update-rc.d-native \ 8263*4882a593Smuzhiyun virtual/i586-poky-linux-compilerlibs virtual/i586-poky-linux-gcc \ 8264*4882a593Smuzhiyun virtual/libc virtual/update-alternatives 8265*4882a593Smuzhiyun PACKAGES = busybox-ptest busybox-httpd busybox-udhcpd busybox-udhcpc \ 8266*4882a593Smuzhiyun busybox-syslog busybox-mdev busybox-hwclock busybox-dbg \ 8267*4882a593Smuzhiyun busybox-staticdev busybox-dev busybox-doc busybox-locale busybox 8268*4882a593Smuzhiyun 8269*4882a593SmuzhiyunFinally, for those recipes fetched from a version control system (e.g., 8270*4882a593SmuzhiyunGit), there is a file that lists source revisions that are specified in 8271*4882a593Smuzhiyunthe recipe and the actual revisions used during the build. Listed 8272*4882a593Smuzhiyunand actual revisions might differ when 8273*4882a593Smuzhiyun:term:`SRCREV` is set to 8274*4882a593Smuzhiyun${:term:`AUTOREV`}. Here is an 8275*4882a593Smuzhiyunexample assuming 8276*4882a593Smuzhiyun``buildhistory/packages/qemux86-poky-linux/linux-yocto/latest_srcrev``):: 8277*4882a593Smuzhiyun 8278*4882a593Smuzhiyun # SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" 8279*4882a593Smuzhiyun SRCREV_machine = "38cd560d5022ed2dbd1ab0dca9642e47c98a0aa1" 8280*4882a593Smuzhiyun # SRCREV_meta = "a227f20eff056e511d504b2e490f3774ab260d6f" 8281*4882a593Smuzhiyun SRCREV_meta ="a227f20eff056e511d504b2e490f3774ab260d6f" 8282*4882a593Smuzhiyun 8283*4882a593SmuzhiyunYou can use the 8284*4882a593Smuzhiyun``buildhistory-collect-srcrevs`` command with the ``-a`` option to 8285*4882a593Smuzhiyuncollect the stored :term:`SRCREV` values from build history and report them 8286*4882a593Smuzhiyunin a format suitable for use in global configuration (e.g., 8287*4882a593Smuzhiyun``local.conf`` or a distro include file) to override floating 8288*4882a593Smuzhiyun:term:`AUTOREV` values to a fixed set of revisions. Here is some example 8289*4882a593Smuzhiyunoutput from this command:: 8290*4882a593Smuzhiyun 8291*4882a593Smuzhiyun $ buildhistory-collect-srcrevs -a 8292*4882a593Smuzhiyun # all-poky-linux 8293*4882a593Smuzhiyun SRCREV:pn-ca-certificates = "07de54fdcc5806bde549e1edf60738c6bccf50e8" 8294*4882a593Smuzhiyun SRCREV:pn-update-rc.d = "8636cf478d426b568c1be11dbd9346f67e03adac" 8295*4882a593Smuzhiyun # core2-64-poky-linux 8296*4882a593Smuzhiyun SRCREV:pn-binutils = "87d4632d36323091e731eb07b8aa65f90293da66" 8297*4882a593Smuzhiyun SRCREV:pn-btrfs-tools = "8ad326b2f28c044cb6ed9016d7c3285e23b673c8" 8298*4882a593Smuzhiyun SRCREV_bzip2-tests:pn-bzip2 = "f9061c030a25de5b6829e1abf373057309c734c0" 8299*4882a593Smuzhiyun SRCREV:pn-e2fsprogs = "02540dedd3ddc52c6ae8aaa8a95ce75c3f8be1c0" 8300*4882a593Smuzhiyun SRCREV:pn-file = "504206e53a89fd6eed71aeaf878aa3512418eab1" 8301*4882a593Smuzhiyun SRCREV_glibc:pn-glibc = "24962427071fa532c3c48c918e9d64d719cc8a6c" 8302*4882a593Smuzhiyun SRCREV:pn-gnome-desktop-testing = "e346cd4ed2e2102c9b195b614f3c642d23f5f6e7" 8303*4882a593Smuzhiyun SRCREV:pn-init-system-helpers = "dbd9197569c0935029acd5c9b02b84c68fd937ee" 8304*4882a593Smuzhiyun SRCREV:pn-kmod = "b6ecfc916a17eab8f93be5b09f4e4f845aabd3d1" 8305*4882a593Smuzhiyun SRCREV:pn-libnsl2 = "82245c0c58add79a8e34ab0917358217a70e5100" 8306*4882a593Smuzhiyun SRCREV:pn-libseccomp = "57357d2741a3b3d3e8425889a6b79a130e0fa2f3" 8307*4882a593Smuzhiyun SRCREV:pn-libxcrypt = "50cf2b6dd4fdf04309445f2eec8de7051d953abf" 8308*4882a593Smuzhiyun SRCREV:pn-ncurses = "51d0fd9cc3edb975f04224f29f777f8f448e8ced" 8309*4882a593Smuzhiyun SRCREV:pn-procps = "19a508ea121c0c4ac6d0224575a036de745eaaf8" 8310*4882a593Smuzhiyun SRCREV:pn-psmisc = "5fab6b7ab385080f1db725d6803136ec1841a15f" 8311*4882a593Smuzhiyun SRCREV:pn-ptest-runner = "bcb82804daa8f725b6add259dcef2067e61a75aa" 8312*4882a593Smuzhiyun SRCREV:pn-shared-mime-info = "18e558fa1c8b90b86757ade09a4ba4d6a6cf8f70" 8313*4882a593Smuzhiyun SRCREV:pn-zstd = "e47e674cd09583ff0503f0f6defd6d23d8b718d3" 8314*4882a593Smuzhiyun # qemux86_64-poky-linux 8315*4882a593Smuzhiyun SRCREV_machine:pn-linux-yocto = "20301aeb1a64164b72bc72af58802b315e025c9c" 8316*4882a593Smuzhiyun SRCREV_meta:pn-linux-yocto = "2d38a472b21ae343707c8bd64ac68a9eaca066a0" 8317*4882a593Smuzhiyun # x86_64-linux 8318*4882a593Smuzhiyun SRCREV:pn-binutils-cross-x86_64 = "87d4632d36323091e731eb07b8aa65f90293da66" 8319*4882a593Smuzhiyun SRCREV_glibc:pn-cross-localedef-native = "24962427071fa532c3c48c918e9d64d719cc8a6c" 8320*4882a593Smuzhiyun SRCREV_localedef:pn-cross-localedef-native = "794da69788cbf9bf57b59a852f9f11307663fa87" 8321*4882a593Smuzhiyun SRCREV:pn-debianutils-native = "de14223e5bffe15e374a441302c528ffc1cbed57" 8322*4882a593Smuzhiyun SRCREV:pn-libmodulemd-native = "ee80309bc766d781a144e6879419b29f444d94eb" 8323*4882a593Smuzhiyun SRCREV:pn-virglrenderer-native = "363915595e05fb252e70d6514be2f0c0b5ca312b" 8324*4882a593Smuzhiyun SRCREV:pn-zstd-native = "e47e674cd09583ff0503f0f6defd6d23d8b718d3" 8325*4882a593Smuzhiyun 8326*4882a593Smuzhiyun.. note:: 8327*4882a593Smuzhiyun 8328*4882a593Smuzhiyun Here are some notes on using the ``buildhistory-collect-srcrevs`` command: 8329*4882a593Smuzhiyun 8330*4882a593Smuzhiyun - By default, only values where the :term:`SRCREV` was not hardcoded 8331*4882a593Smuzhiyun (usually when :term:`AUTOREV` is used) are reported. Use the ``-a`` 8332*4882a593Smuzhiyun option to see all :term:`SRCREV` values. 8333*4882a593Smuzhiyun 8334*4882a593Smuzhiyun - The output statements might not have any effect if overrides are 8335*4882a593Smuzhiyun applied elsewhere in the build system configuration. Use the 8336*4882a593Smuzhiyun ``-f`` option to add the ``forcevariable`` override to each output 8337*4882a593Smuzhiyun line if you need to work around this restriction. 8338*4882a593Smuzhiyun 8339*4882a593Smuzhiyun - The script does apply special handling when building for multiple 8340*4882a593Smuzhiyun machines. However, the script does place a comment before each set 8341*4882a593Smuzhiyun of values that specifies which triplet to which they belong as 8342*4882a593Smuzhiyun previously shown (e.g., ``i586-poky-linux``). 8343*4882a593Smuzhiyun 8344*4882a593SmuzhiyunBuild History Image Information 8345*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8346*4882a593Smuzhiyun 8347*4882a593SmuzhiyunThe files produced for each image are as follows: 8348*4882a593Smuzhiyun 8349*4882a593Smuzhiyun- ``image-files:`` A directory containing selected files from the root 8350*4882a593Smuzhiyun filesystem. The files are defined by 8351*4882a593Smuzhiyun :term:`BUILDHISTORY_IMAGE_FILES`. 8352*4882a593Smuzhiyun 8353*4882a593Smuzhiyun- ``build-id.txt:`` Human-readable information about the build 8354*4882a593Smuzhiyun configuration and metadata source revisions. This file contains the 8355*4882a593Smuzhiyun full build header as printed by BitBake. 8356*4882a593Smuzhiyun 8357*4882a593Smuzhiyun- ``*.dot:`` Dependency graphs for the image that are compatible with 8358*4882a593Smuzhiyun ``graphviz``. 8359*4882a593Smuzhiyun 8360*4882a593Smuzhiyun- ``files-in-image.txt:`` A list of files in the image with 8361*4882a593Smuzhiyun permissions, owner, group, size, and symlink information. 8362*4882a593Smuzhiyun 8363*4882a593Smuzhiyun- ``image-info.txt:`` A text file containing name-value pairs with 8364*4882a593Smuzhiyun information about the image. See the following listing example for 8365*4882a593Smuzhiyun more information. 8366*4882a593Smuzhiyun 8367*4882a593Smuzhiyun- ``installed-package-names.txt:`` A list of installed packages by name 8368*4882a593Smuzhiyun only. 8369*4882a593Smuzhiyun 8370*4882a593Smuzhiyun- ``installed-package-sizes.txt:`` A list of installed packages ordered 8371*4882a593Smuzhiyun by size. 8372*4882a593Smuzhiyun 8373*4882a593Smuzhiyun- ``installed-packages.txt:`` A list of installed packages with full 8374*4882a593Smuzhiyun package filenames. 8375*4882a593Smuzhiyun 8376*4882a593Smuzhiyun.. note:: 8377*4882a593Smuzhiyun 8378*4882a593Smuzhiyun Installed package information is able to be gathered and produced 8379*4882a593Smuzhiyun even if package management is disabled for the final image. 8380*4882a593Smuzhiyun 8381*4882a593SmuzhiyunHere is an example of ``image-info.txt``: 8382*4882a593Smuzhiyun 8383*4882a593Smuzhiyun.. code-block:: none 8384*4882a593Smuzhiyun 8385*4882a593Smuzhiyun DISTRO = poky 8386*4882a593Smuzhiyun DISTRO_VERSION = 3.4+snapshot-a0245d7be08f3d24ea1875e9f8872aa6bbff93be 8387*4882a593Smuzhiyun USER_CLASSES = buildstats 8388*4882a593Smuzhiyun IMAGE_CLASSES = qemuboot qemuboot license_image 8389*4882a593Smuzhiyun IMAGE_FEATURES = debug-tweaks 8390*4882a593Smuzhiyun IMAGE_LINGUAS = 8391*4882a593Smuzhiyun IMAGE_INSTALL = packagegroup-core-boot speex speexdsp 8392*4882a593Smuzhiyun BAD_RECOMMENDATIONS = 8393*4882a593Smuzhiyun NO_RECOMMENDATIONS = 8394*4882a593Smuzhiyun PACKAGE_EXCLUDE = 8395*4882a593Smuzhiyun ROOTFS_POSTPROCESS_COMMAND = write_package_manifest; license_create_manifest; cve_check_write_rootfs_manifest; ssh_allow_empty_password; ssh_allow_root_login; postinst_enable_logging; rootfs_update_timestamp; write_image_test_data; empty_var_volatile; sort_passwd; rootfs_reproducible; 8396*4882a593Smuzhiyun IMAGE_POSTPROCESS_COMMAND = buildhistory_get_imageinfo ; 8397*4882a593Smuzhiyun IMAGESIZE = 9265 8398*4882a593Smuzhiyun 8399*4882a593SmuzhiyunOther than ``IMAGESIZE``, 8400*4882a593Smuzhiyunwhich is the total size of the files in the image in Kbytes, the 8401*4882a593Smuzhiyunname-value pairs are variables that may have influenced the content of 8402*4882a593Smuzhiyunthe image. This information is often useful when you are trying to 8403*4882a593Smuzhiyundetermine why a change in the package or file listings has occurred. 8404*4882a593Smuzhiyun 8405*4882a593SmuzhiyunUsing Build History to Gather Image Information Only 8406*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8407*4882a593Smuzhiyun 8408*4882a593SmuzhiyunAs you can see, build history produces image information, including 8409*4882a593Smuzhiyundependency graphs, so you can see why something was pulled into the 8410*4882a593Smuzhiyunimage. If you are just interested in this information and not interested 8411*4882a593Smuzhiyunin collecting specific package or SDK information, you can enable 8412*4882a593Smuzhiyunwriting only image information without any history by adding the 8413*4882a593Smuzhiyunfollowing to your ``conf/local.conf`` file found in the 8414*4882a593Smuzhiyun:term:`Build Directory`:: 8415*4882a593Smuzhiyun 8416*4882a593Smuzhiyun INHERIT += "buildhistory" 8417*4882a593Smuzhiyun BUILDHISTORY_COMMIT = "0" 8418*4882a593Smuzhiyun BUILDHISTORY_FEATURES = "image" 8419*4882a593Smuzhiyun 8420*4882a593SmuzhiyunHere, you set the 8421*4882a593Smuzhiyun:term:`BUILDHISTORY_FEATURES` 8422*4882a593Smuzhiyunvariable to use the image feature only. 8423*4882a593Smuzhiyun 8424*4882a593SmuzhiyunBuild History SDK Information 8425*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8426*4882a593Smuzhiyun 8427*4882a593SmuzhiyunBuild history collects similar information on the contents of SDKs (e.g. 8428*4882a593Smuzhiyun``bitbake -c populate_sdk imagename``) as compared to information it 8429*4882a593Smuzhiyuncollects for images. Furthermore, this information differs depending on 8430*4882a593Smuzhiyunwhether an extensible or standard SDK is being produced. 8431*4882a593Smuzhiyun 8432*4882a593SmuzhiyunThe following list shows the files produced for SDKs: 8433*4882a593Smuzhiyun 8434*4882a593Smuzhiyun- ``files-in-sdk.txt:`` A list of files in the SDK with permissions, 8435*4882a593Smuzhiyun owner, group, size, and symlink information. This list includes both 8436*4882a593Smuzhiyun the host and target parts of the SDK. 8437*4882a593Smuzhiyun 8438*4882a593Smuzhiyun- ``sdk-info.txt:`` A text file containing name-value pairs with 8439*4882a593Smuzhiyun information about the SDK. See the following listing example for more 8440*4882a593Smuzhiyun information. 8441*4882a593Smuzhiyun 8442*4882a593Smuzhiyun- ``sstate-task-sizes.txt:`` A text file containing name-value pairs 8443*4882a593Smuzhiyun with information about task group sizes (e.g. ``do_populate_sysroot`` 8444*4882a593Smuzhiyun tasks have a total size). The ``sstate-task-sizes.txt`` file exists 8445*4882a593Smuzhiyun only when an extensible SDK is created. 8446*4882a593Smuzhiyun 8447*4882a593Smuzhiyun- ``sstate-package-sizes.txt:`` A text file containing name-value pairs 8448*4882a593Smuzhiyun with information for the shared-state packages and sizes in the SDK. 8449*4882a593Smuzhiyun The ``sstate-package-sizes.txt`` file exists only when an extensible 8450*4882a593Smuzhiyun SDK is created. 8451*4882a593Smuzhiyun 8452*4882a593Smuzhiyun- ``sdk-files:`` A folder that contains copies of the files mentioned 8453*4882a593Smuzhiyun in ``BUILDHISTORY_SDK_FILES`` if the files are present in the output. 8454*4882a593Smuzhiyun Additionally, the default value of ``BUILDHISTORY_SDK_FILES`` is 8455*4882a593Smuzhiyun specific to the extensible SDK although you can set it differently if 8456*4882a593Smuzhiyun you would like to pull in specific files from the standard SDK. 8457*4882a593Smuzhiyun 8458*4882a593Smuzhiyun The default files are ``conf/local.conf``, ``conf/bblayers.conf``, 8459*4882a593Smuzhiyun ``conf/auto.conf``, ``conf/locked-sigs.inc``, and 8460*4882a593Smuzhiyun ``conf/devtool.conf``. Thus, for an extensible SDK, these files get 8461*4882a593Smuzhiyun copied into the ``sdk-files`` directory. 8462*4882a593Smuzhiyun 8463*4882a593Smuzhiyun- The following information appears under each of the ``host`` and 8464*4882a593Smuzhiyun ``target`` directories for the portions of the SDK that run on the 8465*4882a593Smuzhiyun host and on the target, respectively: 8466*4882a593Smuzhiyun 8467*4882a593Smuzhiyun .. note:: 8468*4882a593Smuzhiyun 8469*4882a593Smuzhiyun The following files for the most part are empty when producing an 8470*4882a593Smuzhiyun extensible SDK because this type of SDK is not constructed from 8471*4882a593Smuzhiyun packages as is the standard SDK. 8472*4882a593Smuzhiyun 8473*4882a593Smuzhiyun - ``depends.dot:`` Dependency graph for the SDK that is compatible 8474*4882a593Smuzhiyun with ``graphviz``. 8475*4882a593Smuzhiyun 8476*4882a593Smuzhiyun - ``installed-package-names.txt:`` A list of installed packages by 8477*4882a593Smuzhiyun name only. 8478*4882a593Smuzhiyun 8479*4882a593Smuzhiyun - ``installed-package-sizes.txt:`` A list of installed packages 8480*4882a593Smuzhiyun ordered by size. 8481*4882a593Smuzhiyun 8482*4882a593Smuzhiyun - ``installed-packages.txt:`` A list of installed packages with full 8483*4882a593Smuzhiyun package filenames. 8484*4882a593Smuzhiyun 8485*4882a593SmuzhiyunHere is an example of ``sdk-info.txt``: 8486*4882a593Smuzhiyun 8487*4882a593Smuzhiyun.. code-block:: none 8488*4882a593Smuzhiyun 8489*4882a593Smuzhiyun DISTRO = poky 8490*4882a593Smuzhiyun DISTRO_VERSION = 1.3+snapshot-20130327 8491*4882a593Smuzhiyun SDK_NAME = poky-glibc-i686-arm 8492*4882a593Smuzhiyun SDK_VERSION = 1.3+snapshot 8493*4882a593Smuzhiyun SDKMACHINE = 8494*4882a593Smuzhiyun SDKIMAGE_FEATURES = dev-pkgs dbg-pkgs 8495*4882a593Smuzhiyun BAD_RECOMMENDATIONS = 8496*4882a593Smuzhiyun SDKSIZE = 352712 8497*4882a593Smuzhiyun 8498*4882a593SmuzhiyunOther than ``SDKSIZE``, which is 8499*4882a593Smuzhiyunthe total size of the files in the SDK in Kbytes, the name-value pairs 8500*4882a593Smuzhiyunare variables that might have influenced the content of the SDK. This 8501*4882a593Smuzhiyuninformation is often useful when you are trying to determine why a 8502*4882a593Smuzhiyunchange in the package or file listings has occurred. 8503*4882a593Smuzhiyun 8504*4882a593SmuzhiyunExamining Build History Information 8505*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8506*4882a593Smuzhiyun 8507*4882a593SmuzhiyunYou can examine build history output from the command line or from a web 8508*4882a593Smuzhiyuninterface. 8509*4882a593Smuzhiyun 8510*4882a593SmuzhiyunTo see any changes that have occurred (assuming you have 8511*4882a593Smuzhiyun:term:`BUILDHISTORY_COMMIT` = "1"), 8512*4882a593Smuzhiyunyou can simply use any Git command that allows you to view the history 8513*4882a593Smuzhiyunof a repository. Here is one method:: 8514*4882a593Smuzhiyun 8515*4882a593Smuzhiyun $ git log -p 8516*4882a593Smuzhiyun 8517*4882a593SmuzhiyunYou need to realize, 8518*4882a593Smuzhiyunhowever, that this method does show changes that are not significant 8519*4882a593Smuzhiyun(e.g. a package's size changing by a few bytes). 8520*4882a593Smuzhiyun 8521*4882a593SmuzhiyunThere is a command-line tool called ``buildhistory-diff``, though, 8522*4882a593Smuzhiyunthat queries the Git repository and prints just the differences that 8523*4882a593Smuzhiyunmight be significant in human-readable form. Here is an example:: 8524*4882a593Smuzhiyun 8525*4882a593Smuzhiyun $ poky/poky/scripts/buildhistory-diff . HEAD^ 8526*4882a593Smuzhiyun Changes to images/qemux86_64/glibc/core-image-minimal (files-in-image.txt): 8527*4882a593Smuzhiyun /etc/anotherpkg.conf was added 8528*4882a593Smuzhiyun /sbin/anotherpkg was added 8529*4882a593Smuzhiyun * (installed-package-names.txt): 8530*4882a593Smuzhiyun * anotherpkg was added 8531*4882a593Smuzhiyun Changes to images/qemux86_64/glibc/core-image-minimal (installed-package-names.txt): 8532*4882a593Smuzhiyun anotherpkg was added 8533*4882a593Smuzhiyun packages/qemux86_64-poky-linux/v86d: PACKAGES: added "v86d-extras" 8534*4882a593Smuzhiyun * PR changed from "r0" to "r1" 8535*4882a593Smuzhiyun * PV changed from "0.1.10" to "0.1.12" 8536*4882a593Smuzhiyun packages/qemux86_64-poky-linux/v86d/v86d: PKGSIZE changed from 110579 to 144381 (+30%) 8537*4882a593Smuzhiyun * PR changed from "r0" to "r1" 8538*4882a593Smuzhiyun * PV changed from "0.1.10" to "0.1.12" 8539*4882a593Smuzhiyun 8540*4882a593Smuzhiyun.. note:: 8541*4882a593Smuzhiyun 8542*4882a593Smuzhiyun The ``buildhistory-diff`` tool requires the ``GitPython`` 8543*4882a593Smuzhiyun package. Be sure to install it using Pip3 as follows:: 8544*4882a593Smuzhiyun 8545*4882a593Smuzhiyun $ pip3 install GitPython --user 8546*4882a593Smuzhiyun 8547*4882a593Smuzhiyun 8548*4882a593Smuzhiyun Alternatively, you can install ``python3-git`` using the appropriate 8549*4882a593Smuzhiyun distribution package manager (e.g. ``apt``, ``dnf``, or ``zipper``). 8550*4882a593Smuzhiyun 8551*4882a593SmuzhiyunTo see changes to the build history using a web interface, follow the 8552*4882a593Smuzhiyuninstruction in the ``README`` file 8553*4882a593Smuzhiyun:yocto_git:`here </buildhistory-web/>`. 8554*4882a593Smuzhiyun 8555*4882a593SmuzhiyunHere is a sample screenshot of the interface: 8556*4882a593Smuzhiyun 8557*4882a593Smuzhiyun.. image:: figures/buildhistory-web.png 8558*4882a593Smuzhiyun :align: center 8559*4882a593Smuzhiyun 8560*4882a593SmuzhiyunPerforming Automated Runtime Testing 8561*4882a593Smuzhiyun==================================== 8562*4882a593Smuzhiyun 8563*4882a593SmuzhiyunThe OpenEmbedded build system makes available a series of automated 8564*4882a593Smuzhiyuntests for images to verify runtime functionality. You can run these 8565*4882a593Smuzhiyuntests on either QEMU or actual target hardware. Tests are written in 8566*4882a593SmuzhiyunPython making use of the ``unittest`` module, and the majority of them 8567*4882a593Smuzhiyunrun commands on the target system over SSH. This section describes how 8568*4882a593Smuzhiyunyou set up the environment to use these tests, run available tests, and 8569*4882a593Smuzhiyunwrite and add your own tests. 8570*4882a593Smuzhiyun 8571*4882a593SmuzhiyunFor information on the test and QA infrastructure available within the 8572*4882a593SmuzhiyunYocto Project, see the ":ref:`ref-manual/release-process:testing and quality assurance`" 8573*4882a593Smuzhiyunsection in the Yocto Project Reference Manual. 8574*4882a593Smuzhiyun 8575*4882a593SmuzhiyunEnabling Tests 8576*4882a593Smuzhiyun-------------- 8577*4882a593Smuzhiyun 8578*4882a593SmuzhiyunDepending on whether you are planning to run tests using QEMU or on the 8579*4882a593Smuzhiyunhardware, you have to take different steps to enable the tests. See the 8580*4882a593Smuzhiyunfollowing subsections for information on how to enable both types of 8581*4882a593Smuzhiyuntests. 8582*4882a593Smuzhiyun 8583*4882a593SmuzhiyunEnabling Runtime Tests on QEMU 8584*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8585*4882a593Smuzhiyun 8586*4882a593SmuzhiyunIn order to run tests, you need to do the following: 8587*4882a593Smuzhiyun 8588*4882a593Smuzhiyun- *Set up to avoid interaction with sudo for networking:* To 8589*4882a593Smuzhiyun accomplish this, you must do one of the following: 8590*4882a593Smuzhiyun 8591*4882a593Smuzhiyun - Add ``NOPASSWD`` for your user in ``/etc/sudoers`` either for all 8592*4882a593Smuzhiyun commands or just for ``runqemu-ifup``. You must provide the full 8593*4882a593Smuzhiyun path as that can change if you are using multiple clones of the 8594*4882a593Smuzhiyun source repository. 8595*4882a593Smuzhiyun 8596*4882a593Smuzhiyun .. note:: 8597*4882a593Smuzhiyun 8598*4882a593Smuzhiyun On some distributions, you also need to comment out "Defaults 8599*4882a593Smuzhiyun requiretty" in ``/etc/sudoers``. 8600*4882a593Smuzhiyun 8601*4882a593Smuzhiyun - Manually configure a tap interface for your system. 8602*4882a593Smuzhiyun 8603*4882a593Smuzhiyun - Run as root the script in ``scripts/runqemu-gen-tapdevs``, which 8604*4882a593Smuzhiyun should generate a list of tap devices. This is the option 8605*4882a593Smuzhiyun typically chosen for Autobuilder-type environments. 8606*4882a593Smuzhiyun 8607*4882a593Smuzhiyun .. note:: 8608*4882a593Smuzhiyun 8609*4882a593Smuzhiyun - Be sure to use an absolute path when calling this script 8610*4882a593Smuzhiyun with sudo. 8611*4882a593Smuzhiyun 8612*4882a593Smuzhiyun - The package recipe ``qemu-helper-native`` is required to run 8613*4882a593Smuzhiyun this script. Build the package using the following command:: 8614*4882a593Smuzhiyun 8615*4882a593Smuzhiyun $ bitbake qemu-helper-native 8616*4882a593Smuzhiyun 8617*4882a593Smuzhiyun- *Set the DISPLAY variable:* You need to set this variable so that 8618*4882a593Smuzhiyun you have an X server available (e.g. start ``vncserver`` for a 8619*4882a593Smuzhiyun headless machine). 8620*4882a593Smuzhiyun 8621*4882a593Smuzhiyun- *Be sure your host's firewall accepts incoming connections from 8622*4882a593Smuzhiyun 192.168.7.0/24:* Some of the tests (in particular DNF tests) start an 8623*4882a593Smuzhiyun HTTP server on a random high number port, which is used to serve 8624*4882a593Smuzhiyun files to the target. The DNF module serves 8625*4882a593Smuzhiyun ``${WORKDIR}/oe-rootfs-repo`` so it can run DNF channel commands. 8626*4882a593Smuzhiyun That means your host's firewall must accept incoming connections from 8627*4882a593Smuzhiyun 192.168.7.0/24, which is the default IP range used for tap devices by 8628*4882a593Smuzhiyun ``runqemu``. 8629*4882a593Smuzhiyun 8630*4882a593Smuzhiyun- *Be sure your host has the correct packages installed:* Depending 8631*4882a593Smuzhiyun your host's distribution, you need to have the following packages 8632*4882a593Smuzhiyun installed: 8633*4882a593Smuzhiyun 8634*4882a593Smuzhiyun - Ubuntu and Debian: ``sysstat`` and ``iproute2`` 8635*4882a593Smuzhiyun 8636*4882a593Smuzhiyun - openSUSE: ``sysstat`` and ``iproute2`` 8637*4882a593Smuzhiyun 8638*4882a593Smuzhiyun - Fedora: ``sysstat`` and ``iproute`` 8639*4882a593Smuzhiyun 8640*4882a593Smuzhiyun - CentOS: ``sysstat`` and ``iproute`` 8641*4882a593Smuzhiyun 8642*4882a593SmuzhiyunOnce you start running the tests, the following happens: 8643*4882a593Smuzhiyun 8644*4882a593Smuzhiyun1. A copy of the root filesystem is written to ``${WORKDIR}/testimage``. 8645*4882a593Smuzhiyun 8646*4882a593Smuzhiyun2. The image is booted under QEMU using the standard ``runqemu`` script. 8647*4882a593Smuzhiyun 8648*4882a593Smuzhiyun3. A default timeout of 500 seconds occurs to allow for the boot process 8649*4882a593Smuzhiyun to reach the login prompt. You can change the timeout period by 8650*4882a593Smuzhiyun setting 8651*4882a593Smuzhiyun :term:`TEST_QEMUBOOT_TIMEOUT` 8652*4882a593Smuzhiyun in the ``local.conf`` file. 8653*4882a593Smuzhiyun 8654*4882a593Smuzhiyun4. Once the boot process is reached and the login prompt appears, the 8655*4882a593Smuzhiyun tests run. The full boot log is written to 8656*4882a593Smuzhiyun ``${WORKDIR}/testimage/qemu_boot_log``. 8657*4882a593Smuzhiyun 8658*4882a593Smuzhiyun5. Each test module loads in the order found in :term:`TEST_SUITES`. You can 8659*4882a593Smuzhiyun find the full output of the commands run over SSH in 8660*4882a593Smuzhiyun ``${WORKDIR}/testimgage/ssh_target_log``. 8661*4882a593Smuzhiyun 8662*4882a593Smuzhiyun6. If no failures occur, the task running the tests ends successfully. 8663*4882a593Smuzhiyun You can find the output from the ``unittest`` in the task log at 8664*4882a593Smuzhiyun ``${WORKDIR}/temp/log.do_testimage``. 8665*4882a593Smuzhiyun 8666*4882a593SmuzhiyunEnabling Runtime Tests on Hardware 8667*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8668*4882a593Smuzhiyun 8669*4882a593SmuzhiyunThe OpenEmbedded build system can run tests on real hardware, and for 8670*4882a593Smuzhiyuncertain devices it can also deploy the image to be tested onto the 8671*4882a593Smuzhiyundevice beforehand. 8672*4882a593Smuzhiyun 8673*4882a593SmuzhiyunFor automated deployment, a "controller image" is installed onto the 8674*4882a593Smuzhiyunhardware once as part of setup. Then, each time tests are to be run, the 8675*4882a593Smuzhiyunfollowing occurs: 8676*4882a593Smuzhiyun 8677*4882a593Smuzhiyun1. The controller image is booted into and used to write the image to be 8678*4882a593Smuzhiyun tested to a second partition. 8679*4882a593Smuzhiyun 8680*4882a593Smuzhiyun2. The device is then rebooted using an external script that you need to 8681*4882a593Smuzhiyun provide. 8682*4882a593Smuzhiyun 8683*4882a593Smuzhiyun3. The device boots into the image to be tested. 8684*4882a593Smuzhiyun 8685*4882a593SmuzhiyunWhen running tests (independent of whether the image has been deployed 8686*4882a593Smuzhiyunautomatically or not), the device is expected to be connected to a 8687*4882a593Smuzhiyunnetwork on a pre-determined IP address. You can either use static IP 8688*4882a593Smuzhiyunaddresses written into the image, or set the image to use DHCP and have 8689*4882a593Smuzhiyunyour DHCP server on the test network assign a known IP address based on 8690*4882a593Smuzhiyunthe MAC address of the device. 8691*4882a593Smuzhiyun 8692*4882a593SmuzhiyunIn order to run tests on hardware, you need to set :term:`TEST_TARGET` to an 8693*4882a593Smuzhiyunappropriate value. For QEMU, you do not have to change anything, the 8694*4882a593Smuzhiyundefault value is "qemu". For running tests on hardware, the following 8695*4882a593Smuzhiyunoptions are available: 8696*4882a593Smuzhiyun 8697*4882a593Smuzhiyun- *"simpleremote":* Choose "simpleremote" if you are going to run tests 8698*4882a593Smuzhiyun on a target system that is already running the image to be tested and 8699*4882a593Smuzhiyun is available on the network. You can use "simpleremote" in 8700*4882a593Smuzhiyun conjunction with either real hardware or an image running within a 8701*4882a593Smuzhiyun separately started QEMU or any other virtual machine manager. 8702*4882a593Smuzhiyun 8703*4882a593Smuzhiyun- *"SystemdbootTarget":* Choose "SystemdbootTarget" if your hardware is 8704*4882a593Smuzhiyun an EFI-based machine with ``systemd-boot`` as bootloader and 8705*4882a593Smuzhiyun ``core-image-testmaster`` (or something similar) is installed. Also, 8706*4882a593Smuzhiyun your hardware under test must be in a DHCP-enabled network that gives 8707*4882a593Smuzhiyun it the same IP address for each reboot. 8708*4882a593Smuzhiyun 8709*4882a593Smuzhiyun If you choose "SystemdbootTarget", there are additional requirements 8710*4882a593Smuzhiyun and considerations. See the 8711*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:selecting systemdboottarget`" section, which 8712*4882a593Smuzhiyun follows, for more information. 8713*4882a593Smuzhiyun 8714*4882a593Smuzhiyun- *"BeagleBoneTarget":* Choose "BeagleBoneTarget" if you are deploying 8715*4882a593Smuzhiyun images and running tests on the BeagleBone "Black" or original 8716*4882a593Smuzhiyun "White" hardware. For information on how to use these tests, see the 8717*4882a593Smuzhiyun comments at the top of the BeagleBoneTarget 8718*4882a593Smuzhiyun ``meta-yocto-bsp/lib/oeqa/controllers/beaglebonetarget.py`` file. 8719*4882a593Smuzhiyun 8720*4882a593Smuzhiyun- *"EdgeRouterTarget":* Choose "EdgeRouterTarget" if you are deploying 8721*4882a593Smuzhiyun images and running tests on the Ubiquiti Networks EdgeRouter Lite. 8722*4882a593Smuzhiyun For information on how to use these tests, see the comments at the 8723*4882a593Smuzhiyun top of the EdgeRouterTarget 8724*4882a593Smuzhiyun ``meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py`` file. 8725*4882a593Smuzhiyun 8726*4882a593Smuzhiyun- *"GrubTarget":* Choose "GrubTarget" if you are deploying images and running 8727*4882a593Smuzhiyun tests on any generic PC that boots using GRUB. For information on how 8728*4882a593Smuzhiyun to use these tests, see the comments at the top of the GrubTarget 8729*4882a593Smuzhiyun ``meta-yocto-bsp/lib/oeqa/controllers/grubtarget.py`` file. 8730*4882a593Smuzhiyun 8731*4882a593Smuzhiyun- *"your-target":* Create your own custom target if you want to run 8732*4882a593Smuzhiyun tests when you are deploying images and running tests on a custom 8733*4882a593Smuzhiyun machine within your BSP layer. To do this, you need to add a Python 8734*4882a593Smuzhiyun unit that defines the target class under ``lib/oeqa/controllers/`` 8735*4882a593Smuzhiyun within your layer. You must also provide an empty ``__init__.py``. 8736*4882a593Smuzhiyun For examples, see files in ``meta-yocto-bsp/lib/oeqa/controllers/``. 8737*4882a593Smuzhiyun 8738*4882a593SmuzhiyunSelecting SystemdbootTarget 8739*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8740*4882a593Smuzhiyun 8741*4882a593SmuzhiyunIf you did not set :term:`TEST_TARGET` to "SystemdbootTarget", then you do 8742*4882a593Smuzhiyunnot need any information in this section. You can skip down to the 8743*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:running tests`" section. 8744*4882a593Smuzhiyun 8745*4882a593SmuzhiyunIf you did set :term:`TEST_TARGET` to "SystemdbootTarget", you also need to 8746*4882a593Smuzhiyunperform a one-time setup of your controller image by doing the following: 8747*4882a593Smuzhiyun 8748*4882a593Smuzhiyun1. *Set EFI_PROVIDER:* Be sure that :term:`EFI_PROVIDER` is as follows:: 8749*4882a593Smuzhiyun 8750*4882a593Smuzhiyun EFI_PROVIDER = "systemd-boot" 8751*4882a593Smuzhiyun 8752*4882a593Smuzhiyun2. *Build the controller image:* Build the ``core-image-testmaster`` image. 8753*4882a593Smuzhiyun The ``core-image-testmaster`` recipe is provided as an example for a 8754*4882a593Smuzhiyun "controller" image and you can customize the image recipe as you would 8755*4882a593Smuzhiyun any other recipe. 8756*4882a593Smuzhiyun 8757*4882a593Smuzhiyun Here are the image recipe requirements: 8758*4882a593Smuzhiyun 8759*4882a593Smuzhiyun - Inherits ``core-image`` so that kernel modules are installed. 8760*4882a593Smuzhiyun 8761*4882a593Smuzhiyun - Installs normal linux utilities not BusyBox ones (e.g. ``bash``, 8762*4882a593Smuzhiyun ``coreutils``, ``tar``, ``gzip``, and ``kmod``). 8763*4882a593Smuzhiyun 8764*4882a593Smuzhiyun - Uses a custom Initial RAM Disk (initramfs) image with a custom 8765*4882a593Smuzhiyun installer. A normal image that you can install usually creates a 8766*4882a593Smuzhiyun single root filesystem partition. This image uses another installer that 8767*4882a593Smuzhiyun creates a specific partition layout. Not all Board Support 8768*4882a593Smuzhiyun Packages (BSPs) can use an installer. For such cases, you need to 8769*4882a593Smuzhiyun manually create the following partition layout on the target: 8770*4882a593Smuzhiyun 8771*4882a593Smuzhiyun - First partition mounted under ``/boot``, labeled "boot". 8772*4882a593Smuzhiyun 8773*4882a593Smuzhiyun - The main root filesystem partition where this image gets installed, 8774*4882a593Smuzhiyun which is mounted under ``/``. 8775*4882a593Smuzhiyun 8776*4882a593Smuzhiyun - Another partition labeled "testrootfs" where test images get 8777*4882a593Smuzhiyun deployed. 8778*4882a593Smuzhiyun 8779*4882a593Smuzhiyun3. *Install image:* Install the image that you just built on the target 8780*4882a593Smuzhiyun system. 8781*4882a593Smuzhiyun 8782*4882a593SmuzhiyunThe final thing you need to do when setting :term:`TEST_TARGET` to 8783*4882a593Smuzhiyun"SystemdbootTarget" is to set up the test image: 8784*4882a593Smuzhiyun 8785*4882a593Smuzhiyun1. *Set up your local.conf file:* Make sure you have the following 8786*4882a593Smuzhiyun statements in your ``local.conf`` file:: 8787*4882a593Smuzhiyun 8788*4882a593Smuzhiyun IMAGE_FSTYPES += "tar.gz" 8789*4882a593Smuzhiyun INHERIT += "testimage" 8790*4882a593Smuzhiyun TEST_TARGET = "SystemdbootTarget" 8791*4882a593Smuzhiyun TEST_TARGET_IP = "192.168.2.3" 8792*4882a593Smuzhiyun 8793*4882a593Smuzhiyun2. *Build your test image:* Use BitBake to build the image:: 8794*4882a593Smuzhiyun 8795*4882a593Smuzhiyun $ bitbake core-image-sato 8796*4882a593Smuzhiyun 8797*4882a593SmuzhiyunPower Control 8798*4882a593Smuzhiyun~~~~~~~~~~~~~ 8799*4882a593Smuzhiyun 8800*4882a593SmuzhiyunFor most hardware targets other than "simpleremote", you can control 8801*4882a593Smuzhiyunpower: 8802*4882a593Smuzhiyun 8803*4882a593Smuzhiyun- You can use :term:`TEST_POWERCONTROL_CMD` together with 8804*4882a593Smuzhiyun :term:`TEST_POWERCONTROL_EXTRA_ARGS` as a command that runs on the host 8805*4882a593Smuzhiyun and does power cycling. The test code passes one argument to that 8806*4882a593Smuzhiyun command: off, on or cycle (off then on). Here is an example that 8807*4882a593Smuzhiyun could appear in your ``local.conf`` file:: 8808*4882a593Smuzhiyun 8809*4882a593Smuzhiyun TEST_POWERCONTROL_CMD = "powercontrol.exp test 10.11.12.1 nuc1" 8810*4882a593Smuzhiyun 8811*4882a593Smuzhiyun In this example, the expect 8812*4882a593Smuzhiyun script does the following: 8813*4882a593Smuzhiyun 8814*4882a593Smuzhiyun .. code-block:: shell 8815*4882a593Smuzhiyun 8816*4882a593Smuzhiyun ssh test@10.11.12.1 "pyctl nuc1 arg" 8817*4882a593Smuzhiyun 8818*4882a593Smuzhiyun It then runs a Python script that controls power for a label called 8819*4882a593Smuzhiyun ``nuc1``. 8820*4882a593Smuzhiyun 8821*4882a593Smuzhiyun .. note:: 8822*4882a593Smuzhiyun 8823*4882a593Smuzhiyun You need to customize :term:`TEST_POWERCONTROL_CMD` and 8824*4882a593Smuzhiyun :term:`TEST_POWERCONTROL_EXTRA_ARGS` for your own setup. The one requirement 8825*4882a593Smuzhiyun is that it accepts "on", "off", and "cycle" as the last argument. 8826*4882a593Smuzhiyun 8827*4882a593Smuzhiyun- When no command is defined, it connects to the device over SSH and 8828*4882a593Smuzhiyun uses the classic reboot command to reboot the device. Classic reboot 8829*4882a593Smuzhiyun is fine as long as the machine actually reboots (i.e. the SSH test 8830*4882a593Smuzhiyun has not failed). It is useful for scenarios where you have a simple 8831*4882a593Smuzhiyun setup, typically with a single board, and where some manual 8832*4882a593Smuzhiyun interaction is okay from time to time. 8833*4882a593Smuzhiyun 8834*4882a593SmuzhiyunIf you have no hardware to automatically perform power control but still 8835*4882a593Smuzhiyunwish to experiment with automated hardware testing, you can use the 8836*4882a593Smuzhiyun``dialog-power-control`` script that shows a dialog prompting you to perform 8837*4882a593Smuzhiyunthe required power action. This script requires either KDialog or Zenity 8838*4882a593Smuzhiyunto be installed. To use this script, set the 8839*4882a593Smuzhiyun:term:`TEST_POWERCONTROL_CMD` 8840*4882a593Smuzhiyunvariable as follows:: 8841*4882a593Smuzhiyun 8842*4882a593Smuzhiyun TEST_POWERCONTROL_CMD = "${COREBASE}/scripts/contrib/dialog-power-control" 8843*4882a593Smuzhiyun 8844*4882a593SmuzhiyunSerial Console Connection 8845*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~ 8846*4882a593Smuzhiyun 8847*4882a593SmuzhiyunFor test target classes requiring a serial console to interact with the 8848*4882a593Smuzhiyunbootloader (e.g. BeagleBoneTarget, EdgeRouterTarget, and GrubTarget), 8849*4882a593Smuzhiyunyou need to specify a command to use to connect to the serial console of 8850*4882a593Smuzhiyunthe target machine by using the 8851*4882a593Smuzhiyun:term:`TEST_SERIALCONTROL_CMD` 8852*4882a593Smuzhiyunvariable and optionally the 8853*4882a593Smuzhiyun:term:`TEST_SERIALCONTROL_EXTRA_ARGS` 8854*4882a593Smuzhiyunvariable. 8855*4882a593Smuzhiyun 8856*4882a593SmuzhiyunThese cases could be a serial terminal program if the machine is 8857*4882a593Smuzhiyunconnected to a local serial port, or a ``telnet`` or ``ssh`` command 8858*4882a593Smuzhiyunconnecting to a remote console server. Regardless of the case, the 8859*4882a593Smuzhiyuncommand simply needs to connect to the serial console and forward that 8860*4882a593Smuzhiyunconnection to standard input and output as any normal terminal program 8861*4882a593Smuzhiyundoes. For example, to use the picocom terminal program on serial device 8862*4882a593Smuzhiyun``/dev/ttyUSB0`` at 115200bps, you would set the variable as follows:: 8863*4882a593Smuzhiyun 8864*4882a593Smuzhiyun TEST_SERIALCONTROL_CMD = "picocom /dev/ttyUSB0 -b 115200" 8865*4882a593Smuzhiyun 8866*4882a593SmuzhiyunFor local 8867*4882a593Smuzhiyundevices where the serial port device disappears when the device reboots, 8868*4882a593Smuzhiyunan additional "serdevtry" wrapper script is provided. To use this 8869*4882a593Smuzhiyunwrapper, simply prefix the terminal command with 8870*4882a593Smuzhiyun``${COREBASE}/scripts/contrib/serdevtry``:: 8871*4882a593Smuzhiyun 8872*4882a593Smuzhiyun TEST_SERIALCONTROL_CMD = "${COREBASE}/scripts/contrib/serdevtry picocom -b 115200 /dev/ttyUSB0" 8873*4882a593Smuzhiyun 8874*4882a593SmuzhiyunRunning Tests 8875*4882a593Smuzhiyun------------- 8876*4882a593Smuzhiyun 8877*4882a593SmuzhiyunYou can start the tests automatically or manually: 8878*4882a593Smuzhiyun 8879*4882a593Smuzhiyun- *Automatically running tests:* To run the tests automatically after 8880*4882a593Smuzhiyun the OpenEmbedded build system successfully creates an image, first 8881*4882a593Smuzhiyun set the 8882*4882a593Smuzhiyun :term:`TESTIMAGE_AUTO` 8883*4882a593Smuzhiyun variable to "1" in your ``local.conf`` file in the 8884*4882a593Smuzhiyun :term:`Build Directory`:: 8885*4882a593Smuzhiyun 8886*4882a593Smuzhiyun TESTIMAGE_AUTO = "1" 8887*4882a593Smuzhiyun 8888*4882a593Smuzhiyun Next, build your image. If the image successfully builds, the 8889*4882a593Smuzhiyun tests run:: 8890*4882a593Smuzhiyun 8891*4882a593Smuzhiyun bitbake core-image-sato 8892*4882a593Smuzhiyun 8893*4882a593Smuzhiyun- *Manually running tests:* To manually run the tests, first globally 8894*4882a593Smuzhiyun inherit the 8895*4882a593Smuzhiyun :ref:`testimage <ref-classes-testimage*>` class 8896*4882a593Smuzhiyun by editing your ``local.conf`` file:: 8897*4882a593Smuzhiyun 8898*4882a593Smuzhiyun INHERIT += "testimage" 8899*4882a593Smuzhiyun 8900*4882a593Smuzhiyun Next, use BitBake to run the tests:: 8901*4882a593Smuzhiyun 8902*4882a593Smuzhiyun bitbake -c testimage image 8903*4882a593Smuzhiyun 8904*4882a593SmuzhiyunAll test files reside in ``meta/lib/oeqa/runtime/cases`` in the 8905*4882a593Smuzhiyun:term:`Source Directory`. A test name maps 8906*4882a593Smuzhiyundirectly to a Python module. Each test module may contain a number of 8907*4882a593Smuzhiyunindividual tests. Tests are usually grouped together by the area tested 8908*4882a593Smuzhiyun(e.g tests for systemd reside in ``meta/lib/oeqa/runtime/cases/systemd.py``). 8909*4882a593Smuzhiyun 8910*4882a593SmuzhiyunYou can add tests to any layer provided you place them in the proper 8911*4882a593Smuzhiyunarea and you extend :term:`BBPATH` in 8912*4882a593Smuzhiyunthe ``local.conf`` file as normal. Be sure that tests reside in 8913*4882a593Smuzhiyun``layer/lib/oeqa/runtime/cases``. 8914*4882a593Smuzhiyun 8915*4882a593Smuzhiyun.. note:: 8916*4882a593Smuzhiyun 8917*4882a593Smuzhiyun Be sure that module names do not collide with module names used in 8918*4882a593Smuzhiyun the default set of test modules in ``meta/lib/oeqa/runtime/cases``. 8919*4882a593Smuzhiyun 8920*4882a593SmuzhiyunYou can change the set of tests run by appending or overriding 8921*4882a593Smuzhiyun:term:`TEST_SUITES` variable in 8922*4882a593Smuzhiyun``local.conf``. Each name in :term:`TEST_SUITES` represents a required test 8923*4882a593Smuzhiyunfor the image. Test modules named within :term:`TEST_SUITES` cannot be 8924*4882a593Smuzhiyunskipped even if a test is not suitable for an image (e.g. running the 8925*4882a593SmuzhiyunRPM tests on an image without ``rpm``). Appending "auto" to 8926*4882a593Smuzhiyun:term:`TEST_SUITES` causes the build system to try to run all tests that are 8927*4882a593Smuzhiyunsuitable for the image (i.e. each test module may elect to skip itself). 8928*4882a593Smuzhiyun 8929*4882a593SmuzhiyunThe order you list tests in :term:`TEST_SUITES` is important and influences 8930*4882a593Smuzhiyuntest dependencies. Consequently, tests that depend on other tests should 8931*4882a593Smuzhiyunbe added after the test on which they depend. For example, since the 8932*4882a593Smuzhiyun``ssh`` test depends on the ``ping`` test, "ssh" needs to come after 8933*4882a593Smuzhiyun"ping" in the list. The test class provides no re-ordering or dependency 8934*4882a593Smuzhiyunhandling. 8935*4882a593Smuzhiyun 8936*4882a593Smuzhiyun.. note:: 8937*4882a593Smuzhiyun 8938*4882a593Smuzhiyun Each module can have multiple classes with multiple test methods. 8939*4882a593Smuzhiyun And, Python ``unittest`` rules apply. 8940*4882a593Smuzhiyun 8941*4882a593SmuzhiyunHere are some things to keep in mind when running tests: 8942*4882a593Smuzhiyun 8943*4882a593Smuzhiyun- The default tests for the image are defined as:: 8944*4882a593Smuzhiyun 8945*4882a593Smuzhiyun DEFAULT_TEST_SUITES:pn-image = "ping ssh df connman syslog xorg scp vnc date rpm dnf dmesg" 8946*4882a593Smuzhiyun 8947*4882a593Smuzhiyun- Add your own test to the list of the by using the following:: 8948*4882a593Smuzhiyun 8949*4882a593Smuzhiyun TEST_SUITES:append = " mytest" 8950*4882a593Smuzhiyun 8951*4882a593Smuzhiyun- Run a specific list of tests as follows:: 8952*4882a593Smuzhiyun 8953*4882a593Smuzhiyun TEST_SUITES = "test1 test2 test3" 8954*4882a593Smuzhiyun 8955*4882a593Smuzhiyun Remember, order is important. Be sure to place a test that is 8956*4882a593Smuzhiyun dependent on another test later in the order. 8957*4882a593Smuzhiyun 8958*4882a593SmuzhiyunExporting Tests 8959*4882a593Smuzhiyun--------------- 8960*4882a593Smuzhiyun 8961*4882a593SmuzhiyunYou can export tests so that they can run independently of the build 8962*4882a593Smuzhiyunsystem. Exporting tests is required if you want to be able to hand the 8963*4882a593Smuzhiyuntest execution off to a scheduler. You can only export tests that are 8964*4882a593Smuzhiyundefined in :term:`TEST_SUITES`. 8965*4882a593Smuzhiyun 8966*4882a593SmuzhiyunIf your image is already built, make sure the following are set in your 8967*4882a593Smuzhiyun``local.conf`` file:: 8968*4882a593Smuzhiyun 8969*4882a593Smuzhiyun INHERIT += "testexport" 8970*4882a593Smuzhiyun TEST_TARGET_IP = "IP-address-for-the-test-target" 8971*4882a593Smuzhiyun TEST_SERVER_IP = "IP-address-for-the-test-server" 8972*4882a593Smuzhiyun 8973*4882a593SmuzhiyunYou can then export the tests with the 8974*4882a593Smuzhiyunfollowing BitBake command form:: 8975*4882a593Smuzhiyun 8976*4882a593Smuzhiyun $ bitbake image -c testexport 8977*4882a593Smuzhiyun 8978*4882a593SmuzhiyunExporting the tests places them in the 8979*4882a593Smuzhiyun:term:`Build Directory` in 8980*4882a593Smuzhiyun``tmp/testexport/``\ image, which is controlled by the 8981*4882a593Smuzhiyun:term:`TEST_EXPORT_DIR` variable. 8982*4882a593Smuzhiyun 8983*4882a593SmuzhiyunYou can now run the tests outside of the build environment:: 8984*4882a593Smuzhiyun 8985*4882a593Smuzhiyun $ cd tmp/testexport/image 8986*4882a593Smuzhiyun $ ./runexported.py testdata.json 8987*4882a593Smuzhiyun 8988*4882a593SmuzhiyunHere is a complete example that shows IP addresses and uses the 8989*4882a593Smuzhiyun``core-image-sato`` image:: 8990*4882a593Smuzhiyun 8991*4882a593Smuzhiyun INHERIT += "testexport" 8992*4882a593Smuzhiyun TEST_TARGET_IP = "192.168.7.2" 8993*4882a593Smuzhiyun TEST_SERVER_IP = "192.168.7.1" 8994*4882a593Smuzhiyun 8995*4882a593SmuzhiyunUse BitBake to export the tests:: 8996*4882a593Smuzhiyun 8997*4882a593Smuzhiyun $ bitbake core-image-sato -c testexport 8998*4882a593Smuzhiyun 8999*4882a593SmuzhiyunRun the tests outside of 9000*4882a593Smuzhiyunthe build environment using the following:: 9001*4882a593Smuzhiyun 9002*4882a593Smuzhiyun $ cd tmp/testexport/core-image-sato 9003*4882a593Smuzhiyun $ ./runexported.py testdata.json 9004*4882a593Smuzhiyun 9005*4882a593SmuzhiyunWriting New Tests 9006*4882a593Smuzhiyun----------------- 9007*4882a593Smuzhiyun 9008*4882a593SmuzhiyunAs mentioned previously, all new test files need to be in the proper 9009*4882a593Smuzhiyunplace for the build system to find them. New tests for additional 9010*4882a593Smuzhiyunfunctionality outside of the core should be added to the layer that adds 9011*4882a593Smuzhiyunthe functionality, in ``layer/lib/oeqa/runtime/cases`` (as long as 9012*4882a593Smuzhiyun:term:`BBPATH` is extended in the 9013*4882a593Smuzhiyunlayer's ``layer.conf`` file as normal). Just remember the following: 9014*4882a593Smuzhiyun 9015*4882a593Smuzhiyun- Filenames need to map directly to test (module) names. 9016*4882a593Smuzhiyun 9017*4882a593Smuzhiyun- Do not use module names that collide with existing core tests. 9018*4882a593Smuzhiyun 9019*4882a593Smuzhiyun- Minimally, an empty ``__init__.py`` file must be present in the runtime 9020*4882a593Smuzhiyun directory. 9021*4882a593Smuzhiyun 9022*4882a593SmuzhiyunTo create a new test, start by copying an existing module (e.g. 9023*4882a593Smuzhiyun``syslog.py`` or ``gcc.py`` are good ones to use). Test modules can use 9024*4882a593Smuzhiyuncode from ``meta/lib/oeqa/utils``, which are helper classes. 9025*4882a593Smuzhiyun 9026*4882a593Smuzhiyun.. note:: 9027*4882a593Smuzhiyun 9028*4882a593Smuzhiyun Structure shell commands such that you rely on them and they return a 9029*4882a593Smuzhiyun single code for success. Be aware that sometimes you will need to 9030*4882a593Smuzhiyun parse the output. See the ``df.py`` and ``date.py`` modules for examples. 9031*4882a593Smuzhiyun 9032*4882a593SmuzhiyunYou will notice that all test classes inherit ``oeRuntimeTest``, which 9033*4882a593Smuzhiyunis found in ``meta/lib/oetest.py``. This base class offers some helper 9034*4882a593Smuzhiyunattributes, which are described in the following sections: 9035*4882a593Smuzhiyun 9036*4882a593SmuzhiyunClass Methods 9037*4882a593Smuzhiyun~~~~~~~~~~~~~ 9038*4882a593Smuzhiyun 9039*4882a593SmuzhiyunClass methods are as follows: 9040*4882a593Smuzhiyun 9041*4882a593Smuzhiyun- *hasPackage(pkg):* Returns "True" if ``pkg`` is in the installed 9042*4882a593Smuzhiyun package list of the image, which is based on the manifest file that 9043*4882a593Smuzhiyun is generated during the ``do_rootfs`` task. 9044*4882a593Smuzhiyun 9045*4882a593Smuzhiyun- *hasFeature(feature):* Returns "True" if the feature is in 9046*4882a593Smuzhiyun :term:`IMAGE_FEATURES` or 9047*4882a593Smuzhiyun :term:`DISTRO_FEATURES`. 9048*4882a593Smuzhiyun 9049*4882a593SmuzhiyunClass Attributes 9050*4882a593Smuzhiyun~~~~~~~~~~~~~~~~ 9051*4882a593Smuzhiyun 9052*4882a593SmuzhiyunClass attributes are as follows: 9053*4882a593Smuzhiyun 9054*4882a593Smuzhiyun- *pscmd:* Equals "ps -ef" if ``procps`` is installed in the image. 9055*4882a593Smuzhiyun Otherwise, ``pscmd`` equals "ps" (busybox). 9056*4882a593Smuzhiyun 9057*4882a593Smuzhiyun- *tc:* The called test context, which gives access to the 9058*4882a593Smuzhiyun following attributes: 9059*4882a593Smuzhiyun 9060*4882a593Smuzhiyun - *d:* The BitBake datastore, which allows you to use stuff such 9061*4882a593Smuzhiyun as ``oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager")``. 9062*4882a593Smuzhiyun 9063*4882a593Smuzhiyun - *testslist and testsrequired:* Used internally. The tests 9064*4882a593Smuzhiyun do not need these. 9065*4882a593Smuzhiyun 9066*4882a593Smuzhiyun - *filesdir:* The absolute path to 9067*4882a593Smuzhiyun ``meta/lib/oeqa/runtime/files``, which contains helper files for 9068*4882a593Smuzhiyun tests meant for copying on the target such as small files written 9069*4882a593Smuzhiyun in C for compilation. 9070*4882a593Smuzhiyun 9071*4882a593Smuzhiyun - *target:* The target controller object used to deploy and 9072*4882a593Smuzhiyun start an image on a particular target (e.g. Qemu, SimpleRemote, 9073*4882a593Smuzhiyun and SystemdbootTarget). Tests usually use the following: 9074*4882a593Smuzhiyun 9075*4882a593Smuzhiyun - *ip:* The target's IP address. 9076*4882a593Smuzhiyun 9077*4882a593Smuzhiyun - *server_ip:* The host's IP address, which is usually used 9078*4882a593Smuzhiyun by the DNF test suite. 9079*4882a593Smuzhiyun 9080*4882a593Smuzhiyun - *run(cmd, timeout=None):* The single, most used method. 9081*4882a593Smuzhiyun This command is a wrapper for: ``ssh root@host "cmd"``. The 9082*4882a593Smuzhiyun command returns a tuple: (status, output), which are what their 9083*4882a593Smuzhiyun names imply - the return code of "cmd" and whatever output it 9084*4882a593Smuzhiyun produces. The optional timeout argument represents the number 9085*4882a593Smuzhiyun of seconds the test should wait for "cmd" to return. If the 9086*4882a593Smuzhiyun argument is "None", the test uses the default instance's 9087*4882a593Smuzhiyun timeout period, which is 300 seconds. If the argument is "0", 9088*4882a593Smuzhiyun the test runs until the command returns. 9089*4882a593Smuzhiyun 9090*4882a593Smuzhiyun - *copy_to(localpath, remotepath):* 9091*4882a593Smuzhiyun ``scp localpath root@ip:remotepath``. 9092*4882a593Smuzhiyun 9093*4882a593Smuzhiyun - *copy_from(remotepath, localpath):* 9094*4882a593Smuzhiyun ``scp root@host:remotepath localpath``. 9095*4882a593Smuzhiyun 9096*4882a593SmuzhiyunInstance Attributes 9097*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~ 9098*4882a593Smuzhiyun 9099*4882a593SmuzhiyunThere is a single instance attribute, which is ``target``. The ``target`` 9100*4882a593Smuzhiyuninstance attribute is identical to the class attribute of the same name, 9101*4882a593Smuzhiyunwhich is described in the previous section. This attribute exists as 9102*4882a593Smuzhiyunboth an instance and class attribute so tests can use 9103*4882a593Smuzhiyun``self.target.run(cmd)`` in instance methods instead of 9104*4882a593Smuzhiyun``oeRuntimeTest.tc.target.run(cmd)``. 9105*4882a593Smuzhiyun 9106*4882a593SmuzhiyunInstalling Packages in the DUT Without the Package Manager 9107*4882a593Smuzhiyun---------------------------------------------------------- 9108*4882a593Smuzhiyun 9109*4882a593SmuzhiyunWhen a test requires a package built by BitBake, it is possible to 9110*4882a593Smuzhiyuninstall that package. Installing the package does not require a package 9111*4882a593Smuzhiyunmanager be installed in the device under test (DUT). It does, however, 9112*4882a593Smuzhiyunrequire an SSH connection and the target must be using the 9113*4882a593Smuzhiyun``sshcontrol`` class. 9114*4882a593Smuzhiyun 9115*4882a593Smuzhiyun.. note:: 9116*4882a593Smuzhiyun 9117*4882a593Smuzhiyun This method uses ``scp`` to copy files from the host to the target, which 9118*4882a593Smuzhiyun causes permissions and special attributes to be lost. 9119*4882a593Smuzhiyun 9120*4882a593SmuzhiyunA JSON file is used to define the packages needed by a test. This file 9121*4882a593Smuzhiyunmust be in the same path as the file used to define the tests. 9122*4882a593SmuzhiyunFurthermore, the filename must map directly to the test module name with 9123*4882a593Smuzhiyuna ``.json`` extension. 9124*4882a593Smuzhiyun 9125*4882a593SmuzhiyunThe JSON file must include an object with the test name as keys of an 9126*4882a593Smuzhiyunobject or an array. This object (or array of objects) uses the following 9127*4882a593Smuzhiyundata: 9128*4882a593Smuzhiyun 9129*4882a593Smuzhiyun- "pkg" - A mandatory string that is the name of the package to be 9130*4882a593Smuzhiyun installed. 9131*4882a593Smuzhiyun 9132*4882a593Smuzhiyun- "rm" - An optional boolean, which defaults to "false", that specifies 9133*4882a593Smuzhiyun to remove the package after the test. 9134*4882a593Smuzhiyun 9135*4882a593Smuzhiyun- "extract" - An optional boolean, which defaults to "false", that 9136*4882a593Smuzhiyun specifies if the package must be extracted from the package format. 9137*4882a593Smuzhiyun When set to "true", the package is not automatically installed into 9138*4882a593Smuzhiyun the DUT. 9139*4882a593Smuzhiyun 9140*4882a593SmuzhiyunFollowing is an example JSON file that handles test "foo" installing 9141*4882a593Smuzhiyunpackage "bar" and test "foobar" installing packages "foo" and "bar". 9142*4882a593SmuzhiyunOnce the test is complete, the packages are removed from the DUT. 9143*4882a593Smuzhiyun:: 9144*4882a593Smuzhiyun 9145*4882a593Smuzhiyun { 9146*4882a593Smuzhiyun "foo": { 9147*4882a593Smuzhiyun "pkg": "bar" 9148*4882a593Smuzhiyun }, 9149*4882a593Smuzhiyun "foobar": [ 9150*4882a593Smuzhiyun { 9151*4882a593Smuzhiyun "pkg": "foo", 9152*4882a593Smuzhiyun "rm": true 9153*4882a593Smuzhiyun }, 9154*4882a593Smuzhiyun { 9155*4882a593Smuzhiyun "pkg": "bar", 9156*4882a593Smuzhiyun "rm": true 9157*4882a593Smuzhiyun } 9158*4882a593Smuzhiyun ] 9159*4882a593Smuzhiyun } 9160*4882a593Smuzhiyun 9161*4882a593SmuzhiyunDebugging Tools and Techniques 9162*4882a593Smuzhiyun============================== 9163*4882a593Smuzhiyun 9164*4882a593SmuzhiyunThe exact method for debugging build failures depends on the nature of 9165*4882a593Smuzhiyunthe problem and on the system's area from which the bug originates. 9166*4882a593SmuzhiyunStandard debugging practices such as comparison against the last known 9167*4882a593Smuzhiyunworking version with examination of the changes and the re-application 9168*4882a593Smuzhiyunof steps to identify the one causing the problem are valid for the Yocto 9169*4882a593SmuzhiyunProject just as they are for any other system. Even though it is 9170*4882a593Smuzhiyunimpossible to detail every possible potential failure, this section 9171*4882a593Smuzhiyunprovides some general tips to aid in debugging given a variety of 9172*4882a593Smuzhiyunsituations. 9173*4882a593Smuzhiyun 9174*4882a593Smuzhiyun.. note:: 9175*4882a593Smuzhiyun 9176*4882a593Smuzhiyun A useful feature for debugging is the error reporting tool. 9177*4882a593Smuzhiyun Configuring the Yocto Project to use this tool causes the 9178*4882a593Smuzhiyun OpenEmbedded build system to produce error reporting commands as part 9179*4882a593Smuzhiyun of the console output. You can enter the commands after the build 9180*4882a593Smuzhiyun completes to log error information into a common database, that can 9181*4882a593Smuzhiyun help you figure out what might be going wrong. For information on how 9182*4882a593Smuzhiyun to enable and use this feature, see the 9183*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:using the error reporting tool`" 9184*4882a593Smuzhiyun section. 9185*4882a593Smuzhiyun 9186*4882a593SmuzhiyunThe following list shows the debugging topics in the remainder of this 9187*4882a593Smuzhiyunsection: 9188*4882a593Smuzhiyun 9189*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:viewing logs from failed tasks`" describes 9190*4882a593Smuzhiyun how to find and view logs from tasks that failed during the build 9191*4882a593Smuzhiyun process. 9192*4882a593Smuzhiyun 9193*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:viewing variable values`" describes how to 9194*4882a593Smuzhiyun use the BitBake ``-e`` option to examine variable values after a 9195*4882a593Smuzhiyun recipe has been parsed. 9196*4882a593Smuzhiyun 9197*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:viewing package information with \`\`oe-pkgdata-util\`\``" 9198*4882a593Smuzhiyun describes how to use the ``oe-pkgdata-util`` utility to query 9199*4882a593Smuzhiyun :term:`PKGDATA_DIR` and 9200*4882a593Smuzhiyun display package-related information for built packages. 9201*4882a593Smuzhiyun 9202*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:viewing dependencies between recipes and tasks`" 9203*4882a593Smuzhiyun describes how to use the BitBake ``-g`` option to display recipe 9204*4882a593Smuzhiyun dependency information used during the build. 9205*4882a593Smuzhiyun 9206*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:viewing task variable dependencies`" describes 9207*4882a593Smuzhiyun how to use the ``bitbake-dumpsig`` command in conjunction with key 9208*4882a593Smuzhiyun subdirectories in the 9209*4882a593Smuzhiyun :term:`Build Directory` to determine 9210*4882a593Smuzhiyun variable dependencies. 9211*4882a593Smuzhiyun 9212*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:running specific tasks`" describes 9213*4882a593Smuzhiyun how to use several BitBake options (e.g. ``-c``, ``-C``, and ``-f``) 9214*4882a593Smuzhiyun to run specific tasks in the build chain. It can be useful to run 9215*4882a593Smuzhiyun tasks "out-of-order" when trying isolate build issues. 9216*4882a593Smuzhiyun 9217*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:general bitbake problems`" describes how 9218*4882a593Smuzhiyun to use BitBake's ``-D`` debug output option to reveal more about what 9219*4882a593Smuzhiyun BitBake is doing during the build. 9220*4882a593Smuzhiyun 9221*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:building with no dependencies`" 9222*4882a593Smuzhiyun describes how to use the BitBake ``-b`` option to build a recipe 9223*4882a593Smuzhiyun while ignoring dependencies. 9224*4882a593Smuzhiyun 9225*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:recipe logging mechanisms`" 9226*4882a593Smuzhiyun describes how to use the many recipe logging functions to produce 9227*4882a593Smuzhiyun debugging output and report errors and warnings. 9228*4882a593Smuzhiyun 9229*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:debugging parallel make races`" 9230*4882a593Smuzhiyun describes how to debug situations where the build consists of several 9231*4882a593Smuzhiyun parts that are run simultaneously and when the output or result of 9232*4882a593Smuzhiyun one part is not ready for use with a different part of the build that 9233*4882a593Smuzhiyun depends on that output. 9234*4882a593Smuzhiyun 9235*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) remotely`" 9236*4882a593Smuzhiyun describes how to use GDB to allow you to examine running programs, which can 9237*4882a593Smuzhiyun help you fix problems. 9238*4882a593Smuzhiyun 9239*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:debugging with the gnu project debugger (gdb) on the target`" 9240*4882a593Smuzhiyun describes how to use GDB directly on target hardware for debugging. 9241*4882a593Smuzhiyun 9242*4882a593Smuzhiyun- ":ref:`dev-manual/common-tasks:other debugging tips`" describes 9243*4882a593Smuzhiyun miscellaneous debugging tips that can be useful. 9244*4882a593Smuzhiyun 9245*4882a593SmuzhiyunViewing Logs from Failed Tasks 9246*4882a593Smuzhiyun------------------------------ 9247*4882a593Smuzhiyun 9248*4882a593SmuzhiyunYou can find the log for a task in the file 9249*4882a593Smuzhiyun``${``\ :term:`WORKDIR`\ ``}/temp/log.do_``\ `taskname`. 9250*4882a593SmuzhiyunFor example, the log for the 9251*4882a593Smuzhiyun:ref:`ref-tasks-compile` task of the 9252*4882a593SmuzhiyunQEMU minimal image for the x86 machine (``qemux86``) might be in 9253*4882a593Smuzhiyun``tmp/work/qemux86-poky-linux/core-image-minimal/1.0-r0/temp/log.do_compile``. 9254*4882a593SmuzhiyunTo see the commands :term:`BitBake` ran 9255*4882a593Smuzhiyunto generate a log, look at the corresponding ``run.do_``\ `taskname` file 9256*4882a593Smuzhiyunin the same directory. 9257*4882a593Smuzhiyun 9258*4882a593Smuzhiyun``log.do_``\ `taskname` and ``run.do_``\ `taskname` are actually symbolic 9259*4882a593Smuzhiyunlinks to ``log.do_``\ `taskname`\ ``.``\ `pid` and 9260*4882a593Smuzhiyun``log.run_``\ `taskname`\ ``.``\ `pid`, where `pid` is the PID the task had 9261*4882a593Smuzhiyunwhen it ran. The symlinks always point to the files corresponding to the 9262*4882a593Smuzhiyunmost recent run. 9263*4882a593Smuzhiyun 9264*4882a593SmuzhiyunViewing Variable Values 9265*4882a593Smuzhiyun----------------------- 9266*4882a593Smuzhiyun 9267*4882a593SmuzhiyunSometimes you need to know the value of a variable as a result of 9268*4882a593SmuzhiyunBitBake's parsing step. This could be because some unexpected behavior 9269*4882a593Smuzhiyunoccurred in your project. Perhaps an attempt to :ref:`modify a variable 9270*4882a593Smuzhiyun<bitbake:bitbake-user-manual/bitbake-user-manual-metadata:modifying existing 9271*4882a593Smuzhiyunvariables>` did not work out as expected. 9272*4882a593Smuzhiyun 9273*4882a593SmuzhiyunBitBake's ``-e`` option is used to display variable values after 9274*4882a593Smuzhiyunparsing. The following command displays the variable values after the 9275*4882a593Smuzhiyunconfiguration files (i.e. ``local.conf``, ``bblayers.conf``, 9276*4882a593Smuzhiyun``bitbake.conf`` and so forth) have been parsed:: 9277*4882a593Smuzhiyun 9278*4882a593Smuzhiyun $ bitbake -e 9279*4882a593Smuzhiyun 9280*4882a593SmuzhiyunThe following command displays variable values after a specific recipe has 9281*4882a593Smuzhiyunbeen parsed. The variables include those from the configuration as well:: 9282*4882a593Smuzhiyun 9283*4882a593Smuzhiyun $ bitbake -e recipename 9284*4882a593Smuzhiyun 9285*4882a593Smuzhiyun.. note:: 9286*4882a593Smuzhiyun 9287*4882a593Smuzhiyun Each recipe has its own private set of variables (datastore). 9288*4882a593Smuzhiyun Internally, after parsing the configuration, a copy of the resulting 9289*4882a593Smuzhiyun datastore is made prior to parsing each recipe. This copying implies 9290*4882a593Smuzhiyun that variables set in one recipe will not be visible to other 9291*4882a593Smuzhiyun recipes. 9292*4882a593Smuzhiyun 9293*4882a593Smuzhiyun Likewise, each task within a recipe gets a private datastore based on 9294*4882a593Smuzhiyun the recipe datastore, which means that variables set within one task 9295*4882a593Smuzhiyun will not be visible to other tasks. 9296*4882a593Smuzhiyun 9297*4882a593SmuzhiyunIn the output of ``bitbake -e``, each variable is preceded by a 9298*4882a593Smuzhiyundescription of how the variable got its value, including temporary 9299*4882a593Smuzhiyunvalues that were later overridden. This description also includes 9300*4882a593Smuzhiyunvariable flags (varflags) set on the variable. The output can be very 9301*4882a593Smuzhiyunhelpful during debugging. 9302*4882a593Smuzhiyun 9303*4882a593SmuzhiyunVariables that are exported to the environment are preceded by 9304*4882a593Smuzhiyun``export`` in the output of ``bitbake -e``. See the following example:: 9305*4882a593Smuzhiyun 9306*4882a593Smuzhiyun export CC="i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/ulf/poky/build/tmp/sysroots/qemux86" 9307*4882a593Smuzhiyun 9308*4882a593SmuzhiyunIn addition to variable values, the output of the ``bitbake -e`` and 9309*4882a593Smuzhiyun``bitbake -e`` recipe commands includes the following information: 9310*4882a593Smuzhiyun 9311*4882a593Smuzhiyun- The output starts with a tree listing all configuration files and 9312*4882a593Smuzhiyun classes included globally, recursively listing the files they include 9313*4882a593Smuzhiyun or inherit in turn. Much of the behavior of the OpenEmbedded build 9314*4882a593Smuzhiyun system (including the behavior of the :ref:`ref-manual/tasks:normal recipe build tasks`) is 9315*4882a593Smuzhiyun implemented in the 9316*4882a593Smuzhiyun :ref:`base <ref-classes-base>` class and the 9317*4882a593Smuzhiyun classes it inherits, rather than being built into BitBake itself. 9318*4882a593Smuzhiyun 9319*4882a593Smuzhiyun- After the variable values, all functions appear in the output. For 9320*4882a593Smuzhiyun shell functions, variables referenced within the function body are 9321*4882a593Smuzhiyun expanded. If a function has been modified using overrides or using 9322*4882a593Smuzhiyun override-style operators like ``:append`` and ``:prepend``, then the 9323*4882a593Smuzhiyun final assembled function body appears in the output. 9324*4882a593Smuzhiyun 9325*4882a593SmuzhiyunViewing Package Information with ``oe-pkgdata-util`` 9326*4882a593Smuzhiyun---------------------------------------------------- 9327*4882a593Smuzhiyun 9328*4882a593SmuzhiyunYou can use the ``oe-pkgdata-util`` command-line utility to query 9329*4882a593Smuzhiyun:term:`PKGDATA_DIR` and display 9330*4882a593Smuzhiyunvarious package-related information. When you use the utility, you must 9331*4882a593Smuzhiyunuse it to view information on packages that have already been built. 9332*4882a593Smuzhiyun 9333*4882a593SmuzhiyunFollowing are a few of the available ``oe-pkgdata-util`` subcommands. 9334*4882a593Smuzhiyun 9335*4882a593Smuzhiyun.. note:: 9336*4882a593Smuzhiyun 9337*4882a593Smuzhiyun You can use the standard \* and ? globbing wildcards as part of 9338*4882a593Smuzhiyun package names and paths. 9339*4882a593Smuzhiyun 9340*4882a593Smuzhiyun- ``oe-pkgdata-util list-pkgs [pattern]``: Lists all packages 9341*4882a593Smuzhiyun that have been built, optionally limiting the match to packages that 9342*4882a593Smuzhiyun match pattern. 9343*4882a593Smuzhiyun 9344*4882a593Smuzhiyun- ``oe-pkgdata-util list-pkg-files package ...``: Lists the 9345*4882a593Smuzhiyun files and directories contained in the given packages. 9346*4882a593Smuzhiyun 9347*4882a593Smuzhiyun .. note:: 9348*4882a593Smuzhiyun 9349*4882a593Smuzhiyun A different way to view the contents of a package is to look at 9350*4882a593Smuzhiyun the 9351*4882a593Smuzhiyun ``${``\ :term:`WORKDIR`\ ``}/packages-split`` 9352*4882a593Smuzhiyun directory of the recipe that generates the package. This directory 9353*4882a593Smuzhiyun is created by the 9354*4882a593Smuzhiyun :ref:`ref-tasks-package` task 9355*4882a593Smuzhiyun and has one subdirectory for each package the recipe generates, 9356*4882a593Smuzhiyun which contains the files stored in that package. 9357*4882a593Smuzhiyun 9358*4882a593Smuzhiyun If you want to inspect the ``${WORKDIR}/packages-split`` 9359*4882a593Smuzhiyun directory, make sure that 9360*4882a593Smuzhiyun :ref:`rm_work <ref-classes-rm-work>` is not 9361*4882a593Smuzhiyun enabled when you build the recipe. 9362*4882a593Smuzhiyun 9363*4882a593Smuzhiyun- ``oe-pkgdata-util find-path path ...``: Lists the names of 9364*4882a593Smuzhiyun the packages that contain the given paths. For example, the following 9365*4882a593Smuzhiyun tells us that ``/usr/share/man/man1/make.1`` is contained in the 9366*4882a593Smuzhiyun ``make-doc`` package:: 9367*4882a593Smuzhiyun 9368*4882a593Smuzhiyun $ oe-pkgdata-util find-path /usr/share/man/man1/make.1 9369*4882a593Smuzhiyun make-doc: /usr/share/man/man1/make.1 9370*4882a593Smuzhiyun 9371*4882a593Smuzhiyun- ``oe-pkgdata-util lookup-recipe package ...``: Lists the name 9372*4882a593Smuzhiyun of the recipes that produce the given packages. 9373*4882a593Smuzhiyun 9374*4882a593SmuzhiyunFor more information on the ``oe-pkgdata-util`` command, use the help 9375*4882a593Smuzhiyunfacility:: 9376*4882a593Smuzhiyun 9377*4882a593Smuzhiyun $ oe-pkgdata-util --help 9378*4882a593Smuzhiyun $ oe-pkgdata-util subcommand --help 9379*4882a593Smuzhiyun 9380*4882a593SmuzhiyunViewing Dependencies Between Recipes and Tasks 9381*4882a593Smuzhiyun---------------------------------------------- 9382*4882a593Smuzhiyun 9383*4882a593SmuzhiyunSometimes it can be hard to see why BitBake wants to build other recipes 9384*4882a593Smuzhiyunbefore the one you have specified. Dependency information can help you 9385*4882a593Smuzhiyununderstand why a recipe is built. 9386*4882a593Smuzhiyun 9387*4882a593SmuzhiyunTo generate dependency information for a recipe, run the following 9388*4882a593Smuzhiyuncommand:: 9389*4882a593Smuzhiyun 9390*4882a593Smuzhiyun $ bitbake -g recipename 9391*4882a593Smuzhiyun 9392*4882a593SmuzhiyunThis command writes the following files in the current directory: 9393*4882a593Smuzhiyun 9394*4882a593Smuzhiyun- ``pn-buildlist``: A list of recipes/targets involved in building 9395*4882a593Smuzhiyun `recipename`. "Involved" here means that at least one task from the 9396*4882a593Smuzhiyun recipe needs to run when building `recipename` from scratch. Targets 9397*4882a593Smuzhiyun that are in 9398*4882a593Smuzhiyun :term:`ASSUME_PROVIDED` 9399*4882a593Smuzhiyun are not listed. 9400*4882a593Smuzhiyun 9401*4882a593Smuzhiyun- ``task-depends.dot``: A graph showing dependencies between tasks. 9402*4882a593Smuzhiyun 9403*4882a593SmuzhiyunThe graphs are in 9404*4882a593Smuzhiyun`DOT <https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29>`__ 9405*4882a593Smuzhiyunformat and can be converted to images (e.g. using the ``dot`` tool from 9406*4882a593Smuzhiyun`Graphviz <https://www.graphviz.org/>`__). 9407*4882a593Smuzhiyun 9408*4882a593Smuzhiyun.. note:: 9409*4882a593Smuzhiyun 9410*4882a593Smuzhiyun - DOT files use a plain text format. The graphs generated using the 9411*4882a593Smuzhiyun ``bitbake -g`` command are often so large as to be difficult to 9412*4882a593Smuzhiyun read without special pruning (e.g. with Bitbake's ``-I`` option) 9413*4882a593Smuzhiyun and processing. Despite the form and size of the graphs, the 9414*4882a593Smuzhiyun corresponding ``.dot`` files can still be possible to read and 9415*4882a593Smuzhiyun provide useful information. 9416*4882a593Smuzhiyun 9417*4882a593Smuzhiyun As an example, the ``task-depends.dot`` file contains lines such 9418*4882a593Smuzhiyun as the following:: 9419*4882a593Smuzhiyun 9420*4882a593Smuzhiyun "libxslt.do_configure" -> "libxml2.do_populate_sysroot" 9421*4882a593Smuzhiyun 9422*4882a593Smuzhiyun The above example line reveals that the 9423*4882a593Smuzhiyun :ref:`ref-tasks-configure` 9424*4882a593Smuzhiyun task in ``libxslt`` depends on the 9425*4882a593Smuzhiyun :ref:`ref-tasks-populate_sysroot` 9426*4882a593Smuzhiyun task in ``libxml2``, which is a normal 9427*4882a593Smuzhiyun :term:`DEPENDS` dependency 9428*4882a593Smuzhiyun between the two recipes. 9429*4882a593Smuzhiyun 9430*4882a593Smuzhiyun - For an example of how ``.dot`` files can be processed, see the 9431*4882a593Smuzhiyun ``scripts/contrib/graph-tool`` Python script, which finds and 9432*4882a593Smuzhiyun displays paths between graph nodes. 9433*4882a593Smuzhiyun 9434*4882a593SmuzhiyunYou can use a different method to view dependency information by using 9435*4882a593Smuzhiyunthe following command:: 9436*4882a593Smuzhiyun 9437*4882a593Smuzhiyun $ bitbake -g -u taskexp recipename 9438*4882a593Smuzhiyun 9439*4882a593SmuzhiyunThis command 9440*4882a593Smuzhiyundisplays a GUI window from which you can view build-time and runtime 9441*4882a593Smuzhiyundependencies for the recipes involved in building recipename. 9442*4882a593Smuzhiyun 9443*4882a593SmuzhiyunViewing Task Variable Dependencies 9444*4882a593Smuzhiyun---------------------------------- 9445*4882a593Smuzhiyun 9446*4882a593SmuzhiyunAs mentioned in the 9447*4882a593Smuzhiyun":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section of the BitBake 9448*4882a593SmuzhiyunUser Manual, BitBake tries to automatically determine what variables a 9449*4882a593Smuzhiyuntask depends on so that it can rerun the task if any values of the 9450*4882a593Smuzhiyunvariables change. This determination is usually reliable. However, if 9451*4882a593Smuzhiyunyou do things like construct variable names at runtime, then you might 9452*4882a593Smuzhiyunhave to manually declare dependencies on those variables using 9453*4882a593Smuzhiyun``vardeps`` as described in the 9454*4882a593Smuzhiyun":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section of the BitBake 9455*4882a593SmuzhiyunUser Manual. 9456*4882a593Smuzhiyun 9457*4882a593SmuzhiyunIf you are unsure whether a variable dependency is being picked up 9458*4882a593Smuzhiyunautomatically for a given task, you can list the variable dependencies 9459*4882a593SmuzhiyunBitBake has determined by doing the following: 9460*4882a593Smuzhiyun 9461*4882a593Smuzhiyun1. Build the recipe containing the task:: 9462*4882a593Smuzhiyun 9463*4882a593Smuzhiyun $ bitbake recipename 9464*4882a593Smuzhiyun 9465*4882a593Smuzhiyun2. Inside the :term:`STAMPS_DIR` 9466*4882a593Smuzhiyun directory, find the signature data (``sigdata``) file that 9467*4882a593Smuzhiyun corresponds to the task. The ``sigdata`` files contain a pickled 9468*4882a593Smuzhiyun Python database of all the metadata that went into creating the input 9469*4882a593Smuzhiyun checksum for the task. As an example, for the 9470*4882a593Smuzhiyun :ref:`ref-tasks-fetch` task of the 9471*4882a593Smuzhiyun ``db`` recipe, the ``sigdata`` file might be found in the following 9472*4882a593Smuzhiyun location:: 9473*4882a593Smuzhiyun 9474*4882a593Smuzhiyun ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 9475*4882a593Smuzhiyun 9476*4882a593Smuzhiyun For tasks that are accelerated through the shared state 9477*4882a593Smuzhiyun (:ref:`sstate <overview-manual/concepts:shared state cache>`) cache, an 9478*4882a593Smuzhiyun additional ``siginfo`` file is written into 9479*4882a593Smuzhiyun :term:`SSTATE_DIR` along with 9480*4882a593Smuzhiyun the cached task output. The ``siginfo`` files contain exactly the 9481*4882a593Smuzhiyun same information as ``sigdata`` files. 9482*4882a593Smuzhiyun 9483*4882a593Smuzhiyun3. Run ``bitbake-dumpsig`` on the ``sigdata`` or ``siginfo`` file. Here 9484*4882a593Smuzhiyun is an example:: 9485*4882a593Smuzhiyun 9486*4882a593Smuzhiyun $ bitbake-dumpsig ${BUILDDIR}/tmp/stamps/i586-poky-linux/db/6.0.30-r1.do_fetch.sigdata.7c048c18222b16ff0bcee2000ef648b1 9487*4882a593Smuzhiyun 9488*4882a593Smuzhiyun In the output of the above command, you will find a line like the 9489*4882a593Smuzhiyun following, which lists all the (inferred) variable dependencies for 9490*4882a593Smuzhiyun the task. This list also includes indirect dependencies from 9491*4882a593Smuzhiyun variables depending on other variables, recursively. 9492*4882a593Smuzhiyun :: 9493*4882a593Smuzhiyun 9494*4882a593Smuzhiyun Task dependencies: ['PV', 'SRCREV', 'SRC_URI', 'SRC_URI[md5sum]', 'SRC_URI[sha256sum]', 'base_do_fetch'] 9495*4882a593Smuzhiyun 9496*4882a593Smuzhiyun .. note:: 9497*4882a593Smuzhiyun 9498*4882a593Smuzhiyun Functions (e.g. ``base_do_fetch``) also count as variable dependencies. 9499*4882a593Smuzhiyun These functions in turn depend on the variables they reference. 9500*4882a593Smuzhiyun 9501*4882a593Smuzhiyun The output of ``bitbake-dumpsig`` also includes the value each 9502*4882a593Smuzhiyun variable had, a list of dependencies for each variable, and 9503*4882a593Smuzhiyun :term:`BB_BASEHASH_IGNORE_VARS` 9504*4882a593Smuzhiyun information. 9505*4882a593Smuzhiyun 9506*4882a593SmuzhiyunThere is also a ``bitbake-diffsigs`` command for comparing two 9507*4882a593Smuzhiyun``siginfo`` or ``sigdata`` files. This command can be helpful when 9508*4882a593Smuzhiyuntrying to figure out what changed between two versions of a task. If you 9509*4882a593Smuzhiyuncall ``bitbake-diffsigs`` with just one file, the command behaves like 9510*4882a593Smuzhiyun``bitbake-dumpsig``. 9511*4882a593Smuzhiyun 9512*4882a593SmuzhiyunYou can also use BitBake to dump out the signature construction 9513*4882a593Smuzhiyuninformation without executing tasks by using either of the following 9514*4882a593SmuzhiyunBitBake command-line options:: 9515*4882a593Smuzhiyun 9516*4882a593Smuzhiyun ‐‐dump-signatures=SIGNATURE_HANDLER 9517*4882a593Smuzhiyun -S SIGNATURE_HANDLER 9518*4882a593Smuzhiyun 9519*4882a593Smuzhiyun 9520*4882a593Smuzhiyun.. note:: 9521*4882a593Smuzhiyun 9522*4882a593Smuzhiyun Two common values for `SIGNATURE_HANDLER` are "none" and "printdiff", which 9523*4882a593Smuzhiyun dump only the signature or compare the dumped signature with the cached one, 9524*4882a593Smuzhiyun respectively. 9525*4882a593Smuzhiyun 9526*4882a593SmuzhiyunUsing BitBake with either of these options causes BitBake to dump out 9527*4882a593Smuzhiyun``sigdata`` files in the ``stamps`` directory for every task it would 9528*4882a593Smuzhiyunhave executed instead of building the specified target package. 9529*4882a593Smuzhiyun 9530*4882a593SmuzhiyunViewing Metadata Used to Create the Input Signature of a Shared State Task 9531*4882a593Smuzhiyun-------------------------------------------------------------------------- 9532*4882a593Smuzhiyun 9533*4882a593SmuzhiyunSeeing what metadata went into creating the input signature of a shared 9534*4882a593Smuzhiyunstate (sstate) task can be a useful debugging aid. This information is 9535*4882a593Smuzhiyunavailable in signature information (``siginfo``) files in 9536*4882a593Smuzhiyun:term:`SSTATE_DIR`. For 9537*4882a593Smuzhiyuninformation on how to view and interpret information in ``siginfo`` 9538*4882a593Smuzhiyunfiles, see the 9539*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:viewing task variable dependencies`" section. 9540*4882a593Smuzhiyun 9541*4882a593SmuzhiyunFor conceptual information on shared state, see the 9542*4882a593Smuzhiyun":ref:`overview-manual/concepts:shared state`" 9543*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual. 9544*4882a593Smuzhiyun 9545*4882a593SmuzhiyunInvalidating Shared State to Force a Task to Run 9546*4882a593Smuzhiyun------------------------------------------------ 9547*4882a593Smuzhiyun 9548*4882a593SmuzhiyunThe OpenEmbedded build system uses 9549*4882a593Smuzhiyun:ref:`checksums <overview-manual/concepts:checksums (signatures)>` and 9550*4882a593Smuzhiyun:ref:`overview-manual/concepts:shared state` cache to avoid unnecessarily 9551*4882a593Smuzhiyunrebuilding tasks. Collectively, this scheme is known as "shared state 9552*4882a593Smuzhiyuncode". 9553*4882a593Smuzhiyun 9554*4882a593SmuzhiyunAs with all schemes, this one has some drawbacks. It is possible that 9555*4882a593Smuzhiyunyou could make implicit changes to your code that the checksum 9556*4882a593Smuzhiyuncalculations do not take into account. These implicit changes affect a 9557*4882a593Smuzhiyuntask's output but do not trigger the shared state code into rebuilding a 9558*4882a593Smuzhiyunrecipe. Consider an example during which a tool changes its output. 9559*4882a593SmuzhiyunAssume that the output of ``rpmdeps`` changes. The result of the change 9560*4882a593Smuzhiyunshould be that all the ``package`` and ``package_write_rpm`` shared 9561*4882a593Smuzhiyunstate cache items become invalid. However, because the change to the 9562*4882a593Smuzhiyunoutput is external to the code and therefore implicit, the associated 9563*4882a593Smuzhiyunshared state cache items do not become invalidated. In this case, the 9564*4882a593Smuzhiyunbuild process uses the cached items rather than running the task again. 9565*4882a593SmuzhiyunObviously, these types of implicit changes can cause problems. 9566*4882a593Smuzhiyun 9567*4882a593SmuzhiyunTo avoid these problems during the build, you need to understand the 9568*4882a593Smuzhiyuneffects of any changes you make. Realize that changes you make directly 9569*4882a593Smuzhiyunto a function are automatically factored into the checksum calculation. 9570*4882a593SmuzhiyunThus, these explicit changes invalidate the associated area of shared 9571*4882a593Smuzhiyunstate cache. However, you need to be aware of any implicit changes that 9572*4882a593Smuzhiyunare not obvious changes to the code and could affect the output of a 9573*4882a593Smuzhiyungiven task. 9574*4882a593Smuzhiyun 9575*4882a593SmuzhiyunWhen you identify an implicit change, you can easily take steps to 9576*4882a593Smuzhiyuninvalidate the cache and force the tasks to run. The steps you can take 9577*4882a593Smuzhiyunare as simple as changing a function's comments in the source code. For 9578*4882a593Smuzhiyunexample, to invalidate package shared state files, change the comment 9579*4882a593Smuzhiyunstatements of 9580*4882a593Smuzhiyun:ref:`ref-tasks-package` or the 9581*4882a593Smuzhiyuncomments of one of the functions it calls. Even though the change is 9582*4882a593Smuzhiyunpurely cosmetic, it causes the checksum to be recalculated and forces 9583*4882a593Smuzhiyunthe build system to run the task again. 9584*4882a593Smuzhiyun 9585*4882a593Smuzhiyun.. note:: 9586*4882a593Smuzhiyun 9587*4882a593Smuzhiyun For an example of a commit that makes a cosmetic change to invalidate 9588*4882a593Smuzhiyun shared state, see this 9589*4882a593Smuzhiyun :yocto_git:`commit </poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54>`. 9590*4882a593Smuzhiyun 9591*4882a593SmuzhiyunRunning Specific Tasks 9592*4882a593Smuzhiyun---------------------- 9593*4882a593Smuzhiyun 9594*4882a593SmuzhiyunAny given recipe consists of a set of tasks. The standard BitBake 9595*4882a593Smuzhiyunbehavior in most cases is: ``do_fetch``, ``do_unpack``, ``do_patch``, 9596*4882a593Smuzhiyun``do_configure``, ``do_compile``, ``do_install``, ``do_package``, 9597*4882a593Smuzhiyun``do_package_write_*``, and ``do_build``. The default task is 9598*4882a593Smuzhiyun``do_build`` and any tasks on which it depends build first. Some tasks, 9599*4882a593Smuzhiyunsuch as ``do_devshell``, are not part of the default build chain. If you 9600*4882a593Smuzhiyunwish to run a task that is not part of the default build chain, you can 9601*4882a593Smuzhiyunuse the ``-c`` option in BitBake. Here is an example:: 9602*4882a593Smuzhiyun 9603*4882a593Smuzhiyun $ bitbake matchbox-desktop -c devshell 9604*4882a593Smuzhiyun 9605*4882a593SmuzhiyunThe ``-c`` option respects task dependencies, which means that all other 9606*4882a593Smuzhiyuntasks (including tasks from other recipes) that the specified task 9607*4882a593Smuzhiyundepends on will be run before the task. Even when you manually specify a 9608*4882a593Smuzhiyuntask to run with ``-c``, BitBake will only run the task if it considers 9609*4882a593Smuzhiyunit "out of date". See the 9610*4882a593Smuzhiyun":ref:`overview-manual/concepts:stamp files and the rerunning of tasks`" 9611*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual for how 9612*4882a593SmuzhiyunBitBake determines whether a task is "out of date". 9613*4882a593Smuzhiyun 9614*4882a593SmuzhiyunIf you want to force an up-to-date task to be rerun (e.g. because you 9615*4882a593Smuzhiyunmade manual modifications to the recipe's 9616*4882a593Smuzhiyun:term:`WORKDIR` that you want to try 9617*4882a593Smuzhiyunout), then you can use the ``-f`` option. 9618*4882a593Smuzhiyun 9619*4882a593Smuzhiyun.. note:: 9620*4882a593Smuzhiyun 9621*4882a593Smuzhiyun The reason ``-f`` is never required when running the 9622*4882a593Smuzhiyun :ref:`ref-tasks-devshell` task is because the 9623*4882a593Smuzhiyun [\ :ref:`nostamp <bitbake:bitbake-user-manual/bitbake-user-manual-metadata:variable flags>`\ ] 9624*4882a593Smuzhiyun variable flag is already set for the task. 9625*4882a593Smuzhiyun 9626*4882a593SmuzhiyunThe following example shows one way you can use the ``-f`` option:: 9627*4882a593Smuzhiyun 9628*4882a593Smuzhiyun $ bitbake matchbox-desktop 9629*4882a593Smuzhiyun . 9630*4882a593Smuzhiyun . 9631*4882a593Smuzhiyun make some changes to the source code in the work directory 9632*4882a593Smuzhiyun . 9633*4882a593Smuzhiyun . 9634*4882a593Smuzhiyun $ bitbake matchbox-desktop -c compile -f 9635*4882a593Smuzhiyun $ bitbake matchbox-desktop 9636*4882a593Smuzhiyun 9637*4882a593SmuzhiyunThis sequence first builds and then recompiles ``matchbox-desktop``. The 9638*4882a593Smuzhiyunlast command reruns all tasks (basically the packaging tasks) after the 9639*4882a593Smuzhiyuncompile. BitBake recognizes that the ``do_compile`` task was rerun and 9640*4882a593Smuzhiyuntherefore understands that the other tasks also need to be run again. 9641*4882a593Smuzhiyun 9642*4882a593SmuzhiyunAnother, shorter way to rerun a task and all 9643*4882a593Smuzhiyun:ref:`ref-manual/tasks:normal recipe build tasks` 9644*4882a593Smuzhiyunthat depend on it is to use the ``-C`` option. 9645*4882a593Smuzhiyun 9646*4882a593Smuzhiyun.. note:: 9647*4882a593Smuzhiyun 9648*4882a593Smuzhiyun This option is upper-cased and is separate from the ``-c`` 9649*4882a593Smuzhiyun option, which is lower-cased. 9650*4882a593Smuzhiyun 9651*4882a593SmuzhiyunUsing this option invalidates the given task and then runs the 9652*4882a593Smuzhiyun:ref:`ref-tasks-build` task, which is 9653*4882a593Smuzhiyunthe default task if no task is given, and the tasks on which it depends. 9654*4882a593SmuzhiyunYou could replace the final two commands in the previous example with 9655*4882a593Smuzhiyunthe following single command:: 9656*4882a593Smuzhiyun 9657*4882a593Smuzhiyun $ bitbake matchbox-desktop -C compile 9658*4882a593Smuzhiyun 9659*4882a593SmuzhiyunInternally, the ``-f`` and ``-C`` options work by tainting (modifying) 9660*4882a593Smuzhiyunthe input checksum of the specified task. This tainting indirectly 9661*4882a593Smuzhiyuncauses the task and its dependent tasks to be rerun through the normal 9662*4882a593Smuzhiyuntask dependency mechanisms. 9663*4882a593Smuzhiyun 9664*4882a593Smuzhiyun.. note:: 9665*4882a593Smuzhiyun 9666*4882a593Smuzhiyun BitBake explicitly keeps track of which tasks have been tainted in 9667*4882a593Smuzhiyun this fashion, and will print warnings such as the following for 9668*4882a593Smuzhiyun builds involving such tasks: 9669*4882a593Smuzhiyun 9670*4882a593Smuzhiyun .. code-block:: none 9671*4882a593Smuzhiyun 9672*4882a593Smuzhiyun WARNING: /home/ulf/poky/meta/recipes-sato/matchbox-desktop/matchbox-desktop_2.1.bb.do_compile is tainted from a forced run 9673*4882a593Smuzhiyun 9674*4882a593Smuzhiyun 9675*4882a593Smuzhiyun The purpose of the warning is to let you know that the work directory 9676*4882a593Smuzhiyun and build output might not be in the clean state they would be in for 9677*4882a593Smuzhiyun a "normal" build, depending on what actions you took. To get rid of 9678*4882a593Smuzhiyun such warnings, you can remove the work directory and rebuild the 9679*4882a593Smuzhiyun recipe, as follows:: 9680*4882a593Smuzhiyun 9681*4882a593Smuzhiyun $ bitbake matchbox-desktop -c clean 9682*4882a593Smuzhiyun $ bitbake matchbox-desktop 9683*4882a593Smuzhiyun 9684*4882a593Smuzhiyun 9685*4882a593SmuzhiyunYou can view a list of tasks in a given package by running the 9686*4882a593Smuzhiyun``do_listtasks`` task as follows:: 9687*4882a593Smuzhiyun 9688*4882a593Smuzhiyun $ bitbake matchbox-desktop -c listtasks 9689*4882a593Smuzhiyun 9690*4882a593SmuzhiyunThe results appear as output to the console and are also in 9691*4882a593Smuzhiyunthe file ``${WORKDIR}/temp/log.do_listtasks``. 9692*4882a593Smuzhiyun 9693*4882a593SmuzhiyunGeneral BitBake Problems 9694*4882a593Smuzhiyun------------------------ 9695*4882a593Smuzhiyun 9696*4882a593SmuzhiyunYou can see debug output from BitBake by using the ``-D`` option. The 9697*4882a593Smuzhiyundebug output gives more information about what BitBake is doing and the 9698*4882a593Smuzhiyunreason behind it. Each ``-D`` option you use increases the logging 9699*4882a593Smuzhiyunlevel. The most common usage is ``-DDD``. 9700*4882a593Smuzhiyun 9701*4882a593SmuzhiyunThe output from ``bitbake -DDD -v targetname`` can reveal why BitBake 9702*4882a593Smuzhiyunchose a certain version of a package or why BitBake picked a certain 9703*4882a593Smuzhiyunprovider. This command could also help you in a situation where you 9704*4882a593Smuzhiyunthink BitBake did something unexpected. 9705*4882a593Smuzhiyun 9706*4882a593SmuzhiyunBuilding with No Dependencies 9707*4882a593Smuzhiyun----------------------------- 9708*4882a593Smuzhiyun 9709*4882a593SmuzhiyunTo build a specific recipe (``.bb`` file), you can use the following 9710*4882a593Smuzhiyuncommand form:: 9711*4882a593Smuzhiyun 9712*4882a593Smuzhiyun $ bitbake -b somepath/somerecipe.bb 9713*4882a593Smuzhiyun 9714*4882a593SmuzhiyunThis command form does 9715*4882a593Smuzhiyunnot check for dependencies. Consequently, you should use it only when 9716*4882a593Smuzhiyunyou know existing dependencies have been met. 9717*4882a593Smuzhiyun 9718*4882a593Smuzhiyun.. note:: 9719*4882a593Smuzhiyun 9720*4882a593Smuzhiyun You can also specify fragments of the filename. In this case, BitBake 9721*4882a593Smuzhiyun checks for a unique match. 9722*4882a593Smuzhiyun 9723*4882a593SmuzhiyunRecipe Logging Mechanisms 9724*4882a593Smuzhiyun------------------------- 9725*4882a593Smuzhiyun 9726*4882a593SmuzhiyunThe Yocto Project provides several logging functions for producing 9727*4882a593Smuzhiyundebugging output and reporting errors and warnings. For Python 9728*4882a593Smuzhiyunfunctions, the following logging functions are available. All of these functions 9729*4882a593Smuzhiyunlog to ``${T}/log.do_``\ `task`, and can also log to standard output 9730*4882a593Smuzhiyun(stdout) with the right settings: 9731*4882a593Smuzhiyun 9732*4882a593Smuzhiyun- ``bb.plain(msg)``: Writes msg as is to the log while also 9733*4882a593Smuzhiyun logging to stdout. 9734*4882a593Smuzhiyun 9735*4882a593Smuzhiyun- ``bb.note(msg)``: Writes "NOTE: msg" to the log. Also logs to 9736*4882a593Smuzhiyun stdout if BitBake is called with "-v". 9737*4882a593Smuzhiyun 9738*4882a593Smuzhiyun- ``bb.debug(level, msg)``: Writes "DEBUG: msg" to the 9739*4882a593Smuzhiyun log. Also logs to stdout if the log level is greater than or equal to 9740*4882a593Smuzhiyun level. See the ":ref:`bitbake:bitbake-user-manual/bitbake-user-manual-intro:usage and syntax`" option 9741*4882a593Smuzhiyun in the BitBake User Manual for more information. 9742*4882a593Smuzhiyun 9743*4882a593Smuzhiyun- ``bb.warn(msg)``: Writes "WARNING: msg" to the log while also 9744*4882a593Smuzhiyun logging to stdout. 9745*4882a593Smuzhiyun 9746*4882a593Smuzhiyun- ``bb.error(msg)``: Writes "ERROR: msg" to the log while also 9747*4882a593Smuzhiyun logging to standard out (stdout). 9748*4882a593Smuzhiyun 9749*4882a593Smuzhiyun .. note:: 9750*4882a593Smuzhiyun 9751*4882a593Smuzhiyun Calling this function does not cause the task to fail. 9752*4882a593Smuzhiyun 9753*4882a593Smuzhiyun- ``bb.fatal(msg)``: This logging function is similar to 9754*4882a593Smuzhiyun ``bb.error(msg)`` but also causes the calling task to fail. 9755*4882a593Smuzhiyun 9756*4882a593Smuzhiyun .. note:: 9757*4882a593Smuzhiyun 9758*4882a593Smuzhiyun ``bb.fatal()`` raises an exception, which means you do not need to put a 9759*4882a593Smuzhiyun "return" statement after the function. 9760*4882a593Smuzhiyun 9761*4882a593SmuzhiyunThe same logging functions are also available in shell functions, under 9762*4882a593Smuzhiyunthe names ``bbplain``, ``bbnote``, ``bbdebug``, ``bbwarn``, ``bberror``, 9763*4882a593Smuzhiyunand ``bbfatal``. The 9764*4882a593Smuzhiyun:ref:`logging <ref-classes-logging>` class 9765*4882a593Smuzhiyunimplements these functions. See that class in the ``meta/classes`` 9766*4882a593Smuzhiyunfolder of the :term:`Source Directory` for information. 9767*4882a593Smuzhiyun 9768*4882a593SmuzhiyunLogging With Python 9769*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~ 9770*4882a593Smuzhiyun 9771*4882a593SmuzhiyunWhen creating recipes using Python and inserting code that handles build 9772*4882a593Smuzhiyunlogs, keep in mind the goal is to have informative logs while keeping 9773*4882a593Smuzhiyunthe console as "silent" as possible. Also, if you want status messages 9774*4882a593Smuzhiyunin the log, use the "debug" loglevel. 9775*4882a593Smuzhiyun 9776*4882a593SmuzhiyunFollowing is an example written in Python. The code handles logging for 9777*4882a593Smuzhiyuna function that determines the number of tasks needed to be run. See the 9778*4882a593Smuzhiyun":ref:`ref-tasks-listtasks`" 9779*4882a593Smuzhiyunsection for additional information:: 9780*4882a593Smuzhiyun 9781*4882a593Smuzhiyun python do_listtasks() { 9782*4882a593Smuzhiyun bb.debug(2, "Starting to figure out the task list") 9783*4882a593Smuzhiyun if noteworthy_condition: 9784*4882a593Smuzhiyun bb.note("There are 47 tasks to run") 9785*4882a593Smuzhiyun bb.debug(2, "Got to point xyz") 9786*4882a593Smuzhiyun if warning_trigger: 9787*4882a593Smuzhiyun bb.warn("Detected warning_trigger, this might be a problem later.") 9788*4882a593Smuzhiyun if recoverable_error: 9789*4882a593Smuzhiyun bb.error("Hit recoverable_error, you really need to fix this!") 9790*4882a593Smuzhiyun if fatal_error: 9791*4882a593Smuzhiyun bb.fatal("fatal_error detected, unable to print the task list") 9792*4882a593Smuzhiyun bb.plain("The tasks present are abc") 9793*4882a593Smuzhiyun bb.debug(2, "Finished figuring out the tasklist") 9794*4882a593Smuzhiyun } 9795*4882a593Smuzhiyun 9796*4882a593SmuzhiyunLogging With Bash 9797*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~ 9798*4882a593Smuzhiyun 9799*4882a593SmuzhiyunWhen creating recipes using Bash and inserting code that handles build 9800*4882a593Smuzhiyunlogs, you have the same goals - informative with minimal console output. 9801*4882a593SmuzhiyunThe syntax you use for recipes written in Bash is similar to that of 9802*4882a593Smuzhiyunrecipes written in Python described in the previous section. 9803*4882a593Smuzhiyun 9804*4882a593SmuzhiyunFollowing is an example written in Bash. The code logs the progress of 9805*4882a593Smuzhiyunthe ``do_my_function`` function. 9806*4882a593Smuzhiyun:: 9807*4882a593Smuzhiyun 9808*4882a593Smuzhiyun do_my_function() { 9809*4882a593Smuzhiyun bbdebug 2 "Running do_my_function" 9810*4882a593Smuzhiyun if [ exceptional_condition ]; then 9811*4882a593Smuzhiyun bbnote "Hit exceptional_condition" 9812*4882a593Smuzhiyun fi 9813*4882a593Smuzhiyun bbdebug 2 "Got to point xyz" 9814*4882a593Smuzhiyun if [ warning_trigger ]; then 9815*4882a593Smuzhiyun bbwarn "Detected warning_trigger, this might cause a problem later." 9816*4882a593Smuzhiyun fi 9817*4882a593Smuzhiyun if [ recoverable_error ]; then 9818*4882a593Smuzhiyun bberror "Hit recoverable_error, correcting" 9819*4882a593Smuzhiyun fi 9820*4882a593Smuzhiyun if [ fatal_error ]; then 9821*4882a593Smuzhiyun bbfatal "fatal_error detected" 9822*4882a593Smuzhiyun fi 9823*4882a593Smuzhiyun bbdebug 2 "Completed do_my_function" 9824*4882a593Smuzhiyun } 9825*4882a593Smuzhiyun 9826*4882a593Smuzhiyun 9827*4882a593SmuzhiyunDebugging Parallel Make Races 9828*4882a593Smuzhiyun----------------------------- 9829*4882a593Smuzhiyun 9830*4882a593SmuzhiyunA parallel ``make`` race occurs when the build consists of several parts 9831*4882a593Smuzhiyunthat are run simultaneously and a situation occurs when the output or 9832*4882a593Smuzhiyunresult of one part is not ready for use with a different part of the 9833*4882a593Smuzhiyunbuild that depends on that output. Parallel make races are annoying and 9834*4882a593Smuzhiyuncan sometimes be difficult to reproduce and fix. However, there are some simple 9835*4882a593Smuzhiyuntips and tricks that can help you debug and fix them. This section 9836*4882a593Smuzhiyunpresents a real-world example of an error encountered on the Yocto 9837*4882a593SmuzhiyunProject autobuilder and the process used to fix it. 9838*4882a593Smuzhiyun 9839*4882a593Smuzhiyun.. note:: 9840*4882a593Smuzhiyun 9841*4882a593Smuzhiyun If you cannot properly fix a ``make`` race condition, you can work around it 9842*4882a593Smuzhiyun by clearing either the :term:`PARALLEL_MAKE` or :term:`PARALLEL_MAKEINST` 9843*4882a593Smuzhiyun variables. 9844*4882a593Smuzhiyun 9845*4882a593SmuzhiyunThe Failure 9846*4882a593Smuzhiyun~~~~~~~~~~~ 9847*4882a593Smuzhiyun 9848*4882a593SmuzhiyunFor this example, assume that you are building an image that depends on 9849*4882a593Smuzhiyunthe "neard" package. And, during the build, BitBake runs into problems 9850*4882a593Smuzhiyunand creates the following output. 9851*4882a593Smuzhiyun 9852*4882a593Smuzhiyun.. note:: 9853*4882a593Smuzhiyun 9854*4882a593Smuzhiyun This example log file has longer lines artificially broken to make 9855*4882a593Smuzhiyun the listing easier to read. 9856*4882a593Smuzhiyun 9857*4882a593SmuzhiyunIf you examine the output or the log file, you see the failure during 9858*4882a593Smuzhiyun``make``: 9859*4882a593Smuzhiyun 9860*4882a593Smuzhiyun.. code-block:: none 9861*4882a593Smuzhiyun 9862*4882a593Smuzhiyun | DEBUG: SITE files ['endian-little', 'bit-32', 'ix86-common', 'common-linux', 'common-glibc', 'i586-linux', 'common'] 9863*4882a593Smuzhiyun | DEBUG: Executing shell function do_compile 9864*4882a593Smuzhiyun | NOTE: make -j 16 9865*4882a593Smuzhiyun | make --no-print-directory all-am 9866*4882a593Smuzhiyun | /bin/mkdir -p include/near 9867*4882a593Smuzhiyun | /bin/mkdir -p include/near 9868*4882a593Smuzhiyun | /bin/mkdir -p include/near 9869*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9870*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/types.h include/near/types.h 9871*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9872*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/log.h include/near/log.h 9873*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9874*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/plugin.h include/near/plugin.h 9875*4882a593Smuzhiyun | /bin/mkdir -p include/near 9876*4882a593Smuzhiyun | /bin/mkdir -p include/near 9877*4882a593Smuzhiyun | /bin/mkdir -p include/near 9878*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9879*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/tag.h include/near/tag.h 9880*4882a593Smuzhiyun | /bin/mkdir -p include/near 9881*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9882*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/adapter.h include/near/adapter.h 9883*4882a593Smuzhiyun | /bin/mkdir -p include/near 9884*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9885*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/ndef.h include/near/ndef.h 9886*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9887*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/tlv.h include/near/tlv.h 9888*4882a593Smuzhiyun | /bin/mkdir -p include/near 9889*4882a593Smuzhiyun | /bin/mkdir -p include/near 9890*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9891*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/setting.h include/near/setting.h 9892*4882a593Smuzhiyun | /bin/mkdir -p include/near 9893*4882a593Smuzhiyun | /bin/mkdir -p include/near 9894*4882a593Smuzhiyun | /bin/mkdir -p include/near 9895*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9896*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/device.h include/near/device.h 9897*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9898*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/nfc_copy.h include/near/nfc_copy.h 9899*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9900*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/snep.h include/near/snep.h 9901*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9902*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/version.h include/near/version.h 9903*4882a593Smuzhiyun | ln -s /home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/work/i586-poky-linux/neard/ 9904*4882a593Smuzhiyun 0.14-r0/neard-0.14/include/dbus.h include/near/dbus.h 9905*4882a593Smuzhiyun | ./src/genbuiltin nfctype1 nfctype2 nfctype3 nfctype4 p2p > src/builtin.h 9906*4882a593Smuzhiyun | i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/pokybuild/yocto-autobuilder/nightly-x86/ 9907*4882a593Smuzhiyun build/build/tmp/sysroots/qemux86 -DHAVE_CONFIG_H -I. -I./include -I./src -I./gdbus -I/home/pokybuild/ 9908*4882a593Smuzhiyun yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/glib-2.0 9909*4882a593Smuzhiyun -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/tmp/sysroots/qemux86/usr/ 9910*4882a593Smuzhiyun lib/glib-2.0/include -I/home/pokybuild/yocto-autobuilder/nightly-x86/build/build/ 9911*4882a593Smuzhiyun tmp/sysroots/qemux86/usr/include/dbus-1.0 -I/home/pokybuild/yocto-autobuilder/ 9912*4882a593Smuzhiyun nightly-x86/build/build/tmp/sysroots/qemux86/usr/lib/dbus-1.0/include -I/home/pokybuild/yocto-autobuilder/ 9913*4882a593Smuzhiyun nightly-x86/build/build/tmp/sysroots/qemux86/usr/include/libnl3 9914*4882a593Smuzhiyun -DNEAR_PLUGIN_BUILTIN -DPLUGINDIR=\""/usr/lib/near/plugins"\" 9915*4882a593Smuzhiyun -DCONFIGDIR=\""/etc/neard\"" -O2 -pipe -g -feliminate-unused-debug-types -c 9916*4882a593Smuzhiyun -o tools/snep-send.o tools/snep-send.c 9917*4882a593Smuzhiyun | In file included from tools/snep-send.c:16:0: 9918*4882a593Smuzhiyun | tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory 9919*4882a593Smuzhiyun | #include <near/dbus.h> 9920*4882a593Smuzhiyun | ^ 9921*4882a593Smuzhiyun | compilation terminated. 9922*4882a593Smuzhiyun | make[1]: *** [tools/snep-send.o] Error 1 9923*4882a593Smuzhiyun | make[1]: *** Waiting for unfinished jobs.... 9924*4882a593Smuzhiyun | make: *** [all] Error 2 9925*4882a593Smuzhiyun | ERROR: oe_runmake failed 9926*4882a593Smuzhiyun 9927*4882a593SmuzhiyunReproducing the Error 9928*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~ 9929*4882a593Smuzhiyun 9930*4882a593SmuzhiyunBecause race conditions are intermittent, they do not manifest 9931*4882a593Smuzhiyunthemselves every time you do the build. In fact, most times the build 9932*4882a593Smuzhiyunwill complete without problems even though the potential race condition 9933*4882a593Smuzhiyunexists. Thus, once the error surfaces, you need a way to reproduce it. 9934*4882a593Smuzhiyun 9935*4882a593SmuzhiyunIn this example, compiling the "neard" package is causing the problem. 9936*4882a593SmuzhiyunSo the first thing to do is build "neard" locally. Before you start the 9937*4882a593Smuzhiyunbuild, set the 9938*4882a593Smuzhiyun:term:`PARALLEL_MAKE` variable 9939*4882a593Smuzhiyunin your ``local.conf`` file to a high number (e.g. "-j 20"). Using a 9940*4882a593Smuzhiyunhigh value for :term:`PARALLEL_MAKE` increases the chances of the race 9941*4882a593Smuzhiyuncondition showing up:: 9942*4882a593Smuzhiyun 9943*4882a593Smuzhiyun $ bitbake neard 9944*4882a593Smuzhiyun 9945*4882a593SmuzhiyunOnce the local build for "neard" completes, start a ``devshell`` build:: 9946*4882a593Smuzhiyun 9947*4882a593Smuzhiyun $ bitbake neard -c devshell 9948*4882a593Smuzhiyun 9949*4882a593SmuzhiyunFor information on how to use a ``devshell``, see the 9950*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:using a development shell`" section. 9951*4882a593Smuzhiyun 9952*4882a593SmuzhiyunIn the ``devshell``, do the following:: 9953*4882a593Smuzhiyun 9954*4882a593Smuzhiyun $ make clean 9955*4882a593Smuzhiyun $ make tools/snep-send.o 9956*4882a593Smuzhiyun 9957*4882a593SmuzhiyunThe ``devshell`` commands cause the failure to clearly 9958*4882a593Smuzhiyunbe visible. In this case, there is a missing dependency for the ``neard`` 9959*4882a593SmuzhiyunMakefile target. Here is some abbreviated, sample output with the 9960*4882a593Smuzhiyunmissing dependency clearly visible at the end:: 9961*4882a593Smuzhiyun 9962*4882a593Smuzhiyun i586-poky-linux-gcc -m32 -march=i586 --sysroot=/home/scott-lenovo/...... 9963*4882a593Smuzhiyun . 9964*4882a593Smuzhiyun . 9965*4882a593Smuzhiyun . 9966*4882a593Smuzhiyun tools/snep-send.c 9967*4882a593Smuzhiyun In file included from tools/snep-send.c:16:0: 9968*4882a593Smuzhiyun tools/../src/near.h:41:23: fatal error: near/dbus.h: No such file or directory 9969*4882a593Smuzhiyun #include <near/dbus.h> 9970*4882a593Smuzhiyun ^ 9971*4882a593Smuzhiyun compilation terminated. 9972*4882a593Smuzhiyun make: *** [tools/snep-send.o] Error 1 9973*4882a593Smuzhiyun $ 9974*4882a593Smuzhiyun 9975*4882a593Smuzhiyun 9976*4882a593SmuzhiyunCreating a Patch for the Fix 9977*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9978*4882a593Smuzhiyun 9979*4882a593SmuzhiyunBecause there is a missing dependency for the Makefile target, you need 9980*4882a593Smuzhiyunto patch the ``Makefile.am`` file, which is generated from 9981*4882a593Smuzhiyun``Makefile.in``. You can use Quilt to create the patch:: 9982*4882a593Smuzhiyun 9983*4882a593Smuzhiyun $ quilt new parallelmake.patch 9984*4882a593Smuzhiyun Patch patches/parallelmake.patch is now on top 9985*4882a593Smuzhiyun $ quilt add Makefile.am 9986*4882a593Smuzhiyun File Makefile.am added to patch patches/parallelmake.patch 9987*4882a593Smuzhiyun 9988*4882a593SmuzhiyunFor more information on using Quilt, see the 9989*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:using quilt in your workflow`" section. 9990*4882a593Smuzhiyun 9991*4882a593SmuzhiyunAt this point you need to make the edits to ``Makefile.am`` to add the 9992*4882a593Smuzhiyunmissing dependency. For our example, you have to add the following line 9993*4882a593Smuzhiyunto the file:: 9994*4882a593Smuzhiyun 9995*4882a593Smuzhiyun tools/snep-send.$(OBJEXT): include/near/dbus.h 9996*4882a593Smuzhiyun 9997*4882a593SmuzhiyunOnce you have edited the file, use the ``refresh`` command to create the 9998*4882a593Smuzhiyunpatch:: 9999*4882a593Smuzhiyun 10000*4882a593Smuzhiyun $ quilt refresh 10001*4882a593Smuzhiyun Refreshed patch patches/parallelmake.patch 10002*4882a593Smuzhiyun 10003*4882a593SmuzhiyunOnce the patch file is created, you need to add it back to the originating 10004*4882a593Smuzhiyunrecipe folder. Here is an example assuming a top-level 10005*4882a593Smuzhiyun:term:`Source Directory` named ``poky``:: 10006*4882a593Smuzhiyun 10007*4882a593Smuzhiyun $ cp patches/parallelmake.patch poky/meta/recipes-connectivity/neard/neard 10008*4882a593Smuzhiyun 10009*4882a593SmuzhiyunThe final thing you need to do to implement the fix in the build is to 10010*4882a593Smuzhiyunupdate the "neard" recipe (i.e. ``neard-0.14.bb``) so that the 10011*4882a593Smuzhiyun:term:`SRC_URI` statement includes 10012*4882a593Smuzhiyunthe patch file. The recipe file is in the folder above the patch. Here 10013*4882a593Smuzhiyunis what the edited :term:`SRC_URI` statement would look like:: 10014*4882a593Smuzhiyun 10015*4882a593Smuzhiyun SRC_URI = "${KERNELORG_MIRROR}/linux/network/nfc/${BPN}-${PV}.tar.xz \ 10016*4882a593Smuzhiyun file://neard.in \ 10017*4882a593Smuzhiyun file://neard.service.in \ 10018*4882a593Smuzhiyun file://parallelmake.patch \ 10019*4882a593Smuzhiyun " 10020*4882a593Smuzhiyun 10021*4882a593SmuzhiyunWith the patch complete and moved to the correct folder and the 10022*4882a593Smuzhiyun:term:`SRC_URI` statement updated, you can exit the ``devshell``:: 10023*4882a593Smuzhiyun 10024*4882a593Smuzhiyun $ exit 10025*4882a593Smuzhiyun 10026*4882a593SmuzhiyunTesting the Build 10027*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~ 10028*4882a593Smuzhiyun 10029*4882a593SmuzhiyunWith everything in place, you can get back to trying the build again 10030*4882a593Smuzhiyunlocally:: 10031*4882a593Smuzhiyun 10032*4882a593Smuzhiyun $ bitbake neard 10033*4882a593Smuzhiyun 10034*4882a593SmuzhiyunThis build should succeed. 10035*4882a593Smuzhiyun 10036*4882a593SmuzhiyunNow you can open up a ``devshell`` again and repeat the clean and make 10037*4882a593Smuzhiyunoperations as follows:: 10038*4882a593Smuzhiyun 10039*4882a593Smuzhiyun $ bitbake neard -c devshell 10040*4882a593Smuzhiyun $ make clean 10041*4882a593Smuzhiyun $ make tools/snep-send.o 10042*4882a593Smuzhiyun 10043*4882a593SmuzhiyunThe build should work without issue. 10044*4882a593Smuzhiyun 10045*4882a593SmuzhiyunAs with all solved problems, if they originated upstream, you need to 10046*4882a593Smuzhiyunsubmit the fix for the recipe in OE-Core and upstream so that the 10047*4882a593Smuzhiyunproblem is taken care of at its source. See the 10048*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:submitting a change to the yocto project`" 10049*4882a593Smuzhiyunsection for more information. 10050*4882a593Smuzhiyun 10051*4882a593SmuzhiyunDebugging With the GNU Project Debugger (GDB) Remotely 10052*4882a593Smuzhiyun------------------------------------------------------ 10053*4882a593Smuzhiyun 10054*4882a593SmuzhiyunGDB allows you to examine running programs, which in turn helps you to 10055*4882a593Smuzhiyununderstand and fix problems. It also allows you to perform post-mortem 10056*4882a593Smuzhiyunstyle analysis of program crashes. GDB is available as a package within 10057*4882a593Smuzhiyunthe Yocto Project and is installed in SDK images by default. See the 10058*4882a593Smuzhiyun":ref:`ref-manual/images:Images`" chapter in the Yocto 10059*4882a593SmuzhiyunProject Reference Manual for a description of these images. You can find 10060*4882a593Smuzhiyuninformation on GDB at https://sourceware.org/gdb/. 10061*4882a593Smuzhiyun 10062*4882a593Smuzhiyun.. note:: 10063*4882a593Smuzhiyun 10064*4882a593Smuzhiyun For best results, install debug (``-dbg``) packages for the applications you 10065*4882a593Smuzhiyun are going to debug. Doing so makes extra debug symbols available that give 10066*4882a593Smuzhiyun you more meaningful output. 10067*4882a593Smuzhiyun 10068*4882a593SmuzhiyunSometimes, due to memory or disk space constraints, it is not possible 10069*4882a593Smuzhiyunto use GDB directly on the remote target to debug applications. These 10070*4882a593Smuzhiyunconstraints arise because GDB needs to load the debugging information 10071*4882a593Smuzhiyunand the binaries of the process being debugged. Additionally, GDB needs 10072*4882a593Smuzhiyunto perform many computations to locate information such as function 10073*4882a593Smuzhiyunnames, variable names and values, stack traces and so forth - even 10074*4882a593Smuzhiyunbefore starting the debugging process. These extra computations place 10075*4882a593Smuzhiyunmore load on the target system and can alter the characteristics of the 10076*4882a593Smuzhiyunprogram being debugged. 10077*4882a593Smuzhiyun 10078*4882a593SmuzhiyunTo help get past the previously mentioned constraints, there are two 10079*4882a593Smuzhiyunmethods you can use: running a debuginfod server and using gdbserver. 10080*4882a593Smuzhiyun 10081*4882a593SmuzhiyunUsing the debuginfod server method 10082*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10083*4882a593Smuzhiyun 10084*4882a593Smuzhiyun``debuginfod`` from ``elfutils`` is a way to distribute ``debuginfo`` files. 10085*4882a593SmuzhiyunRunning a ``debuginfod`` server makes debug symbols readily available, 10086*4882a593Smuzhiyunwhich means you don't need to download debugging information 10087*4882a593Smuzhiyunand the binaries of the process being debugged. You can just fetch 10088*4882a593Smuzhiyundebug symbols from the server. 10089*4882a593Smuzhiyun 10090*4882a593SmuzhiyunTo run a ``debuginfod`` server, you need to do the following: 10091*4882a593Smuzhiyun 10092*4882a593Smuzhiyun- Ensure that ``debuginfod`` is present in :term:`DISTRO_FEATURES` 10093*4882a593Smuzhiyun (it already is in ``OpenEmbedded-core`` defaults and ``poky`` reference distribution). 10094*4882a593Smuzhiyun If not, set in your distro config file or in ``local.conf``:: 10095*4882a593Smuzhiyun 10096*4882a593Smuzhiyun DISTRO_FEATURES:append = " debuginfod" 10097*4882a593Smuzhiyun 10098*4882a593Smuzhiyun This distro feature enables the server and client library in ``elfutils``, 10099*4882a593Smuzhiyun and enables ``debuginfod`` support in clients (at the moment, ``gdb`` and ``binutils``). 10100*4882a593Smuzhiyun 10101*4882a593Smuzhiyun- Run the following commands to launch the ``debuginfod`` server on the host:: 10102*4882a593Smuzhiyun 10103*4882a593Smuzhiyun $ oe-debuginfod 10104*4882a593Smuzhiyun 10105*4882a593Smuzhiyun- To use ``debuginfod`` on the target, you need to know the ip:port where 10106*4882a593Smuzhiyun ``debuginfod`` is listening on the host (port defaults to 8002), and export 10107*4882a593Smuzhiyun that into the shell environment, for example in ``qemu``:: 10108*4882a593Smuzhiyun 10109*4882a593Smuzhiyun root@qemux86-64:~# export DEBUGINFOD_URLS="http://192.168.7.1:8002/" 10110*4882a593Smuzhiyun 10111*4882a593Smuzhiyun- Then debug info fetching should simply work when running the target ``gdb``, 10112*4882a593Smuzhiyun ``readelf`` or ``objdump``, for example:: 10113*4882a593Smuzhiyun 10114*4882a593Smuzhiyun root@qemux86-64:~# gdb /bin/cat 10115*4882a593Smuzhiyun ... 10116*4882a593Smuzhiyun Reading symbols from /bin/cat... 10117*4882a593Smuzhiyun Downloading separate debug info for /bin/cat... 10118*4882a593Smuzhiyun Reading symbols from /home/root/.cache/debuginfod_client/923dc4780cfbc545850c616bffa884b6b5eaf322/debuginfo... 10119*4882a593Smuzhiyun 10120*4882a593Smuzhiyun- It's also possible to use ``debuginfod-find`` to just query the server:: 10121*4882a593Smuzhiyun 10122*4882a593Smuzhiyun root@qemux86-64:~# debuginfod-find debuginfo /bin/ls 10123*4882a593Smuzhiyun /home/root/.cache/debuginfod_client/356edc585f7f82d46f94fcb87a86a3fe2d2e60bd/debuginfo 10124*4882a593Smuzhiyun 10125*4882a593Smuzhiyun 10126*4882a593SmuzhiyunUsing the gdbserver method 10127*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10128*4882a593Smuzhiyun 10129*4882a593Smuzhiyungdbserver, which runs on the remote target and does not load any 10130*4882a593Smuzhiyundebugging information from the debugged process. Instead, a GDB instance 10131*4882a593Smuzhiyunprocesses the debugging information that is run on a remote computer - 10132*4882a593Smuzhiyunthe host GDB. The host GDB then sends control commands to gdbserver to 10133*4882a593Smuzhiyunmake it stop or start the debugged program, as well as read or write 10134*4882a593Smuzhiyunmemory regions of that debugged program. All the debugging information 10135*4882a593Smuzhiyunloaded and processed as well as all the heavy debugging is done by the 10136*4882a593Smuzhiyunhost GDB. Offloading these processes gives the gdbserver running on the 10137*4882a593Smuzhiyuntarget a chance to remain small and fast. 10138*4882a593Smuzhiyun 10139*4882a593SmuzhiyunBecause the host GDB is responsible for loading the debugging 10140*4882a593Smuzhiyuninformation and for doing the necessary processing to make actual 10141*4882a593Smuzhiyundebugging happen, you have to make sure the host can access the 10142*4882a593Smuzhiyununstripped binaries complete with their debugging information and also 10143*4882a593Smuzhiyunbe sure the target is compiled with no optimizations. The host GDB must 10144*4882a593Smuzhiyunalso have local access to all the libraries used by the debugged 10145*4882a593Smuzhiyunprogram. Because gdbserver does not need any local debugging 10146*4882a593Smuzhiyuninformation, the binaries on the remote target can remain stripped. 10147*4882a593SmuzhiyunHowever, the binaries must also be compiled without optimization so they 10148*4882a593Smuzhiyunmatch the host's binaries. 10149*4882a593Smuzhiyun 10150*4882a593SmuzhiyunTo remain consistent with GDB documentation and terminology, the binary 10151*4882a593Smuzhiyunbeing debugged on the remote target machine is referred to as the 10152*4882a593Smuzhiyun"inferior" binary. For documentation on GDB see the `GDB 10153*4882a593Smuzhiyunsite <https://sourceware.org/gdb/documentation/>`__. 10154*4882a593Smuzhiyun 10155*4882a593SmuzhiyunThe following steps show you how to debug using the GNU project 10156*4882a593Smuzhiyundebugger. 10157*4882a593Smuzhiyun 10158*4882a593Smuzhiyun1. *Configure your build system to construct the companion debug 10159*4882a593Smuzhiyun filesystem:* 10160*4882a593Smuzhiyun 10161*4882a593Smuzhiyun In your ``local.conf`` file, set the following:: 10162*4882a593Smuzhiyun 10163*4882a593Smuzhiyun IMAGE_GEN_DEBUGFS = "1" 10164*4882a593Smuzhiyun IMAGE_FSTYPES_DEBUGFS = "tar.bz2" 10165*4882a593Smuzhiyun 10166*4882a593Smuzhiyun These options cause the 10167*4882a593Smuzhiyun OpenEmbedded build system to generate a special companion filesystem 10168*4882a593Smuzhiyun fragment, which contains the matching source and debug symbols to 10169*4882a593Smuzhiyun your deployable filesystem. The build system does this by looking at 10170*4882a593Smuzhiyun what is in the deployed filesystem, and pulling the corresponding 10171*4882a593Smuzhiyun ``-dbg`` packages. 10172*4882a593Smuzhiyun 10173*4882a593Smuzhiyun The companion debug filesystem is not a complete filesystem, but only 10174*4882a593Smuzhiyun contains the debug fragments. This filesystem must be combined with 10175*4882a593Smuzhiyun the full filesystem for debugging. Subsequent steps in this procedure 10176*4882a593Smuzhiyun show how to combine the partial filesystem with the full filesystem. 10177*4882a593Smuzhiyun 10178*4882a593Smuzhiyun2. *Configure the system to include gdbserver in the target filesystem:* 10179*4882a593Smuzhiyun 10180*4882a593Smuzhiyun Make the following addition in either your ``local.conf`` file or in 10181*4882a593Smuzhiyun an image recipe:: 10182*4882a593Smuzhiyun 10183*4882a593Smuzhiyun IMAGE_INSTALL:append = " gdbserver" 10184*4882a593Smuzhiyun 10185*4882a593Smuzhiyun The change makes 10186*4882a593Smuzhiyun sure the ``gdbserver`` package is included. 10187*4882a593Smuzhiyun 10188*4882a593Smuzhiyun3. *Build the environment:* 10189*4882a593Smuzhiyun 10190*4882a593Smuzhiyun Use the following command to construct the image and the companion 10191*4882a593Smuzhiyun Debug Filesystem:: 10192*4882a593Smuzhiyun 10193*4882a593Smuzhiyun $ bitbake image 10194*4882a593Smuzhiyun 10195*4882a593Smuzhiyun Build the cross GDB component and 10196*4882a593Smuzhiyun make it available for debugging. Build the SDK that matches the 10197*4882a593Smuzhiyun image. Building the SDK is best for a production build that can be 10198*4882a593Smuzhiyun used later for debugging, especially during long term maintenance:: 10199*4882a593Smuzhiyun 10200*4882a593Smuzhiyun $ bitbake -c populate_sdk image 10201*4882a593Smuzhiyun 10202*4882a593Smuzhiyun Alternatively, you can build the minimal toolchain components that 10203*4882a593Smuzhiyun match the target. Doing so creates a smaller than typical SDK and 10204*4882a593Smuzhiyun only contains a minimal set of components with which to build simple 10205*4882a593Smuzhiyun test applications, as well as run the debugger:: 10206*4882a593Smuzhiyun 10207*4882a593Smuzhiyun $ bitbake meta-toolchain 10208*4882a593Smuzhiyun 10209*4882a593Smuzhiyun A final method is to build Gdb itself within the build system:: 10210*4882a593Smuzhiyun 10211*4882a593Smuzhiyun $ bitbake gdb-cross-<architecture> 10212*4882a593Smuzhiyun 10213*4882a593Smuzhiyun Doing so produces a temporary copy of 10214*4882a593Smuzhiyun ``cross-gdb`` you can use for debugging during development. While 10215*4882a593Smuzhiyun this is the quickest approach, the two previous methods in this step 10216*4882a593Smuzhiyun are better when considering long-term maintenance strategies. 10217*4882a593Smuzhiyun 10218*4882a593Smuzhiyun .. note:: 10219*4882a593Smuzhiyun 10220*4882a593Smuzhiyun If you run ``bitbake gdb-cross``, the OpenEmbedded build system suggests 10221*4882a593Smuzhiyun the actual image (e.g. ``gdb-cross-i586``). The suggestion is usually the 10222*4882a593Smuzhiyun actual name you want to use. 10223*4882a593Smuzhiyun 10224*4882a593Smuzhiyun4. *Set up the* ``debugfs``\ *:* 10225*4882a593Smuzhiyun 10226*4882a593Smuzhiyun Run the following commands to set up the ``debugfs``:: 10227*4882a593Smuzhiyun 10228*4882a593Smuzhiyun $ mkdir debugfs 10229*4882a593Smuzhiyun $ cd debugfs 10230*4882a593Smuzhiyun $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image.rootfs.tar.bz2 10231*4882a593Smuzhiyun $ tar xvfj build-dir/tmp-glibc/deploy/images/machine/image-dbg.rootfs.tar.bz2 10232*4882a593Smuzhiyun 10233*4882a593Smuzhiyun5. *Set up GDB:* 10234*4882a593Smuzhiyun 10235*4882a593Smuzhiyun Install the SDK (if you built one) and then source the correct 10236*4882a593Smuzhiyun environment file. Sourcing the environment file puts the SDK in your 10237*4882a593Smuzhiyun ``PATH`` environment variable. 10238*4882a593Smuzhiyun 10239*4882a593Smuzhiyun If you are using the build system, Gdb is located in 10240*4882a593Smuzhiyun `build-dir`\ ``/tmp/sysroots/``\ `host`\ ``/usr/bin/``\ `architecture`\ ``/``\ `architecture`\ ``-gdb`` 10241*4882a593Smuzhiyun 10242*4882a593Smuzhiyun6. *Boot the target:* 10243*4882a593Smuzhiyun 10244*4882a593Smuzhiyun For information on how to run QEMU, see the `QEMU 10245*4882a593Smuzhiyun Documentation <https://wiki.qemu.org/Documentation/GettingStartedDevelopers>`__. 10246*4882a593Smuzhiyun 10247*4882a593Smuzhiyun .. note:: 10248*4882a593Smuzhiyun 10249*4882a593Smuzhiyun Be sure to verify that your host can access the target via TCP. 10250*4882a593Smuzhiyun 10251*4882a593Smuzhiyun7. *Debug a program:* 10252*4882a593Smuzhiyun 10253*4882a593Smuzhiyun Debugging a program involves running gdbserver on the target and then 10254*4882a593Smuzhiyun running Gdb on the host. The example in this step debugs ``gzip``: 10255*4882a593Smuzhiyun 10256*4882a593Smuzhiyun .. code-block:: shell 10257*4882a593Smuzhiyun 10258*4882a593Smuzhiyun root@qemux86:~# gdbserver localhost:1234 /bin/gzip —help 10259*4882a593Smuzhiyun 10260*4882a593Smuzhiyun For 10261*4882a593Smuzhiyun additional gdbserver options, see the `GDB Server 10262*4882a593Smuzhiyun Documentation <https://www.gnu.org/software/gdb/documentation/>`__. 10263*4882a593Smuzhiyun 10264*4882a593Smuzhiyun After running gdbserver on the target, you need to run Gdb on the 10265*4882a593Smuzhiyun host and configure it and connect to the target. Use these commands:: 10266*4882a593Smuzhiyun 10267*4882a593Smuzhiyun $ cd directory-holding-the-debugfs-directory 10268*4882a593Smuzhiyun $ arch-gdb 10269*4882a593Smuzhiyun (gdb) set sysroot debugfs 10270*4882a593Smuzhiyun (gdb) set substitute-path /usr/src/debug debugfs/usr/src/debug 10271*4882a593Smuzhiyun (gdb) target remote IP-of-target:1234 10272*4882a593Smuzhiyun 10273*4882a593Smuzhiyun At this 10274*4882a593Smuzhiyun point, everything should automatically load (i.e. matching binaries, 10275*4882a593Smuzhiyun symbols and headers). 10276*4882a593Smuzhiyun 10277*4882a593Smuzhiyun .. note:: 10278*4882a593Smuzhiyun 10279*4882a593Smuzhiyun The Gdb ``set`` commands in the previous example can be placed into the 10280*4882a593Smuzhiyun users ``~/.gdbinit`` file. Upon starting, Gdb automatically runs whatever 10281*4882a593Smuzhiyun commands are in that file. 10282*4882a593Smuzhiyun 10283*4882a593Smuzhiyun8. *Deploying without a full image rebuild:* 10284*4882a593Smuzhiyun 10285*4882a593Smuzhiyun In many cases, during development you want a quick method to deploy a 10286*4882a593Smuzhiyun new binary to the target and debug it, without waiting for a full 10287*4882a593Smuzhiyun image build. 10288*4882a593Smuzhiyun 10289*4882a593Smuzhiyun One approach to solving this situation is to just build the component 10290*4882a593Smuzhiyun you want to debug. Once you have built the component, copy the 10291*4882a593Smuzhiyun executable directly to both the target and the host ``debugfs``. 10292*4882a593Smuzhiyun 10293*4882a593Smuzhiyun If the binary is processed through the debug splitting in 10294*4882a593Smuzhiyun OpenEmbedded, you should also copy the debug items (i.e. ``.debug`` 10295*4882a593Smuzhiyun contents and corresponding ``/usr/src/debug`` files) from the work 10296*4882a593Smuzhiyun directory. Here is an example:: 10297*4882a593Smuzhiyun 10298*4882a593Smuzhiyun $ bitbake bash 10299*4882a593Smuzhiyun $ bitbake -c devshell bash 10300*4882a593Smuzhiyun $ cd .. 10301*4882a593Smuzhiyun $ scp packages-split/bash/bin/bash target:/bin/bash 10302*4882a593Smuzhiyun $ cp -a packages-split/bash-dbg/\* path/debugfs 10303*4882a593Smuzhiyun 10304*4882a593SmuzhiyunDebugging with the GNU Project Debugger (GDB) on the Target 10305*4882a593Smuzhiyun----------------------------------------------------------- 10306*4882a593Smuzhiyun 10307*4882a593SmuzhiyunThe previous section addressed using GDB remotely for debugging 10308*4882a593Smuzhiyunpurposes, which is the most usual case due to the inherent hardware 10309*4882a593Smuzhiyunlimitations on many embedded devices. However, debugging in the target 10310*4882a593Smuzhiyunhardware itself is also possible with more powerful devices. This 10311*4882a593Smuzhiyunsection describes what you need to do in order to support using GDB to 10312*4882a593Smuzhiyundebug on the target hardware. 10313*4882a593Smuzhiyun 10314*4882a593SmuzhiyunTo support this kind of debugging, you need do the following: 10315*4882a593Smuzhiyun 10316*4882a593Smuzhiyun- Ensure that GDB is on the target. You can do this by adding "gdb" to 10317*4882a593Smuzhiyun :term:`IMAGE_INSTALL`:: 10318*4882a593Smuzhiyun 10319*4882a593Smuzhiyun IMAGE_INSTALL:append = " gdb" 10320*4882a593Smuzhiyun 10321*4882a593Smuzhiyun Alternatively, you can add "tools-debug" to :term:`IMAGE_FEATURES`:: 10322*4882a593Smuzhiyun 10323*4882a593Smuzhiyun IMAGE_FEATURES:append = " tools-debug" 10324*4882a593Smuzhiyun 10325*4882a593Smuzhiyun- Ensure that debug symbols are present. You can make sure these 10326*4882a593Smuzhiyun symbols are present by installing ``-dbg``:: 10327*4882a593Smuzhiyun 10328*4882a593Smuzhiyun IMAGE_INSTALL:append = "packagename-dbg" 10329*4882a593Smuzhiyun 10330*4882a593Smuzhiyun Alternatively, you can do the following to include 10331*4882a593Smuzhiyun all the debug symbols:: 10332*4882a593Smuzhiyun 10333*4882a593Smuzhiyun IMAGE_FEATURES:append = " dbg-pkgs" 10334*4882a593Smuzhiyun 10335*4882a593Smuzhiyun.. note:: 10336*4882a593Smuzhiyun 10337*4882a593Smuzhiyun To improve the debug information accuracy, you can reduce the level 10338*4882a593Smuzhiyun of optimization used by the compiler. For example, when adding the 10339*4882a593Smuzhiyun following line to your ``local.conf`` file, you will reduce optimization 10340*4882a593Smuzhiyun from :term:`FULL_OPTIMIZATION` of "-O2" to :term:`DEBUG_OPTIMIZATION` 10341*4882a593Smuzhiyun of "-O -fno-omit-frame-pointer":: 10342*4882a593Smuzhiyun 10343*4882a593Smuzhiyun DEBUG_BUILD = "1" 10344*4882a593Smuzhiyun 10345*4882a593Smuzhiyun Consider that this will reduce the application's performance and is 10346*4882a593Smuzhiyun recommended only for debugging purposes. 10347*4882a593Smuzhiyun 10348*4882a593SmuzhiyunOther Debugging Tips 10349*4882a593Smuzhiyun-------------------- 10350*4882a593Smuzhiyun 10351*4882a593SmuzhiyunHere are some other tips that you might find useful: 10352*4882a593Smuzhiyun 10353*4882a593Smuzhiyun- When adding new packages, it is worth watching for undesirable items 10354*4882a593Smuzhiyun making their way into compiler command lines. For example, you do not 10355*4882a593Smuzhiyun want references to local system files like ``/usr/lib/`` or 10356*4882a593Smuzhiyun ``/usr/include/``. 10357*4882a593Smuzhiyun 10358*4882a593Smuzhiyun- If you want to remove the ``psplash`` boot splashscreen, add 10359*4882a593Smuzhiyun ``psplash=false`` to the kernel command line. Doing so prevents 10360*4882a593Smuzhiyun ``psplash`` from loading and thus allows you to see the console. It 10361*4882a593Smuzhiyun is also possible to switch out of the splashscreen by switching the 10362*4882a593Smuzhiyun virtual console (e.g. Fn+Left or Fn+Right on a Zaurus). 10363*4882a593Smuzhiyun 10364*4882a593Smuzhiyun- Removing :term:`TMPDIR` (usually 10365*4882a593Smuzhiyun ``tmp/``, within the 10366*4882a593Smuzhiyun :term:`Build Directory`) can often fix 10367*4882a593Smuzhiyun temporary build issues. Removing :term:`TMPDIR` is usually a relatively 10368*4882a593Smuzhiyun cheap operation, because task output will be cached in 10369*4882a593Smuzhiyun :term:`SSTATE_DIR` (usually 10370*4882a593Smuzhiyun ``sstate-cache/``, which is also in the Build Directory). 10371*4882a593Smuzhiyun 10372*4882a593Smuzhiyun .. note:: 10373*4882a593Smuzhiyun 10374*4882a593Smuzhiyun Removing :term:`TMPDIR` might be a workaround rather than a fix. 10375*4882a593Smuzhiyun Consequently, trying to determine the underlying cause of an issue before 10376*4882a593Smuzhiyun removing the directory is a good idea. 10377*4882a593Smuzhiyun 10378*4882a593Smuzhiyun- Understanding how a feature is used in practice within existing 10379*4882a593Smuzhiyun recipes can be very helpful. It is recommended that you configure 10380*4882a593Smuzhiyun some method that allows you to quickly search through files. 10381*4882a593Smuzhiyun 10382*4882a593Smuzhiyun Using GNU Grep, you can use the following shell function to 10383*4882a593Smuzhiyun recursively search through common recipe-related files, skipping 10384*4882a593Smuzhiyun binary files, ``.git`` directories, and the Build Directory (assuming 10385*4882a593Smuzhiyun its name starts with "build"):: 10386*4882a593Smuzhiyun 10387*4882a593Smuzhiyun g() { 10388*4882a593Smuzhiyun grep -Ir \ 10389*4882a593Smuzhiyun --exclude-dir=.git \ 10390*4882a593Smuzhiyun --exclude-dir='build*' \ 10391*4882a593Smuzhiyun --include='*.bb*' \ 10392*4882a593Smuzhiyun --include='*.inc*' \ 10393*4882a593Smuzhiyun --include='*.conf*' \ 10394*4882a593Smuzhiyun --include='*.py*' \ 10395*4882a593Smuzhiyun "$@" 10396*4882a593Smuzhiyun } 10397*4882a593Smuzhiyun 10398*4882a593Smuzhiyun Following are some usage examples:: 10399*4882a593Smuzhiyun 10400*4882a593Smuzhiyun $ g FOO # Search recursively for "FOO" 10401*4882a593Smuzhiyun $ g -i foo # Search recursively for "foo", ignoring case 10402*4882a593Smuzhiyun $ g -w FOO # Search recursively for "FOO" as a word, ignoring e.g. "FOOBAR" 10403*4882a593Smuzhiyun 10404*4882a593Smuzhiyun If figuring 10405*4882a593Smuzhiyun out how some feature works requires a lot of searching, it might 10406*4882a593Smuzhiyun indicate that the documentation should be extended or improved. In 10407*4882a593Smuzhiyun such cases, consider filing a documentation bug using the Yocto 10408*4882a593Smuzhiyun Project implementation of 10409*4882a593Smuzhiyun :yocto_bugs:`Bugzilla <>`. For information on 10410*4882a593Smuzhiyun how to submit a bug against the Yocto Project, see the Yocto Project 10411*4882a593Smuzhiyun Bugzilla :yocto_wiki:`wiki page </Bugzilla_Configuration_and_Bug_Tracking>` 10412*4882a593Smuzhiyun and the 10413*4882a593Smuzhiyun ":ref:`dev-manual/common-tasks:submitting a defect against the yocto project`" 10414*4882a593Smuzhiyun section. 10415*4882a593Smuzhiyun 10416*4882a593Smuzhiyun .. note:: 10417*4882a593Smuzhiyun 10418*4882a593Smuzhiyun The manuals might not be the right place to document variables 10419*4882a593Smuzhiyun that are purely internal and have a limited scope (e.g. internal 10420*4882a593Smuzhiyun variables used to implement a single ``.bbclass`` file). 10421*4882a593Smuzhiyun 10422*4882a593SmuzhiyunMaking Changes to the Yocto Project 10423*4882a593Smuzhiyun=================================== 10424*4882a593Smuzhiyun 10425*4882a593SmuzhiyunBecause the Yocto Project is an open-source, community-based project, 10426*4882a593Smuzhiyunyou can effect changes to the project. This section presents procedures 10427*4882a593Smuzhiyunthat show you how to submit a defect against the project and how to 10428*4882a593Smuzhiyunsubmit a change. 10429*4882a593Smuzhiyun 10430*4882a593SmuzhiyunSubmitting a Defect Against the Yocto Project 10431*4882a593Smuzhiyun--------------------------------------------- 10432*4882a593Smuzhiyun 10433*4882a593SmuzhiyunUse the Yocto Project implementation of 10434*4882a593Smuzhiyun`Bugzilla <https://www.bugzilla.org/about/>`__ to submit a defect (bug) 10435*4882a593Smuzhiyunagainst the Yocto Project. For additional information on this 10436*4882a593Smuzhiyunimplementation of Bugzilla see the ":ref:`Yocto Project 10437*4882a593SmuzhiyunBugzilla <resources-bugtracker>`" section in the 10438*4882a593SmuzhiyunYocto Project Reference Manual. For more detail on any of the following 10439*4882a593Smuzhiyunsteps, see the Yocto Project 10440*4882a593Smuzhiyun:yocto_wiki:`Bugzilla wiki page </Bugzilla_Configuration_and_Bug_Tracking>`. 10441*4882a593Smuzhiyun 10442*4882a593SmuzhiyunUse the following general steps to submit a bug: 10443*4882a593Smuzhiyun 10444*4882a593Smuzhiyun1. Open the Yocto Project implementation of :yocto_bugs:`Bugzilla <>`. 10445*4882a593Smuzhiyun 10446*4882a593Smuzhiyun2. Click "File a Bug" to enter a new bug. 10447*4882a593Smuzhiyun 10448*4882a593Smuzhiyun3. Choose the appropriate "Classification", "Product", and "Component" 10449*4882a593Smuzhiyun for which the bug was found. Bugs for the Yocto Project fall into 10450*4882a593Smuzhiyun one of several classifications, which in turn break down into 10451*4882a593Smuzhiyun several products and components. For example, for a bug against the 10452*4882a593Smuzhiyun ``meta-intel`` layer, you would choose "Build System, Metadata & 10453*4882a593Smuzhiyun Runtime", "BSPs", and "bsps-meta-intel", respectively. 10454*4882a593Smuzhiyun 10455*4882a593Smuzhiyun4. Choose the "Version" of the Yocto Project for which you found the 10456*4882a593Smuzhiyun bug (e.g. &DISTRO;). 10457*4882a593Smuzhiyun 10458*4882a593Smuzhiyun5. Determine and select the "Severity" of the bug. The severity 10459*4882a593Smuzhiyun indicates how the bug impacted your work. 10460*4882a593Smuzhiyun 10461*4882a593Smuzhiyun6. Choose the "Hardware" that the bug impacts. 10462*4882a593Smuzhiyun 10463*4882a593Smuzhiyun7. Choose the "Architecture" that the bug impacts. 10464*4882a593Smuzhiyun 10465*4882a593Smuzhiyun8. Choose a "Documentation change" item for the bug. Fixing a bug might 10466*4882a593Smuzhiyun or might not affect the Yocto Project documentation. If you are 10467*4882a593Smuzhiyun unsure of the impact to the documentation, select "Don't Know". 10468*4882a593Smuzhiyun 10469*4882a593Smuzhiyun9. Provide a brief "Summary" of the bug. Try to limit your summary to 10470*4882a593Smuzhiyun just a line or two and be sure to capture the essence of the bug. 10471*4882a593Smuzhiyun 10472*4882a593Smuzhiyun10. Provide a detailed "Description" of the bug. You should provide as 10473*4882a593Smuzhiyun much detail as you can about the context, behavior, output, and so 10474*4882a593Smuzhiyun forth that surrounds the bug. You can even attach supporting files 10475*4882a593Smuzhiyun for output from logs by using the "Add an attachment" button. 10476*4882a593Smuzhiyun 10477*4882a593Smuzhiyun11. Click the "Submit Bug" button submit the bug. A new Bugzilla number 10478*4882a593Smuzhiyun is assigned to the bug and the defect is logged in the bug tracking 10479*4882a593Smuzhiyun system. 10480*4882a593Smuzhiyun 10481*4882a593SmuzhiyunOnce you file a bug, the bug is processed by the Yocto Project Bug 10482*4882a593SmuzhiyunTriage Team and further details concerning the bug are assigned (e.g. 10483*4882a593Smuzhiyunpriority and owner). You are the "Submitter" of the bug and any further 10484*4882a593Smuzhiyuncategorization, progress, or comments on the bug result in Bugzilla 10485*4882a593Smuzhiyunsending you an automated email concerning the particular change or 10486*4882a593Smuzhiyunprogress to the bug. 10487*4882a593Smuzhiyun 10488*4882a593SmuzhiyunSubmitting a Change to the Yocto Project 10489*4882a593Smuzhiyun---------------------------------------- 10490*4882a593Smuzhiyun 10491*4882a593SmuzhiyunContributions to the Yocto Project and OpenEmbedded are very welcome. 10492*4882a593SmuzhiyunBecause the system is extremely configurable and flexible, we recognize 10493*4882a593Smuzhiyunthat developers will want to extend, configure or optimize it for their 10494*4882a593Smuzhiyunspecific uses. 10495*4882a593Smuzhiyun 10496*4882a593SmuzhiyunThe Yocto Project uses a mailing list and a patch-based workflow that is 10497*4882a593Smuzhiyunsimilar to the Linux kernel but contains important differences. In 10498*4882a593Smuzhiyungeneral, there is a mailing list through which you can submit patches. You 10499*4882a593Smuzhiyunshould send patches to the appropriate mailing list so that they can be 10500*4882a593Smuzhiyunreviewed and merged by the appropriate maintainer. The specific mailing 10501*4882a593Smuzhiyunlist you need to use depends on the location of the code you are 10502*4882a593Smuzhiyunchanging. Each component (e.g. layer) should have a ``README`` file that 10503*4882a593Smuzhiyunindicates where to send the changes and which process to follow. 10504*4882a593Smuzhiyun 10505*4882a593SmuzhiyunYou can send the patch to the mailing list using whichever approach you 10506*4882a593Smuzhiyunfeel comfortable with to generate the patch. Once sent, the patch is 10507*4882a593Smuzhiyunusually reviewed by the community at large. If somebody has concerns 10508*4882a593Smuzhiyunwith the patch, they will usually voice their concern over the mailing 10509*4882a593Smuzhiyunlist. If a patch does not receive any negative reviews, the maintainer 10510*4882a593Smuzhiyunof the affected layer typically takes the patch, tests it, and then 10511*4882a593Smuzhiyunbased on successful testing, merges the patch. 10512*4882a593Smuzhiyun 10513*4882a593SmuzhiyunThe "poky" repository, which is the Yocto Project's reference build 10514*4882a593Smuzhiyunenvironment, is a hybrid repository that contains several individual 10515*4882a593Smuzhiyunpieces (e.g. BitBake, Metadata, documentation, and so forth) built using 10516*4882a593Smuzhiyunthe combo-layer tool. The upstream location used for submitting changes 10517*4882a593Smuzhiyunvaries by component: 10518*4882a593Smuzhiyun 10519*4882a593Smuzhiyun- *Core Metadata:* Send your patch to the 10520*4882a593Smuzhiyun :oe_lists:`openembedded-core </g/openembedded-core>` 10521*4882a593Smuzhiyun mailing list. For example, a change to anything under the ``meta`` or 10522*4882a593Smuzhiyun ``scripts`` directories should be sent to this mailing list. 10523*4882a593Smuzhiyun 10524*4882a593Smuzhiyun- *BitBake:* For changes to BitBake (i.e. anything under the 10525*4882a593Smuzhiyun ``bitbake`` directory), send your patch to the 10526*4882a593Smuzhiyun :oe_lists:`bitbake-devel </g/bitbake-devel>` 10527*4882a593Smuzhiyun mailing list. 10528*4882a593Smuzhiyun 10529*4882a593Smuzhiyun- *"meta-\*" trees:* These trees contain Metadata. Use the 10530*4882a593Smuzhiyun :yocto_lists:`poky </g/poky>` mailing list. 10531*4882a593Smuzhiyun 10532*4882a593Smuzhiyun- *Documentation*: For changes to the Yocto Project documentation, use the 10533*4882a593Smuzhiyun :yocto_lists:`docs </g/docs>` mailing list. 10534*4882a593Smuzhiyun 10535*4882a593SmuzhiyunFor changes to other layers hosted in the Yocto Project source 10536*4882a593Smuzhiyunrepositories (i.e. ``yoctoproject.org``) and tools use the 10537*4882a593Smuzhiyun:yocto_lists:`Yocto Project </g/yocto/>` general mailing list. 10538*4882a593Smuzhiyun 10539*4882a593Smuzhiyun.. note:: 10540*4882a593Smuzhiyun 10541*4882a593Smuzhiyun Sometimes a layer's documentation specifies to use a particular 10542*4882a593Smuzhiyun mailing list. If so, use that list. 10543*4882a593Smuzhiyun 10544*4882a593SmuzhiyunFor additional recipes that do not fit into the core Metadata, you 10545*4882a593Smuzhiyunshould determine which layer the recipe should go into and submit the 10546*4882a593Smuzhiyunchange in the manner recommended by the documentation (e.g. the 10547*4882a593Smuzhiyun``README`` file) supplied with the layer. If in doubt, please ask on the 10548*4882a593SmuzhiyunYocto general mailing list or on the openembedded-devel mailing list. 10549*4882a593Smuzhiyun 10550*4882a593SmuzhiyunYou can also push a change upstream and request a maintainer to pull the 10551*4882a593Smuzhiyunchange into the component's upstream repository. You do this by pushing 10552*4882a593Smuzhiyunto a contribution repository that is upstream. See the 10553*4882a593Smuzhiyun":ref:`overview-manual/development-environment:git workflows and the yocto project`" 10554*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual for additional 10555*4882a593Smuzhiyunconcepts on working in the Yocto Project development environment. 10556*4882a593Smuzhiyun 10557*4882a593SmuzhiyunMaintainers commonly use ``-next`` branches to test submissions prior to 10558*4882a593Smuzhiyunmerging patches. Thus, you can get an idea of the status of a patch based on 10559*4882a593Smuzhiyunwhether the patch has been merged into one of these branches. The commonly 10560*4882a593Smuzhiyunused testing branches for OpenEmbedded-Core are as follows: 10561*4882a593Smuzhiyun 10562*4882a593Smuzhiyun- *openembedded-core "master-next" branch:* This branch is part of the 10563*4882a593Smuzhiyun :oe_git:`openembedded-core </openembedded-core/>` repository and contains 10564*4882a593Smuzhiyun proposed changes to the core metadata. 10565*4882a593Smuzhiyun 10566*4882a593Smuzhiyun- *poky "master-next" branch:* This branch is part of the 10567*4882a593Smuzhiyun :yocto_git:`poky </poky/>` repository and combines proposed 10568*4882a593Smuzhiyun changes to bitbake, the core metadata and the poky distro. 10569*4882a593Smuzhiyun 10570*4882a593SmuzhiyunSimilarly, stable branches maintained by the project may have corresponding 10571*4882a593Smuzhiyun``-next`` branches which collect proposed changes. For example, 10572*4882a593Smuzhiyun``&DISTRO_NAME_NO_CAP;-next`` and ``&DISTRO_NAME_NO_CAP_MINUS_ONE;-next`` 10573*4882a593Smuzhiyunbranches in both the "openembdedded-core" and "poky" repositories. 10574*4882a593Smuzhiyun 10575*4882a593SmuzhiyunOther layers may have similar testing branches but there is no formal 10576*4882a593Smuzhiyunrequirement or standard for these so please check the documentation for the 10577*4882a593Smuzhiyunlayers you are contributing to. 10578*4882a593Smuzhiyun 10579*4882a593SmuzhiyunThe following sections provide procedures for submitting a change. 10580*4882a593Smuzhiyun 10581*4882a593SmuzhiyunPreparing Changes for Submission 10582*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10583*4882a593Smuzhiyun 10584*4882a593Smuzhiyun1. *Make Your Changes Locally:* Make your changes in your local Git 10585*4882a593Smuzhiyun repository. You should make small, controlled, isolated changes. 10586*4882a593Smuzhiyun Keeping changes small and isolated aids review, makes 10587*4882a593Smuzhiyun merging/rebasing easier and keeps the change history clean should 10588*4882a593Smuzhiyun anyone need to refer to it in future. 10589*4882a593Smuzhiyun 10590*4882a593Smuzhiyun2. *Stage Your Changes:* Stage your changes by using the ``git add`` 10591*4882a593Smuzhiyun command on each file you changed. 10592*4882a593Smuzhiyun 10593*4882a593Smuzhiyun3. *Commit Your Changes:* Commit the change by using the ``git commit`` 10594*4882a593Smuzhiyun command. Make sure your commit information follows standards by 10595*4882a593Smuzhiyun following these accepted conventions: 10596*4882a593Smuzhiyun 10597*4882a593Smuzhiyun - Be sure to include a "Signed-off-by:" line in the same style as 10598*4882a593Smuzhiyun required by the Linux kernel. This can be done by using the 10599*4882a593Smuzhiyun ``git commit -s`` command. Adding this line signifies that you, 10600*4882a593Smuzhiyun the submitter, have agreed to the Developer's Certificate of 10601*4882a593Smuzhiyun Origin 1.1 as follows: 10602*4882a593Smuzhiyun 10603*4882a593Smuzhiyun .. code-block:: none 10604*4882a593Smuzhiyun 10605*4882a593Smuzhiyun Developer's Certificate of Origin 1.1 10606*4882a593Smuzhiyun 10607*4882a593Smuzhiyun By making a contribution to this project, I certify that: 10608*4882a593Smuzhiyun 10609*4882a593Smuzhiyun (a) The contribution was created in whole or in part by me and I 10610*4882a593Smuzhiyun have the right to submit it under the open source license 10611*4882a593Smuzhiyun indicated in the file; or 10612*4882a593Smuzhiyun 10613*4882a593Smuzhiyun (b) The contribution is based upon previous work that, to the best 10614*4882a593Smuzhiyun of my knowledge, is covered under an appropriate open source 10615*4882a593Smuzhiyun license and I have the right under that license to submit that 10616*4882a593Smuzhiyun work with modifications, whether created in whole or in part 10617*4882a593Smuzhiyun by me, under the same open source license (unless I am 10618*4882a593Smuzhiyun permitted to submit under a different license), as indicated 10619*4882a593Smuzhiyun in the file; or 10620*4882a593Smuzhiyun 10621*4882a593Smuzhiyun (c) The contribution was provided directly to me by some other 10622*4882a593Smuzhiyun person who certified (a), (b) or (c) and I have not modified 10623*4882a593Smuzhiyun it. 10624*4882a593Smuzhiyun 10625*4882a593Smuzhiyun (d) I understand and agree that this project and the contribution 10626*4882a593Smuzhiyun are public and that a record of the contribution (including all 10627*4882a593Smuzhiyun personal information I submit with it, including my sign-off) is 10628*4882a593Smuzhiyun maintained indefinitely and may be redistributed consistent with 10629*4882a593Smuzhiyun this project or the open source license(s) involved. 10630*4882a593Smuzhiyun 10631*4882a593Smuzhiyun - Provide a single-line summary of the change and, if more 10632*4882a593Smuzhiyun explanation is needed, provide more detail in the body of the 10633*4882a593Smuzhiyun commit. This summary is typically viewable in the "shortlist" of 10634*4882a593Smuzhiyun changes. Thus, providing something short and descriptive that 10635*4882a593Smuzhiyun gives the reader a summary of the change is useful when viewing a 10636*4882a593Smuzhiyun list of many commits. You should prefix this short description 10637*4882a593Smuzhiyun with the recipe name (if changing a recipe), or else with the 10638*4882a593Smuzhiyun short form path to the file being changed. 10639*4882a593Smuzhiyun 10640*4882a593Smuzhiyun - For the body of the commit message, provide detailed information 10641*4882a593Smuzhiyun that describes what you changed, why you made the change, and the 10642*4882a593Smuzhiyun approach you used. It might also be helpful if you mention how you 10643*4882a593Smuzhiyun tested the change. Provide as much detail as you can in the body 10644*4882a593Smuzhiyun of the commit message. 10645*4882a593Smuzhiyun 10646*4882a593Smuzhiyun .. note:: 10647*4882a593Smuzhiyun 10648*4882a593Smuzhiyun You do not need to provide a more detailed explanation of a 10649*4882a593Smuzhiyun change if the change is minor to the point of the single line 10650*4882a593Smuzhiyun summary providing all the information. 10651*4882a593Smuzhiyun 10652*4882a593Smuzhiyun - If the change addresses a specific bug or issue that is associated 10653*4882a593Smuzhiyun with a bug-tracking ID, include a reference to that ID in your 10654*4882a593Smuzhiyun detailed description. For example, the Yocto Project uses a 10655*4882a593Smuzhiyun specific convention for bug references - any commit that addresses 10656*4882a593Smuzhiyun a specific bug should use the following form for the detailed 10657*4882a593Smuzhiyun description. Be sure to use the actual bug-tracking ID from 10658*4882a593Smuzhiyun Bugzilla for bug-id:: 10659*4882a593Smuzhiyun 10660*4882a593Smuzhiyun Fixes [YOCTO #bug-id] 10661*4882a593Smuzhiyun 10662*4882a593Smuzhiyun detailed description of change 10663*4882a593Smuzhiyun 10664*4882a593SmuzhiyunUsing Email to Submit a Patch 10665*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10666*4882a593Smuzhiyun 10667*4882a593SmuzhiyunDepending on the components changed, you need to submit the email to a 10668*4882a593Smuzhiyunspecific mailing list. For some guidance on which mailing list to use, 10669*4882a593Smuzhiyunsee the 10670*4882a593Smuzhiyun:ref:`list <dev-manual/common-tasks:submitting a change to the yocto project>` 10671*4882a593Smuzhiyunat the beginning of this section. For a description of all the available 10672*4882a593Smuzhiyunmailing lists, see the ":ref:`Mailing Lists <resources-mailinglist>`" section in the 10673*4882a593SmuzhiyunYocto Project Reference Manual. 10674*4882a593Smuzhiyun 10675*4882a593SmuzhiyunHere is the general procedure on how to submit a patch through email 10676*4882a593Smuzhiyunwithout using the scripts once the steps in 10677*4882a593Smuzhiyun:ref:`dev-manual/common-tasks:preparing changes for submission` have been followed: 10678*4882a593Smuzhiyun 10679*4882a593Smuzhiyun1. *Format the Commit:* Format the commit into an email message. To 10680*4882a593Smuzhiyun format commits, use the ``git format-patch`` command. When you 10681*4882a593Smuzhiyun provide the command, you must include a revision list or a number of 10682*4882a593Smuzhiyun patches as part of the command. For example, either of these two 10683*4882a593Smuzhiyun commands takes your most recent single commit and formats it as an 10684*4882a593Smuzhiyun email message in the current directory:: 10685*4882a593Smuzhiyun 10686*4882a593Smuzhiyun $ git format-patch -1 10687*4882a593Smuzhiyun 10688*4882a593Smuzhiyun or :: 10689*4882a593Smuzhiyun 10690*4882a593Smuzhiyun $ git format-patch HEAD~ 10691*4882a593Smuzhiyun 10692*4882a593Smuzhiyun After the command is run, the current directory contains a numbered 10693*4882a593Smuzhiyun ``.patch`` file for the commit. 10694*4882a593Smuzhiyun 10695*4882a593Smuzhiyun If you provide several commits as part of the command, the 10696*4882a593Smuzhiyun ``git format-patch`` command produces a series of numbered files in 10697*4882a593Smuzhiyun the current directory – one for each commit. If you have more than 10698*4882a593Smuzhiyun one patch, you should also use the ``--cover`` option with the 10699*4882a593Smuzhiyun command, which generates a cover letter as the first "patch" in the 10700*4882a593Smuzhiyun series. You can then edit the cover letter to provide a description 10701*4882a593Smuzhiyun for the series of patches. For information on the 10702*4882a593Smuzhiyun ``git format-patch`` command, see ``GIT_FORMAT_PATCH(1)`` displayed 10703*4882a593Smuzhiyun using the ``man git-format-patch`` command. 10704*4882a593Smuzhiyun 10705*4882a593Smuzhiyun .. note:: 10706*4882a593Smuzhiyun 10707*4882a593Smuzhiyun If you are or will be a frequent contributor to the Yocto Project 10708*4882a593Smuzhiyun or to OpenEmbedded, you might consider requesting a contrib area 10709*4882a593Smuzhiyun and the necessary associated rights. 10710*4882a593Smuzhiyun 10711*4882a593Smuzhiyun2. *Send the patches via email:* Send the patches to the recipients and 10712*4882a593Smuzhiyun relevant mailing lists by using the ``git send-email`` command. 10713*4882a593Smuzhiyun 10714*4882a593Smuzhiyun .. note:: 10715*4882a593Smuzhiyun 10716*4882a593Smuzhiyun In order to use ``git send-email``, you must have the proper Git packages 10717*4882a593Smuzhiyun installed on your host. 10718*4882a593Smuzhiyun For Ubuntu, Debian, and Fedora the package is ``git-email``. 10719*4882a593Smuzhiyun 10720*4882a593Smuzhiyun The ``git send-email`` command sends email by using a local or remote 10721*4882a593Smuzhiyun Mail Transport Agent (MTA) such as ``msmtp``, ``sendmail``, or 10722*4882a593Smuzhiyun through a direct ``smtp`` configuration in your Git ``~/.gitconfig`` 10723*4882a593Smuzhiyun file. If you are submitting patches through email only, it is very 10724*4882a593Smuzhiyun important that you submit them without any whitespace or HTML 10725*4882a593Smuzhiyun formatting that either you or your mailer introduces. The maintainer 10726*4882a593Smuzhiyun that receives your patches needs to be able to save and apply them 10727*4882a593Smuzhiyun directly from your emails. A good way to verify that what you are 10728*4882a593Smuzhiyun sending will be applicable by the maintainer is to do a dry run and 10729*4882a593Smuzhiyun send them to yourself and then save and apply them as the maintainer 10730*4882a593Smuzhiyun would. 10731*4882a593Smuzhiyun 10732*4882a593Smuzhiyun The ``git send-email`` command is the preferred method for sending 10733*4882a593Smuzhiyun your patches using email since there is no risk of compromising 10734*4882a593Smuzhiyun whitespace in the body of the message, which can occur when you use 10735*4882a593Smuzhiyun your own mail client. The command also has several options that let 10736*4882a593Smuzhiyun you specify recipients and perform further editing of the email 10737*4882a593Smuzhiyun message. For information on how to use the ``git send-email`` 10738*4882a593Smuzhiyun command, see ``GIT-SEND-EMAIL(1)`` displayed using the 10739*4882a593Smuzhiyun ``man git-send-email`` command. 10740*4882a593Smuzhiyun 10741*4882a593SmuzhiyunThe Yocto Project uses a `Patchwork instance <https://patchwork.yoctoproject.org/>`__ 10742*4882a593Smuzhiyunto track the status of patches submitted to the various mailing lists and to 10743*4882a593Smuzhiyunsupport automated patch testing. Each submitted patch is checked for common 10744*4882a593Smuzhiyunmistakes and deviations from the expected patch format and submitters are 10745*4882a593Smuzhiyunnotified by patchtest if such mistakes are found. This process helps to 10746*4882a593Smuzhiyunreduce the burden of patch review on maintainers. 10747*4882a593Smuzhiyun 10748*4882a593Smuzhiyun.. note:: 10749*4882a593Smuzhiyun 10750*4882a593Smuzhiyun This system is imperfect and changes can sometimes get lost in the flow. 10751*4882a593Smuzhiyun Asking about the status of a patch or change is reasonable if the change 10752*4882a593Smuzhiyun has been idle for a while with no feedback. 10753*4882a593Smuzhiyun 10754*4882a593SmuzhiyunUsing Scripts to Push a Change Upstream and Request a Pull 10755*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10756*4882a593Smuzhiyun 10757*4882a593SmuzhiyunFor larger patch series it is preferable to send a pull request which not 10758*4882a593Smuzhiyunonly includes the patch but also a pointer to a branch that can be pulled 10759*4882a593Smuzhiyunfrom. This involves making a local branch for your changes, pushing this 10760*4882a593Smuzhiyunbranch to an accessible repository and then using the ``create-pull-request`` 10761*4882a593Smuzhiyunand ``send-pull-request`` scripts from openembedded-core to create and send a 10762*4882a593Smuzhiyunpatch series with a link to the branch for review. 10763*4882a593Smuzhiyun 10764*4882a593SmuzhiyunFollow this procedure to push a change to an upstream "contrib" Git 10765*4882a593Smuzhiyunrepository once the steps in :ref:`dev-manual/common-tasks:preparing changes for submission` have 10766*4882a593Smuzhiyunbeen followed: 10767*4882a593Smuzhiyun 10768*4882a593Smuzhiyun.. note:: 10769*4882a593Smuzhiyun 10770*4882a593Smuzhiyun You can find general Git information on how to push a change upstream 10771*4882a593Smuzhiyun in the 10772*4882a593Smuzhiyun `Git Community Book <https://git-scm.com/book/en/v2/Distributed-Git-Distributed-Workflows>`__. 10773*4882a593Smuzhiyun 10774*4882a593Smuzhiyun1. *Push Your Commits to a "Contrib" Upstream:* If you have arranged for 10775*4882a593Smuzhiyun permissions to push to an upstream contrib repository, push the 10776*4882a593Smuzhiyun change to that repository:: 10777*4882a593Smuzhiyun 10778*4882a593Smuzhiyun $ git push upstream_remote_repo local_branch_name 10779*4882a593Smuzhiyun 10780*4882a593Smuzhiyun For example, suppose you have permissions to push 10781*4882a593Smuzhiyun into the upstream ``meta-intel-contrib`` repository and you are 10782*4882a593Smuzhiyun working in a local branch named `your_name`\ ``/README``. The following 10783*4882a593Smuzhiyun command pushes your local commits to the ``meta-intel-contrib`` 10784*4882a593Smuzhiyun upstream repository and puts the commit in a branch named 10785*4882a593Smuzhiyun `your_name`\ ``/README``:: 10786*4882a593Smuzhiyun 10787*4882a593Smuzhiyun $ git push meta-intel-contrib your_name/README 10788*4882a593Smuzhiyun 10789*4882a593Smuzhiyun2. *Determine Who to Notify:* Determine the maintainer or the mailing 10790*4882a593Smuzhiyun list that you need to notify for the change. 10791*4882a593Smuzhiyun 10792*4882a593Smuzhiyun Before submitting any change, you need to be sure who the maintainer 10793*4882a593Smuzhiyun is or what mailing list that you need to notify. Use either these 10794*4882a593Smuzhiyun methods to find out: 10795*4882a593Smuzhiyun 10796*4882a593Smuzhiyun - *Maintenance File:* Examine the ``maintainers.inc`` file, which is 10797*4882a593Smuzhiyun located in the :term:`Source Directory` at 10798*4882a593Smuzhiyun ``meta/conf/distro/include``, to see who is responsible for code. 10799*4882a593Smuzhiyun 10800*4882a593Smuzhiyun - *Search by File:* Using :ref:`overview-manual/development-environment:git`, you can 10801*4882a593Smuzhiyun enter the following command to bring up a short list of all 10802*4882a593Smuzhiyun commits against a specific file:: 10803*4882a593Smuzhiyun 10804*4882a593Smuzhiyun git shortlog -- filename 10805*4882a593Smuzhiyun 10806*4882a593Smuzhiyun Just provide the name of the file for which you are interested. The 10807*4882a593Smuzhiyun information returned is not ordered by history but does include a 10808*4882a593Smuzhiyun list of everyone who has committed grouped by name. From the list, 10809*4882a593Smuzhiyun you can see who is responsible for the bulk of the changes against 10810*4882a593Smuzhiyun the file. 10811*4882a593Smuzhiyun 10812*4882a593Smuzhiyun - *Examine the List of Mailing Lists:* For a list of the Yocto 10813*4882a593Smuzhiyun Project and related mailing lists, see the ":ref:`Mailing 10814*4882a593Smuzhiyun lists <resources-mailinglist>`" section in 10815*4882a593Smuzhiyun the Yocto Project Reference Manual. 10816*4882a593Smuzhiyun 10817*4882a593Smuzhiyun3. *Make a Pull Request:* Notify the maintainer or the mailing list that 10818*4882a593Smuzhiyun you have pushed a change by making a pull request. 10819*4882a593Smuzhiyun 10820*4882a593Smuzhiyun The Yocto Project provides two scripts that conveniently let you 10821*4882a593Smuzhiyun generate and send pull requests to the Yocto Project. These scripts 10822*4882a593Smuzhiyun are ``create-pull-request`` and ``send-pull-request``. You can find 10823*4882a593Smuzhiyun these scripts in the ``scripts`` directory within the 10824*4882a593Smuzhiyun :term:`Source Directory` (e.g. 10825*4882a593Smuzhiyun ``poky/scripts``). 10826*4882a593Smuzhiyun 10827*4882a593Smuzhiyun Using these scripts correctly formats the requests without 10828*4882a593Smuzhiyun introducing any whitespace or HTML formatting. The maintainer that 10829*4882a593Smuzhiyun receives your patches either directly or through the mailing list 10830*4882a593Smuzhiyun needs to be able to save and apply them directly from your emails. 10831*4882a593Smuzhiyun Using these scripts is the preferred method for sending patches. 10832*4882a593Smuzhiyun 10833*4882a593Smuzhiyun First, create the pull request. For example, the following command 10834*4882a593Smuzhiyun runs the script, specifies the upstream repository in the contrib 10835*4882a593Smuzhiyun directory into which you pushed the change, and provides a subject 10836*4882a593Smuzhiyun line in the created patch files:: 10837*4882a593Smuzhiyun 10838*4882a593Smuzhiyun $ poky/scripts/create-pull-request -u meta-intel-contrib -s "Updated Manual Section Reference in README" 10839*4882a593Smuzhiyun 10840*4882a593Smuzhiyun Running this script forms ``*.patch`` files in a folder named 10841*4882a593Smuzhiyun ``pull-``\ `PID` in the current directory. One of the patch files is a 10842*4882a593Smuzhiyun cover letter. 10843*4882a593Smuzhiyun 10844*4882a593Smuzhiyun Before running the ``send-pull-request`` script, you must edit the 10845*4882a593Smuzhiyun cover letter patch to insert information about your change. After 10846*4882a593Smuzhiyun editing the cover letter, send the pull request. For example, the 10847*4882a593Smuzhiyun following command runs the script and specifies the patch directory 10848*4882a593Smuzhiyun and email address. In this example, the email address is a mailing 10849*4882a593Smuzhiyun list:: 10850*4882a593Smuzhiyun 10851*4882a593Smuzhiyun $ poky/scripts/send-pull-request -p ~/meta-intel/pull-10565 -t meta-intel@lists.yoctoproject.org 10852*4882a593Smuzhiyun 10853*4882a593Smuzhiyun You need to follow the prompts as the script is interactive. 10854*4882a593Smuzhiyun 10855*4882a593Smuzhiyun .. note:: 10856*4882a593Smuzhiyun 10857*4882a593Smuzhiyun For help on using these scripts, simply provide the ``-h`` 10858*4882a593Smuzhiyun argument as follows:: 10859*4882a593Smuzhiyun 10860*4882a593Smuzhiyun $ poky/scripts/create-pull-request -h 10861*4882a593Smuzhiyun $ poky/scripts/send-pull-request -h 10862*4882a593Smuzhiyun 10863*4882a593SmuzhiyunResponding to Patch Review 10864*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~ 10865*4882a593Smuzhiyun 10866*4882a593SmuzhiyunYou may get feedback on your submitted patches from other community members 10867*4882a593Smuzhiyunor from the automated patchtest service. If issues are identified in your 10868*4882a593Smuzhiyunpatch then it is usually necessary to address these before the patch will be 10869*4882a593Smuzhiyunaccepted into the project. In this case you should amend the patch according 10870*4882a593Smuzhiyunto the feedback and submit an updated version to the relevant mailing list, 10871*4882a593Smuzhiyuncopying in the reviewers who provided feedback to the previous version of the 10872*4882a593Smuzhiyunpatch. 10873*4882a593Smuzhiyun 10874*4882a593SmuzhiyunThe patch should be amended using ``git commit --amend`` or perhaps ``git 10875*4882a593Smuzhiyunrebase`` for more expert git users. You should also modify the ``[PATCH]`` 10876*4882a593Smuzhiyuntag in the email subject line when sending the revised patch to mark the new 10877*4882a593Smuzhiyuniteration as ``[PATCH v2]``, ``[PATCH v3]``, etc as appropriate. This can be 10878*4882a593Smuzhiyundone by passing the ``-v`` argument to ``git format-patch`` with a version 10879*4882a593Smuzhiyunnumber. 10880*4882a593Smuzhiyun 10881*4882a593SmuzhiyunLastly please ensure that you also test your revised changes. In particular 10882*4882a593Smuzhiyunplease don't just edit the patch file written out by ``git format-patch`` and 10883*4882a593Smuzhiyunresend it. 10884*4882a593Smuzhiyun 10885*4882a593SmuzhiyunSubmitting Changes to Stable Release Branches 10886*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10887*4882a593Smuzhiyun 10888*4882a593SmuzhiyunThe process for proposing changes to a Yocto Project stable branch differs 10889*4882a593Smuzhiyunfrom the steps described above. Changes to a stable branch must address 10890*4882a593Smuzhiyunidentified bugs or CVEs and should be made carefully in order to avoid the 10891*4882a593Smuzhiyunrisk of introducing new bugs or breaking backwards compatibility. Typically 10892*4882a593Smuzhiyunbug fixes must already be accepted into the master branch before they can be 10893*4882a593Smuzhiyunbackported to a stable branch unless the bug in question does not affect the 10894*4882a593Smuzhiyunmaster branch or the fix on the master branch is unsuitable for backporting. 10895*4882a593Smuzhiyun 10896*4882a593SmuzhiyunThe list of stable branches along with the status and maintainer for each 10897*4882a593Smuzhiyunbranch can be obtained from the 10898*4882a593Smuzhiyun:yocto_wiki:`Releases wiki page </Releases>`. 10899*4882a593Smuzhiyun 10900*4882a593Smuzhiyun.. note:: 10901*4882a593Smuzhiyun 10902*4882a593Smuzhiyun Changes will not typically be accepted for branches which are marked as 10903*4882a593Smuzhiyun End-Of-Life (EOL). 10904*4882a593Smuzhiyun 10905*4882a593SmuzhiyunWith this in mind, the steps to submit a change for a stable branch are as 10906*4882a593Smuzhiyunfollows: 10907*4882a593Smuzhiyun 10908*4882a593Smuzhiyun1. *Identify the bug or CVE to be fixed:* This information should be 10909*4882a593Smuzhiyun collected so that it can be included in your submission. 10910*4882a593Smuzhiyun 10911*4882a593Smuzhiyun See :ref:`dev-manual/common-tasks:checking for vulnerabilities` 10912*4882a593Smuzhiyun for details about CVE tracking. 10913*4882a593Smuzhiyun 10914*4882a593Smuzhiyun2. *Check if the fix is already present in the master branch:* This will 10915*4882a593Smuzhiyun result in the most straightforward path into the stable branch for the 10916*4882a593Smuzhiyun fix. 10917*4882a593Smuzhiyun 10918*4882a593Smuzhiyun a. *If the fix is present in the master branch - Submit a backport request 10919*4882a593Smuzhiyun by email:* You should send an email to the relevant stable branch 10920*4882a593Smuzhiyun maintainer and the mailing list with details of the bug or CVE to be 10921*4882a593Smuzhiyun fixed, the commit hash on the master branch that fixes the issue and 10922*4882a593Smuzhiyun the stable branches which you would like this fix to be backported to. 10923*4882a593Smuzhiyun 10924*4882a593Smuzhiyun b. *If the fix is not present in the master branch - Submit the fix to the 10925*4882a593Smuzhiyun master branch first:* This will ensure that the fix passes through the 10926*4882a593Smuzhiyun project's usual patch review and test processes before being accepted. 10927*4882a593Smuzhiyun It will also ensure that bugs are not left unresolved in the master 10928*4882a593Smuzhiyun branch itself. Once the fix is accepted in the master branch a backport 10929*4882a593Smuzhiyun request can be submitted as above. 10930*4882a593Smuzhiyun 10931*4882a593Smuzhiyun c. *If the fix is unsuitable for the master branch - Submit a patch 10932*4882a593Smuzhiyun directly for the stable branch:* This method should be considered as a 10933*4882a593Smuzhiyun last resort. It is typically necessary when the master branch is using 10934*4882a593Smuzhiyun a newer version of the software which includes an upstream fix for the 10935*4882a593Smuzhiyun issue or when the issue has been fixed on the master branch in a way 10936*4882a593Smuzhiyun that introduces backwards incompatible changes. In this case follow the 10937*4882a593Smuzhiyun steps in :ref:`dev-manual/common-tasks:preparing changes for submission` and 10938*4882a593Smuzhiyun :ref:`dev-manual/common-tasks:using email to submit a patch` but modify the subject header of your patch 10939*4882a593Smuzhiyun email to include the name of the stable branch which you are 10940*4882a593Smuzhiyun targetting. This can be done using the ``--subject-prefix`` argument to 10941*4882a593Smuzhiyun ``git format-patch``, for example to submit a patch to the dunfell 10942*4882a593Smuzhiyun branch use 10943*4882a593Smuzhiyun ``git format-patch --subject-prefix='&DISTRO_NAME_NO_CAP_MINUS_ONE;][PATCH' ...``. 10944*4882a593Smuzhiyun 10945*4882a593SmuzhiyunWorking With Licenses 10946*4882a593Smuzhiyun===================== 10947*4882a593Smuzhiyun 10948*4882a593SmuzhiyunAs mentioned in the ":ref:`overview-manual/development-environment:licensing`" 10949*4882a593Smuzhiyunsection in the Yocto Project Overview and Concepts Manual, open source 10950*4882a593Smuzhiyunprojects are open to the public and they consequently have different 10951*4882a593Smuzhiyunlicensing structures in place. This section describes the mechanism by 10952*4882a593Smuzhiyunwhich the :term:`OpenEmbedded Build System` 10953*4882a593Smuzhiyuntracks changes to 10954*4882a593Smuzhiyunlicensing text and covers how to maintain open source license compliance 10955*4882a593Smuzhiyunduring your project's lifecycle. The section also describes how to 10956*4882a593Smuzhiyunenable commercially licensed recipes, which by default are disabled. 10957*4882a593Smuzhiyun 10958*4882a593SmuzhiyunTracking License Changes 10959*4882a593Smuzhiyun------------------------ 10960*4882a593Smuzhiyun 10961*4882a593SmuzhiyunThe license of an upstream project might change in the future. In order 10962*4882a593Smuzhiyunto prevent these changes going unnoticed, the 10963*4882a593Smuzhiyun:term:`LIC_FILES_CHKSUM` 10964*4882a593Smuzhiyunvariable tracks changes to the license text. The checksums are validated 10965*4882a593Smuzhiyunat the end of the configure step, and if the checksums do not match, the 10966*4882a593Smuzhiyunbuild will fail. 10967*4882a593Smuzhiyun 10968*4882a593SmuzhiyunSpecifying the ``LIC_FILES_CHKSUM`` Variable 10969*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10970*4882a593Smuzhiyun 10971*4882a593SmuzhiyunThe :term:`LIC_FILES_CHKSUM` variable contains checksums of the license text 10972*4882a593Smuzhiyunin the source code for the recipe. Following is an example of how to 10973*4882a593Smuzhiyunspecify :term:`LIC_FILES_CHKSUM`:: 10974*4882a593Smuzhiyun 10975*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \ 10976*4882a593Smuzhiyun file://licfile1.txt;beginline=5;endline=29;md5=yyyy \ 10977*4882a593Smuzhiyun file://licfile2.txt;endline=50;md5=zzzz \ 10978*4882a593Smuzhiyun ..." 10979*4882a593Smuzhiyun 10980*4882a593Smuzhiyun.. note:: 10981*4882a593Smuzhiyun 10982*4882a593Smuzhiyun - When using "beginline" and "endline", realize that line numbering 10983*4882a593Smuzhiyun begins with one and not zero. Also, the included lines are 10984*4882a593Smuzhiyun inclusive (i.e. lines five through and including 29 in the 10985*4882a593Smuzhiyun previous example for ``licfile1.txt``). 10986*4882a593Smuzhiyun 10987*4882a593Smuzhiyun - When a license check fails, the selected license text is included 10988*4882a593Smuzhiyun as part of the QA message. Using this output, you can determine 10989*4882a593Smuzhiyun the exact start and finish for the needed license text. 10990*4882a593Smuzhiyun 10991*4882a593SmuzhiyunThe build system uses the :term:`S` 10992*4882a593Smuzhiyunvariable as the default directory when searching files listed in 10993*4882a593Smuzhiyun:term:`LIC_FILES_CHKSUM`. The previous example employs the default 10994*4882a593Smuzhiyundirectory. 10995*4882a593Smuzhiyun 10996*4882a593SmuzhiyunConsider this next example:: 10997*4882a593Smuzhiyun 10998*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\ 10999*4882a593Smuzhiyun md5=bb14ed3c4cda583abc85401304b5cd4e" 11000*4882a593Smuzhiyun LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6" 11001*4882a593Smuzhiyun 11002*4882a593SmuzhiyunThe first line locates a file in ``${S}/src/ls.c`` and isolates lines 11003*4882a593Smuzhiyunfive through 16 as license text. The second line refers to a file in 11004*4882a593Smuzhiyun:term:`WORKDIR`. 11005*4882a593Smuzhiyun 11006*4882a593SmuzhiyunNote that :term:`LIC_FILES_CHKSUM` variable is mandatory for all recipes, 11007*4882a593Smuzhiyununless the :term:`LICENSE` variable is set to "CLOSED". 11008*4882a593Smuzhiyun 11009*4882a593SmuzhiyunExplanation of Syntax 11010*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~ 11011*4882a593Smuzhiyun 11012*4882a593SmuzhiyunAs mentioned in the previous section, the :term:`LIC_FILES_CHKSUM` variable 11013*4882a593Smuzhiyunlists all the important files that contain the license text for the 11014*4882a593Smuzhiyunsource code. It is possible to specify a checksum for an entire file, or 11015*4882a593Smuzhiyuna specific section of a file (specified by beginning and ending line 11016*4882a593Smuzhiyunnumbers with the "beginline" and "endline" parameters, respectively). 11017*4882a593SmuzhiyunThe latter is useful for source files with a license notice header, 11018*4882a593SmuzhiyunREADME documents, and so forth. If you do not use the "beginline" 11019*4882a593Smuzhiyunparameter, then it is assumed that the text begins on the first line of 11020*4882a593Smuzhiyunthe file. Similarly, if you do not use the "endline" parameter, it is 11021*4882a593Smuzhiyunassumed that the license text ends with the last line of the file. 11022*4882a593Smuzhiyun 11023*4882a593SmuzhiyunThe "md5" parameter stores the md5 checksum of the license text. If the 11024*4882a593Smuzhiyunlicense text changes in any way as compared to this parameter then a 11025*4882a593Smuzhiyunmismatch occurs. This mismatch triggers a build failure and notifies the 11026*4882a593Smuzhiyundeveloper. Notification allows the developer to review and address the 11027*4882a593Smuzhiyunlicense text changes. Also note that if a mismatch occurs during the 11028*4882a593Smuzhiyunbuild, the correct md5 checksum is placed in the build log and can be 11029*4882a593Smuzhiyuneasily copied to the recipe. 11030*4882a593Smuzhiyun 11031*4882a593SmuzhiyunThere is no limit to how many files you can specify using the 11032*4882a593Smuzhiyun:term:`LIC_FILES_CHKSUM` variable. Generally, however, every project 11033*4882a593Smuzhiyunrequires a few specifications for license tracking. Many projects have a 11034*4882a593Smuzhiyun"COPYING" file that stores the license information for all the source 11035*4882a593Smuzhiyuncode files. This practice allows you to just track the "COPYING" file as 11036*4882a593Smuzhiyunlong as it is kept up to date. 11037*4882a593Smuzhiyun 11038*4882a593Smuzhiyun.. note:: 11039*4882a593Smuzhiyun 11040*4882a593Smuzhiyun - If you specify an empty or invalid "md5" parameter, 11041*4882a593Smuzhiyun :term:`BitBake` returns an md5 11042*4882a593Smuzhiyun mis-match error and displays the correct "md5" parameter value 11043*4882a593Smuzhiyun during the build. The correct parameter is also captured in the 11044*4882a593Smuzhiyun build log. 11045*4882a593Smuzhiyun 11046*4882a593Smuzhiyun - If the whole file contains only license text, you do not need to 11047*4882a593Smuzhiyun use the "beginline" and "endline" parameters. 11048*4882a593Smuzhiyun 11049*4882a593SmuzhiyunEnabling Commercially Licensed Recipes 11050*4882a593Smuzhiyun-------------------------------------- 11051*4882a593Smuzhiyun 11052*4882a593SmuzhiyunBy default, the OpenEmbedded build system disables components that have 11053*4882a593Smuzhiyuncommercial or other special licensing requirements. Such requirements 11054*4882a593Smuzhiyunare defined on a recipe-by-recipe basis through the 11055*4882a593Smuzhiyun:term:`LICENSE_FLAGS` variable 11056*4882a593Smuzhiyundefinition in the affected recipe. For instance, the 11057*4882a593Smuzhiyun``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` recipe 11058*4882a593Smuzhiyuncontains the following statement:: 11059*4882a593Smuzhiyun 11060*4882a593Smuzhiyun LICENSE_FLAGS = "commercial" 11061*4882a593Smuzhiyun 11062*4882a593SmuzhiyunHere is a 11063*4882a593Smuzhiyunslightly more complicated example that contains both an explicit recipe 11064*4882a593Smuzhiyunname and version (after variable expansion):: 11065*4882a593Smuzhiyun 11066*4882a593Smuzhiyun LICENSE_FLAGS = "license_${PN}_${PV}" 11067*4882a593Smuzhiyun 11068*4882a593SmuzhiyunIn order for a component restricted by a 11069*4882a593Smuzhiyun:term:`LICENSE_FLAGS` definition to be enabled and included in an image, it 11070*4882a593Smuzhiyunneeds to have a matching entry in the global 11071*4882a593Smuzhiyun:term:`LICENSE_FLAGS_ACCEPTED` 11072*4882a593Smuzhiyunvariable, which is a variable typically defined in your ``local.conf`` 11073*4882a593Smuzhiyunfile. For example, to enable the 11074*4882a593Smuzhiyun``poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly`` package, you 11075*4882a593Smuzhiyuncould add either the string "commercial_gst-plugins-ugly" or the more 11076*4882a593Smuzhiyungeneral string "commercial" to :term:`LICENSE_FLAGS_ACCEPTED`. See the 11077*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:license flag matching`" section for a full 11078*4882a593Smuzhiyunexplanation of how :term:`LICENSE_FLAGS` matching works. Here is the 11079*4882a593Smuzhiyunexample:: 11080*4882a593Smuzhiyun 11081*4882a593Smuzhiyun LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly" 11082*4882a593Smuzhiyun 11083*4882a593SmuzhiyunLikewise, to additionally enable the package built from the recipe 11084*4882a593Smuzhiyuncontaining ``LICENSE_FLAGS = "license_${PN}_${PV}"``, and assuming that 11085*4882a593Smuzhiyunthe actual recipe name was ``emgd_1.10.bb``, the following string would 11086*4882a593Smuzhiyunenable that package as well as the original ``gst-plugins-ugly`` 11087*4882a593Smuzhiyunpackage:: 11088*4882a593Smuzhiyun 11089*4882a593Smuzhiyun LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly license_emgd_1.10" 11090*4882a593Smuzhiyun 11091*4882a593SmuzhiyunAs a convenience, you do not need to specify the 11092*4882a593Smuzhiyuncomplete license string for every package. You can use 11093*4882a593Smuzhiyunan abbreviated form, which consists of just the first portion or 11094*4882a593Smuzhiyunportions of the license string before the initial underscore character 11095*4882a593Smuzhiyunor characters. A partial string will match any license that contains the 11096*4882a593Smuzhiyungiven string as the first portion of its license. For example, the 11097*4882a593Smuzhiyunfollowing value will also match both of the packages 11098*4882a593Smuzhiyunpreviously mentioned as well as any other packages that have licenses 11099*4882a593Smuzhiyunstarting with "commercial" or "license". 11100*4882a593Smuzhiyun:: 11101*4882a593Smuzhiyun 11102*4882a593Smuzhiyun LICENSE_FLAGS_ACCEPTED = "commercial license" 11103*4882a593Smuzhiyun 11104*4882a593SmuzhiyunLicense Flag Matching 11105*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~ 11106*4882a593Smuzhiyun 11107*4882a593SmuzhiyunLicense flag matching allows you to control what recipes the 11108*4882a593SmuzhiyunOpenEmbedded build system includes in the build. Fundamentally, the 11109*4882a593Smuzhiyunbuild system attempts to match :term:`LICENSE_FLAGS` strings found in 11110*4882a593Smuzhiyunrecipes against strings found in :term:`LICENSE_FLAGS_ACCEPTED`. 11111*4882a593SmuzhiyunA match causes the build system to include a recipe in the 11112*4882a593Smuzhiyunbuild, while failure to find a match causes the build system to exclude 11113*4882a593Smuzhiyuna recipe. 11114*4882a593Smuzhiyun 11115*4882a593SmuzhiyunIn general, license flag matching is simple. However, understanding some 11116*4882a593Smuzhiyunconcepts will help you correctly and effectively use matching. 11117*4882a593Smuzhiyun 11118*4882a593SmuzhiyunBefore a flag defined by a particular recipe is tested against the 11119*4882a593Smuzhiyunentries of :term:`LICENSE_FLAGS_ACCEPTED`, the expanded 11120*4882a593Smuzhiyunstring ``_${PN}`` is appended to the flag. This expansion makes each 11121*4882a593Smuzhiyun:term:`LICENSE_FLAGS` value recipe-specific. After expansion, the 11122*4882a593Smuzhiyunstring is then matched against the entries. Thus, specifying 11123*4882a593Smuzhiyun``LICENSE_FLAGS = "commercial"`` in recipe "foo", for example, results 11124*4882a593Smuzhiyunin the string ``"commercial_foo"``. And, to create a match, that string 11125*4882a593Smuzhiyunmust appear among the entries of :term:`LICENSE_FLAGS_ACCEPTED`. 11126*4882a593Smuzhiyun 11127*4882a593SmuzhiyunJudicious use of the :term:`LICENSE_FLAGS` strings and the contents of the 11128*4882a593Smuzhiyun:term:`LICENSE_FLAGS_ACCEPTED` variable allows you a lot of flexibility for 11129*4882a593Smuzhiyunincluding or excluding recipes based on licensing. For example, you can 11130*4882a593Smuzhiyunbroaden the matching capabilities by using license flags string subsets 11131*4882a593Smuzhiyunin :term:`LICENSE_FLAGS_ACCEPTED`. 11132*4882a593Smuzhiyun 11133*4882a593Smuzhiyun.. note:: 11134*4882a593Smuzhiyun 11135*4882a593Smuzhiyun When using a string subset, be sure to use the part of the expanded 11136*4882a593Smuzhiyun string that precedes the appended underscore character (e.g. 11137*4882a593Smuzhiyun ``usethispart_1.3``, ``usethispart_1.4``, and so forth). 11138*4882a593Smuzhiyun 11139*4882a593SmuzhiyunFor example, simply specifying the string "commercial" in the 11140*4882a593Smuzhiyun:term:`LICENSE_FLAGS_ACCEPTED` variable matches any expanded 11141*4882a593Smuzhiyun:term:`LICENSE_FLAGS` definition that starts with the string 11142*4882a593Smuzhiyun"commercial" such as "commercial_foo" and "commercial_bar", which 11143*4882a593Smuzhiyunare the strings the build system automatically generates for 11144*4882a593Smuzhiyunhypothetical recipes named "foo" and "bar" assuming those recipes simply 11145*4882a593Smuzhiyunspecify the following:: 11146*4882a593Smuzhiyun 11147*4882a593Smuzhiyun LICENSE_FLAGS = "commercial" 11148*4882a593Smuzhiyun 11149*4882a593SmuzhiyunThus, you can choose to exhaustively enumerate each license flag in the 11150*4882a593Smuzhiyunlist and allow only specific recipes into the image, or you can use a 11151*4882a593Smuzhiyunstring subset that causes a broader range of matches to allow a range of 11152*4882a593Smuzhiyunrecipes into the image. 11153*4882a593Smuzhiyun 11154*4882a593SmuzhiyunThis scheme works even if the :term:`LICENSE_FLAGS` string already has 11155*4882a593Smuzhiyun``_${PN}`` appended. For example, the build system turns the license 11156*4882a593Smuzhiyunflag "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would match 11157*4882a593Smuzhiyunboth the general "commercial" and the specific "commercial_1.2_foo" 11158*4882a593Smuzhiyunstrings found in the :term:`LICENSE_FLAGS_ACCEPTED` variable, as expected. 11159*4882a593Smuzhiyun 11160*4882a593SmuzhiyunHere are some other scenarios: 11161*4882a593Smuzhiyun 11162*4882a593Smuzhiyun- You can specify a versioned string in the recipe such as 11163*4882a593Smuzhiyun "commercial_foo_1.2" in a "foo" recipe. The build system expands this 11164*4882a593Smuzhiyun string to "commercial_foo_1.2_foo". Combine this license flag with a 11165*4882a593Smuzhiyun :term:`LICENSE_FLAGS_ACCEPTED` variable that has the string 11166*4882a593Smuzhiyun "commercial" and you match the flag along with any other flag that 11167*4882a593Smuzhiyun starts with the string "commercial". 11168*4882a593Smuzhiyun 11169*4882a593Smuzhiyun- Under the same circumstances, you can add "commercial_foo" in the 11170*4882a593Smuzhiyun :term:`LICENSE_FLAGS_ACCEPTED` variable and the build system not only 11171*4882a593Smuzhiyun matches "commercial_foo_1.2" but also matches any license flag with 11172*4882a593Smuzhiyun the string "commercial_foo", regardless of the version. 11173*4882a593Smuzhiyun 11174*4882a593Smuzhiyun- You can be very specific and use both the package and version parts 11175*4882a593Smuzhiyun in the :term:`LICENSE_FLAGS_ACCEPTED` list (e.g. 11176*4882a593Smuzhiyun "commercial_foo_1.2") to specifically match a versioned recipe. 11177*4882a593Smuzhiyun 11178*4882a593SmuzhiyunOther Variables Related to Commercial Licenses 11179*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11180*4882a593Smuzhiyun 11181*4882a593SmuzhiyunThere are other helpful variables related to commercial license handling, 11182*4882a593Smuzhiyundefined in the 11183*4882a593Smuzhiyun``poky/meta/conf/distro/include/default-distrovars.inc`` file:: 11184*4882a593Smuzhiyun 11185*4882a593Smuzhiyun COMMERCIAL_AUDIO_PLUGINS ?= "" 11186*4882a593Smuzhiyun COMMERCIAL_VIDEO_PLUGINS ?= "" 11187*4882a593Smuzhiyun 11188*4882a593SmuzhiyunIf you 11189*4882a593Smuzhiyunwant to enable these components, you can do so by making sure you have 11190*4882a593Smuzhiyunstatements similar to the following in your ``local.conf`` configuration 11191*4882a593Smuzhiyunfile:: 11192*4882a593Smuzhiyun 11193*4882a593Smuzhiyun COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \ 11194*4882a593Smuzhiyun gst-plugins-ugly-mpegaudioparse" 11195*4882a593Smuzhiyun COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \ 11196*4882a593Smuzhiyun gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse" 11197*4882a593Smuzhiyun LICENSE_FLAGS_ACCEPTED = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp" 11198*4882a593Smuzhiyun 11199*4882a593Smuzhiyun 11200*4882a593SmuzhiyunOf course, you could also create a matching list for those 11201*4882a593Smuzhiyuncomponents using the more general "commercial" in the 11202*4882a593Smuzhiyun:term:`LICENSE_FLAGS_ACCEPTED` variable, but that would also enable all 11203*4882a593Smuzhiyunthe other packages with :term:`LICENSE_FLAGS` 11204*4882a593Smuzhiyuncontaining "commercial", which you may or may not want:: 11205*4882a593Smuzhiyun 11206*4882a593Smuzhiyun LICENSE_FLAGS_ACCEPTED = "commercial" 11207*4882a593Smuzhiyun 11208*4882a593SmuzhiyunSpecifying audio and video plugins as part of the 11209*4882a593Smuzhiyun``COMMERCIAL_AUDIO_PLUGINS`` and ``COMMERCIAL_VIDEO_PLUGINS`` statements 11210*4882a593Smuzhiyun(along with the enabling :term:`LICENSE_FLAGS_ACCEPTED`) includes the 11211*4882a593Smuzhiyunplugins or components into built images, thus adding support for media 11212*4882a593Smuzhiyunformats or components. 11213*4882a593Smuzhiyun 11214*4882a593SmuzhiyunMaintaining Open Source License Compliance During Your Product's Lifecycle 11215*4882a593Smuzhiyun-------------------------------------------------------------------------- 11216*4882a593Smuzhiyun 11217*4882a593SmuzhiyunOne of the concerns for a development organization using open source 11218*4882a593Smuzhiyunsoftware is how to maintain compliance with various open source 11219*4882a593Smuzhiyunlicensing during the lifecycle of the product. While this section does 11220*4882a593Smuzhiyunnot provide legal advice or comprehensively cover all scenarios, it does 11221*4882a593Smuzhiyunpresent methods that you can use to assist you in meeting the compliance 11222*4882a593Smuzhiyunrequirements during a software release. 11223*4882a593Smuzhiyun 11224*4882a593SmuzhiyunWith hundreds of different open source licenses that the Yocto Project 11225*4882a593Smuzhiyuntracks, it is difficult to know the requirements of each and every 11226*4882a593Smuzhiyunlicense. However, the requirements of the major FLOSS licenses can begin 11227*4882a593Smuzhiyunto be covered by assuming that there are three main areas of concern: 11228*4882a593Smuzhiyun 11229*4882a593Smuzhiyun- Source code must be provided. 11230*4882a593Smuzhiyun 11231*4882a593Smuzhiyun- License text for the software must be provided. 11232*4882a593Smuzhiyun 11233*4882a593Smuzhiyun- Compilation scripts and modifications to the source code must be 11234*4882a593Smuzhiyun provided. 11235*4882a593Smuzhiyun 11236*4882a593Smuzhiyun- spdx files can be provided. 11237*4882a593Smuzhiyun 11238*4882a593SmuzhiyunThere are other requirements beyond the scope of these three and the 11239*4882a593Smuzhiyunmethods described in this section (e.g. the mechanism through which 11240*4882a593Smuzhiyunsource code is distributed). 11241*4882a593Smuzhiyun 11242*4882a593SmuzhiyunAs different organizations have different methods of complying with open 11243*4882a593Smuzhiyunsource licensing, this section is not meant to imply that there is only 11244*4882a593Smuzhiyunone single way to meet your compliance obligations, but rather to 11245*4882a593Smuzhiyundescribe one method of achieving compliance. The remainder of this 11246*4882a593Smuzhiyunsection describes methods supported to meet the previously mentioned 11247*4882a593Smuzhiyunthree requirements. Once you take steps to meet these requirements, and 11248*4882a593Smuzhiyunprior to releasing images, sources, and the build system, you should 11249*4882a593Smuzhiyunaudit all artifacts to ensure completeness. 11250*4882a593Smuzhiyun 11251*4882a593Smuzhiyun.. note:: 11252*4882a593Smuzhiyun 11253*4882a593Smuzhiyun The Yocto Project generates a license manifest during image creation 11254*4882a593Smuzhiyun that is located in ``${DEPLOY_DIR}/licenses/``\ `image_name`\ ``-``\ `datestamp` 11255*4882a593Smuzhiyun to assist with any audits. 11256*4882a593Smuzhiyun 11257*4882a593SmuzhiyunProviding the Source Code 11258*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~ 11259*4882a593Smuzhiyun 11260*4882a593SmuzhiyunCompliance activities should begin before you generate the final image. 11261*4882a593SmuzhiyunThe first thing you should look at is the requirement that tops the list 11262*4882a593Smuzhiyunfor most compliance groups - providing the source. The Yocto Project has 11263*4882a593Smuzhiyuna few ways of meeting this requirement. 11264*4882a593Smuzhiyun 11265*4882a593SmuzhiyunOne of the easiest ways to meet this requirement is to provide the 11266*4882a593Smuzhiyunentire :term:`DL_DIR` used by the 11267*4882a593Smuzhiyunbuild. This method, however, has a few issues. The most obvious is the 11268*4882a593Smuzhiyunsize of the directory since it includes all sources used in the build 11269*4882a593Smuzhiyunand not just the source used in the released image. It will include 11270*4882a593Smuzhiyuntoolchain source, and other artifacts, which you would not generally 11271*4882a593Smuzhiyunrelease. However, the more serious issue for most companies is 11272*4882a593Smuzhiyunaccidental release of proprietary software. The Yocto Project provides 11273*4882a593Smuzhiyunan :ref:`archiver <ref-classes-archiver>` class to 11274*4882a593Smuzhiyunhelp avoid some of these concerns. 11275*4882a593Smuzhiyun 11276*4882a593SmuzhiyunBefore you employ :term:`DL_DIR` or the :ref:`archiver <ref-classes-archiver>` class, you need to 11277*4882a593Smuzhiyundecide how you choose to provide source. The source ``archiver`` class 11278*4882a593Smuzhiyuncan generate tarballs and SRPMs and can create them with various levels 11279*4882a593Smuzhiyunof compliance in mind. 11280*4882a593Smuzhiyun 11281*4882a593SmuzhiyunOne way of doing this (but certainly not the only way) is to release 11282*4882a593Smuzhiyunjust the source as a tarball. You can do this by adding the following to 11283*4882a593Smuzhiyunthe ``local.conf`` file found in the 11284*4882a593Smuzhiyun:term:`Build Directory`:: 11285*4882a593Smuzhiyun 11286*4882a593Smuzhiyun INHERIT += "archiver" 11287*4882a593Smuzhiyun ARCHIVER_MODE[src] = "original" 11288*4882a593Smuzhiyun 11289*4882a593SmuzhiyunDuring the creation of your 11290*4882a593Smuzhiyunimage, the source from all recipes that deploy packages to the image is 11291*4882a593Smuzhiyunplaced within subdirectories of ``DEPLOY_DIR/sources`` based on the 11292*4882a593Smuzhiyun:term:`LICENSE` for each recipe. 11293*4882a593SmuzhiyunReleasing the entire directory enables you to comply with requirements 11294*4882a593Smuzhiyunconcerning providing the unmodified source. It is important to note that 11295*4882a593Smuzhiyunthe size of the directory can get large. 11296*4882a593Smuzhiyun 11297*4882a593SmuzhiyunA way to help mitigate the size issue is to only release tarballs for 11298*4882a593Smuzhiyunlicenses that require the release of source. Let us assume you are only 11299*4882a593Smuzhiyunconcerned with GPL code as identified by running the following script: 11300*4882a593Smuzhiyun 11301*4882a593Smuzhiyun.. code-block:: shell 11302*4882a593Smuzhiyun 11303*4882a593Smuzhiyun # Script to archive a subset of packages matching specific license(s) 11304*4882a593Smuzhiyun # Source and license files are copied into sub folders of package folder 11305*4882a593Smuzhiyun # Must be run from build folder 11306*4882a593Smuzhiyun #!/bin/bash 11307*4882a593Smuzhiyun src_release_dir="source-release" 11308*4882a593Smuzhiyun mkdir -p $src_release_dir 11309*4882a593Smuzhiyun for a in tmp/deploy/sources/*; do 11310*4882a593Smuzhiyun for d in $a/*; do 11311*4882a593Smuzhiyun # Get package name from path 11312*4882a593Smuzhiyun p=`basename $d` 11313*4882a593Smuzhiyun p=${p%-*} 11314*4882a593Smuzhiyun p=${p%-*} 11315*4882a593Smuzhiyun # Only archive GPL packages (update *GPL* regex for your license check) 11316*4882a593Smuzhiyun numfiles=`ls tmp/deploy/licenses/$p/*GPL* 2> /dev/null | wc -l` 11317*4882a593Smuzhiyun if [ $numfiles -ge 1 ]; then 11318*4882a593Smuzhiyun echo Archiving $p 11319*4882a593Smuzhiyun mkdir -p $src_release_dir/$p/source 11320*4882a593Smuzhiyun cp $d/* $src_release_dir/$p/source 2> /dev/null 11321*4882a593Smuzhiyun mkdir -p $src_release_dir/$p/license 11322*4882a593Smuzhiyun cp tmp/deploy/licenses/$p/* $src_release_dir/$p/license 2> /dev/null 11323*4882a593Smuzhiyun fi 11324*4882a593Smuzhiyun done 11325*4882a593Smuzhiyun done 11326*4882a593Smuzhiyun 11327*4882a593SmuzhiyunAt this point, you 11328*4882a593Smuzhiyuncould create a tarball from the ``gpl_source_release`` directory and 11329*4882a593Smuzhiyunprovide that to the end user. This method would be a step toward 11330*4882a593Smuzhiyunachieving compliance with section 3a of GPLv2 and with section 6 of 11331*4882a593SmuzhiyunGPLv3. 11332*4882a593Smuzhiyun 11333*4882a593SmuzhiyunProviding License Text 11334*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~ 11335*4882a593Smuzhiyun 11336*4882a593SmuzhiyunOne requirement that is often overlooked is inclusion of license text. 11337*4882a593SmuzhiyunThis requirement also needs to be dealt with prior to generating the 11338*4882a593Smuzhiyunfinal image. Some licenses require the license text to accompany the 11339*4882a593Smuzhiyunbinary. You can achieve this by adding the following to your 11340*4882a593Smuzhiyun``local.conf`` file:: 11341*4882a593Smuzhiyun 11342*4882a593Smuzhiyun COPY_LIC_MANIFEST = "1" 11343*4882a593Smuzhiyun COPY_LIC_DIRS = "1" 11344*4882a593Smuzhiyun LICENSE_CREATE_PACKAGE = "1" 11345*4882a593Smuzhiyun 11346*4882a593SmuzhiyunAdding these statements to the 11347*4882a593Smuzhiyunconfiguration file ensures that the licenses collected during package 11348*4882a593Smuzhiyungeneration are included on your image. 11349*4882a593Smuzhiyun 11350*4882a593Smuzhiyun.. note:: 11351*4882a593Smuzhiyun 11352*4882a593Smuzhiyun Setting all three variables to "1" results in the image having two 11353*4882a593Smuzhiyun copies of the same license file. One copy resides in 11354*4882a593Smuzhiyun ``/usr/share/common-licenses`` and the other resides in 11355*4882a593Smuzhiyun ``/usr/share/license``. 11356*4882a593Smuzhiyun 11357*4882a593Smuzhiyun The reason for this behavior is because 11358*4882a593Smuzhiyun :term:`COPY_LIC_DIRS` and 11359*4882a593Smuzhiyun :term:`COPY_LIC_MANIFEST` 11360*4882a593Smuzhiyun add a copy of the license when the image is built but do not offer a 11361*4882a593Smuzhiyun path for adding licenses for newly installed packages to an image. 11362*4882a593Smuzhiyun :term:`LICENSE_CREATE_PACKAGE` 11363*4882a593Smuzhiyun adds a separate package and an upgrade path for adding licenses to an 11364*4882a593Smuzhiyun image. 11365*4882a593Smuzhiyun 11366*4882a593SmuzhiyunAs the source ``archiver`` class has already archived the original 11367*4882a593Smuzhiyununmodified source that contains the license files, you would have 11368*4882a593Smuzhiyunalready met the requirements for inclusion of the license information 11369*4882a593Smuzhiyunwith source as defined by the GPL and other open source licenses. 11370*4882a593Smuzhiyun 11371*4882a593SmuzhiyunProviding Compilation Scripts and Source Code Modifications 11372*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11373*4882a593Smuzhiyun 11374*4882a593SmuzhiyunAt this point, we have addressed all we need to prior to generating the 11375*4882a593Smuzhiyunimage. The next two requirements are addressed during the final 11376*4882a593Smuzhiyunpackaging of the release. 11377*4882a593Smuzhiyun 11378*4882a593SmuzhiyunBy releasing the version of the OpenEmbedded build system and the layers 11379*4882a593Smuzhiyunused during the build, you will be providing both compilation scripts 11380*4882a593Smuzhiyunand the source code modifications in one step. 11381*4882a593Smuzhiyun 11382*4882a593SmuzhiyunIf the deployment team has a :ref:`overview-manual/concepts:bsp layer` 11383*4882a593Smuzhiyunand a distro layer, and those 11384*4882a593Smuzhiyunthose layers are used to patch, compile, package, or modify (in any way) 11385*4882a593Smuzhiyunany open source software included in your released images, you might be 11386*4882a593Smuzhiyunrequired to release those layers under section 3 of GPLv2 or section 1 11387*4882a593Smuzhiyunof GPLv3. One way of doing that is with a clean checkout of the version 11388*4882a593Smuzhiyunof the Yocto Project and layers used during your build. Here is an 11389*4882a593Smuzhiyunexample: 11390*4882a593Smuzhiyun 11391*4882a593Smuzhiyun.. code-block:: shell 11392*4882a593Smuzhiyun 11393*4882a593Smuzhiyun # We built using the dunfell branch of the poky repo 11394*4882a593Smuzhiyun $ git clone -b dunfell git://git.yoctoproject.org/poky 11395*4882a593Smuzhiyun $ cd poky 11396*4882a593Smuzhiyun # We built using the release_branch for our layers 11397*4882a593Smuzhiyun $ git clone -b release_branch git://git.mycompany.com/meta-my-bsp-layer 11398*4882a593Smuzhiyun $ git clone -b release_branch git://git.mycompany.com/meta-my-software-layer 11399*4882a593Smuzhiyun # clean up the .git repos 11400*4882a593Smuzhiyun $ find . -name ".git" -type d -exec rm -rf {} \; 11401*4882a593Smuzhiyun 11402*4882a593SmuzhiyunOne 11403*4882a593Smuzhiyunthing a development organization might want to consider for end-user 11404*4882a593Smuzhiyunconvenience is to modify ``meta-poky/conf/bblayers.conf.sample`` to 11405*4882a593Smuzhiyunensure that when the end user utilizes the released build system to 11406*4882a593Smuzhiyunbuild an image, the development organization's layers are included in 11407*4882a593Smuzhiyunthe ``bblayers.conf`` file automatically:: 11408*4882a593Smuzhiyun 11409*4882a593Smuzhiyun # POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf 11410*4882a593Smuzhiyun # changes incompatibly 11411*4882a593Smuzhiyun POKY_BBLAYERS_CONF_VERSION = "2" 11412*4882a593Smuzhiyun 11413*4882a593Smuzhiyun BBPATH = "${TOPDIR}" 11414*4882a593Smuzhiyun BBFILES ?= "" 11415*4882a593Smuzhiyun 11416*4882a593Smuzhiyun BBLAYERS ?= " \ 11417*4882a593Smuzhiyun ##OEROOT##/meta \ 11418*4882a593Smuzhiyun ##OEROOT##/meta-poky \ 11419*4882a593Smuzhiyun ##OEROOT##/meta-yocto-bsp \ 11420*4882a593Smuzhiyun ##OEROOT##/meta-mylayer \ 11421*4882a593Smuzhiyun " 11422*4882a593Smuzhiyun 11423*4882a593SmuzhiyunCreating and 11424*4882a593Smuzhiyunproviding an archive of the :term:`Metadata` 11425*4882a593Smuzhiyunlayers (recipes, configuration files, and so forth) enables you to meet 11426*4882a593Smuzhiyunyour requirements to include the scripts to control compilation as well 11427*4882a593Smuzhiyunas any modifications to the original source. 11428*4882a593Smuzhiyun 11429*4882a593SmuzhiyunCompliance Limitations with Executables Built from Static Libraries 11430*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11431*4882a593Smuzhiyun 11432*4882a593SmuzhiyunWhen package A is added to an image via the :term:`RDEPENDS` or :term:`RRECOMMENDS` 11433*4882a593Smuzhiyunmechanisms as well as explicitly included in the image recipe with 11434*4882a593Smuzhiyun:term:`IMAGE_INSTALL`, and depends on a static linked library recipe B 11435*4882a593Smuzhiyun(``DEPENDS += "B"``), package B will neither appear in the generated license 11436*4882a593Smuzhiyunmanifest nor in the generated source tarballs. This occurs as the 11437*4882a593Smuzhiyun:ref:`license <ref-classes-license>` and :ref:`archiver <ref-classes-archiver>` 11438*4882a593Smuzhiyunclasses assume that only packages included via :term:`RDEPENDS` or :term:`RRECOMMENDS` 11439*4882a593Smuzhiyunend up in the image. 11440*4882a593Smuzhiyun 11441*4882a593SmuzhiyunAs a result, potential obligations regarding license compliance for package B 11442*4882a593Smuzhiyunmay not be met. 11443*4882a593Smuzhiyun 11444*4882a593SmuzhiyunThe Yocto Project doesn't enable static libraries by default, in part because 11445*4882a593Smuzhiyunof this issue. Before a solution to this limitation is found, you need to 11446*4882a593Smuzhiyunkeep in mind that if your root filesystem is built from static libraries, 11447*4882a593Smuzhiyunyou will need to manually ensure that your deliveries are compliant 11448*4882a593Smuzhiyunwith the licenses of these libraries. 11449*4882a593Smuzhiyun 11450*4882a593SmuzhiyunCopying Non Standard Licenses 11451*4882a593Smuzhiyun----------------------------- 11452*4882a593Smuzhiyun 11453*4882a593SmuzhiyunSome packages, such as the linux-firmware package, have many licenses 11454*4882a593Smuzhiyunthat are not in any way common. You can avoid adding a lot of these 11455*4882a593Smuzhiyuntypes of common license files, which are only applicable to a specific 11456*4882a593Smuzhiyunpackage, by using the 11457*4882a593Smuzhiyun:term:`NO_GENERIC_LICENSE` 11458*4882a593Smuzhiyunvariable. Using this variable also avoids QA errors when you use a 11459*4882a593Smuzhiyunnon-common, non-CLOSED license in a recipe. 11460*4882a593Smuzhiyun 11461*4882a593SmuzhiyunHere is an example that uses the ``LICENSE.Abilis.txt`` file as 11462*4882a593Smuzhiyunthe license from the fetched source:: 11463*4882a593Smuzhiyun 11464*4882a593Smuzhiyun NO_GENERIC_LICENSE[Firmware-Abilis] = "LICENSE.Abilis.txt" 11465*4882a593Smuzhiyun 11466*4882a593SmuzhiyunChecking for Vulnerabilities 11467*4882a593Smuzhiyun============================ 11468*4882a593Smuzhiyun 11469*4882a593SmuzhiyunVulnerabilities in Poky and OE-Core 11470*4882a593Smuzhiyun----------------------------------- 11471*4882a593Smuzhiyun 11472*4882a593SmuzhiyunThe Yocto Project has an infrastructure to track and address unfixed 11473*4882a593Smuzhiyunknown security vulnerabilities, as tracked by the public 11474*4882a593Smuzhiyun:wikipedia:`Common Vulnerabilities and Exposures (CVE) <Common_Vulnerabilities_and_Exposures>` 11475*4882a593Smuzhiyundatabase. 11476*4882a593Smuzhiyun 11477*4882a593SmuzhiyunThe Yocto Project maintains a `list of known vulnerabilities 11478*4882a593Smuzhiyun<https://autobuilder.yocto.io/pub/non-release/patchmetrics/>`__ 11479*4882a593Smuzhiyunfor packages in Poky and OE-Core, tracking the evolution of the number of 11480*4882a593Smuzhiyununpatched CVEs and the status of patches. Such information is available for 11481*4882a593Smuzhiyunthe current development version and for each supported release. 11482*4882a593Smuzhiyun 11483*4882a593SmuzhiyunSecurity is a process, not a product, and thus at any time, a number of security 11484*4882a593Smuzhiyunissues may be impacting Poky and OE-Core. It is up to the maintainers, users, 11485*4882a593Smuzhiyuncontributors and anyone interested in the issues to investigate and possibly fix them by 11486*4882a593Smuzhiyunupdating software components to newer versions or by applying patches to address them. 11487*4882a593SmuzhiyunIt is recommended to work with Poky and OE-Core upstream maintainers and submit 11488*4882a593Smuzhiyunpatches to fix them, see ":ref:`dev-manual/common-tasks:submitting a change to the yocto project`" for details. 11489*4882a593Smuzhiyun 11490*4882a593SmuzhiyunVulnerability check at build time 11491*4882a593Smuzhiyun--------------------------------- 11492*4882a593Smuzhiyun 11493*4882a593SmuzhiyunTo enable a check for CVE security vulnerabilities using :ref:`cve-check <ref-classes-cve-check>` in the specific image 11494*4882a593Smuzhiyunor target you are building, add the following setting to your configuration:: 11495*4882a593Smuzhiyun 11496*4882a593Smuzhiyun INHERIT += "cve-check" 11497*4882a593Smuzhiyun 11498*4882a593SmuzhiyunThe CVE database contains some old incomplete entries which have been 11499*4882a593Smuzhiyundeemed not to impact Poky or OE-Core. These CVE entries can be excluded from the 11500*4882a593Smuzhiyuncheck using build configuration:: 11501*4882a593Smuzhiyun 11502*4882a593Smuzhiyun include conf/distro/include/cve-extra-exclusions.inc 11503*4882a593Smuzhiyun 11504*4882a593SmuzhiyunWith this CVE check enabled, BitBake build will try to map each compiled software component 11505*4882a593Smuzhiyunrecipe name and version information to the CVE database and generate recipe and 11506*4882a593Smuzhiyunimage specific reports. These reports will contain: 11507*4882a593Smuzhiyun 11508*4882a593Smuzhiyun- metadata about the software component like names and versions 11509*4882a593Smuzhiyun 11510*4882a593Smuzhiyun- metadata about the CVE issue such as description and NVD link 11511*4882a593Smuzhiyun 11512*4882a593Smuzhiyun- for each software component, a list of CVEs which are possibly impacting this version 11513*4882a593Smuzhiyun 11514*4882a593Smuzhiyun- status of each CVE: ``Patched``, ``Unpatched`` or ``Ignored`` 11515*4882a593Smuzhiyun 11516*4882a593SmuzhiyunThe status ``Patched`` means that a patch file to address the security issue has been 11517*4882a593Smuzhiyunapplied. ``Unpatched`` status means that no patches to address the issue have been 11518*4882a593Smuzhiyunapplied and that the issue needs to be investigated. ``Ignored`` means that after 11519*4882a593Smuzhiyunanalysis, it has been deemed to ignore the issue as it for example affects 11520*4882a593Smuzhiyunthe software component on a different operating system platform. 11521*4882a593Smuzhiyun 11522*4882a593SmuzhiyunAfter a build with CVE check enabled, reports for each compiled source recipe will be 11523*4882a593Smuzhiyunfound in ``build/tmp/deploy/cve``. 11524*4882a593Smuzhiyun 11525*4882a593SmuzhiyunFor example the CVE check report for the ``flex-native`` recipe looks like:: 11526*4882a593Smuzhiyun 11527*4882a593Smuzhiyun $ cat poky/build/tmp/deploy/cve/flex-native 11528*4882a593Smuzhiyun LAYER: meta 11529*4882a593Smuzhiyun PACKAGE NAME: flex-native 11530*4882a593Smuzhiyun PACKAGE VERSION: 2.6.4 11531*4882a593Smuzhiyun CVE: CVE-2016-6354 11532*4882a593Smuzhiyun CVE STATUS: Patched 11533*4882a593Smuzhiyun CVE SUMMARY: Heap-based buffer overflow in the yy_get_next_buffer function in Flex before 2.6.1 might allow context-dependent attackers to cause a denial of service or possibly execute arbitrary code via vectors involving num_to_read. 11534*4882a593Smuzhiyun CVSS v2 BASE SCORE: 7.5 11535*4882a593Smuzhiyun CVSS v3 BASE SCORE: 9.8 11536*4882a593Smuzhiyun VECTOR: NETWORK 11537*4882a593Smuzhiyun MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2016-6354 11538*4882a593Smuzhiyun 11539*4882a593Smuzhiyun LAYER: meta 11540*4882a593Smuzhiyun PACKAGE NAME: flex-native 11541*4882a593Smuzhiyun PACKAGE VERSION: 2.6.4 11542*4882a593Smuzhiyun CVE: CVE-2019-6293 11543*4882a593Smuzhiyun CVE STATUS: Ignored 11544*4882a593Smuzhiyun CVE SUMMARY: An issue was discovered in the function mark_beginning_as_normal in nfa.c in flex 2.6.4. There is a stack exhaustion problem caused by the mark_beginning_as_normal function making recursive calls to itself in certain scenarios involving lots of '*' characters. Remote attackers could leverage this vulnerability to cause a denial-of-service. 11545*4882a593Smuzhiyun CVSS v2 BASE SCORE: 4.3 11546*4882a593Smuzhiyun CVSS v3 BASE SCORE: 5.5 11547*4882a593Smuzhiyun VECTOR: NETWORK 11548*4882a593Smuzhiyun MORE INFORMATION: https://nvd.nist.gov/vuln/detail/CVE-2019-6293 11549*4882a593Smuzhiyun 11550*4882a593SmuzhiyunFor images, a summary of all recipes included in the image and their CVEs is also 11551*4882a593Smuzhiyungenerated in textual and JSON formats. These ``.cve`` and ``.json`` reports can be found 11552*4882a593Smuzhiyunin the ``tmp/deploy/images`` directory for each compiled image. 11553*4882a593Smuzhiyun 11554*4882a593SmuzhiyunAt build time CVE check will also throw warnings about ``Unpatched`` CVEs:: 11555*4882a593Smuzhiyun 11556*4882a593Smuzhiyun WARNING: flex-2.6.4-r0 do_cve_check: Found unpatched CVE (CVE-2019-6293), for more information check /poky/build/tmp/work/core2-64-poky-linux/flex/2.6.4-r0/temp/cve.log 11557*4882a593Smuzhiyun WARNING: libarchive-3.5.1-r0 do_cve_check: Found unpatched CVE (CVE-2021-36976), for more information check /poky/build/tmp/work/core2-64-poky-linux/libarchive/3.5.1-r0/temp/cve.log 11558*4882a593Smuzhiyun 11559*4882a593SmuzhiyunIt is also possible to check the CVE status of individual packages as follows:: 11560*4882a593Smuzhiyun 11561*4882a593Smuzhiyun bitbake -c cve_check flex libarchive 11562*4882a593Smuzhiyun 11563*4882a593SmuzhiyunFixing CVE product name and version mappings 11564*4882a593Smuzhiyun-------------------------------------------- 11565*4882a593Smuzhiyun 11566*4882a593SmuzhiyunBy default, :ref:`cve-check <ref-classes-cve-check>` uses the recipe name :term:`BPN` as CVE 11567*4882a593Smuzhiyunproduct name when querying the CVE database. If this mapping contains false positives, e.g. 11568*4882a593Smuzhiyunsome reported CVEs are not for the software component in question, or false negatives like 11569*4882a593Smuzhiyunsome CVEs are not found to impact the recipe when they should, then the problems can be 11570*4882a593Smuzhiyunin the recipe name to CVE product mapping. These mapping issues can be fixed by setting 11571*4882a593Smuzhiyunthe :term:`CVE_PRODUCT` variable inside the recipe. This defines the name of the software component in the 11572*4882a593Smuzhiyunupstream `NIST CVE database <https://nvd.nist.gov/>`__. 11573*4882a593Smuzhiyun 11574*4882a593SmuzhiyunThe variable supports using vendor and product names like this:: 11575*4882a593Smuzhiyun 11576*4882a593Smuzhiyun CVE_PRODUCT = "flex_project:flex" 11577*4882a593Smuzhiyun 11578*4882a593SmuzhiyunIn this example the vendor name used in the CVE database is ``flex_project`` and the 11579*4882a593Smuzhiyunproduct is ``flex``. With this setting the ``flex`` recipe only maps to this specific 11580*4882a593Smuzhiyunproduct and not products from other vendors with same name ``flex``. 11581*4882a593Smuzhiyun 11582*4882a593SmuzhiyunSimilarly, when the recipe version :term:`PV` is not compatible with software versions used by 11583*4882a593Smuzhiyunthe upstream software component releases and the CVE database, these can be fixed using 11584*4882a593Smuzhiyunthe :term:`CVE_VERSION` variable. 11585*4882a593Smuzhiyun 11586*4882a593SmuzhiyunNote that if the CVE entries in the NVD database contain bugs or have missing or incomplete 11587*4882a593Smuzhiyuninformation, it is recommended to fix the information there directly instead of working 11588*4882a593Smuzhiyunaround the issues possibly for a long time in Poky and OE-Core side recipes. Feedback to 11589*4882a593SmuzhiyunNVD about CVE entries can be provided through the `NVD contact form <https://nvd.nist.gov/info/contact-form>`__. 11590*4882a593Smuzhiyun 11591*4882a593SmuzhiyunFixing vulnerabilities in recipes 11592*4882a593Smuzhiyun--------------------------------- 11593*4882a593Smuzhiyun 11594*4882a593SmuzhiyunIf a CVE security issue impacts a software component, it can be fixed by updating to a newer 11595*4882a593Smuzhiyunversion of the software component or by applying a patch. For Poky and OE-Core master branches, updating 11596*4882a593Smuzhiyunto a newer software component release with fixes is the best option, but patches can be applied 11597*4882a593Smuzhiyunif releases are not yet available. 11598*4882a593Smuzhiyun 11599*4882a593SmuzhiyunFor stable branches, it is preferred to apply patches for the issues. For some software 11600*4882a593Smuzhiyuncomponents minor version updates can also be applied if they are backwards compatible. 11601*4882a593Smuzhiyun 11602*4882a593SmuzhiyunHere is an example of fixing CVE security issues with patch files, 11603*4882a593Smuzhiyunan example from the :oe_layerindex:`ffmpeg recipe</layerindex/recipe/47350>`:: 11604*4882a593Smuzhiyun 11605*4882a593Smuzhiyun SRC_URI = "https://www.ffmpeg.org/releases/${BP}.tar.xz \ 11606*4882a593Smuzhiyun file://0001-libavutil-include-assembly-with-full-path-from-sourc.patch \ 11607*4882a593Smuzhiyun file://fix-CVE-2020-20446.patch \ 11608*4882a593Smuzhiyun file://fix-CVE-2020-20453.patch \ 11609*4882a593Smuzhiyun file://fix-CVE-2020-22015.patch \ 11610*4882a593Smuzhiyun file://fix-CVE-2020-22021.patch \ 11611*4882a593Smuzhiyun file://fix-CVE-2020-22033-CVE-2020-22019.patch \ 11612*4882a593Smuzhiyun file://fix-CVE-2021-33815.patch \ 11613*4882a593Smuzhiyun 11614*4882a593SmuzhiyunA good practice is to include the CVE identifier in both the patch file name 11615*4882a593Smuzhiyunand inside the patch file commit message using the format:: 11616*4882a593Smuzhiyun 11617*4882a593Smuzhiyun CVE: CVE-2020-22033 11618*4882a593Smuzhiyun 11619*4882a593SmuzhiyunCVE checker will then capture this information and change the CVE status to ``Patched`` 11620*4882a593Smuzhiyunin the generated reports. 11621*4882a593Smuzhiyun 11622*4882a593SmuzhiyunIf analysis shows that the CVE issue does not impact the recipe due to configuration, platform, 11623*4882a593Smuzhiyunversion or other reasons, the CVE can be marked as ``Ignored`` using the :term:`CVE_CHECK_IGNORE` variable. 11624*4882a593SmuzhiyunAs mentioned previously, if data in the CVE database is wrong, it is recommend to fix those 11625*4882a593Smuzhiyunissues in the CVE database directly. 11626*4882a593Smuzhiyun 11627*4882a593SmuzhiyunRecipes can be completely skipped by CVE check by including the recipe name in 11628*4882a593Smuzhiyunthe :term:`CVE_CHECK_SKIP_RECIPE` variable. 11629*4882a593Smuzhiyun 11630*4882a593SmuzhiyunImplementation details 11631*4882a593Smuzhiyun---------------------- 11632*4882a593Smuzhiyun 11633*4882a593SmuzhiyunHere's what the :ref:`cve-check <ref-classes-cve-check>` class does to 11634*4882a593Smuzhiyunfind unpatched CVE IDs. 11635*4882a593Smuzhiyun 11636*4882a593SmuzhiyunFirst the code goes through each patch file provided by a recipe. If a valid CVE ID 11637*4882a593Smuzhiyunis found in the name of the file, the corresponding CVE is considered as patched. 11638*4882a593SmuzhiyunDon't forget that if multiple CVE IDs are found in the filename, only the last 11639*4882a593Smuzhiyunone is considered. Then, the code looks for ``CVE: CVE-ID`` lines in the patch 11640*4882a593Smuzhiyunfile. The found CVE IDs are also considered as patched. 11641*4882a593Smuzhiyun 11642*4882a593SmuzhiyunThen, the code looks up all the CVE IDs in the NIST database for all the 11643*4882a593Smuzhiyunproducts defined in :term:`CVE_PRODUCT`. Then, for each found CVE: 11644*4882a593Smuzhiyun 11645*4882a593Smuzhiyun- If the package name (:term:`PN`) is part of 11646*4882a593Smuzhiyun :term:`CVE_CHECK_SKIP_RECIPE`, it is considered as ``Patched``. 11647*4882a593Smuzhiyun 11648*4882a593Smuzhiyun- If the CVE ID is part of :term:`CVE_CHECK_IGNORE`, it is 11649*4882a593Smuzhiyun set as ``Ignored``. 11650*4882a593Smuzhiyun 11651*4882a593Smuzhiyun- If the CVE ID is part of the patched CVE for the recipe, it is 11652*4882a593Smuzhiyun already considered as ``Patched``. 11653*4882a593Smuzhiyun 11654*4882a593Smuzhiyun- Otherwise, the code checks whether the recipe version (:term:`PV`) 11655*4882a593Smuzhiyun is within the range of versions impacted by the CVE. If so, the CVE 11656*4882a593Smuzhiyun is considered as ``Unpatched``. 11657*4882a593Smuzhiyun 11658*4882a593SmuzhiyunThe CVE database is stored in :term:`DL_DIR` and can be inspected using 11659*4882a593Smuzhiyun``sqlite3`` command as follows:: 11660*4882a593Smuzhiyun 11661*4882a593Smuzhiyun sqlite3 downloads/CVE_CHECK/nvdcve_1.1.db .dump | grep CVE-2021-37462 11662*4882a593Smuzhiyun 11663*4882a593SmuzhiyunWhen analyzing CVEs, it is recommended to: 11664*4882a593Smuzhiyun 11665*4882a593Smuzhiyun- study the latest information in `CVE database <https://nvd.nist.gov/vuln/search>`__. 11666*4882a593Smuzhiyun 11667*4882a593Smuzhiyun- check how upstream developers of the software component addressed the issue, e.g. 11668*4882a593Smuzhiyun what patch was applied, which upstream release contains the fix. 11669*4882a593Smuzhiyun 11670*4882a593Smuzhiyun- check what other Linux distributions like `Debian <https://security-tracker.debian.org/tracker/>`__ 11671*4882a593Smuzhiyun did to analyze and address the issue. 11672*4882a593Smuzhiyun 11673*4882a593Smuzhiyun- follow security notices from other Linux distributions. 11674*4882a593Smuzhiyun 11675*4882a593Smuzhiyun- follow public `open source security mailing lists <https://oss-security.openwall.org/wiki/mailing-lists>`__ for 11676*4882a593Smuzhiyun discussions and advance notifications of CVE bugs and software releases with fixes. 11677*4882a593Smuzhiyun 11678*4882a593SmuzhiyunCreating a Software Bill of Materials 11679*4882a593Smuzhiyun===================================== 11680*4882a593Smuzhiyun 11681*4882a593SmuzhiyunOnce you are able to build an image for your project, once the licenses for 11682*4882a593Smuzhiyuneach software component are all identified (see 11683*4882a593Smuzhiyun":ref:`dev-manual/common-tasks:working with licenses`") and once vulnerability 11684*4882a593Smuzhiyunfixes are applied (see ":ref:`dev-manual/common-tasks:checking 11685*4882a593Smuzhiyunfor vulnerabilities`"), the OpenEmbedded build system can generate 11686*4882a593Smuzhiyuna description of all the components you used, their licenses, their dependencies, 11687*4882a593Smuzhiyunthe changes that were applied and the known vulnerabilities that were fixed. 11688*4882a593Smuzhiyun 11689*4882a593SmuzhiyunThis description is generated in the form of a *Software Bill of Materials* 11690*4882a593Smuzhiyun(:term:`SBOM`), using the :term:`SPDX` standard. 11691*4882a593Smuzhiyun 11692*4882a593SmuzhiyunWhen you release software, this is the most standard way to provide information 11693*4882a593Smuzhiyunabout the Software Supply Chain of your software image and SDK. The 11694*4882a593Smuzhiyun:term:`SBOM` tooling is often used to ensure open source license compliance by 11695*4882a593Smuzhiyunproviding the license texts used in the product which legal departments and end 11696*4882a593Smuzhiyunusers can read in standardized format. 11697*4882a593Smuzhiyun 11698*4882a593Smuzhiyun:term:`SBOM` information is also critical to performing vulnerability exposure 11699*4882a593Smuzhiyunassessments, as all the components used in the Software Supply Chain are listed. 11700*4882a593Smuzhiyun 11701*4882a593SmuzhiyunThe OpenEmbedded build system doesn't generate such information by default. 11702*4882a593SmuzhiyunTo make this happen, you must inherit the 11703*4882a593Smuzhiyun:ref:`create-spdx <ref-classes-create-spdx>` class from a configuration file:: 11704*4882a593Smuzhiyun 11705*4882a593Smuzhiyun INHERIT += "create-spdx" 11706*4882a593Smuzhiyun 11707*4882a593SmuzhiyunYou then get :term:`SPDX` output in JSON format as an 11708*4882a593Smuzhiyun``IMAGE-MACHINE.spdx.json`` file in ``tmp/deploy/images/MACHINE/`` inside the 11709*4882a593Smuzhiyun:term:`Build Directory`. 11710*4882a593Smuzhiyun 11711*4882a593SmuzhiyunThis is a toplevel file accompanied by an ``IMAGE-MACHINE.spdx.index.json`` 11712*4882a593Smuzhiyuncontaining an index of JSON :term:`SPDX` files for individual recipes, together 11713*4882a593Smuzhiyunwith an ``IMAGE-MACHINE.spdx.tar.zst`` compressed archive containing all such 11714*4882a593Smuzhiyunfiles. 11715*4882a593Smuzhiyun 11716*4882a593SmuzhiyunThe :ref:`ref-classes-create-spdx` class offers options to include 11717*4882a593Smuzhiyunmore information in the output :term:`SPDX` data, such as making the generated 11718*4882a593Smuzhiyunfiles more human readable (:term:`SPDX_PRETTY`), adding compressed archives of 11719*4882a593Smuzhiyunthe files in the generated target packages (:term:`SPDX_ARCHIVE_PACKAGED`), 11720*4882a593Smuzhiyunadding a description of the source files used to generate host tools and target 11721*4882a593Smuzhiyunpackages (:term:`SPDX_INCLUDE_SOURCES`) and adding archives of these source 11722*4882a593Smuzhiyunfiles themselves (:term:`SPDX_ARCHIVE_SOURCES`). 11723*4882a593Smuzhiyun 11724*4882a593SmuzhiyunThough the toplevel :term:`SPDX` output is available in 11725*4882a593Smuzhiyun``tmp/deploy/images/MACHINE/`` inside the :term:`Build Directory`, ancillary 11726*4882a593Smuzhiyungenerated files are available in ``tmp/deploy/spdx/MACHINE`` too, such as: 11727*4882a593Smuzhiyun 11728*4882a593Smuzhiyun- The individual :term:`SPDX` JSON files in the ``IMAGE-MACHINE.spdx.tar.zst`` 11729*4882a593Smuzhiyun archive. 11730*4882a593Smuzhiyun 11731*4882a593Smuzhiyun- Compressed archives of the files in the generated target packages, 11732*4882a593Smuzhiyun in ``packages/packagename.tar.zst`` (when :term:`SPDX_ARCHIVE_PACKAGED` 11733*4882a593Smuzhiyun is set). 11734*4882a593Smuzhiyun 11735*4882a593Smuzhiyun- Compressed archives of the source files used to build the host tools 11736*4882a593Smuzhiyun and the target packages in ``recipes/recipe-packagename.tar.zst`` 11737*4882a593Smuzhiyun (when :term:`SPDX_ARCHIVE_SOURCES` is set). Those are needed to fulfill 11738*4882a593Smuzhiyun "source code access" license requirements. 11739*4882a593Smuzhiyun 11740*4882a593SmuzhiyunSee the `tools page <https://spdx.dev/resources/tools/>`__ on the :term:`SPDX` 11741*4882a593Smuzhiyunproject website for a list of tools to consume and transform the :term:`SPDX` 11742*4882a593Smuzhiyundata generated by the OpenEmbedded build system. 11743*4882a593Smuzhiyun 11744*4882a593SmuzhiyunSee also Joshua Watt's 11745*4882a593Smuzhiyun`Automated SBoM generation with OpenEmbedded and the Yocto Project <https://youtu.be/Q5UQUM6zxVU>`__ 11746*4882a593Smuzhiyunpresentation at FOSDEM 2023. 11747*4882a593Smuzhiyun 11748*4882a593Smuzhiyun 11749*4882a593SmuzhiyunUsing the Error Reporting Tool 11750*4882a593Smuzhiyun============================== 11751*4882a593Smuzhiyun 11752*4882a593SmuzhiyunThe error reporting tool allows you to submit errors encountered during 11753*4882a593Smuzhiyunbuilds to a central database. Outside of the build environment, you can 11754*4882a593Smuzhiyunuse a web interface to browse errors, view statistics, and query for 11755*4882a593Smuzhiyunerrors. The tool works using a client-server system where the client 11756*4882a593Smuzhiyunportion is integrated with the installed Yocto Project 11757*4882a593Smuzhiyun:term:`Source Directory` (e.g. ``poky``). 11758*4882a593SmuzhiyunThe server receives the information collected and saves it in a 11759*4882a593Smuzhiyundatabase. 11760*4882a593Smuzhiyun 11761*4882a593SmuzhiyunThere is a live instance of the error reporting server at 11762*4882a593Smuzhiyunhttps://errors.yoctoproject.org. 11763*4882a593SmuzhiyunWhen you want to get help with build failures, you can submit all of the 11764*4882a593Smuzhiyuninformation on the failure easily and then point to the URL in your bug 11765*4882a593Smuzhiyunreport or send an email to the mailing list. 11766*4882a593Smuzhiyun 11767*4882a593Smuzhiyun.. note:: 11768*4882a593Smuzhiyun 11769*4882a593Smuzhiyun If you send error reports to this server, the reports become publicly 11770*4882a593Smuzhiyun visible. 11771*4882a593Smuzhiyun 11772*4882a593SmuzhiyunEnabling and Using the Tool 11773*4882a593Smuzhiyun--------------------------- 11774*4882a593Smuzhiyun 11775*4882a593SmuzhiyunBy default, the error reporting tool is disabled. You can enable it by 11776*4882a593Smuzhiyuninheriting the 11777*4882a593Smuzhiyun:ref:`report-error <ref-classes-report-error>` 11778*4882a593Smuzhiyunclass by adding the following statement to the end of your 11779*4882a593Smuzhiyun``local.conf`` file in your 11780*4882a593Smuzhiyun:term:`Build Directory`. 11781*4882a593Smuzhiyun:: 11782*4882a593Smuzhiyun 11783*4882a593Smuzhiyun INHERIT += "report-error" 11784*4882a593Smuzhiyun 11785*4882a593SmuzhiyunBy default, the error reporting feature stores information in 11786*4882a593Smuzhiyun``${``\ :term:`LOG_DIR`\ ``}/error-report``. 11787*4882a593SmuzhiyunHowever, you can specify a directory to use by adding the following to 11788*4882a593Smuzhiyunyour ``local.conf`` file:: 11789*4882a593Smuzhiyun 11790*4882a593Smuzhiyun ERR_REPORT_DIR = "path" 11791*4882a593Smuzhiyun 11792*4882a593SmuzhiyunEnabling error 11793*4882a593Smuzhiyunreporting causes the build process to collect the errors and store them 11794*4882a593Smuzhiyunin a file as previously described. When the build system encounters an 11795*4882a593Smuzhiyunerror, it includes a command as part of the console output. You can run 11796*4882a593Smuzhiyunthe command to send the error file to the server. For example, the 11797*4882a593Smuzhiyunfollowing command sends the errors to an upstream server:: 11798*4882a593Smuzhiyun 11799*4882a593Smuzhiyun $ send-error-report /home/brandusa/project/poky/build/tmp/log/error-report/error_report_201403141617.txt 11800*4882a593Smuzhiyun 11801*4882a593SmuzhiyunIn the previous example, the errors are sent to a public database 11802*4882a593Smuzhiyunavailable at https://errors.yoctoproject.org, which is used by the 11803*4882a593Smuzhiyunentire community. If you specify a particular server, you can send the 11804*4882a593Smuzhiyunerrors to a different database. Use the following command for more 11805*4882a593Smuzhiyuninformation on available options:: 11806*4882a593Smuzhiyun 11807*4882a593Smuzhiyun $ send-error-report --help 11808*4882a593Smuzhiyun 11809*4882a593SmuzhiyunWhen sending the error file, you are prompted to review the data being 11810*4882a593Smuzhiyunsent as well as to provide a name and optional email address. Once you 11811*4882a593Smuzhiyunsatisfy these prompts, the command returns a link from the server that 11812*4882a593Smuzhiyuncorresponds to your entry in the database. For example, here is a 11813*4882a593Smuzhiyuntypical link: https://errors.yoctoproject.org/Errors/Details/9522/ 11814*4882a593Smuzhiyun 11815*4882a593SmuzhiyunFollowing the link takes you to a web interface where you can browse, 11816*4882a593Smuzhiyunquery the errors, and view statistics. 11817*4882a593Smuzhiyun 11818*4882a593SmuzhiyunDisabling the Tool 11819*4882a593Smuzhiyun------------------ 11820*4882a593Smuzhiyun 11821*4882a593SmuzhiyunTo disable the error reporting feature, simply remove or comment out the 11822*4882a593Smuzhiyunfollowing statement from the end of your ``local.conf`` file in your 11823*4882a593Smuzhiyun:term:`Build Directory`. 11824*4882a593Smuzhiyun:: 11825*4882a593Smuzhiyun 11826*4882a593Smuzhiyun INHERIT += "report-error" 11827*4882a593Smuzhiyun 11828*4882a593SmuzhiyunSetting Up Your Own Error Reporting Server 11829*4882a593Smuzhiyun------------------------------------------ 11830*4882a593Smuzhiyun 11831*4882a593SmuzhiyunIf you want to set up your own error reporting server, you can obtain 11832*4882a593Smuzhiyunthe code from the Git repository at :yocto_git:`/error-report-web/`. 11833*4882a593SmuzhiyunInstructions on how to set it up are in the README document. 11834*4882a593Smuzhiyun 11835*4882a593SmuzhiyunUsing Wayland and Weston 11836*4882a593Smuzhiyun======================== 11837*4882a593Smuzhiyun 11838*4882a593Smuzhiyun`Wayland <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)>`__ 11839*4882a593Smuzhiyunis a computer display server protocol that provides a method for 11840*4882a593Smuzhiyuncompositing window managers to communicate directly with applications 11841*4882a593Smuzhiyunand video hardware and expects them to communicate with input hardware 11842*4882a593Smuzhiyunusing other libraries. Using Wayland with supporting targets can result 11843*4882a593Smuzhiyunin better control over graphics frame rendering than an application 11844*4882a593Smuzhiyunmight otherwise achieve. 11845*4882a593Smuzhiyun 11846*4882a593SmuzhiyunThe Yocto Project provides the Wayland protocol libraries and the 11847*4882a593Smuzhiyunreference 11848*4882a593Smuzhiyun`Weston <https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston>`__ 11849*4882a593Smuzhiyuncompositor as part of its release. You can find the integrated packages 11850*4882a593Smuzhiyunin the ``meta`` layer of the :term:`Source Directory`. 11851*4882a593SmuzhiyunSpecifically, you 11852*4882a593Smuzhiyuncan find the recipes that build both Wayland and Weston at 11853*4882a593Smuzhiyun``meta/recipes-graphics/wayland``. 11854*4882a593Smuzhiyun 11855*4882a593SmuzhiyunYou can build both the Wayland and Weston packages for use only with 11856*4882a593Smuzhiyuntargets that accept the `Mesa 3D and Direct Rendering 11857*4882a593SmuzhiyunInfrastructure <https://en.wikipedia.org/wiki/Mesa_(computer_graphics)>`__, 11858*4882a593Smuzhiyunwhich is also known as Mesa DRI. This implies that you cannot build and 11859*4882a593Smuzhiyunuse the packages if your target uses, for example, the Intel Embedded 11860*4882a593SmuzhiyunMedia and Graphics Driver (Intel EMGD) that overrides Mesa DRI. 11861*4882a593Smuzhiyun 11862*4882a593Smuzhiyun.. note:: 11863*4882a593Smuzhiyun 11864*4882a593Smuzhiyun Due to lack of EGL support, Weston 1.0.3 will not run directly on the 11865*4882a593Smuzhiyun emulated QEMU hardware. However, this version of Weston will run 11866*4882a593Smuzhiyun under X emulation without issues. 11867*4882a593Smuzhiyun 11868*4882a593SmuzhiyunThis section describes what you need to do to implement Wayland and use 11869*4882a593Smuzhiyunthe Weston compositor when building an image for a supporting target. 11870*4882a593Smuzhiyun 11871*4882a593SmuzhiyunEnabling Wayland in an Image 11872*4882a593Smuzhiyun---------------------------- 11873*4882a593Smuzhiyun 11874*4882a593SmuzhiyunTo enable Wayland, you need to enable it to be built and enable it to be 11875*4882a593Smuzhiyunincluded (installed) in the image. 11876*4882a593Smuzhiyun 11877*4882a593SmuzhiyunBuilding Wayland 11878*4882a593Smuzhiyun~~~~~~~~~~~~~~~~ 11879*4882a593Smuzhiyun 11880*4882a593SmuzhiyunTo cause Mesa to build the ``wayland-egl`` platform and Weston to build 11881*4882a593SmuzhiyunWayland with Kernel Mode Setting 11882*4882a593Smuzhiyun(`KMS <https://wiki.archlinux.org/index.php/Kernel_Mode_Setting>`__) 11883*4882a593Smuzhiyunsupport, include the "wayland" flag in the 11884*4882a593Smuzhiyun:term:`DISTRO_FEATURES` 11885*4882a593Smuzhiyunstatement in your ``local.conf`` file:: 11886*4882a593Smuzhiyun 11887*4882a593Smuzhiyun DISTRO_FEATURES:append = " wayland" 11888*4882a593Smuzhiyun 11889*4882a593Smuzhiyun.. note:: 11890*4882a593Smuzhiyun 11891*4882a593Smuzhiyun If X11 has been enabled elsewhere, Weston will build Wayland with X11 11892*4882a593Smuzhiyun support 11893*4882a593Smuzhiyun 11894*4882a593SmuzhiyunInstalling Wayland and Weston 11895*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 11896*4882a593Smuzhiyun 11897*4882a593SmuzhiyunTo install the Wayland feature into an image, you must include the 11898*4882a593Smuzhiyunfollowing 11899*4882a593Smuzhiyun:term:`CORE_IMAGE_EXTRA_INSTALL` 11900*4882a593Smuzhiyunstatement in your ``local.conf`` file:: 11901*4882a593Smuzhiyun 11902*4882a593Smuzhiyun CORE_IMAGE_EXTRA_INSTALL += "wayland weston" 11903*4882a593Smuzhiyun 11904*4882a593SmuzhiyunRunning Weston 11905*4882a593Smuzhiyun-------------- 11906*4882a593Smuzhiyun 11907*4882a593SmuzhiyunTo run Weston inside X11, enabling it as described earlier and building 11908*4882a593Smuzhiyuna Sato image is sufficient. If you are running your image under Sato, a 11909*4882a593SmuzhiyunWeston Launcher appears in the "Utility" category. 11910*4882a593Smuzhiyun 11911*4882a593SmuzhiyunAlternatively, you can run Weston through the command-line interpretor 11912*4882a593Smuzhiyun(CLI), which is better suited for development work. To run Weston under 11913*4882a593Smuzhiyunthe CLI, you need to do the following after your image is built: 11914*4882a593Smuzhiyun 11915*4882a593Smuzhiyun1. Run these commands to export ``XDG_RUNTIME_DIR``:: 11916*4882a593Smuzhiyun 11917*4882a593Smuzhiyun mkdir -p /tmp/$USER-weston 11918*4882a593Smuzhiyun chmod 0700 /tmp/$USER-weston 11919*4882a593Smuzhiyun export XDG_RUNTIME_DIR=/tmp/$USER-weston 11920*4882a593Smuzhiyun 11921*4882a593Smuzhiyun2. Launch Weston in the shell:: 11922*4882a593Smuzhiyun 11923*4882a593Smuzhiyun weston 11924