Skip to content

Building the bitbake core‐image‐weston‐wpe image from scratch for the Raspberry Pi

Pablo Saavedra Rodiño edited this page Apr 17, 2024 · 4 revisions

Building the bitbake core-image-weston-wpe image from scratch for the Raspberry Pi

QuickStart steps

CI_COMMIT_REF_NAME="main"
YOCTO_RELEASE="nanbield"
mkdir -p ~/devel/image-wpe-bsp/
cd ~/devel/image-wpe-bsp
repo init -u https://github.com/Igalia/meta-wpe-image.git -m manifest-"${YOCTO_RELEASE}".xml -b "${CI_COMMIT_REF_NAME}"
repo sync --force-sync
pushd sources/meta-wpe-image/
git fetch --all
git checkout main
popd
export MACHINE=raspberrypi3-64-mesa
export DISTRO=wpe
export BUILD_ENV=${MACHINE}-wpe

cd    ~/devel/image-wpe-bsp/
# source setup-environment targetname   machine    distro    bblayers    presets          --update-config
source setup-environment   ${BUILD_ENV} ${MACHINE} ${DISTRO} layers.raspberrypi     conf.wpe-2_44    --update-config
export IMAGE=core-image-weston-wpe
bitbake ${IMAGE}

Getting the sources:

repo is a tool from the chromium project depot_tools to handle projects repositories, check here how to download it.

CI_COMMIT_REF_NAME="main"
YOCTO_RELEASE="nanbield"

mkdir -p ~/devel/image-wpe-bsp/
cd ~/devel/image-wpe-bsp
repo init -u https://github.com/Igalia/meta-wpe-image.git -m manifest-"${YOCTO_RELEASE}".xml -b "${CI_COMMIT_REF_NAME}"
repo sync --force-sync
pushd sources/meta-wpe-image/
git fetch --all
git checkout main
popd

Activating the bitbake environment:

export MACHINE=raspberrypi3-64-mesa
export DISTRO=wpe
export BUILD_ENV=${MACHINE}-wpe

cd    ~/devel/image-wpe-bsp/

# source setup-environment targetname   machine    distro    bblayers    presets          --update-config
source setup-environment   ${BUILD_ENV} ${MACHINE} ${DISTRO} layers.raspberrypi     conf.wpe-2_44    --update-config
# or ... (to build WPE from Trunk)
# source setup-environment   ${BUILD_ENV} ${MACHINE} ${DISTRO} layers.raspberrypi     conf.wpe-nightly --update-config
# or to avoid rewriting configuration
# source setup-environment ${BUILD_ENV}

Note: that the --update-config option will remove any changes made to your local.conf file, it is unnecessary to specify it each time.

In the build conf dir (the setup-environment script moved you to this directory already), edit conf/presets/wpe-2_44.conf according with your preferences.

PREFERRED_PROVIDER_virtual/wpebackend = "wpebackend-fdo"
PREFERRED_PROVIDER_virtual/libwpe = "libwpe"
# PREFERRED_VERSION_cog = "0.18.%"
PREFERRED_VERSION_cog = "trunk+%"
PREFERRED_VERSION_libwpe = "1.14.%"
PREFERRED_VERSION_wpebackend-fdo = "1.14.%"
PREFERRED_VERSION_wpebackend-rdk = "1.20200213"
# PREFERRED_VERSION_wpewebkit = "2.44.%"
PREFERRED_VERSION_wpewebkit = "trunk+%"

Optionaly, you can set this local-host.conf in the BSP work dir (~/devel/image-wpe-bsp/)

TMPDIR = "/share/yocto/tmp/image-wpe-bsp-rpi4-nanbield"
SSTATE_DIR = "/share/yocto/sstate-cache/${@d.getVar('LAYERSERIES_CORENAMES').replace(' ', '_')}"
DL_DIR = "/share/yocto/downloads/${@d.getVar('LAYERSERIES_CORENAMES').replace(' ', '_')}"

# Generate tarball with the debug files
IMAGE_GEN_DEBUGFS = "1"
IMAGE_FSTYPES_DEBUGFS = "tar.bz2"

# Add additional free space to the image
IMAGE_ROOTFS_EXTRA_SPACE:append = " + 22000000"

LICENSE_FLAGS_ACCEPTED = "commercial synaptics-killswitch"

These settings will be shared among the different machine builds defined in your BSP.

Verifying the recipes to build

bitbake-layers show-recipes cog libwpe weston wpebackend-fdo wpewebkit
...
=== Matching recipes: ===
cog:
  meta-webkit          0.18.2
  meta-webkit          0.16.1
libwpe:
  meta-webkit          1.14.1
  meta                 1.14.1
weston:
  meta                 12.0.2
