diff mbox series

[6/7] Add attribute in swupdate.cfg to get fw_env.config

Message ID 20231009153152.416365-7-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series Introduce SWUpdate environment | expand

Commit Message

Stefano Babic Oct. 9, 2023, 3:31 p.m. UTC
Add a way to override the compile option CONFIG_UBOOT_FWENV at runtime.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 bootloader/uboot.c                  | 4 ++--
 core/swupdate.c                     | 7 +++++++
 examples/configuration/swupdate.cfg | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/bootloader/uboot.c b/bootloader/uboot.c
index 4be034df..a4802775 100644
--- a/bootloader/uboot.c
+++ b/bootloader/uboot.c
@@ -42,9 +42,9 @@  static int bootloader_initialize(struct uboot_ctx **ctx)
 	int ret;
 	const char *namespace = NULL;
 
-	ret = libuboot_read_config_ext(ctx, CONFIG_UBOOT_FWENV);
+	ret = libuboot_read_config_ext(ctx, get_fwenv_config());
 	if (ret) {
-		ERROR("Cannot initialize environment from %s", CONFIG_UBOOT_FWENV);
+		ERROR("Cannot initialize environment from %s", get_fwenv_config());
 		return -EINVAL;
 	}
 
diff --git a/core/swupdate.c b/core/swupdate.c
index 07e5ef70..be78282f 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -321,6 +321,13 @@  static int read_globals_settings(void *elem, void *data)
 	get_field(LIBCFG_PARSER, elem, "syslog", &sw->syslog_enabled);
 	GET_FIELD_STRING(LIBCFG_PARSER, elem,
 				"no-downgrading", sw->minimum_version);
+	tmp[0] = '\0';
+	GET_FIELD_STRING(LIBCFG_PARSER, elem,
+				"fwenv-config-location", tmp);
+	if (strlen(tmp)) {
+		set_fwenv_config(tmp);
+		tmp[0] = '\0';
+	}
 	if (strlen(sw->minimum_version))
 		sw->no_downgrading = true;
 	GET_FIELD_STRING(LIBCFG_PARSER, elem,
diff --git a/examples/configuration/swupdate.cfg b/examples/configuration/swupdate.cfg
index c9053ddf..16532c26 100644
--- a/examples/configuration/swupdate.cfg
+++ b/examples/configuration/swupdate.cfg
@@ -48,10 +48,10 @@ 
 #			  Possible values are ebg, grub, uboot, and none for
 #			  EFI Boot Guard, U-Boot, GRUB, and the Environment in RAM bootloader,
 #			  respectively, given the respective bootloader support is compiled-in.
-#
 # namespace-vars	: namespace used by libubootenv for application/SWUpdate persistent
 #			  variables. This can be overridden in sw-description.
 #			  It is one set in libubootenv configuration file.
+# fwenv-config-location	: path of the configuration file for libubootenv
 globals :
 {