Add delta.ua - a binary to apply an upgrade of DELTA_FS type. 80/280480/6
authorAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Mon, 29 Aug 2022 15:21:28 +0000 (17:21 +0200)
committerAntoni Adaszkiewicz <a.adaszkiewi@samsung.com>
Mon, 7 Nov 2022 10:02:48 +0000 (11:02 +0100)
The binary is build with code previously from tota-ua and libtota, although some
changes were made. They include: changes to make delta.ua a command line tool
(reading given parameters instead of reading config files), changes to make delta.ua a tool
only applying the deltas and only applying them for one partition, adding support for handling
hardlinks (previously in cases where harlinks were present in a delta, upgrade wasn't guaranteed
to be successsful), removing code/files unused for update types other than DELTA_FS
and other more minor changes (e.g. removing unused functions)

Change-Id: Ice1e272a553abb5ebae4230eaffe82afc931b204

23 files changed:
CMakeLists.txt
packaging/upgrade.spec
src/delta-ua/CMakeLists.txt [new file with mode: 0644]
src/delta-ua/engine/SS_Common.c
src/delta-ua/engine/SS_Common.h
src/delta-ua/engine/SS_Engine_Errors.h
src/delta-ua/engine/SS_FSUpdate.c
src/delta-ua/engine/SS_FSUpdate.h
src/delta-ua/engine/SS_PatchDelta.c
src/delta-ua/engine/SS_PatchDelta.h
src/delta-ua/engine/SS_UPI.c
src/delta-ua/engine/SS_UPI.h
src/delta-ua/engine/fota_common.h
src/delta-ua/engine/fota_log.c
src/delta-ua/engine/fota_log.h
src/delta-ua/engine/fota_tar.c
src/delta-ua/engine/ua_types.h
src/delta-ua/fota_cfg.c
src/delta-ua/fota_cfg.h
src/delta-ua/fota_util.c
src/delta-ua/fota_util.h
src/delta-ua/ua.c
src/delta-ua/ua.h

index 1861131..439f010 100644 (file)
@@ -43,6 +43,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed -pie")
 ADD_SUBDIRECTORY(src/dmverity)
 ADD_SUBDIRECTORY(src/img-verifier)
 ADD_SUBDIRECTORY(src/upgrade-apply)
+ADD_SUBDIRECTORY(src/delta-ua)
 ADD_SUBDIRECTORY(src/blkid-print)
 ADD_SUBDIRECTORY(data)
 ADD_SUBDIRECTORY(scripts/rw-upgrade)
index a5cf45f..cf88573 100644 (file)
@@ -38,7 +38,6 @@ Update engine adding all necessary tools, scripts and configuration
 for updating Tizen platform images using delta files as generated by
 upgrade-tools.
 
-
 %description
 Update engine for updating Tizen platform images using delta files
 generated by upgrade-tools.
@@ -137,6 +136,7 @@ fi
 %{upgrade_support_dir}/upgrade-common.inc
 %{_bindir}/upgrade-apply
 %{_bindir}/verity_handler
+%{_bindir}/delta.ua
 %{_bindir}/blkid-print
 # Image verifier
 %{_sbindir}/img-verifier
