Raspberry Pi 4 Model B - Yocto 5.0 "scarthgap" and later

Board description

The Raspberry Pi 4 Model B is the probably most popular board of the Raspberry Pi family.

URL: https://www.raspberrypi.org/products/raspberry-pi-4-model-b/
Wiki: https://elinux.org/RPi_Hub

Test results

Raspberry Pi 4 is one of the official reference devices of Mender and is easy to get started with. This device is continuously tested as part of Mender testing pipelines which assures high quality of the integration.

Version notes

This tutorial uses scarthgap as the primary target, which is the current LTS release by the Yocto Project. You can find more infomation on releases here.

NOTE: before the Yocto 5.0 release “scarthgap”, meta-mender and meta-mender-community used Google Repo configuration files. Please see the Raspberry Pi 4 Model B - Yocto 4.0 "kirkstone" and earlier article for building these releases.

Supported releases for following the tutorial are:

Yocto Project Tutorial applies Maintenance
scarthgap (5.0) :test_works: :test_works: LTS1
nanbield (4.3) and older :test_fails: :test_fails: does not apply

1. Disabled GRUB integration for ARM systems which is default in meta-mender/meta-mender-raspberrypi. U-Boot is still primary integration method for this platform.

Please note: a failure in the “tutorial applies” column indicates that the instructions do not work without modification. Depending on the combination of release and host Linux distribution, installing other python versions or dependencies might provide a functional state.

Build Means that the Yocto Project build using this Mender integration completes without errors and outputs images.
Runtime Means that Mender has been verified to work on the board. For U-Boot-based boards, the integration checklist has been verified.

Getting started

Prerequisites

  • A supported Linux distribution and dependencies installed on your workstation/laptop as described in the Yocto Development Manual
  • NOTE. Instructions depend on which Yocto version you intend to use.
  • kas installed and in your PATH.

Configuring the build

Setup Yocto environment

Create a directory for your mender-raspberrypi5 setup to live in and clone the

meta information.

mkdir mender-raspberrypi4 && cd mender-raspberrypi4

Clone the meta-mender-community layer:

git clone https://github.com/theyoctojester/meta-mender-community \
  -b scarthgap

Setup build environment

Change into the cloned repository and create a directory to hold the build:

cd meta-mender-community
mkdir my-raspberrypi4
cd my-raspberrypi4

Use kas to set up the build structure:

kas shell ../kas/raspberrypi4.yml

This opens a sub-shell which is initialized for the build process. You can close it using the exit command.

Configure Mender server URL (optional)

This section is not required for a successful build but images that are generated by default are only suitable for usage with the Mender client in Standalone deployments, due to lack of server configuration.

You can edit the conf/local.conf file to provide your Mender server configuration, ensuring the generated images and Mender Artifacts are connecting to the Mender server that you are using. There should already be a commented section in the generated conf/local.conf file and you can simply uncomment the relevant configuration options and assign appropriate values to them.

Build for Hosted Mender:

# To get your tenant token:
#    - log in to https://hosted.mender.io
#    - click your email at the top right and then "My organization"
#    - press the "COPY TO CLIPBOARD"
#    - assign content of clipboard to MENDER_TENANT_TOKEN
#
MENDER_SERVER_URL = "https://hosted.mender.io"
MENDER_TENANT_TOKEN = "<copy token here>"

Building the image

You can now proceed with building an image:

bitbake core-image-minimal

Replace core-image-minimal with your desired image target. core-image-minimal is chosen as an example for short build time and minimal dependencies.

Using the build output

After a successful build, the images and build artifacts are:

  • tmp/deploy/images/raspberrypi4/core-image-base-raspberrypi4.sdimg
  • tmp/deploy/images/raspberrypi4/core-image-base-raspberrypi4.mender

The disk image (with .sdimg suffix) is used to provision the device storage for devices without Mender running already. Please proceed to the official documentation on provisioning a new device for steps to do this.

On the other hand, if you already have Mender running on your device and want to deploy a rootfs update using this build, you should use the Mender Artifact files, which have .mender suffix. You can either deploy this Artifact in managed mode with the Mender server (upload it under Releases in the server UI) or by using the Mender client standalone mode.

References

  • The Mender integration layer for Raspberry Pi boards can be found in meta-mender-community.

  • The official Mender documentation explains how Mender works. This is simply a board-specific complement to the official documentation.

Known issues

Boot firmware files

