[FL-2510] Fixed BT startup while backing up LFS (#1180)

* Waiting for dummy BT record on LFS ops; cleaner retry for backup file open
* Fixed files not being closed on failed open
This commit is contained in:
hedger 2022-04-28 19:05:37 +03:00 committed by GitHub
parent 19f42c5290
commit fe254d469f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 15 deletions

View file

@ -29,7 +29,8 @@ static bool update_task_pre_update(UpdateTask* update_task) {
update_task->state.total_stages = 1;
update_task_set_progress(update_task, UpdateTaskStageLfsBackup, 0);
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal); // to avoid bootloops
/* to avoid bootloops */
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
if((success = lfs_backup_create(update_task->storage, string_get_cstr(backup_file_path)))) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeUpdate);
}
@ -61,7 +62,7 @@ static bool update_task_post_update(UpdateTask* update_task) {
string_t file_path;
string_init(file_path);
// status text is too long, too few stages to bother with a counter
/* status text is too long, too few stages to bother with a counter */
update_task->state.total_stages = 0;
do {
@ -70,9 +71,6 @@ static bool update_task_post_update(UpdateTask* update_task) {
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);
@ -117,7 +115,7 @@ int32_t update_task_worker_backup_restore(void* context) {
FuriHalRtcBootMode boot_mode = furi_hal_rtc_get_boot_mode();
if((boot_mode != FuriHalRtcBootModePreUpdate) && (boot_mode != FuriHalRtcBootModePostUpdate)) {
// no idea how we got here. Clear to normal boot
/* no idea how we got here. Clear to normal boot */
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModeNormal);
return UPDATE_TASK_NOERR;
}
@ -128,12 +126,17 @@ int32_t update_task_worker_backup_restore(void* context) {
return UPDATE_TASK_FAILED;
}
/* Waiting for BT service to 'start', so we don't race for boot mode */
furi_record_open("bt");
if(boot_mode == FuriHalRtcBootModePreUpdate) {
success = update_task_pre_update(update_task);
} else if(boot_mode == FuriHalRtcBootModePostUpdate) {
success = update_task_post_update(update_task);
}
furi_record_close("bt");
if(success) {
update_task_set_progress(update_task, UpdateTaskStageCompleted, 100);
} else {
@ -141,4 +144,4 @@ int32_t update_task_worker_backup_restore(void* context) {
}
return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED;
}
}

View file

@ -206,12 +206,14 @@ static int archive_extract_foreach_cb(mtar_t* tar, const mtar_header_t* header,
bool failed = false;
uint8_t n_tries = FILE_OPEN_NTRIES;
do {
while(
(n_tries-- > 0) &&
!storage_file_open(out_file, string_get_cstr(fname), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
while(n_tries-- > 0) {
if(storage_file_open(
out_file, string_get_cstr(fname), FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
break;
}
FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", string_get_cstr(fname), n_tries);
storage_file_close(out_file);
osDelay(FILE_OPEN_RETRY_DELAY);
continue;
}
if(!storage_file_is_open(out_file)) {
@ -257,11 +259,13 @@ bool tar_archive_add_file(
File* src_file = storage_file_alloc(archive->storage);
uint8_t n_tries = FILE_OPEN_NTRIES;
do {
while((n_tries-- > 0) &&
!storage_file_open(src_file, fs_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
while(n_tries-- > 0) {
if(storage_file_open(src_file, fs_file_path, FSAM_READ, FSOM_OPEN_EXISTING)) {
break;
}
FURI_LOG_W(TAG, "Failed to open '%s', reties: %d", fs_file_path, n_tries);
storage_file_close(src_file);
osDelay(FILE_OPEN_RETRY_DELAY);
continue;
}
if(!storage_file_is_open(src_file) ||
@ -341,4 +345,4 @@ bool tar_archive_add_dir(TarArchive* archive, const char* fs_full_path, const ch
free(name);
storage_file_free(directory);
return success;
}
}