diff options
author | Marek Szulc <m.szulc3@samsung.com> | 2022-08-30 10:16:48 +0200 |
---|---|---|
committer | Marek Szulc <m.szulc3@samsung.com> | 2022-09-01 12:34:37 +0200 |
commit | e55d6c05c23d03715970e4d6196f42c4496d7fa3 (patch) | |
tree | 55a471e6393bd05711d197cce8b9938e6001c4fa | |
parent | 6bb329e39830ea5a11bec8182aef5481c3688fa2 (diff) | |
download | device-rpi-e55d6c05c23d03715970e4d6196f42c4496d7fa3.tar.gz device-rpi-e55d6c05c23d03715970e4d6196f42c4496d7fa3.tar.bz2 device-rpi-e55d6c05c23d03715970e4d6196f42c4496d7fa3.zip |
add API functions get_upgrade_status(), set_partition_status(),
get_partition_status(), clear_boot_mode()
Change-Id: Ifc9c32d3c7c27d42cb907aabf769daa95fa2cefe
Signed-off-by: Marek Szulc <m.szulc3@samsung.com>
-rw-r--r-- | hw/board/board.c | 85 |
1 files changed, 83 insertions, 2 deletions
diff --git a/hw/board/board.c b/hw/board/board.c index 070bc8a..1ddd57c 100644 --- a/hw/board/board.c +++ b/hw/board/board.c @@ -33,9 +33,17 @@ #define PARTITION_AB_CLONED_PATH INFORM_MNT_PATH"/partition-ab-cloned.info" #define UPGRADE_STATUS_PATH INFORM_MNT_PATH"/upgrade-status.info" #define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" +#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 INT_BUFFER_LEN 32 -#define LINE_LEN 64 +#define INT_BUFFER_LEN 32 +#define STATUS_BUFFER_LEN 16 +#define LINE_LEN 64 + +#define PARTITION_STATUS_OK "ok" +#define PARTITION_STATUS_CORRUPTED "corrupted" +#define PARTITION_STATUS_FAILED "failed" static int get_device_serial_number(char *buffer, int len) { @@ -163,6 +171,75 @@ static int set_upgrade_status(int status) return 0; } +static int get_upgrade_status(int *status) +{ + return sys_get_int(UPGRADE_STATUS_PATH, status); +} + +static int set_partition_status(char partition_ab, const char *status) +{ + char *path; + + if ((partition_ab != 'a' && partition_ab != 'b') || status == NULL) + return -ENOTSUP; + if (strcmp(status, PARTITION_STATUS_OK) != 0 && strcmp(status, PARTITION_STATUS_CORRUPTED) != 0 && + strcmp(status, PARTITION_STATUS_FAILED) != 0) + return -ENOTSUP; + + if (partition_ab == 'a') + path = PARTITION_A_STATUS_PATH; + else + path = PARTITION_B_STATUS_PATH; + + /* clear contents of the file first */ + if (truncate(path, 0) == -1) { + int ferror = errno; + errno = 0; + return -ferror; + } + + return sys_set_str(path, (char *)status); +} + +static int get_partition_status(char partition_ab, char *res_buf, const int max_len) +{ + char *path; + + if (partition_ab != 'a' && partition_ab != 'b') + return -ENOTSUP; + if (res_buf == NULL || max_len <= strlen(PARTITION_STATUS_CORRUPTED) + 1) + return -ENOBUFS; + + if (partition_ab == 'a') + path = PARTITION_A_STATUS_PATH; + else + path = PARTITION_B_STATUS_PATH; + + int result = sys_get_str(path, res_buf, max_len); + /* remove potential newline | tokenizer will place '\0' in a place of '\n' */ + strtok(res_buf, "\n"); + + if (strcmp(res_buf, PARTITION_STATUS_OK) != 0 && strcmp(res_buf, PARTITION_STATUS_CORRUPTED) != 0 && strcmp(res_buf, PARTITION_STATUS_FAILED) != 0) + result = -ENOTSUP; + + return result; +} + +static int clear_boot_mode() +{ + char *cont = "norm"; + char *path = REBOOT_PARAM_PATH; + + /* clear contents of the file first */ + if (truncate(path, 0) == -1) { + int ferror = errno; + errno = 0; + return -ferror; + } + + return sys_set_str(path, cont); +} + static int board_init(void **data) { hal_backend_board_funcs *board_funcs; @@ -180,6 +257,10 @@ static int board_init(void **data) board_funcs->get_partition_ab_cloned = get_partition_ab_cloned; board_funcs->set_upgrade_status = set_upgrade_status; + board_funcs->get_upgrade_status = get_upgrade_status; + board_funcs->set_partition_status = set_partition_status; + board_funcs->get_partition_status = get_partition_status; + board_funcs->clear_boot_mode = clear_boot_mode; *data = (void *)board_funcs; |