See Updating Raspberry Pi boot firmware files using Yocto Project and Mender.

See this thread where the limitations of the boot firmware files on Raspberry Pi are discussed.

Devicetree is not updated

To be able to support update of Linux kernel and devicetree, Mender requires these to be installed in the /boot directory for each rootfs (normally /dev/mmcblk0p2 and /dev/mmcblk0p3). On the other hand, the Raspberry Pi boot firmware requires that the DTB file is in the same partition as the boot firmware (/dev/mmcblk0p1) and the config.txt file. For now Mender will not use the DTB that is delivered with new artifacts and will continue to boot with the original DTB that was populated using the sdimg file.

Problem using ‘dtoverlay=pi3-disable-bt’

pi3-disable-bt disables the Bluetooth device and restores UART0/ttyAMA0 to GPIOs 14 and 15. It is also necessary to disable the system service that initialises the modem so it doesn’t use the UART

There is currently a known issue with above functionality, that is to enable UART0 on PIN 14 and 15.

It is actually not something that is caused by Mender specifically, but Mender requires U-Boot to be present to support robust features such as roll-back. U-Boot is typically not enabled if you do a stock Raspberry Pi and some people are often surprised that the Bluetooth UART stopped working when they integrate meta-mender.

The problem is in U-Boot which does conflicting configuration, and there is a workaround reported here and it has been reported to U-Boot but unclear when/if it will be fixed.


If this post was useful to you, please press like, or leave a thank you note to the contributor who put valuable time into this and made it available to you. It will be much appreciated!

2 Likes

Thank you very much for taking the time to update the tutorial!

5 posts were split to a new topic: Trouble getting RPi4 to work

I recently started working with yocto because I want to set up a Mender Device Management with my Raspberry Pi 4.
I came across this tutorial, which I found to be very helpful.

With the help of the tutorial, I was able to successfully install a first image on my Raspberry Pi 4 and successfully connect to Mender.
Now I want to install a first update and have proceeded as follows:

Adjusted local.conf in mender-raspberrypi4/meta-mender-community/my-raspberrypi4/build/conf/ to my needs:

# change mender artifact name to be able to update the OS
MENDER_ARTIFACT_NAME = "gha_autobuild v1.1"

# add the mender connect feature to the built
IMAGE_INSTALL:append = " mender-connect"
MENDER_CONNECT_USER = "root"
MENDER_CONNECT_SHELL = "/bin/bash"

A few questions have arisen:

  1. Each time I use the command
    kas shell ../kas/raspberrypi4.yml
    it overwrites my customized local.conf under
    mender-raspberrypi4/meta-mender-community/my-raspberrypi4/build/conf/local.conf
    What do I have to change if I want to work on an existing project without it overwriting everything again?

  2. Why do I have to specify MACHINE=raspberrypi4 at the beginning of the bitbake core-image-base command?

  3. The first build process writes the core-image-base-raspberrypi4.mender file. However, if I have adjusted the local.conf and run MACHINE=raspberrypi4 bitbake core-image-base again, it only recreates the sdimg file, but not the mender file, which is important to upload it as an artifact to Mender. Commands like bitbake -c cleanall core-image-base don’t solve the issue.

HI @wlbdv,

Thanks a lot for reaching out, and nice to hear you found this helpful. For your questions:

  1. The core concept of kas is that the whole build is defined by the data given, and hence it re-creates local.conf based on the passed .yml files every time. The way to augment the information in meta-mender-community with your local settings is to use an override file as described at Using kas to reproduce your Yocto builds. You would put your additions into a file like wlbdev-mender.yml, and then invoke kas like kas shell ../kas/raspberrypi4.yml:wlbdev-mender.yml. This way, whatever assignments you have in wlbdev-mender.yml will overwrite the given defaults.
  2. good catch, that’s a leftover from the original repo-based tutorial. Fixed now.
  3. the core-image-base-raspberrypi4.mender file is in fact a symlink to the last built artifact. I have just given it a test build, and after the second build the link is pointing to the newly created .mender file. Can you check if this is the case for you?

Greetz,
Josef

Hi @TheYoctoJester

I have been evaluating mender OTA deployment, and trying to build an yocto image for raspberry pi 4, as then viewed this tutorial to build an image, Followed the steps, building it on Ubuntu 24.04 host, once my build got completed after several hours, the mender image and sdimg had huge size difference, please guide me as is something i missed out or doing anything wrong.