diff --git a/src/delta-ua/CMakeLists.txt b/src/delta-ua/CMakeLists.txt
new file mode 100644 (file)
index 0000000..9b5c61f
--- /dev/null
@@ -0,0 +1,36 @@
+ADD_DEFINITIONS("-DFEATURE_SUPPORT_CAPABILITY")
+ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
+
+SET(SRCS
+       fota_cfg.c
+       fota_util.c
+       ua.c
+       engine/SS_Common.c
+       ../upgrade-apply/sha1/sha1.c
+       engine/SS_UPI.c
+       engine/SS_FSUpdate.c
+       engine/fota_tar.c
+       engine/SS_ApplyPatch.c
+       engine/SS_PatchDelta.c
+       engine/fota_log.c
+       engine/fota_tar.c
+       engine/ss_bspatch_common.c
+)
+
+INCLUDE_DIRECTORIES(../upgrade-apply/sha1)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(${PROJECT_NAME}_pkgs REQUIRED liblzma-tool libbrotlienc hal-api-device zlib)
+
+FOREACH(flag ${${PROJECT_NAME}_pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -I./include")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(EXECNAME "delta.ua")
+SET(BINDIR "/usr/bin")
+ADD_EXECUTABLE(${EXECNAME} ${SRCS})
+TARGET_LINK_LIBRARIES(${EXECNAME} ${${PROJECT_NAME}_pkgs_LDFLAGS} "-g" "-pthread")
+INSTALL(TARGETS ${EXECNAME} DESTINATION ${BINDIR})
index b0815ea..fe4c74d 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
 #include <fcntl.h>
 #include <string.h>
 
-#include "SS_ImageUpdate.h"
 #include "SS_Engine_Errors.h"
 #include "SS_Common.h"
 
 #include "fota_common.h"
 #include "sha1.h"
 
-void SS_Progress(void *pbUserData, SS_UINT32 uPercent)
-{
-       LOG("Progress before\n");
-       LOGL(LOG_SSENGINE, "Progress.. (%u %%)\n", uPercent);
-       LOG("Progress after:\n");
-       ((ua_data_t *) pbUserData)->ui_progress(pbUserData, uPercent);
-}
-
-/* Prints a string like the C printf() function */
-SS_UINT32 SS_Trace(const char *aFormat, ...)
-{
-#if 0
-       LOGL(LOG_SSENGINE, aFormat);
-#else
-       char temp[4096];
-       va_list list;
-
-       va_start(list, aFormat);
-       vsnprintf(temp, sizeof(temp), aFormat, list);
-       va_end(list);
-
-       LOGL(LOG_SSENGINE, "%s\n", temp);
-#endif
-       return S_SS_SUCCESS;
-}
-
-long SS_FSTrace(const unsigned short *aFormat, ...)
-{
-       va_list list;
-
-       va_start(list, aFormat);
-       vprintf((const char *)aFormat, list);
-       va_end(list);
-
-       return S_SS_SUCCESS;
-}
-
-long SS_ResetTimerA(void)
-{
-       //LOG("%s \n", __func__);
-
-       return S_SS_SUCCESS;
-}
-
-long SS_GetDelta(void *pbUserData, unsigned char *pbBuffer, SS_UINT32 dwStartAddressOffset, SS_UINT32 dwSize)
-{
-       int ret = S_SS_SUCCESS;
-       int readCount = 0;
-       FILE *fp;
-       long itemOffset = 0;
-
-       ua_data_t *ua_data = (ua_data_t *) pbUserData;
-       ua_part_info_t *ua_partition = ua_data->parti_info;
-       ua_update_data_t *ua_update_data = ua_data->update_data;
-
-       LOGL(LOG_SSENGINE, "SS_GetDelta offset 0x%x(%u), size 0x%x(%u)\n",
-                dwStartAddressOffset, dwStartAddressOffset, dwSize, dwSize);
-
-       itemOffset = tar_get_item_offset(ua_update_data->ua_delta_path, ua_partition->ua_subject_name);
-       if (itemOffset < 0)
-               return E_SS_OPENFILE_ONLYR;
-
-       fp = fopen(ua_update_data->ua_delta_path, "r");
-       if (!fp) {
-               LOGL(LOG_SSENGINE, "open file %s failed.\n", ua_update_data->ua_delta_path);
-               return E_SS_OPENFILE_ONLYR;
-       }
-
-       if (fseek(fp, itemOffset + dwStartAddressOffset, 0) == -1)
-               ret = E_SS_READ_ERROR;
-       else {
-               readCount = fread(pbBuffer, 1, dwSize, fp);
-               if (readCount != dwSize) {
-                       LOGL(LOG_SSENGINE, "error in read size\n");
-                       ret = E_SS_READ_ERROR;
-               }
-       }
-       fclose(fp);
-
-       return ret;
-}
-
-int SS_CalculateFileSha(char *filename, long int filesize, unsigned char calculated_sha1[SHA_DIGEST_SIZE])
-{
-
-       FILE *fp = NULL;
-       int ulResult = S_SS_SUCCESS;
-       long int chunk = 20*1024*1024;
-       char buf[256];
-       uint8_t *buffer = NULL;
-
-       fp = fopen(filename, "rb");
-       if (fp == NULL) {
-               strerror_r(errno, buf, sizeof(buf));
-               LOGE("failed to open \"%s\": %s\n", filename, buf);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       buffer = SS_Malloc(chunk);
-       if (!buffer) {
-               strerror_r(errno, buf, sizeof(buf));
-               LOGE("failed to allocate memory for \"%s\": %s\n", filename, buf);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       ssize_t bytes_read = 0;
-       SHA1_CTX sha_ctx;
-       SHA1Init(&sha_ctx);
-
-       while (filesize > 0) {
-               if (filesize < chunk) {
-                       bytes_read = fread(buffer, 1, filesize, fp);
-                       if (bytes_read != filesize) {
-                               LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, filesize);
-                               ulResult = E_SS_FAILURE;
-                               goto Cleanup;
-                       }
-                       SHA1Update(&sha_ctx, buffer, filesize);
-                       break;
-               } else {
-                       bytes_read = fread(buffer, 1, chunk, fp);
-                       if (bytes_read != chunk) {
-                               LOGE("short read of \"%s\" (%ld bytes of %ld)\n", filename, (long)bytes_read, filesize);
-                               ulResult = E_SS_FAILURE;
-                               goto Cleanup;
-                       }
-                       SHA1Update(&sha_ctx, buffer, chunk);
-                       filesize -= chunk;
-               }
-       }
-
-       SHA1Final(calculated_sha1, &sha_ctx);
-
-Cleanup:
-       if (fp)
-               fclose(fp);
-       if (buffer)
-               SS_Free(buffer);
-       return ulResult;
-}
-
 void hex_digest(char * sha1, char *buffer, int size)
 {
        for (int i = 0; i < size; i++) {
index 6e75a46..8a2caf1 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 
 #pragma once
 
-#include "SS_MultiProcessUpdate.h"
 #include "SS_FSUpdate.h"
-#include "SS_ImageUpdate.h"
 #include "SS_Engine_Errors.h"
-#include "SS_Engine_Update.h"
+typedef enum {
+       FT_REGULAR_FILE,
+       FT_SYMBOLIC_LINK,
+       FT_FOLDER,
+       FT_MISSING
+} enumFileType;
 
 #include "ua_types.h"
 
 #define MAX_PATH 256
 
-#define NAND_BLOCK_BITS 18       // 0x40000
-#define NAND_PAGE_BITS 12         // 0x1000
-
-#if defined(PART_W) || defined(PART_WB1) || defined(PART_W3G) || defined(PART_TINY) \
-       || defined(PART_HIGGS) || defined(PART_KIRAN) || defined(PART_KIRANLTE) || defined(PART_ORBIS)
-#define UA_RAM_SIZE            64*1024*1024    // it sould be same <RamSize>0x4000000</RamSize> in xml.
-#else
-#define UA_RAM_SIZE            512*1024*1024   // it sould be same <RamSize>0x20000000</RamSize> in xml.
-#endif
-
-#define FS_ID_MAX_LEN          4
-#define DP_HEADER_SIZE         36
-#define DP_START_OFFSET                0
-#define  BACKUPBUFFER_NUM      4
 #define SIZE_4GB (0Xffffffff)
 
-/*******[ Multiprocess API sample implementation ]******/
-#define _NOEXEC_
-#define SAMPLE_PROCS_NUM       (0)
-#define EXTRA_ARGS                     (3)
-#define HANDLE_RUN_PROC        "handle_run_process"
-
-struct status_header_page {
-       unsigned char preamble[5];  // state·Î »ç¿ëÇÒ ¼ö ÀÖÀ½, FOTA, SBLB, ZIMG, PLRM, MDEM, DONE, FAILµî
-       unsigned long format;      //ÃÖÁ¾ return °ª, ¾Æ·¡ °¢ image¿¡ ´ëÇÑ engineÀÇ return°ªÀ» DM error table·Î º¯°æµÈ °ª
-       unsigned long reserved;  // Not used
-       unsigned long flexStatus;   // Not used
-       unsigned long apfwStatus;   //zImage update¿¡ ´ëÇÑ engineÀÇ return °ª
-       unsigned long apffsStatus;  //platform update¿¡ ´ëÇÑengineÀÇreturn °ª
-       unsigned long apuaStatus;   //sbl update¿¡ ´ëÇÑengineÀÇreturn °ª
-       unsigned long bpfwStatus;   //modem update¿¡ ´ëÇÑengineÀÇreturn °ª
-       unsigned long bpuaStatus;
-};
-
 void SS_unicode_to_char(const char *src, char *dest, int size);
 
-#ifndef SHA_DIGEST_SIZE
-#define SHA_DIGEST_SIZE 20  // To avoid creating dependencies on sha1.h
-#endif
-int SS_CalculateFileSha(char *filename, long int filesize, unsigned char calculated_sha1[SHA_DIGEST_SIZE]);
 void hex_digest(char * sha1, char *buffer, int size);
index c9e2daa..2fa68e9 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #define E_SS_FSFAILEDTOPARSEDELTACNT                                   (0xA06) /* Failed to parse the PATCH count information */
 #define E_SS_FSFAILEDTOPARSEDELTAINFO                                  (0xA07) /* Failed to parse the Delta patch information */
 
-/* update package errors */
-#define  E_SS_PKG_TOO_LONG                                             (0xA08) /**< expected length error    */
-#define  E_SS_PKG_CORRUPTED                                            (0xA09) /**< structural error         */
-#define  E_SS_SOURCE_CORRUPTED                                         (0xA10) /**< signature error          */
-
 /*Delta Errors*/
-
-#define E_SS_FSBADPATCH                                                        (0xB00) /*File Patch Does NOT match the signature */
-#define E_SS_FSSHA_MISMATCH                                            (0xB01) /*Could NOT produce expected Target SHA for file */
-#define E_SS_IMGBADDELTA                                               (0xB02) /* Failed to parse attribute data */
-#define E_SS_IMGBADPATCH                                               (0xB03) /*Image Patch Does NOT match the signature */
-#define E_SS_IMGSHA_MISMATCH                                           (0xB04) /*Could NOT produce expected Target SHA for Image */
-#define E_SS_SHAPRASE_FAILED                                           (0xB05) /*Could NOT Parse SHA */
-
-/* SYSTEM errors */
+#define E_SS_FSSHA_MISMATCH                                            (0xB00) /*Could NOT produce expected Target SHA for file */
 
 /* Resources errors */
-#define  E_SS_NOT_ENOUGH_RAM                                           (0xC00) /**< given RAM is not enough  */
-#define  E_SS_BAD_RAM                                                  (0xC01) /**< does not behave as RAM   */
-#define  E_SS_MALLOC_ERROR                                             (0xC02) /**< memory allocation failure */
+#define  E_SS_MALLOC_ERROR                                             (0xC00) /**< memory allocation failure */
 
 /* Image update Error codes */
-#define  E_SS_WRITE_ERROR                                              (0xC03) /**< flash writing failure    */
-#define  E_SS_ERASE_ERROR                                              (0xC04) /**< flash erasing failure    */
-#define  E_SS_READ_ERROR                                               (0xC05) /**< flash reading failure    */
+#define  E_SS_WRITE_ERROR                                              (0xC01) /**< flash writing failure    */
+#define  E_SS_READ_ERROR                                               (0xC02) /**< flash reading failure    */
 
 /*File System Error codes */
-#define  E_SS_OPENFILE_ONLYR                                           (0xC06)         /**< file does not exist      */
-#define  E_SS_OPENFILE_WRITE                                           (0xC07)         /**< RO or no access rights   */
-#define  E_SS_DELETEFILE_NOFILE                                                (0xC08) /**< file does not exist      */
-#define  E_SS_DELETEFILE                                               (0xC09) /**< no access rights         */
-#define  E_SS_RESIZEFILE                                               (0xC10) /**< cannot resize file       */
-#define  E_SS_READFILE_SIZE                                            (0xC11) /**< cannot read specified size*/
-#define  E_SS_CLOSEFILE_ERROR                                          (0xC12) /**< cannot close file handle */
-#define  E_SS_FAILED_CREATING_SYMBOLIC_LINK                            (0xC13)         /**< Failed creating symbolic link */
-#define  E_SS_CANNOT_CREATE_DIRECTORY                                  (0xC14)         /**< Failed creating directory */
-#define  E_SS_FSMEMORYERROR                                            (0xC15) /* Failed to allocate Memory */
-#define  E_SS_FILENAMELENERROR                                         (0xC16) /* Failed to serve filename length */
+#define  E_SS_OPENFILE_ONLYR                                           (0xC03)         /**< file does not exist      */
+#define  E_SS_OPENFILE_WRITE                                           (0xC04)         /**< RO or no access rights   */
+#define  E_SS_DELETEFILE                                               (0xC05) /**< no access rights         */
+#define  E_SS_READFILE_SIZE                                            (0xC06) /**< cannot read specified size*/
+#define  E_SS_CLOSEFILE_ERROR                                          (0xC07) /**< cannot close file handle */
+#define  E_SS_CANNOT_CREATE_DIRECTORY                                  (0xC08)         /**< Failed creating directory */
+#define  E_SS_FSMEMORYERROR                                            (0xC09) /* Failed to allocate Memory */
+#define  E_SS_FILENAMELENERROR                                         (0xC10) /* Failed to serve filename length */
 
 /*Engine errors */
-
-#define E_SS_NOT_ENOUGH_RAM_FOR_OPERATION2                             (0xD00) /**< There is not enough RAM to run with operation=2 (Dry update) */
-#define E_SS_DELTA_FILE_TOO_LONG                                       (0xD01) /**< Delta file too long - curropted */
-#define E_SS_ERROR_IN_DELETES_SIG                                      (0xD02) /**< Mismatch between deletes sig and delta deletes buffers signature */
-#define E_SS_DELTA_IS_CORRUPT                                          (0xD03) /**< Delta file is corrupt: signature mismatch between delta header signature and calculated signature */
-#define E_SS_SOURCE_FILE_SIG_MISMATCH                                  (0xD04) /**< File signature does not match signature */
-#define E_SS_TARGET_SIG_MISMATCH                                       (0xD05) /**< Signature for the target buffer does not match the one stored in the delta file */
-#define E_SS_INVALID_BACKUP                                            (0xD06) /**< Too many dirty buffers */
-#define E_SS_UPI_VERSION_MISMATCH                                      (0xD07) /**< UPI version mismatch between UPI and delta */
-#define E_SS_PARTITION_NAME_NOT_FOUND                                  (0xD08) /**< Partition name is different in delta and in UPI data */
-#define E_SS_NO_SPACE_LEFT                                             (0xD09) /**< There is not enough flash to update or install the files */
-#define E_SS_INVALID_DP_HEADER                                         (0xD10)  /**< Deployment Package header is invalid */
-#define E_SS_INVALID_DP_WRONG_SIGNATURE                                        (0xD11)  /**< Deployment Package signature is invalid */
-#define E_SS_FSFAILEDTOBACKUPPATCHINFO                                 (0xD12) /* Failed to create backup file to write Delta patch info data */
-#define E_SS_FSUPDATEFAILED                                            (0xD13) /*FS Failed during UPGRADE */
-#define E_SS_FSSRCBACKUPFAILED                                         (0xD14) /*Failed to backup FS */
-#define E_SS_FSSRCCURRUPTED                                            (0xD15) /*Could NOT update FS as SRC seems to be corrupted */
-#define E_SS_IMGUPDATEFAILED                                           (0xD16) /*IMG Failed during UPGRADE */
-#define E_SS_IMGSRCBACKUPFAILED                                                (0xD17) /*Failed to backup IMG */
-#define E_SS_IMGRECOVERYWRITEFAILED                                    (0xD18) /*Failed to write patched Recovery IMG */
-#define E_SS_IMGSRCCURRUPTED                                           (0xD19) /*Could NOT update IMG as SRC seems to be corrupted */
-#define E_SS_IMGFLASHWRITEFAIL                                         (0xD20) /*Failed to write Patched IMG data to flash */
-#define E_SS_PATCHFILE_DEL_ERROR                                       (0xD21) /*Failed to Clear/Del Patched SRC file */
+#define E_SS_FSFAILEDTOBACKUPPATCHINFO                                 (0xD00) /* Failed to create backup file to write Delta patch info data */
+#define E_SS_FSUPDATEFAILED                                            (0xD01) /*FS Failed during UPGRADE */
+#define E_SS_FSSRCBACKUPFAILED                                         (0xD02) /*Failed to backup FS */
+#define E_SS_FSSRCCURRUPTED                                            (0xD03) /*Could NOT update FS as SRC seems to be corrupted */
+#define E_SS_PATCHFILE_DEL_ERROR     (0xD04) /*Failed to Clear/Del Patched SRC file */
 
 #endif
index 8f382fd..d8d031f 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -227,24 +227,6 @@ long SS_DeleteFolder(const char *strPath)
        return ((long)nftw(strPath, SS_unlink_cbf, 64, FTW_DEPTH | FTW_PHYS) == 0) ? S_SS_SUCCESS : E_SS_FAILURE;
 }
 
-long SS_DeleteFolderEmpty(const char *strPath)
-{
-
-       int ret = 0;
-       char path[MAX_PATH] = { '\0' };
-
-       SS_unicode_to_char((const char *)strPath, (char *)path, MAX_PATH - 1);
-       //LOGL(LOG_SSENGINE, "%s\n", path);
-       ret = rmdir(path);
-       if ((ret == 0)
-           || ((ret < 0) && ((errno == ENOENT) || (errno == ENOTEMPTY)))) {
-               LOGL(LOG_SSENGINE, "rmdir value: %d, errno: %d\n", ret, errno);
-               return S_SS_SUCCESS;
-       }
-       LOGE("rmdir value: %d, errno: %d\n", ret, errno);
-       return E_SS_FAILURE;
-}
-
 long SS_CreateFolder(const char *strPath)
 {
        mode_t mode = 0;
@@ -373,22 +355,6 @@ SS_OpenFile(const char *strPath, E_RW_TYPE wFlag, long *pwHandle)
        return S_SS_SUCCESS;
 }
 
-long SS_ResizeFile(long wHandle, SS_UINT32 dwSize)
-{
-       int ret = 0;
-
-       LOGL(LOG_SSENGINE, "handle %ld, dwSize %d\n", wHandle, errno);
-
-       if (wHandle)
-               ret = ftruncate(wHandle, dwSize);
-       else
-               ret = E_SS_RESIZEFILE;
-
-       LOGL(LOG_SSENGINE, "ret %d handle %ld %d\n", ret, wHandle, errno);
-
-       return ret;
-}
-
 long SS_CloseFile(long wHandle)
 {
        int ret = 0;
@@ -491,10 +457,6 @@ long SS_MoveFile(const char *strFromPath, const char *strToPath)
        LOGL(LOG_INFO, "leaved path1:%s | path2:%s\n", path1, path2);
        return S_SS_SUCCESS;
 }
-long SS_SyncFile(long wHandle)
-{
-       return (-1 == fsync(wHandle)) ? E_SS_FAILURE : S_SS_SUCCESS;
-}
 
 long
 SS_ReadFile(long wHandle,
@@ -638,6 +600,24 @@ SS_Link(void *pbUserData, char *pLinkName, char *pReferenceFileName)
        return S_SS_SUCCESS;
 }
 
+long
+SS_HardLink(char *hardLinkName, char *referenceName)
+{
+       int ret = 0;
+       char hardpath[MAX_PATH] = { '\0' };
+       char refpath[MAX_PATH] = { '\0' };
+
+       SS_unicode_to_char((const char *)hardLinkName, (char *)hardpath, MAX_PATH - 1);
+       SS_unicode_to_char((const char *)referenceName, (char *)refpath, MAX_PATH - 1);
+
+       ret = link(refpath, hardpath);
+       if (ret != 0) {
+               LOGE("Linking failed for hardlink %s with errno: %d\n", hardpath, errno);
+               return E_SS_FAILURE;
+       }
+       return S_SS_SUCCESS;
+}
+
 long SS_GetFileType(char *pLinkName, enumFileType * fileType)
 {
        int ret = 0;
@@ -682,94 +662,6 @@ long SS_GetFileType(char *pLinkName, enumFileType * fileType)
        return E_SS_FAILURE;
 }
 
-char SS_a2ch(int value)
-{
-       char set_value = 0;
-
-       LOGL(LOG_SSENGINE, "%d\n", value);
-
-       switch (value) {
-       case '1':
-               set_value = 0x01;
-               break;
-       case '2':
-               set_value = 0x02;
-               break;
-       case '3':
-               set_value = 0x03;
-               break;
-       case '4':
-               set_value = 0x04;
-               break;
-       case '5':
-               set_value = 0x05;
-               break;
-       case '6':
-               set_value = 0x06;
-               break;
-       case '7':
-               set_value = 0x07;
-               break;
-       case '8':
-               set_value = 0x08;
-               break;
-       case '9':
-               set_value = 0x09;
-               break;
-       case '0':
-               set_value = 0x00;
-               break;
-       default:
-               LOGL(LOG_SSENGINE, "Wrong attribute value: %d\n", value);
-
-       }
-       LOGL(LOG_SSENGINE, "SS_a2ch : %c\n", set_value);
-
-       return set_value;
-}
-
-void SS_chtoa(int value, char *str)
-{
-       char *pStr = str;
-
-       LOGL(LOG_SSENGINE, "%d\n", value);
-
-       switch (value) {
-       case 1:
-               *pStr = '1';
-               break;
-       case 2:
-               *pStr = '2';
-               break;
-       case 3:
-               *pStr = '3';
-               break;
-       case 4:
-               *pStr = '4';
-               break;
-       case 5:
-               *pStr = '5';
-               break;
-       case 6:
-               *pStr = '6';
-               break;
-       case 7:
-               *pStr = '7';
-               break;
-       case 8:
-               *pStr = '8';
-               break;
-       case 9:
-               *pStr = '9';
-               break;
-       case 0:
-               *pStr = '0';
-               break;
-       default:
-               LOGL(LOG_SSENGINE, "Wrong attribute value: %d\n", value);
-       }
-}
-
 static inline char *SS_get_xattr_name(enum smack_label_type type)
 {
        switch (type) {
@@ -1138,27 +1030,11 @@ long SS_SetFileAttributes(const char *ui16pFilePath,
        return S_SS_SUCCESS;
 }
 
-
-long SS_CompareFileAttributes(void)
-{
-       return S_SS_SUCCESS;
-}
-
-
-
-#define MAX_INT 0xefffffff
-
 /* vrm functions */
 long
 SS_GetAvailableFreeSpace(const char *partition_name,
                         SS_UINT32 *available_flash_size)
 {
-//     *available_flash_size = MAX_INT;
-/*
-#define IDENT_SBL          "sbl"
-#define IDENT_PLATFORM     "platform"
-#define IDENT_BOOT     "boot"
-*/
        int result = 0;
        char path[MAX_PATH] = { '\0' };
 
@@ -1214,95 +1090,6 @@ void SS_Free(void *pMemBlock)
        if (pMemBlock)
                free(pMemBlock);
 }
-
-SS_UINT32 SS_GetMaxNumProcess(void)
-{
-       return SAMPLE_PROCS_NUM;
-}
-
-void* SS_WaitForProcess(const void *handle, SS_UINT32* process_exit_code)
-{
-       pid_t pid;
-       *process_exit_code = 0;
-
-       // processes
-       if (handle)
-               #ifdef _NOEXEC_
-               pid = waitpid((pid_t)handle, (int *)process_exit_code, 0);
-               #else
-               pid = wait((int*)process_exit_code);
-               #endif
-
-       else
-               pid = wait((int*)process_exit_code);
-
-       if (pid < 0)
-               return NULL;
-
-       if (!WIFEXITED(*process_exit_code)) {
-               *process_exit_code = (char)WTERMSIG(*process_exit_code);
-               LOG("Wait Error\n");
-       } else {
-               *process_exit_code = (char)WEXITSTATUS(*process_exit_code);
-       }
-
-       return (void*)pid;
-}
-unsigned long SS_GetMaxProcRamSize(void)
-{
-       return UA_RAM_SIZE;
-}
-
-void* SS_RunProcess(void)
-{
-       pid_t child_pid;
-
-       #ifdef _NOEXEC_
-       child_pid = fork();
-       #else
-       child_pid = vfork();
-       #endif
-
-       if (child_pid == -1) {
-               LOG("Fork failed.\n");
-               return (void *)-1;
-       }
-
-       // This is the child
-       if (child_pid == 0) {
-               #ifdef _NOEXEC_
-               #ifdef _TIZEN_SSENGINE//bota
-               SS_HandleProcessRequest(pbUserData, argc, argv);
-               #endif
-               LOGL(LOG_SSENGINE, "SS_RunProcess was called - SS_HandleProcessRequest\n");
-               exit(0);
-               #else
-
-               char **params = NULL;
-               int i;
-
-               params = (char **)SS_Malloc((argc+EXTRA_ARGS) *sizeof(char*));
-               if (!params) {
-                       LOG("params allocation failed\n");
-                       return NULL;
-               }
-               // prepare child data, as it's forbidden to change data after vfork
-               params[0] = strdup(((sample_userdata*)user)->exec_path);
-               params[1] = strdup("handle_run_process");
-               params[2] = strdup(((sample_userdata*)user)->delta_path);
-
-               for (i = 0; i < argc; i++)
-                       params[i+EXTRA_ARGS] = strdup(argv[i]);
-
-               // no need to free allocated memory - execv takes care of it
-               execv(params[0], (char**)params);
-               _exit(-1); // if we're here, execv has failed
-               #endif
-       } else {
-               return (void *)child_pid;
-       }
-}
-
 int SS_get_feature_support_capability(void)
 {
        return feature_support_capability;
@@ -1311,4 +1098,4 @@ int SS_get_feature_support_capability(void)
 void SS_set_feature_support_capability(int val)
 {
        feature_support_capability = val;
-}
+}
\ No newline at end of file
index 0cc839b..668bf61 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -26,8 +26,8 @@
 #ifndef _SS_FILESYSTEM_UPDATE_H_
 #define _SS_FILESYSTEM_UPDATE_H_
 
-#include "SS_Engine_Update.h"
 #include "SS_Engine_Errors.h"
+#include "ua_types.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -41,7 +41,6 @@ extern "C" {
                ONLY_W,                 //!< Write-only
                BOTH_RW                 //!< Read-write
        } E_RW_TYPE;
-
 /*!
  *******************************************************************************
  * Copy file.<p>
@@ -138,19 +137,6 @@ extern "C" {
 
 /*!
  *******************************************************************************
- * Set file size.
- *
- * \param      wHandle         File handle
- * \param      dwSize          New file size
- *
- * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
- *******************************************************************************
- */
-
-       long SS_ResizeFile(long wHandle, SS_UINT32 dwSize);
-
-/*!
- *******************************************************************************
  * Close file.
  *
  * \param      wHandle         File handle
@@ -181,19 +167,6 @@ extern "C" {
 
 /*!
  *******************************************************************************
- * Commit file to storage.<p>
- *
- * Generally called after \ref SS_WriteFile.
- *
- * \param      wHandle         File handle
- *
- * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
- *******************************************************************************
- */
-       long SS_SyncFile(long wHandle);
-
-/*!
- *******************************************************************************
  * Read data from a specified position within a file.
  * If fewer bytes than requested are available in the specified position, this
  * function should read up to the end of file and return S_SS_SUCCESS.
@@ -295,23 +268,6 @@ extern "C" {
        long SS_SetFileAttributes(const char *ui16pFilePath,
                        const SS_UINT32 ui32AttribSize, const unsigned char *ui8pAttribs);
 
-/*!
- *******************************************************************************
- * Print status and debug information.
- *
- * \param      aFormat         A NULL-terminated printf-like string with support for
- *                                             the following tags:
- *                                             \li %x:  Hex number
- *                                             \li %0x: Hex number with leading zeros
- *                                             \li %u:  Unsigned decimal
- *                                             \li %s:  NULL-terminated string
- * \param      ...                     Strings to insert in \a aFormat
- *
- * \return     S_SS_SUCCESS on success or an \ref SS_vRM_Errors.h error code
- *******************************************************************************
- */
-       SS_UINT32 SS_Trace(const char *aFormat, ...);
-
 /**
  *******************************************************************************
  * Allocate a memory block.
@@ -331,7 +287,6 @@ extern "C" {
  *******************************************************************************
  */
        void SS_Free(void *pMemBlock);
-
 /**
  *******************************************************************************
  * Get capability feature flag value
@@ -350,6 +305,19 @@ extern "C" {
  */
        void SS_set_feature_support_capability(int val);
 
+/**
+ *******************************************************************************
+ * Create a hardlink to a file
+ *
+ * \param      hardLinkName    Name of the hardlink to be created
+ * \param      referenceName   Name of the file that we link to
+ * 
+ * \return     S_SS_SUCCESS on success, E_SS_FAILURE otherwise
+ *******************************************************************************
+ */
+
+       long SS_HardLink(char *hardLinkName, char *referenceName);
+    
 #ifdef __cplusplus
 }
 #endif                          /* __cplusplus */
index dd292ee..9c87579 100755 (executable)
 #include <sys/types.h>
 #include <fcntl.h>
 #include <unistd.h>
-#include "ua_types.h"
-#include "sha1.h"
+#include "../../upgrade-apply/sha1/sha1.h"
 #include "SS_PatchDelta.h"
 #include "fota_common.h"
 #include "SS_Engine_Errors.h"
-#include "ss_brotli_patch.h"
 #include "SS_Common.h"
 
 extern void *SS_Malloc(unsigned int size);
@@ -42,16 +40,6 @@ typedef struct {
        ssize_t pos;
 } MemorySinkInfo;
 
-ssize_t ss_memorySink(unsigned char *data, ssize_t len, void *token)
-{
-       MemorySinkInfo *msi = (MemorySinkInfo *) token;
-       if (msi->size - msi->pos < len)
-               return -1;
-       memcpy(msi->buffer + msi->pos, data, len);
-       msi->pos += len;
-       return len;
-}
-
 ssize_t ss_fileSink(unsigned char *data, ssize_t len, void *token)
 {
        int ss_fd = *(int *)token;
@@ -103,75 +91,6 @@ int ParseSha1(const char *str, uint8_t * digest)
        return 0;
 }
 
-//Function to find the start of gzipped part in compressed kernel
-//This function will be removed during further optimization of kernel delta
-int getOffset(char *zimage_path)
-{
-       char gzip_header[] = { 31, -117, 8 };      //header value for gzip which needs to be checked
-       char buf[4] = { 0, };
-       int offset = -1;//wgid:14074
-
-       FILE *f = fopen(zimage_path, "r");
-       if (!f) {
-               LOGE("Fopen failed for path %s\n", zimage_path);
-               SS_SetUpgradeState(E_SS_OPENFILE_ONLYR);
-               return -1;
-       }
-       fseek(f, 0, SEEK_SET);
-       while (fread(buf, 1, 3, f) > 0) {
-               if (gzip_header[0] == buf[0] && gzip_header[1] == buf[1] && gzip_header[2] == buf[2]) {
-                       LOGL(LOG_SSENGINE, "match for %d %d %d found at %d\n", buf[0], buf[1], buf[2], ftell(f) - 3);
-                       offset = ftell(f) - 3;//145599
-                       break;
-               } else {
-                       if (fseek(f, -2, SEEK_CUR) < 0)
-                               LOGE("Failed to fseek\n");
-               }
-       }
-       fclose(f);
-       return offset;
-}
-
-int SS_LoadPartition(const char *filename, FileInfo * file)
-{
-       size_t read = 0;
-       FILE *dev = NULL;
-       int i;
-       char buf[256];
-
-       dev = fopen(filename, "rb");
-       if (dev == NULL) {
-               strerror_r(errno, buf, sizeof(buf));
-               LOGE("failed to open partition \"%s\": %s\n", filename, buf);
-               return -1;
-       }
-
-       SHA1_CTX sha_ctx;
-       SHA1Init(&sha_ctx);
-
-       file->data = SS_Malloc(file->size);
-       if (file->data) {
-               read = fread(file->data, 1, file->size, dev);
-               LOGL(LOG_SSENGINE, "Partition size read %d\n", read);
-               SHA1Update(&sha_ctx, file->data, read);
-               file->size = read;
-       }
-
-       unsigned char sha_final[SHA_DIGEST_SIZE] = { 0, };
-       SHA1Final(sha_final, &sha_ctx);
-       for (i = 0; i < SHA_DIGEST_SIZE; ++i)
-               file->sha1[i] = sha_final[i];
-       //LOGL(LOG_SSENGINE, "Final SHA of Source (%s)\n", sha_final);
-
-       file->st.st_mode = 0644;
-       file->st.st_uid = 0;
-       file->st.st_gid = 0;
-       fclose(dev);
-       return 0;
-}
-
-//extern int write_data_to_blkdev(char* dev_name, int blk_start, int blk_cnt, char* data);
-
 int SS_LoadFile(const char *filename, FileInfo * file)
 {
        char buf[256];
@@ -237,8 +156,11 @@ extern void create_dir(char *pathname, int mode);
  */
 
 int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
-                                        const char *source_sha1_str, const char *target_sha1_str, int patch_data_size)
+                                        const char *source_sha1_str, const char *target_sha1_str, int patch_data_size, char *delta_folder)
 {
+       char backup_path[MAX_FILE_PATH], patchfile_source_path[MAX_FILE_PATH];
+       snprintf(backup_path, MAX_FILE_PATH, "%s/%s", delta_folder, SS_BACKUP_SOURCE);
+       snprintf(patchfile_source_path, MAX_FILE_PATH, "%s/%s", delta_folder, SS_PATCHFILE_SOURCE);
        uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
        uint8_t source_sha1[SHA_DIGEST_SIZE] = { 0, };
        SHA1_CTX ctx1;
@@ -287,11 +209,11 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
                                        }
                                }
 
-                               if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
+                               if (SS_LoadFile(backup_path, &source_file) == 0) {
                                        SS_Free(source_file.data);
 
                                        if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                                               if (SS_CopyFile(SS_BACKUP_SOURCE, source_filename) != S_SS_SUCCESS) {
+                                               if (SS_CopyFile(backup_path, source_filename) != S_SS_SUCCESS) {
                                                        strerror_r(errno, buf, sizeof(buf));
                                                        LOGE("copy of backup to \"%s\" failed: %s\n", source_filename, buf);
                                                        SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
@@ -320,7 +242,7 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
                        }
 
                        LOGL(LOG_SSENGINE, "Try loading from backup source\n");
-                       if (SS_LoadFile(SS_BACKUP_SOURCE, &source_file) == 0) {
+                       if (SS_LoadFile(backup_path, &source_file) == 0) {
                                SS_Free(source_file.data);
 
                                if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
@@ -357,7 +279,7 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
 
                if (!use_backup) {
 #ifndef ENHANCED_BSDIFF
-                       backupsrc = SS_BackupSource(source_filename);
+                       backupsrc = SS_BackupSource(source_filename, backup_path);
                        if (backupsrc != 0) {
                                LOGE("failed to Backup source File:[%s] \n", source_filename);
                                SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
@@ -415,9 +337,9 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
                }
                SHA1Init(&ctx1);
                if (use_backup)
-                       result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+                       result = SS_ApplyBsdiff(backup_path, outname, patchfile_source_path, sink, token, &ctx1);
                else
-                       result = SS_ApplyBsdiff((char *)source_filename, outname, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
+                       result = SS_ApplyBsdiff((char *)source_filename, outname, patchfile_source_path, sink, token, &ctx1);
                if (output >= 0) {
                        fsync(output);
                        close(output);
@@ -471,571 +393,10 @@ int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
        //remove source file if target is not same
        if (strcmp(source_filename, target_filename) != 0)
                unlink(source_filename);
-       SS_BackupSourceClear();
+       SS_BackupSourceClear(backup_path);
 #endif
-       SS_PatchSourceClear();
+       SS_PatchSourceClear(patchfile_source_path);
        SS_Free(outname);
 
        return result;
-}
-
-/*!
- *********************************************************************************
- *                                      SS_UpdateDeltaKernel
- *********************************************************************************
- *
- * @brief
- *     This is used to apply patch for kernel delta during delta Image upgrade
- *
- *
- *     @param
- *
- *     @return                         0 - in case of success
- *                                             1 - in case of error during patch application
- *
- *********************************************************************************
- */
-
-int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *))
-{
-       uint8_t target_sha1[SHA_DIGEST_SIZE];
-       uint8_t source_sha1[SHA_DIGEST_SIZE];
-       FileInfo source_file;
-       int result = S_SS_SUCCESS;
-       int blk_cnt, read_count = 0;
-       int blk_start = 0;
-       int backupsrc = -1;
-       int use_backup_img = -1;
-       FILE *fp = NULL, *wp = NULL, *kp = NULL;
-       int i = 0, j = 0, file_len = 0;
-       char *magic = NULL, *file_name = NULL, *tok_buf = NULL, *buf = NULL, a = '0';
-       char *saveptr;
-       char err_buf[256];
-       char cmd[1024] = { 0, };
-       char source_filename[MAX_FILE_PATH] = { 0, };
-       char part_filename[MAX_FILE_PATH] = { 0, };
-       int file_num = 0;
-       SinkFn sink = NULL;
-       void *tok = NULL;
-       int output = -1;
-       char *outname = NULL;
-       //Kernel Parts are created on unpacking kernel which is then used to apply delta
-       char *kernel_parts[] = { "decompression_code",
-               "piggy.gz",
-               "padding_piggy",
-               "piggy_trailer"
-       };
-
-       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-               return E_SS_FAILURE;
-       }
-
-       source_file.size = ua_dataSS->update_cfg->soure_img_size;
-       source_file.data = NULL;
-       if (0 == gvalid_session) {
-
-               if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-                       LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-                       return E_SS_FAILURE;
-               }
-
-               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
-                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
-
-                       } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
-                               SS_Free(source_file.data);
-                               return S_SS_SUCCESS;
-                       } else {
-                               SS_Free(source_file.data);
-                               source_file.data = NULL;
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
-                               if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
-                                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                                               use_backup_img = 1;
-
-                                               LOGL(LOG_SSENGINE,
-                                                        "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
-                                       } else {
-                                               SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-                                               SS_Free(source_file.data);
-                                               return E_SS_FAILURE;
-                                       }
-                               }
-                       }
-               }
-       } else {                                        //in case of kernel delta need to copy kernel data  from blk to buffer
-               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) != 0) {
-                       SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-                       LOGE("Fatal Error : Kernel block is corrupted\n");
-                       return E_SS_FAILURE;
-               }
-       }
-       if (use_backup_img == -1) {
-               backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
-               if (backupsrc != 0) {
-                       LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
-                       SS_Free(source_file.data);
-                       SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
-                       return E_SS_FAILURE;
-               }
-       }
-       //Cleanup workspace and copy helper executables to it before proceeding
-       SS_DeleteFolder(SS_KERNEL_WORKSPACE);
-       create_dir(SS_KERNEL_WORKSPACE, 0755);
-       SS_CopyFile(SS_GZIP_SOURCE, SS_GZIP_TARGET);
-       SS_CopyFile(SS_STAT_SOURCE, SS_STAT_TARGET);
-       SS_CopyFile(SS_DD_SOURCE, SS_DD_TARGET);
-
-       if (tar_get_item_size(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT) > 0)
-               if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, SS_KERNEL_UNPACK_SCRIPT, SS_KERN_UNPK_SCRIPT_PATH) > 0)
-                       LOGL(LOG_SSENGINE, "Extracted %s successfully\n", SS_KERNEL_UNPACK_SCRIPT);
-               else {
-                       LOGE("Error in fn tar_extract_file for item %s\n", SS_KERNEL_UNPACK_SCRIPT);
-                       SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-                       result = E_SS_FAILURE;
-                       goto Cleanup;
-       } else {
-               LOGE("Error size is not positive for item %s\n", SS_KERNEL_UNPACK_SCRIPT);
-               SS_SetUpgradeState(E_SS_DELTA_IS_CORRUPT);
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       //Now write the kernel data to the workplace and start applying patch
-       snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME);
-       fp = fopen(source_filename, "w");
-       if (!fp) {
-               LOGE("file open error [%s] code [%d]\n", source_filename, errno);
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       //write source kernel data to workspace
-       if (!source_file.data) {
-               LOGE("source_file.data is null before fwrite");
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       read_count = fwrite(source_file.data, 1, source_file.size, fp);
-       if (read_count != source_file.size) {
-               LOGE("file write error read_count = %d for [%s]\n", read_count, source_filename);
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       fclose(fp);
-       fp = NULL;//wgid: 59313
-
-       //Unpack source kernel
-       int offset = getOffset(source_filename);
-       if (offset < 0) {
-               LOGE("Failed to get offset\n");
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       snprintf(cmd, sizeof(cmd) - 1, "%s -u %s %s %d", SS_KERN_UNPK_SCRIPT_PATH, SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
-                        offset);
-       int ret = _system_cmd_wait(cmd);
-       LOGL(LOG_SSENGINE, "ret for %s is %d\n", cmd, ret);
-
-       //open delta file, extract kernel delta parts and apply patch to previously unpacked kernel
-       fp = fopen(SS_PATCHFILE_SOURCE, "r");
-       if (fp == NULL) {
-               LOGE("Failed to open kernel delta patch\n");
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       //read kernel delta header for  delta names and size
-       buf = SS_Malloc(SS_KERNEL_DELTA_HEADER + 1);
-       if (!buf) {//wgid: 13099
-               LOGE("Failed to allocate memory\n");
-               result = E_SS_MALLOC_ERROR;
-               goto Cleanup;
-       }
-       ssize_t bytes_read = fread(buf, 1, SS_KERNEL_DELTA_HEADER, fp);
-       if (bytes_read != SS_KERNEL_DELTA_HEADER)
-               LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)SS_KERNEL_DELTA_HEADER);
-       buf[bytes_read] = '\0';
-
-       magic = strtok_r(buf, ":", &saveptr);
-       LOGL(LOG_SSENGINE, "magic: %s\n", magic);
-       tok_buf = strtok_r(NULL, ":", &saveptr);
-       if (tok_buf)
-               file_num = atoi(tok_buf);
-
-       //adjust offset to start of data section before proceeding
-       ret = fseek(fp, SS_KERNEL_DELTA_HEADER, SEEK_SET);
-       if (ret != 0) {
-               LOGE("fseek is failed : errno[%d]\n", ret);
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       while (file_num-- > 0) {
-               file_name = strtok_r(NULL, ":", &saveptr);
-               tok_buf = strtok_r(NULL, ":", &saveptr);
-               if (tok_buf)
-                       file_len = atoi(tok_buf);
-               j = file_len;
-               snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s_unpacked/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_NAME,
-                                file_name);
-               snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, file_name);
-               wp = fopen(part_filename, "w");
-               if (wp == NULL) {
-                       LOGE("Failed to open %s\n", part_filename);
-                       result = E_SS_FAILURE;
-                       goto Cleanup;
-               }
-               while (j-- > 0) {
-                       a = fgetc(fp);
-                       fputc(a, wp);
-               }
-               fclose(wp);
-
-               //apply bspatch to the unpacked kernel parts
-
-               {
-                       // We write the decoded output to "<tgt-file>.patch".
-                       //allocate some extra space to allow for concatinating ".patch" with the name
-                       outname = (char *)SS_Malloc(strlen(source_filename) + 10);
-                       if (outname == NULL) {
-                               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-                               result = E_SS_FAILURE;
-                               goto Cleanup;
-                       }
-                       snprintf(outname, strlen(source_filename) + 10, "%s.patch",
-                                       source_filename);
-
-                       output = open(outname, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-                       if (output < 0) {
-                               strerror_r(errno, err_buf, sizeof(err_buf));
-                               LOGE("failed to open output file %s: %s\n", outname, err_buf);
-                               result = E_SS_FAILURE;
-                               goto Cleanup;
-                       }
-                       sink = ss_fileSink;
-                       tok = &output;
-               }
-               result = SS_ApplyBsdiff(source_filename, outname, part_filename, sink, tok, NULL);
-               LOGL(LOG_SSENGINE, "GenerateTarget Output is %d and result is %d\n", output, result);
-               if (output >= 0) {
-                       fsync(output);
-                       close(output);
-               }
-
-               if (result != S_SS_SUCCESS) {
-                       LOGE("applying patch failed %s\n", source_filename);
-                       if (outname != NULL)
-                               unlink(outname);
-                       goto Cleanup;
-               }
-               result = rename(outname, source_filename);
-               if (result != S_SS_SUCCESS) {
-                       LOGE("fatal error %s\n", source_filename);
-                       goto Cleanup;
-               }
-               if (file_name && strcmp(file_name, "piggy") == 0) {
-                       snprintf(cmd, sizeof(cmd) - 1,
-                                        "%s/gzip -n -9 -c %s/%s/%s > %s/%s/%s.gz",
-                                        SS_KERNEL_WORKSPACE, SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name,
-                                        SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR, file_name);
-                       result = _system_cmd_wait(cmd);
-                       LOGL(LOG_SSENGINE, "ret for %s = %d\n", cmd, result);
-                       unlink(source_filename);
-               }
-               unlink(part_filename);
-               SS_Free(outname);//wgid :144116
-               outname = NULL;
-       }
-       //open new kernel file and append kernel parts to it in
-       snprintf(source_filename, sizeof(source_filename) - 1, "%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_TARGET_NAME);
-       kp = fopen(source_filename, "w");
-       if (kp == NULL) {
-               LOGE("Failed to open %s\n", source_filename);
-               result = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       for (i = 0; i < 4; i++) {
-               snprintf(part_filename, sizeof(part_filename) - 1, "%s/%s/%s", SS_KERNEL_WORKSPACE, SS_KERNEL_UNPACK_DIR,
-                                kernel_parts[i]);
-               wp = fopen(part_filename, "r");
-               if (wp == NULL) {
-                       LOGE("Failed to open %s\n", part_filename);
-                       result = E_SS_FAILURE;
-                       fclose(kp);
-                       goto Cleanup;
-               }
-               fseek(wp, SEEK_SET, SEEK_END);
-               j = ftell(wp);
-               fseek(wp, SEEK_SET, SEEK_SET);
-               while (j-- > 0) {
-                       a = fgetc(wp);
-                       if (a != EOF)
-                               fputc(a, kp);
-                       else
-                               break;
-               }
-               fclose(wp);
-               unlink(part_filename);
-       }
-       fclose(fp);
-       fp = NULL;
-       fclose(kp);
-
-       SS_Free(source_file.data);
-       source_file.data = NULL;
-       if (SS_LoadFile(source_filename, &source_file) == 0)
-               result = memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE);
-       if (result != S_SS_SUCCESS) {
-               LOGE("patch did not produce expected sha1 \n");
-               SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
-               goto Cleanup;
-       }
-       //Considering EMMC partition by default
-
-       blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
-       result = write_to_blkdev((char *)ua_dataSS->parti_info->ua_blk_name, blk_start, blk_cnt, (char *)source_file.data);
-       if (result != S_SS_SUCCESS) {
-               LOGE("write of patched data to %s failed\n", ua_dataSS->parti_info->ua_blk_name);          // All returns should go to CLEAN UP.
-               SS_SetUpgradeState(E_SS_IMGFLASHWRITEFAIL);
-               goto Cleanup;
-       }
-
- Cleanup:
-       SS_BackupSourceClear();
-       SS_PatchSourceClear();
-       SS_DeleteFile(SS_KERN_UNPK_SCRIPT_PATH);
-       SS_DeleteFolder(SS_KERNEL_WORKSPACE);
-       SS_Free(source_file.data);
-       SS_Free(buf);
-       SS_Free(outname);//wgid: 20740
-       if (result == S_SS_SUCCESS)
-               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  SUCCESS *****************\n");
-       else{
-               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaKernel  FAILED *****************\n");
-               if (fp)
-                       fclose(fp);//wgid:14711
-       }
-       return result;
-
-}
-
-/*!
- *********************************************************************************
- *                                      SS_UpdateDeltaIMG
- *********************************************************************************
- *
- * @brief
- *     This is used to apply patch for an image during delta Image upgrade
- *
- *
- *     @param
- *
- *     @return                         0 - in case of success
- *                                             1 - in case of error during patch application
- *
- *********************************************************************************
- */
-
-int SS_UpdateDeltaIMG(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *))
-{
-       uint8_t target_sha1[SHA_DIGEST_SIZE];
-       uint8_t source_sha1[SHA_DIGEST_SIZE];
-       unsigned char current_target_sha1[SHA_DIGEST_SIZE];
-       FileInfo source_file;
-       SHA1_CTX ctx1;
-       MemorySinkInfo msi;
-       int result = S_SS_SUCCESS;
-       int blk_cnt;
-       int blk_start = 0;
-       int backupsrc = -1;
-       int use_backup_img = -1;
-       int fd = -1;
-       char buf[256];
-       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-               return E_SS_FAILURE;
-       }
-
-       source_file.size = ua_dataSS->update_cfg->soure_img_size;
-       source_file.data = NULL;
-       if (0 == gvalid_session) {
-
-               if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-                       LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-                       return E_SS_FAILURE;
-               }
-
-               if (SS_LoadPartition(ua_dataSS->parti_info->ua_blk_name, &source_file) == 0) {
-                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Can be applied\n");
-                               SS_Free(source_file.data);
-                       } else if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Patch Already applied\n");
-                               SS_Free(source_file.data);
-                               return S_SS_SUCCESS;
-                       } else {
-                               SS_Free(source_file.data);
-                               source_file.data = NULL;
-                               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMG - Source was currupted, Try loading from backup source\n");
-                               if (SS_LoadPartition(SS_BACKUP_SOURCE, &source_file) == 0) {
-                                       if (memcmp(source_file.sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-                                               use_backup_img = 1;
-                                               SS_Free(source_file.data);
-                                               LOGL(LOG_SSENGINE,
-                                                        "SS_UpdateDeltaIMG - Patch Can be applied from using backup file as source\n");
-                                       } else {
-                                               SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-                                               SS_Free(source_file.data);
-                                               return E_SS_FAILURE;
-                                       }
-                               }
-                       }
-               }
-       }
-       if (use_backup_img == -1) {
-               backupsrc = SS_BackupSource(ua_dataSS->parti_info->ua_blk_name);
-               if (backupsrc != 0) {
-                       LOGE("failed to Backup source File:[%s] \n", ua_dataSS->parti_info->ua_blk_name);
-                       SS_SetUpgradeState(E_SS_IMGSRCBACKUPFAILED);
-                       return E_SS_FAILURE;
-               }
-       }
-       SinkFn sink = NULL;
-       void *token = NULL;
-
-       blk_cnt = ((ua_dataSS->update_cfg->target_img_size - 1) / SECTOR_SIZE) + 1;
-
-       msi.buffer = SS_Malloc(blk_cnt * SECTOR_SIZE);
-       if (msi.buffer == NULL) {
-               LOGE("failed to alloc %ld bytes for output\n", (long)ua_dataSS->update_cfg->target_img_size);
-               SS_SetUpgradeState(E_SS_MALLOC_ERROR);
-               return E_SS_FAILURE;
-       }
-       msi.pos = 0;
-       msi.size = ua_dataSS->update_cfg->target_img_size;
-       sink = ss_memorySink;
-       token = &msi;
-
-       SHA1Init(&ctx1);
-       //if souce was corrupted, use backup to apply diff
-       if (use_backup_img == -1)
-               result =
-                       SS_ApplyBsdiff((char *)ua_dataSS->parti_info->ua_blk_name, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-       else
-               result = SS_ApplyBsdiff(SS_BACKUP_SOURCE, NULL, SS_PATCHFILE_SOURCE, sink, token, &ctx1);
-       if (result != S_SS_SUCCESS) {
-               LOGE("failed to SS_ApplyBsdiff\n");
-               SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-               goto Cleanup;
-       }
-
-       SHA1Final(current_target_sha1, &ctx1);
-       result = memcmp(current_target_sha1, target_sha1, SHA_DIGEST_SIZE);
-       if (result != S_SS_SUCCESS) {
-               LOGE("patch did not produce expected sha1 \n");
-               SS_SetUpgradeState(E_SS_IMGSHA_MISMATCH);
-               goto Cleanup;
-       }
-       //Considering EMMC partition by default
-
-       if (ua_dataSS->update_cfg->update_type == EXTRA && ua_dataSS->update_data->ua_temp_path) {
-               fd = open(ua_dataSS->update_data->ua_temp_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);
-               if (fd < 0) {
-                       strerror_r(errno, buf, sizeof(buf));
-                       LOGE("failed to open %s for write: %s\n", ua_dataSS->update_data->ua_temp_path, buf);
-                       SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-                       result = E_SS_FAILURE;
-                       goto Cleanup;
-               }
-               result = SS_WriteFile(fd, 0, msi.buffer, msi.size);
-               if (result != S_SS_SUCCESS) {
-                       LOGE("failed to write\n");
-                       SS_SetUpgradeState(E_SS_IMGRECOVERYWRITEFAILED);
-                       goto Cleanup;
-               }
-               fsync(fd);
-       } else {
-               SS_SetUpgradeState(E_SS_IMGUPDATEFAILED);
-               result = E_SS_FAILURE;
-               LOGE("failed to apply patch - Invalid Update type params \n");
-       }
-
-Cleanup:
-       SS_BackupSourceClear();
-       SS_PatchSourceClear();
-       if (msi.buffer)
-               SS_Free(msi.buffer);
-       if (fd >= 0)
-               close(fd);
-       if (result == S_SS_SUCCESS)
-               LOGL(LOG_SSENGINE, "************* SS_UpdateDeltaIMG  SUCCESS *****************\n");
-       return result;
-
-}
-
-
-int SS_UpdateDeltaIMGAB(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *))
-{
-       int result = S_SS_SUCCESS;
-       uint8_t target_sha1[SHA_DIGEST_SIZE];
-       uint8_t source_sha1[SHA_DIGEST_SIZE];
-       uint8_t current_target_sha1[SHA_DIGEST_SIZE];
-
-       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-               return E_SS_FAILURE;
-       }
-
-       if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-               LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-               return E_SS_FAILURE;
-       }
-
-       SS_CalculateFileSha(ua_dataSS->parti_info->ua_blk_name,
-                           ua_dataSS->update_cfg->target_img_size,
-                           current_target_sha1);
-
-       /* source_file.size = ua_dataSS->update_cfg->soure_img_size; */
-       /* source_file.data = NULL; */
-       if (memcmp(target_sha1, current_target_sha1, SHA_DIGEST_SIZE) == 0) {
-               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Patch already applied\n");
-               return S_SS_SUCCESS;
-       }
-
-       LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Checksum calculation of the source partition\n");
-       SS_CalculateFileSha(ua_dataSS->parti_info->ua_blk_name_previous,
-                           ua_dataSS->update_cfg->soure_img_size,
-                           current_target_sha1);
-
-       if (memcmp(source_sha1, current_target_sha1, SHA_DIGEST_SIZE) != 0) {
-               unsigned char actualShaBuffer[41] = { 0, };
-               hex_digest(current_target_sha1, actualShaBuffer, SHA_DIGEST_SIZE);
-               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Source partition was corrupted. SRC: [%s] Expected [%s] Actual [%s]\n",
-                    ua_dataSS->parti_info->ua_blk_name_previous, ua_dataSS->update_cfg->soure_sha1, actualShaBuffer);
-               return E_SS_FAILURE;
-       }
-
-       LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Applying the patch\n");
-       apply_patch_brotli(ua_dataSS->parti_info->ua_blk_name_previous,
-                          ua_dataSS->update_cfg->soure_img_size,
-                          ua_dataSS->parti_info->ua_blk_name,
-                          ua_dataSS->update_cfg->target_img_size,
-                          SS_PATCHFILE_SOURCE);
-
-       LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Checksum calculation of the target partition\n");
-       SS_CalculateFileSha(ua_dataSS->parti_info->ua_blk_name,
-                           ua_dataSS->update_cfg->target_img_size,
-                           current_target_sha1);
-
-       if (memcmp(target_sha1, current_target_sha1, SHA_DIGEST_SIZE) != 0) {
-               unsigned char actualShaBuffer[41] = { 0, };
-               hex_digest(current_target_sha1, actualShaBuffer, SHA_DIGEST_SIZE);
-               LOGL(LOG_SSENGINE, "SS_UpdateDeltaIMGAB - Target partition was corrupted. SRC: [%s] Expected [%s] Actual [%s]\n",
-                    ua_dataSS->parti_info->ua_blk_name, ua_dataSS->update_cfg->target_sha1, actualShaBuffer);
-               return E_SS_FAILURE;
-       }
-
-       return result;
-}
+}
\ No newline at end of file
index edbe182..d8cb16a 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #include "unistd.h"
 #include "fcntl.h"
 #include "errno.h"
