.. SPDX-License-Identifier: CC-BY-SA-2.0-UK Building ******** This section describes various build procedures, such as the steps needed for a simple build, building a target for multiple configurations, generating an image for more than one machine, and so forth. Building a Simple Image ======================= In the development environment, you need to build an image whenever you change hardware support, add or change system libraries, or add or change services that have dependencies. There are several methods that allow you to build an image within the Yocto Project. This section presents the basic steps you need to build a simple image using BitBake from a build host running Linux. .. note:: - For information on how to build an image using :term:`Toaster`, see the :doc:`/toaster-manual/index`. - For information on how to use ``devtool`` to build images, see the ":ref:`sdk-manual/extensible:using \`\`devtool\`\` in your sdk workflow`" section in the Yocto Project Application Development and the Extensible Software Development Kit (eSDK) manual. - For a quick example on how to build an image using the OpenEmbedded build system, see the :doc:`/brief-yoctoprojectqs/index` document. - You can also use the `Yocto Project BitBake `__ extension for Visual Studio Code to build images. The build process creates an entire Linux distribution from source and places it in your :term:`Build Directory` under ``tmp/deploy/images``. For detailed information on the build process using BitBake, see the ":ref:`overview-manual/concepts:images`" section in the Yocto Project Overview and Concepts Manual. The following figure and list overviews the build process: .. image:: figures/bitbake-build-flow.png :width: 100% #. *Set up Your Host Development System to Support Development Using the Yocto Project*: See the ":doc:`start`" section for options on how to get a build host ready to use the Yocto Project. #. *Initialize the Build Environment:* Initialize the build environment by sourcing the build environment script (i.e. :ref:`structure-core-script`):: $ source oe-init-build-env [build_dir] When you use the initialization script, the OpenEmbedded build system uses ``build`` as the default :term:`Build Directory` in your current work directory. You can use a `build_dir` argument with the script to specify a different :term:`Build Directory`. .. note:: A common practice is to use a different :term:`Build Directory` for different targets; for example, ``~/build/x86`` for a ``qemux86`` target, and ``~/build/arm`` for a ``qemuarm`` target. In any event, it's typically cleaner to locate the :term:`Build Directory` somewhere outside of your source directory. #. *Make Sure Your* ``local.conf`` *File is Correct*: Ensure the ``conf/local.conf`` configuration file, which is found in the :term:`Build Directory`, is set up how you want it. This file defines many aspects of the build environment including the target machine architecture through the :term:`MACHINE` variable, the packaging format used during the build (:term:`PACKAGE_CLASSES`), and a centralized tarball download directory through the :term:`DL_DIR` variable. #. *Build the Image:* Build the image using the ``bitbake`` command:: $ bitbake target .. note:: For information on BitBake, see the :doc:`bitbake:index`. The target is the name of the recipe you want to build. Common targets are the images in ``meta/recipes-core/images``, ``meta/recipes-sato/images``, and so forth all found in the :term:`Source Directory`. Alternatively, the target can be the name of a recipe for a specific piece of software such as BusyBox. For more details about the images the OpenEmbedded build system supports, see the ":ref:`ref-manual/images:Images`" chapter in the Yocto Project Reference Manual. As an example, the following command builds the ``core-image-minimal`` image:: $ bitbake core-image-minimal Once an image has been built, it often needs to be installed. The images and kernels built by the OpenEmbedded build system are placed in the :term:`Build Directory` in ``tmp/deploy/images``. For information on how to run pre-built images such as ``qemux86`` and ``qemuarm``, see the :doc:`/sdk-manual/index` manual. For information about how to install these images, see the documentation for your particular board or machine. Building Images for Multiple Targets Using Multiple Configurations ================================================================== See the :doc:`multiconfig` section of the Yocto Project Development Tasks Manual. Building an Initial RAM Filesystem (Initramfs) Image ==================================================== An initial RAM filesystem (:term:`Initramfs`) image provides a temporary root filesystem used for early system initialization, typically providing tools and loading modules needed to locate and mount the final root filesystem. Follow these steps to create an :term:`Initramfs` image: #. *Create the Initramfs Image Recipe:* You can reference the ``core-image-minimal-initramfs.bb`` recipe found in the ``meta/recipes-core`` directory of the :term:`Source Directory` as an example from which to work. The ``core-image-minimal-initramfs`` recipe is based on the :ref:`initramfs-framework ` recipe described below. #. *Decide if You Need to Bundle the Initramfs Image Into the Kernel Image:* If you want the :term:`Initramfs` image that is built to be bundled in with the kernel image, set the :term:`INITRAMFS_IMAGE_BUNDLE` variable to ``"1"`` in your ``local.conf`` configuration file and set the :term:`INITRAMFS_IMAGE` variable in the recipe that builds the kernel image. Setting the :term:`INITRAMFS_IMAGE_BUNDLE` flag causes the :term:`Initramfs` image to be unpacked into the ``${B}/usr/`` directory. The unpacked :term:`Initramfs` image is then passed to the kernel's ``Makefile`` using the :term:`CONFIG_INITRAMFS_SOURCE` variable, allowing the :term:`Initramfs` image to be built into the kernel normally. #. *Optionally Add Items to the Initramfs Image Through the Initramfs Image Recipe:* If you add items to the :term:`Initramfs` image by way of its recipe, you should use :term:`PACKAGE_INSTALL` rather than :term:`IMAGE_INSTALL`. :term:`PACKAGE_INSTALL` gives more direct control of what is added to the image as compared to the defaults you might not necessarily want that are set by the :ref:`ref-classes-image` or :ref:`ref-classes-core-image` classes. #. *Build the Kernel Image and the Initramfs Image:* Build your kernel image using BitBake. Because the :term:`Initramfs` image recipe is a dependency of the kernel image, the :term:`Initramfs` image is built as well and bundled with the kernel image if you used the :term:`INITRAMFS_IMAGE_BUNDLE` variable described earlier. Customizing an Initramfs using ``initramfs-framework`` ------------------------------------------------------ The ``core-image-minimal-initramfs.bb`` recipe found in :oe_git:`meta/recipes-core/images ` uses the :oe_git:`initramfs-framework_1.0.bb ` recipe as its base component. The goal of the ``initramfs-framework`` recipe is to provide the building blocks to build a customized :term:`Initramfs`. The ``initramfs-framework`` recipe relies on shell initialization scripts defined in :oe_git:`meta/recipes-core/initrdscripts/initramfs-framework `. Since some of these scripts do not apply for all use cases, the ``initramfs-framework`` recipe defines different packages: - ``initramfs-framework-base``: this package installs the basic components of an :term:`Initramfs`, such as the ``init`` script or the ``/dev/console`` character special file. As this package is a runtime dependency of all modules listed below, it is automatically pulled in when one of the modules is installed in the image. - ``initramfs-module-exec``: support for execution of applications. - ``initramfs-module-mdev``: support for `mdev `__. - ``initramfs-module-udev``: support for :wikipedia:`Udev `. - ``initramfs-module-e2fs``: support for :wikipedia:`ext4/ext3/ext2 ` filesystems. - ``initramfs-module-nfsrootfs``: support for locating and mounting the root partition via :wikipedia:`NFS `. - ``initramfs-module-rootfs``: support for locating and mounting the root partition. - ``initramfs-module-debug``: dynamic debug support. - ``initramfs-module-lvm``: :wikipedia:`LVM ` rootfs support. - ``initramfs-module-overlayroot``: support for mounting a read-write overlay on top of a read-only root filesystem. In addition to the packages defined by the ``initramfs-framework`` recipe itself, the following packages are defined by the recipes present in :oe_git:`meta/recipes-core/initrdscripts `: - ``initramfs-module-install``: module to create and install a partition layout on a selected block device. - ``initramfs-module-install-efi``: module to create and install an EFI partition layout on a selected block device. - ``initramfs-module-setup-live``: module to start a shell in the :term:`Initramfs` if ``root=/dev/ram0`` in passed in the `Kernel command-line `__ or the ``root=`` parameter was not passed. To customize the :term:`Initramfs`, you can add or remove packages listed earlier from the :term:`PACKAGE_INSTALL` variable with a :ref:`bbappend ` on the ``core-image-minimal-initramfs`` recipe, or create a custom recipe for the :term:`Initramfs` taking ``core-image-minimal-initramfs`` as example. Custom scripts can be added to the :term:`Initramfs` by writing your own recipes. The recipes are conventionally named ``initramfs-module-`` where ```` is the name of the module. The recipe should set its :term:`RDEPENDS` package-specific variables to include ``initramfs-framework-base`` and the other packages on which the module depends at runtime. The recipe must install shell initialization scripts in :term:`${D} `\ ``/init.d`` and must follow the ``-