diff mbox series

[3/9] bootloader: change "none" in RAM mode

Message ID 20180906114041.21828-3-sbabic@denx.de
State Accepted
Headers show
Series None | expand

Commit Message

Stefano Babic Sept. 6, 2018, 11:40 a.m. UTC
Instead of doing nothing, the "none" bootloader
maintains a list of environment in RAM.

This allows full test when a variable is set and then
read back from code.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 bootloader/Config.in |  6 ++++--
 bootloader/none.c    | 24 ++++++++++++++++++++----
 2 files changed, 24 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/bootloader/Config.in b/bootloader/Config.in
index 9e33dba..c71a143 100644
--- a/bootloader/Config.in
+++ b/bootloader/Config.in
@@ -27,9 +27,11 @@  comment "U-Boot support needs libubootenv, libz"
 	depends on !HAVE_LIBUBOOTENV || !HAVE_ZLIB
 
 config BOOTLOADER_NONE
-	bool "None"
+	bool "Environment in RAM"
 	help
-	  No interface to a bootloader
+	  This simulates the interface to a bootloader.
+	  Bootloader environment is just maitained in RAM
+	  and lost when SWUpdate exits.
 
 config BOOTLOADER_GRUB
 	bool "GRUB"
diff --git a/bootloader/none.c b/bootloader/none.c
index a061ca0..57ff121 100644
--- a/bootloader/none.c
+++ b/bootloader/none.c
@@ -6,24 +6,40 @@ 
  */
 
 #include <unistd.h>
+#include <string.h>
 #include "bootloader.h"
+#include "swupdate_dict.h"
+
+static struct dict environment;
+
 int bootloader_env_set(const char __attribute__ ((__unused__)) *name,
 			const char __attribute__ ((__unused__)) *value)
 {
+	dict_set_value(&environment, name, value);
+
 	return 0;
 }
 
-int bootloader_env_unset(const char __attribute__ ((__unused__)) *name)
+int bootloader_env_unset(const char *name)
 {
+	dict_remove(&environment, name);
+
 	return 0;
 }
 
 char *bootloader_env_get(const char __attribute__ ((__unused__)) *name)
 {
-	return NULL;
+	char *value = NULL, *var;
+
+	var = dict_get_value(&environment, name);
+
+	if (var)
+		value = strdup(var);
+
+	return value;
 }
 
-int bootloader_apply_list(const char __attribute__ ((__unused__)) *filename)
+int bootloader_apply_list(const char *filename)
 {
-	return 0;
+	return dict_parse_script(&environment, filename);
 }