Add upgrade type feature 56/313856/2 accepted/tizen/unified/x/20240708.014828
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Tue, 2 Jul 2024 10:29:14 +0000 (12:29 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 4 Jul 2024 12:41:53 +0000 (14:41 +0200)
Use set_upgrade_type to select the type of upgrade:
* online
* offline

After reboot fota, u-boot will run online or offline upgrade based on
the selected  type.

Change-Id: Ie9fc41224140d0ef4a7a481dcbb4718954dc85e8

hw/board/board.c

index 1db770cc205fb4c187df9fd90f21dfcbeb697b8a..271e1a2fa3dcd9014dea605816bad01b0653b2b9 100644 (file)
@@ -36,6 +36,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"
@@ -43,6 +44,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;
@@ -338,6 +342,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 sysfs_write_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 = sysfs_read_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_device_board_funcs *device_board_funcs;
@@ -370,6 +418,9 @@ static int board_init(void **data)
        device_board_funcs->set_upgrade_state = set_upgrade_state;
        device_board_funcs->get_upgrade_state = get_upgrade_state;
 
+       device_board_funcs->set_upgrade_type = set_upgrade_type;
+       device_board_funcs->get_upgrade_type = get_upgrade_type;
+
        return 0;
 }