Skip to main content

Bakit SWUpdate?

Hindi maiiwasan ang mga pag-update sa larangan. Nagbibigay SWUpdate ng isang matatag, modular na solusyon para sa pag-update ng firmware, root filesystem, at mga layer ng application - lahat na may built-in na kakayahan sa rollback.
Ito ay bukas na mapagkukunan, mahusay na dokumentado, at nagsasama nang walang putol sa isang layout ng partisyon ng A / B.

Web browser GUI para sa SWUpdate

Pangkalahatang-ideya ng arkitektura

SWUpdate ay binubuo ng ilang mahahalagang sangkap:

  • I-update ang daemon (swupdate) - tumatakbo sa aparato at inilalapat ang mga update
  • I-update ang mga handler - tukuyin kung ano ang i-update (rootfs, file, script, atbp.)
  • Mga interface ng kliyente - web interface, REST API, o lokal na CLI
  • sw-description file - tumutukoy sa istraktura at lohika ng pakete ng pag-update

Halimbawa ng daloy ng pag-update

  1. Bumuo ng isang update package (.swu) na naglalaman ng:
    ● Isang bagong imahe ng root filesystem
    ● Ang sw-description file
    • Opsyonal na mga script (para sa pagpapasadya o pag-verify)
  2. Isinusulatswupdate ang pag-update sa mga tinukoy na aparato.
  3. Kinukumpirma ng isang script pagkatapos ng pag-update ang tagumpay o nag-trigger ng isang rollback kung kinakailangan.

Halimbawa

Sa halimbawang ito, hinati namin ang isang opisyal na imahe ng Raspberry Pi OS Trixie sa dalawang file:

  • 2025-10-01-raspios-trixie-arm64.boot.vfat
  • 2025-10-01-raspios-trixie-arm64.root.ext4

Ang mga file na ito ay tinutukoy sa sw-description file upang lumikha ng .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"
        }
    ),
}

Ang sumusunod na script ng Lua ay nag-aayos ng mga partition UUID sa cmdline.txt at fstab pagkatapos ng pag-flash:

#!/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.")

Gamitin swugenerator upang i-bundle ang update:(https://github.com/sbabic/swugenerator).

Ilapat ang update

Upang subukan ang nabuong .swu file:

  1. I-boot ang CM5 sa sistema ng pagsagip.
  2. Lumikha ng isang mount point, halimbawa:
sudo mkdir -p /mnt/update
  1. Mag-mount ng isang NFS share na naglalaman ng update file:
sudo mount -t nfs :/path/to/share /mnt/update
  1. Ilapat ang update:
sudo swupdate -i /mnt/update/update.swu

Mga posibilidad ng pagsasama

Mag-trigger ng mga update mula sa isang lokal na UI o backend API

  • Mag-sign at i-verify ang mga update para sa pinahusay na seguridad
  • Gumamit SWUpdate’s web interface para sa pagsubok o pag-debug
  • Pagsamahin sa mga serbisyo ng systemd upang i-automate ang pagbawi at pag-rollback

Bakit ito akma sa stack na ito

Kasama ang rpi-image-gen at rpi-sb-provisioner, nakumpleto SWUpdate ang larawan:

  • Build → rpi-image-gen (Paglikha ng imahe)
  • I-deploy → rpi-sb-provisioner (Pagbibigay ng aparato)
  • Panatilihin ang → SWUpdate (mga update ng OTA at pamamahala ng lifecycle)

Ang resulta ay isang kakayahang umangkop, bukas, at mapanatili na naka-embed na platform ng Linux - isa na nagbabago sa iyong produkto, nang walang overhead ng Yocto.