-#include "SS_Engine_Update.h"
+#include "ua_types.h"
 
-//#define ENHANCED_BSDIFF
-#define SS_UPDATE_FS 0
-#define SS_UPDATE_IMG 1
 #define SHA_DIGEST_SIZE 20
-typedef struct {
-       int type;
-       ssize_t size;
-       char *data;
-} Value;
-typedef struct _Patch {
-       uint8_t sha1[SHA_DIGEST_SIZE];
-       const char *patch_filename;
-} Patch;
 
 typedef struct _FileInfo {
        unsigned char sha1[20];     //SHA_DIGEST_SIZE 20
@@ -46,27 +34,17 @@ typedef struct _FileInfo {
        int size;
        struct stat st;
 } FileInfo;
-
 typedef ssize_t(*SinkFn) (unsigned char *, ssize_t, void *);
 
 int ParseSha1(const char *str, uint8_t * digest);
 
-void ShowBSDiffLicense();
-int ApplyBSDiffPatch(const unsigned char *old_data, ssize_t old_size,
-               const Value * patch, ssize_t patch_offset, SinkFn sink, void *token, SHA1_CTX * ctx1);
-int ApplyBSDiffPatchMem(const unsigned char *old_data, ssize_t old_size,
-               const Value * patch, ssize_t patch_offset, unsigned char **new_data, ssize_t * new_size);
-//int ApplyOptimizedBSDiffPatch(const unsigned char* old_data,void* token,
-//                              const Value* patch, SinkFn sink,sha1_ctx_t* ctx1);
-
-int SS_LoadPartition(const char *filename, FileInfo * file);
 int SS_LoadFile(const char *filename, FileInfo * file);
 extern void SS_SetUpgradeState(int Val);
 extern long SS_GetAvailableFreeSpace(const char *partition_name, SS_UINT32 * available_flash_size);
-extern int SS_BackupSource(const char *source_filename);
+extern int SS_BackupSource(const char *source_filename, char *backup_path);
 extern int SS_ApplyBsdiff(char *oldfile, char *newfile, char *patch, SinkFn sink, void *token, SHA1_CTX * ctx1);
-extern int SS_BackupSourceClear();
-extern int SS_PatchSourceClear();
+extern int SS_BackupSourceClear(char * backup_path);
+extern int SS_PatchSourceClear(char *patch_path);
 extern long SS_WriteFile(long wHandle, SS_UINT32 dwPosition, unsigned char *pbBuffer, SS_UINT32 dwSize);
 extern void SS_Free(void * pMemBlock);
 extern long SS_CopyFile(const char * strFromPath, const char * strToPath);
index a7a4cac..7a168ed 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -41,13 +41,11 @@ Function Prototypes Mandatory
 #include "SS_PatchDelta.h"
 #include "SS_Engine_Errors.h"
 #include "SS_FSUpdate.h"
-#include "ss_bspatch_common.h"
 
 int gtotalFSCnt = 0;
 int FS_UpgradeState = E_SS_FAILURE;
 int gvalid_session = 0;                 //used as fail-safe in case device is turmed off or battery removed during update
-fs_list *fs_headptr_main = NULL;
-fs_list *headptr_list[UA_PARTI_MAX];
+fs_list *headptr_list;
 tar_Data_t *tar_cfg_data = NULL;
 
 #ifdef MEM_PROFILING
@@ -116,15 +114,6 @@ static void get_time_stamp1(void)
        msec = (int)(tv.tv_usec / 1000);
        snprintf(ts1, 256, "%06d.%03d", sec % 100000, msec);
 }
-
-static double get_time_stamp2(void)
-{
-       struct timeval tv;
-
-       gettimeofday(&tv, NULL);
-       ts2 = (double)tv.tv_sec + (double)(tv.tv_usec / 1000000.0);
-       return ts2;
-}
 #endif
 
 //Check SS function if available
@@ -136,6 +125,7 @@ int file_exist(char *filename)
        ret = lstat(filename, &buf);
        if (ret < 0)
                ret = stat(filename, &buf);
+
        return (ret >= 0) ? (1) : (0);
 }
 
@@ -221,123 +211,6 @@ int SS_Do_Power_fail_test(int del_type)
 }
 #endif
 
