Why SWUpdate?
Field updates are inevitable. SWUpdate provides a robust, modular solution for updating firmware, root filesystems, and application layers — all with built-in rollback capability.
It’s open source, well documented, and integrates seamlessly with an A/B partition layout.
Architecture overview
SWUpdate consists of several key components:
- Update daemon (swupdate) — runs on the device and applies updates
- Update handlers — define what to update (rootfs, files, scripts, etc.)
- Client interfaces — web interface, REST API, or local CLI
- sw-description file — defines the structure and logic of the update package
Example update flow
- Build an update package (.swu) that contains:
• A new root filesystem image
• The sw-description file
• Optional scripts (for customization or verification) - swupdate writes the update to the defined devices.
- A post-update script confirms success or triggers a rollback if necessary.
Example
In this example, we split an official Raspberry Pi OS Trixie image into two files:
- 2025-10-01-raspios-trixie-arm64.boot.vfat
- 2025-10-01-raspios-trixie-arm64.root.ext4
These files are referenced in the sw-description file to create the .swu package:
software =
{
version = "0.1.0";
description = "Firmware update for XXXXX Project";
hardware-compatibility: [ "1.0", "1.2", "1.3"];
images: (
{
filename = "2025-10-01-raspios-trixie-arm64.boot.vfat";
device = "/dev/mmcblk0p1";
compressed = "zlib";
installed-directly = true;
},
{
filename = "2025-10-01-raspios-trixie-arm64.root.ext4";
device = "/dev/mmcblk0p2";
compressed = "zlib";
installed-directly = true;
}
);
scripts: (
{
type: "lua",
filename: "repair-disk-uuid.lua"
}
),
}The following Lua script adjusts partition UUIDs in cmdline.txt and fstab after flashing:
#!/usr/bin/lua
-- helper: run shell command and capture output
function run(cmd)
local f = io.popen(cmd)
local out = f:read("*a")
f:close()
return (out:gsub("%s+$", ""))
end
-- detect PARTUUIDs
local root_part = "/dev/mmcblk0p2"
local boot_part = "/dev/mmcblk0p1"
local root_uuid = run("blkid -s PARTUUID -o value " .. root_part)
local boot_uuid = run("blkid -s PARTUUID -o value " .. boot_part)
print("Rootfs PARTUUID: " .. root_uuid)
print("Boot PARTUUID: " .. boot_uuid)
-- mount points
os.execute("mkdir -p /mnt/root /mnt/boot")
os.execute("mount " .. root_part .. " /mnt/root")
os.execute("mount " .. boot_part .. " /mnt/boot")
-- update cmdline.txt
local cmdline_path = "/mnt/boot/cmdline.txt"
local file = io.open(cmdline_path, "r")
local text = file:read("*a")
file:close()
text = text:gsub("root=PARTUUID=[^ ]+", "root=PARTUUID=" .. root_uuid)
file = io.open(cmdline_path, "w")
file:write(text)
file:close()
-- update /etc/fstab
local fstab_path = "/mnt/root/etc/fstab"
local fstab = io.open(fstab_path, "r")
local content = fstab:read("*a")
fstab:close()
-- replace root line
content = content:gsub("PARTUUID=[^%s]+%s+/%s", "PARTUUID=" .. root_uuid .. " /")
-- replace boot line (/boot or /boot/firmware)
content = content:gsub("PARTUUID=[^%s]+%s+/boot", "PARTUUID=" .. boot_uuid .. " /boot")
fstab = io.open(fstab_path, "w")
fstab:write(content)
fstab:close()
os.execute("sync")
os.execute("umount /mnt/boot")
os.execute("umount /mnt/root")
print("All PARTUUIDs updated successfully.")Use swugenerator to bundle the update:(https://github.com/sbabic/swugenerator).
Apply the update
To test the generated .swu file:
- Boot the CM5 into the rescue system.
- Create a mount point, for example:
sudo mkdir -p /mnt/update- Mount an NFS share containing the update file:
sudo mount -t nfs :/path/to/share /mnt/update- Apply the update:
sudo swupdate -i /mnt/update/update.swuIntegration possibilities
Trigger updates from a local UI or backend API
- Sign and verify updates for enhanced security
- Use SWUpdate’s web interface for testing or debugging
- Combine with systemd services to automate recovery and rollbacks
Why it fits this stack
Together with rpi-image-gen and rpi-sb-provisioner, SWUpdate completes the picture:
- Build → rpi-image-gen (Image creation)
- Deploy → rpi-sb-provisioner (Device provisioning)
- Maintain → SWUpdate (OTA updates and lifecycle management)
The result is a flexible, open, and maintainable embedded Linux platform — one that evolves with your product, without the overhead of Yocto.
Articles in this series
- Building a Production-Ready Linux for Raspberry Pi Compute Module 5
- From Stock OS to Production Platform
- Customizing Raspberry Pi OS with rpi-image-gen
- System Robustness — Designing an A/B Root Filesystem Layout
- Provisioning — Automating First Boot with rpi-sb-provisioner
- OTA and Lifecycle — Software Updates with SWUpdate
Sources
- rpi-image-gen: https://github.com/raspberrypi/rpi-image-gen
- rpi-sb-provisioner: https://github.com/raspberrypi/rpi-sb-provisioner
- SWUpdate: https://github.com/sbabic/swupdate
- swugenerator: https://github.com/sbabic/swugenerator