diff mbox series

libubootenv: support newer yaml config

Message ID 20231004080725.16575-1-stefano.babic@swupdate.org
State Accepted
Delegated to: Stefano Babic
Headers show
Series libubootenv: support newer yaml config | expand

Commit Message

Stefano Babic Oct. 4, 2023, 8:07 a.m. UTC
libubootenv supports now a configuartion file in YAML.  Adjust initialization
to support the new format that requires a different initialization.

This is also a preparation to full support libubootenv's namespaces in
SWUpdate and to have a persistent area for variables handled by SWUpdate
but not by the bootloader.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 bootloader/uboot.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/bootloader/uboot.c b/bootloader/uboot.c
index a2f07948..7fd47ac7 100644
--- a/bootloader/uboot.c
+++ b/bootloader/uboot.c
@@ -39,14 +39,20 @@  static struct {
 
 static int bootloader_initialize(struct uboot_ctx **ctx)
 {
-	if (libuboot.initialize(ctx, NULL) < 0) {
-		ERROR("Error: environment not initialized");
-		return -ENODEV;
-	}
-	if (libuboot.read_config(*ctx, CONFIG_UBOOT_FWENV) < 0) {
-		ERROR("Configuration file %s wrong or corrupted", CONFIG_UBOOT_FWENV);
+	int ret;
+	const char *namespace = NULL;
+
+	ret = libuboot_read_config_ext(ctx, CONFIG_UBOOT_FWENV);
+	if (ret) {
+		ERROR("Cannot initialize environment from %s", CONFIG_UBOOT_FWENV);
 		return -EINVAL;
 	}
+
+	namespace = libuboot_namespace_from_dt();
+
+	if (namespace)
+		*ctx = libuboot_get_namespace(*ctx, namespace);
+
 	if (libuboot.open(*ctx) < 0) {
 		WARN("Cannot read environment, using default");
 		if (libuboot.load_file(*ctx, CONFIG_UBOOT_DEFAULTENV) < 0) {