[FL-2477] Updater support for resource bundles (#1131)

* Resource unpacking core
* Added more fields to manifest; updated dist scripts
* Python linter fixes
* Parsing manifest before unpacking
* Updated pipelines for separate resource build
* Removed raw path formatting
* Visual progress for resource extraction
* Renamed update status enum

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
hedger
2022-04-19 11:03:28 +03:00
committed by GitHub
parent 1623134a82
commit e8499e4ede
12 changed files with 260 additions and 47 deletions

View File

@@ -73,7 +73,7 @@ bool updater_scene_main_on_event(void* context, SceneManagerEvent event) {
case UpdaterCustomEventRetryUpdate:
if(!update_task_is_running(updater->update_task) &&
(update_task_get_state(updater->update_task)->stage != UpdateTaskStageComplete))
(update_task_get_state(updater->update_task)->stage != UpdateTaskStageCompleted))
update_task_start(updater->update_task);
consumed = true;
break;

View File

@@ -19,7 +19,8 @@ static const char* update_task_stage_descr[] = {
[UpdateTaskStageRadioCommit] = "Applying radio stack",
[UpdateTaskStageLfsBackup] = "Backing up LFS",
[UpdateTaskStageLfsRestore] = "Restoring LFS",
[UpdateTaskStageComplete] = "Complete",
[UpdateTaskStageAssetsUpdate] = "Updating assets",
[UpdateTaskStageCompleted] = "Completed!",
[UpdateTaskStageError] = "Error",
};

View File

@@ -23,7 +23,8 @@ typedef enum {
UpdateTaskStageRadioCommit,
UpdateTaskStageLfsBackup,
UpdateTaskStageLfsRestore,
UpdateTaskStageComplete,
UpdateTaskStageAssetsUpdate,
UpdateTaskStageCompleted,
UpdateTaskStageError,
} UpdateTaskStage;

View File

@@ -8,6 +8,7 @@
#include <update_util/dfu_file.h>
#include <update_util/lfs_backup.h>
#include <update_util/update_operation.h>
#include <toolbox/tar/tar_archive.h>
#define CHECK_RESULT(x) \
if(!(x)) { \
@@ -19,6 +20,8 @@
/* Written into DFU file by build pipeline */
#define FLIPPER_ZERO_DFU_DEVICE_CODE 0xFFFF
#define EXT_PATH "/ext"
static const DfuValidationParams flipper_dfu_params = {
.device = FLIPPER_ZERO_DFU_DEVICE_CODE,
.product = STM_DFU_PRODUCT_ID,
@@ -85,7 +88,7 @@ int32_t update_task_worker_flash_writer(void* context) {
CHECK_RESULT(dfu_file_process_targets(&page_task, update_task->file, valid_targets));
}
update_task_set_progress(update_task, UpdateTaskStageComplete, 100);
update_task_set_progress(update_task, UpdateTaskStageCompleted, 100);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePostUpdate);
@@ -99,6 +102,95 @@ int32_t update_task_worker_flash_writer(void* context) {
return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED;
}
static bool update_task_pre_update(UpdateTask* update_task) {
bool success = false;
string_t backup_file_path;
string_init(backup_file_path);
path_concat(
string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, backup_file_path);
update_task->state.total_stages = 1;
update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); // to avoid bootloops
if((success = lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate);
}
string_clear(backup_file_path);
return success;
}
typedef struct {
UpdateTask* update_task;
int32_t total_files, processed_files;
} TarUnpackProgress;
static bool update_task_resource_unpack_cb(const char* name, bool is_directory, void* context) {
UNUSED(name);
UNUSED(is_directory);
TarUnpackProgress* unpack_progress = context;
unpack_progress->processed_files++;
update_task_set_progress(
unpack_progress->update_task,
UpdateTaskStageProgress,
unpack_progress->processed_files * 100 / (unpack_progress->total_files + 1));
return true;
}
static bool update_task_post_update(UpdateTask* update_task) {
bool success = false;
string_t file_path;
string_init(file_path);
update_task->state.total_stages = 2;
do {
CHECK_RESULT(update_task_parse_manifest(update_task));
path_concat(
string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, file_path);
bool unpack_resources = !string_empty_p(update_task->manifest->resource_bundle);
if(unpack_resources) {
update_task->state.total_stages++;
}
update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
CHECK_RESULT(lfs_backup_unpack(update_task->storage, string_get_cstr(file_path)));
if(unpack_resources) {
TarUnpackProgress progress = {
.update_task = update_task,
.total_files = 0,
.processed_files = 0,
};
update_task_set_progress(update_task, UpdateTaskStageAssetsUpdate, 0);
path_concat(
string_get_cstr(update_task->update_path),
string_get_cstr(update_task->manifest->resource_bundle),
file_path);
update_task_set_progress(update_task, UpdateTaskStageProgress, 0);
TarArchive* archive = tar_archive_alloc(update_task->storage);
tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress);
success = tar_archive_open(archive, string_get_cstr(file_path), TAR_OPEN_MODE_READ);
if(success) {
progress.total_files = tar_archive_get_entries_count(archive);
if(progress.total_files > 0) {
tar_archive_unpack_to(archive, EXT_PATH);
}
}
tar_archive_free(archive);
}
} while(false);
string_clear(file_path);
return success;
}
int32_t update_task_worker_backup_restore(void* context) {
furi_assert(context);
UpdateTask* update_task = context;
@@ -112,37 +204,22 @@ int32_t update_task_worker_backup_restore(void* context) {
}
update_task->state.current_stage_idx = 0;
update_task->state.total_stages = 1;
if(!update_operation_get_current_package_path(update_task->storage, update_task->update_path)) {
return UPDATE_TASK_FAILED;
}
string_t backup_file_path;
string_init(backup_file_path);
path_concat(
string_get_cstr(update_task->update_path), LFS_BACKUP_DEFAULT_FILENAME, backup_file_path);
if(boot_mode == FuriHalRtcBootModePreUpdate) {
update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); // to avoid bootloops
if((success =
lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate);
}
success = update_task_pre_update(update_task);
} else if(boot_mode == FuriHalRtcBootModePostUpdate) {
update_task_set_progress(update_task, UpdateTaskStageLfsRestore, 0);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
success = lfs_backup_unpack(update_task->storage, string_get_cstr(backup_file_path));
success = update_task_post_update(update_task);
}
if(success) {
update_task_set_progress(update_task, UpdateTaskStageComplete, 100);
update_task_set_progress(update_task, UpdateTaskStageCompleted, 100);
} else {
update_task_set_progress(update_task, UpdateTaskStageError, update_task->state.progress);
}
string_clear(backup_file_path);
return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED;
}
}