Rename upgrade types: 16/276116/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 9 Jun 2022 16:27:41 +0000 (18:27 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 9 Jun 2022 17:32:29 +0000 (19:32 +0200)
  Types now include information in the name about what the upgrade is
  (FULL_IMAGE, DELTA_IMAGE) and when it is to be performed
  (BEFORE_BOOT_FOTA, AT_BOOT_FOTA):

    PRE_UA    -> FULL_IMAGE:BEFORE_BOOT_FOTA
    FULL_IMG  -> FULL_IMAGE:AT_BOOT_FOTA
    DELTA_IMG -> DELTA_IMAGE:AT_BOOT_FOTA

Change-Id: Ic0a71c1e2463ac3bad9b0c0a1119ab562cd9b100

scripts/upgrade-common.inc
scripts/upgrade-legacy.sh
scripts/upgrade-trigger.sh
src/ua.c

index 54e0692..422f88a 100644 (file)
@@ -156,8 +156,9 @@ upgrade_images() {
                        PART_NAME=${LABEL_NAME}
                fi
 
-               # We support only PRE_UA and DELTA_IMG_AB
-               if [[ ! "$TYPE" =~ ^(PRE_UA|DELTA_IMG_AB|DELTA_IMG)$ ]]; then
+               TYPE_S=(${TYPE//:/ })
+               # We support only FULL_IMAGE  and DELTA_IMAGE
+               if [[ ! "${TYPE_S[0]}" =~ ^(FULL_IMAGE|DELTA_IMAGE)$ ]]; then
                        PARTS_NAME_TO_UPDATE+=( "$PART_NAME:$TYPE" )
                        continue
                fi
@@ -176,8 +177,8 @@ upgrade_images() {
 
                local UP_RES
                untrap
-               case "$TYPE" in
-                       PRE_UA)
+               case "${TYPE_S[0]}" in
+                       FULL_IMAGE)
                                "$FOTA_DIR/upgrade-apply" --archive "$DELTA_TAR" \
                                                          --dest "$NEXT_PARTITION" \
                                                          --dest-size "$NEW_SIZE" \
@@ -185,16 +186,7 @@ upgrade_images() {
                                                          --kind raw \
                                                          --dest-sha1 "$NEW_SHA" && UP_RES=$? || UP_RES=$?
                                ;;
-                       DELTA_IMG)
-                               "$FOTA_DIR/upgrade-apply" --archive "$DELTA_TAR" \
-                                                         --dest "$NEXT_PARTITION" \
-                                                         --dest-size "$NEW_SIZE" \
-                                                         --archive-file "$DELTA_NAME" \
-                                                         --kind ss_lzma_patch \
-                                                         --patch-orig "$CURR_PARTITION" \
-                                                         --dest-sha1 "$NEW_SHA" && UP_RES=$? || UP_RES=$?
-                               ;;
-                       DELTA_IMG_AB)
+                       DELTA_IMAGE)
                                "$FOTA_DIR/upgrade-apply" --archive "$DELTA_TAR" \
                                                          --dest "$NEXT_PARTITION" \
                                                          --dest-size "$NEW_SIZE" \
index 73fc85d..d24ba55 100644 (file)
@@ -44,7 +44,7 @@ flash_pre_image() {
 
        while read -r PART_NAME DELTA_NAME TYPE DEV _OFFSET _SIZE _HASH1 _HASH2
        do
-               if [ "$TYPE" = "PRE_UA" ]; then
+               if [ "$TYPE" = "FULL_IMAGE:BEFORE_BOOT_FOTA" ]; then
                        if ! /bin/tar tf "$DELTA_TAR" "$DELTA_NAME"; then
                                log "[Info] There is no delta for $PART_NAME" "$LOG_FILE"
                                continue
index af51fd3..2f7b73d 100755 (executable)
@@ -53,9 +53,9 @@ log() {
 }
 
 is_full_upgrade() {
-       # Check if update.cfg contains any entry with type other than PRE_UA. If so,
+       # Check if update.cfg contains any entry with type other than FULL_IMAGE:BEFORE_BOOT_FOTA. If so,
        # it is not full upgrade
-       if tar Oxf "$DOWNLOAD_DELTA" update.cfg | awk '{print $3}' | grep -q -v PRE_UA; then
+       if tar Oxf "$DOWNLOAD_DELTA" update.cfg | awk '{print $3}' | grep -q -v FULL_IMAGE:BEFORE_BOOT_FOTA; then
                return $FALSE
        fi
        return $TRUE
@@ -88,7 +88,7 @@ do_update() {
                device_board_clear_partition_ab_cloned
 
                if is_full_upgrade; then
-                       # If the update.cfg file contains only PRE_UA type updates, we consider
+                       # If the update.cfg file contains only FULL_IMAGE:BEFORE_BOOT_FOTA type updates, we consider
                        # it a full upgrade. In this case the provided images will be flashed to
                        # the appropriate partitions directly from the archive so as not to
                        # consume additional space on the device.
index e744976..dcfa87b 100755 (executable)
--- a/src/ua.c
+++ b/src/ua.c
@@ -472,34 +472,9 @@ int update_Delta_FS(int part_idx, unsigned long ui32Operation)
 }
 
 /*-----------------------------------------------------------------------------
-  verify_Delta_IMG
+  verify_Delta_IMAGE
  ----------------------------------------------------------------------------*/
-int verify_Delta_IMG(int part_idx)
-{
-       int ret = SUCCESS;
-       ua_dataSS_t ua_dataSS;
-       ua_part_info_t *ua_part_info = &s_part_info[part_idx];
-       ua_update_cfg_t *ua_update_cfg = &s_update_cfg[part_idx];
-       ua_update_data_t *ua_update_data = &s_update_data[part_idx];
-       ua_delta_info_t *ua_delta_info = &s_delta_info;
-
-       ua_dataSS.parti_info = ua_part_info;
-       ua_dataSS.update_cfg = ua_update_cfg;
-       ua_dataSS.update_data = ua_update_data;
-       ua_dataSS.update_delta = ua_delta_info;
-       ua_dataSS.ua_operation = UI_OP_SCOUT;
-       ua_dataSS.ui_progress = fota_gui_progress;
-
-       if (ua_update_data->ua_delta_path != NULL)
-               ret = SS_IMGVerfiyPartition(&ua_dataSS, ua_dataSS.parti_info->ua_blk_name, true);
-
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
-  verify_Delta_IMGAB
- ----------------------------------------------------------------------------*/
-int verify_Delta_IMGAB(int part_idx)
+int verify_Delta_IMAGE(int part_idx)
 {
        int ret = SUCCESS;
        ua_dataSS_t ua_dataSS;
@@ -522,9 +497,9 @@ int verify_Delta_IMGAB(int part_idx)
 }
 
 /*-----------------------------------------------------------------------------
-  update_Delta_IMG
+  update_Delta_IMAGE
  ----------------------------------------------------------------------------*/
-int update_Delta_IMG(int part_idx, unsigned long ui32Operation)
+int update_Delta_IMAGE(int part_idx, unsigned long ui32Operation)
 {
        int ret = SUCCESS;
        ua_dataSS_t ua_dataSS;
@@ -541,35 +516,11 @@ int update_Delta_IMG(int part_idx, unsigned long ui32Operation)
        ua_dataSS.ui_progress = fota_gui_progress;
        ua_dataSS.write_data_to_blkdev = write_data_to_blkdev;
        if (ua_update_data->ua_delta_path != NULL)
-               ret = SS_IMGUpdatemain(&ua_dataSS, DELTA_IMG);
+               ret = SS_IMGUpdatemain(&ua_dataSS, DELTA_IMAGE);
        return ret;
 }
 
-/*-----------------------------------------------------------------------------
-  update_Delta_IMG_AB
- ----------------------------------------------------------------------------*/
-int update_Delta_IMG_AB(int part_idx, unsigned long ui32Operation)
-{
-       int ret = SUCCESS;
-       ua_dataSS_t ua_dataSS;
-       ua_part_info_t *ua_part_info = &s_part_info[part_idx];
-       ua_update_cfg_t *ua_update_cfg = &s_update_cfg[part_idx];
-       ua_update_data_t *ua_update_data = &s_update_data[part_idx];
-
-       ua_delta_info_t *ua_delta_info = &s_delta_info;
-       ua_dataSS.parti_info = ua_part_info;
-       ua_dataSS.update_cfg = ua_update_cfg;
-       ua_dataSS.update_data = ua_update_data;
-       ua_dataSS.update_delta = ua_delta_info;
-       ua_dataSS.ua_operation = ui32Operation;
-       ua_dataSS.ui_progress = fota_gui_progress;
-       ua_dataSS.write_data_to_blkdev = write_data_to_blkdev;
-       if (ua_update_data->ua_delta_path != NULL)
-               ret = SS_IMGUpdatemain(&ua_dataSS, DELTA_IMG_AB);
-       return ret;
-}
-
-int verify_RecoveryDelta_IMG(int part_idx, int update_type)
+int verify_RecoveryDelta_IMAGE(int part_idx, int update_type)
 {
        int ret = SUCCESS;
        ua_dataSS_t ua_dataSS;
@@ -583,12 +534,12 @@ int verify_RecoveryDelta_IMG(int part_idx, int update_type)
        ua_dataSS.update_delta = ua_delta_info;
        ua_dataSS.ua_operation = UI_OP_SCOUT;
        ua_dataSS.ui_progress = fota_gui_progress;
-       if (update_type == FULL_IMG) {
+       if (update_type == FULL_IMAGE) {
                if (ua_update_data->ua_delta_path != NULL) {
                        ret = SUCCESS;
                        fota_gui_progress(&ua_dataSS, 100);
                }
-       } else if (update_type == DELTA_IMG) {
+       } else if (update_type == DELTA_IMAGE) {
                if (ua_update_data->ua_delta_path != NULL)
                        ret = SS_IMGVerfiyPartition(&ua_dataSS, ua_dataSS.parti_info->ua_blk_name, true);
        }
@@ -596,7 +547,7 @@ int verify_RecoveryDelta_IMG(int part_idx, int update_type)
 }
 
 
-int update_RecoveryDelta_IMG(int part_idx, int update_type)
+int update_RecoveryDelta_IMAGE(int part_idx, int update_type)
 {
        int ret = SUCCESS;
        ua_dataSS_t ua_dataSS;
@@ -613,7 +564,7 @@ int update_RecoveryDelta_IMG(int part_idx, int update_type)
        ua_dataSS.ui_progress = fota_gui_progress;
        if (ua_update_data->ua_delta_path != NULL && ua_dataSS.update_data->ua_temp_path) {
                snprintf(ua_dataSS.update_data->ua_temp_path, MAX_FILE_PATH, "%s/%s", RAMDISK_PATH, ua_dataSS.parti_info->ua_parti_name);
-               LOG("update_RecoveryDelta_IMG() [%s] temp path [%s]\n", ua_dataSS.parti_info->ua_parti_name, ua_dataSS.update_data->ua_temp_path);
+               LOG("update_RecoveryDelta_IMAGE() [%s] temp path [%s]\n", ua_dataSS.parti_info->ua_parti_name, ua_dataSS.update_data->ua_temp_path);
                ret = SS_IMGUpdatemain(&ua_dataSS, update_type);        //PASS temp path whr file has to be written, Once written it should be UNLINKED after upgrade.
                }
        return ret;
@@ -774,16 +725,18 @@ int update_all()
                                LOG("[%s] Verify %s ..............................................................\n", ts,
                                        s_part_info[part_idx].ua_parti_name);
                                update_type = s_update_cfg[part_idx].update_type;
-                               if (update_type == FULL_IMG)
+                               if (s_update_cfg[part_idx].update_when != AT_BOOT_FOTA) {
+                                       LOG("ignore %s - should be modified BEFORE_BOOT_FOTA", s_part_info[part_idx].ua_parti_name);
+                                       continue;
+                               }
+                               if (update_type == FULL_IMAGE)
                                        ret = verify_Full_Image(part_idx);
-                               else if (update_type == DELTA_IMG)
-                                       ret = verify_Delta_IMG(part_idx);
-                               else if (update_type == DELTA_IMG_AB)
-                                       ret = verify_Delta_IMGAB(part_idx);
+                               else if (update_type == DELTA_IMAGE)
+                                       ret = verify_Delta_IMAGE(part_idx);
                                else if (update_type == DELTA_FS)
                                        ret = verify_Delta_FS(part_idx);
                                else if (update_type == EXTRA)
-                                       ret = verify_RecoveryDelta_IMG(part_idx, FULL_IMG);
+                                       ret = verify_RecoveryDelta_IMAGE(part_idx, FULL_IMAGE);
                                else
                                        ret = -1;
 
@@ -818,17 +771,19 @@ int update_all()
 
                                SS_Set_last_update_status(update_status, del_type);
 
+                               if (s_update_cfg[part_idx].update_when != AT_BOOT_FOTA) {
+                                       LOG("ignore %s - should be modified BEFORE_BOOT_FOTA", s_part_info[part_idx].ua_parti_name);
+                                       continue;
+                               }
                                update_type = s_update_cfg[part_idx].update_type;
-                               if (update_type == FULL_IMG)
+                               if (update_type == FULL_IMAGE)
                                        ret = update_Full_Image(part_idx);
-                               else if (update_type == DELTA_IMG)
-                                       ret = update_Delta_IMG(part_idx, ui32Operation);
-                               else if (update_type == DELTA_IMG_AB)
-                                       ret = update_Delta_IMG_AB(part_idx, ui32Operation);
+                               else if (update_type == DELTA_IMAGE)
+                                       ret = update_Delta_IMAGE(part_idx, ui32Operation);
                                else if (update_type == DELTA_FS)
                                        ret = update_Delta_FS(part_idx, ui32Operation);
                                else if (update_type == EXTRA) //TOTA
-                                       ret = update_RecoveryDelta_IMG(part_idx, FULL_IMG);
+                                       ret = update_RecoveryDelta_IMAGE(part_idx, FULL_IMAGE);
                                else
                                        ret = -1;
 
@@ -1184,19 +1139,42 @@ void remove_temp_files(void)
  ----------------------------------------------------------------------------*/
 int get_update_type(char* part_name)
 {
-       if (strcmp(part_name, "FULL_IMG") == 0)
-               return FULL_IMG;
-       if (strcmp(part_name, "DELTA_IMG") == 0)
-               return DELTA_IMG;
-       if (strcmp(part_name, "DELTA_IMG_AB") == 0)
-               return DELTA_IMG_AB;
-       if (strcmp(part_name, "DELTA_FS") == 0)
-               return DELTA_FS;
+       char *ctx;
+       char *part = strtok_r(part_name, ":", &ctx);
+       if (part) {
+               if (strcmp(part, "FULL_IMAGE") == 0)
+                       return FULL_IMAGE;
+               if (strcmp(part, "DELTA_IMAGE") == 0)
+                       return DELTA_IMAGE;
+               if (strcmp(part, "DELTA_FS") == 0)
+                       return DELTA_FS;
+       }
 
        return EXTRA;
 }
 
 /*-----------------------------------------------------------------------------
+  get_update_when
+ ----------------------------------------------------------------------------*/
+int get_update_when(char* part_name)
+{
+       char *ctx;
+       char *part = strtok_r(part_name, ":", &ctx);
+
+       if (part) // ignore the first element
+               part = strtok_r(NULL, ":", &ctx);
+
+       if (part) {
+               if (strcmp(part, "BEFORE_BOOT_FOTA") == 0)
+                       return BEFORE_BOOT_FOTA;
+               if (strcmp(part, "AT_BOOT_FOTA") == 0)
+                       return AT_BOOT_FOTA;
+       }
+       return -1;
+}
+
+
+/*-----------------------------------------------------------------------------
   fota_blkid_update
  ----------------------------------------------------------------------------*/
 int fota_blkid_update(void)
@@ -1305,6 +1283,7 @@ int fota_configure_update(void)
        char* part_name = NULL;
        char* subj_name = NULL;
        int update_type = EXTRA;
+       int update_when = -1;
        char *blk_name = NULL;
        int blk_offset = 0;
        int src_img_size = 0;
@@ -1345,6 +1324,11 @@ int fota_configure_update(void)
                                break;
                        case 2:
                                update_type = get_update_type(field);
+                               update_when = get_update_when(field);
+                               if (update_when < 0) {
+                                       LOG("unknown update type: %s", field);
+                                       return -1;
+                               }
                                break;
                        case 3:
                                blk_name = strdup(field);
@@ -1381,6 +1365,7 @@ int fota_configure_update(void)
                        s_part_info[line_num].ua_blk_offset = blk_offset;
 
                        s_update_cfg[line_num].update_type = update_type;
+                       s_update_cfg[line_num].update_when = update_when;
                        s_update_cfg[line_num].soure_img_size = src_img_size;
                        s_update_cfg[line_num].target_img_size = trg_img_size;
                        s_update_cfg[line_num].soure_sha1 = src_img_sha1;