diff mbox series

[5/7] util: add getter/setter for libuboot config

Message ID 20231009153152.416365-6-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
This is to introduce a runtime setup for libubootenv configuration file
that overrides CONFIG_UBOOT_FWENV.

Signed-off-by: Stefano Babic <stefano.babic@swupdate.org>
---
 core/util.c    | 27 +++++++++++++++++++++++++++
 include/util.h |  4 ++++
 2 files changed, 31 insertions(+)
diff mbox series

Patch

diff --git a/core/util.c b/core/util.c
index 9ab0a17d..afe447fb 100644
--- a/core/util.c
+++ b/core/util.c
@@ -53,6 +53,12 @@  struct decryption_key {
 
 static struct decryption_key *aes_key = NULL;
 
+/*
+ * Configuration file for fw_env.config
+ */
+
+static char *fwenv_config = NULL;
+
 char *sdup(const char *str) {
 	char *p;
 	if ((p = (char *) malloc(strlen(str) + 1)) != NULL) {
@@ -573,6 +579,27 @@  int set_aes_ivt(const char *ivt)
 	return 0;
 }
 
+const char *get_fwenv_config(void) {
+	if (!fwenv_config)
+#if defined(CONFIG_UBOOT)
+		return CONFIG_UBOOT_FWENV;
+#else
+		return NULL;
+#endif
+	return fwenv_config;
+}
+
+void set_fwenv_config(const char *fname) {
+	if (!fname)
+		return;
+
+	if (fwenv_config)
+		free(fwenv_config);
+
+	fwenv_config = strdup(fname);
+}
+
+
 char** string_split(const char* in, const char d)
 {
 	char** result = 0;
diff --git a/include/util.h b/include/util.h
index 5f4cdc01..b50b58ec 100644
--- a/include/util.h
+++ b/include/util.h
@@ -234,6 +234,10 @@  long long get_output_size(struct img_type *img, bool strict);
 bool img_check_free_space(struct img_type *img, int fd);
 bool check_same_file(int fd1, int fd2);
 
+/* location for libubootenv configuration file */
+const char *get_fwenv_config(void);
+void set_fwenv_config(const char *fname);
+
 /* Decryption key functions */
 int load_decryption_key(char *fname);
 unsigned char *get_aes_key(void);