diff mbox series

[v2] swupdate-progress: Remove #ifdef SURICATTA_WFX

Message ID D189C8B8-4B20-4AAE-BC12-63BD225885BB@siemens.com
State Accepted
Headers show
Series [v2] swupdate-progress: Remove #ifdef SURICATTA_WFX | expand

Commit Message

Storm, Christian Nov. 3, 2023, 10 p.m. UTC
Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 include/progress_ipc.h    |  2 +-
 suricatta/server_wfx.lua  | 19 ++++++++-----
 suricatta/suricatta.lua   |  7 +++++
 tools/swupdate-progress.c | 56 ++++++++++++++++++++++-----------------
 4 files changed, 51 insertions(+), 33 deletions(-)
diff mbox series

Patch

diff --git a/include/progress_ipc.h b/include/progress_ipc.h
index 0d4551f9..f0b4b816 100644
--- a/include/progress_ipc.h
+++ b/include/progress_ipc.h
@@ -16,7 +16,7 @@  extern "C" {
 
 #define PRINFOSIZE	2048
 
-	typedef enum progress_cause {
+typedef enum progress_cause {
 	CAUSE_NONE,
 	CAUSE_REBOOT_MODE,
 } progress_cause_t;
diff --git a/suricatta/server_wfx.lua b/suricatta/server_wfx.lua
index e34c3f6f..fd678863 100644
--- a/suricatta/server_wfx.lua
+++ b/suricatta/server_wfx.lua
@@ -1214,13 +1214,15 @@  end
 local function send_progress_activation_msg(job)
     suricatta.notify.progress(M.utils.string
         .escape([[
-    {
-        "state": "ACTIVATING",
-        "progress": 100,
-        "message": "%s"
-    }
-    ]])
-        :format(table.concat(job.definition.type, ":")))
+        {
+            "source": %s,
+            "module": "wfx",
+            "state": "ACTIVATING",
+            "progress": 100,
+            "message": "%s"
+        }
+        ]])
+        :format(suricatta.ipc.sourcetype.SOURCE_SURICATTA, table.concat(job.definition.type, ":")))
 end
 
 --- Helper function to set persistent bootloader state.
@@ -1459,6 +1461,9 @@  M.job.workflow.dispatch:set(
             suricatta.notify.warn("Cannot initialize progress reporting channel, won't send progress.")
         end
 
+        suricatta.notify.progress(M.utils.string.escape([[{"%s": { "reboot-mode" : "no-reboot"}}]])
+            :format(suricatta.ipc.progress_cause.CAUSE_REBOOT_MODE))
+
         suricatta.notify.debug(
             "%s Version '%s' (Type: %s).",
             self.to.name,
diff --git a/suricatta/suricatta.lua b/suricatta/suricatta.lua
index 419b58c2..23a964c0 100644
--- a/suricatta/suricatta.lua
+++ b/suricatta/suricatta.lua
@@ -353,6 +353,13 @@  suricatta.ipc.RECOVERY_STATUS = {
     PROGRESS   = 8
 }
 
+--- @enum suricatta.ipc.progress_cause
+--- Lua equivalent of `progress_cause_t` as in `include/progress_ipc.h`.
+suricatta.ipc.progress_cause = {
+    CAUSE_NONE        = 0,
+    CAUSE_REBOOT_MODE = 1,
+}
+
 --- Lua-alike of `progress_msg` as in `include/progress_ipc.h`.
 --
 --- @class suricatta.ipc.progress_msg
diff --git a/tools/swupdate-progress.c b/tools/swupdate-progress.c
index a91b252e..8aaef069 100644
--- a/tools/swupdate-progress.c
+++ b/tools/swupdate-progress.c
@@ -270,7 +270,7 @@  int main(int argc, char **argv)
 			break;
 		}
 	}
