diff options
-rw-r--r-- | hw/board/board.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/hw/board/board.c b/hw/board/board.c index c396ff1..b02f22d 100644 --- a/hw/board/board.c +++ b/hw/board/board.c @@ -37,6 +37,7 @@ #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 UPGRADE_TYPE_PATH INFORM_MNT_PATH"/upgrade-type.info" #define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" #define PARTITION_STATUS_OK "ok" @@ -44,6 +45,9 @@ #define PARTITION_STATUS_FAILED "failed" #define BOOT_MODE_NORMAL "norm" +#define UPGRADE_TYPE_ONLINE "online" +#define UPGRADE_TYPE_OFFLINE "offline" + static int get_device_serial_number(char *buffer, int len) { FILE *fp; @@ -339,6 +343,50 @@ static int get_upgrade_state(char *buffer, const int max_len) return 0; } +static int set_upgrade_type(char *type) +{ + if (type == NULL) + return -EINVAL; + + if (strcmp(type, UPGRADE_TYPE_ONLINE) != 0 && + strcmp(type, UPGRADE_TYPE_OFFLINE) != 0) { + return -EINVAL; + } + + /* clear contents of the file first */ + if (truncate(UPGRADE_TYPE_PATH, 0) == -1) { + int ferror = errno; + errno = 0; + return -ferror; + } + + return sys_set_str(UPGRADE_TYPE_PATH, type); +} + +static int get_upgrade_type(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_TYPE_PATH, buffer, max_len - 1); + if (ret < 0) + return ret; + + trim_str(buffer); + + if (strcmp(buffer, UPGRADE_TYPE_ONLINE) != 0 && + strcmp(buffer, UPGRADE_TYPE_OFFLINE) != 0) { + return -ENOENT; + } + + return 0; +} + static int board_init(void **data) { hal_backend_board_funcs *board_funcs; @@ -368,6 +416,9 @@ static int board_init(void **data) *data = (void *)board_funcs; + board_funcs->set_upgrade_type = set_upgrade_type; + board_funcs->get_upgrade_type = get_upgrade_type; + return 0; } |