From 174d0d81f7fb18741922db683c8b33fefa2ad6b4 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Tue, 4 Jun 2024 19:23:59 +0900 Subject: Add upgrade state feature To clarify the states of upgrade process, "upgrade state" feature is added. It is different from the "upgrade status", which looks similar but only shows the progress(-1 and 0~100) of RO and RW upgrades. The "upgrade state" shows the upgrade processes by multiple steps. (Steps follow the definition of the platform) Since the names "upgrade status" and "upgrade state" are similar, to distinguish them, "upgrade status" is renamed as "upgrade progress status". Change-Id: I7881ade876fa733f1c74ac1017df63d3c0ab31e8 Signed-off-by: SangYoun Kwak --- hw/board/board.c | 66 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/hw/board/board.c b/hw/board/board.c index 292126d..e96f4d5 100644 --- a/hw/board/board.c +++ b/hw/board/board.c @@ -28,14 +28,15 @@ #include #include -#define INFORM_MNT_PATH "/mnt/inform" -#define PARTITION_AB_PATH INFORM_MNT_PATH"/partition-ab.info" -#define PARTITION_AB_CLONED_PATH INFORM_MNT_PATH"/partition-ab-cloned.info" -#define UPGRADE_STATUS_PATH INFORM_MNT_PATH"/upgrade-status.info" -#define PARTITION_A_STATUS_PATH INFORM_MNT_PATH"/partition-a-status.info" -#define PARTITION_B_STATUS_PATH INFORM_MNT_PATH"/partition-b-status.info" -#define REBOOT_PARAM_PATH INFORM_MNT_PATH"/reboot-param.bin" -#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" +#define INFORM_MNT_PATH "/mnt/inform" +#define PARTITION_AB_PATH INFORM_MNT_PATH"/partition-ab.info" +#define PARTITION_AB_CLONED_PATH INFORM_MNT_PATH"/partition-ab-cloned.info" +#define UPGRADE_PROGRESS_STATUS_PATH INFORM_MNT_PATH"/upgrade-progress-status.info" +#define PARTITION_A_STATUS_PATH INFORM_MNT_PATH"/partition-a-status.info" +#define PARTITION_B_STATUS_PATH INFORM_MNT_PATH"/partition-b-status.info" +#define REBOOT_PARAM_PATH INFORM_MNT_PATH"/reboot-param.bin" +#define UPGRADE_STATE_PATH INFORM_MNT_PATH"/upgrade-state.info" +#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" #define PARTITION_STATUS_OK "ok" #define PARTITION_STATUS_CORRUPTED "corrupted" @@ -242,7 +243,7 @@ static int get_partition_status(char partition_ab, char *buffer, const int max_l return 0; } -static int set_upgrade_status(int status) +static int set_upgrade_progress_status(int status) { /* status: -1 if upgrade fail, otherwise 0~100 */ if (status < -1 || status > 100) { @@ -250,18 +251,18 @@ static int set_upgrade_status(int status) } /* clear contents of the file first */ - if (truncate(UPGRADE_STATUS_PATH, 0) == -1) { + if (truncate(UPGRADE_PROGRESS_STATUS_PATH, 0) == -1) { int ferror = errno; errno = 0; return -ferror; } - return sys_set_int(UPGRADE_STATUS_PATH, status); + return sys_set_int(UPGRADE_PROGRESS_STATUS_PATH, status); } -static int get_upgrade_status(int *status) +static int get_upgrade_progress_status(int *status) { - int ret_get_int = sys_get_int(UPGRADE_STATUS_PATH, status); + int ret_get_int = sys_get_int(UPGRADE_PROGRESS_STATUS_PATH, status); if (ret_get_int < 0) { return ret_get_int; @@ -275,6 +276,38 @@ static int get_upgrade_status(int *status) return 0; } +static int set_upgrade_state(char *state) +{ + if (state == NULL) + return -EINVAL; + + /* clear contents of the file first */ + if (truncate(UPGRADE_STATE_PATH, 0) == -1) { + int ferror = errno; + errno = 0; + return -ferror; + } + + return sys_set_str(UPGRADE_STATE_PATH, state); +} + +static int get_upgrade_state(char *buffer, const int max_len) +{ + int ret = 0; + + if (buffer == NULL) + return -EINVAL; + + if (max_len < 1) + return -EINVAL; + + ret = sys_get_str(UPGRADE_STATE_PATH, buffer, max_len - 1); + if (ret < 0) + return ret; + + return 0; +} + static int board_init(void **data) { hal_backend_device_board_funcs *device_board_funcs; @@ -301,8 +334,11 @@ static int board_init(void **data) device_board_funcs->set_partition_status = set_partition_status; device_board_funcs->get_partition_status = get_partition_status; - device_board_funcs->set_upgrade_status = set_upgrade_status; - device_board_funcs->get_upgrade_status = get_upgrade_status; + device_board_funcs->set_upgrade_progress_status = set_upgrade_progress_status; + device_board_funcs->get_upgrade_progress_status = get_upgrade_progress_status; + + device_board_funcs->set_upgrade_state = set_upgrade_state; + device_board_funcs->get_upgrade_state = get_upgrade_state; return 0; } -- cgit v1.2.3