kas build …/kas/raspberrypi4-64.yml
2025-02-18 12:21:34 - INFO - kas 4.7 started
2025-02-18 12:21:34 - INFO - Using /home/user01/rpi_yocto_image/meta-mender-community as root for repository meta-mender-community
2025-02-18 12:21:34 - INFO - Repository poky already contains 7117d115eab7351ecf21388ec720a3bb5f4a9b30 as commit
2025-02-18 12:21:34 - INFO - Repository meta-openembedded already contains 3c293e14492f01e22a64004e2330fb620c27578a as commit
2025-02-18 12:21:34 - INFO - Repository meta-mender already contains 4c242af57ff0a00a4d44328896a5cd81c27c8c46 as commit
2025-02-18 12:21:34 - INFO - Repository meta-raspberrypi already contains 6df7e028a2b7b2d8cab0745dc0ed2eebc3742a17 as commit
2025-02-18 12:21:35 - INFO - Repository meta-lts-mixins already contains 66ceeebd047d7fdfc8668b300319a76da8ae257d as commit
2025-02-18 12:21:35 - INFO - Repository poky checked out to 7117d115eab7351ecf21388ec720a3bb5f4a9b30
2025-02-18 12:21:35 - INFO - Repository meta-openembedded checked out to 3c293e14492f01e22a64004e2330fb620c27578a
2025-02-18 12:21:35 - WARNING - Repo meta-mender is dirty - no checkout
2025-02-18 12:21:35 - INFO - Repository meta-raspberrypi checked out to 6df7e028a2b7b2d8cab0745dc0ed2eebc3742a17
2025-02-18 12:21:35 - INFO - Repository meta-lts-mixins checked out to 66ceeebd047d7fdfc8668b300319a76da8ae257d
2025-02-18 12:21:35 - INFO - /home/user01/rpi_yocto_image/meta-mender-community/rpi-build-image/build$ /home/user01/rpi_yocto_image/meta-mender-community/rpi-build-image/poky/bitbake/bin/bitbake -c build core-image-minimal
WARNING: Host distribution “ubuntu-24.04” has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
Loading cache: 100% |##########################################################################################################################################################| Time: 0:00:03
Loaded 3344 entries from dependency cache.
Parsing recipes: 100% |########################################################################################################################################################| Time: 0:00:31
Parsing of 1968 .bb files complete (1941 cached, 27 parsed). 3344 targets, 126 skipped, 0 masked, 0 errors.
NOTE: Resolving any missing task queue dependencies

Build Configuration:
BB_VERSION = “2.8.0”
BUILD_SYS = “x86_64-linux”
NATIVELSBSTRING = “universal”
TARGET_SYS = “aarch64-poky-linux”
MACHINE = “raspberrypi4-64”
DISTRO = “poky”
DISTRO_VERSION = “5.0.6”
TUNE_FEATURES = “aarch64 crc cortexa72”
TARGET_FPU = “”
meta-lts-mixins = “HEAD:66ceeebd047d7fdfc8668b300319a76da8ae257d”
meta-mender-core = “HEAD:4c242af57ff0a00a4d44328896a5cd81c27c8c46”
meta-mender-raspberrypi = “scarthgap:3ee37a7e9fe81d812acf485f74bed5c878014c12”
meta-oe = “HEAD:3c293e14492f01e22a64004e2330fb620c27578a”
meta-raspberrypi = “HEAD:6df7e028a2b7b2d8cab0745dc0ed2eebc3742a17”
meta
meta-poky
meta-yocto-bsp = “HEAD:7117d115eab7351ecf21388ec720a3bb5f4a9b30”

Sstate summary: Wanted 1 Local 0 Mirrors 0 Missed 1 Current 2301 (0% match, 99% complete)###################################################################### | ETA: 0:00:00
Removing 1 stale sstate objects for arch raspberrypi4_64: 100% |###############################################################################################################| Time: 0:00:00
NOTE: Executing Tasks
NOTE: Tasks Summary: Attempted 4840 tasks of which 4834 didn’t need to be rerun and all succeeded.

Summary: There was 1 WARNING message.

