diff mbox series

[6/6] IPC: let decide selections at runtime

Message ID 20201111120327.607444-7-sbabic@denx.de
State Changes Requested
Headers show
Series Rework and extend IPC for install | expand

Commit Message

Stefano Babic Nov. 11, 2020, 12:03 p.m. UTC
It is useful to change the selection type at runtime if more as one
section inside sw-description can be installed. This activates a
selection sent via IPC to be used for the next update. The default
configuration is cached and will be active at next update if the request
does not contain any valid selection.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 core/stream_interface.c | 19 ++++++++++++++++++-
 core/swupdate.c         |  8 +++++++-
 include/swupdate.h      |  2 ++
 3 files changed, 27 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/core/stream_interface.c b/core/stream_interface.c
index e7298d9..89ae52e 100644
--- a/core/stream_interface.c
+++ b/core/stream_interface.c
@@ -476,6 +476,7 @@  void *network_initializer(void *data)
 {
 	int ret;
 	struct swupdate_cfg *software = data;
+	struct swupdate_request *req;
 
 	/* No installation in progress */
 	memset(&inst, 0, sizeof(inst));
@@ -497,14 +498,30 @@  void *network_initializer(void *data)
 		pthread_mutex_unlock(&stream_mutex);
 		notify(START, RECOVERY_NO_ERROR, INFOLEVEL, "Software Update started !");
 
+		req = &inst.req;
+
 		/*
 		 * Check if the dry run flag is overwritten
 		 */
-		if (inst.req.dry_run)
+		if (req->dry_run)
 			software->globals.dry_run = 1;
 		else
 			software->globals.dry_run = 0;
 
+		/*
+		 * Find the selection to be installed
+		 */
+		if ((strnlen(req->software_set, sizeof(req->software_set)) > 0) &&
+				(strnlen(req->running_mode, sizeof(req->running_mode)) > 0)) {
+			strlcpy(software->software_set, req->software_set, sizeof(software->software_set) - 1);
+			strlcpy(software->running_mode, req->running_mode, sizeof(software->running_mode) - 1);
+		} else {
+			strlcpy(software->software_set, software->globals.default_software_set,
+				sizeof(software->software_set) - 1);
+			strlcpy(software->running_mode, software->globals.default_running_mode,
+				sizeof(software->running_mode) - 1);
+		}
+
 		/*
 		 * Check if the stream should be saved
 		 */
diff --git a/core/swupdate.c b/core/swupdate.c
index 5e5fbaf..ba5d129 100644
--- a/core/swupdate.c
+++ b/core/swupdate.c
@@ -414,8 +414,14 @@  static int parse_image_selector(const char *selector, struct swupdate_cfg *sw)
 
 	*pos = '\0';
 
+	/*
+	 * the runtime copy in swcfg can be overloaded by IPC,
+	 * so maintain a copy to restore it after an update
+	 */
+	strlcpy(sw->globals.default_software_set, selector, sizeof(sw->globals.default_software_set));
 	strlcpy(sw->software_set, selector, sizeof(sw->software_set));
 	/* pos + 1 will either be NULL or valid text */
+	strlcpy(sw->globals.default_running_mode, pos + 1, sizeof(sw->globals.default_running_mode));
 	strlcpy(sw->running_mode, pos + 1, sizeof(sw->running_mode));
 
 	if (strlen(sw->software_set) == 0 || strlen(sw->running_mode) == 0)
@@ -986,7 +992,7 @@  int main(int argc, char **argv)
 			exit(EXIT_FAILURE);
 		}
 		fprintf(stderr, "software set: %s mode: %s\n",
-			swcfg.software_set, swcfg.running_mode);
+			swcfg.globals.default_software_set, swcfg.globals.default_running_mode);
 	}
 
 	/* Read sw-versions */
diff --git a/include/swupdate.h b/include/swupdate.h
index 29b756d..4ae0b43 100644
--- a/include/swupdate.h
+++ b/include/swupdate.h
@@ -135,6 +135,8 @@  struct swupdate_global_cfg {
 	char aeskeyfname[SWUPDATE_GENERAL_STRING_SIZE];
 	char postupdatecmd[SWUPDATE_GENERAL_STRING_SIZE];
 	char preupdatecmd[SWUPDATE_GENERAL_STRING_SIZE];
+	char default_software_set[SWUPDATE_GENERAL_STRING_SIZE];
+	char default_running_mode[SWUPDATE_GENERAL_STRING_SIZE];
 	char minimum_version[SWUPDATE_GENERAL_STRING_SIZE];
 	char current_version[SWUPDATE_GENERAL_STRING_SIZE];
 	int cert_purpose;