-		
+
 	if (opt_p) {
 		rundir = getenv("PSPLASH_FIFO_DIR");
 		if(!rundir){
@@ -326,10 +326,9 @@  int main(int argc, char **argv)
 					break;
 				}
 				/*
-				 * Reset per update variables
+				 * Reset some per update variables prior to update.
 				 */
 				curstep = 0;
-				disable_reboot = false;
 				wait_update = false;
 			}
 		}
@@ -351,6 +350,7 @@  int main(int argc, char **argv)
 			 * Check for no-reboot mode
 			 * Just do a simple parsing for now. If more messages
 			 * will be added, JSON lib should be linked.
+			 * NOTE: Until then, the exact string format is imperative!
 			 */
 			n = sscanf(msg.info, "{\"%d\": { \"reboot-mode\" : \"%m[-a-z]\"}}",
 				   &cause, &reboot_mode);
@@ -414,46 +414,52 @@  int main(int argc, char **argv)
 				run_post_script(script, &msg);
 			}
 			resetterm();
-		#if !defined(CONFIG_SURICATTA_WFX)
-			if (psplash_ok)
+
+			if (psplash_ok && msg.status == FAILURE) {
 				psplash_progress(psplash_pipe_path, &msg);
-			psplash_ok = 0;
-			if ((msg.status == SUCCESS) && (msg.cur_step > 0) && opt_r && !disable_reboot) {
-				reboot_device();
+				psplash_ok = 0;
 			}
-		#else
-			if (msg.status == SUCCESS) {
-				fprintf(stdout, "\nWaiting for activation.\n");
+			if (psplash_ok && disable_reboot) {
+				fprintf(stdout,
+					"\nReboot disabled or waiting for activation.\n");
 				char *buf = alloca(PSPLASH_MSG_SIZE);
-				snprintf(buf, PSPLASH_MSG_SIZE - 1, "MSG Waiting for activation.");
+				snprintf(buf, PSPLASH_MSG_SIZE - 1,
+					 "MSG Reboot disabled or waiting for activation.");
 				psplash_write_fifo(psplash_pipe_path, buf);
 			}
-			if (msg.status == FAILURE) {
-				if (psplash_ok)
-					psplash_progress(psplash_pipe_path, &msg);
-				psplash_ok = 0;
+
+			if ((msg.status == SUCCESS) && (msg.cur_step > 0) && opt_r && !disable_reboot) {
+				reboot_device();
 			}
-		#endif
+			/*
+			 * Reset per update variables after update.
+			 */
+			disable_reboot = false;
 			wait_update = true;
 			break;
 		case DONE:
 			fprintf(stdout, "\nDONE.\n\n");
 			break;
 		case PROGRESS:
-			#if defined(CONFIG_SURICATTA_WFX)
-			if (strcasestr(msg.info, "\"state\": \"ACTIVATING\"") &&
+			/*
+			 * Could also check for "source": <sourcetype> as sent
+			 * by wfx but that's left for later when we have full
+			 * JSON support here.
+			 */
+			if (strcasestr(msg.info, "\"module\": \"wfx\"") &&
+			    strcasestr(msg.info, "\"state\": \"ACTIVATING\"") &&
 			    strcasestr(msg.info, "\"progress\": 100")) {
-				msg.status = SUCCESS;
-				if (psplash_ok)
+				if (psplash_ok) {
+					msg.status = SUCCESS;
 					psplash_progress(psplash_pipe_path, &msg);
-				psplash_ok = 0;
-				if (opt_r && !disable_reboot && strcasestr(msg.info, "firmware")) {
+					psplash_ok = 0;
+				}
+				if (opt_r && strcasestr(msg.info, "firmware")) {
 					reboot_device();
 					break;
 				}
-				fprintf(stdout, "Don't know how to activate this update, doing nothing.\n");
+				fprintf(stdout, "\nDon't know how to activate this update, doing nothing.\n");
 			}
-			#endif
 			break;
 		default:
 			break;