This is the list of image been generated:
104857600 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.bootimg
394264576 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.ext3
394264576 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.ext4
4025 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.manifest
472402 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.spdx.tar.zst
50270208 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.tar
387298 Feb 14 19:34 core-image-minimal-raspberrypi4-64-20250214133511.testdata.json
5120 Feb 15 10:54 core-image-minimal-raspberrypi4-64-20250215052340.bootstrap-artifact
134217728 Feb 15 10:54 core-image-minimal-raspberrypi4-64-20250215052340.dataimg
36365312 Feb 15 10:54 core-image-minimal-raspberrypi4-64-20250215052340.mender
1056964608 Feb 15 10:54 core-image-minimal-raspberrypi4-64-20250215052340.sdimg

Hi @parag,

That sounds about correct.

The .sdimg file is the full device image for provisioning, so the one you will flash to the SD card. It is about 1GB in size by default, and includes boot and data partitions, as well as the two root filesystem partitions A and B.
The .mender file is an Artifact for deploying through the Mender Client, either using the management server or locally. It contains “only” one root filesystem, which will be written to the currently inactive root partition and then used after reboot. Its size being around 300MByte sounds about right too.

So to me the build seems to be good, are you experiencing any problems when running the resulting images on your device?

Greetz,
Josef

Thanks for your response @TheYoctoJester, currently flashed image is “2024-10-22-raspios-lite-raspberrypi4_bookworm_64bit-mender-convert-4.3.0.img” on raspberry pi 4 then deployed above generated image using deployment manager deployment fails and errors :

2025-02-20 06:55:50.162 +0000 UTC info: Running Mender client 5.0.0
2025-02-20 06:55:50.162 +0000 UTC info: Deployment with ID 4046823d-eb22-47f4-b302-f262f1afbd1b started.
2025-02-20 06:55:50.163 +0000 UTC info: Sending status update to server
2025-02-20 06:55:50.685 +0000 UTC info: Installing artifact…
2025-02-20 06:56:03.698 +0000 UTC info: Update Module output (stdout): ================ STATISTICS ================
2025-02-20 06:56:03.699 +0000 UTC info: Update Module output (stdout): Blocks written: 0
2025-02-20 06:56:03.699 +0000 UTC info: Update Module output (stdout): Blocks omitted: 376
2025-02-20 06:56:03.699 +0000 UTC info: Update Module output (stdout): Bytes written: 0
2025-02-20 06:56:03.699 +0000 UTC info: Update Module output (stdout): ============================================
2025-02-20 06:56:03.75 +0000 UTC info: Sending status update to server
2025-02-20 06:56:04.4 +0000 UTC info: Sending status update to server
2025-02-20 06:56:04.664 +0000 UTC info: Calling reboot command and waiting for system to restart.
2025-02-20 06:56:04.784 +0000 UTC info: Termination signal received, shutting down gracefully
2025-02-20 06:56:18.178 +0000 UTC info: Running Mender client 5.0.0
2025-02-20 06:56:18.189 +0000 UTC info: The update client daemon is now ready to handle incoming deployments
2025-02-20 06:56:18.554 +0000 UTC error: Process returned non-zero exit status: ArtifactVerifyReboot: Process exited with status 1
2025-02-20 06:56:19.246 +0000 UTC info: Calling reboot command and waiting for system to restart.
2025-02-20 06:56:19.384 +0000 UTC info: Termination signal received, shutting down gracefully
2025-02-20 06:56:33.099 +0000 UTC info: Running Mender client 5.0.0
2025-02-20 06:56:33.107 +0000 UTC info: The update client daemon is now ready to handle incoming deployments
2025-02-20 06:56:33.594 +0000 UTC info: Sending status update to server

then flashed above generated sdimg and turned device ON it boots logs upto Starting kernel and then device screen gets blackout not able to figure out issue.

Hi @parag,

I guess you are mixing up one too many things here. So I’ll leave out the deploying a Yocto build to a device currently running Raspberry Pi OS for now, there might be issues hidden.

For the .sdimg just getting “blackout”, my guess is that it actually boots nicely and opens a terminal on the UART. The core-image-minimal build is, as its name says, really minimal and will not start a graphical UI. I’d suggest to attach a UART adapter and checking the output there. Alternatively, build core-image-base or some other bigger image, like core-image-weston.

Greetz,
Josef

Thanks for suggestion @TheYoctoJester

  1. Gave try with uart adapter boot was successfull, but problem now with login credential incorrect used default raspberrypi4-64 login:pi and passwd: raspberry ,also as “root” without password still unsuccessfull, as suggested in this post here .

  2. As suggest generated the core-image-base still the device screen get blackout.