diff options
author | SangYoun Kwak <sy.kwak@samsung.com> | 2022-07-14 13:47:20 +0900 |
---|---|---|
committer | SangYoun Kwak <sy.kwak@samsung.com> | 2022-07-14 14:13:39 +0900 |
commit | 992fa5ec277802ab3e053cc5855dd02d2077561a (patch) | |
tree | 02500a093b8900513f9170e5bd47ee71d520fa60 | |
parent | 152ec3c908636513adb63a507c7e6546b7b76c26 (diff) | |
download | device-rpi-992fa5ec277802ab3e053cc5855dd02d2077561a.tar.gz device-rpi-992fa5ec277802ab3e053cc5855dd02d2077561a.tar.bz2 device-rpi-992fa5ec277802ab3e053cc5855dd02d2077561a.zip |
Add hal board functions to manipulate partition/upgrade parameterssubmit/tizen/20220714.055817accepted/tizen/unified/20220715.141308
Change-Id: Ie3946532dbb0c93026fe94156b32504bf3b45fe0
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
-rw-r--r-- | hw/board/board.c | 74 |
1 files changed, 67 insertions, 7 deletions
diff --git a/hw/board/board.c b/hw/board/board.c index 061e511..775a725 100644 --- a/hw/board/board.c +++ b/hw/board/board.c @@ -22,13 +22,20 @@ #include <stdlib.h> #include <errno.h> #include <string.h> +#include <fcntl.h> +#include <unistd.h> #include </hal/include/device/hal-backend-common.h> #include <libsyscommon/file.h> -#define PARTITION_PARAM_PATH "/mnt/inform/partition-param.bin" -#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" -#define LINE_LEN 64 +#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 SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number" + +#define INT_BUFFER_LEN 32 +#define LINE_LEN 64 static int get_device_serial_number(char *buffer, int len) { @@ -89,7 +96,55 @@ static int switch_partition(char partition_ab) return -EINVAL; } - return sys_write_buf(PARTITION_PARAM_PATH, next_partition_ab); + return sys_write_buf(PARTITION_AB_PATH, next_partition_ab); +} + +static int set_partition_ab_cloned(void) +{ + return sys_write_buf(PARTITION_AB_CLONED_PATH, "1"); +} + +static int clear_partition_ab_cloned(void) +{ + return sys_write_buf(PARTITION_AB_CLONED_PATH, "0"); +} + +static int get_partition_ab_cloned(int *cloned) +{ + return sys_get_int(PARTITION_AB_CLONED_PATH, cloned); +} + +static int set_upgrade_status(int status) +{ + int fd; + int ferror; + char buf[INT_BUFFER_LEN]; + int buf_strlen; + int written_len; + + buf_strlen = snprintf(buf, sizeof(buf), "%d", status); + + /* file should be truncated before writing status to it */ + errno = 0; + fd = open(UPGRADE_STATUS_PATH, O_WRONLY | O_TRUNC); + if (fd < 0) { + ferror = errno; + errno = 0; + return -ferror; + } + + errno = 0; + written_len = write(fd, buf, buf_strlen); + if (written_len < 0) { + ferror = errno; + errno = 0; + close(fd); + return -ferror; + } + + close(fd); + + return 0; } static int board_init(void **data) @@ -100,9 +155,14 @@ static int board_init(void **data) if (!board_funcs) return -ENOMEM; - board_funcs->get_device_serial_number = get_device_serial_number; - board_funcs->get_current_partition = get_current_partition; - board_funcs->switch_partition = switch_partition; + board_funcs->get_device_serial_number = get_device_serial_number; + board_funcs->get_current_partition = get_current_partition; + board_funcs->switch_partition = switch_partition; + board_funcs->set_partition_ab_cloned = set_partition_ab_cloned; + board_funcs->clear_partition_ab_cloned = clear_partition_ab_cloned; + board_funcs->get_partition_ab_cloned = get_partition_ab_cloned; + + board_funcs->set_upgrade_status = set_upgrade_status; *data = (void *)board_funcs; |