From patchwork Sun Nov 8 13:37:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 5014 Delivered-To: michael@amarulasolutions.com Received: by 2002:a05:7300:aca6:b0:36a:3487:1c26 with SMTP id cr38csp1710785dyb; Sun, 8 Nov 2026 05:37:54 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErGqJFtCPAQ9OUbzefzKTbQ7W9sxn3glAw+F2ZLj58XCPyYebJm3lKLXN8OS1C+yRXCZOkrYWNFo@amarulasolutions.com X-Received: by 2002:a5d:6f05:0:b0:493:f3f2:224d with SMTP id ffacd0b85a97d-49586c257e2mr2557733f8f.5.1794145074523; Sun, 08 Nov 2026 05:37:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794145074; cv=none; d=google.com; s=arc-20260327; b=UYr1L9M3RtAjGfsiXKxJHmlrUYibNwQs0Nmjk5Oy/PpPVHfLzngj7wNApaREPlpncY o9J0EFTWIrmL4LewJiFlqdevqCwSAJlumXVnu1vTro7lz4nt0CbHPzwj7NC4tUibGZxi 4t+7FsTfe2p6wJP/2QQWPR0bRjSaA859qaERt8ETx6BqlcGERPaD1l6yII0x+OHWAx/5 fIBX1M/3PNDQrAKyslQd44MjXLAtjIl7SwA/iVwYDr0sDRSpMugbZWRw7+LyPR/NLOmv 6xS586o1FEImYMmHrgxIS3uoE9giu6FBVRfYeGvdBWR9ED9xy0Nwb4H0wNNpyvP5nY6w O5uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=1iAOGxjBTcNOOZXC8+F9WKX8PeyEvR16Z9ewHspWC+Q=; fh=XI3eNYudqIRz3J3+SoUPbmi8lOyHODZIBEN11WubDG8=; b=QGCM67kmrlwQoTo9RGHopa2wo2oaIX07Fnmt1ocjwkZkRNHV1P7SiwJJ/Cuz9cjag/ Q3EkW3vCnhrxzgPZiKP9nVO95P74lR8GT/UMOm6kcPriinE6AWgpAq5+J9K6ZpITNuEM aBROQZE6aPPzpV/Vyg7BzEvL4S3ThKXNbcksRGI3ZISZFxYAjFl3u4sZs2xdcy3Od5yV KPNlMCIWQSXacoWXGfeqUuWTOnN7SI2rsj8b06UsWeIYJ4oiiXshgu9EY5QGvaovNded jDzsN1wy9p7xi5U32Ru8u3HhIrrSt7t5qaiuW4Jz177ZKsHIXWgMktfxXSz5am2HZfuB 8dkg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="SM/DYBth"; 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 Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id ffacd0b85a97d-495983c3131sor231173f8f.14.2026.11.08.05.37.54 for (Google Transport Security); Sun, 08 Nov 2026 05:37:54 -0800 (PST) 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; Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b="SM/DYBth"; 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=1794145074; x=1794749874; darn=amarulasolutions.com; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=1iAOGxjBTcNOOZXC8+F9WKX8PeyEvR16Z9ewHspWC+Q=; b=SM/DYBthT3jlhyWNcML/TYNmEGjxwG7+2mmZQxZBgKtcwT2l5iifev7M+iaWrJDPpw CZQ8ygC7Mm6qelQngm5X3Z+hxx+hcvBz6CCAZLEX17d3VccFubstx8N3ar9chlfr0X2K vMV4IAZHj+ecniyZlrVHPvFHkU5rhUb7t6sKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794145074; x=1794749874; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=1iAOGxjBTcNOOZXC8+F9WKX8PeyEvR16Z9ewHspWC+Q=; b=2Ie7xV2Agb5wB+ZQeemQ/fCOuLU0chKQF3HQs6OzadL5NDz+s3xvKxbAIGmOmCYoN/ nvMwhfN74umjC7oQzWhC0Rtbl6QoHQ64SyR62O3gWJEUtmoZLloTG/dH/060LEkdgTmM MKHLFOn8jqf+EKZvmgqP+1DAylnx4+qOANfHE+YpAtXiIeDlia6XBElCl3wbGpJ3xnfX x4X8inaO8mSGmJCWEpoS8rspo3Mpsx5y7nukXCVd0x/o3cGuZ25oxsEUsRViYuwQ5eXZ hRHxam960ft1ti6FHa6ZXsOpJQ6p5GZzvlcF7RiNHOUW9C1qibIVae7baAl+N3G47pN4 qZRA== X-Forwarded-Encrypted: i=1; AL+hErHBZ1HNFd857nJ2PjiJgvchZ7THYQy+reR/JDivVNU/+RmUS/fF2jPwVk/RowJ8H9SIJK1DEeN+@amarulasolutions.com X-Gm-Message-State: APuU4Z/Zmc0RymyHwhQQNw3eo8Q5awPa5/+jYJk8HddI5bxxd4N19RUY UhWiUmcezM9L86rEeKfOPEemNfTg7gKv+0w+65/F0YWS02Kdzt7uFLkKbfJS+ztGquzH23lgt8r R5Kqb8hk= X-Gm-Gg: AYBFou2akM87hRAzHm0xsXXtzDQNUPrfQYfl3sUAOoqmts0KVwp887I0gwaHOft30gH kPzIgR/cdRLQwmu0vCW1WzdU0k+GKVM96uNX62idFL/OHPBFQtYrBD7w159zcdt4NqAu62ueGWf WgqgUiy/K5H0aBgTIs2sQ28WmLFPzfNFPKKU6QmqVdlubdjotfHsI2dtN41aPGbmER4dxNmxcka Tm9blmYyVPyYjdznC9LOz6+og7QtC9myY/Zxh63+bO78eBZW0dL9LNIYQWqh7BlwJwSkO9ukUP4 hkHS92gNTFojnshnokPIQQUVhsxWz9xdjAOyXUzm6a8TtQ0dgjYPPV1gwI61FC6hpymp/J5UDmn B36v8OmmxNsy8M3mQafQ+9OzZf/KlSPXFU8H56qFxqFT9WSF1kcboz/Cl5ZTvJjYM0+wn4XCRpn ZHk9WmiQlTFX6SX+y8PrKxTukOYy8WYKCw6amiSVHnzT+rafP1Ff1gq1SEtCyoU+0DZWPwoLCvy Eb6GyEWDBRsx8s6ig/VEAWuOusX4WO7wbPbKZdU00edKbiVX8QsfvmaQPfPM9txy12nJWIRaV0L M2qGov8ltOF+wJ5W0NkzJRKXEdzhpixO2thUllIYyjb/hnOAmIM6WjgsqydtzV7wmoqIRO+P8eu 1n9Fm/NaySslQov9Qa5WAplGu2QEwdn1tzmTgOPH6KTAPCxo/qyjY+DZ9I5+svOftmx/XvrCEg+ QQZrkPAbQyRh8JuhCgQu6/CuEiOA== X-Received: by 2002:a05:600c:3f1a:b0:4a1:c6fd:4db0 with SMTP id 5b1f17b1804b1-4b963c87ffdmr28858215e9.19.1794145073863; Sun, 08 Nov 2026 05:37:53 -0800 (PST) Return-Path: Received: from dario-ThinkPad-P14s-Gen-5.homenet.telecomitalia.it (host-79-14-29-58.business.telecomitalia.it. [79.14.29.58]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4b7efb1f3acsm164386465e9.14.2026.11.08.05.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2026 05:37:53 -0800 (PST) From: Dario Binacchi To: swupdate@googlegroups.com Cc: stefano.babic@swupdate.org, linux-amarula@amarulasolutions.com, michael@amarulasolutions.com, Dario Binacchi Subject: [RFC PATCH] parser: allow selecting the namespace of bootenv variables Date: Sun, 8 Nov 2026 14:37:46 +0100 Message-ID: <20261108133746.2484081-1-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 All the variables of the bootenv section go to the bootloader environment, although libubootenv handles other namespaces. The Arm FWU metadata is one of them, containing the variables that select the boot bank. Add the optional "namespace" attribute to the entries of bootenv. Existing sw-description files are not affected, and entries specifying a namespace are stored even with the "none" bootloader. Link: https://groups.google.com/g/swupdate/c/kYr2Hy-f3us Signed-off-by: Dario Binacchi --- This needs the FWU metadata storage format of libubootenv, sent as "[libubootenv][RFC PATCH 0/4] Add the FWU metadata storage format". It follows the discussion in [1]. Tested on the STM32MP257F-EV1 with TF-A and U-Boot: update of either bank, acceptance at boot, rollback by TF-A after failed trial boots. Unknown namespaces, rejected variables and the "none" bootloader were also tested on the host. [1] https://groups.google.com/g/swupdate/c/kYr2Hy-f3us core/installer.c | 39 +++++++++++++++++++++++++++ core/swupdate.c | 1 + doc/source/sw-description.rst | 33 +++++++++++++++++++++++ include/swupdate.h | 10 +++++++ parser/parser.c | 51 ++++++++++++++++++++++++++++++++--- 5 files changed, 130 insertions(+), 4 deletions(-) -- 2.43.0 diff --git a/core/installer.c b/core/installer.c index d4f08b9fb02a..f0da6c2e6cd9 100644 --- a/core/installer.c +++ b/core/installer.c @@ -260,6 +260,25 @@ static int update_swupdate_vars(struct swupdate_cfg *cfg, const char *script) return ret; } +static int update_bootenv_namespaces(struct swupdate_cfg *cfg, const char *script) +{ + struct bootenv_namespace *ns; + int ret; + + LIST_FOREACH(ns, &cfg->bootenv_namespaces, next) { + ret = prepare_var_script(&ns->vars, script); + if (ret) + return ret; + + if ((ret = swupdate_vars_apply_list(script, ns->name)) < 0) { + ERROR("Error %d updating namespace %s", ret, ns->name); + return ret; + } + } + + return 0; +} + int run_prepost_scripts(struct imglist *list, script_fn type) { int ret; @@ -524,6 +543,17 @@ int install_images(struct swupdate_cfg *sw) } } + /* + * Stored last, so that a namespace is updated only if the bootloader + * environment has been stored + */ + if (!LIST_EMPTY(&sw->bootenv_namespaces)) { + ret = update_bootenv_namespaces(sw, script); + if (ret) { + return ret; + } + } + /* * Should we generate a list with installed software? */ @@ -573,6 +603,8 @@ void cleanup_files(struct swupdate_cfg *software) { struct img_type *img_tmp; struct hw_type *hw; struct hw_type *hw_tmp; + struct bootenv_namespace *ns; + struct bootenv_namespace *ns_tmp; const char* TMPDIR = get_tmpdir(); struct imglist *list[] = {&software->scripts}; @@ -604,6 +636,13 @@ void cleanup_files(struct swupdate_cfg *software) { dict_drop_db(&software->bootloader); dict_drop_db(&software->vars); + LIST_FOREACH_SAFE(ns, &software->bootenv_namespaces, next, ns_tmp) { + LIST_REMOVE(ns, next); + dict_drop_db(&ns->vars); + free(ns->name); + free(ns); + } + /* * Drop per update URLs */ diff --git a/core/swupdate.c b/core/swupdate.c index d11faba2458c..e7112cb1683b 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -304,6 +304,7 @@ static void swupdate_init(struct swupdate_cfg *sw) LIST_INIT(&sw->hardware); LIST_INIT(&sw->scripts); LIST_INIT(&sw->bootloader); + LIST_INIT(&sw->bootenv_namespaces); LIST_INIT(&sw->extprocs); LIST_INIT(&sw->swupdate_types); LIST_INIT(&sw->external_urls); diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index 6933f4c7a672..a9204382dd31 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -1015,6 +1015,39 @@ that must be changed: SWUpdate will internally generate a script that will be passed to the bootloader handler for adjusting the environment. +The optional attribute *namespace* stores a variable in another namespace of +the `libubootenv` configuration instead of the bootloader environment, for +example in the Arm FWU metadata: + +:: + + bootenv: ( + { + name = "bootcount"; + value = "0"; + }, + { + name = "active_index"; + value = "1"; + namespace = "fwu"; + }, + { + name = "previous_active_index"; + value = "0"; + namespace = "fwu"; + }, + { + name = "bank1_state"; + value = "valid"; + namespace = "fwu"; + } + ) + +Each namespace is stored once, after the bootloader environment and in the +order in which it first appears. The update fails if a namespace or one of its +variables is rejected. The update state is always stored in the bootloader +environment. The attribute is not supported by the *bootloader* image type. + For backward compatibility with previously built `.swu` images, the "uboot" group name is still supported as an alias. However, its usage is deprecated. diff --git a/include/swupdate.h b/include/swupdate.h index c1289bfac040..5620a7bcbfe5 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -72,6 +72,15 @@ struct swupdate_parms { struct swupdate_type_cfg *type; }; +/* bootenv variables stored in a libubootenv namespace other than the default */ +struct bootenv_namespace { + char *name; + struct dict vars; + LIST_ENTRY(bootenv_namespace) next; +}; + +LIST_HEAD(bootenv_namespaces, bootenv_namespace); + struct swupdate_cfg { char name[SWUPDATE_GENERAL_STRING_SIZE]; char description[SWUPDATE_UPDATE_DESCRIPTION_STRING_SIZE]; @@ -109,6 +118,7 @@ struct swupdate_cfg { struct imglist images; struct imglist scripts; struct dict bootloader; + struct bootenv_namespaces bootenv_namespaces; struct dict vars; struct dict accepted_set; struct dict external_urls; diff --git a/parser/parser.c b/parser/parser.c index a5a6590b9402..c98ac0c048f3 100644 --- a/parser/parser.c +++ b/parser/parser.c @@ -834,11 +834,42 @@ static int parse_scripts(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lu return _parse_scripts(p, cfg, setting, nodes, swcfg, L); } +static struct dict *get_bootenv_namespace(struct swupdate_cfg *swcfg, const char *name) +{ + struct bootenv_namespace *ns; + + /* Entries are read backwards, move it first to keep the file order */ + LIST_FOREACH(ns, &swcfg->bootenv_namespaces, next) { + if (!strcmp(ns->name, name)) { + LIST_REMOVE(ns, next); + LIST_INSERT_HEAD(&swcfg->bootenv_namespaces, ns, next); + return &ns->vars; + } + } + + ns = calloc(1, sizeof(*ns)); + if (!ns) + return NULL; + + ns->name = strdup(name); + if (!ns->name) { + free(ns); + return NULL; + } + + LIST_INIT(&ns->vars); + LIST_INSERT_HEAD(&swcfg->bootenv_namespaces, ns, next); + + return &ns->vars; +} + static int _parse_bootloader(parsertype p, void *cfg, void *setting, const char **nodes, struct swupdate_cfg *swcfg, lua_State *L) { void *elem; int count, i, skip, err; struct img_type dummy; + char namespace[SWUPDATE_GENERAL_STRING_SIZE]; + struct dict *vars; if (setting == NULL) { return 0; @@ -875,15 +906,26 @@ static int _parse_bootloader(parsertype p, void *cfg, void *setting, const char */ GET_FIELD_STRING(p, elem, "name", dummy.id.name); GET_FIELD_STRING(p, elem, "value", dummy.id.version); + GET_FIELD_STRING_RESET(p, elem, "namespace", namespace); skip = run_embscript(p, elem, &dummy, L, swcfg->embscript); if (skip < 0) { return -1; } if (!skip) { - dict_set_value(&swcfg->bootloader, dummy.id.name, dummy.id.version); - TRACE("Bootloader var: %s = %s", + vars = &swcfg->bootloader; + if (strlen(namespace)) { + vars = get_bootenv_namespace(swcfg, namespace); + if (!vars) { + ERROR("No memory for namespace %s", namespace); + return -ENOMEM; + } + } + dict_set_value(vars, dummy.id.name, dummy.id.version); + TRACE("Bootloader var: %s = %s%s%s", dummy.id.name, - dict_get_value(&swcfg->bootloader, dummy.id.name)); + dict_get_value(vars, dummy.id.name), + strlen(namespace) ? ", namespace " : "", + namespace); } } @@ -1224,7 +1266,8 @@ static int parser(parsertype p, void *cfg, struct swupdate_cfg *swcfg) if (LIST_EMPTY(&swcfg->images) && LIST_EMPTY(&swcfg->scripts) && - LIST_EMPTY(&swcfg->bootloader)) { + LIST_EMPTY(&swcfg->bootloader) && + LIST_EMPTY(&swcfg->bootenv_namespaces)) { ERROR("Found nothing to install"); return -1; }