diff mbox series

[04/17] Add set of properties for each image

Message ID 1511176210-28928-4-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series [01/17] parser: added function to get net child in tree | expand

Commit Message

Stefano Babic Nov. 20, 2017, 11:09 a.m. UTC
Support free to be set attributes for each image.
They are set as forbootloader with a couple of <name>,<value>
and put into a dictionary for each image. They are not used by the
installer, but can be retrieved by the handler to trim the installation.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 include/swupdate.h |  1 +
 parser/parser.c    | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
diff mbox series

Patch

diff --git a/include/swupdate.h b/include/swupdate.h
index 09e81d5..f0a6c28 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -77,6 +77,7 @@  struct img_type {
 	int install_directly;
 	int is_script;
 	int is_partitioner;
+	struct dictlist properties;
 	long long partsize;
 	int fdin;	/* Used for streaming file */
 	off_t offset;	/* offset in cpio file */
diff --git a/parser/parser.c b/parser/parser.c
index fe70b3b..8dfb326 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -152,6 +152,35 @@  static void *find_node(parsertype p, void *root, const char *node,
 	return NULL;
 }
 
+static void add_properties(parsertype p, void *node, struct img_type *image)
+{
+
+	void *properties, *prop;
+	int count, i;
+
+	properties = get_child(p, node, "properties");
+	if (properties) {
+		count = get_array_length(p, properties);
+
+		TRACE("Found %d properties for %s:", count, image->fname);
+
+		for (i = 0; i < count; i++) {
+			char key[255];
+			char value[255];
+			prop = get_elem_from_idx(p, properties, i);
+			GET_FIELD_STRING(p, prop, "name", key);
+			GET_FIELD_STRING(p, prop, "value", value);
+			TRACE("\t\tProperty %d: name=%s val=%s ", i,
+				key,
+				value
+			);
+			if (dict_insert_entry(&image->properties, key, value))
+				ERROR("Property not stored, skipping...");
+
+		}
+	}
+}
+
 #ifdef CONFIG_HW_COMPATIBILITY
 /*
  * Check if the software can run on the hardware
@@ -466,7 +495,10 @@  static int parse_images(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua
 					"Version must be checked" : ""
 			);
 
+		add_properties(p, elem, image);
+
 		if (run_embscript(p, elem, image, L, swcfg->embscript)) {
+			dict_drop_db(&image->properties);
 			free(image);
 			return -1;
 		}
@@ -537,7 +569,10 @@  static int parse_files(parsertype p, void *cfg, struct swupdate_cfg *swcfg, lua_
 			(strlen(file->id.name) && file->id.install_if_different) ?
 					"Version must be checked" : "");
 
+		add_properties(p, elem, file);
+
 		if (run_embscript(p, elem, file, L, swcfg->embscript)) {
+			dict_drop_db(&file->properties);
 			free(file);
 			return -1;
 		}