@@ -30,6 +30,7 @@
#include "swupdate.h"
#include "pctl.h"
#include "generated/autoconf.h"
+#include "state.h"
#ifdef CONFIG_SYSTEMD
#include <systemd/sd-daemon.h>
@@ -213,6 +214,7 @@ void *network_thread (void *data)
int pipe;
fd_set pipefds;
struct timeval tv;
+ update_state_t value;
if (!instp) {
TRACE("Fatal error: Network thread aborting...");
@@ -404,6 +406,11 @@ void *network_thread (void *data)
if (set_aes_key(msg.data.aeskeymsg.key_ascii, msg.data.aeskeymsg.ivt_ascii))
msg.type = NACK;
break;
+ case SET_UPDATE_STATE:
+ value = *(update_state_t *)msg.data.msg;
+ ret = save_state((char *)STATE_KEY, value);
+ msg.type = (ret == 0) ? ACK : NACK;
+ break;
default:
msg.type = NACK;
}
@@ -12,6 +12,10 @@
#include <util.h>
#include <bootloader.h>
#include <state.h>
+#include <network_ipc.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "pctl.h"
/*
* This check is to avoid to corrupt the environment
@@ -28,16 +32,32 @@
static server_op_res_t do_save_state(char *key, char* value)
{
+ char c;
CHECK_STATE_VAR(key);
+ if (!value)
+ return -EINVAL;
+ c = *value;
+ if (c < STATE_OK || c > STATE_LAST)
+ return -EINVAL;
return bootloader_env_set(key, value) == 0 ? SERVER_OK : SERVER_EERR;
}
server_op_res_t save_state(char *key, update_state_t value)
{
char value_str[2] = {value, '\0'};
- return do_save_state(key, value_str);
+ ipc_message msg;
+ if (pid == getpid()) {
+ memset(&msg, 0, sizeof(msg));
+ msg.magic = IPC_MAGIC;
+ msg.type = SET_UPDATE_STATE;
+ msg.data.msg[0] = (char)value;
+ return (ipc_send_cmd(&msg));
+ } else { /* Main process */
+ return do_save_state(key, value_str);
+ }
}
+
server_op_res_t save_state_string(char *key, update_state_t value)
{
return do_save_state(key, get_state_string(value));
@@ -33,7 +33,9 @@ typedef enum {
POST_UPDATE,
SWUPDATE_SUBPROCESS,
REQ_INSTALL_DRYRUN,
- SET_AES_KEY
+ SET_AES_KEY,
+ SET_UPDATE_STATE, /* set bootloader ustate */
+ GET_UPDATE_STATE /* return bootloader ustate */
} msgtype;
/*
The update state sets bootloader variable to track the update state. Due to privilege separations, coprocesses are not automatically allowed to write into the bootloader interface. Create an IPC to let coprocesses like webserver and suricatta to ask the main installer to change the update state. Signed-off-by: Stefano Babic <sbabic@denx.de> --- core/network_thread.c | 7 +++++++ core/state.c | 22 +++++++++++++++++++++- include/network_ipc.h | 4 +++- 3 files changed, 31 insertions(+), 2 deletions(-)