Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions applications/updater/util/update_task_worker_backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -128,17 +126,22 @@ 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 {
update_task_set_progress(update_task, UpdateTaskStageError, update_task->state.progress);
}

return success ? UPDATE_TASK_NOERR : UPDATE_TASK_FAILED;
}
}
20 changes: 12 additions & 8 deletions lib/toolbox/tar/tar_archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) ||
Expand Down Expand Up @@ -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;
}
}