My learnings on bitbake

Jyothi
4 min readDec 11, 2024

--

Bitbake is a task execution tool primarily used in the Yocto Project for creating custom Linux distributions and embedded software. It streamlines the processes of fetching, configuring, compiling, and packaging software components, such as U-Boot, the kernel, and various applications. Additionally, Bitbake supports cross-compilation for target architectures using appropriate tools.

To define the fetching, configuring, compiling, and packaging procedures for each software package and its dependencies, Bitbake defines recipe files (.bb). These files contain several components, including metadata, source information, dependencies, tasks, variables, functions, and overrides. For a more detailed explanation, refer to 5 Writing a New Recipe — The Yocto Project ® 5.1.999 documentation.

Key Points About Recipe Files:

  • Metadata: This includes essential information such as the package name, version, description, and license.
  • LICENSE: This specifies the licensing terms under which the software is distributed. It comprises the license type, a checksum for the license file, and any custom licenses. The LICENSE variable can accept various standard string values representing different software licenses. Common examples include:

These string values are crucial for ensuring compliance with legal and open-source requirements.

  • License Verification: For standard license types, the verification process involves checking the MD5 checksum of the specified license file or its relevant sections. This ensures that the license text aligns with the expected content. The LIC_FILES_CHECKSUM variable is used to specify the filename, line numbers, and MD5 checksum. For example:
  • CLOSED License Type: This is used for software that is not open source or cannot be freely distributed or due to significant restrictions. When applying this license type, no checksum for a license file is necessary, as the source code and license text are not publicly accessible.
  • Source Code Fetching: Source code can be retrieved using various fetchers, including local file fetchers (file://), HTTP/FTP fetchers (http://, ftp://, https:// ), and version control system fetchers (git://, svn://, cvs://, hg://). The SRC_URI variable specifies the locations for fetching this source code.
  • Checksum Verification: The SRC_URI[sha256sum] variable in a BitBake recipe is used to define the SHA-256 checksum of the source file being fetched, ensuring the integrity and authenticity of the downloaded file.
  • Source Revision Control: The SRCREV variable specifies the exact revision (or commit) of the source code to retrieve from a version control system (VCS) like Git, Subversion, or Mercurial, allowing precise control over the version used during the build process.
  • Including Binutils: To incorporate binutils (a collection of binary tools such as gcc, ar, ld, etc.) into the root filesystem, add IMAGE_INSTALL += “binutils” to your image recipe file.
  • Dependency Management:
  • Autotools Integration: Using inherit autotools in your BitBake recipe allows you to bypass defining standard functions like do_configure, do_compile, and do_install, as the autotools class provides default implementations for these functions.
  • Linker Flags: The EXTRA_LDFLAGS variable in BitBake is used to specify additional linker flags that should be passed during the package build process. These flags are appended to the default LDFLAGS.
  • Source and Build Directories:
  • Make Command Arguments: The EXTRA_OEMAKE variable in BitBake allows you to pass additional arguments to the make command during the build process. For example: EXTRA_OEMAKE = “-j4 CFLAGS=’-O2 -g’”.
  • Library Compilation: To compile both shared and static libraries, you can define:

.bbappend file:

.bbappend file BitBake append file, is used to modify or extend an existing BitBake recipe (.bb file) without directly altering the original recipe. This is particularly useful in the Yocto Project and OpenEmbedded environments where maintaining customizations separately from the original metadata is important for manageability and upgradeability.

Key Bitbake Options:

  • Use -v, -D, -DD, or -DDD for detailed output and debugging.
  • Add set -x and set +x to enable and disable shell debugging within functions like do_configure/do_compile().
  • Bitbake logs in the work directory gives debugging info; check for files like log.do_configure, log.do_compile.
  • The command bitbake -s displays a summary of available recipes and their versions. For example: bitbake -s | grep recipe_name.
  • To add a new layer to the BitBake build environment, use the command bitbake-layers add-layer meta-my-layer. This updates the bblayers.conf file in the build directory to include the specified layer, making its recipes and configurations accessible for the build process.
  • The command bitbake-layers show-layers lists all layers currently included in the build environment, along with their priorities and paths.
  • When executing bitbake -c populate_sysroot <recipe>, BitBake performs several steps:
  • The command bitbake -e displays the environment variables and their values for a specific BitBake recipe, which is particularly useful for debugging. For example:
  • Adding INHERIT:remove = “license” to local.conf removes the license handling class (license.bbclass) from the BitBake build process.
  • The command bitbake -c patch <recipe-name> -v applies patches to the source code of a specified recipe.

Troubleshooting Bitbake:

If Bitbake fails to start and gives below errors:

NOTE: Reconnecting to bitbake server… NOTE: Previous bitbake instance shutting down?, waiting to retry… NOTE: Retrying server connection (#1)… NOTE: Reconnecting to bitbake server…

Consider the following steps :

  1. Terminate the BitBake Process: First, identify the process ID (PID) of BitBake by executing the command:
  2. Remove BitBake Files: Next, delete the BitBake socket, lock, and temporary files using the following commands:
  3. Source Your Build Environment: Finally, ensure that your build environment is correctly sourced by running:

References: 5 Writing a New Recipe — The Yocto Project ® 5.1.999 documentation

--

--

No responses yet