-long SS_GetUPIVersion(unsigned char *ver_str)
-{
-       if (ver_str) {
-               strncpy((char *)ver_str, SS_TOTA_VERSION, MAX_PATH);
-#ifdef MEM_PROFILING
-               if (!mem_profiling_start)
-                       if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
-                               LOGE("Unable to start Memory_Profiling\n");
-#endif
-               return S_SS_SUCCESS;//wgid: 2456
-       } else
-               return E_SS_FAILURE;
-}
-
-int SS_verify_DELTA_image(char *filename)
-{
-
-       FileInfo file;
-       FILE *fp = NULL;
-       char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
-       char *delta_size = NULL;
-       char *signature = NULL;
-       char *sha1trg = NULL;
-       char *saveptr = NULL;
-       uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
-       char cmd[512] = { 0, };
-       char buf[256];
-       long int udelta_size = 0;
-       int ulResult = S_SS_SUCCESS;
-
-       file.data = NULL;
-       if (stat(filename, &file.st) != 0) {
-               strerror_r(errno, buf, sizeof(buf));
-               LOGE("failed to stat \"%s\": %s\n", filename, buf);
-               return -1;
-       }
-
-       snprintf(cmd, sizeof(cmd) - 1, "grep -o -P '%s' --binary-files=text system/%s > %s",
-                               SS_IMAGE_MAGIC_KEY, filename, SS_IMAGE_MAGIC_KEY_VAL);
-
-       ulResult = _system_cmd_wait(cmd);
-       if (ulResult != S_SS_SUCCESS) {
-               LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       fp = fopen(SS_IMAGE_MAGIC_KEY_VAL, "r");
-       if (!fp) {
-               LOGE("Grep extraction for [%s] failed, code [%d]\n", cmd, ulResult);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       fclose(fp);
-       fp = NULL;
-
-       signature = strtok_r(line, SS_TOEKN_COLON, &saveptr);
-       delta_size = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-       sha1trg = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
-
-       if (signature && sha1trg && delta_size) {
-               udelta_size = strtol(delta_size, NULL, 10);
-
-               if (udelta_size <= 0) {
-                       LOGE("Invalid udelta_size %ld (%s)\n", udelta_size, delta_size);
-                       ulResult = E_SS_FAILURE;
-                       goto Cleanup;
-               }
-               else if (udelta_size >= __INT_MAX__) {
-                       LOGE("Too big udelta_size %ld (%s)\n", udelta_size, delta_size);
-                       ulResult = E_SS_FAILURE;
-                       goto Cleanup;
-               }
-
-               LOGL(LOG_SSENGINE, "delta_size %ld sha1trg %s\n", udelta_size, sha1trg);
-       } else {
-               LOGE("Could not parse signature [%s]\n", line);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       if (ParseSha1(sha1trg, target_sha1) != 0) {
-               LOGE("failed to parse tgt-sha1 \"%s\"\n", sha1trg);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       unsigned char calcualted_sha1[SHA_DIGEST_SIZE];
-       ulResult = SS_CalculateFileSha(filename, udelta_size, calcualted_sha1);
-       if (ulResult != S_SS_SUCCESS)
-               goto Cleanup;
-
-       if (memcmp(file.sha1, target_sha1, SHA_DIGEST_SIZE) != 0) {
-               unsigned char actualShaBuffer[41] = { 0, };
-               hex_digest(file.sha1, actualShaBuffer, SHA_DIGEST_SIZE);
-               LOGE("SHA mismatch -[%s] actual [%s] target [%s]\n", filename, actualShaBuffer, sha1trg);
-               SS_SetUpgradeState(E_SS_FSBADDELTA);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       } else {
-               LOGL(LOG_SSENGINE, "DELTA verified %s \n", sha1trg);
-       }
-
-Cleanup:
-       if (fp)
-               fclose(fp);
-       if (file_exist(SS_IMAGE_MAGIC_KEY_VAL))
-               SS_DeleteFile(SS_IMAGE_MAGIC_KEY_VAL);
-       return ulResult;
-}
-
-
 int SS_GetProgressResolution(int ultotalFSCnt)
 {
        if (ultotalFSCnt < DISPLAYRESOLUTION_SIZE)
@@ -358,7 +231,7 @@ int SS_GetUpgradeState()
        return FS_UpgradeState;
 }
 
-int SS_Get_last_update_status(int* last_update_status, int* del_type)
+int SS_Get_last_update_status(int* last_update_status, int* del_type, char* status_path)
 {
        int fd;
        unsigned char buf[257];
@@ -366,14 +239,14 @@ int SS_Get_last_update_status(int* last_update_status, int* del_type)
        char *saveptr = NULL;
        int result = 0;
 
-       if (file_exist(SS_UPDATE_STATUR_PATH) == 0) {
-               LOG("No exist file!! - File_path:[%s]\n", SS_UPDATE_STATUR_PATH);
+       if (file_exist(status_path) == 0) {
+               LOG("No exist file!! - File_path:[%s]\n", status_path);
                return -1;
        }
 
-       fd = open(SS_UPDATE_STATUR_PATH, O_RDWR, S_IRWXU);
+       fd = open(status_path, O_RDWR, S_IRWXU);
        if (fd == -1) {
-               LOGE("Could not open status file!!, File_path:[%s]\n", SS_UPDATE_STATUR_PATH);
+               LOGE("Could not open status file!!, File_path:[%s]\n", status_path);
                return -1;
        }
 
@@ -404,16 +277,16 @@ int SS_Get_last_update_status(int* last_update_status, int* del_type)
        return 0;
 }
 
-void SS_Set_last_update_status(int last_update_status, int del_type)
+void SS_Set_last_update_status(int last_update_status, int del_type, char *status_path)
 {
        int fd;
        int result = 0;
        char num_str[16];
        LOG("last_update_status:[%d], del_type:[%d]\n", last_update_status, del_type);
 
-       fd = open(SS_UPDATE_STATUR_PATH, O_RDWR | O_CREAT, S_IRWXU);
+       fd = open(status_path, O_RDWR | O_CREAT, S_IRWXU);
        if (fd == -1) {
-               LOGE("Could not open status file!!, File_path:[%s]\n", SS_UPDATE_STATUR_PATH);
+               LOGE("Could not open status file!!, File_path:[%s]\n", status_path);
                return;
        }
 
@@ -430,25 +303,8 @@ void SS_Set_last_update_status(int last_update_status, int del_type)
 
 }
 
-int SS_rename(const char *old_file_name, const char *new_file_name)
-{
-       if (link(old_file_name, new_file_name) < 0) {
-               if (errno == EEXIST) {
-                       if (unlink(new_file_name) < 0 || link(old_file_name, new_file_name) < 0)
-                               return -1;
-               } else
-                       return -1;
-       }
-       if (unlink(old_file_name) < 0) {
-               if (unlink(new_file_name) == 0)
-                       return -1;
-       }
-       return 0;
-}
-
 int SS_rename1(const char *old_file_name, const char *new_file_name)
 {
-
        int result = E_SS_FAILURE;
        char *temp_name = NULL;
        temp_name = (char *)SS_Malloc(strlen(new_file_name) + 10);
@@ -656,62 +512,78 @@ void SS_UpdateUIProgress(ua_dataSS_t * ua_dataSS, int ulTotalFsCnt, int ulDone)
  *
  *********************************************************************************
  */
-void SS_FSClearNodes(int idx)
+void SS_FSClearNodes()
 {
        fs_params *local_temp = NULL;
        fs_params *local_next = NULL;
-       LOGL(LOG_SSENGINE, "Free Nodes idx=%d \n", idx);
-       if (headptr_list[idx]) {
-               if (headptr_list[idx]->del_ref) {
-                       local_temp = headptr_list[idx]->del_ref;
+       LOGL(LOG_SSENGINE, "Free Nodes\n");
+       if (headptr_list) {
+               if (headptr_list->del_ref) {
+                       local_temp = headptr_list->del_ref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               if (headptr_list[idx]->dif_ref) {
-                       local_temp = headptr_list[idx]->dif_ref;
+               if (headptr_list->dif_ref) {
+                       local_temp = headptr_list->dif_ref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               if (headptr_list[idx]->move_ref) {
-                       local_temp = headptr_list[idx]->move_ref;
+               if (headptr_list->move_ref) {
+                       local_temp = headptr_list->move_ref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               if (headptr_list[idx]->new_ref) {
-                       local_temp = headptr_list[idx]->new_ref;
+               if (headptr_list->new_ref) {
+                       local_temp = headptr_list->new_ref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               if (headptr_list[idx]->sym_difref) {
-                       local_temp = headptr_list[idx]->sym_difref;
+               if (headptr_list->sym_difref) {
+                       local_temp = headptr_list->sym_difref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               if (headptr_list[idx]->sym_newref) {
-                       local_temp = headptr_list[idx]->sym_newref;
+               if (headptr_list->sym_newref) {
+                       local_temp = headptr_list->sym_newref;
                        while (local_temp) {
                                local_next = local_temp->nextnode;
                                SS_Free(local_temp);
                                local_temp = local_next;
                        }
                }
-               SS_Free(headptr_list[idx]);
-               headptr_list[idx] = NULL;
+               if (headptr_list->hard_newref) {
+                       local_temp = headptr_list->hard_newref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               if (headptr_list->hard_difref) {
+                       local_temp = headptr_list->hard_difref;
+                       while (local_temp) {
+                               local_next = local_temp->nextnode;
+                               SS_Free(local_temp);
+                               local_temp = local_next;
+                       }
+               }
+               SS_Free(headptr_list);
+               headptr_list = NULL;
        }
 }
 
@@ -732,7 +604,7 @@ void SS_FSClearNodes(int idx)
  *********************************************************************************
  */
 
-struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile)
+struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile, char *patchlist_backup_patch)
 {
        int size = 0, bckupsize = 0, ret = 1;
        char *token = NULL;
@@ -782,7 +654,7 @@ struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile)
                ret = 0;
                goto cleanup;
        }
-       filename_bkup = fopen(SS_PATCHLIST_BKUPLOC, "wb+");
+       filename_bkup = fopen(patchlist_backup_patch, "wb+");
        if (filename_bkup == NULL) {
                strerror_r(errno, buf, sizeof(buf));
                LOGE("Failed to create BACKUP file Error:[%s]\n", buf);
@@ -856,9 +728,27 @@ struct details *SS_FSGetDeltaCount(char *ubDeltaPath, char *ubDeltaInfoFile)
                        goto cleanup;
                }
 
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->harddiffs = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
+               token = strtok_r(NULL, SS_TOKEN_SPACE, &saveptr);
+               if (token)
+                       refer_copy->hardnews = atoi(token);
+               else {
+                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTACNT);
+                       ret = 0;
+                       goto cleanup;
+               }
+
                gtotalFSCnt =
                        refer_copy->diffs + refer_copy->moves + refer_copy->news + refer_copy->deletes + refer_copy->symdiffs +
-                       refer_copy->symnews;
+                       refer_copy->symnews + refer_copy->harddiffs + refer_copy->hardnews;
                LOG("SS_FSGetDeltaCount() total no of file %d\n", gtotalFSCnt);
 
        } else {
@@ -907,6 +797,8 @@ fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
 {
        FILE *fp = NULL;
        char line[SS_TOKEN_MAXLINE_LEN] = { '\0' };
+       char patchlist_backup_patch[MAX_FILE_PATH];
+       snprintf(patchlist_backup_patch, MAX_FILE_PATH, "%s/%s",ua_dataSS->update_data->ua_delta_folder, SS_PATCHLIST_BKUPLOC);
        char string_na[] = "NA";
        char *patch_name = NULL;
        char *source_name = NULL;
@@ -928,6 +820,10 @@ fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
        fs_params *fs_symlinkdifftail = NULL;
        fs_params *fs_symlinknewhead = NULL;
        fs_params *fs_symlinknewtail = NULL;
+       fs_params *fs_hardlinkdiffhead = NULL;
+       fs_params *fs_hardlinkdifftail = NULL;
+       fs_params *fs_hardlinknewhead = NULL;
+       fs_params *fs_hardlinkdnewtail = NULL;
 
        struct details *local = NULL;
        fs_list *fs_head_node = NULL;
@@ -945,7 +841,7 @@ fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
                SS_SetUpgradeState(E_SS_BAD_PARAMS);
                return NULL;
        }
-       local = SS_FSGetDeltaCount(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_patch_info);
+       local = SS_FSGetDeltaCount(ua_dataSS->update_data->ua_delta_path, ua_dataSS->update_delta->ua_patch_info, patchlist_backup_patch);
        if (local == NULL) {
                LOGE(" Build Nodes Failed \n");
                if (tar_cfg_data)
@@ -954,7 +850,7 @@ fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
                return NULL;
        }
 
-       fp = fopen(SS_PATCHLIST_BKUPLOC, "r");
+       fp = fopen(patchlist_backup_patch, "r");
        if (!fp) {
                SS_SetUpgradeState(E_SS_FSFAILEDTOOPENPATCHINFO);
                if (tar_cfg_data)
@@ -963,7 +859,8 @@ fs_list *SS_FSBuildNodes(ua_dataSS_t * ua_dataSS)
                return NULL;
        }
 
-       ulPatchCount = local->diffs + local->deletes + local->news + local->moves + local->symdiffs + local->symnews;
+       ulPatchCount = local->diffs + local->deletes + local->news + local->moves + local->symdiffs +
+               local->symnews + local->harddiffs + local->hardnews;
        LOG("Total FS count [%d].\n", ulPatchCount);
 /*
 ************************************************************************
@@ -978,9 +875,13 @@ DIFF:TPK:system/usr/packages/removable/com.samsung.calculator.tpk:system/usr/pac
 MOVE:REG:system/etc/smack/accesses.d/heremaps-engine-devel:system/usr/apps/com.samsung.contacts/res/temp:da39a3ee5e6b4b0d3255bfef95601890afd80709
 DEL:REG:system/usr/ug/res/images/ug-phone/contacts/favorites_icon_remove.PNG:38ad8be378506d19b1c769d46be262cf100f6c59
 DEL:SYM:system/usr/apps/com.samsung.message-lite/lib/libmsg-common.so
+DEL:HARD:system/usr/apps/com.samsung.message-lite/lib/libmsg-common.so
 SYM:DIFF:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:
                                        libplugin-na-mobex.so.0.3.57
 SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
+HARD:DIFF:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:system/usr/lib/sync-agent/kies-private/libplugin-na-mobex.so.0:
+                                       libplugin-na-mobex.so.0.3.57
+HARD:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
 ***********************************************************************
 */
        if (local && ((local->diffs) > 0 || (local->moves > 0))) {
@@ -1080,7 +981,7 @@ SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
                                source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
                                sha1src = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
                                del_type = DELETES;
-                       } else if (file_type && strcmp(file_type, SS_STRING_SYM) == 0) {
+                       } else if (file_type && ((strcmp(file_type, SS_STRING_SYM) == 0) || (strcmp(file_type, SS_STRING_HARD) == 0))) {
                                source_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
                                sha1src = string_na;
                                del_type = DELETES;
@@ -1185,6 +1086,80 @@ SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
                }
                        }
                }
+       }                       // For hardlinks
+       if (local && (local->hardnews) > 0) {
+               LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_HARD, SS_STRING_NEW, local->hardnews);
+               for (i = 0; i < (local->hardnews); i++) {
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+                       //LOGL(LOG_SSENGINE, "HARDNEWS LINE:[%d] [%s] \n",i+1,line);
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if ((change_type && file_type) &&
+                                       (strcmp(change_type, SS_STRING_HARD) == 0 && strcmp(file_type, SS_STRING_NEW) == 0)) {
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_NEW, i);
+
+                               if (!source_name || !patch_name) {
+                                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                                       //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                                       LOGE("Failed to parse HardNews - LINE:[%d] [%s] \n", i + 1, line);
+                                       goto CleanUp;
+                               }
+                               retval =
+                                       SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_hardlinknewhead, &fs_hardlinkdnewtail,
+                                                                 source_name, string_na, patch_name, string_na, string_na, HARDNEWFILES,
+                                                                 ua_dataSS->update_delta->ua_patch_path);
+                               if (retval == E_SS_FAILURE)      // ONLY test purpose, should enable this
+                                       goto CleanUp;
+               if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+               }
+                       }
+               }
+       }
+
+               if (local && (local->harddiffs) > 0) {
+               LOGL(LOG_SSENGINE, "%s %ss [%d]\n", SS_STRING_HARD, SS_STRING_DIFF, local->harddiffs);
+               for (i = 0; i < (local->harddiffs); i++) {         //get the count from below function
+                       if (fgets(line, SS_TOKEN_MAXLINE_LEN, fp) == NULL) {
+                               SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                               break;
+                       }
+                       //LOGL(LOG_SSENGINE, "HARDIFFS LINE:[%d] [%s] \n",i+1,line);
+
+                       change_type = strtok_r(line, SS_TOEKN_COLON, &saveptr);
+                       file_type = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+
+                       if ((change_type && file_type) &&
+                                       strcmp(change_type, SS_STRING_HARD) == 0 && strcmp(file_type, SS_STRING_DIFF) == 0) {   // && strcmp(file_type,"TPK") == 0){
+                               source_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               target_name = strtok_r(NULL, SS_TOEKN_COLON, &saveptr);
+                               patch_name = strtok_r(NULL, SS_TOKEN_NEWLINE, &saveptr);
+                               //LOGL(LOG_SSENGINE, "%s %s Index [%d]\n", SS_STRING_SYM, SS_STRING_DIFF, i);
+
+                               if (!source_name || !target_name || !patch_name) {
+                                       SS_SetUpgradeState(E_SS_FSFAILEDTOPARSEDELTAINFO);
+                                       //LOGE("Failed to extract Patch Info Type:DELETES \n");
+                                       LOGE("Failed to parse HardDiffs - LINE:[%d] [%s] \n", i + 1, line);
+                                       goto CleanUp;
+                               }
+                               retval =
+                                       SS_AppendNode(ua_dataSS->update_data->ua_delta_path, &fs_hardlinkdiffhead, &fs_hardlinkdifftail,
+                                                                 source_name, target_name, patch_name, string_na, string_na, HARDDIFFS,
+                                                                 ua_dataSS->update_delta->ua_patch_path);
+                               if (retval == E_SS_FAILURE)      // ONLY test purpose, should enable this
+                                       goto CleanUp;
+               if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+               }
+                       }
+               }
        }
 
        fs_head_node = (fs_list *) SS_Malloc(sizeof(fs_list));
@@ -1198,6 +1173,8 @@ SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
        fs_head_node->del_ref = fs_delhead;
        fs_head_node->sym_difref = fs_symlinkdiffhead;
        fs_head_node->sym_newref = fs_symlinknewhead;
+       fs_head_node->hard_difref = fs_hardlinkdiffhead;
+       fs_head_node->hard_newref = fs_hardlinknewhead;
        fs_head_node->ulPatchCount = ulPatchCount;
 
        if (ua_dataSS->ua_operation == UI_OP_SCOUT) {
@@ -1207,7 +1184,7 @@ SYM:NEW:system/lib/firmware/vbc_eq:/opt/system/vbc_eq
  CleanUp:
        fclose(fp);
        SS_Free(local);
-       unlink(SS_PATCHLIST_BKUPLOC);
+       unlink(patchlist_backup_patch);
        if (retval == E_SS_FAILURE)
                if (tar_cfg_data)
                        tar_free_cfg_table(&tar_cfg_data);
@@ -1378,6 +1355,9 @@ int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, f
        FileInfo source_file;
        FileInfo target_file;
        uint8_t target_sha1[SHA_DIGEST_SIZE] = { 0, };
+       char new_compressed_path[MAX_FILE_PATH], patchfile_source_path[MAX_FILE_PATH];
+       snprintf(new_compressed_path, MAX_FILE_PATH, "%s/%s", ua_dataSS->update_data->ua_delta_folder, SS_NEW_COMPRESSED_FILE);
+       snprintf(patchfile_source_path, MAX_FILE_PATH, "%s/%s", ua_dataSS->update_data->ua_delta_folder, SS_PATCHFILE_SOURCE);
 
        if (!patch_path) {
                LOGE("Bad patch_path name\n");
@@ -1400,7 +1380,7 @@ int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, f
                                //LOGL(LOG_SSENGINE, "DIFF list --- [File Name %s]\n [Patch Name %s]",pFsNode->file_path, ubPatch);
                                if (pFsNode->data_size > 0) {
                                        ulReadCnt =
-                                               fast_tar_extract_file(ua_dataSS->update_data->ua_delta_path, ubPatch, SS_PATCHFILE_SOURCE,
+                                               fast_tar_extract_file(ua_dataSS->update_data->ua_delta_path, ubPatch, patchfile_source_path,
                                                                                          pFsNode->data_size, pFsNode->data_offset);
                                        if (ulReadCnt < 0) {
                                                ulResult = E_SS_FAILURE;
@@ -1414,7 +1394,7 @@ int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, f
                                        if (ulReadCnt > 0)
                                                ulResult =
                                                        SS_UpdateDeltaFS(pFsNode->file_old_path, pFsNode->file_new_path, pFsNode->sha1src,
-                                                                                        pFsNode->sha1trg, pFsNode->data_size);
+                                                                                        pFsNode->sha1trg, pFsNode->data_size, ua_dataSS->update_data->ua_delta_folder);
                                        if (ulResult != S_SS_SUCCESS) {
                                                LOGE("FS update Failed Result : [%d], [Item - %s]and size is[%d] Read Count[%d], index = [%d]\n", ulResult,
                                                         ubPatch, pFsNode->data_size, ulReadCnt, ulFileIndex);
@@ -1636,15 +1616,15 @@ int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, f
                             t1);
 #endif
                        LOGL(LOG_SSENGINE, "Starting New file upgrade for   [%s]\n", patch_path);
-                       if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, (char *)patch_path, SS_NEW_COMPRESSED_FILE) >=
+                       if (tar_extract_file(ua_dataSS->update_data->ua_delta_path, (char *)patch_path, new_compressed_path) >=
                                0)
-                               if (_7zdecompress(SS_NEW_COMPRESSED_FILE) == 0)
+                               if (_7zdecompress(new_compressed_path) == 0)
                                        LOGL(LOG_SSENGINE, "7zip extracted  successfully %s\n", ua_dataSS->parti_info->ua_parti_name);
                                else
                                        LOGL(LOG_SSENGINE, "7zip extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
                        else
                                LOGL(LOG_SSENGINE, "tar extraction error for %s\n", ua_dataSS->parti_info->ua_parti_name);
-                       SS_DeleteFile(SS_NEW_COMPRESSED_FILE);
+                       SS_DeleteFile(new_compressed_path);
 #ifdef TIME_PROFILING
                        get_time_stamp1();      //total time capturing
                        t2 = atof(ts1);
@@ -1752,6 +1732,86 @@ int SS_FSUpdateFile(int ubFileType, ua_dataSS_t * ua_dataSS, int ulPatchCount, f
                        LOGL(LOG_SSENGINE, "SYMNEWFILES mode end\n");
                }
                break;
+       case HARDDIFFS:
+               {
+                       LOGL(LOG_SSENGINE, "HARDDIFFS mode start\n");
+
+#ifdef TIME_PROFILING
+                       get_time_stamp1();      //total time capturing
+                       t1 = atof(ts1);
+                       LOGL(LOG_SSENGINE, "HARDDIFFS mode start time = [%lf]\n",
+                            t1);
+#endif
+                       while (pFsNode) {
+                               //LOGL(LOG_SSENGINE, "SYMDIFFS update Index: [%d] \n", ulFileIndex++);
+                               //LOG("Sym Diff file paths: [Linkname - %s] [reference file name- %s][]\n", pFsNode->file_path,pFsNode->patch_name);
+                               ulResult = SS_DeleteFile(pFsNode->file_old_path);
+                               if (ulResult == S_SS_SUCCESS) {
+                                       ulResult = SS_HardLink(pFsNode->file_new_path, pFsNode->patch_name);
+                                       if (ulResult != S_SS_SUCCESS) {
+                                               LOGE("SS_HardLink Failed, Linkname:[%s], reference file name, index = [%d]:[%s]\n",
+                                               pFsNode->file_new_path, ulFileIndex, pFsNode->patch_name);
+                                       }
+                               } else {
+                                       LOGE("Removing old hardlink Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
+                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                       break;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               pFsNode = pFsNode->nextnode;
+                               ulFileIndex++;
+                       }
+                       LOGL(LOG_SSENGINE, "HARDDIFFS : Total index = [%d]\n",
+                            ulFileIndex - 1);
+#ifdef TIME_PROFILING
+                       get_time_stamp1();      //total time capturing
+                       t2 = atof(ts1);
+                       LOGL(LOG_SSENGINE,
+                            "HARDDIFFS mode end time = [%lf], diff = [%lf]\n",
+                            t2, (t2 - t1));
+#endif
+                       LOGL(LOG_SSENGINE, "HARDDIFFS mode end\n");
+               }
+               break;
+       case HARDNEWFILES:
+               {
+                       LOGL(LOG_SSENGINE, "HARDNEWFILES mode start\n");
+
+#ifdef TIME_PROFILING
+                       get_time_stamp1();      //total time capturing
+                       t1 = atof(ts1);
+                       LOGL(LOG_SSENGINE,
+                            "HARDNEWFILES mode start time = [%lf]\n", t1);
+#endif
+            fs_params *head_node = pFsNode;
+                       while (head_node) {
+                               //LOGL(LOG_SSENGINE, "SYMNEWS update Index: [%d] \n", ulFileIndex++);
+                               LOGL(LOG_SSENGINE, "Hardlink New file paths: [Linkname - %s] [reference file name- %s][]\n",
+                                        head_node->file_old_path, head_node->patch_name);
+                               ulResult = SS_HardLink(head_node->file_old_path, head_node->patch_name);
+                               if (ulResult == E_SS_FAILURE) {
+                                       LOGE("Link Failed, result = [%d], index = [%d]\n", ulResult, ulFileIndex);
+                                       SS_SetUpgradeState(E_SS_FSUPDATEFAILED);
+                                       break;
+                               }
+                               SS_UpdateUIProgress(ua_dataSS, ulPatchCount, 0);
+                               head_node = head_node->nextnode;
+                               ulFileIndex++;
+                       }
+                       LOGL(LOG_SSENGINE, "HARDNEWFILES : Total index = [%d]\n",
+                            ulFileIndex - 1);
+
+#ifdef TIME_PROFILING
+                       get_time_stamp1();      //total time capturing
+                       t2 = atof(ts1);
+                       LOGL(LOG_SSENGINE,
+                            "HARDNEWFILES mode end time = [%lf], diff = [%lf]\n",
+                            t2, (t2 - t1));
+#endif
+                       LOGL(LOG_SSENGINE, "HARDNEWFILES mode end\n");
+
+        }
+               break;
        default:
                break;
        }
@@ -1779,7 +1839,7 @@ extern int cur_mem;
  *********************************************************************************
  */
 
-int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
+int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS)
 {
        int ulResult = S_SS_SUCCESS;
        int last_update_status = 0;
@@ -1788,14 +1848,16 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
        char new_patch_path[SS_MAX_FILE_PATH] = {
                0
        };
+       char status_path[MAX_FILE_PATH];
+       snprintf(status_path, MAX_FILE_PATH, "%s/%s",ua_dataSS->update_data->ua_delta_folder, SS_UPDATE_STATUS_PATH);
 
        if (!ua_dataSS)
                return E_SS_BAD_PARAMS; // Set error ??
-       head_ptr_node = headptr_list[part_idx];
+       head_ptr_node = headptr_list;
 
        if (!head_ptr_node) {      //in case of power failure, try rebilding nodes again
-               SS_FSVerifyPartition(ua_dataSS, part_idx);
-               head_ptr_node = headptr_list[part_idx];
+               SS_FSVerifyPartition(ua_dataSS);
+               head_ptr_node = headptr_list;
        }
 
        if (!head_ptr_node)
@@ -1803,7 +1865,7 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
 
        SS_GetPartition_LocDetails(ua_dataSS);
 
-       LOGL(LOG_SSENGINE, "FS Update Entry PartIndex: [%d]\n", part_idx);
+       LOGL(LOG_SSENGINE, "FS Update Entry\n");
 
 #ifdef POWER_FAIL_TEST
        int fail_test_flag = 0;
@@ -1811,11 +1873,14 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
        LOGL(LOG_SSENGINE, "fail_test_flag: [%d]\n", fail_test_flag);
 #endif
 
-       if(SS_Get_last_update_status(&last_update_status, &del_type) == -1)
+       if(SS_Get_last_update_status(&last_update_status, &del_type, status_path) == -1)
                LOGE("SS_Get_last_update_status failed!!\n");
 
        LOGL(LOG_SSENGINE, "last_update_status: [%d], del_type: [%d]\n", last_update_status, del_type);
 
+       // for now, we don't want to read last del_type as the logic doesn't work
+       del_type = 0;
+
        if (head_ptr_node->del_ref == NULL) {
                LOGL(LOG_SSENGINE, "No DEL header\n");
        } else if (ulResult == S_SS_SUCCESS) {
@@ -1832,7 +1897,7 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
                                        }
                                }
 #endif
-                               SS_Set_last_update_status(part_idx, DELETES);
+                               SS_Set_last_update_status(0, DELETES, status_path);
                        }
                } else {
                        LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETES already applied!!\n");
@@ -1873,7 +1938,7 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
                                        }
                                }
 #endif
-                               SS_Set_last_update_status(part_idx, MOVES);
+                               SS_Set_last_update_status(0, MOVES, status_path);
                        }
                } else {
                        LOGL(LOG_SSENGINE, "SS_FSUpdateFile - MOVES already applied!!\n");
@@ -1895,7 +1960,7 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
                                        }
                                }
 #endif
-                               SS_Set_last_update_status(part_idx, DELETE_END);
+                               SS_Set_last_update_status(0, DELETE_END, status_path);
                        }
                } else {
                        LOGL(LOG_SSENGINE, "SS_FSUpdateFile - DELETE_END already applied!!\n");
@@ -1950,6 +2015,41 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
                }
        }
 
+       if (head_ptr_node->hard_newref == NULL) {
+               LOGL(LOG_SSENGINE, "No HARDNEW header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(HARDNEWFILES, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->hard_newref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+               if (ulResult == S_SS_SUCCESS) {
+                       LOGL(LOG_SSENGINE, "SS_FSUpdateFile - HARDNEWFILES success!!\n");
+#ifdef POWER_FAIL_TEST
+                       if (fail_test_flag < HARDNEWFILES) {
+                               if (SS_Do_Power_fail_test(HARDNEWFILES) == E_SS_FAILURE) {
+                                       LOGE("SS_Do_Power_fail_test failed!!\n");
+                               }
+                       }
+#endif
+               }
+       }
+
+       if (head_ptr_node->hard_difref == NULL) {
+               LOGL(LOG_SSENGINE, "No HARDDIFF header\n");
+       } else if (ulResult == S_SS_SUCCESS) {
+               ulResult =
+                       SS_FSUpdateFile(HARDDIFFS, ua_dataSS, head_ptr_node->ulPatchCount, head_ptr_node->hard_difref,
+                                                       ua_dataSS->update_delta->ua_patch_path);
+               if (ulResult == S_SS_SUCCESS) {
+                       LOGL(LOG_SSENGINE, "SS_FSUpdateFile - HARDDIFFs success!!\n");
+#ifdef POWER_FAIL_TEST
+                       if (fail_test_flag < HARDDIFFS) {
+                               if (SS_Do_Power_fail_test(HARDDIFFS) == E_SS_FAILURE) {
+                                       LOGE("SS_Do_Power_fail_test failed!!\n");
+                               }
+                       }
+#endif
+               }
+       }
 
        if (ulResult == S_SS_SUCCESS) {
                ulResult = SS_FSSetAttributes(ua_dataSS);
@@ -1959,14 +2059,14 @@ int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx)
 
        sync();
        sleep(1);
-       SS_FSClearNodes(part_idx);
+       SS_FSClearNodes();
 
        if (ulResult == S_SS_SUCCESS) {
                SS_UpdateUIProgress(ua_dataSS, 0, 1);   //fix WGID : 51963, When all updates are done to FS , patchcount is not needed, passing 1 to 3rd arg is enough
-               SS_Set_last_update_status(part_idx, DEL_TYPE_MAX);
+               SS_Set_last_update_status(0, DEL_TYPE_MAX, status_path);
        }
 
-       LOGL(LOG_SSENGINE, "FS update Complete PartIndex: [%d]\n", part_idx);
+       LOGL(LOG_SSENGINE, "FS update Complete\n");
 #ifdef  MEM_PROFILING
        LOGL(LOG_SSENGINE, "Stats are : Cur Max : [%d] Global Max : [%d]\n", cur_mem, max_mem);
 #endif
@@ -2019,54 +2119,33 @@ size_t SS_FSAvailiableFreeSpace(char *block_name)
        return ((long long)sb.f_bsize * (long long)sb.f_bavail >= (long long)SIZE_4GB) ? SIZE_4GB : sb.f_bsize * sb.f_bavail ;
 }
 
-int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS, int part_idx)
+int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS)
 {
        int ulResult = S_SS_SUCCESS;
-       size_t free_space = 0;
        if (!ua_dataSS) {
                LOGE("Wrong Param for fs verification\n");
                SS_SetUpgradeState(E_SS_BAD_PARAMS);
                return E_SS_FAILURE;
        }
 
-       LOGL(LOG_SSENGINE, "FS max free mem reqired : [%d]\n", ua_dataSS->update_cfg->soure_img_size);
-       free_space = SS_FSAvailiableFreeSpace(ua_dataSS->parti_info->ua_blk_name);
-       if (free_space != E_SS_FAILURE) {
-               //Source img size is max single file size for a file system under upgrade, which is updated in CFG file by UPG
-               if ((free_space) < (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10)) {
-                       LOGE("Not enough free space [%d] for max size [%d]\n", free_space,
-                                (ua_dataSS->update_cfg->soure_img_size + ua_dataSS->update_cfg->soure_img_size / 10));
-                       //SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-                       //return E_SS_FAILURE;
-               } else
-                       LOGL(LOG_SSENGINE, "Enough space for Partition [%s]\n", ua_dataSS->parti_info->ua_parti_name);
-       }
-
-       SS_GetAvailableFreeSpace(SS_COMMON_WORKSPACE, &free_space);
-       //Checking for 2 times the file size free space , as delta can be worst case size of file.
-       if ((free_space) < (2 * ua_dataSS->update_cfg->soure_img_size)) {
-               LOGE("Not enough free space [%d] for max size [%d]\n", free_space, (2 * ua_dataSS->update_cfg->soure_img_size));
-               SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-               return E_SS_FAILURE;
-       }
 #ifdef MEM_PROFILING
        if (!mem_profiling_start)
                if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
                        return E_SS_FAILURE;
 #endif
        SS_GetPartition_LocDetails(ua_dataSS);
-       LOGL(LOG_SSENGINE, "FS Verification Start PartIndex:[%d]\n", part_idx);
+       LOGL(LOG_SSENGINE, "FS Verification Start\n");
        if (ua_dataSS->ua_operation == UI_OP_SCOUT)
                gvalid_session = 1;  // (shd b true if called during verification)
-       headptr_list[part_idx] = SS_FSBuildNodes(ua_dataSS);
+       headptr_list = SS_FSBuildNodes(ua_dataSS);
 #ifdef TIME_PROFILING
        LOGL(LOG_SSENGINE, "fast_tar_get_item_size_time :[%lf]\n", fast_tar_get_item_size_time);
        LOGL(LOG_SSENGINE, "SS_LoadFile_time :[%lf]\n", SS_LoadFile_time);
        LOGL(LOG_SSENGINE, "SS_FSBuildNodes_time :[%lf]\n", SS_FSBuildNodes_time);
 #endif
-       if (!headptr_list[part_idx]) {
-               LOGE("FS Verification Failed PartIndex: [%d]\n", part_idx);
-               SS_FSClearNodes(part_idx);
+       if (!headptr_list) {
+               LOGE("FS Verification Failed\n");
+               SS_FSClearNodes();
                ulResult = E_SS_FAILURE;
        }
 
@@ -2077,12 +2156,12 @@ int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS, int part_idx)
 }
 
 //Should check if space is available????
