Yocto Project Interview Questions and Answers

Yocto is an Open-source Project and used to create custom Linux for embedded devices. This is part-2 of the Yocto Interview Questions and Answers which surely gonna help you in your professional interviews. Here we are going to discuss the Build Process, bbclass files, PREFERRED_VERSION variable, bb utils function, and state cache use case, etc...

What are the steps required to build a custom Linux image using the Yocto Project?

  • The Yocto Project provides tools, metadata, and a build framework to create the custom Linux image for your target board.
  • You have to follow the below steps to building the image with the Yocto Project.
    1. You need to install some tools on your host system to support the Yocto Project Development.
    2. Download the Poky source code from the Yocto repository.
    3. Setup the build environment by running the oe-init-build-env script from the Poky directory.
    4. Select the machine (target board name) from local.conf file.
    5. Run the bitbake command from the build directory to create the image.

What is the bbclass in the Yocto?

    • A bbclass file contains common functionality that is shared between the multiple recipes.
    • .bbclass is the extension of the class files.
    • Each meta-layer has a class directory that contains the .bbclass files.
# You can use bbclass in the recipe by inheriting the class file.
# autotools.bbclass is a class file present in meta directory.
inherit autotools

How to build a particular version of a software package in the Yocto Project when there is multiple version of recipe present.

    • By default, if multiple versions of the recipe present in the layer then Bitbake selects the latest version of the recipe.
    • Suppose you have multiple versions of linux-yocto recipe in your meta layer then you can select any version of the recipe with the below code.
    • Add this code in your local.conf file
# Select the particular version of the recipe 
PREFERRED_VERSION_package_name = “version”

#Here package_name is linux-yocto and version 4.14
PREFERRED_VERSION_linux-yocto =	“4.14”

# Some time you need to add the "%" symbol to match with the version string
PREFERRED_VERSION_linux-yocto =	“4.14%”

What is the bitbake utility function in the bitbake recipe?

  • bb.utils is the bitbake utility function and bb.utils.contains function is most commonly used in the bitbake recipe.
  • You can find the complete code of the bibake utility function from here
  • Basic Syntex of the bb.utils.contains function.
  • bb.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
    1. variable - Name of the variable
    2. checkvalues - This argument is used to check the presence of checkvalues in variable value
    3. truevalue - if checkvalues is a subset of variable then it returns the 3rd argument truevalue
    4. falsevalue -- if checkvalues is not a subset of variable then return 4th argument falsevalue
    5. d - the data store.
  • Example:
  • A hello_1.0.bb recipe contains the below code snippet and we are checking the var1 and var2 values using the bb.utils.contains function.

bb.utils.contains function

# if var1 and var2 value is correct then return True otherwise False
var1 = "10"
var2 = "hello"
foo1 = "${@bb.utils.contains('var1', '10', 'True', 'False', d)}"
foo2 = "${@bb.utils.contains('var2', 'hello', 'True', 'False', d)}"
foo3 = "${@bb.utils.contains('var1', '20', 'True', 'False', d)}"

# As per the above code we will get the below result.

bb.utils.contains function output

What is shared state cache(sstate cache ) in Yocto Project?

  • It stores the intermediate files which are generated during the build process.
  • This sstate-cache directory is used to speed up the build process.
  • You can find this directory inside the build folder.