Menu-Submenu

Bitbake


Bitbake - build engine

  • Basically it is a Python program which, driven by user created configuration, can execute user created tasks for user specified targets, so called recipes.
  • It is concerned with building and deploying the packages
  • It needs to deploy all the packages that are needed to satisfy run-time dependencies on the target system
  • Built tool primary by the OpenEmbedded and Yocto Project, to build Linux distributions.


NOTE: https://a4z.bitbucket.io/docs/BitBake/guide.html Tutorial to create the smallest possible project and extend it step by step to show and explain how BitBake works

Build-time dependency

within T.bb (recipe of T)
DEPEND:= P
  • P must be built before T; as T can’t be built without P
  • P::do_populate_sysroot()   –> T::do_configure()

Example,
in tar.bb
DEPEND:= gcc
Here it is DEPEND, because
  • tar can’t be built without gcc (C compiler)
  • but there is no need gcc (C compiler) to use tar; tar can be deployed without deploying gcc (C compiler)


Run-time dependency

within T.bb (recipe of T)
RDEPEND:= P
  • P must be deploy to the target system if it deploys T; as T can’t be used without P
  • P::do_package_write() –> T::do_build()

Example,
in tar.bb
RDEPEND:= libc
Here it is RDEPEND, because
  • tar can’t be used without libc (C run-time library)
  • if tar is deployed then libc (C run-time library) must also be deployed


Bitbake Command Line options


Option
Meaning
-h --help
Show usage help
-s
Show recipe version information
(latest & preferred versions)
-c <task>
Execute specified task
-f
Force execution of operation (specified task), even if not required.
Removes stamp file & Rebuild from scratch.
-k
To continue execution on errors
-b
Execute tasks from the given recipe (without resolving dependencies)
-v
Show verbose output
-DDD
Show lots of debug information
-g
Output dependency tree in graphviz format
-e
List build environment on a global or image or per-recipes basis (even if recipe is not part of built image)
bitbake -env
Show individual bitbake variable values
--version
Show bitbake version


Bitbake tasks

task examples: listtasks, fetch, fetchall, devshell, compile, clearall, clearstate etc
Each task has resp function, like compile task function is do_compile() [with/without _append() or _prepend()]
  • BitBake stores the output of each task in a directory, the shared state cache. Its location is controlled by the SSTATE_DIR variable.
  • This cache is use to speed up compilation
  • Over time, as compile more recipes, it can grow quite big It is possible to clean old data with:
$ ./scripts/sstate-cache-management.sh –remove-duplicated -d \–cache-dir=<SSTATE_DIR>

Task
Description
listtasks
Lists all tasks
fetch
Fetches only those packages necessary for further fetching and patching in ‘downloads/’ folder
fetchall
Fetch everything may need for a later build of that selected recipe/image. Fetch all packages sources and their dependencies.
devshell
Open a new shell where with necessary system values already defined for recipe
compile
compile source
clearall
clear all downloaded source files, states
clearsstate
clear all states listtasks, fetchall, devshell, compile
clean
Deletes all .o and .obj files.
This command clean up ‘tmp’ dir for the given package.
It is very useful to work on a new .bb recipe. Without it changes to the recipe may not work
cleanall
​Removes all .o and cleans statecache
clean_sstatecache
Remove sstate cache of the component​


Bitbake commands


Command
Description
bitbake-layers show-layers
Show layers
bitbake-layers show-recipes “*-image-*”
Show possible recipes to bake
Without "*-image-*": show possible images to bake
-
-
bitbake -s
List all locally available recipes/packages/images, and versions
bitbake target [-f] [-c task] [-k]
Bake provided target and Build ipk.
target = a recipe or an image or a package.
target is specified without any extension or version number.
-
-
bitbake -g [-u depexp ]
Show dependency for image or package. Creates 4 file with dependency info, or even displays it in a UI.
bitbake -g -u taskexp [recipe]
Show dependency information in a graphical interface
bitbake -g && cat pn-depends.dot | grep -v -e ‘-native’ | grep -v digraph | grep -v -e ‘-image’ | awk ‘{print $1}’ | sort | uniq
Show all image’s packages
bitbake -g && cat pn-depends.dot | grep -v -e ‘-native’ | grep -v digraph | grep -v -e ‘-image’ | awk ‘{print $1}’ | sort | uniq
Show all package’s dependencies


Typical useful commands


Command
Description
bitbake <recipe>
Start a build
bitbake -c clean <recipe>
Clean up. Delete all .o &.obj files
bitbake -c compile -f <recipe>
Forcefully recompile code changes
bitbake -c cleanall <recipe>
Removes all .o & cleans statecache
bitbake -c clean_sstatecache
Remove sstate cache of the component
bitbake -s | grep <recipe>
Recipe version


References

  • https://elinux.org/Bitbake_Cheat_Sheet