Skip to content

Instantly share code, notes, and snippets.

@laoshaw
Forked from Scott31393/Bitbake-Cheatsheet.md
Created July 31, 2023 15:14
Show Gist options
  • Save laoshaw/c0f536b70a0aece53d518b512f274af0 to your computer and use it in GitHub Desktop.
Save laoshaw/c0f536b70a0aece53d518b512f274af0 to your computer and use it in GitHub Desktop.

Bitbake Cheatsheet

Verbose as possible

bitbake -vDDD your-recipe

List recipes

bitbake -s

List recipes task

bitbake -c listtasks recipe

Run only one task of a recipe

bitbake -c your-task your-recipe

Run all tasks for all recipes

bitbake world

Bitbake-layers command (help)

bitbake-layers -h

Bitbake-layers command

Add New Layer

bitbake-layers add-layer

Remove Layer

bitbake-layers remove-layer

Show Layers

bitbake-layers show-layers

Show Recipes

bitbake-layers show-recipes

Dump Task order of a recipe

cat build_directory/tmp/work/machine_toolchain/package_name/package_version/temp/log.task_order

Example Adding task in a Recipe

First list all tasks of a recipe using:

bitbake -c listtasks recipe

Then add your task where you prefer by adding another task in your recipe:

OUT = "${TOPDIR}/tmp/deploy/images/board-name"


do_copy_example() {
    cp ${WORKDIR}/example.txt ${OUT}/example.txt
}

do_copy_example[doc] = "Task added in Recipe"
addtask do_copy_example after task1 before task2

Then run your task using:

bitbake -c do_copy_example recipe-name

Example adding file into rootfs

DESCRIPTION = "Install file into rootfs"

LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"

FILESEXTRAPATHS_prepend := "${THISDIR}/files:" 

#take file from files directory
SRC_URI += "\
file://file1 \
file://file2 \
"

#specify where to get the files
S = "${WORKDIR}"


do_install_append() {
    #create custom dir into rootfs
    install -d ${D}/path/to/dir/on/fs
    #copy files inside
    install -m 0644 ${WORKDIR}/file1 ${D}/path/to/dir/on/fs
    install -m 0644 ${WORKDIR}/file2 ${D}/path/to/dir/on/fs
}

FILES_${PN} += "/path/to/dir/on/fs"

Example Copy file into ${DEPLOY_IMAGE_DIR} (Yocto image output)

DESCRIPTION = "Install SECO boot tool and uuu-tool"

LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"

UUU_TOOL_BINARY_SRC ?= "git://git.example.com/project.git;"
PROTOCOL ?= "protocol=ssh;"
REPO_USER ?= ""
SRCBRANCH = "master"
SRCREV ="0b47efdb976eeae09e23b077928bdbcc483be80f"


SRC_URI = "${UUU_TOOL_BINARY_SRC}branch=${SRCBRANCH};${PROTOCOL}${REPO_USER}"

S = "${WORKDIR}"

do_install() {
    #create directory
    install -d ${DEPLOY_DIR_IMAGE}/folder1
    #copy file
    cp -r ${WORKDIR}/git/* ${DEPLOY_DIR_IMAGE}/folder1
    #create link
    if [ ! -L ${DEPLOY_DIR_IMAGE}/link ]; then
    ln -s ${DEPLOY_DIR_IMAGE}/folder1/file1 ${DEPLOY_DIR_IMAGE}/file1
    fi   
}

Increase Filesystem size of a .wic/.sdcard

For example setting the RootFS to 2GB would require the following addition to the local.conf file:

IMAGE_ROOTFS_SIZE = “2097152”
IMAGE_OVERHEAD_FACTOR = “1.0”

Kill bitbake process

$ ps -ef|grep bitbake
$ kill -9 [PPID]
$ ps -ef| grep bitbake |awk '{print $2}' | xargs kill -9

.wks theory (.wic)

# short-description: Create SD card image with a boot partition
# long-description:
# Create an image that can be written onto a SD card using dd for use
# with i.MX SoC family.
# It uses SPL and u-boot
#
# The disk layout used is:
#  - ----- --------- --------- --------------
# | | SPL | u-boot  |  /boot  |    rootfs    |
#  - ----- --------- --------- --------------
# ^ ^     ^         ^         ^              ^
# | |     |         |         |              |
# 0 1kiB  69kiB     4MiB   4MiB + 8MiB    4MiB + 8Mib + rootfs + IMAGE_EXTRA_SPACE (default 10MiB)
#
part SPL --source rawcopy --sourceparams="file=SPL" --ondisk mmcblk --no-table --align 1
part u-boot --source rawcopy --sourceparams="file=u-boot.imx" --ondisk mmcblk --no-table --align 69
part /boot --source bootimg-partition --ondisk mmcblk --fstype=vfat --label boot --active --align 4096 --size 8M --extra-space 0
part / --source rootfs --ondisk mmcblk --fstype=ext4 --label root --align 4096

References: https://docs.yoctoproject.org/ref-manual/kickstart.html
References: https://github.com/Freescale/meta-fsl-arm/blob/master/scripts/lib/image/canned-wks/imx-uboot-spl.wks

IF statment example in Yocto recipe (.bb )

IMAGE_INSTALL += ${@'linux-firmware imx-gpu-viv kernel-module-imx-gpu-viv' if \
 	(d.getVar('MACHINEOVERRIDES') == 'True') else ''}
inherit ${@'flatpak-image-variants' if \
	(d.getVar('HAVE_META_FLATPAK') == 'True' and \
	 'flatpak' in d.getVar('DISTRO_FEATURES')) else ''}
inherit ${@'flatpak-repository' if \
	(d.getVar('HAVE_META_FLATPAK') == 'True' and \
	 'flatpak' in d.getVar('DISTRO_FEATURES')) else ''}

IF and Search in a string

IMAGE_INSTALL += "${@ 'linux-firmware imx-gpu-viv kernel-module-imx-gpu-viv' if \
                         (d.getVar('MACHINE_SOCARCH_SUFFIX') == '-imx6sx') else ''}"

IMAGE_INSTALL += "${@bb.utils.contains("MACHINE_SOCARCH_SUFFIX", "imx6", "linux-firmware imx-gpu-viv kernel-module-imx-gpu-viv", "", d)}"

Referencies: https://github.com/openembedded/bitbake/blob/master/lib/bb/utils.py#L974

Create vFat image from folder after deploy

core-image-minimal.bbappend

do_image_complete() {
    cd ${DEPLOY_DIR_IMAGE}
    dd if=/dev/zero of=boot.img bs=1M count=50
    mkfs.vfat boot.img
    mcopy -i boot.img file.dtb ::file.dtb
    mcopy -i boot.img Image ::Image
    mcopy -i boot.img boot.scr ::boot.scr
}

References: https://stackoverflow.com/questions/22385189/add-files-to-vfat-image-without-mounting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment