This document discusses using Buildroot and swupdate to update embedded Linux devices. It begins by introducing Buildroot as a tool for building a complete Linux system for embedded devices. It then provides an overview of swupdate, including its update strategies, interfaces, and features. Finally, it demonstrates how to set up Buildroot and swupdate to automatically build system images and generate over-the-air update files for deploying changes to devices.
2. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
$ whoami
Angelo Compagnucci
angelo@amarulasolutions.com
https://www.linkedin.com/in/compagnucciangelo/
Proud Buildroot contributor
Maintaining Mono package
Golang infrastructure
Passionate developer
Devops
Mostly proud of s3-pit-restore
And a reckless Enduro rider!
2
3. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Topics
1. How to use buildroot as a
base system for your
stack
2. An introduction to
swupdate and it’s fields
of use
3. An example of using
buildroot + swupdate to
update your stack.
3
4. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Part 1
How to use buildroot as a base
system for your stack
4
5. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Buildroot
Buildroot is a tool that simplifies and automates the process of
building a complete Linux system for an embedded system,
using cross-compilation.
In order to achieve this, Buildroot is able to generate a
cross-compilation toolchain, a root filesystem, a Linux kernel
image and a bootloader for your target.
Buildroot is written mainly in Kconfig and make.
You can find it at https://www.buildroot.org
5
6. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Buildroot usage
$ make help
Cleaning:
clean - delete all files
created by build
distclean - delete all
non-source files (including .config)
Build:
all - make world
toolchain - build toolchain
sdk - build relocatable
SDK
Configuration:
menuconfig - interactive
curses-based configurator
nconfig - interactive
ncurses-based configurator
xconfig - interactive Qt-based
configurator
gconfig - interactive
GTK-based configurator
[...]
6
7. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Buildroot daily routine
7
$ make qemu_arm_versatile_defconfig O=../br_qemu_arm
1. You are in your Buildroot source tree:
$ cd ../br_qemu_arm
$ make xconfig
2. Modify your configuration
$ make -l
3. Build your project:
$ make xconfig
$ make -l
$ make clean
4. Modify your configuration, rebuild, clean:
8. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
.config vs defconfig
8
#
# Automatically generated file; DO NOT EDIT.
# Buildroot 2018.11-rc1-00139-ge35fbc69f2
Configuration
#
BR2_HAVE_DOT_CONFIG=y
BR2_HOST_GCC_AT_LEAST_4_5=y
BR2_HOST_GCC_AT_LEAST_4_6=y
BR2_HOST_GCC_AT_LEAST_4_7=y
BR2_HOST_GCC_AT_LEAST_4_8=y
BR2_HOST_GCC_AT_LEAST_4_9=y
BR2_HOST_GCC_AT_LEAST_5=y
BR2_HOST_GCC_AT_LEAST_6=y
BR2_HOST_GCC_AT_LEAST_7=y
BR2_HOSTARCH_NEEDS_IA32_LIBS=y
#
# Target options
#
BR2_SOFT_FLOAT=y
BR2_ARCH_HAS_MMU_OPTIONAL=y
[...]
BR2_arm=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_SYSTEM_DHCP="eth0"
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_FAIL2BAN=y
BR2_TARGET_ROOTFS_EXT2=y
# BR2_TARGET_ROOTFS_TAR is not set
Always save your configuration!
$ make savedefconfig BR2_DEFCONFIG=yourdefconfigfile
9. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Adapt Buildroot to suit your needs
● Customization could be
○ BR2_*_CUSTOM_CONFIG_FILE
■ Ex: busybox.config
○ BR2_*_PRE/POST_*_SCRIPT
■ script used to customize
your image files
○ Custom users or devices
■ device_table.txt
○ Artifacts
■ Your own files
● Your own customizations should
be in a board directory!
9
$ ls board/example/board/
busybox.config
device_table.txt
linux.config
uboot.config
users_table.txt
[...]
10. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Adding packages
A package is defined by a folder in
package directory
Must contain:
● Config.in
● package makefile
● package hash
To be selectable in gui, an entry should
be present in package/Config.in
10
package/python-web2py/
|-- Config.in
|-- python-web2py.hash
|-- python-web2py.mk
|-- S51web2py
`-- web2py.service
source "package/python-web2py/Config.in"
11. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Commiting your customization
It’s not advisable to commit to the buildroot tree
11
Committing to the buildroot
tree is wrong:
● You are forking buildroot
● Bump to a new buildroot
version could be impossible
● Probably you end up with an
outdated buildroot version
● Licensing problems
12. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
BR2_EXTERNAL to the rescue
BR2_EXTERNAL
is a mechanism to store your own custom
packages, defconfigs and other artifacts
outside of the Buildroot source tree.
An external directory must contain:
● external.desc: which provides a name and a
description
● Config.in: configuration options that will be
included in menuconfig
● external.mk, will be included in the make
logic
12
13. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Your (more complicated) daily routine
13
$ make qemu_arm_versatile_defconfig O=../br_qemu_arm BR2_EXTERNAL=../br_external
2. You are in your Buildroot source tree:
$ cd ../br_qemu_arm
$ make xconfig
3. Modify your configuration
$ make -l
4. Build your project:
5. [...]
1. Configure your BR2_EXTERNAL
14. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Adding a Makefile to your project
14
$ make help
br-template help
Building
all - compiles everything
image - produces images files in out/images
update - produces an update swu file in out/update
Cleaning
clean - removes everything but keeps dl folder
distclean - reset the project to a clean state
Buildroot management
qemu_arm_versatile_custom [TARGET]
- calls TARGET on qemu_arm_versatile_custom buildroot makefile
qemu_arm_versatile_custom_recovery [TARGET]
- calls TARGET on qemu_arm_versatile_custom_recovery buildroot makefile
15. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Part 2
An introduction to swupdate and
it’s fields of use
15
17. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
SWUpdate to the rescue
17
SWUpdate is a Linux Update agent with the goal to provide an
efficient and safe way to update an embedded system.
SWUpdate supports local and remote updates, multiple update
strategies and it can be well integrated in the buildroot build
system.
18. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Tons of features
● Install on embedded media (eMMC, SD, Raw NAND, NOR
and SPI-NOR flashes)
● Allow delivery single image for multiple devices
● Multiple interfaces for getting software
○ local storage
○ integrated web server
○ integrated REST client connector to hawkBit
○ remote server download
● Software delivered as images, gzipped tarball, etc.
● Allow custom handlers for installing FPGA firmware,
microcontroller firmware via custom protocols.
● Power-Off safe
(from the official readme)
18
20. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Update strategies
20
Bootloader Kernel
1. Plain
2. Mixed A/B
3. Full A/B
Rootfs Data
Bootloader Kernel A Rootfs DataKernel B
Bootloader
A
Kernel A Rootfs A DataKernel B
Bootloader
B
Rootfs B
21. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Using a recovery
21
3. Mixed A/B + Recovery
Bootloader
A
Kernel Rootfs Data
Bootloader
B
Recovery
A
Recovery
B
Advantages of having a recovery:
● It’s always available
● You can switch into recovery mode if the system is bricked
● Easier to implement than a full A/B system
● It’s advisable to have a redundant bootloader
● It’s advisable to have a redundant recovery
● Recovery is loaded in memory and can self update
SPL
22. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Recovery
Built by buildroot through a custom
configuration
Should contain a minimal logic to
apply the update:
● Custom logic: you write your own
software (ex: detecting usb storage
and looking for a valid swu file)
● Web interface: you can run the
included webserver and waiting for
user interaction
● User interaction through screen:
use the recently introduced
SWUpdateGUI or write your own
22
BR2_PACKAGE_SWUPDATE=y
BR2_TARGET_ROOTFS_INITRAMFS=y
23. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
SPL
SPL (Secondary Program Loader)
● Minimal bootloader runnable from static RAM
● Con do al lot of initialization
○ Memory
○ Power
○ GPIO
● Can be used to implementd redundant bootloader
23
CONFIG_SPL=y
CONFIG_SPL_FRAMEWORK=y
CONFIG_SPL_GPIO_SUPPORT=y
CONFIG_SPL_LIBCOMMON_SUPPORT=y
CONFIG_SPL_LIBGENERIC_SUPPORT=y
24. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Redundancy
● U-boot redundancy
○ bootloader can be configured
for redundancy
○ You should have an SPL to really
implement bootloader
redundancy
● Recovery redundancy
○ Doubling the recovery
○ bootloader is responsible to
check if recovery is working else
switch to emergency copy
24
CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
CONFIG_SYS_NAND_U_BOOT_OFFS=
CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND=
bootcmd_recovery = run recovery || run bootcmd_emergency
25. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
How to enter recovery mode
● User or system interaction
○ bootloader is responsible to
switch to recovery mode
● bootcount mechanism
○ bootloader sets a boot count
limit, boot count should be
zeroed by the operating system
○ u-boot has
CONFIG_BOOTCOUNT_LIMIT
■ bootcount
■ bootlimit
■ altbootcmd
25
Example:
$ fw_setenv recovery 1; reboot
uboot> env set recovery 1; boot
#!/bin/sh
#
# This service resets the
# bootcount u-boot variable to 0
#each time a successful
# boot happens.
#
case "$1" in
start)
printf "Starting the
bootcount service: "
fw_setenv bootcount 0
[...]
26. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
sw-description
Is the main file for
describing the update:
● images section
Update images for
system partitions
● files section
Custom files to be added to
a filesystem
● scripts
Scripts to be executed while
installing the update
● bootenv
Updates to the bootloader
environment
26
software =
{
version = "0.1.0";
description = "Firmware update for XXXXX Project";
hardware-compatibility: [ "1.0", "1.2", "1.3"];
images: (
{ filename = "rootfs.ubifs";
volume = "rootfs"; }
);
files: (
{ filename = "README";
path = "/README";
device = "/dev/mmcblk0p1";
filesystem = "vfat"; }
);
scripts: (
{ filename = "erase_data";
type = "shell"; },
);
bootenv: (
{ filename = "bootloader-env";
type = "bootloader"; },
);
}
27. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
swu file
Is the actual update file
● sw-description as first file
● other files following
● CPIO format
● Optional signature
27
CPIO header
sw-description
image file 1
[...]
image file n
file 1
[...]
file n
28. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Part 3
An example of using buildroot +
swupdate to update your stack
28
29. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Summarising up
1. Create your buildroot external tree
2. Adding your software
3. Modify your configuration
4. Do the same for the recovery
5. build, clean, rebuild
6. Move the artifacts somewhere
7. Build the swu update file
8. Redo
29
32. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Let’s automate it
image: $(BR2T_CONFIG) $(BR2T_RECOVERY_CONFIG)
$(MAKE) -l -C out/$(BR2T_DEFCONFIG) source
$(MAKE) -l -C out/$(BR2T_RECOVERY_DEFCONFIG) source
$(MAKE) -l -C out/$(BR2T_DEFCONFIG)
$(MAKE) -l -C out/$(BR2T_RECOVERY_DEFCONFIG)
@for file in $(BR2T_IMAGE_FILES); do
cp -v "$${file%%:*}" ${BR2T_IMG_DIR}/"$${file##*:}";
done
32
5. Building the images ...
6. Building the swu update file ...
recovery:
@rm -rf $(BR2T_TMP_DIR)
@mkdir -p $(BR2T_TMP_DIR)
@cp -v $(BR2T_IMG_DIR)/* $(BR2T_TMP_DIR)/
@cp -v $(BR2T_EXTERNAL)/$(BR2T_SWDESCRIPTION) $(BR2T_TMP_DIR)
@cd $(BR2T_TMP_DIR) &&
echo sw-description
$$(find . -type f -name "*" ! -name "sw-description*")
| tr " " "n" |
cpio -ov -H crc > ../$(BR2T_NAME)_$(BR2T_ID).swu;
@rm -rf $(BR2T_TMP_DIR)
33. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
br-template
33
$ make help
br-template help
Building
all - compiles everything
image - produces images files in out/images
update - produces an update swu file in out/update
Cleaning
clean - removes everything but keeps dl folder
distclean - reset the project to a clean state
Buildroot management
qemu_arm_versatile_custom [TARGET]
- calls TARGET on qemu_arm_versatile_custom buildroot makefile
qemu_arm_versatile_custom_recovery [TARGET]
- calls TARGET on qemu_arm_versatile_custom_recovery buildroot makefile
Freely available at https://github.com/angeloc/br-template
34. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com
Resources
● https://buildroot.org
Main buildroot website
● http://bootlin.com/doc/training/buildroot/buildroot-slides.pdf
Buildroot training from Bootlin
● https://sbabic.github.io/swupdate/swupdate.html
Main swupdate documentation source
● http://events17.linuxfoundation.org/sites/events/files/slides/S
WUpdateELCE2017.pdf
Inspiring presentation from Stefano Babic
● https://www.eclipse.org/hawkbit/
IOT rollouts management GUI
34
35. Upgrading buildroot based devices with swupdate - www.amarulasolutions.com 35
Q/A
Thanks for your attention
Questions?