From patchwork Fri Nov 13 17:19:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 5024 Delivered-To: michael@amarulasolutions.com Received: by 2002:a05:7301:4187:b0:36a:3487:1c26 with SMTP id ph7csp547321dyb; Fri, 13 Nov 2026 09:19:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHlRkykYS2L2M6CcSi4w7sQsGGhCytX+z53yfL4ltPLKnUTZMxUM6E4Cfl3utJdSIT0XoE1IOZC@amarulasolutions.com X-Received: by 2002:a05:6000:250b:b0:48e:127a:c914 with SMTP id ffacd0b85a97d-49b01734a18mr14185050f8f.5.1794590349321; Fri, 13 Nov 2026 09:19:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794590349; cv=none; d=google.com; s=arc-20260327; b=A6CGdZRUn2nwhLhWHLm7bQ9oIH3rPoOabU4zWs0EkmHqkKdsHpcICy42sZuzZx5kPk bAhMJLcpvUpBZsWPYK8deaWWxshr/AcXmprlgGl8nqMDkFCm5k1W0HCw2rwPRyIgSM4t v1eAwdyIG17Nm8v2d3Z9fpayUgE3UmbbGPD5uqsx3x/YDLX71whWzrjKRvYr43tXXY/l 8yKZpzNLbtMDcswqy8+PYSt3YEVjaS+Rl5Wf1meDRQ+TUkSm30NKxXlwddZUyAPFAoNb /tfWiXoy+hhlvyj8yFv8UxdZ3bRzU9tesCYtPsF8IRCr9t3Y4FCWrgULgqlhwaI1g2n3 OwNg== 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=dOhLiTs7rIiWmiGgqIR7PtxAovgoBH6jeMdIltIqPo4=; fh=/Oe3i81Jt3G0pzU4Tr8uRlUzEg8bnVvzUxYP7rBgLqQ=; b=hgvnIRwm4MqJUalpD88mEGpuOZ3PW95hnj5N16ZhPOe+VcDnK2iz7blo+cqtvCY3Kp cUOz92/nzsPl++0n0iJGgoxf7t3NL7+qd1I5EMW88l9k7R+tVo+D9tgL6Zwpu5Q/UuvQ nNR2rKgyNOXTvLLCSCiVj1UO0x73R0Nu2xE7ZYGhsA4jsBdRcP4TQmJpEXgqtBFgqp7N x3WY/8TsV9koblPWxvi+G4UjtawHS9O9WBqwRWHR/+QX86/sqf87Zo2IXiI2O+qQgItl EdEeX1vYdIGY9r3dA5onys0bQ3nHWENDnHjkoPQjwARqWSNxX0WfrZSr5XHDop9858Vj 0f2Q==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=CrSxccSU; 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-49c67fdf16csor334260f8f.4.2026.11.13.09.19.09 for (Google Transport Security); Fri, 13 Nov 2026 09:19:09 -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=CrSxccSU; 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=1794590349; x=1795195149; 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=dOhLiTs7rIiWmiGgqIR7PtxAovgoBH6jeMdIltIqPo4=; b=CrSxccSUVIQsw3lpRRrisqtjqIbWv+z2lRc/h0gyHJNsnUpuZNhoyfoea8T7crXdq7 A5AUpvzVqdm7UNwWdXQsv2CqMHRAlIsA0T4S9V0/6qGmgqptnYfAY3dQdiw9tMuInDsv VAGQccDF/Ai+Lil5OQAlZ645znB8CWCiNXF8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794590349; x=1795195149; 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=dOhLiTs7rIiWmiGgqIR7PtxAovgoBH6jeMdIltIqPo4=; b=u20MRcw8s3xe2w7YlThTVZDL6jTzlvnJ49ASbdD9DZJHUj672DLTM598Q9pZOQlAHc begrlPLY0qjuzqq4WcyAbb7jWajPJZeAMyje+wHKBbWqo6AnD+H3pCvjJEAhuc4h6u2y VOsTygIVKYBC0RfZ36UY9h5iSVCLnc4pKu06JyVQJhbBIoLYi378SFtKj5rB4/VPqirP YgMCcQElb63uJXX2XYCwtv/vsCRyuSUkz27QTB6eJ44wJ9d7c9WyE17hJBP8kWYvIPd/ mSKuiZJVo5k8D8jtlf6yYLnDNOQs0qIJ88tP0o6R22T4bFzz1QHc3s85qy47U0qUTCOf F2mQ== X-Forwarded-Encrypted: i=1; AL+hErEt9fujkSgUA+ZkpgI3F/fA/O2duX7jg6TQQc9Ca8jlm7BZSF+Eq+hoK+Y3reTKQjqqIun9Tr9s@amarulasolutions.com X-Gm-Message-State: APuU4Z9EdshR/tLOpqOrZD5elufs0RL7lTZbARF+jdidnAkenDe3D/vV mE8f4oLFq2hAuRjvXjfv6i1Yz0ZWQybxs8pFXkd8Zu6ID9l4d/Kp7qUWlS6sKSSvfwkcow== X-Gm-Gg: AYBFou2+DuSbENiqKfooo4l06loZGR6NC6sk0PuRvYSblXPsqr1O3JuqWg/ewkGOOVc CJPH3IRkXyYiwmaRmDC2QG7kGOwoCBMCFdLSOvvX8uQM1Xyq5CSxoFT+R7N9SmlWNc15/+/Ts7/ m7yE6bBvlE+ajkp3Ihz/1etBaJ0l3/9NP4AS8HWMxlxEcdiSTErky622zuzccUtImirlMy6ho9r Z2UHZM81jbU4nnecLsMrtzYzeORRBmZ+Xct22izlhyRcxn+g9rtLISPAcv67e7LERn/EDDi3XUn pAEx+i2ZoOa7Lemu5JuSBtVVWiS8uUOcHK+yBqrW6zcgYp8KlElOQ6Ucou6pHQxS7SjuTM7Nong gYq2nEi+ok5KVPgmcW7Zzdt0g3xY3F/WqS+ukT7PwuMm+KhfM8f7MxZhT2INJIEBox2akndF7vd Fss+S9RK+WDb5sxnJB/S4ONMFHJvsoxpzflvV+F6nkPI2vapjr/aHgDlsdmWly+oGbcS9zl9ZjY ZGUWBoMdw15qcnSJc6z8O0yP6pGCGjk4c1i1UMhKNwXS+5IG75LY0uWEKZ04O225m08pFs5ugS+ rub59Gw64avMUhR9dVtpKIlJgs8evBanYA5oKrY42828NP9n6pcC7kRsP2//Nqiss8UFp1qEmqz nWb/xlOuT9w6KAYXYclP7xLjG86bNDhBjHZacQR2N1opN78ZdeXzMNdiG/ScEf1RxxvhVYU8WT+ UayVX0qvXNqksuDlICveAbD0llVA== X-Received: by 2002:a05:600c:2201:b0:4a2:f58:9a82 with SMTP id 5b1f17b1804b1-4bb4e2e9c75mr126640755e9.13.1794590348629; Fri, 13 Nov 2026 09:19:08 -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 ffacd0b85a97d-49c609c651esm6321154f8f.47.2026.11.13.09.19.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2026 09:19:07 -0800 (PST) From: Dario Binacchi To: swupdate@googlegroups.com Cc: stefano.babic@swupdate.org, linux-amarula@amarulasolutions.com, michael@amarulasolutions.com, Dario Binacchi Subject: [PATCH v2] parser: allow selecting the namespace of bootenv variables Date: Fri, 13 Nov 2026 18:19:04 +0100 Message-ID: <20261113171904.471357-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. An update with a namespace not defined in the libubootenv configuration is rejected before installing anything. The vars section with namespace-for-vars could set these variables as well, but with one namespace for all the variables of the update, and stored before the bootloader environment. The namespaces of bootenv are stored after it, so the bank switch is the last step of the update. 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][PATCH v2 0/8] Add the FWU metadata storage format". It follows the discussion in [1]. v1 was 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. v2 was tested on the same board, updating both banks and rejecting an unknown namespace, and on the host: a missing libubootenv configuration, the "none" bootloader and the unit tests. Changes in v2: - Check that the namespaces are defined in the libubootenv configuration before installing anything - Document where the namespaces are defined, with a link to the libubootenv format, and that the bootloader environment is already stored when a namespace fails - Add test cases for entries with one and two namespaces - Explain in the commit message why bootenv is used instead of vars - Drop RFC Link to v1: https://groups.google.com/g/swupdate/c/pzHEhpNxCyU [1] https://groups.google.com/g/swupdate/c/kYr2Hy-f3us core/installer.c | 39 +++++++++++++++++++++++++++ core/parser.c | 20 ++++++++++++++ core/swupdate.c | 1 + core/swupdate_vars.c | 13 +++++++++ doc/source/sw-description.rst | 41 ++++++++++++++++++++++++++++ include/swupdate.h | 10 +++++++ include/swupdate_vars.h | 1 + parser/parser.c | 51 ++++++++++++++++++++++++++++++++--- test/test_parser.c | 51 +++++++++++++++++++++++++++++++++++ 9 files changed, 223 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/parser.c b/core/parser.c index 74b39d0781a3..1caa46ec923e 100644 --- a/core/parser.c +++ b/core/parser.c @@ -17,6 +17,7 @@ #include "progress.h" #include "handler.h" #include "swupdate_crypto.h" +#include "swupdate_vars.h" static parser_fn parsers[] = { parse_cfg, @@ -211,6 +212,25 @@ int parse(struct swupdate_cfg *sw, const char *descfile) return -EINVAL; } + /* + * The namespaces are stored after the images are installed, check + * them before installing anything + */ + const char *fwenv_config = get_fwenv_config(); + if (!LIST_EMPTY(&sw->bootenv_namespaces) && !fwenv_config) { + ERROR("No libubootenv configuration for bootenv namespaces"); + return -EINVAL; + } + + struct bootenv_namespace *ns; + LIST_FOREACH(ns, &sw->bootenv_namespaces, next) { + if (!swupdate_vars_namespace_exists(ns->name)) { + ERROR("Namespace %s not found in %s", ns->name, + fwenv_config); + return -EINVAL; + } + } + #ifdef CONFIG_SIGNED_IMAGES /* 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/core/swupdate_vars.c b/core/swupdate_vars.c index 1762713f2afc..95e0255491da 100644 --- a/core/swupdate_vars.c +++ b/core/swupdate_vars.c @@ -182,6 +182,19 @@ int swupdate_vars_apply_list(const char *filename, const char *namespace) return ret; } +bool swupdate_vars_namespace_exists(const char *namespace) +{ + struct uboot_ctx *ctx = NULL; + bool exists = false; + + if (!libuboot_read_config_ext(&ctx, get_fwenv_config())) + exists = libuboot_get_namespace(ctx, namespace) != NULL; + + libuboot_exit(ctx); + + return exists; +} + bool swupdate_set_default_namespace(const char *namespace) { if (namespace_default) diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst index 6933f4c7a672..7f7ea749f4db 100644 --- a/doc/source/sw-description.rst +++ b/doc/source/sw-description.rst @@ -1015,6 +1015,47 @@ 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"; + } + ) + +The namespace must be defined in the `libubootenv` configuration, set by +*fwenv-config-location* in swupdate.cfg. See the `libubootenv documentation +`_ +for its format. An update with a namespace that is not defined is rejected +before installing anything. + +Each namespace is stored once, after the bootloader environment and in the +order in which it first appears. If a namespace cannot be stored, for example +because the FWU metadata rejects a value, the update fails but the bootloader +environment is already stored. The update state is always stored in the +bootloader environment. Variables set with a file of type *bootloader* always +go to the bootloader environment. + 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/include/swupdate_vars.h b/include/swupdate_vars.h index 1dcab9729fe8..e816926b0723 100644 --- a/include/swupdate_vars.h +++ b/include/swupdate_vars.h @@ -15,4 +15,5 @@ int swupdate_vars_apply_list(const char *filename, const char *namespace); char *swupdate_vars_get(const char *name, const char *namespace); int swupdate_vars_set(const char *name, const char *value, const char *namespace); int swupdate_vars_unset(const char *name, const char *namespace); +bool swupdate_vars_namespace_exists(const char *namespace); bool swupdate_set_default_namespace(const char *namespace); 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; } diff --git a/test/test_parser.c b/test/test_parser.c index 20cafde57190..4f0a1f8e89ee 100644 --- a/test/test_parser.c +++ b/test/test_parser.c @@ -66,6 +66,7 @@ static void sw_init(void) LIST_INIT(&sw.hardware); LIST_INIT(&sw.scripts); LIST_INIT(&sw.bootloader); + LIST_INIT(&sw.bootenv_namespaces); LIST_INIT(&sw.vars); LIST_INIT(&sw.extprocs); LIST_INIT(&sw.swupdate_types); @@ -625,6 +626,25 @@ static void test_parser_bootenv_vars(void **state) .cfg = "bootenv: ( { value = \"1\"; } );", .json = "\"bootenv\": [ { \"value\": \"1\" } ]", }; + static const struct swd ns_single = { + .cfg = "bootenv: ( { name = \"a\"; value = \"1\"; }," + " { name = \"x\"; value = \"2\"; namespace = \"fwu\"; }," + " { name = \"y\"; namespace = \"fwu\"; } );", + .json = "\"bootenv\": [ { \"name\": \"a\", \"value\": \"1\" }," + " { \"name\": \"x\", \"value\": \"2\", \"namespace\": \"fwu\" }," + " { \"name\": \"y\", \"namespace\": \"fwu\" } ]", + }; + static const struct swd ns_multi = { + .cfg = "bootenv: ( { name = \"x\"; value = \"1\"; namespace = \"fwu\"; }," + " { name = \"a\"; value = \"2\"; }," + " { name = \"y\"; value = \"3\"; namespace = \"app\"; }," + " { name = \"z\"; value = \"4\"; namespace = \"fwu\"; } );", + .json = "\"bootenv\": [ { \"name\": \"x\", \"value\": \"1\", \"namespace\": \"fwu\" }," + " { \"name\": \"a\", \"value\": \"2\" }," + " { \"name\": \"y\", \"value\": \"3\", \"namespace\": \"app\" }," + " { \"name\": \"z\", \"value\": \"4\", \"namespace\": \"fwu\" } ]", + }; + struct bootenv_namespace *ns; FOR_EACH_FORMAT(f) { sw_init(); @@ -637,6 +657,37 @@ static void test_parser_bootenv_vars(void **state) /* a link in vars adds vars, not bootloader variables */ assert_dict_value(&sw.vars, "w", "y"); assert_null(dict_get_value(&sw.bootloader, "w")); + assert_true(LIST_EMPTY(&sw.bootenv_namespaces)); + sw_free(); + + sw_init(); + assert_int_equal(parse_swd(&ns_single, f), 0); + assert_dict_value(&sw.bootloader, "a", "1"); + assert_null(dict_get_value(&sw.bootloader, "x")); + ns = LIST_FIRST(&sw.bootenv_namespaces); + assert_non_null(ns); + assert_string_equal(ns->name, "fwu"); + assert_dict_value(&ns->vars, "x", "2"); + assert_dict_value(&ns->vars, "y", ""); + assert_null(LIST_NEXT(ns, next)); + sw_free(); + + /* namespaces keep the order in which they first appear */ + sw_init(); + assert_int_equal(parse_swd(&ns_multi, f), 0); + assert_dict_value(&sw.bootloader, "a", "2"); + assert_null(dict_get_value(&sw.bootloader, "x")); + ns = LIST_FIRST(&sw.bootenv_namespaces); + assert_non_null(ns); + assert_string_equal(ns->name, "fwu"); + assert_dict_value(&ns->vars, "x", "1"); + assert_dict_value(&ns->vars, "z", "4"); + assert_null(dict_get_value(&ns->vars, "y")); + ns = LIST_NEXT(ns, next); + assert_non_null(ns); + assert_string_equal(ns->name, "app"); + assert_dict_value(&ns->vars, "y", "3"); + assert_null(LIST_NEXT(ns, next)); sw_free(); sw_init();