SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS_BASE} -Wall -fPIE")
-INCLUDE_DIRECTORIES(${INCLUDE_DIR})
+INCLUDE_DIRECTORIES(${INCLUDE_DIR} ${SOURCE_DIR})
FILE(GLOB SOURCE_FILES
"${SOURCE_DIR}/*.h" "${SOURCE_DIR}/*.c"
"${SOURCE_DIR}/*/*.h" "${SOURCE_DIR}/*/*.c"
--- /dev/null
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/common.h"
+#include "fota-manager.h"
+
+int check_is_delta_appropriate(const char *delta_path, bool *checksum_available)
+{
+ int ret;
+ bool do_checksum = false;
+ char buf[MAX_BUFFER_SIZE] = {0, };
+
+ ret = util_file_untar(delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME);
+ if (ret < 0) {
+ ret = -1;
+ goto exit;
+ }
+
+ ret = util_file_untar(delta_path, FOTA_DIR, DELTA_VERIFIER_BIN);
+ if (ret < 0) {
+ ret = -1;
+ goto exit;
+ }
+
+ ret = util_file_untar(delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE);
+ if (ret < 0) {
+ _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE);
+ } else {
+ do_checksum = true;
+ }
+
+ if (checksum_available != NULL)
+ *checksum_available = do_checksum;
+
+ if (do_checksum) {
+ if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) {
+ _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH);
+ } else {
+ ret = -1;
+ _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH);
+ goto exit;
+ }
+ }
+
+ snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH);
+ ret = system(buf);
+ if (ret < 0) {
+ _FLOGE("Delta verification failed due to an error [return code: %d].", ret);
+ } else if (ret > 0) {
+ _FLOGI("The delta at [%s] is not compatible with this device [return code: %d].", delta_path, ret);
+ }
+
+exit:
+ return ret;
+}
int fota_installer_execute(pid_t sender_pid)
{
int ret = 0, status = 0, exec_status = 0;
- char buf[MAX_BUFFER_SIZE] = {0, };
char *appid = NULL;
gchar *client_delta_path = NULL;
pid_t pid;
bool check_sha = false;
- /* 1. Check client have delta.tar */
+ /* Check client have delta.tar */
appid = get_sender_appid(sender_pid);
- /* 2. Find the delta file path */
+ /* Find the delta file path */
client_delta_path = find_delta_dir(appid);
if (appid != NULL) {
free(appid);
}
_FLOGI("Delta found: %s", client_delta_path);
- /* 3. Prepare fota dir */
+ /* Prepare fota dir */
ret = util_file_mkdir(FOTA_DIR);
if (ret < 0) {
status = -1;
goto execute_destroy;
}
- /* 4. Check client have appropriate delta */
- ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME);
- if (ret < 0) {
- status = -1;
- goto execute_destroy;
- }
- ret = util_file_untar(client_delta_path, FOTA_DIR, DELTA_VERIFIER_BIN);
- if (ret < 0) {
+ /* Check client have appropriate delta */
+ if (check_is_delta_appropriate(client_delta_path, &check_sha) != 0) {
status = -1;
goto execute_destroy;
}
- ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE);
- if (ret < 0) {
- _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE);
- } else {
- check_sha = true;
- }
-
- if (check_sha) {
- if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) {
- _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH);
- } else {
- status = -1;
- _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH);
- goto execute_destroy;
- }
- }
-
- snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH);
- ret = system(buf);
- if (ret < 0) {
- _FLOGE("Delta verification failed due to an error [return code: %d].", ret);
- status = -1;
- goto execute_destroy;
- } else if (ret > 0) {
- _FLOGI("The delta of the caller is not compatible with this device [return code: %d].", ret);
- status = -3;
- goto execute_destroy;
- }
-
- /* 5. Setup local update flag */
+ /* Setup local update flag */
ret = util_file_mkdir(FOTA_STATUS_DIR);
if (ret < 0) {
status = -1;
goto execute_destroy;
}
- /* 6. Trigger update */
+ /* Trigger update */
ret = util_file_untar(client_delta_path, FOTA_DIR, FOTA_TRIGGER_FILE);
if (ret < 0) {
status = -1;
void fota_storage_checker_plug(int, const char *);
void fota_storage_checker_unplug(int, const char *);
+int check_is_delta_appropriate(const char *delta_path, bool *checksum_available);
#endif /* __FOTA_MANAGER_H__ */
{
int ret = 0;
bool is_appropriate = false;
- char buf[MAX_BUFFER_SIZE] = {0, };
gchar *storage_delta_path = NULL;
- /* 1. Check storage have delta.tar */
+ /* Check storage have delta.tar */
storage_delta_path = g_strjoin("/", mount_path, folder_name, FOTA_DELTA_FILENAME, NULL);
if (!g_file_test(storage_delta_path, G_FILE_TEST_EXISTS)) {
gchar *tmp_storage_delta_path = storage_delta_path;
}
}
- /* 2. Prepare fota dir */
+ /* Prepare fota dir */
ret = util_file_mkdir(FOTA_DIR);
if (ret < 0) {
goto verify_destroy;
}
- /* 2. Check storage have appropriate delta */
- ret = util_file_untar(storage_delta_path, FOTA_DIR, FOTA_DELTA_UPDATE_INFO_FILENAME);
- if (ret < 0) {
- goto verify_destroy;
- }
-
- ret = util_file_untar(storage_delta_path, FOTA_DIR, FOTA_CHECKSUM_FILE);
- if (ret < 0) {
- _FLOGW("There is no %s in delta", FOTA_CHECKSUM_FILE);
- } else {
- if (verify_checksum(FOTA_CHECKSUM_PATH, DELTA_VERIFIER_PATH) == 0) {
- _FLOGI("Checksum of %s is correct", DELTA_VERIFIER_PATH);
- } else {
- ret = -1;
- _FLOGE("Failed checksum verification of %s", DELTA_VERIFIER_PATH);
- goto verify_destroy;
- }
- }
-
- snprintf(buf, MAX_BUFFER_SIZE, "%s %s %s", DELTA_VERIFIER_BIN_PATH, DELTA_VERIFIER_BIN_LONG_ARG, FOTA_DELTA_UPDATE_INFO_PATH);
- ret = system(buf);
-
- if (ret < 0) {
- _FLOGE("Delta verification failed due to an error [return code: %d].", ret);
- goto verify_destroy;
- } else if (ret > 0) {
- _FLOGI("The delta at [%s] is not compatible with this device [return code: %d].", storage_delta_path, ret);
+ /* Check storage have appropriate delta */
+ if (check_is_delta_appropriate(storage_delta_path, NULL) != 0) {
+ ret = -1;
goto verify_destroy;
}