summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSangYoun Kwak <sy.kwak@samsung.com>2022-07-13 13:46:46 +0900
committerSangYoun Kwak <sy.kwak@samsung.com>2022-07-13 14:01:06 +0900
commit7efb8402a1611e5b121f23cc5994a264c2249877 (patch)
treec066ebe039db8717e3549d43d559d1c8fa4611cd
parent55ec59005280f2a2ebf9a019a5590b6bfdcf5814 (diff)
downloaddevice-rpi-7efb8402a1611e5b121f23cc5994a264c2249877.tar.gz
device-rpi-7efb8402a1611e5b121f23cc5994a264c2249877.tar.bz2
device-rpi-7efb8402a1611e5b121f23cc5994a264c2249877.zip
Add hal board function to get/switch partition_ab
Change-Id: Ic217a5077414e9f51c79c6394cff2429cc806e55 Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
-rw-r--r--hw/board/CMakeLists.txt5
-rw-r--r--hw/board/board.c50
2 files changed, 52 insertions, 3 deletions
diff --git a/hw/board/CMakeLists.txt b/hw/board/CMakeLists.txt
index de3acea..5234091 100644
--- a/hw/board/CMakeLists.txt
+++ b/hw/board/CMakeLists.txt
@@ -4,7 +4,10 @@ PROJECT(hal-backend-device-board C)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
INCLUDE(FindPkgConfig)
-pkg_check_modules(hal-backend-device-board_pkgs REQUIRED hal-backend-device-common)
+pkg_check_modules(hal-backend-device-board_pkgs REQUIRED
+ hal-backend-device-common
+ libsyscommon
+ )
FOREACH(flag ${hal-backend-device-board_pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
diff --git a/hw/board/board.c b/hw/board/board.c
index 05525c3..061e511 100644
--- a/hw/board/board.c
+++ b/hw/board/board.c
@@ -24,9 +24,11 @@
#include <string.h>
#include </hal/include/device/hal-backend-common.h>
+#include <libsyscommon/file.h>
-#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number"
-#define LINE_LEN 64
+#define PARTITION_PARAM_PATH "/mnt/inform/partition-param.bin"
+#define SERIAL_FILE_PATH "/sys/firmware/devicetree/base/serial-number"
+#define LINE_LEN 64
static int get_device_serial_number(char *buffer, int len)
{
@@ -48,6 +50,48 @@ static int get_device_serial_number(char *buffer, int len)
return 0;
}
+static int get_current_partition(char *partition_ab)
+{
+ int ret_parse = libsys_parse_cmdline_scanf("partition_ab=%c", partition_ab);
+
+ if (ret_parse <= 0) {
+ return -ENOENT;
+ }
+
+ return 0;
+
+}
+
+static int switch_partition(char partition_ab)
+{
+ char cur_partition_ab;
+ char next_partition_ab[2];
+
+ next_partition_ab[0] = partition_ab;
+ next_partition_ab[1] = '\0';
+
+ if (partition_ab == '\0') {
+ /* Toggle partition a/b */
+ int ret_cur_part = get_current_partition(&cur_partition_ab);
+
+ if (ret_cur_part < 0) {
+ return ret_cur_part;
+ }
+
+ if (cur_partition_ab == 'a') {
+ next_partition_ab[0] = 'b';
+ } else if(cur_partition_ab == 'b') {
+ next_partition_ab[0] = 'a';
+ } else {
+ return -ENOENT;
+ }
+ } else if(partition_ab != 'a' && partition_ab != 'b') {
+ return -EINVAL;
+ }
+
+ return sys_write_buf(PARTITION_PARAM_PATH, next_partition_ab);
+}
+
static int board_init(void **data)
{
hal_backend_board_funcs *board_funcs;
@@ -57,6 +101,8 @@ static int board_init(void **data)
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;
*data = (void *)board_funcs;