[PATCH] suricatta: save action_id in grubenv when in use

70 views
Skip to first unread message

Vincent Prince

unread,
Jun 5, 2024, 6:46:02 AM6/5/24
to vincent....@gmail.com, swup...@googlegroups.com, Vincent Prince
From: Vincent Prince <vincent.pri...@saftbatteries.com>

When GRUB is selected as bootloader, use GRUB environment file
to save action_id instead of using libubootenv methods

Signed-off-by: Vincent Prince <vincent....@gmail.com>
---
suricatta/server_hawkbit.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/suricatta/server_hawkbit.c b/suricatta/server_hawkbit.c
index 9c3e9741..f2a6edf7 100644
--- a/suricatta/server_hawkbit.c
+++ b/suricatta/server_hawkbit.c
@@ -32,6 +32,7 @@
#include "swupdate_settings.h"
#include "swupdate_dict.h"
#include "swupdate_vars.h"
+#include "bootloader.h"

#define INITIAL_STATUS_REPORT_WAIT_DELAY 10

@@ -868,7 +869,14 @@ static void get_action_id_from_env(int *action_id)
* stored.
*/
*action_id = -1;
- char *action_str = swupdate_vars_get("action_id", NULL);
+ char *action_str = NULL;
+
+ if (is_bootloader(BOOTLOADER_GRUB)) {
+ action_str = bootloader_env_get("action_id");
+ } else {
+ action_str = swupdate_vars_get("action_id", NULL);
+ }
+
if (action_str) {
int tmp = ustrtoull(action_str, NULL, 10);
if (errno)
@@ -882,6 +890,8 @@ static void get_action_id_from_env(int *action_id)
TRACE("Retrieve action_id from previous run: %d", *action_id);
}
free(action_str);
+ } else {
+ INFO("'action_id' not found in environment.");
}
}

@@ -951,7 +961,11 @@ server_op_res_t server_handle_initial_state(update_state_t stateovrrd)
/*
* Everything fine, reset action_id if any
*/
- swupdate_vars_set("action_id", NULL, NULL);
+ if (is_bootloader(BOOTLOADER_GRUB)) {
+ bootloader_env_unset("action_id");
+ } else {
+ swupdate_vars_set("action_id", NULL, NULL);
+ }

/* NOTE (Re-)setting STATE_KEY=STATE_OK == '0' instead of deleting it
* as it may be required for the switchback/recovery U-Boot logics.
@@ -1112,9 +1126,17 @@ server_op_res_t server_process_update_artifact(int action_id,
ERROR("OOM reached when saving action_id");
return SERVER_EERR;
}
- if (swupdate_vars_set("action_id", action_id_str, NULL)) {
- WARN("Action_id cannot be stored, do yourself");
- }
+
+ int ret;
+ if (is_bootloader(BOOTLOADER_GRUB)) {
+ ret = bootloader_env_set("action_id", action_id_str);
+ } else {
+ ret = swupdate_vars_set("action_id", action_id_str, NULL);
+ }
+ if (ret) {
+ WARN("Action_id cannot be stored, do yourself");
+ }
+
free(action_id_str);

for (int json_data_artifact_count = 0;
--
2.36.1

Vincent Prince

unread,
Jun 5, 2024, 6:47:38 AM6/5/24
to swup...@googlegroups.com, Vincent Prince

vincent....@gmail.com

unread,
Jun 5, 2024, 6:49:31 AM6/5/24
to swupdate

Oops sorry for the resend

Hello, 

I don't know if this kind of modification should be accepted but it's how I managed handling of action_id for suricatta with Grub bootloader.

Best regards,
Vincent

Reply all
Reply to author
Forward
0 new messages