-int SS_BackupSource(const char *source_filename)
+int SS_BackupSource(const char *source_filename, char *backup_path)
 {
        int ret = E_SS_FAILURE;
 
        if (source_filename) {
-               ret = (int)SS_CopyFile(source_filename, SS_BACKUP_SOURCE);
+               ret = (int)SS_CopyFile(source_filename, backup_path);
                if (ret != S_SS_SUCCESS) {
                        LOGE("failed to back up source file  Error [%d]\n", ret);
                        SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
@@ -2091,10 +2170,10 @@ int SS_BackupSource(const char *source_filename)
        return ret;
 }
 
-int SS_BackupSourceClear(void)
+int SS_BackupSourceClear(char *backup_path)
 {
        int ret = E_SS_FAILURE;
-       ret = (int)SS_DeleteFile(SS_BACKUP_SOURCE);
+       ret = (int)SS_DeleteFile(backup_path);
        if (ret != S_SS_SUCCESS) {
                LOGE("failed to delete BACKUP file\n");
                SS_SetUpgradeState(E_SS_FSSRCBACKUPFAILED);
@@ -2102,250 +2181,27 @@ int SS_BackupSourceClear(void)
        return ret;
 }
 
-int SS_PatchSourceClear(void)
+int SS_PatchSourceClear(char *patch_path)
 {
        int ret = E_SS_FAILURE;
-       ret = (int)SS_DeleteFile(SS_PATCHFILE_SOURCE);
+       ret = (int)SS_DeleteFile(patch_path);
        if (ret != S_SS_SUCCESS) {
                LOGE("failed to delete PATCHFILE file\n");
                SS_SetUpgradeState(E_SS_PATCHFILE_DEL_ERROR);
        }
        return ret;
 }
-int SS_IMGVerifyFullImage(ua_dataSS_t * ua_dataSS)
-{
-       int read_cnt = 0, patch_size = 0;
-       FileInfo source_file;
-       uint8_t target_sha1[SHA_DIGEST_SIZE];
-       int ulResult = S_SS_SUCCESS;
 
-       if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info &&
-                               ua_dataSS->parti_info->ua_blk_name &&
-                               !(ua_dataSS->update_cfg->skip_verify == 1))) {
-               LOGE("Bad structure or members\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               return E_SS_FAILURE;
-       }
-
-       LOGL(LOG_SSENGINE, "FULL IMG Verification Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
-
-       if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
-               && ua_dataSS->parti_info->ua_subject_name) {
-               patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
-       } else {
-               LOGE("Bad structure members in ua_dataSS\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1) {
-               LOGL(LOG_SSENGINE, "\nParams -image size [%d] sha1 [%s]\n",
-                        ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
-       } else {
-               LOGE("Bad structure member update_cfg in ua_dataSS\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-               LOGE("failed to parse tgt-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-               SS_SetUpgradeState(E_SS_IMGBADDELTA);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-
-       if ((patch_size) > 0)
-               read_cnt = tar_extract_file(ua_dataSS->update_data->ua_delta_path,
-                               ua_dataSS->parti_info->ua_subject_name, SS_PATCHFILE_SOURCE);
-
-       if (read_cnt <= 0) {
-               LOGL(LOG_SSENGINE, "Failed to read delta\n");
-               SS_SetUpgradeState(E_SS_IMGBADDELTA);
-               ulResult = E_SS_FAILURE;
-               goto Cleanup;
-       }
-       if (SS_LoadFile(SS_PATCHFILE_SOURCE, &source_file) == 0) {
-               if (memcmp(source_file.sha1, target_sha1, SHA_DIGEST_SIZE) == 0) {
-                       LOGL(LOG_SSENGINE, "Patch Can be applied\n");
-                       SS_Free(source_file.data);
-                       ulResult = S_SS_SUCCESS;
-               } else{
-                       LOGL(LOG_SSENGINE, "Patch Cannot be applied\n");
-                       SS_Free(source_file.data);
-                       SS_SetUpgradeState(E_SS_IMGBADDELTA);
-                       ulResult = E_SS_FAILURE;
-                       goto Cleanup;
-               }
-       } else {
-               LOGL(LOG_SSENGINE, "Failed to LoadFile\n");
-               SS_SetUpgradeState(E_SS_IMGBADDELTA);
-               ulResult = E_SS_FAILURE;
-       }
-
-Cleanup:
-       if (file_exist(SS_PATCHFILE_SOURCE))
-               SS_DeleteFile(SS_PATCHFILE_SOURCE);
-       return ulResult;
-}
-
-int SS_IMGVerfiyPartition(ua_dataSS_t * ua_dataSS, const char *src_blk_name, bool check_free_space)
+long SS_GetUPIVersion(unsigned char *ver_str)
 {
-       int ulResult = S_SS_SUCCESS;
-       uint8_t source_sha1[SHA_DIGEST_SIZE];
-       uint8_t target_sha1[SHA_DIGEST_SIZE];
-       uint8_t calculated_sha1[SHA_DIGEST_SIZE];
-       size_t free_space = 0;
-
-       if (!(ua_dataSS && ua_dataSS->update_cfg && ua_dataSS->parti_info && src_blk_name)) {
-               LOGE("Bad structure or members\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               return E_SS_FAILURE;
-       }
-
-       if (check_free_space) {
-               //We verify twice the image size for BACKUP source, not on Partition. As Patch will be created on RAM
-               SS_GetAvailableFreeSpace(SS_COMMON_WORKSPACE, &free_space);
-               if ((free_space) < (2 * ua_dataSS->update_cfg->target_img_size)) {
-                       LOGE("Not enough free space [%d] for twice max size [%d]\n", free_space,
-                                (2 * ua_dataSS->update_cfg->target_img_size));
-                       SS_SetUpgradeState(E_SS_FSMEMORYERROR);
-                       return E_SS_FAILURE;
-               }
-       }
-
-       if (ParseSha1(ua_dataSS->update_cfg->soure_sha1, source_sha1) != 0) {
-               LOGE("failed to parse Src-sha1 \"%s\"\n", ua_dataSS->update_cfg->soure_sha1);
-               SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
-               return E_SS_FAILURE;
-       }
-       // corner case, Parsing sha can fail if update.cfg is wrong/manually edited
-       if (ParseSha1(ua_dataSS->update_cfg->target_sha1, target_sha1) != 0) {
-               LOGE("failed to parse Target-sha1 \"%s\"\n", ua_dataSS->update_cfg->target_sha1);
-               SS_SetUpgradeState(E_SS_SHAPRASE_FAILED);
-               return E_SS_FAILURE;
-       }
-
-       /*
-        * If ab_update is set it means it is a DELTA_IMAGE update, where the patch
-        * is applied to data directly read from a partition in the previous slot
-        */
-       SS_CalculateFileSha(src_blk_name, ua_dataSS->update_cfg->soure_img_size, calculated_sha1);
-       if (memcmp(calculated_sha1, source_sha1, SHA_DIGEST_SIZE) == 0) {
-               LOGL(LOG_SSENGINE, "SS_IMGVerfiyPartition - SHA matches with source [%s] \n", src_blk_name);
-       } else {                          // Need not compare with Target sha as once upgraded, it should NOT verify same partition again.
-               unsigned char actualShaBuffer[41] = { 0, };
-               hex_digest(calculated_sha1, actualShaBuffer, SHA_DIGEST_SIZE);
-               LOGE("SS_IMGVerfiyPartition - SHA mismatch with SRC [%s] Expected [%s] Actual [%s]\n",
-                       src_blk_name, ua_dataSS->update_cfg->soure_sha1, actualShaBuffer);
-               SS_SetUpgradeState(E_SS_IMGSRCCURRUPTED);
-               ulResult = E_SS_FAILURE;
-       }
-       if (ulResult == S_SS_SUCCESS) {
-               if (ua_dataSS->ui_progress)
-                       ua_dataSS->ui_progress(ua_dataSS, 100);
-               return ulResult;
+       if (ver_str) {
+               strncpy((char *)ver_str, SS_TOTA_VERSION, MAX_PATH);
+#ifdef MEM_PROFILING
+               if (!mem_profiling_start)
+                       if (!(S_SS_SUCCESS == SS_Do_Memory_Profiling()))
+                               LOGE("Unable to start Memory_Profiling\n");
+#endif
+               return S_SS_SUCCESS;//wgid: 2456
        } else
-               return SS_GetUpgradeState();
-}
-
-/*!
- *********************************************************************************
- *                                      SS_IMGUpdatemain
- *********************************************************************************
- *
- * @brief
- *     This is the API exposed from the engine to update Images(FULL and DELTA images)
- *
- *
- *     @param
- *
- *     @return                         returns S_SS_SUCCESS
- *                                             E_SS_FAILURE in case of error
- *
- *********************************************************************************
- */
-
-int SS_IMGUpdatemain(ua_dataSS_t * ua_dataSS, int update_type)  //SS_FSUpdatePartition
-{
-       int read_cnt = 0, patch_size;
-       int ulResult = S_SS_SUCCESS;
-
-       //sprintf(Blk_name, "%s%s%s","EMMC",":", ua_dataSS->parti_info->ua_blk_name);
-       //LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n",Blk_name);
-       if (!ua_dataSS) {
-               LOGE("Bad structure ua_dataSS\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               return E_SS_FAILURE;
-       }
-       LOGL(LOG_SSENGINE, "IMG Upgrade Entry BlkName:[%s]\n", ua_dataSS->parti_info->ua_blk_name);
-
-       if (ua_dataSS->update_data && ua_dataSS->parti_info && ua_dataSS->update_data->ua_delta_path
-               && ua_dataSS->parti_info->ua_subject_name)
-               patch_size = tar_get_item_size(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name);
-       else {
-               LOGE("Bad structure members in ua_dataSS\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               return E_SS_FAILURE;
-       }
-       if (ua_dataSS->update_cfg && ua_dataSS->update_cfg->soure_img_size && ua_dataSS->update_cfg->target_sha1)
-               LOGL(LOG_SSENGINE, "SS_IMGUpdatemain Params -source size [%d] sha1 [%s]\n",
-                        ua_dataSS->update_cfg->soure_img_size, ua_dataSS->update_cfg->target_sha1);
-       else {
-               LOGE("Bad structure member update_cfg in ua_dataSS\n");
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
                return E_SS_FAILURE;
-       }
-
-       if ((patch_size) > 0)
-               read_cnt =
-                       tar_extract_file(ua_dataSS->update_data->ua_delta_path, ua_dataSS->parti_info->ua_subject_name,
-                                                        SS_PATCHFILE_SOURCE);
-
-       if (read_cnt <= 0) {
-               ulResult = E_SS_FAILURE;
-               SS_SetUpgradeState(E_SS_IMGBADDELTA);
-               return E_SS_FAILURE;    //ulResult;
-       }
-       if (ua_dataSS->ui_progress)
-               ua_dataSS->ui_progress(ua_dataSS, 40);
-
-       if (update_type == FULL_IMAGE && ua_dataSS->update_data->ua_temp_path)
-               ulResult = SS_MoveFile(SS_PATCHFILE_SOURCE, ua_dataSS->update_data->ua_temp_path);
-       else if (ua_dataSS->update_cfg->update_type == EXTRA || ua_dataSS->update_cfg->update_type == DELTA_IMAGE) {
-
-               FILE *fp = NULL;
-               char buf[14] = { 0, };  //to store zImage-delta magic keyword
-               char err_buf[256];
-               ssize_t bytes_read;
-               fp = fopen(SS_PATCHFILE_SOURCE, "r");
-               if (fp == NULL) {
-                       strerror_r(errno, err_buf, sizeof(err_buf));
-                       LOGE("Failed to open patch file Error:[%s]\n", err_buf);
-                       SS_SetUpgradeState(E_SS_FSFAILEDTOOPENPATCHINFO);
-                       return E_SS_FAILURE;
-               }
-               bytes_read = fread(buf, 1, 13, fp);             //error check not required as any delta corruption will be caught in SS_UpdateDeltaIMG
-               if (bytes_read != 13)
-                       LOGL(LOG_SSENGINE, "short read of \"%s\" (%ld bytes of %ld)\n", SS_PATCHFILE_SOURCE, (long)bytes_read, (long)13);
-               fclose(fp);
-
-               if (update_type == DELTA_IMAGE)
-                       ulResult = SS_UpdateDeltaIMGAB(ua_dataSS);
-               else if (strncmp(buf, SS_KERNEL_MAGIC, sizeof(buf) / sizeof(char)) == 0)
-                       ulResult = SS_UpdateDeltaKernel(ua_dataSS, ua_dataSS->write_data_to_blkdev);
-       } else {
-               LOGE("Update type is INVALID - Exit \n");
-               ulResult = E_SS_FAILURE;
-               SS_SetUpgradeState(E_SS_BAD_PARAMS);
-               return E_SS_FAILURE;
-       }
-
-       if (ulResult == S_SS_SUCCESS) {
-               if (ua_dataSS->ui_progress)
-                       ua_dataSS->ui_progress(ua_dataSS, 100);
-               return ulResult;
-       } else
-               return SS_GetUpgradeState();
-}
+}
\ No newline at end of file
index 9e6fa1d..107a810 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 #ifndef _SS_UPI_H_
 #define _SS_UPI_H_
 #include <stdbool.h>
+#include "fota_common.h"
 
 #define DISPLAYRESOLUTION_SIZE 50
 
@@ -29,9 +30,11 @@ struct details {
        int deletes;
        int symdiffs;
        int symnews;
+       int harddiffs;
+       int hardnews;
 };
 
-enum DEL_TYPE { DELETES = 1, DIFFS, MOVES, DELETE_END, NEWFILES, SYMDIFFS, SYMNEWFILES, DEL_TYPE_MAX };
+enum DEL_TYPE { DELETES = 1, DIFFS, MOVES, DELETE_END, NEWFILES, SYMDIFFS, SYMNEWFILES, HARDDIFFS, HARDNEWFILES, DEL_TYPE_MAX };
 struct fs_params {                       // Use Macros
        char file_old_path[512];
        char file_new_path[512];
@@ -52,21 +55,18 @@ struct fs_list {
        fs_params *del_ref;
        fs_params *sym_difref;
        fs_params *sym_newref;
+       fs_params *hard_difref;
+       fs_params *hard_newref;
        int ulPatchCount;
 };
 typedef struct fs_list fs_list;
-struct details *get_fs_details(char *filename);
 
 int SS_AppendNode(const char *ubDeltaPath, fs_params ** headparam, fs_params ** tailparam, const char *old_path,
                                  const char *new_path, const char *patchname, const char *sha1src, const char *sha1trg, int type,
                                  char *patchpath_name);
-extern int SS_IMGUpdatemain(ua_dataSS_t * ua_dataSS, int update_type);
-extern int SS_IMGVerfiyPartition(ua_dataSS_t * ua_dataSS, const char *src_blk_name, bool check_free_space);
-extern int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS, int part_idx);
-extern int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS, int part_idx);
-extern int SS_UpdateDeltaIMG(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *));
-extern int SS_UpdateDeltaKernel(ua_dataSS_t * ua_dataSS, int (*write_to_blkdev) (char *, int, int, char *));
-extern int SS_UpdateDeltaIMGAB(ua_dataSS_t * ua_dataSS);
+long SS_GetUPIVersion(unsigned char *ver_str);
+extern int SS_FSUpdatemain(ua_dataSS_t * ua_dataSS);
+extern int SS_FSVerifyPartition(ua_dataSS_t * ua_dataSS);
 
 //extra functions
 extern void *SS_Malloc(unsigned int size);
@@ -79,13 +79,13 @@ extern int tar_open(char *tar);
 extern int fast_tar_extract_file(char *tar, char *item, char *pathname, int size, int offset);
 extern int tar_close();
 extern int SS_UpdateDeltaFS(const char *source_filename, const char *target_filename,
-                                                       const char *source_sha1_str, const char *target_sha1_str, int patch_data_size);
+                                                       const char *source_sha1_str, const char *target_sha1_str, int patch_data_size, char *delta_folder);
 extern int tar_extract_file(char *tar, char *item, char *pathname);
 extern int _7zdecompress(char *path);
 extern void tar_free_cfg_table(tar_Data_t ** delta_tar);
 extern long SS_GetFileType(char *pLinkName, enumFileType * fileType);
 
-extern int SS_Get_last_update_status(int* last_update_status, int* del_type);
-extern void SS_Set_last_update_status(int last_update_status, int del_type);
+extern int SS_Get_last_update_status(int* last_update_status, int* del_type, char *status_path);
+extern void SS_Set_last_update_status(int last_update_status, int del_type, char *status_path);
 
 #endif                                           //_SS_UPI_H_
index 93d28fa..607ae5f 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #include <stdio.h>
 #include "fota_log.h"
 
-typedef signed char s8;
-typedef unsigned char u8;
-
-typedef signed short s16;
-typedef unsigned short u16;
-
-typedef signed int s32;
 typedef unsigned int u32;
 #ifndef __size_t /* typedef check for x86 env: stddef.h */
 #define __size_t
 typedef u32 size_t;
 #endif /* __size_t */
 
-typedef signed long sl32;
-typedef unsigned long ul32;
-
-typedef signed long long s64;
-typedef unsigned long long u64;
-
 #define MAX_FILE_PATH           512
 
 #ifndef TIME_PROFILING
@@ -61,44 +48,23 @@ typedef unsigned long long u64;
 #define SS_TOTA_VERSION                        "1.0.19"
 #define BSDIFF                         "BSDIFF40"
 #define IMGDIFF                                "IMGDIFF2"
-#define SECTOR_SIZE                    512
+#define SECTOR_SIZE                    512F
 #define SS_KERNEL_DELTA_HEADER         128
 
-#define SS_COMMON_WORKSPACE                    "/run/upgrade-sysroot/opt/usr/data/fota"
-#define SS_KERNEL_UNPACK_SCRIPT                "unpack.sh"
-#define SS_KERN_UNPK_SCRIPT_PATH       SS_COMMON_WORKSPACE "/" SS_KERNEL_UNPACK_SCRIPT
-#define SS_BACKUP_SOURCE               SS_COMMON_WORKSPACE "/saved.file"       //How to make sure there is SPACE
-#define SS_PATCHFILE_SOURCE            SS_COMMON_WORKSPACE "/patchfile.file"   //define in common place
-#define SS_PATCHLIST_BKUPLOC           SS_COMMON_WORKSPACE "/patchlist.txt"
-#define SS_NEW_COMPRESSED_FILE         SS_COMMON_WORKSPACE "/system.7z"
-#define SS_KERNEL_WORKSPACE            SS_COMMON_WORKSPACE "/kernel-work"
-#define SS_GZIP_TARGET                 SS_KERNEL_WORKSPACE "/gzip"
-#define SS_STAT_TARGET                 SS_KERNEL_WORKSPACE "/stat"
-#define SS_DD_TARGET                   SS_KERNEL_WORKSPACE "/dd"
-//#define SS_UPDATE_STATUR_PATH                SS_COMMON_WORKSPACE "/UP.STATUS"
-#define SS_UPDATE_STATUR_PATH          "/run/upgrade-sysroot/opt/data/recovery/UP.STATUS"
-
-#define SS_GZIP_SOURCE                 "run/upgrade-sysroot/bin/gzip"
-#define SS_STAT_SOURCE                 "run/upgrade-sysroot/usr/bin/stat"
-#define SS_DD_SOURCE                   "run/upgrade-sysroot/bin/dd"
-
-#define SS_KERNEL_MAGIC                        "UnpackdzImage"
-#define SS_KERNEL_NAME                 "zImage"
-#define SS_KERNEL_TARGET_NAME          "dzImage_final"
-#define SS_KERNEL_UNPACK_DIR           SS_KERNEL_NAME "_unpacked"
-#define SS_PATCHLISTFOLDER             "/p"
-#define SS_NEWPATCHFOLDER              "/n"
+#define SS_BACKUP_SOURCE                "/saved.file"       //How to make sure there is SPACE
+#define SS_PATCHFILE_SOURCE             "/patchfile.file"   //define in common place
+#define SS_PATCHLIST_BKUPLOC            "/patchlist.txt"
+#define SS_NEW_COMPRESSED_FILE          "/system.7z"
+#define SS_UPDATE_STATUS_PATH           "/UP.STATUS"
+
 #define SS_PATCHLISTFORMAT             ".txt"
 #define SS_PATCH_ATTR_FORMAT           "_attr.txt"
 #define SS_FSCOUNT_MAGIC_KEY           "PaTcHCoUnT:"
 #define SS_FSCOUNT_MAGIG_KEYLEN                (11)    //length of  SS_FSCOUNT_MAGIC_KEY
-#define SS_IMAGE_MAGIC_KEY             "TiZSiG@tOtA_00_:.{0,64}"
-#define SS_IMAGE_MAGIC_KEY_VAL         SS_COMMON_WORKSPACE "/delta_sha.txt"
 
 #define SS_TOKEN_SPACE                 " "
 #define SS_TOKEN_NEWLINE               "\n"
 #define SS_TOEKN_COLON                 ":"
-#define SS_CHAR_FWSLASH                        '/'
 #define SS_FWSLASH                     "/"
 #define SS_NULLENTRY                   "0"
 #define SS_MAX_NAMELENSUPPORTED                (200)   //(Tar supports 256, But extra space is used for PartitionName, .delta, /p, so restricting filename max to 200)
@@ -110,12 +76,15 @@ typedef unsigned long long u64;
 #define SS_STRING_MOVE                 "MOVE"
 #define SS_STRING_DEL                  "DEL"
 #define SS_STRING_SYM                  "SYM"
+#define SS_STRING_HARD                 "HARD"
 #define SS_STRING_NEW                  "NEW"
 #define SS_STRING_REG                  "REG"
 #define SS_STRING_TPK                  "TPK"
 #define SS_STRING_ZIP                  "ZIP"
 #define SS_STRING_END                  "END"
 
+#define SS_COMMON_WORKSPACE                    "/run/upgrade-sysroot/opt/usr/data/fota"
+
 #ifdef MEM_PROFILING
 #define SS_MEMORY_USAGE_LOG            SS_COMMON_WORKSPACE "/log_memory"
 #define SS_MEMORY_PROFILING_SCRIPT     SS_COMMON_WORKSPACE "/mem_use.sh"
index 348dba0..0fb8285 100755 (executable)
@@ -165,29 +165,4 @@ int log_printf(FILE* log_fp, char* format_str, ...)
 
 exit:
        return ret;
-}
-
-/*-----------------------------------------------------------------------------
-  truncate_log_file
- ----------------------------------------------------------------------------*/
-void truncate_log_file(char *log_path, int size_kb)
-{
-       FILE *log_fp;
-
-       if (max_logfile_size != DEF_MAX_LOG_SIZE) {
-               /* This means someone wants to see log file, so not truncate. */
-               return;
-       }
-
-       if (size_kb == 0) {
-               log_fp = fopen(log_path, "w");
-               if (log_fp == NULL)
-                       perror("file open error\n");
-               else
-                       fclose(log_fp);
-       }
-
-       sync();
-}
-
-
+}
\ No newline at end of file
index 231af30..f3e8b35 100755 (executable)
@@ -28,7 +28,6 @@
 extern unsigned int __log_level__;
 extern FILE *__log_out_file__;
 extern int log_printf(FILE* log_fp, char* format_str, ...);
-extern void truncate_log_file(char *log_path, int size_kb);
 extern void set_max_logfile_size(void);
 
 #define LOG_INFO       (1<<8)
index af32bb2..d0304f9 100755 (executable)
@@ -24,7 +24,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include "SS_Engine_Update.h"
 #include "SS_Engine_Errors.h"
 #include "SS_FSUpdate.h"
 #include "fota_common.h"
@@ -64,7 +63,6 @@ struct posix_header {            /* byte offset */
 #define        TAR_ITEM_NAME_SIZE              100
 #define        TAR_LONG_NAME_SIZE              256
 #define        TAR_ITEM_TYPE_FLAG_POS  156
-
 /*** The byte that indicates whether the prefix is present or not */
 #define PREFIX_INDICATOR_BYTE 345
 #define PREFIX_LEN 155
@@ -99,48 +97,6 @@ extern void *SS_Malloc(SS_UINT32 size);
 
 int gTarFd = -1;                               // Currenlty this logic supports only one tar file
 
-/* Parse an octal number, ignoring leading and trailing nonsense. */
-static int parseoct(const char *p, size_t n)
-{
-       int i = 0;
-
-       while (*p < '0' || *p > '7') {
-               ++p;
-               --n;
-       }
-       while (*p >= '0' && *p <= '7' && n > 0) {
-               i *= 8;
-               i += *p - '0';
-               ++p;
-               --n;
-       }
-       return (i);
-}
-
-/* Verify the tar checksum. */
-static int verify_checksum(const char *p)
-{
-       int n, u = 0;
-       for (n = 0; n < 512; ++n) {
-               if (n < 148 || n > 155)
-                       /* Standard tar checksum adds unsigned bytes. */
-                       u += ((unsigned char *)p)[n];
-               else
-                       u += 0x20;
-
-       }
-       return (u == parseoct(p + 148, 8));
-}
-
-static int is_end_of_archive(const char *p)
-{
-       int n;
-       for (n = 511; n >= 0; --n)
-               if (p[n] != '\0')
-                       return (0);
-       return (1);
-}
-
 void create_dir(char *pathname, int mode)
 {
        char *p;
@@ -169,24 +125,6 @@ void create_dir(char *pathname, int mode)
        }
 }
 
-/* Create a file, including parent directory as necessary. */
-static FILE *create_file(char *pathname)
-{
-       FILE *f;
-       f = fopen(pathname, "w+");
-       if (f == NULL) {
-               /* Try creating parent dir and then creating file. */
-               char *p = strrchr(pathname, '/');
-               if (p != NULL) {
-                       *p = '\0';
-                       create_dir(pathname, 0755);
-                       *p = '/';
-                       f = fopen(pathname, "w+");
-               }
-       }
-       return (f);
-}
-
 /*-----------------------------------------------------------------------------
   tar_get_item_offset
  ----------------------------------------------------------------------------*/
@@ -388,106 +326,6 @@ int tar_get_item_size(char *tar, char *item)
 }
 
 /*-----------------------------------------------------------------------------
-  tar_get_item_tye. (Dir/file/link etc)
- ----------------------------------------------------------------------------*/
-
-char tar_get_item_type(char *tar, char *item)
-{
-       char ret = '0';
-       int fd = -1;
-       char header[TAR_BLOCK_SIZE] = { 0, };
-       char uExtendedName[MAX_FILE_PATH + 1] = { 0, };
-       char size_oct[TAR_SIZE_OF_HEADER] = { 0, };
-       unsigned long size_dec = 0;
-       int blknum = 0;
-       off_t pos = 0;
-       off_t tar_len = 0;
-       ssize_t rdcnt = 0;
-
-       if (!item || !tar){
-               LOG("Invalid params\n");
-               return -1;
-       }
-       //LOG("Tar file Looking for (%s)\n", item);
-       fd = open(tar, O_RDONLY);
-       if (fd < 0) {
-               LOG("can't open file(%s).\n", tar);
-               return -1;
-       }
-
-       tar_len = lseek(fd, 0, SEEK_END);
-       if (tar_len < 0) {
-               LOGL(LOG_SSENGINE, "can't read tar_len (%s).\n", tar);
-               goto Cleanup;
-       }
-       pos = lseek(fd, 0, SEEK_SET);
-       if (pos < 0) {
-               LOGL(LOG_SSENGINE, "can't read pos (%s).\n", tar);
-               goto Cleanup;
-       }
-
-       while (pos < tar_len) {
-               /* read file header */
-               rdcnt = read(fd, header, sizeof(header));
-               if (rdcnt <= 0) {
-                       LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                       ret = -1;
-                       break;
-               }
-
-               /* get file name and file size */
-               if (header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGNAME || header[TAR_ITEM_TYPE_FLAG_POS] == GNUTYPE_LONGLINK) {
-                       //rdcnt = read(fd, header, sizeof(header));
-                       memset(uExtendedName, 0, sizeof(uExtendedName));
-                       rdcnt = read(fd, uExtendedName, sizeof(uExtendedName) - 1);
-                       if (rdcnt <= 0) {
-                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                               break;
-                       }
-                       rdcnt = read(fd, header, sizeof(header));
-                       if (rdcnt <= 0) {
-                               LOG("read failed. (rdcnt=%d)\n", rdcnt);
-                               break;
-                       }
-               } else {
-                       memset(uExtendedName, 0, sizeof(uExtendedName));
-                       memcpy(uExtendedName, header, TAR_ITEM_NAME_SIZE);
-               }
-               memcpy(size_oct, header + TAR_ITEM_SIZE_POSITION, sizeof(size_oct));
-               size_dec = strtoul(size_oct, NULL, TAR_SIZE_OF_ITEM_SIZE);
-               if (size_dec > MAX_ITEM_SIZE) {
-                       LOG("ITEM : [%s]\n", item);
-                       LOG("size too big. (size_dec=0x%08X)\n", (unsigned int)size_dec);
-                       ret = -1;
-                       break;
-               }
-
-               /* check if the file is what we are looking for */
-               if (strncmp(uExtendedName, item, sizeof(uExtendedName) - 1) == 0) {
-                       ret = header[TAR_ITEM_TYPE_FLAG_POS];
-                       break;
-               }
-
-               /* move file pointer to next file header */
-               blknum = size_dec / TAR_BLOCK_SIZE;
-               if (size_dec % TAR_BLOCK_SIZE)
-                       blknum++;
-
-               pos = lseek(fd, (off_t) (blknum * TAR_BLOCK_SIZE), SEEK_CUR);
-               if (pos < 0) {
-                       LOGL(LOG_SSENGINE, "can't read next block (%s).\n", tar);
-                       close(fd);
-                       return -1;
-               }
-       }
-
- Cleanup:
-       close(fd);
-
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
   tar_get_cfg_data
  ----------------------------------------------------------------------------*/
 int tar_get_cfg_data(char *tar, char *item, char *buf, int buflen)
@@ -748,18 +586,6 @@ int tar_get_item_size_from_struct(tar_Data_t ** delta_tar, const char *patchname
        }
 }
 
-tar_Data_t *tar_cfg_clear_nodes(tar_Data_t * head)
-{
-       tar_Data_t *local_temp = NULL;
-       while (head) {
-               LOGL(LOG_SSENGINE, "tar_cfg_delete_node [%s]\n", (char *)head->itemName);
-               local_temp = head->nextnode;
-               SS_Free(head);
-               head = local_temp;
-       }
-       return 0;
-}
-
 int tar_open(char *tar)
 {
        if (gTarFd >= 0)
@@ -874,188 +700,6 @@ int tar_get_folder_size(char *tar, char *item)
        return ret;                              //Should return +1?? or Ignore??
 }
 
-/*Extract Specific Folder from tar, Taken from Untar.c */
-int tar_extract_folder(char *tar, char *item, char *path)
-{
-       char buff[MAX_FILE_PATH];
-       FILE *f = NULL;
-       size_t bytes_read;
-       int filesize;
-       int data_offset = -1;
-       int fd = -1;
-       char name[512] = { 0, };
-       int folderpathlen = 0;
-       char dirPath[512] = { 0 };
-       int getheader = 1;                // Asuming initial header is TAR header
-       char fullname[512] = { 0 };
-       int ret;
-
-       if (!item || !tar || !path){
-               LOG("Invalid params\n");
-               return -1;
-       }
-       LOG("Extracting Folder from %s %s to %s\n", tar, item, path);
-
-       data_offset = tar_get_item_offset(tar, item);
-       if (data_offset < 0) {
-               LOGE("data offset for [%s] is [%d]\n", item, data_offset);
-               return -1;
-       }
-
-       fd = open(tar, O_RDONLY);
-       if (fd < 0) {
-               LOGE("can't open file(%s).\n", tar);
-               return -1;
-       }
-
-       folderpathlen = strlen(item);
-
-       for (;;) {
-               bytes_read = read(fd, buff, sizeof(buff));
-               if (bytes_read < 512) {
-                       LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
-                       close(fd);
-                       return -1;
-               }
-               if (is_end_of_archive(buff)) {
-                       close(fd);
-                       LOG("End of %s\n", tar);        //Can stop at end of folder.
-                       return S_SS_SUCCESS;
-               }
-               if (!verify_checksum(buff)) {
-                       close(fd);
-                       LOGE("Checksum failure\n");
-                       return -1;
-               }
-               filesize = parseoct(buff + 124, 12);
-               if (getheader == 2) {
-                       getheader = 1;
-                       //LOG(" Working on LONG FILE NAME CASE [%s]\n", fullname);
-               } else {
-                       memset(fullname, 0, sizeof(fullname));
-                       strncpy(fullname, buff, 100);
-                       //LOG(" Working on Normal FILE NAME CASE [%s]\n", fullname);
-               }
-
-               switch (buff[156]) {
-               case '1':
-                       LOG(" Ignoring hardlink %s\n", fullname);
-                       break;
-               case '2':
-
-                       //LOG(" Creating symlink %s\n", buff);
-                       if (strncmp(fullname, item, folderpathlen) == 0) {
-                               //LOG("Printing Buffer \n");
-                               //for(i=157; buff[i] !='\0' ;i++)
-                               //{
-                               //LOG("%c", buff[i])    ;
-                               //}
-                               //LOG("\nEnd buffer\n");
-                               memset(name, 0, sizeof(name));
-                               strncpy(name, buff + 157, 100); //157, target link name will be present
-                               memset(dirPath, 0, sizeof(dirPath));
-                               snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                               LOG(" Creating Symlink [%s][%s]\n", name, dirPath);
-                               ret = symlink(name, dirPath); // use ss_link
-                               if (ret < 0)
-                                       LOG("Error with symlink: %d\n", errno);
-                       }
-                       break;
-               case '3':
-                       LOG(" Ignoring character device %s\n", fullname);
-                       break;
-               case '4':
-                       LOG(" Ignoring block device %s\n", fullname);
-                       break;
-               case '5':
-                       //break;//delete
-                       //LOG(" Dir [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
-                       if (strncmp(fullname, item, folderpathlen) == 0) {
-                               //LOG(" Extracting dir %s\n", fullname);
-                               memset(dirPath, 0, sizeof(dirPath));
-                               snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                               create_dir(dirPath, parseoct(fullname + 100, 8));
-                       }
-
-                       filesize = 0;
-                       break;
-               case '6':
-                       LOG(" Ignoring FIFO %s\n", fullname);
-                       break;
-               case GNUTYPE_LONGLINK:
-               case GNUTYPE_LONGNAME:
-                       {
-                               getheader = 2;
-                               memset(fullname, 0, sizeof(fullname));
-                               bytes_read = read(fd, fullname, sizeof(fullname));
-                               if (bytes_read < 512) {
-                                       LOGE("Short read on %s: expected 512, got %d\n", tar, bytes_read);
-                                       close(fd);
-                                       return -1;
-                               }
-                               filesize = 0;
-                               //LOG("Entered LONG FILE NAME CASE  new NAME is [%s]\n", fullname);
-                               break;
-                       }
-
-               default:
-                       //break;
-                       //LOG(" File [%s] Item [%s] Length [%d]\n", fullname, item, folderpathlen);
-                       if (strncmp(fullname, item, folderpathlen) == 0) {
-                               if (buff[PREFIX_INDICATOR_BYTE] != 0) {
-                                       memset(name, 0, sizeof(name));
-                                       memset(dirPath, 0, sizeof(dirPath));
-                                       strncpy(name, buff, 100);
-                                       snprintf(name + strlen(name), sizeof(name) - strlen(name),
-                                                       "%s", buff + PREFIX_INDICATOR_BYTE);
-                                       snprintf(dirPath, sizeof(dirPath), "%s/%s", path, name + folderpathlen);
-                                       LOG(" File Name is longer than 100 bytes -Remaining Str [%s]\n Full Str[%s]\n", dirPath, fullname);
-                               } else {
-                                       //LOG(" Extracting file %s\n", fullname);
-                                       memset(dirPath, 0, sizeof(dirPath));
-                                       snprintf(dirPath, sizeof(dirPath), "%s/%s", path, fullname + folderpathlen);
-                                       f = create_file(dirPath);
-                               }
-                       }
-
-                       break;
-               }
-
-               while (filesize > 0) {
-                       bytes_read = read(fd, buff, sizeof(buff));
-                       if (bytes_read < 512) {
-                               LOGE("Short read on %s: Expected 512, got %d\n", tar, bytes_read);
-                               close(fd);
-                               if (f) {
-                                       fclose(f);//wgid: 16892
-                                       f = NULL;
-                               }
-                               return -1;
-                       }
-                       if (filesize < 512)
-                               bytes_read = filesize;
-                       if (f != NULL) {
-                               if (fwrite(buff, 1, bytes_read, f)
-                                       != bytes_read) {
-                                       LOG("Failed write\n");
-                                       fclose(f);
-                                       f = NULL;
-                                       close(fd);//wgid: 59268
-                                       return -1;//wgid: 16892
-                               }
-                       }
-                       filesize -= bytes_read;
-               }
-               if (f != NULL) {
-                       fclose(f);
-                       f = NULL;
-               }
-
-       }
-       close(fd);
-       return S_SS_SUCCESS;
-}
-
 int fast_tar_extract_file(char *tar, char *item, char *pathname, int size, int offset)
 {
        int fd = -1;
index cb53ca7..5adb0ad 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * libtota
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
  * FOTA Adaptaion header
  */
 
-#define UA_PARTI_MAX                   20      //currently supporting max 20 partitions
-
 #define UI_OP_SCOUT_UPDATE             0
 #define UI_OP_SCOUT                    1
 #define UI_OP_UPDATE                   3
 
-typedef enum {
-       FULL_IMAGE,
-       DELTA_IMAGE,
-       DELTA_FS,
-       EXTRA
-} UA_DATA_FORMAT;
-
-typedef enum {
-       BEFORE_BOOT_FOTA,
-       AT_BOOT_FOTA
-} UPDATE_WHEN;
-
-typedef enum {
-       UA_MODE_SCOUT_UPDATE,
-       UA_MODE_SCOUT,
-       UA_MODE_VERIFYTARGET,
-       UA_MODE_UPDATE,
-       UA_MODE_SUPPLYIMFOM = 200
-} UA_OPERATION_MODE;
-
 typedef struct _ua_update_data_t {
-       unsigned int exist_check;
-       unsigned int verify_check;
-       unsigned int update_check;
        unsigned int weight; // the sum of weight should be 100
        unsigned int weight_offset; // start offset
        unsigned int data_size; // byte
        char *ua_delta_path; // it will be allocated to copy delta file path, need to free memory
        char *ua_temp_path; // it will be allocated to copy delta file path, need to free memory
+       char *ua_delta_folder;
 } ua_update_data_t;
 
 typedef struct _ua_update_cfg_t {
-       unsigned int update_type;
-       unsigned int update_when;
        int skip_verify;
        int skip_update;
-       int soure_img_size; //TOTA
-       int target_img_size;
-       char *soure_sha1;
-       char *target_sha1;
+       int source_img_size; //TOTA
 } ua_update_cfg_t;
 
 typedef struct _ua_part_info_t {
        char *ua_parti_name;
        char *ua_subject_name;
-       char *ua_blk_name;
-       char *ua_blk_name_previous;
-       int ua_blk_offset;
 } ua_part_info_t;
 
 // User data structure
@@ -112,4 +80,6 @@ typedef struct _ua_dataSS_t { // partition operations
        int (*write_data_to_blkdev)(char *, int, int, char *);
 } ua_dataSS_t;
 
+typedef unsigned int SS_UINT32;
+
 #endif
index 23747e2..033e558 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
index 0afd301..e55d223 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 -2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
index 4e0b46b..a8552df 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #include <unistd.h>
 #include <errno.h>
 
-#include "fota_common.h"
+#include "engine/fota_common.h"
 
 int s_fd_stdin = -1;
 int s_fd_stdout = -1;
 int s_fd_stderr = -1;
 
 /*-----------------------------------------------------------------------------
-  set_default_stdio
- ----------------------------------------------------------------------------*/
-static int set_default_stdio(int flags, int nfd)
-{
-       int fd, r;
-
-       fd = open("/dev/null", flags|O_NOCTTY);
-       if (fd < 0)
-               return -errno;
-
-       if (fd == nfd) {
-               return fd;
-       } else {
-               r = dup2(fd, nfd) < 0 ? -errno : nfd;
-               close(fd);
-               return r;
-       }
-}
-
-/*-----------------------------------------------------------------------------
-  _init_stdio
- ----------------------------------------------------------------------------*/
-void _init_stdio(void)
-{
-       s_fd_stdin = set_default_stdio(O_RDONLY, STDIN_FILENO);
-
-       s_fd_stdout = set_default_stdio(O_WRONLY, STDOUT_FILENO);
-
-       s_fd_stderr = set_default_stdio(O_WRONLY, STDERR_FILENO);
-}
-
-/*-----------------------------------------------------------------------------
   _exit_stdio
  ----------------------------------------------------------------------------*/
 void _exit_stdio(void)
@@ -146,49 +114,3 @@ int _system_cmd_nowait(const char *command)
 
        return 0;
 }
-
-/*-----------------------------------------------------------------------------
-  check_existence
- ----------------------------------------------------------------------------*/
-long check_existence(const char *file_path)
-{
-       struct stat statbuf;
-       char filename[MAX_FILE_PATH];
-       char buf[256];
-
-       LOG("%s: %s\n", __func__ , file_path);
-       if (strncpy(filename, file_path, sizeof(filename) - 1) == NULL) {
-               LOG("strncpy error=%s\n", filename);
-               return 0;
-       }
-       if (stat(filename, &statbuf)) {
-               if (ENOENT == errno) {
-                       strerror_r(errno, buf, sizeof(buf));
-                       LOG("stat %s: %s\n", filename, buf);
-                       return 0;
-               }
-       }
-       LOG("%s: statbuf.st_size = %d\n", __func__ , (int)statbuf.st_size);
-       return statbuf.st_size;
-}
-
-/*-----------------------------------------------------------------------------
-  make_temp_file
- ----------------------------------------------------------------------------*/
-void make_temp_file(char *temp_file, int file_size)
-{
-       FILE *fp;
-       int i = 0, temp = 0;
-
-       LOG("Make %s file\n", temp_file);
-
-       fp = fopen(temp_file, "wb");
-       if (!fp) {
-               LOGE("failed to fopen\n");
-               return;
-       }
-       for (i = 0; i < file_size; i++)
-               fwrite(&temp, sizeof(int), 1, fp);
-       fclose(fp);
-}
-
index 184ef65..ae0e568 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #ifndef _FOTA_UTIL_H_
 #define _FOTA_UTIL_H_
 
-extern void _init_stdio(void);
 extern void _exit_stdio(void);
 extern int _system_cmd_wait(const char *command);
 extern int _system_cmd_nowait(const char *command);
-extern long check_existence(const char *file_path);
-extern void make_temp_file(char *temp_file, int file_size);
-
 
 #endif /* _FOTA_UTIL_H_ */
 
index ac6652e..479ccdf 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 - 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
 #include <fcntl.h>
 #include <unistd.h>
 #include <string.h>
-#include <blkid/blkid.h>
+#include <getopt.h>
 
 #include <hal/device/hal-board.h>
 
-#include "SS_Common.h"
-#include "fota_common.h"
-#include "ua.h"
-#include "ua_types.h"
-#include "mmc_io.h"
 #include "fota_cfg.h"
-#include "fota_tar.h"
+#include "ua.h"
 #include "fota_util.h"
-#include "SS_UPI.h"
-#include "blkid-api.h"
+#include "engine/SS_Common.h"
+#include "engine/SS_UPI.h"
+#include "engine/fota_common.h"
+#include "engine/fota_tar.h"
+#include "engine/ua_types.h"
 
-#define MAX_CFG_LEN    4096
 
-#define RAMDISK_PATH           "/opt/usr/data/fota"
 #define SYSTEM_LOG_DIR         "/opt/var/log"
+#define TEMP_FOLDER         "/tmp" // TODO
 
-int ua_op_mode = UA_OP_MODE_FG;
-char ua_slot_mode = 0;
+//char ua_slot_mode = 0;
 int dm_verity_status = DM_VERITY_DISABLED;
 
 // TODO: Consider changing all to PATH_MAX
@@ -65,15 +61,19 @@ static char log_folder[MAX_FOLDER_PATH];
 static char result_folder[MAX_FOLDER_PATH];
 static char temp_folder[MAX_FOLDER_PATH];
 static char log_path[MAX_FILE_PATH];
-static char blk_dev_arg[PATH_MAX] = "/dev/mmcblk0";
 
-static ua_part_info_t s_part_info[UA_PARTI_MAX];
+static ua_part_info_t s_part_info;
+
+static ua_update_cfg_t s_update_cfg;
 
-static ua_update_cfg_t s_update_cfg[UA_PARTI_MAX];
+static ua_update_data_t s_update_data;
 
-static ua_update_data_t s_update_data[UA_PARTI_MAX];
+typedef struct temp_opt{
+    char * archive;
+    char * archive_file;
+    char * dest;
+}temp_opt;
 
-static int s_part_num = 0;
 static ua_delta_info_t s_delta_info;
 
 unsigned int __log_level__ =
@@ -83,9 +83,6 @@ FILE *__log_out_file__;
 static void save_result(int result);
 static void save_cause(int cause);
 
-/*-----------------------------------------------------------------------------
-  fota_gui_update_progress
- ----------------------------------------------------------------------------*/
 #define TMP_DIR "/tmp/upgrade"
 #define PROGRESS_FILE TMP_DIR "/ro_progress"
 
@@ -97,17 +94,10 @@ void print_usage(const char *msg)
        if (msg) {
                printf("%s\n", msg);
        }
-       printf("USAGE: delta.ua delta_dir output_dir [operation_mode] [upgrade_slot block_device]\n"
+       printf("print_usage: delta.ua --archive delta_dir --dest label --archive-file label.img\n"
        "delta_dir: directory path where delta.tar file is located\n"
-       "output_dir: directory path for log file, result file, temporary file\n"
-       "operation_mode: run program in Background Mode: 0 or Foreground Mode: 1\n"
-       "upgrade_slot: upgrade slot number \"a\" or \"b\" It is used for A|B upgrade mode.\n"
-       "    When it is set delta.ua will not read hardcoded partitions from config file.\n"
-       "    Program will use libblkid to determine it based on GPT partition label.\n"
-       "    e.g. delta.ua will try to update rootfs from a slot, so it will search for rootfs_a label\n"
-       "    NOTE: if this argument is set block_device have to be specified.\n"
-       "block_device: block device that partitions for upgrade are on. e.g. /dev/mmcblk0\n"
-       "    NOTE: if this argument is set upgrade_slot have to be specified.\n"
+       "label: label of the partition to be updated\n"
+       "label.img: name of the file inside of delta that is to be used during upgrade\n"
        );
 }
 
@@ -122,7 +112,7 @@ void print_error_code(int err)
                printf("%s delta path error.\n", msg);
                break;
        case UPI_DELTA_PATH_LENGTH_ERROR:
-               printf("%s delta path lenght error.\n", msg);
+               printf("%s delta path length error.\n", msg);
                break;
        case UPI_VERSION_ERROR:
                printf("%s version error.\n", msg);
@@ -216,6 +206,7 @@ static void set_upgrade_progress(int percent)
 /*-----------------------------------------------------------------------------
   fota_gui_progress
  ----------------------------------------------------------------------------*/
+ // TODO - remove this mechanism, only makes log less readable
 void fota_gui_progress(void * pbUserData, unsigned long uPercent)
 {
        int percent;
@@ -261,181 +252,15 @@ void fota_gui_progress(void * pbUserData, unsigned long uPercent)
 }
 
 /*-----------------------------------------------------------------------------
-  write_data_to_blkdev
-  - blk_start : start sector number
-  - blk_cnt : number of sectors to write
-  - data length should be blk_cnt x SECTOR_SIZE
- ----------------------------------------------------------------------------*/
-static int write_data_to_blkdev(char* dev_name, int blk_start, int blk_cnt, char* data)
-{
-       int fd_mmc;
-
-       LOG("%s: entered start offset=%d sectos, size=%d sectos\n",  dev_name, blk_start, blk_cnt);
-       /* destination MMC device open */
-       fd_mmc = mmc_dev_open(dev_name, O_RDWR);
-       if (fd_mmc < 0) {
-               LOG("mmc_dev_open() fail ...\n");
-               return FAIL;
-       }
-
-       if (mmc_dev_sector_write(fd_mmc, blk_start, blk_cnt, data) < 0) {
-               LOG("mmc_dev_sector_write() fail ...\n");
-               mmc_dev_close(fd_mmc);
-               return FAIL;
-       }
-
-       mmc_dev_close(fd_mmc);
-       LOG("%s: leaved\n", __func__);
-
-       return SUCCESS;
-}
-
-/*-----------------------------------------------------------------------------
-  write_full_image
- ----------------------------------------------------------------------------*/
-static int write_full_image(ua_dataSS_t* ua_data, int part_idx)
-{
-       int ret = SUCCESS;
-       int blk_start = 0;
-       int blk_cnt = 0;
-       int read_count = 0, data_length = 0;
-       char* data = NULL;
-       int bin_size = 0, offset = 0;
-       ua_part_info_t *ua_part_info = ua_data->parti_info;
-       ua_update_data_t *ua_update_data = ua_data->update_data;
-
-       FILE *fp;
-
-       LOG("ua_delta_path=%s, ua_subject_name=%s\n", ua_update_data->ua_delta_path, ua_part_info->ua_subject_name);
-
-       fp = fopen(ua_update_data->ua_delta_path, "r");
-       if (!fp) {
-               LOGE("open file %s failed.\n",  ua_update_data->ua_delta_path);
-               return FAIL;
-       }
-
-       bin_size = tar_get_item_size(ua_update_data->ua_delta_path, ua_part_info->ua_subject_name);
-       if (bin_size <= 0) {
-               LOGE("bin_size=%d\n", bin_size);
-               fclose(fp);
-               return FAIL;
-       }
-       offset = tar_get_item_offset(ua_update_data->ua_delta_path, ua_part_info->ua_subject_name);
-       if (offset < 0) {
-               LOGE("offset=%d\n", offset);
-               fclose(fp);
-               return FAIL;
-       }
-
-       blk_cnt = ((bin_size-1)/SECTOR_SIZE)+1;
-       data_length = blk_cnt * SECTOR_SIZE;
-       LOG("bin_size=%d, data_length=%d\n", bin_size, data_length);
-
-       if (fseek(fp,  offset,  SEEK_SET) < 0) {
-               LOGE("fseek() fail\n");
-               fclose(fp);
-               return FAIL;
-       }
-
-       data = malloc(data_length);
-       if (data) {
-               read_count = fread(data, 1, bin_size, fp);
-               LOG("read file read_count=%d byte, blk_cnt=%d\n",  read_count, blk_cnt);
-               if (read_count != bin_size) {
-                       LOGE("error in read size\n");
-                       if (data)
-                               free(data);
-                       if (fp)
-                               fclose(fp);
-                       return FAIL;
-               }
-
-               if (write_data_to_blkdev(ua_part_info->ua_blk_name,
-                               blk_start, blk_cnt, data) != SUCCESS) {
-                       LOGE("error in write_data_to_blkdev()\n");
-                       ret = FAIL;
-               }
-
-               if (data)
-                       free(data);
-       }
-
-       if (fp)
-               fclose(fp);
-
-       LOG("%s leaved\n", __func__);
-
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
-  verify_Full_Image
- ----------------------------------------------------------------------------*/
-int verify_Full_Image(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 = SUCCESS;//SS_IMGVerfiyPartition(&ua_dataSS);
-               fota_gui_progress(&ua_dataSS, 100);
-       }
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
-  update_Full_Image
- ----------------------------------------------------------------------------*/
-int update_Full_Image(int part_idx)
-{
-       int ret = FAIL;
-       ua_dataSS_t ua_data;
-       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_data.parti_info = ua_part_info;
-       ua_data.update_cfg = ua_update_cfg;
-       ua_data.update_data = ua_update_data;
-       ua_data.ui_progress = fota_gui_progress;
-       ua_data.ua_operation = UI_OP_UPDATE;
-
-       LOG("%s entered\n", __func__);
-
-       ret = write_full_image(&ua_data, part_idx);
-       if (ret != SUCCESS) {
-               LOGE("%s entered\n", __func__);
-               goto CleanUp;
-       }
-
-       fota_gui_progress(&ua_data, 100);       /* display completion of update_Sbl */
-
- CleanUp:
-
-       LOG("%s leaved ret=%d\n", __func__, ret);
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
   verify_Delta_FS
  ----------------------------------------------------------------------------*/
-int verify_Delta_FS(int part_idx)
+int verify_Delta_FS()
 {
        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_part_info_t *ua_part_info = &s_part_info;
+       ua_update_cfg_t *ua_update_cfg = &s_update_cfg;
+       ua_update_data_t *ua_update_data = &s_update_data;
        ua_delta_info_t *ua_delta_info = &s_delta_info;
        ua_dataSS.parti_info = ua_part_info;
        ua_dataSS.update_cfg = ua_update_cfg;
@@ -446,7 +271,7 @@ int verify_Delta_FS(int part_idx)
 
        if (ua_update_data->ua_delta_path != NULL) {
                LOG("Verifying %s \n", ua_dataSS.parti_info->ua_parti_name);
-               ret = SS_FSVerifyPartition(&ua_dataSS, part_idx);
+               ret = SS_FSVerifyPartition(&ua_dataSS);
        }
 
        return ret;
@@ -455,13 +280,13 @@ int verify_Delta_FS(int part_idx)
 /*-----------------------------------------------------------------------------
   update_Delta_FS
  ----------------------------------------------------------------------------*/
-int update_Delta_FS(int part_idx, unsigned long ui32Operation)
+int update_Delta_FS(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_part_info_t *ua_part_info = &s_part_info;
+       ua_update_cfg_t *ua_update_cfg = &s_update_cfg;
+       ua_update_data_t *ua_update_data = &s_update_data;
        ua_delta_info_t *ua_delta_info = &s_delta_info;
        ua_dataSS.parti_info = ua_part_info;
        ua_dataSS.update_cfg = ua_update_cfg;
@@ -471,166 +296,32 @@ int update_Delta_FS(int part_idx, unsigned long ui32Operation)
        ua_dataSS.ui_progress = fota_gui_progress;
 
        if (ua_update_data->ua_delta_path != NULL)
-               ret = SS_FSUpdatemain(&ua_dataSS, part_idx);
-
-       return ret;
-}
-
-/*-----------------------------------------------------------------------------
-  verify_Delta_IMAGE
- ----------------------------------------------------------------------------*/
-int verify_Delta_IMAGE(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_previous, false);
-
-       return ret;
-}
+               ret = SS_FSUpdatemain(&ua_dataSS);
 
-/*-----------------------------------------------------------------------------
-  update_Delta_IMAGE
- ----------------------------------------------------------------------------*/
-int update_Delta_IMAGE(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_IMAGE);
-       return ret;
-}
-
-int verify_RecoveryDelta_IMAGE(int part_idx, int update_type)
-{
-       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 (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_IMAGE) {
-               if (ua_update_data->ua_delta_path != NULL)
-                       ret = SS_IMGVerfiyPartition(&ua_dataSS, ua_dataSS.parti_info->ua_blk_name, true);
-       }
-       return ret;
-}
-
-
-int update_RecoveryDelta_IMAGE(int part_idx, int update_type)
-{
-       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.update_data->ua_temp_path = malloc(MAX_FILE_PATH);
-       ua_dataSS.ua_operation = UI_OP_SCOUT_UPDATE;
-       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_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;
 }
 
-
 /*-----------------------------------------------------------------------------
   set_data_weight
  ----------------------------------------------------------------------------*/
 /* set data weight using data size minimum:1 total: 100 */
+// TODO - remove
 static void set_data_weight(unsigned int total_data_size)
 {
-       int i = 0, big = 0, weight = 0, total_weight = 0;
-
        LOG("%s entered, total_data_size=%u\n", __func__, total_data_size);
-
-       for (i = 0; i < s_part_num; i++) {
-               if (s_update_data[i].exist_check) {
-                       s_update_data[i].weight = 100 * (unsigned long long)s_update_data[i].data_size / total_data_size;
-
-                       if (s_update_data[i].weight == 0)
-                               s_update_data[i].weight = 1;
-
-                       if (weight < s_update_data[i].weight) {
-                               weight = s_update_data[i].weight;
-                               big = i;
-                       }
-
-                       total_weight += s_update_data[i].weight;
-               }
-
-               LOG("[%d] exist_check=%d, weight=%u total_weight=%u\n",
-                       i, s_update_data[i].exist_check, s_update_data[i].weight, total_weight);
-       }
-
-       if (total_weight < 100)
-               s_update_data[big].weight += (100 - total_weight);
-       else
-               s_update_data[big].weight -= (total_weight - 100);
-
-       LOG("[big: %d] weight=%u\n", big, s_update_data[big].weight);
-
+       s_update_data.weight = 100;
        LOG("%s leaved\n", __func__);
 }
 
 /*-----------------------------------------------------------------------------
   set_data_weight_offset
  ----------------------------------------------------------------------------*/
+ // TODO - remove
 static void set_data_weight_offset(void)
 {
-       int i = 0, k = 0;
-
        LOG("%s entered\n", __func__);
-
-       for (i = 0; i < s_part_num; i++) {
-               for (k = 0; k < i; k++)
-                       s_update_data[i].weight_offset += s_update_data[k].weight;
-
-               LOG("s_update_data[%d].weight_offset=%u\n", i, s_update_data[i].weight_offset);
-       }
-
+       s_update_data.weight_offset = 0; // not sure what it does, keep it like this for now
+    LOG("s_update_data.weight_offset=%u\n", s_update_data.weight_offset);
        LOG("%s leaved\n", __func__);
 }
 
@@ -654,69 +345,43 @@ static void get_time_stamp(void)
  ----------------------------------------------------------------------------*/
 int update_all()
 {
-       int i, data_count = 0, ret = OK;
-       unsigned long total_data_size = 0;
-       int cause = 0;
-       int item_size = 0;
+       int ret = OK;
+       int cause = 0, item_size = 0;
        int last_update_status = UP_START_NONE;
        int update_status = UP_START_NONE;
-       int del_type = 0;       // delta type
-       int part_idx = UA_PARTI_MAX;
-       unsigned int update_type = 0;
        unsigned long ui32Operation = UI_OP_SCOUT;
+       int del_type = 0; // TODO, for clarity
+       char status_path[MAX_FILE_PATH];
+       snprintf(status_path, MAX_FILE_PATH, "%s/%s",s_update_data.ua_delta_folder, SS_UPDATE_STATUS_PATH);
 
-       LOG("%s entered\n", __func__);
+       item_size = tar_get_item_size(s_update_data.ua_delta_path, s_part_info.ua_subject_name);
+       if (item_size > 0)
+               s_update_data.data_size = (unsigned int)item_size;
+       else
+               s_update_data.data_size = 0;
 
-       data_count = 0;
+    LOGL(LOG_DEBUG, "s_update_data.data_size=%lu, ua_delta_path=%s, "
+               "ua_subject_name=%s\n",
+               (long unsigned int)s_update_data.data_size,
+               s_update_data.ua_delta_path,
+               s_part_info.ua_subject_name);
 
-       for (i = 0; i < s_part_num; i++) {
-               item_size = tar_get_item_size(s_update_data[i].ua_delta_path, s_part_info[i].ua_subject_name);
-               if (item_size > 0)
-                       s_update_data[i].data_size = (unsigned int)item_size;
-               else
-                       s_update_data[i].data_size = 0;
-
-               LOGL(LOG_DEBUG, "s_update_data[%d].data_size=%lu, ua_delta_path=%s, "
-                       "ua_blk_name = %s, ua_subject_name=%s\n",
-                       i,
-                       (long unsigned int)s_update_data[i].data_size,
-                       s_update_data[i].ua_delta_path,
-                       s_part_info[i].ua_blk_name,
-                       s_part_info[i].ua_subject_name);
-
-               if (s_update_data[i].data_size) {
-                       data_count++;
-
-                       s_update_data[i].exist_check = 1;
-                       total_data_size += s_update_data[i].data_size;
-
-                       LOGL(LOG_DEBUG,
-                               "Check Delta : part_idx(%d), file_path(%s), total data cnt(%lu)\n",
-                               i, s_update_data[i].ua_delta_path,
-                               (long unsigned int)data_count);
-               }
-       }
-
-       LOG("data_count=%lu, total_data_size=%lu\n",
-               (long unsigned int)data_count, (long unsigned int)total_data_size);
-       if (data_count == 0) {
+       if (s_update_data.data_size <= 0) {
                ret = UPI_DELTACOUNT_ERROR;
                sleep(3);
 
                goto CleanUp;
        }
        LOG(" set weight to draw progressive bar.....\n");
-       set_data_weight(total_data_size);
+       set_data_weight(s_update_data.data_size);
        set_data_weight_offset();
 
-       for (i = 0; i < s_part_num; i++) {
-               LOG("s_part_info[%s].ua_delta_path = %s ua_subject_name=%s\n",
-                       s_part_info[i].ua_parti_name,
-                       s_update_data[i].ua_delta_path,
-                       s_part_info[i].ua_subject_name);
-       }
+       LOG("s_part_info.ua_parti_name = %s ua_delta_path = %s ua_subject_name=%s\n",
+               s_part_info.ua_parti_name,
+               s_update_data.ua_delta_path,
+               s_part_info.ua_subject_name);
 
-       if (SS_Get_last_update_status(&last_update_status, &del_type) == -1)
+       if (SS_Get_last_update_status(&last_update_status, &del_type, status_path) == -1)
                LOG("No last_update_status. Go normal update scenario.\n");
        else
                LOG("Get last_update_status. Go Power safe update scenario.\n");
@@ -724,34 +389,19 @@ int update_all()
        LOG("last_update_status: [%d], del_type: [%d] \n", last_update_status, del_type);
        /* Verify */
        if (last_update_status == UP_START_NONE) {
-               for (part_idx = 0; part_idx < s_part_num; part_idx++) {
-                       if (s_update_data[part_idx].data_size > 0) {
-                               get_time_stamp();
-                               LOG("[%s] Verify %s ..............................................................\n", ts,
-                                       s_part_info[part_idx].ua_parti_name);
-                               update_type = s_update_cfg[part_idx].update_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;
-                               }
-                               if (update_type == FULL_IMAGE)
-                                       ret = verify_Full_Image(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_IMAGE(part_idx, FULL_IMAGE);
-                               else
-                                       ret = -1;
-
-                               if (ret != OK) {
-                                       cause = ret;
-                                       ret = UPI_VERIFY_ERROR;
-                                       LOG("%s verify fail\n", s_part_info[part_idx].ua_parti_name);
-                                       goto CleanUp;
-                               }
-                               s_update_data[part_idx].verify_check = 1;
+
+               if (s_update_data.data_size > 0) {
+                       get_time_stamp();
+                       LOG("[%s] Verify %s ..............................................................\n", ts,
+                               s_part_info.ua_parti_name);
+
+                       ret = verify_Delta_FS();
+                       LOG("return form verify : %d\n", ret);
+                       if (ret != OK) {
+                               cause = ret;
+                               ret = UPI_VERIFY_ERROR;
+                               LOG("%s verify fail\n", s_part_info.ua_parti_name);
+                               goto CleanUp;
                        }
                }
 
@@ -761,52 +411,26 @@ int update_all()
        LOG("[%s] Verify End ..............................................................\n", ts);
 
        /* Update */
-       for (part_idx = 0; part_idx < s_part_num; part_idx++) {
-               update_status = part_idx;
-               if (last_update_status <= update_status) {
-                       if (last_update_status == update_status)
-                               ui32Operation = UI_OP_SCOUT_UPDATE;
-                       else
-                               ui32Operation = UI_OP_UPDATE;
-
-                       if (s_update_data[part_idx].data_size > 0) {
-                               get_time_stamp();
-                               LOG("[%s] Update %s ..............................................................\n", ts,
-                                       s_part_info[part_idx].ua_parti_name);
-
-                               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_IMAGE)
-                                       ret = update_Full_Image(part_idx);
-                               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_IMAGE(part_idx, FULL_IMAGE);
-                               else
-                                       ret = -1;
-
-                               if (ret != OK) {
-                                       cause = ret;
-                                       ret = UPI_UPDATE_ERROR;
-                                       LOG("%s update fail\n", s_part_info[part_idx].ua_parti_name);
-                                       goto CleanUp;
-                               }
-                               s_update_data[part_idx].update_check = 1;
-                               del_type = 0;
-                       }
+       ui32Operation = UI_OP_SCOUT_UPDATE;
+
+
+       if (s_update_data.data_size > 0) {
+               get_time_stamp();
+               LOG("[%s] Update %s ..............................................................\n", ts,
+                       s_part_info.ua_parti_name);
+
+               SS_Set_last_update_status(update_status, del_type, status_path); // i have to look into what it does
+
+               ret = update_Delta_FS(ui32Operation);
+               LOG("return form update : %d\n", ret);
+               if (ret != OK) {
+                       cause = ret;
+                       ret = UPI_UPDATE_ERROR;
+                       LOG("%s update fail\n", s_part_info.ua_parti_name);
+                       goto CleanUp;
                }
        }
 
-       if (part_idx == s_part_num)
-               SS_Set_last_update_status(s_part_num, 0);
-
        get_time_stamp();
        LOG("[%s] Update End ..............................................................\n", ts);
 
@@ -823,14 +447,13 @@ int update_all()
 void log_init(void)
 {
        memset(log_path, 0x00, sizeof(log_path));
-       snprintf(log_path, sizeof(log_path), "%s%s", log_folder, LOG_FILE_PATH);
+       snprintf(log_path, sizeof(log_path), "%s", LOG_FILE_PATH);
 
        __log_out_file__ = fopen(log_path, "w");
        if (__log_out_file__ == NULL) {
                perror("file open error\n");
                return;
        }
-
        get_time_stamp();
        LOG("===== log start [%s] =====\n", ts);
 }
@@ -857,38 +480,22 @@ void log_deinit(void)
 static void print_error_cause(int error)
 {
        switch (error) {
-       case E_SS_PKG_CORRUPTED:
-       case E_SS_SOURCE_CORRUPTED: /* not used */
-       case E_SS_IMGBADDELTA:
        case E_SS_FSBADDELTA:
                LOG("Corrupted firmware update package, did not store correctly.  Detected, for example, by mismatched CRCs between actual and expected.\n");
                break;
        case E_SS_BAD_PARAMS:
                LOG("Wrong Firmware Update Package delivered to device based on current device characteristics\n");
                break;
-       case E_SS_INVALID_DP_HEADER:
-       case E_SS_INVALID_DP_WRONG_SIGNATURE:
-               LOG("Failure to positively validate digital signature of firmware update package\n");
-               break;
-       case E_SS_PKG_TOO_LONG: /* not used */
-               LOG("Firmware Update Package is Not Acceptable\n");
-               break;
-       case E_SS_NOT_ENOUGH_RAM:
        case E_SS_MALLOC_ERROR:
                LOG("The update fails because there isn't sufficient memory to update the device.\n");
                break;
        case E_SS_FSSRCBACKUPFAILED:
-       case E_SS_IMGSRCBACKUPFAILED:
-       case E_SS_IMGRECOVERYWRITEFAILED:
-       case E_SS_IMGFLASHWRITEFAIL:
        case E_SS_WRITE_ERROR:
        case E_SS_FSFAILEDTOBACKUPPATCHINFO:
        case E_SS_FSBADATTRIBUTES:
                LOG("The update failed because writing data to the device was unsuccessful.\n");
                break;
        case E_SS_FSSRCCURRUPTED:
-       case E_SS_IMGSRCCURRUPTED:
-       case E_SS_IMGSHA_MISMATCH:
        case E_SS_FSSHA_MISMATCH:
        case E_SS_FSFAILEDTOPARSEDELTACNT:
        case E_SS_FSFAILEDTOOPENPATCHINFO:
@@ -931,6 +538,7 @@ E_RB_PKG_NOT_AUTHORIZED(0x8000000F)
 The update fails because there isn\A1\AFt sufficient memory to update the device.
 E_RB_NOT_ENOUGH_RAM(0x8000001E)
 */
+
 /*-----------------------------------------------------------------------------
   save_cause
  ----------------------------------------------------------------------------*/
@@ -984,33 +592,24 @@ void save_result(int result)
  ----------------------------------------------------------------------------*/
 int fota_path_init(void)
 {
-       int i;
-
        if (strlen(delta_folder) > MAX_FILE_PATH - 15) {
                LOG("FOTA path is too long\n");
                return FAIL;
        }
 
-       for (i = 0; i < s_part_num; i++) {
-               s_update_data[i].ua_delta_path = malloc(MAX_FILE_PATH);
-               if (s_update_data[i].ua_delta_path == NULL) {
-                       LOG("Memory allocation fail\n");
-                       return FAIL;
-               }
-               snprintf(s_update_data[i].ua_delta_path, MAX_FILE_PATH, "%s/%s", delta_folder, DEFAULT_DELTA_NAME);
-               //will be filled by UA if required (eg : RAMDISK case in TOTA)
-               //s_update_data[i].ua_temp_path = malloc(MAX_FILE_PATH);
-               //sprintf(s_update_data[i].ua_temp_path, "%s/fota_temp_%s", delta_folder, s_part_info[i].ua_parti_name);
-       }
 
+       s_update_data.ua_delta_path = malloc(MAX_FILE_PATH);
+       if (s_update_data.ua_delta_path == NULL) {
+               LOG("Memory allocation fail\n");
+               return FAIL;
+       }
+       snprintf(s_update_data.ua_delta_path, MAX_FILE_PATH, "%s/%s", delta_folder, DEFAULT_DELTA_NAME);
        snprintf(fota_cause, sizeof(fota_cause), "%s/%s", result_folder, "cause");
        snprintf(fota_status_path, sizeof(fota_status_path), "%s/%s", result_folder, UP_STATUS_FILE);
 
-       for (i = 0; i < s_part_num; i++) {
-               LOG("s_part_info[UA_%s].ua_delta_path=%s\n",
-                       s_part_info[i].ua_parti_name,
-                       s_update_data[i].ua_delta_path);
-       }
+       LOG("s_part_info[UA_%s].ua_delta_path=%s\n",
+               s_part_info.ua_parti_name,
+               s_update_data.ua_delta_path);
 
        return SUCCESS;
 }
@@ -1020,63 +619,14 @@ int fota_path_init(void)
  ----------------------------------------------------------------------------*/
 void fota_path_deinit(void)
 {
-       int i;
-       for (i = 0; i < s_part_num; i++) {
-               if (s_update_data[i].ua_delta_path) {
-                       free(s_update_data[i].ua_delta_path);
-                       s_update_data[i].ua_delta_path = NULL;
-               }
-               if (s_update_data[i].ua_temp_path) {
-                       free(s_update_data[i].ua_temp_path);
-                       s_update_data[i].ua_temp_path = NULL;
-               }
+       if (s_update_data.ua_delta_path) {
+               free(s_update_data.ua_delta_path);
+               s_update_data.ua_delta_path = NULL;
        }
-}
-
-/*-----------------------------------------------------------------------------
-  check_ua_op_mode
- ----------------------------------------------------------------------------*/
-int check_ua_op_mode(int argc, char **argv)
-{
-       ua_op_mode = -1;
-       ua_slot_mode = 0;
-       if (argc == 3) {
-               ua_op_mode = UA_OP_MODE_FG;
-       } else if (argc >= 4 && argc <= 6) {
-               if (argv[3][0] == '0') {
-                       ua_op_mode = UA_OP_MODE_FG;
-               } else if (argv[3][0] == '1') {
-                       ua_op_mode = UA_OP_MODE_BG;
-               }
-               if (argc == 6) {
-                       if (argv[4][0] == 'a') {
-                               ua_slot_mode = 'a';
-                       } else if (argv[4][0] == 'b') {
-                               ua_slot_mode = 'b';
-                       } else {
-                               ua_slot_mode = -1;
-                       }
-                       // TODO: realpath is fundamentally broken, see man. Not that we care :)
-                       char *block_device = realpath(argv[5], blk_dev_arg);
-                       if (!block_device) {
-                               int max_err_len = strlen(argv[5]) + 100;
-                               char err[max_err_len];
-                               snprintf(err, max_err_len, "Unable to get realpath for: %s\n", argv[5]);
-                               print_usage(err);
-                               return -1;
-                       }
-                       // Thanks to realpath call, blk_dev_arg now contains the path.
-               }
-               else if (argc == 5) {
-                       print_usage("Unable to parse arguments, please specify upgrade_slot and block_device or none of them.\n");
-                       return -1;
-               }
+       if (s_update_data.ua_temp_path) {
+               free(s_update_data.ua_temp_path);
+               s_update_data.ua_temp_path = NULL;
        }
-       if (ua_op_mode != -1 || ua_slot_mode == -1)
-               return 0;
-
-       print_usage("Unable to parse arguments.\n");
-       return -1;
 }
 
 /*-----------------------------------------------------------------------------
@@ -1109,325 +659,119 @@ int check_dm_verity_status(void)
 void remove_temp_files(void)
 {
        int ret = 0;
-       int i;
        char *ua_temp_path;
        struct stat sbuf;
 
-       for (i = 0; i < s_part_num; i++) {
-               ua_temp_path = s_update_data[i].ua_temp_path;
-               if (NULL == ua_temp_path)
-                       continue;
 
-               ret = lstat(ua_temp_path, &sbuf);
-               if (ret < 0) {
-                       ret = stat(ua_temp_path, &sbuf);
-                       if (ret < 0) {
-                               LOG("stat failed with return value: %d errno: %d\n", ret, errno);
-                               continue;
-                       }
-               }
+       ua_temp_path = s_update_data.ua_temp_path;
+       if (NULL == ua_temp_path)
+               return;
 
-               if (S_ISDIR(sbuf.st_mode)) {
-                       ret = rmdir(ua_temp_path);
-                       if (ret < 0)
-                               LOG("rmdir(%s) failed with return value: %d errno: %d\n", ua_temp_path, ret, errno);
-               } else {
-                       ret = unlink(ua_temp_path);
-                       if (ret < 0)
-                               LOG("unlink(%s) failed with return value: %d errno: %d\n", ua_temp_path, ret, errno);
+       ret = lstat(ua_temp_path, &sbuf);
+       if (ret < 0) {
+               ret = stat(ua_temp_path, &sbuf);
+               if (ret < 0) {
+                       LOG("stat failed with return value: %d errno: %d\n", ret, errno);
+                       return;
                }
        }
-}
 
-/*-----------------------------------------------------------------------------
-  get_update_type
- ----------------------------------------------------------------------------*/
-int get_update_type(char* part_name)
-{
-       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;
+       if (S_ISDIR(sbuf.st_mode)) {
+               ret = rmdir(ua_temp_path);
+               if (ret < 0)
+                       LOG("rmdir(%s) failed with return value: %d errno: %d\n", ua_temp_path, ret, errno);
+       } else {
+               ret = unlink(ua_temp_path);
+               if (ret < 0)
+                       LOG("unlink(%s) failed with return value: %d errno: %d\n", ua_temp_path, ret, errno);
        }
-
-       return EXTRA;
 }
 
 /*-----------------------------------------------------------------------------
-  get_update_when
+  arg_parse
  ----------------------------------------------------------------------------*/
-int get_update_when(char* part_name)
+int arg_parse(int argc, char ** argv, temp_opt *my_opt)
 {
-       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;
+       if (argc != 7) {
+               print_usage("Invalid parameter count");
+               return -1;
        }
-       return -1;
-}
-
-
-/*-----------------------------------------------------------------------------
-  fota_blkid_update
- ----------------------------------------------------------------------------*/
-int fota_blkid_update(void)
-{
-       char part_tbl_path[MAX_FILE_PATH];
-       FILE *fp;
-       int num_part;
-       int i, j;
-       int id, id_previous;
-       char part_name[256];
-       char blk_name[PATH_MAX + 32];
-       char blk_name_previous[PATH_MAX + 32];
-       blkid_partlist pr = NULL;
-       blkid_probe bp = NULL;
-
-       // new mode: use libblkid rather than reading partitions from
-       // part_table configuration file.
-       if (ua_slot_mode == 'a' || ua_slot_mode == 'b') {
-               char ua_slot_mode_previous = ua_slot_mode == 'a' ? 'b' : 'a';
-               pr = get_part_list(blk_dev_arg, &bp);
-               if (!pr) {
-                       return -1;
-               }
-               for (j = 0; j < s_part_num; ++j) {
-                       memset((void*)blk_name, 0x00, sizeof(blk_name));
-                       memset((void*)blk_name_previous, 0x00, sizeof(blk_name_previous));
-                       id = get_part_number_by_name(pr, s_part_info[j].ua_parti_name, &ua_slot_mode);
-                       id_previous = get_part_number_by_name(pr, s_part_info[j].ua_parti_name, &ua_slot_mode_previous);
-                       if (id == -1 || id_previous == -1) {
-                               LOG("failed to get_part_number_by_name for: %s, slot: %c, %c (%d %d)",
-                                               s_part_info[j].ua_parti_name, ua_slot_mode, ua_slot_mode_previous,
-                                               id, id_previous);
-                               blkid_free_probe(bp);
+       const char * archive = NULL;
+       const char * archive_file = NULL;
+       const char * dest = NULL;
+       const struct option long_options[] = {
+               {"archive",      required_argument, NULL, 0  },
+               {"dest",         required_argument, NULL, 1  },
+               {"archive-file", required_argument, NULL, 2  },
+               {0}
+       };
+       while (1) {
+               int option = getopt_long(argc, argv, "", long_options, NULL);
+               if (option < 0)
+                       break;
+               switch (option) {
+               case 0:
+                       if (archive != NULL) {
+                               print_usage("Parameters repeated");
                                return -1;
                        }
-                       if (s_part_info[j].ua_blk_name) free(s_part_info[j].ua_blk_name);
-                       if (s_part_info[j].ua_blk_name_previous) free(s_part_info[j].ua_blk_name_previous);
-                       if (strncmp("/dev/sd", blk_dev_arg, strlen(blk_dev_arg) + 1) == 0) {
-                               snprintf(blk_name, sizeof(blk_name)-1, "%s%d", blk_dev_arg, id);
-                               snprintf(blk_name_previous, sizeof(blk_name_previous)-1, "%s%d", blk_dev_arg, id_previous);
-                       } else {
-                               snprintf(blk_name, sizeof(blk_name)-1, "%sp%d", blk_dev_arg, id);
-                               snprintf(blk_name_previous, sizeof(blk_name_previous)-1, "%sp%d", blk_dev_arg, id_previous);
+                       archive = optarg;
+                       break;
+               case 1:
+                       if (dest != NULL) {
+                               print_usage("Parameters repeated");
+                               return -1;
                        }
-                       s_part_info[j].ua_blk_name = strdup(blk_name);
-                       s_part_info[j].ua_blk_name_previous = strdup(blk_name_previous);
-                       if (s_part_info[j].ua_blk_name == NULL ||
-                                       s_part_info[j].ua_blk_name_previous == NULL) {
-                               LOG("failed to allocate memory for device name: %m (%d)", errno);
+                       dest = optarg;
+                       break;
+               case 2:
+                       if (archive_file != NULL) {
+                               print_usage("Parameters repeated");
                                return -1;
                        }
-               }
-               blkid_free_probe(bp);
-       } else {
-       // legacy mode: get part numbers from file
-               memset((void*)part_tbl_path, 0x00, sizeof(part_tbl_path));
-               snprintf(part_tbl_path, sizeof(part_tbl_path)-1, "%s/%s", temp_folder,
-                               PART_TBL_FILE);
-
-               fp = fopen(part_tbl_path, "r");
-               if (fp == NULL) {
-                       LOG("fail to open partition table\n");
-                       return -1;
-               }
-
-               if ((fscanf(fp, "%d", &num_part) < 0) || (num_part <= 0) ||
-                               (num_part >= MAX_PART_TBL_ITEM)) {
-                       LOG("fail to fscanf() or num_part is 0\n");
-                       fclose(fp);
+                       archive_file = optarg;
+                       break;
+               default:
+                       print_usage("Invalid parameters");
                        return -1;
                }
-               for (i = 0; i < num_part; i++) {
-                       if (fscanf(fp, "%d %32s", &id, part_name) < 0) {
-                               LOG("fail to fscanf()\n");
-                               break;
-                       }
-                       LOG("%s [%d]\n", part_name, id);
-                       for (j = 0; j < s_part_num; j++) {
-                               memset((void*)blk_name, 0x00, sizeof(blk_name));
-                               if (strncmp("/dev/sd", blk_dev_arg, strlen(blk_dev_arg) + 1) == 0)
-                                       snprintf(blk_name, sizeof(blk_name)-1, "%s%d", blk_dev_arg, id);
-                               else
-                                       snprintf(blk_name, sizeof(blk_name)-1, "%sp%d", blk_dev_arg, id);
-                               s_part_info[j].ua_blk_name = strdup(blk_name);
-                               }
-                       }
-               fclose(fp);
        }
-
-       return 0;
-}
-
-/*-----------------------------------------------------------------------------
-  fota_configure_update
- ----------------------------------------------------------------------------*/
-int fota_configure_update(void)
-{
-       char cfg_data[MAX_CFG_LEN+1];
-       int data_size = -1;
-       char* line = NULL;
-       char* field = NULL;
-       char* ctx1 = NULL;
-       char* ctx2 = NULL;
-       int line_num = 0;
-       int field_num = 0;
-       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;
-       int trg_img_size = 0;
-       char *src_img_sha1 = NULL;
-       char *trg_img_sha1 = NULL;
-       memset((void*)cfg_data, 0x00, sizeof(cfg_data));
-
-       data_size = tar_get_cfg_data(delta_path, UPDATTE_CFG_FILE, cfg_data, MAX_CFG_LEN);
-       if (data_size <= 0) {
-               LOG("tar_get_cfg_data() fail\n");
+       if (archive_file == NULL || dest == NULL || archive == NULL) {
+               print_usage("Wrong parameters");
                return -1;
        }
-       cfg_data[data_size] = '\0';
-
-       line_num = 0;
-       line = strtok_r(cfg_data, "\n", &ctx1);
-       while (line) {
-               part_name = NULL;
-               subj_name = NULL;
-               update_type = EXTRA;
-               blk_name = NULL;
-               blk_offset = 0;
-               src_img_size = 0;
-               trg_img_size = 0;
-               src_img_sha1 = NULL;
-               trg_img_sha1 = NULL;
-
-               field_num = 0;
-               field = strtok_r(line, "\t", &ctx2);
-               while (field) {
-                       switch (field_num) {
-                       case 0:
-                               part_name = strdup(field);
-                               break;
-                       case 1:
-                               subj_name = strdup(field);
-                               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);
-                               break;
-                       case 4:
-                               blk_offset = atoi(field);
-                               break;
-                       case 5:
-                               src_img_size = atoi(field);
-                               break;
-                       case 6:
-                               trg_img_size = atoi(field);
-                               break;
-                       case 7:
-                               src_img_sha1 = strdup(field);
-                               break;
-                       case 8:
-                               trg_img_sha1 = strdup(field);
-                               break;
-                       }
-                       field_num++;
-                       LOG("%s,", field);
-                       field = strtok_r(NULL, "\t", &ctx2);
-               }
-               LOG("\n");
-
-               if (!part_name)
-                       return -1;
-
-               if ((update_type != EXTRA) || (0 == strcmp(part_name, "RAMDISK2"))) {
-                       s_part_info[line_num].ua_parti_name = part_name;
-                       s_part_info[line_num].ua_subject_name = subj_name;
-                       s_part_info[line_num].ua_blk_name = blk_name;
-                       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;
-                       s_update_cfg[line_num].target_sha1 = trg_img_sha1;
-
-                       line_num++;
-               } else {
-                       if (part_name)  free(part_name);
-                       if (subj_name)  free(subj_name);
-                       if (blk_name)   free(blk_name);
-                       if (src_img_sha1) free(src_img_sha1);
-                       if (trg_img_sha1) free(trg_img_sha1);
-               }
-               line = strtok_r(NULL, "\n", &ctx1);
-       }
-
-       LOG("Effective cfg line num = %d\n", line_num);
+       (*my_opt).archive = archive;
+       (*my_opt).dest = dest;
+       (*my_opt).archive_file = archive_file;
 
-       return line_num;
+       return 0;
 }
 
 /*-----------------------------------------------------------------------------
   main
-
-  argv[1] : directory path for delta file
-  argv[2] : directory path for log file, result file, temp file
-  argv[3] : operation mode ("0" or none : Foreground Mode, "1" : Background Mode)
-  argv[4] : "a" or "b" upgrade slot number. This is optional parameter.
-  When it's set ua will not read hardcoded partitions numbers from config file.
-  Ua will use libblkid to determine it based on partition label e.g. rootfs_a which is rootfs from a slot.
-  argv[5]: path for blkid device e.g. /dev/mmcblk0
-
  ----------------------------------------------------------------------------*/
 int main(int argc, char **argv)
 {
        char ver_str[MAX_PATH];
        int ret = FAIL;
-       int i = 0;
-
+       temp_opt my_opt;
        log_init();
+       if(arg_parse(argc, argv, &my_opt) < 0) {
+               ret = UPI_INVALID_PARAM_ERROR;
+               goto Results;
+       }
 
 #if defined(FEATURE_SUPPORT_CAPABILITY)
        SS_set_feature_support_capability(1);
 #endif
 
-       /* check whether FG mode or BG mode */
-       if (check_ua_op_mode(argc, argv) < 0) {
-               ret = UPI_INVALID_PARAM_ERROR;
-               goto Results;
-       }
-
        memset(delta_folder, 0x00, sizeof(delta_folder));
-       snprintf(delta_folder, sizeof(delta_folder)-1, "%s", argv[1]);
+       snprintf(delta_folder, sizeof(delta_folder)-1, "%s", my_opt.archive);
        snprintf(delta_path, sizeof(delta_path)-1, "%s/%s", delta_folder, DEFAULT_DELTA_NAME);
+       s_update_data.ua_delta_folder = strdup(delta_folder);
 
        memset(temp_folder, 0x00, sizeof(temp_folder));
-       snprintf(temp_folder, sizeof(temp_folder)-1, "%s", argv[2]);
+       snprintf(temp_folder, sizeof(temp_folder)-1, "%s", TEMP_FOLDER);
 
        memset(log_folder, 0x00, sizeof(log_folder));
        snprintf(log_folder, sizeof(log_folder)-1, "%s", SYSTEM_LOG_DIR);
@@ -1438,42 +782,23 @@ int main(int argc, char **argv)
 
        fota_cfg_str_load();
 
-       if (check_dm_verity_status() < 0) {
+       if (check_dm_verity_status() < 0) { // to be removed
                LOG("check_dm_verity_status fail\n");
                ret = UPI_CONFIG_ERROR;
                goto Results;
        }
 
-       /* Check fota folder path */
-       if (check_existence(delta_folder) == 0) {
-               ret = UPI_DELTA_PATH_ERROR;
-               goto Results;
-       }
-
-       /* load update configuration */
-       ret = fota_configure_update();
-       if (ret > 0) {
-               s_part_num = ret;
-       } else {
-               LOG("Update Configuration fail.\n");
-               ret = UPI_CONFIG_ERROR;
-               goto Results;
-       }
+       s_part_info.ua_parti_name = my_opt.dest;
+       s_part_info.ua_subject_name = my_opt.archive_file;
+       s_update_cfg.source_img_size = 0; // TODO lets see if 0 will work
 
        /* load block device number at run-time */
-       ret = fota_blkid_update();
-       if (ret < 0) {
-               LOG("fota_blkid_update() fail\n");
-               ret = UPI_PARTINFO_ERROR;
-               goto Results;
-       }
 
        ret = fota_path_init();
        if (ret == FAIL) {
                ret = UPI_DELTA_PATH_LENGTH_ERROR;
                goto Results;
        }
-
        LOG("<<<<<<<<<<< log_init >>>>>>>>>>>>\n");
 
        /* UPI version check */
@@ -1518,21 +843,15 @@ int main(int argc, char **argv)
                fota_path_deinit();
                log_deinit();
                /* Preserve log file for debugging */
-               //truncate_log_file(log_path, 0);
                _exit_stdio();
                return 0;
        default:
                LOG("!!! Not expected ret (= %d)\n", ret);
        }
 
-       for(i = 0; i < s_part_num; i++) {
-               if(s_part_info[i].ua_parti_name)        free(s_part_info[i].ua_parti_name);
-               if(s_part_info[i].ua_subject_name)      free(s_part_info[i].ua_subject_name);
-               if(s_part_info[i].ua_blk_name)          free(s_part_info[i].ua_blk_name);
-               if(s_update_cfg[i].soure_sha1)          free(s_update_cfg[i].soure_sha1);
-               if(s_update_cfg[i].target_sha1)         free(s_update_cfg[i].target_sha1);
-       }
+       if(s_part_info.ua_parti_name)   free(s_part_info.ua_parti_name);
+       if(s_part_info.ua_subject_name) free(s_part_info.ua_subject_name);
 
        _exit_stdio();
        return -1;
-}
+}
\ No newline at end of file
index a9cc34b..c5077fe 100755 (executable)
@@ -1,7 +1,7 @@
 /*
- * tota-ua
+ * delta-ua
  *
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 - 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the License);
  * you may not use this file except in compliance with the License.
@@ -33,9 +33,6 @@
 #define MAX_FILE_PATH           512
 #define MAX_FOLDER_PATH         384
 
-#define PART_TBL_FILE "part_tbl.txt"
-#define MAX_PART_TBL_ITEM              50
-
 /*
  * FOTA Adaptaion header
  */
@@ -67,8 +64,6 @@
 #define UPI_DELTACOUNT_ERROR                   UPI_ERROR(EC)
 #define UPI_PARTINFO_ERROR                             UPI_ERROR(ED)
 
-#define TEMP_SIZE          0x40000
-
 #define DEFAULT_DELTA_NAME             "delta.tar"
 #define UPDATTE_CFG_FILE               "update.cfg"