+#include "fota/fota-manager.h"
#include "update-manager.h"
+#include "update-manager-dbus.h"
static guint owner_id;
int ret = 0;
_D("Dbus status : result called");
- ret = fota_controller_result();
+ ret = fota_result_sender_execute();
if (ret < 0)
_W("Failed to fetch result with fota : %d", ret);
org_tizen_update_manager_complete_result(skeleton, invocation, ret);
int ret = 0;
_D("Dbus status : install called");
- ret = fota_controller_install();
+ ret = fota_installer_execute();
if (ret < 0)
_W("Failed to install delta with fota : %d", ret);
org_tizen_update_manager_complete_install(skeleton, invocation, ret);
+++ /dev/null
-#include "fota/fota-manager.h"
-#include "update-manager.h"
-
-int fota_controller_setup_delta()
-{
- int ret = 0, status = 0;
- char *appid = NULL, *build_string = NULL;
- gchar *shared_path = NULL;
-
- ret = util_file_mkdir(FOTA_DIR);
- if (ret < 0) {
- status = -1;
- goto delta_destroy;
- }
-
- appid = fota_client_info_get_appid();
- if (appid == NULL) {
- _I("Failed to get client app id");
- status = -1;
- goto delta_destroy;
- }
-
- build_string = fota_info_get_build_string();
- if (build_string == NULL) {
- _E("Failed to get build string");
- status = -1;
- goto delta_destroy;
- }
-
- ret = remove(FOTA_DELTA_PATH);
- if (ret < 0 && errno != ENOENT)
- _W("Failed to remove exist link : %m");
-
- shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL);
- ret = fota_delta_verify(shared_path, build_string, NULL);
- if (ret != 0) {
- _E("Failed to verify delta : %d", ret);
- status = -1;
- goto delta_destroy;
- }
-
- ret = symlink(shared_path, FOTA_DELTA_PATH);
- if (ret < 0) {
- _E("Failed to link delta : %m");
- status = -1;
- goto delta_destroy;
- }
-
- ret = util_file_untar(FOTA_DELTA_PATH, FOTA_DIR, FOTA_DELTA_UA_FILE);
- if (ret < 0) {
- _E("Failed to fetch delta.ua from delta : %d", ret);
- status = -1;
- goto delta_destroy;
- }
-
- _I("Success to setup delta to %s", FOTA_DIR);
-
-delta_destroy:
- g_free(shared_path);
-
- return status;
-}
-
-int fota_controller_setup_status()
-{
- int ret = 0;
-
- ret = util_file_mkdir(STATUS_DIR);
- if (ret < 0)
- return -1;
-
- ret = util_file_write_line(STATUS_FLAG_PATH, "");
- if (ret < 0)
- return -1;
-
- ret = util_file_write_line(STATUS_FOTA_PATH, FOTA_DIR);
- if (ret < 0)
- return -1;
-
- _I("Success to setup fota status to %s", STATUS_DIR);
-
- return 0;
-}
-
-int fota_controller_write_platform_version()
-{
- int ret = 0, status = 0;
- char *platform_version = NULL;
- gchar *formatted_version = NULL;
-
- platform_version = fota_info_get_platform_version();
- if (platform_version == NULL) {
- _E("Failed to get platform version");
- status = -1;
- goto version_destroy;
- }
-
- formatted_version = g_strconcat("OLD_VER=", platform_version, ".0.0\n", NULL);
- ret = util_file_write_line(PLATFORM_VERSION_PATH, formatted_version);
- if (ret < 0) {
- status = -1;
- goto version_destroy;
- }
-
- _I("Success to write version to %s : %s", PLATFORM_VERSION_PATH, formatted_version);
-
-version_destroy:
- g_free(formatted_version);
-
- return status;
-}
-
-int fota_controller_install()
-{
- int ret = 0;
-
- ret = fota_controller_setup_delta();
- if (ret < 0) {
- _E("Failed to setup delta.tar : %d", ret);
- return -1;
- }
-
- ret = fota_controller_write_platform_version();
- if (ret < 0) {
- _E("Failed to write platform version : %d", ret);
- return -1;
- }
-
- ret = fota_controller_setup_status();
- if (ret < 0) {
- _E("Failed to setup fota update status : %d", ret);
- return -1;
- }
-
- ret = device_power_reboot(FOTA_REBOOT_REASON);
- if (ret != DEVICE_ERROR_NONE) {
- _E("Failed to request reboot with reason : %s", FOTA_REBOOT_REASON);
- return -1;
- }
-
- _I("Success to request fota, device will reboot");
- return 0;
-}
-
-int fota_controller_result()
-{
- char *fota_result = NULL;
- int len = 0;
-
- fota_result = fota_status_get_result();
- if (fota_result == NULL) {
- _I("Fota result : Not exist");
- return 4;
- }
-
- len = strlen(fota_result);
- _I("Fota result length : %d", len);
-
- if (len > 2 && fota_result[0] == 'F') {
- if (fota_result[1] == 'D') {
- _I("Fota result : RO failed, %s", fota_result);
- return 3;
- }
- else if (fota_result[1] == 'A') {
- _I("Fota result : RW failed, %s", fota_result);
- return 2;
- }
- }
-
- if (len > 1 && fota_result[1] != '0') {
- _I("Fota result : RO only success, %s", fota_result);
- return 1;
- }
-
- if (len > 1 && fota_result[0] == '0' && fota_result[1] == '0') {
- _I("Fota result : RO/RW success, %s", fota_result);
- return 0;
- }
-
- _E("Unexpected result : %s", fota_result);
- return -1;
-}
#include "../update-manager.h"
#include "fota-manager.h"
+#define FOTA_CLIENT_APP_CTRL_PLUG_KEY "fota-plug"
+#define FOTA_CLIENT_APP_CTRL_UNPLUG_KEY "fota-unplug"
+#define FOTA_CLIENT_APP_CTRL_REBOOT_KEY "fota-reboot"
+
static const char* fota_event_keys[FOTA_EVENT_SIZE] = {
FOTA_CLIENT_APP_CTRL_PLUG_KEY,
FOTA_CLIENT_APP_CTRL_UNPLUG_KEY,
#include "../update-manager.h"
#include "fota-manager.h"
+#define FOTA_CLIENT_METADATA_KEY "tizen-fota-manager"
+#define FOTA_CLIENT_METADATA_VALUE "client"
+
static char *fota_client_app_id = NULL;
char *fota_client_info_get_appid()
if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
_FLOGI("Not found delta in %s", path);
- status = 1;
+ status = -2;
goto verify_destroy;
}
if (old_build_string == NULL) {
_FLOGE("Failed to try verify, old build string must be passed");
- status = -1;
+ status = -3;
goto verify_destroy;
}
_FLOGI("Found delta in %s, start process to verify", path);
ret = util_file_untar(path, BUILD_ID_DIR, BUILD_ID_FILE);
if (ret < 0) {
- _FLOGE("Failed to fetch %s from delta : %d", BUILD_ID_FILE, ret);
status = -1;
goto verify_destroy;
}
if (g_strrstr(buf, old_build_string) == NULL) {
_FLOGI("Unmatched occur, old_build_string : %s, delta : %s", old_build_string, buf);
- status = 2;
+ status = -4;
goto verify_destroy;
}
if (g_strrstr(buf, new_build_string) == NULL) {
_FLOGI("Unmatched occur, new_build_string : %s, delta : %s", new_build_string, buf);
- status = 3;
+ status = -4;
goto verify_destroy;
}
}
_FLOGI("Success to verify %s, old : %s, new : %s", path, old_build_string, new_build_string);
verify_destroy:
- ret = remove(BUILD_ID_PATH);
- if (ret < 0)
- _FLOGW("Failed to remove %s : %m", BUILD_ID_PATH);
+ util_file_remove(BUILD_ID_PATH);
if (!fp)
fclose(fp);
#include "fota-manager.h"
#include "../update-manager.h"
+#define SYSTEM_INFO_BUILD_STRING "tizen.org/system/build.string"
+#define SYSTEM_INFO_PLATFORM_VERSION "tizen.org/feature/platform.version"
+
static char *build_string = NULL;
static char *platform_version = NULL;
--- /dev/null
+#include "fota-manager.h"
+#include "../update-manager.h"
+
+int fota_installer_setup_delta()
+{
+ int ret = 0;
+ char *appid = NULL, *build_string = NULL;
+ gchar *shared_path = NULL;
+
+ ret = util_file_mkdir(FOTA_DIR);
+ if (ret < 0)
+ return -1;
+
+ appid = fota_client_info_get_appid();
+ if (appid == NULL) {
+ _FLOGE("Failed to get client app id");
+ return -1;
+ }
+
+ build_string = fota_info_get_build_string();
+ if (build_string == NULL) {
+ _FLOGE("Failed to get build string");
+ return -1;
+ }
+
+ shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL);
+ ret = fota_delta_verify(shared_path, build_string, NULL);
+ if (ret < 0) {
+ _FLOGE("Failed to verify delta : %d, path : %s, old_build_string : %s",
+ ret, shared_path, build_string);
+ g_free(shared_path);
+ return -1;
+ }
+
+ ret = util_file_symlink(shared_path, FOTA_DELTA_PATH);
+ if (ret < 0) {
+ g_free(shared_path);
+ return -1;
+ }
+ g_free(shared_path);
+
+ ret = util_file_untar(FOTA_DELTA_PATH, FOTA_DIR, FOTA_DELTA_UA_FILE);
+ if (ret < 0)
+ return -1;
+
+ _FLOGI("Success to setup delta to %s", FOTA_DIR);
+ return 0;
+}
+
+int fota_installer_setup_platform_version()
+{
+ int ret = 0;
+ char *platform_version = NULL;
+ gchar *formatted_version = NULL;
+
+ platform_version = fota_info_get_platform_version();
+ if (platform_version == NULL) {
+ _FLOGE("Failed to get platform version");
+ return -1;
+ }
+
+ switch(strlen(platform_version)) {
+ case 1:
+ formatted_version = g_strconcat("OLD_VER=", platform_version, ".0.0.0\n", NULL);
+ break;
+ case 3:
+ formatted_version = g_strconcat("OLD_VER=", platform_version, ".0.0\n", NULL);
+ break;
+ case 5:
+ formatted_version = g_strconcat("OLD_VER=", platform_version, ".0\n", NULL);
+ break;
+ case 7:
+ formatted_version = g_strconcat("OLD_VER=", platform_version, "\n", NULL);
+ break;
+ default:
+ _FLOGE("Unexpected version string : %s", platform_version);
+ return -1;
+ }
+
+ ret = util_file_write_line(FOTA_INSTALL_PLATFORM_VERSION_PATH, formatted_version);
+ if (ret < 0) {
+ g_free(formatted_version);
+ return -1;
+ }
+
+ _FLOGI("Success to setup version to %s : %s", FOTA_INSTALL_PLATFORM_VERSION_PATH, formatted_version);
+ g_free(formatted_version);
+
+ return 0;
+}
+
+int fota_installer_setup_status()
+{
+ int ret = 0;
+
+ ret = util_file_mkdir(STATUS_DIR);
+ if (ret < 0)
+ return -1;
+
+ ret = util_file_write_line(STATUS_FLAG_PATH, NULL);
+ if (ret < 0)
+ return -1;
+
+ ret = util_file_write_line(STATUS_FOTA_PATH, FOTA_DIR);
+ if (ret < 0)
+ return -1;
+
+ _FLOGI("Success to setup fota status");
+ return 0;
+}
+
+int fota_installer_execute()
+{
+ int ret = 0;
+
+ ret = fota_installer_setup_delta();
+ if (ret < 0) {
+ _FLOGE("Failed to setup delta.tar : %d", ret);
+ return -1;
+ }
+
+ ret = fota_installer_setup_platform_version();
+ if (ret < 0) {
+ _FLOGE("Failed to setup platform version : %d", ret);
+ return -1;
+ }
+
+ ret = fota_installer_setup_status();
+ if (ret < 0) {
+ _FLOGE("Failed to setup fota status : %d", ret);
+ return -1;
+ }
+
+ ret = device_power_reboot(FOTA_INSTALL_REBOOT_REASON);
+ if (ret != DEVICE_ERROR_NONE) {
+ _FLOGE("Failed to reboot with %s", FOTA_INSTALL_REBOOT_REASON);
+ return -1;
+ }
+
+ _FLOGI("Success to reboot with %s, device will reboot", FOTA_INSTALL_REBOOT_REASON);
+ return 0;
+}
#define _FLOGE(fmt, arg...) SLOG(LOG_ERROR, FOTA_LOG_TAG, fmt, ##arg)
/* Constant */
-#define FOTA_CLIENT_METADATA_KEY "tizen-fota-manager"
-#define FOTA_CLIENT_METADATA_VALUE "client"
-#define FOTA_CLIENT_APP_CTRL_PLUG_KEY "fota-plug"
-#define FOTA_CLIENT_APP_CTRL_UNPLUG_KEY "fota-unplug"
-#define FOTA_CLIENT_APP_CTRL_REBOOT_KEY "fota-reboot"
-#define SYSTEM_INFO_BUILD_STRING "tizen.org/system/build.string"
-#define SYSTEM_INFO_PLATFORM_VERSION "tizen.org/feature/platform.version"
-#define FOTA_EVENT_SIZE 3
+#define FOTA_INSTALL_PLATFORM_VERSION_PATH "/opt/etc/version"
+#define FOTA_INSTALL_REBOOT_REASON "fota"
-#define FOTA_LOCAL_FOLDER_TOKEN "@"
+#define FOTA_EVENT_SIZE 3
/* Enum */
typedef enum {
char *fota_info_get_build_string(void);
char *fota_info_get_platform_version(void);
+int fota_installer_execute(void);
+
+int fota_result_sender_execute(void);
+
int fota_status_checker_init(void);
int fota_status_checker_fini(void);
char *fota_status_get_result(void);
--- /dev/null
+#include "fota-manager.h"
+#include "../update-manager.h"
+
+int fota_result_sender_execute()
+{
+ char *fota_result = NULL;
+ int len = 0;
+
+ fota_result = fota_status_get_result();
+ if (fota_result == NULL) {
+ _FLOGI("Fota result : Not exist");
+ return 4;
+ }
+
+ len = strlen(fota_result);
+ _FLOGD("Fota result length : %d", len);
+
+ if (len > 2 && fota_result[0] == 'F') {
+ if (fota_result[1] == 'D') {
+ _FLOGI("Fota result : RO failed, %s", fota_result);
+ return 3;
+ }
+ else if (fota_result[1] == 'A') {
+ _FLOGI("Fota result : RW failed, %s", fota_result);
+ return 2;
+ }
+ }
+
+ if (len > 1 && fota_result[1] != '0') {
+ _FLOGI("Fota result : RO only success, %s", fota_result);
+ return 1;
+ }
+
+ if (len > 1 && fota_result[0] == '0' && fota_result[1] == '0') {
+ _FLOGI("Fota result : RO/RW success, %s", fota_result);
+ return 0;
+ }
+
+ _FLOGW("Unexpected result : %s", fota_result);
+ return -1;
+}
}
ret = util_file_read_single_line(STATUS_RESULT_PATH, buf);
- if (ret < 0) {
- _FLOGE("Failed to read fota result : %d", ret);
+ if (ret < 0)
return -1;
- }
fota_result = strndup(buf, strlen(buf));
if (fota_result == NULL) {
return -1;
}
- ret = remove(STATUS_FLAG_PATH);
- if (ret != 0) {
- _FLOGE("Failed to remove fota flag : %d, %m", ret);
+ ret = util_file_remove(STATUS_FLAG_PATH);
+ if (ret < 0)
return -1;
- }
return 0;
}
#include "../update-manager.h"
#include "fota-manager.h"
+#define FOTA_STORAGE_FOLDER_TOKEN "@"
+
static int fota_storage_id = -1;
int fota_storage_verify_delta(const char* mount_path, const char *folder_name, gchar **delta_path)
old_build_string = fota_info_get_build_string();
if (old_build_string == NULL) {
_FLOGE("Failed to get build string");
- status = -1;
- goto verify_destroy;
+ return -1;
}
if (g_str_has_prefix(folder_name, old_build_string) != TRUE) {
_FLOGI("Folder %s is not start with %s, pass", folder_name, old_build_string);
- goto verify_destroy;
+ return -1;
}
- new_build_string = strstr(folder_name, FOTA_LOCAL_FOLDER_TOKEN);
+ new_build_string = strstr(folder_name, FOTA_STORAGE_FOLDER_TOKEN);
if (new_build_string == NULL) {
- _FLOGI("Folder %s doesn't have token : %s", folder_name, FOTA_LOCAL_FOLDER_TOKEN);
- goto verify_destroy;
+ _FLOGI("Folder %s doesn't have token : %s", folder_name, FOTA_STORAGE_FOLDER_TOKEN);
+ return -1;
}
new_build_string = new_build_string + 1;
path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILE, NULL);
if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
_FLOGI("Folder %s doesn't have delta.tar", folder_name);
+ status = -1;
goto verify_destroy;
}
ret = fota_delta_verify(path, old_build_string, new_build_string);
if (ret < 0) {
+ _FLOGE("Failed to verify delta : %d, path : %s, old_build_string : %s, new_build_string : %s",
+ ret, path, old_build_string, new_build_string);
status = -1;
goto verify_destroy;
}
- else if (ret > 0) {
- goto verify_destroy;
- }
*delta_path = path;
folder_name = g_file_info_get_name(info);
ret = fota_storage_verify_delta(mount_path, folder_name, delta_path);
if (ret < 0) {
- _FLOGE("Failed to verify delta : %d, folder : %s", ret, folder_name);
+ _FLOGE("Failed to verify storage delta : %d", ret);
status = -1;
+ g_object_unref(info);
+ continue;
+ }
+
+ if (*delta_path != NULL) {
+ _FLOGI("Success to find verified delta in %s", *delta_path);
+ status = 0;
+ goto search_destroy;
}
g_object_unref(info);
}
+ status = -1;
search_destroy:
if (enumerator)
_FLOGI("Storage mounted with %s, start process to check local delta", mount_path);
ret = fota_storage_search_delta_path(mount_path, &delta_path);
if (ret < 0) {
- _FLOGE("Failed to find delta path : %d", ret);
- goto plug_destroy;
- }
-
- if (delta_path == NULL) {
- _FLOGI("Not found matched delta in %s", mount_path);
+ _FLOGE("Failed to search delta path : %d", ret);
goto plug_destroy;
}
#include "recovery-manager.h"
#include "../update-manager.h"
+#define RECOVERY_CLIENT_APP_CTRL_PLUG_KEY "recovery-plug"
+#define RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY "recovery-unplug"
+
static const char* recovery_event_keys[RECOVERY_EVENT_SIZE] = {
RECOVERY_CLIENT_APP_CTRL_PLUG_KEY,
RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY,
#include "recovery-manager.h"
#include "../update-manager.h"
+#define RECOVERY_CLIENT_METADATA_KEY "tizen-recovery-manager"
+#define RECOVERY_CLIENT_METADATA_VALUE "client"
+
static char *recovery_client_app_id = NULL;
char *recovery_client_info_get_appid()
#define _RLOGE(fmt, arg...) SLOG(LOG_ERROR, RECOVERY_LOG_TAG, fmt, ##arg)
/* Constant */
-#define RECOVERY_CLIENT_METADATA_KEY "tizen-recovery-manager"
-#define RECOVERY_CLIENT_METADATA_VALUE "client"
-#define RECOVERY_CLIENT_APP_CTRL_PLUG_KEY "recovery-plug"
-#define RECOVERY_CLIENT_APP_CTRL_UNPLUG_KEY "recovery-unplug"
-
#define RECOVERY_IMAGE_FILE "tizen-recovery.img"
#define RECOVERY_EVENT_SIZE 2
#include <unistd.h>
#include <vconf.h>
-#include "update-manager-dbus.h"
-
/* Log */
#undef LOG_TAG
#define LOG_TAG "UPDATE_MANAGER"
#define NODE_NAME "/org/tizen/update/manager"
/* Update */
-#define PLATFORM_VERSION_DIR "/opt/etc"
-#define PLATFORM_VERSION_FILE "version"
-#define PLATFORM_VERSION_PATH PLATFORM_VERSION_DIR "/" PLATFORM_VERSION_FILE
#define BUILD_ID_DIR "/tmp"
#define BUILD_ID_FILE "build_id.txt"
#define BUILD_ID_PATH BUILD_ID_DIR "/" BUILD_ID_FILE
-#define FOTA_REBOOT_REASON "fota"
#define FOTA_DIR "/opt/usr/data/fota"
#define FOTA_DELTA_FILE "delta.tar"
#define FOTA_DELTA_PATH FOTA_DIR "/" FOTA_DELTA_FILE
int dbus_manager_init(void);
int dbus_manager_fini(void);
-int fota_controller_install(void);
-int fota_controller_result(void);
-
int util_file_mkdir(const char *);
+int util_file_remove(const char *);
+int util_file_symlink(const char *, const char *);
int util_file_read_single_line(const char *, char []);
int util_file_write_line(const char *, const char *);
int util_file_untar(const char *, const char *, const char *);
return 0;
}
+int util_file_remove(const char *path)
+{
+ int ret = 0;
+ gboolean exist = FALSE;
+
+ exist = g_file_test(path, G_FILE_TEST_EXISTS);
+ if (exist) {
+ ret = remove(path);
+ if (ret < 0) {
+ _E("Failed to remove %s : %m", path);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
+int util_file_symlink(const char *target_path, const char *link_path)
+{
+ int ret = 0;
+ gboolean exist = FALSE;
+
+ exist = g_file_test(target_path, G_FILE_TEST_EXISTS);
+ if (!exist) {
+ _E("Failed to find %s", target_path);
+ return -1;
+ }
+
+ ret = util_file_remove(link_path);
+ if (ret < 0)
+ return -1;
+
+ ret = symlink(target_path, link_path);
+ if (ret < 0) {
+ _E("Failed to symlink from %s to %s : %m", target_path, link_path);
+ return -1;
+ }
+
+ return 0;
+}
+
int util_file_read_single_line(const char *path, char buf[])
{
int status = 0;
ret = system(command);
if (ret < 0) {
- _E("Failed to execute untar command : %m");
+ _E("Failed to execute untar command %s : %m", command);
status = -1;
} else if (ret > 0) {
_E("Failed to untar : %d", ret);