wpebackend-fdo:
  meta-webkit          1.14.2
  meta-webkit          trunk+git
  meta-webkit          devupstream
  meta                 1.14.2
wpewebkit:
  meta-webkit          2.44.1
  meta-webkit          2.42.5
  meta-webkit          1.downstream-20180424

(the listed first is the one to be built and installed)

Bitbaking the image:

export IMAGE=core-image-weston-wpe

bitbake ${IMAGE}
# If you want to build the SDK ...
bitbake ${IMAGE} -c populate_sdk

the resulting image will be located at ${TMPDIR}/deploy/images/${MACHINE}/${IMAGE}-${MACHINE}.wic.bz2 and others.

Flashing the SDCard

# Pay attention to the device the write, it depends on your system, and
# THE DATA ON THE DEVICE WILL BE OVERWRITTEN AND LOST, of course.
# Typically the name/path is `/dev/mmcblk0` on Linux with only one
# SD-card attached, but it can have other names e.g. if using USB adaptors.
# `lsblk` can help to find it.
export OUTPUT="/dev/REMOVE_THIS/mmcblk0"

export MACHINE="raspberrypi3-mesa"
export BUILD_ENV=${MACHINE}-wpe
export DEPLOY_DIR="~/image-wpe-bsp/builds/${BUILD_ENV}/tmp/deploy/images/${MACHINE}/"
export SDIMG="${IMAGE}-${MACHINE}.wic"
export BMAP="${SDIMG}.bmap"
export BZ2="${SDIMG}.bz2"

sudo umount ${OUTPUT}?   # ex: /dev/sdb1
sudo umount ${OUTPUT}p?  # ex: /dev/mmcblk0p1

# if you have this tool  
sudo bmaptool copy --bmap "${DEPLOY_DIR}/${BMAP}" "${DEPLOY_DIR}/${SDIMG}" "${OUTPUT}"

# or with the classical `dd`
bz2 -d ${DEPLOY_DIR}/${BZ2}
sudo dd if="${DEPLOY_DIR}/${SDIMG}" of="${OUTPUT}" bs=4k conv=fsync status=progress

Connecting to the image using SSH:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no  root@dynamic-ip

or if you have mDNS setup:

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no  root@${MACHINE}.local

Running the browsers:

cog-fdo-exported-wayland https://wpewebkit.org

Setting up debugging

Debugging tools and symbols can be automatically added to a built image by editing local.conf, located at ~/devel/image-wpe-bsp/builds/${BUILD_ENV}/conf/ and adding this line:

EXTRA_IMAGE_FEATURES ?= 'dbg-pkgs tools-debug'

Debugging on the device can be slow, and debugging large libraries (such as WebKit) can easily run out of memory. Enabling a swap partition can help with this. The Disks tool included in GNOME is the easiest way to do this. Expand the root partition on the SD card, leaving however much space you want for a swap partition (for example, 8GiB). Then create a new Linux swap partition. This can be enabled by running swapon /dev/mmcblk0p3 as root on the device.

Using devtool

If you want to make frequent changes to a particular package, it is easiest to use devtool. Typing devtool modify <recipe> will setup a workspace that will override the default package directory and allow you to make changes. The recipe can be built with devtool build <recipe> and deployed on device with devtool deploy-target <recipe> root@${MACHINE}.local -c -s. To remove the override, you can run devtool reset <recipe>. For example:

devtool modify wpewebkit
# Make your changes in the wpewebkit workspace source dir
devtool build wpewebkit
devtool deploy-target  -s -c  -P 22  wpewebkit [email protected]

Rebuilding and deploying a single recipe

When modifications have been made to a single recipe, it can be useful to build and deploy that single recipe, rather than rebuilding the image. This can be done like so,

bitbake <recipe> -c clean
bitbake <recipe>

Note that when making modifications, this will cause unnecessary work. Instead, you can execute,

bitbake <recipe> -C compile # Note capital C

Any packages that are built will be in a subdirectory of ~/image-wpe-bsp/builds/${BUILD_ENV}/tmp/deploy/rpm. These packages can be copied to the device and installed manually using rpm.

Serving a local package repository

It can be cumbersome to manually transfer and install packages, especially if there are dependencies involved. Much easier is to serve a local repository. Add these lines to your local.conf file:

PACKAGE_FEED_URIS = "http://cwiiis-desktop.local:8000"
PRSERV_HOST = "localhost:0"

After rebuilding any recipe, execute bitbake package-index to rebuild the list of packages. To serve the packages, run

python3 -m http.server --directory /home/cwiiis/Projects/image-wpe-bsp/builds/${BUILD_ENV}/tmp/deploy/rpm

and then dnf can be used normally from the device.