Add new API to set/get partition status 90/274590/6 accepted/tizen/unified/20220526.144326 submit/tizen/20220525.001052
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 3 May 2022 05:30:53 +0000 (14:30 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Wed, 4 May 2022 05:37:36 +0000 (14:37 +0900)
Change-Id: I1c21ce2dc6ec8f08b40316867682576f195ff23c
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
include/backend/hal-board-interface.h
include/hal-board.h
src/board.c

index b73f47de699785fa9fff3f6072d4ac9a7afc6f91..3226597cb23717ac1be33522841e53a00014d1c0 100644 (file)
@@ -24,19 +24,21 @@ extern "C" {
 
 typedef struct _hal_backend_board_funcs {
        /* Serial number of this device */
-       int (*get_device_serial_number)(char *buffer, int len);
+       int (*get_device_serial_number)(char *buffer, const int max_len);
        int (*get_device_revision)(int *revision);
 
        int (*set_boot_success)(void);
        int (*clear_boot_mode)(void);
-       int (*get_boot_mode)(char *buffer, int len);
-       int (*get_boot_reason)(char *buffer, int len);
+       int (*get_boot_mode)(char *buffer, const int max_len);
+       int (*get_boot_reason)(char *buffer, const int max_len);
 
        int (*get_current_partition)(char *partition_ab);
        int (*switch_partition)(char partition_ab);
        int (*set_partition_ab_cloned)(void);
        int (*clear_partition_ab_cloned)(void);
        int (*get_partition_ab_cloned)(int *cloned);
+       int (*set_partition_status)(char partition_ab, const char *status);
+       int (*get_partition_status)(char partition_ab, char *buffer, const int max_len);
 
        int (*set_upgrade_status)(int status);
        int (*get_upgrade_status)(int *status);
index f1dfe223aaed2495e5fba90108ed0032b70bcd9a..b018df0d281287bf4d12ab39a3f6b8617c355a8b 100644 (file)
@@ -41,12 +41,15 @@ int hal_device_board_put_backend(void);
 /**
  * @brief Get device serial number and save it to a buffer
  *
- * @param[in] len Buffer size
+ * @param[in] max_len Buffer size
  * @param[out] buffer Serial number
  *
+ * At most (max_len - 1) bytes of the serial number string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
  * @return 0 on success, otherwise a negative error value
  */
-int hal_device_board_get_device_serial_number(char *buffer, int len);
+int hal_device_board_get_device_serial_number(char *buffer, const int max_len);
 
 /**
  * @brief Get device revision (not in use, no hal backend function)
@@ -75,22 +78,28 @@ int hal_device_board_clear_boot_mode(void);
 /**
  * @brief Get the boot mode ("fota", "recovery", "normal")
  *
- * @param[in] len Buffer size
+ * @param[in] max_len Buffer size
  * @param[out] buffer boot mode
  *
+ * At most (max_len - 1) bytes of the boot mode string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
  * @return 0 on success, otherwise a negative error value
  */
-int hal_device_board_get_boot_mode(char *buffer, int len);
+int hal_device_board_get_boot_mode(char *buffer, const int max_len);
 
 /**
  * @brief Get the boot reason (not in use)
  *
- * @param[in] len Buffer size
- * @param[out] buffer boot mode
+ * @param[in] max_len Buffer size
+ * @param[out] buffer boot reason
+ *
+ * At most (max_len - 1) bytes of the boot reason string will be copied to the buffer argument,
+ * and NULL is finally appended.
  *
  * @return 0 on success, otherwise a negative error value
  */
-int hal_device_board_get_boot_reason(char *buffer, int len);// not in use
+int hal_device_board_get_boot_reason(char *buffer, const int max_len);
 
 
 /**
@@ -134,6 +143,31 @@ int hal_device_board_clear_partition_ab_cloned(void);
  */
 int hal_device_board_get_partition_ab_cloned(int *cloned);
 
+/**
+ * @brief Set the partition_status flag
+ *
+ * @param[in] partition_ab Partition slot ('a', 'b', '\0')(if '\0' then current partition)
+ * @param[in] status Status of partition ("ok", "failed", "corrupted")
+ *
+ * @return 0 on success, otherwise a negative error value
+ */
+int hal_device_board_set_partition_status(char partition_ab, const char *status);
+
+/**
+ * @brief Set the partition_status flag
+ *
+ * @param[in] partition_ab Partition slot ('a', 'b', '\0')(if '\0' then current partition)
+ * @param[out] buffer Status of partition
+ * @param[in] max_len Buffer size
+ *
+ * Examples status strings are: "ok", "failed", "corrupted"
+ * At most (max_len - 1) bytes of the status string will be copied to the buffer argument,
+ * and NULL is finally appended.
+ *
+ * @return 0 on success, otherwise a negative error value
+ */
+int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len);
+
 
 /**
  * @brief Set upgrade status
index 4affda15215bba56a874ff2b49e70ba333ff59de..6d11d72efab2f4941ccc4f00c2b54b972c5ec36c 100644 (file)
@@ -58,7 +58,7 @@ int hal_device_board_put_backend(void)
        return 0;
 }
 
-int hal_device_board_get_device_serial_number(char *buffer, int len)
+int hal_device_board_get_device_serial_number(char *buffer, const int max_len)
 {
        int ret ;
 
@@ -71,7 +71,7 @@ int hal_device_board_get_device_serial_number(char *buffer, int len)
            !hal_board_funcs->get_device_serial_number)
                return -ENODEV;
 
-       return hal_board_funcs->get_device_serial_number(buffer, len);
+       return hal_board_funcs->get_device_serial_number(buffer, max_len);
 }
 
 int hal_device_board_get_device_revision(int *revision)
@@ -123,7 +123,7 @@ int hal_device_board_clear_boot_mode(void)
        return hal_board_funcs->clear_boot_mode();
 }
 
-int hal_device_board_get_boot_mode(char *buffer, int len)
+int hal_device_board_get_boot_mode(char *buffer, const int max_len)
 {
        int ret;
 
@@ -136,10 +136,10 @@ int hal_device_board_get_boot_mode(char *buffer, int len)
            !hal_board_funcs->get_boot_mode)
                return -ENODEV;
 
-       return hal_board_funcs->get_boot_mode(buffer, len);
+       return hal_board_funcs->get_boot_mode(buffer, max_len);
 }
 
-int hal_device_board_get_boot_reason(char *buffer, int len)
+int hal_device_board_get_boot_reason(char *buffer, const int max_len)
 {
        int ret;
 
@@ -152,7 +152,7 @@ int hal_device_board_get_boot_reason(char *buffer, int len)
            !hal_board_funcs->get_boot_reason)
                return -ENODEV;
 
-       return hal_board_funcs->get_boot_reason(buffer, len);
+       return hal_board_funcs->get_boot_reason(buffer, max_len);
 }
 
 int hal_device_board_get_current_partition(char *partition_ab)
@@ -235,6 +235,38 @@ int hal_device_board_get_partition_ab_cloned(int *cloned)
        return hal_board_funcs->get_partition_ab_cloned(cloned);
 }
 
+int hal_device_board_set_partition_status(char partition_ab, const char *status)
+{
+       int ret;
+
+       if (!hal_board_funcs && !hal_initialized) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_board_funcs ||
+           !hal_board_funcs->set_partition_status)
+               return -ENODEV;
+
+       return hal_board_funcs->set_partition_status(partition_ab, status);
+}
+
+int hal_device_board_get_partition_status(char partition_ab, char *buffer, const int max_len)
+{
+       int ret;
+
+       if (!hal_board_funcs && !hal_initialized) {
+               if ((ret = hal_device_board_get_backend()) < 0)
+                       return ret;
+       }
+
+       if (!hal_board_funcs ||
+           !hal_board_funcs->get_partition_status)
+               return -ENODEV;
+
+       return hal_board_funcs->get_partition_status(partition_ab, buffer, max_len);
+}
+
 int hal_device_board_set_upgrade_status(int status)
 {
        int ret;