Using the Yocto Project This chapter describes common usage for the Yocto Project. The information is introductory in nature as other manuals in the Yocto Project provide more details on how to use the Yocto Project.
Running a Build You can find general information on how to build an image using the Yocto Project in the "Building an Image" section of The Yocto Project Quick Start. This section provides a summary of the build process and provides information for less obvious aspects of the build process.
Build Overview The first thing you need to do is set up the Yocto Project build environment by sourcing the environment setup script as follows: $ source oe-init-build-env [build_dir] The build_dir is optional and specifies the directory Yocto Project uses for the build. If you do not specify a build directory it defaults to build in your current working directory. A common practice is to use a different build directory for different targets. For example, ~/build/x86 for a qemux86 target, and ~/build/arm for a qemuarm target. See oe-init-build-env for more information on this script. Once the Yocto Project build environment is set up, you can build a target using: $ bitbake <target> 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, etc. all found in the Yocto Project files. Or, 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 Yocto Project supports, see the "Reference: Images" appendix. Building an image without GNU Public License Version 3 (GPLv3) components is only supported for minimal and base images. See the "Reference: Images" appendix for more information.
Building an Image Using GPL Components When building an image using GPL components, you need to maintain your original settings and not switch back and forth applying different versions of the GNU Public License. If you rebuild using different versions of GPL, dependency errors might occur due to some components not being rebuilt.
Installing and Using the Result Once an image has been built, it often needs to be installed. The images and kernels built by the Yocto Project are placed in the build directory in tmp/deploy/images. For information on how to run pre-built images such as qemux86 and qemuarm, see the "Using Pre-Built Binaries and QEMU" section in The Yocto Project Quick Start. For information about how to install these images, see the documentation for your particular board/machine.
Debugging Build Failures The exact method for debugging Yocto Project build failures depends on the nature of the problem and on the system's area from which the bug originates. Standard debugging practices such as comparison against the last known working version with examination of the changes and the re-application of steps to identify the one causing the problem are valid for Yocto Project just as they are for any other system. Even though it is impossible to detail every possible potential failure, this section provides some general tips to aid in debugging.
Task Failures The log file for shell tasks is available in ${WORKDIR}/temp/log.do_taskname.pid. For example, the compile task for the QEMU minimal image for the x86 machine (qemux86) might be tmp/work/qemux86-poky-linux/core-image-minimal-1.0-r0/temp/log.do_compile.20830. To see what BitBake runs to generate that log, look at the corresponding run.do_taskname.pid file located in the same directory. Presently, the output from Python tasks is sent directly to the console.
Running Specific Tasks Any given package consists of a set of tasks. The standard BitBake behavior in most cases is: fetch, unpack, patch, configure, compile, install, package, package_write, and build. The default task is build and any tasks on which it depends build first. Some tasks exist, such as devshell, that are not part of the default build chain. If you wish to run a task that is not part of the default build chain, you can use the -c option in BitBake as follows: $ bitbake matchbox-desktop -c devshell If you wish to rerun a task, use the -f force option. For example, the following sequence forces recompilation after changing files in the working directory. $ bitbake matchbox-desktop . . [make some changes to the source code in the working directory] . . $ bitbake matchbox-desktop -c compile -f $ bitbake matchbox-desktop This sequence first builds matchbox-desktop and then recompiles it. The last command reruns all tasks (basically the packaging tasks) after the compile. BitBake recognizes that the compile task was rerun and therefore understands that the other tasks also need to be run again. You can view a list of tasks in a given package by running the listtasks task as follows: $ bitbake matchbox-desktop -c listtasks The results are in the file ${WORKDIR}/temp/log.do_listtasks.
Dependency Graphs Sometimes it can be hard to see why BitBake wants to build some other packages before a given package you have specified. The bitbake -g targetname command creates the depends.dot and task-depends.dot files in the current directory. These files show the package and task dependencies and are useful for debugging problems. You can use the bitbake -g -u depexp targetname command to display the results in a more human-readable form.
General BitBake Problems You can see debug output from BitBake by using the -D option. The debug output gives more information about what BitBake is doing and the reason behind it. Each -D option you use increases the logging level. The most common usage is -DDD. The output from bitbake -DDD -v targetname can reveal why BitBake chose a certain version of a package or why BitBake picked a certain provider. This command could also help you in a situation where you think BitBake did something unexpected.
Building with No Dependencies If you really want to build a specific .bb file, you can use the command form bitbake -b <somepath/somefile.bb>. This command form does not check for dependencies so you should use it only when you know its dependencies already exist. You can also specify fragments of the filename. In this case, BitBake checks for a unique match.
Variables The -e option dumps the resulting environment for either the configuration (no package specified) or for a specific package when specified; or -b recipename to show the environment from parsing a single recipe file only.
Recipe Logging Mechanisms Best practices exist while writing recipes that both log build progress and act on build conditions such as warnings and errors. Both Python and Bash language bindings exist for the logging mechanism: Python: For Python functions, BitBake supports several loglevels: bb.fatal, bb.error, bb.warn, bb.note, bb.plain, and bb.debug. Bash: For Bash functions, the same set of loglevels exist and are accessed with a similar syntax: bbfatal, bberror, bbwarn, bbnote, bbplain, and bbdebug. For guidance on how logging is handled in both Python and Bash recipes, see the logging.bbclass file in the meta/classes directory of the Yocto Project files.
Logging With Python When creating recipes using Python and inserting code that handles build logs keep in mind the goal is to have informative logs while keeping the console as "silent" as possible. Also, if you want status messages in the log use the "debug" loglevel. Following is an example written in Python. The code handles logging for a function that determines the number of tasks needed to be run: python do_listtasks() { bb.debug(2, "Starting to figure out the task list") if noteworthy_condition: bb.note("There are 47 tasks to run") bb.debug(2, "Got to point xyz") if warning_trigger: bb.warn("Detected warning_trigger, this might be a problem later.") if recoverable_error: bb.error("Hit recoverable_error, you really need to fix this!") if fatal_error: bb.fatal("fatal_error detected, unable to print the task list") bb.plain("The tasks present are abc") bb.debug(2, "Finished figureing out the tasklist") }
Logging With Bash When creating recipes using Bash and inserting code that handles build logs you have the same goals - informative with minimal console output. The syntax you use for recipes written in Bash is similar to that of recipes written in Python described in the previous section. Following is an example written in Bash. The code logs the progress of the do_my_function function. do_my_function() { bbdebug 2 "Running do_my_function" if [ exceptional_condition ]; then bbnote "Hit exceptional_condition" fi bbdebug 2 "Got to point xyz" if [ warning_trigger ]; then bbwarn "Detected warning_trigger, this might cause a problem later." fi if [ recoverable_error ]; then bberror "Hit recoverable_error, correcting" fi if [ fatal_error ]; then bbfatal "fatal_error detected" fi bbdebug 2 "Completed do_my_function" }
Other Tips Here are some other tips that you might find useful: When adding new packages, it is worth watching for undesirable items making their way into compiler command lines. For example, you do not want references to local system files like /usr/lib/ or /usr/include/. If you want to remove the psplash boot splashscreen, add psplash=false to the kernel command line. Doing so prevents psplash from loading and thus allows you to see the console. It is also possible to switch out of the splashscreen by switching the virtual console (e.g. Fn+Left or Fn+Right on a Zaurus).