Skip to content

Instantly share code, notes, and snippets.

@Scott31393
Last active April 25, 2024 21:02
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Scott31393/e7e3c952cee327fe0496ae09e3e839cd to your computer and use it in GitHub Desktop.
Save Scott31393/e7e3c952cee327fe0496ae09e3e839cd 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)}"

Reference: 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

Create .vfat and .ext4 images from folder after deploy (RAUC integration)

core-image-minimal.bbappend

do_image_complete() {
    # Create etc.ext4 part
    dd if=/dev/zero of="${WORKDIR}/etc.ext4" bs=1M count=${ETC_PART_SIZE_MB};
    mke2fs -d ${IMAGE_ROOTFS}/etc -t ext4 -L etc_image ${WORKDIR}/etc.ext4;
    cp -rf ${WORKDIR}/etc.ext4 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.etc.ext4;
    ln -sfn "${IMAGE_NAME}.etc.ext4" "${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.etc.ext4";

    # Create boot.vfat part
    cd ${DEPLOY_DIR_IMAGE}
    dd if=/dev/zero of=${IMAGE_BASENAME}-${MACHINE}.boot.vfat bs=1M count=${BOOT_PART_SIZE_MB};
    mkfs.vfat ${IMAGE_BASENAME}-${MACHINE}.boot.vfat
    mcopy -i ${IMAGE_BASENAME}-${MACHINE}.boot.vfat file.dtb ::file.dtb
    mcopy -i ${IMAGE_BASENAME}-${MACHINE}.boot.vfat Image ::Image
    ln -sfn "${IMAGE_NAME}.boot.vfat" "${IMAGE_BASENAME}-${MACHINE}.boot.vfat";
}

Reference: https://github.com/prusa3d/Prusa-Firmware-SL1/blob/master/sources/meta-prusa/recipes-core/bundles/sla-update-bundle.bb

Override PSplash with a custom ones

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

DEPENDS += "gdk-pixbuf-native"

PRINC = "8"

SRC_URI += "file://psplash-colors.h \
	    file://psplash-bar-img.png"

# NB: this is only for the main logo image; if you add multiple images here,
#     poky will build multiple psplash packages with 'outsuffix' in name for
#     each of these ...
SPLASH_IMAGES = "file://psplash-poky-img.png;outsuffix=default"

# The core psplash recipe is only designed to deal with modifications to the
# 'logo' image; we need to change the bar image too, since we are changing
# colors
do_configure_append () {
	cd ${S}
	cp ../psplash-colors.h ./
	# strip the -img suffix from the bar png -- we could just store the
	# file under that suffix-less name, but that would make it confusing
	# for anyone updating the assets
	cp ../psplash-bar-img.png ./psplash-bar.png
	./make-image-header.sh ./psplash-bar.png BAR
}

References:

@AndreRicardo-Zoetis
Copy link

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment