mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 21:28:36 -07:00
Merge pull request #114 from Next-Flip/gzipped-resources
Updater: Gzipped resources (220% faster FW upload) + Updater improvements
This commit is contained in:
@@ -238,7 +238,7 @@ static const UpdateTaskStageGroupMap update_task_stage_progress[] = {
|
||||
[UpdateTaskStageOBValidation] = STAGE_DEF(UpdateTaskStageGroupOptionBytes, 2),
|
||||
|
||||
[UpdateTaskStageValidateDFUImage] = STAGE_DEF(UpdateTaskStageGroupFirmware, 30),
|
||||
[UpdateTaskStageFlashWrite] = STAGE_DEF(UpdateTaskStageGroupFirmware, 150),
|
||||
[UpdateTaskStageFlashWrite] = STAGE_DEF(UpdateTaskStageGroupFirmware, 75),
|
||||
[UpdateTaskStageFlashValidate] = STAGE_DEF(UpdateTaskStageGroupFirmware, 15),
|
||||
|
||||
[UpdateTaskStageLfsRestore] = STAGE_DEF(UpdateTaskStageGroupPostUpdate, 5),
|
||||
@@ -334,11 +334,23 @@ void update_task_set_progress(UpdateTask* update_task, UpdateTaskStage stage, ui
|
||||
update_task->state.overall_progress = adapted_progress;
|
||||
|
||||
if(update_task->status_change_cb) {
|
||||
(update_task->status_change_cb)(
|
||||
furi_string_get_cstr(update_task->state.status),
|
||||
adapted_progress,
|
||||
update_stage_is_error(update_task->state.stage),
|
||||
update_task->status_change_cb_state);
|
||||
if(update_stage_is_error(update_task->state.stage)) {
|
||||
(update_task->status_change_cb)(
|
||||
furi_string_get_cstr(update_task->state.status),
|
||||
adapted_progress,
|
||||
update_stage_is_error(update_task->state.stage),
|
||||
update_task->status_change_cb_state);
|
||||
} else {
|
||||
size_t len = furi_string_size(update_task->state.status) + strlen(" 100%") + 1;
|
||||
char* s = malloc(len);
|
||||
snprintf(s, len, "%s %d%%", furi_string_get_cstr(update_task->state.status), progress);
|
||||
(update_task->status_change_cb)(
|
||||
s,
|
||||
adapted_progress,
|
||||
update_stage_is_error(update_task->state.stage),
|
||||
update_task->status_change_cb_state);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <update_util/lfs_backup.h>
|
||||
#include <update_util/update_operation.h>
|
||||
#include <update_util/resources/manifest.h>
|
||||
#include <update_util/resources/manifest_i.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <toolbox/tar/tar_archive.h>
|
||||
#include <toolbox/crc32_calc.h>
|
||||
|
||||
@@ -39,34 +41,24 @@ static bool update_task_pre_update(UpdateTask* update_task) {
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
UpdateTaskResourcesWeightsFileCleanup = 20,
|
||||
UpdateTaskResourcesWeightsDirCleanup = 20,
|
||||
UpdateTaskResourcesWeightsFileUnpack = 60,
|
||||
UpdateTaskResourcesWeightsFileCleanup = 10,
|
||||
UpdateTaskResourcesWeightsDirCleanup = 10,
|
||||
UpdateTaskResourcesWeightsFileUnpack = 80,
|
||||
} UpdateTaskResourcesWeights;
|
||||
|
||||
#define UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT 90
|
||||
|
||||
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++;
|
||||
static void update_task_resource_progress_cb(size_t progress, size_t total, void* context) {
|
||||
UpdateTask* update_task = context;
|
||||
update_task_set_progress(
|
||||
unpack_progress->update_task,
|
||||
update_task,
|
||||
UpdateTaskStageProgress,
|
||||
/* For this stage, last progress segment = extraction */
|
||||
(UpdateTaskResourcesWeightsFileCleanup + UpdateTaskResourcesWeightsDirCleanup) +
|
||||
(unpack_progress->processed_files * UpdateTaskResourcesWeightsFileUnpack) /
|
||||
(unpack_progress->total_files + 1));
|
||||
return true;
|
||||
(progress * UpdateTaskResourcesWeightsFileUnpack) / total);
|
||||
}
|
||||
|
||||
static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_t n_tar_entries) {
|
||||
static void update_task_cleanup_resources(UpdateTask* update_task) {
|
||||
ResourceManifestReader* manifest_reader = resource_manifest_reader_alloc(update_task->storage);
|
||||
do {
|
||||
FURI_LOG_D(TAG, "Cleaning up old manifest");
|
||||
@@ -75,8 +67,7 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_
|
||||
break;
|
||||
}
|
||||
|
||||
const uint32_t n_approx_file_entries =
|
||||
n_tar_entries * UPDATE_TASK_RESOURCES_FILE_TO_TOTAL_PERCENT / 100 + 1;
|
||||
size_t manifest_size = stream_size(manifest_reader->stream);
|
||||
uint32_t n_dir_entries = 1;
|
||||
|
||||
ResourceManifestEntry* entry_ptr = NULL;
|
||||
@@ -87,8 +78,9 @@ static void update_task_cleanup_resources(UpdateTask* update_task, const uint32_
|
||||
update_task,
|
||||
UpdateTaskStageProgress,
|
||||
/* For this stage, first pass = old manifest's file cleanup */
|
||||
(n_processed_entries++ * UpdateTaskResourcesWeightsFileCleanup) /
|
||||
n_approx_file_entries);
|
||||
(stream_tell(manifest_reader->stream) *
|
||||
UpdateTaskResourcesWeightsFileCleanup) /
|
||||
manifest_size);
|
||||
|
||||
FuriString* file_path = furi_string_alloc();
|
||||
path_concat(
|
||||
@@ -177,11 +169,6 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
||||
#endif
|
||||
|
||||
if(update_task->state.groups & UpdateTaskStageGroupResources) {
|
||||
TarUnpackProgress progress = {
|
||||
.update_task = update_task,
|
||||
.total_files = 0,
|
||||
.processed_files = 0,
|
||||
};
|
||||
update_task_set_progress(update_task, UpdateTaskStageResourcesUpdate, 0);
|
||||
|
||||
path_concat(
|
||||
@@ -189,16 +176,13 @@ static bool update_task_post_update(UpdateTask* update_task) {
|
||||
furi_string_get_cstr(update_task->manifest->resource_bundle),
|
||||
file_path);
|
||||
|
||||
tar_archive_set_file_callback(archive, update_task_resource_unpack_cb, &progress);
|
||||
tar_archive_set_read_callback(archive, update_task_resource_progress_cb, update_task);
|
||||
CHECK_RESULT(
|
||||
tar_archive_open(archive, furi_string_get_cstr(file_path), TAR_OPEN_MODE_READ));
|
||||
|
||||
progress.total_files = tar_archive_get_entries_count(archive);
|
||||
if(progress.total_files > 0) {
|
||||
update_task_cleanup_resources(update_task, progress.total_files);
|
||||
update_task_cleanup_resources(update_task);
|
||||
|
||||
CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL));
|
||||
}
|
||||
CHECK_RESULT(tar_archive_unpack_to(archive, STORAGE_EXT_PATH_PREFIX, NULL));
|
||||
}
|
||||
|
||||
if(update_task->state.groups & UpdateTaskStageGroupSplashscreen) {
|
||||
|
||||
Reference in New Issue
Block a user