From patchwork Wed Apr 29 14:01:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 4583 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 7C8793F206 for ; Wed, 29 Apr 2026 16:01:44 +0200 (CEST) Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-488c2a4e257sf96314455e9.3 for ; Wed, 29 Apr 2026 07:01:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1777471304; cv=pass; d=google.com; s=arc-20240605; b=kZvifjsFAszgdUphrhvVHPeo3fy6D4aAs8vOh8de7yCbtTqbadxj170qDYKQzb2iZV GQpaNe7bKTLvA0/QKBwtacxbjVsGHFD5NpSeTY3gxhYqdBtyO21nJrVgwhevY1vHUUo6 bGXJD8tguk1gmE86yimrHwpH0NK715hFjBNgoKF8GN/iZcdHRXPpp/m2M3j5PoGNOI0b Dk6bqWoDvizPXbnfKAcHHTrLxM/vg4UbUK4Pdrz1Fq5Why7aFOoItwQzFD2GUYGfkak+ RBdZEuSzj1F8THM8s0eL49/d0c0VtfOVF2+QQZqlrJ6bHEyQ0JpUcf8RtHzJl1uteXsg P4DQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=n+auAc3p/sQFDy1oP91CYEh1FaYEDzuLdEzro9U/DIw=; fh=KWyN/B4aldOF8JKcZWgXyBZkRF1JtUu3BlX9bdkrVT4=; b=duZP3CaxW/EkglOezXuzLBp4VoRkbVFPURaEUkPYeT/+DF1T9JKwYi4DUJIFFfCyJq V00p7kgHeWA+hawJAcs6cWgTihu1/kyv0fuaEHkhBZJ4daAUIcb2DClFTSP/6EQnV5wT /7QlN2YRTJ6smG0xxpioe9Dfb1PfQB/Jzf6ivboPxQSu+YfK7cRhVMK0Mwyb0lQonwyX R2soXJuwQa9IGPBrk+AvuiKZSf1cY+cD23PhhMFSHtJIhs5hKDkFrHFpaLY81rbIyIT+ YEDm2oroE5cPjRVMbNEUsupFD4HjwgyjGTutLv+5JP1b+9KVQUlbPARyqrtPiGvekGxy BJbA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Sd2zrBQg; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1777471304; x=1778076104; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=n+auAc3p/sQFDy1oP91CYEh1FaYEDzuLdEzro9U/DIw=; b=keO+5gi306q6G4QwNae6YnHrAtj513RsU5c34YjalG6vCSqgVZeXdCNo2TJaDVFkip eFCAI5j32dNbqOq0bR30QwO31KHwK3G2ltQPnCz4PMDBcM/zctUAToubYQKyt/xeB+NV brKyebEwAMLkPWtWX4eWJodQsNMirAD+ynMBY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777471304; x=1778076104; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=n+auAc3p/sQFDy1oP91CYEh1FaYEDzuLdEzro9U/DIw=; b=bZUtZ4++R7dctWP4pc+C6H/eZdeYB+G0NYfUUrTuUQX6sWKUFiOOV2Y6CoWKRYB3JH w/TMclos5J6+UX94Eftm5aHGnVgCsH7CN+gM8v6q/8khlCcAPWyaLwmC3yjG0Wx97h7S J/7DkvmIXu8RWCH0A+o9Od+gOH1ssK2t9KK5UXjvCRvY8Pt9w//t/Jhu+MBWl+RiRVMr /VJcVp2E/n2Q7CUhfx4YYHBG3Z/JkJBlyhTFcNr5G4wsok6M/QCTs43Yhbwi6pXSEKKR enttXGxoalbtnu/FnO+ep5IOxIq9ZaxosNBCBvgtNyFhYIO0LkipChzeCEjT9vhglC/X mAdA== X-Forwarded-Encrypted: i=2; AFNElJ/HGi+ve1cjrE3CvLuGTrm0Nd5gXvITrbb5MQhay/4wAv4OfwGFS7pFk3byy2L0JcI/HefPC7holpMla5Pk@patchwork.amarulasolutions.com X-Gm-Message-State: AOJu0YxixAvJWu5DaVzcxor4tyt7LlSdegIDp/odnp+S0hUf1ksxa2+3 9ZCj6+ILeFIxx5MlzesRR1g6xIZ304eEnSqhRZKtyllVED7qAmAheAqrNnbhQK6u9YERYQ== X-Received: by 2002:a05:600c:8b54:b0:48a:5339:ef0e with SMTP id 5b1f17b1804b1-48a77ae5405mr136039475e9.3.1777471303763; Wed, 29 Apr 2026 07:01:43 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com; h="AUV6zMO566VRYoDhoMCrzy2rhcES+S2GykRBAGeP0Sn7TsIoAw==" Received: by 2002:a05:600c:a405:b0:485:3184:a1ab with SMTP id 5b1f17b1804b1-48a5bc86f0els47542285e9.1.-pod-prod-03-eu; Wed, 29 Apr 2026 07:01:42 -0700 (PDT) X-Received: by 2002:a05:600c:c084:b0:489:ad:7b5b with SMTP id 5b1f17b1804b1-48a77b22e19mr91893585e9.24.1777471301901; Wed, 29 Apr 2026 07:01:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777471301; cv=none; d=google.com; s=arc-20240605; b=cgs532yzibR+rrPDeWJfUvbAcl506EF9s9Woz6v1i9AZw6fMJUwc7YlR/RN/MfNF4P C2EaaXaGwNLBuBA6sfqsE7lpE4UOjKzeGQB+VYUVVokkh6JiSlc/yO6TCo7Shbw2BfR0 kWs0UNKyqxNfi2+c1hGb5Bl5dBxtdvOckPOf2eydRCfNqeozMgIX9aCC+mB29aLRqn0N 1wMkjfJHl2o+OpxEo/Guee8T1qK2nBJ0pccQJ4ZCapcifgeYgY6NlgTVS7Ghk8ig673h mVFiWJSdcFP019hjWM24F5okE87jZyA7SJaSKAlSZwA61AkdDPNcnNny8GfWmrdaTfB4 onrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=nrGs4Vp9VVfTAec6ofwPGOsc3bnWbDFNe1MDtOtYVIo=; fh=PVQ6qK/apE8apMCQLUsBZ5FgEk1zvaf7+lv3UFNLduQ=; b=jqwliX0JGQyECpcymfwGm6L9lR+0WTb04OYFSX81vkCRw9L77hUC5LfquWCXpAufDn MQkEFcgHUBcb9F4VkrqCv2aEMYMtpaPxf2HDPfRqSyZBy4KXUljKOcjogWLDZDW9B9m2 NLa8+gi7+VX4aWwF8T7hPcpWSWhCfKJzIPF+i2jf5E53ETtFFh+NfTTpJWJOZnUp8DAE py8YMQ/ay9aaycmH5RIDnkkYmpWMVSLUshgzG3HbuP4mWzKQBmDduMwryOit/KEsfPUy USf2v0hHq2siGGZrhYMhmFXCuaOg9mIyu4BGuQFk6utU8CHO82X9Bk3UbgFSi1bspHys j/oA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Sd2zrBQg; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-48a7c5d27aasor4039375e9.13.2026.04.29.07.01.41 for (Google Transport Security); Wed, 29 Apr 2026 07:01:41 -0700 (PDT) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Gm-Gg: AeBDiesoZ5Zw3Kbq7J+0C9ZMBOxBowR0gQGLRvc61N/5d0oUaefgECsG2nzr/nnaWvh mSUmN6dNImx80vcB/HjABEGpz2rbPVrM/FJIZf91KNELUF096tge6QSZCf/ORE8Lfdrxuoin/1Y hhKUv8y4BC/jZETMbAmG4mAF91CATcNeh0HuKM6arVrzGvyB+GcaLqOKcAchqPlxlylguDEEhd5 kckeBaEIw4MUnw4CASUzrYV3g6R6yXl7Mvg91VtHmdNcVIUDe+dtfj3Yj5R0HCcYirhu1pPnv/3 pYpjs38qj/ZFNyAXseJyg4jZBh3KArRaUQSda2NhBNaCtyx6T+9+vp/HO7Hvnx5EiYX5AhbYx4b r712VTT5RmjgKMlP8p2CSZZTNssg1yJTmPrS7PpO0EG5qQBT2vhS6w/geKeMGw+KQkXD8OAKfzs vYDfcSzMc3oUO9QZoc/yfNQT7p5gqlNWF0fu/zGeCpLlK7TYcjdrGMmMIDGm8HH5F4rUwYPGG/S eGjVxBu6u/kP4RyanUvqRSDs9DEt2ITAlSEyONeLsw2sk02StoQEchoEjDaWE53l3DTd1lFgBO/ uMgs1xmBaEQXifqoFHgmaN0qoD4scfMrfow= X-Received: by 2002:a05:600c:3b15:b0:489:1f04:96c3 with SMTP id 5b1f17b1804b1-48a77ae53famr132004095e9.2.1777471299725; Wed, 29 Apr 2026 07:01:39 -0700 (PDT) Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it (host-82-56-22-134.retail.telecomitalia.it. [82.56.22.134]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48a7c5c7631sm53190915e9.13.2026.04.29.07.01.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2026 07:01:38 -0700 (PDT) From: Dario Binacchi To: swupdate@googlegroups.com Cc: linux-amarula@amarulasolutions.com, Dario Binacchi Subject: [PATCH 1/1] handler: add "fwumdata" handler Date: Wed, 29 Apr 2026 16:01:30 +0200 Message-ID: <20260429140130.615536-2-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260429140130.615536-1-dario.binacchi@amarulasolutions.com> References: <20260429140130.615536-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Sd2zrBQg; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Add a handler to manage the boot selection process according to the Firmware Update (FWU) metadata specification using the libfwumdata library. The handler is a script handler that updates the active_index and marks the selected bank as valid during the post-install phase. Example in sw-description: scripts: ( { type = "fwumdata"; properties: { active = "1"; } } ); Signed-off-by: Dario Binacchi --- Kconfig | 4 ++ Makefile.deps | 4 ++ Makefile.flags | 3 + bootloader/Kconfig | 7 ++ configs/all_handlers_defconfig | 1 + doc/source/handlers.rst | 37 ++++++++++ handlers/Kconfig | 17 +++++ handlers/Makefile | 1 + handlers/fwumdata_handler.c | 125 +++++++++++++++++++++++++++++++++ 9 files changed, 199 insertions(+) create mode 100644 handlers/fwumdata_handler.c diff --git a/Kconfig b/Kconfig index 2cf68eb890b0..fcb60f900b3f 100644 --- a/Kconfig +++ b/Kconfig @@ -129,6 +129,10 @@ config HAVE_ZCK bool option env="HAVE_ZCK" +config HAVE_LIBFWUMDATA + bool + option env="HAVE_LIBFWUMDATA" + menu "SWUpdate Settings" menu "General Configuration" diff --git a/Makefile.deps b/Makefile.deps index c759f6876dea..313d5af6230c 100644 --- a/Makefile.deps +++ b/Makefile.deps @@ -121,3 +121,7 @@ endif ifeq ($(HAVE_ZCK),) export HAVE_ZCK = y endif + +ifeq ($(HAVE_LIBFWUMDATA),) +export HAVE_LIBFWUMDATA = y +endif diff --git a/Makefile.flags b/Makefile.flags index 40dd3b66856e..76b87e67fe67 100644 --- a/Makefile.flags +++ b/Makefile.flags @@ -233,6 +233,9 @@ ifeq ($(CONFIG_UCFWHANDLER),y) LDLIBS += gpiod endif +ifeq ($(CONFIG_FWUMDATA_HANDLER),y) +LDLIBS += fwumdata +endif ifeq ($(CONFIG_BOOTLOADER_STATIC_LINKED),y) ifeq ($(CONFIG_BOOTLOADER_EBG),y) diff --git a/bootloader/Kconfig b/bootloader/Kconfig index edc02d99b2d1..36f856507356 100644 --- a/bootloader/Kconfig +++ b/bootloader/Kconfig @@ -158,3 +158,10 @@ config UPDATE_STATE_BOOTLOADER help Store update information in Bootloader's environment. +config FWUMDATA_CONFIG_FILE + string "FWU Metadata Configuration file" + depends on HAVE_LIBFWUMDATA + default "/etc/fwumdata.config" + help + It tells where the FWU metadata are saved. + diff --git a/configs/all_handlers_defconfig b/configs/all_handlers_defconfig index 16cd9b6b98f1..63299bd223ae 100644 --- a/configs/all_handlers_defconfig +++ b/configs/all_handlers_defconfig @@ -20,6 +20,7 @@ CONFIG_DISKPART=y CONFIG_DISKPART_FORMAT=y CONFIG_DISKFORMAT_HANDLER=y CONFIG_FAT_FILESYSTEM=y +CONFIG_FWUMDATA_HANDLER=y CONFIG_EXT_FILESYSTEM=y CONFIG_LUASCRIPTHANDLER=y CONFIG_RAW=y diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 6742c10a58c3..cbfb146f099c 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -1710,3 +1710,40 @@ Examples: name = "helloworld"; }; }); + +FWU Metadata Handler +-------------------- + +This is a script handler used to manage the boot selection process according to +the Firmware Update (FWU) metadata specification. + +The handler implements a post-install script that updates the metadata to switch +the active bank and marks it as valid, ensuring the system boots from the new +bank at the next reset. The ``active`` property defines which bank must be +selected. + +Example selecting boot bank 1 (bank A in A/B schema): + +:: + + scripts: ( + { + type = "fwumdata"; + properties: { + active = "1"; + } + } + ); + +Example selecting boot bank 2 (bank B in A/B schema): + +:: + + scripts: ( + { + type = "fwumdata"; + properties: { + active = "2"; + } + } + ); diff --git a/handlers/Kconfig b/handlers/Kconfig index 152bc08074a1..b7d9e51a20c9 100644 --- a/handlers/Kconfig +++ b/handlers/Kconfig @@ -151,6 +151,23 @@ config EMMC_HANDLER with a dual-copy concept. This guarantees that the upgrade is power-cut safe. +config FWUMDATA_HANDLER + bool "FWU metadata update" + depends on HAVE_LIBFWUMDATA + default n + help + This handler allows to manage the boot selection process using + firmware update (FWU) metadata via libfwumdata. + + Selecting the new boot bank automatically triggers the handler to + set the current bank for rollback and mark the selected boot-up + bank as 'valid'. + + This ensures the system is ready to boot from the updated + partition while maintaining a safe path to revert to the previous + working state if the new firmware fails to reach the 'accepted' + state + config RAW bool "raw" default n diff --git a/handlers/Makefile b/handlers/Makefile index 8490172a10a3..45fcb525e461 100644 --- a/handlers/Makefile +++ b/handlers/Makefile @@ -30,3 +30,4 @@ obj-$(CONFIG_SWUFORWARDER_HANDLER) += swuforward_handler.o swuforward-ws.o obj-$(CONFIG_UBIVOL) += ubivol_handler.o obj-$(CONFIG_UCFWHANDLER) += ucfw_handler.o obj-$(CONFIG_DOCKER) += docker_handler.o +obj-$(CONFIG_FWUMDATA_HANDLER) += fwumdata_handler.o diff --git a/handlers/fwumdata_handler.c b/handlers/fwumdata_handler.c new file mode 100644 index 000000000000..1331fe64aa74 --- /dev/null +++ b/handlers/fwumdata_handler.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "swupdate_image.h" +#include "handler.h" +#include "util.h" + +#include + +static int _fwumdata_set(uint32_t active_index, uint32_t previous_index, + uint8_t bank_state) +{ + int mdd; + int ret; + + mdd = fwumdata_init(); + if (mdd < 0) { + ERROR("Cannot initialize libfwumdata\n"); + return mdd; + } + + ret = fwumdata_read_config(mdd, CONFIG_FWUMDATA_CONFIG_FILE); + if (ret) { + ERROR("Cannot read %s\n", CONFIG_FWUMDATA_CONFIG_FILE); + goto exit; + } + + ret = fwumdata_open(mdd, 0); + if (ret) { + ERROR("Cannot open %s\n", CONFIG_FWUMDATA_CONFIG_FILE); + goto exit; + } + + ret = fwumdata_set_active_index(mdd, active_index); + if (ret) { + ERROR("Cannot set active index\n"); + goto close; + } + + fwumdata_set_previous_index(mdd, previous_index); + if (ret) { + ERROR("Cannot set previous index\n"); + goto close; + } + + ret = fwumdata_set_bank_state(mdd, active_index, bank_state); + if (ret) { + ERROR("Cannot set bank state\n"); + goto close; + } + + ret = fwumdata_store(mdd); + if (ret) { + ERROR("Cannot store fwu metadata\n"); + goto close; + } + + DEBUG("fwumdata: active: %d, previous: %d, state: 0x%x", + active_index, previous_index, bank_state); + +close: + fwumdata_close(mdd); +exit: + fwumdata_exit(mdd); + return ret; +} + +static int fwumdata_set(struct img_type *img, void *data) +{ + struct script_handler_data *script_data; + char *value; + int active_index = -1; + int previous_index; + + + if (!data) + return -EINVAL; + + script_data = data; + + /* + * Call only in case of postinstall + */ + if (script_data->scriptfn != POSTINSTALL) + return 0; + + value = dict_get_value(&img->properties, "active"); + if (!value) { + ERROR("active: cannot find in sw-description"); + return -EINVAL; + } + + active_index = ustrtoull(value, NULL, 10); + if (errno) { + ERROR("active %s: ustrotull failed", value); + return -EINVAL; + } + + active_index--; + if (active_index == 0) { + previous_index = 1; + } else if (active_index == 1) { + previous_index = 0; + } else { + ERROR("active %s: invalid value", value); + return -EINVAL; + + } + + return _fwumdata_set(active_index, previous_index, FWUMDATA_BANK_VALID); +} + +__attribute__((constructor)) +void fwumdata_handler(void) +{ + register_handler("fwumdata", fwumdata_set, + SCRIPT_HANDLER | NO_DATA_HANDLER, NULL); +}