[FL-3289] Various Furi/FuriHal bug fixes and improvements (#2637)

* Furi: properly handle thread free before TCB scrapping, add furi_free - more invasive version of free to memmgr. FuriHal: add DWT comparator api to cortex. Updater, RPC: refactor various thread shanenigans. Code cleanup.
* Rollback free macros and related changes
This commit is contained in:
あく
2023-05-05 21:40:55 +09:00
committed by GitHub
parent a7d1ec03e8
commit 914129a0d9
15 changed files with 204 additions and 70 deletions
+6 -20
View File
@@ -85,22 +85,10 @@ static void updater_cli_ep(Cli* cli, FuriString* args, void* context) {
updater_cli_help(args);
}
static int32_t updater_spawner_thread_worker(void* arg) {
static void updater_start_app(void* context, uint32_t arg) {
UNUSED(context);
UNUSED(arg);
Loader* loader = furi_record_open(RECORD_LOADER);
loader_start(loader, "UpdaterApp", NULL);
furi_record_close(RECORD_LOADER);
return 0;
}
static void updater_spawner_thread_cleanup(FuriThreadState state, void* context) {
FuriThread* thread = context;
if(state == FuriThreadStateStopped) {
furi_thread_free(thread);
}
}
static void updater_start_app() {
FuriHalRtcBootMode mode = furi_hal_rtc_get_boot_mode();
if((mode != FuriHalRtcBootModePreUpdate) && (mode != FuriHalRtcBootModePostUpdate)) {
return;
@@ -110,11 +98,9 @@ static void updater_start_app() {
* inside loader process, at startup.
* So, accessing its record would cause a deadlock
*/
FuriThread* thread =
furi_thread_alloc_ex("UpdateAppSpawner", 768, updater_spawner_thread_worker, NULL);
furi_thread_set_state_callback(thread, updater_spawner_thread_cleanup);
furi_thread_set_state_context(thread, thread);
furi_thread_start(thread);
Loader* loader = furi_record_open(RECORD_LOADER);
loader_start(loader, "UpdaterApp", NULL);
furi_record_close(RECORD_LOADER);
}
void updater_on_system_start() {
@@ -126,7 +112,7 @@ void updater_on_system_start() {
UNUSED(updater_cli_ep);
#endif
#ifndef FURI_RAM_EXEC
updater_start_app();
furi_timer_pending_callback(updater_start_app, NULL, 0);
#else
UNUSED(updater_start_app);
#endif
@@ -346,7 +346,11 @@ int32_t update_task_worker_flash_writer(void* context) {
furi_hal_rtc_set_boot_mode(FuriHalRtcBootModePostUpdate);
// Format LFS before restoring backup on next boot
furi_hal_rtc_set_flag(FuriHalRtcFlagFactoryReset);
#ifdef FURI_NDEBUG
// Production
furi_hal_rtc_set_log_level(FuriLogLevelDefault);
furi_hal_rtc_reset_flag(FuriHalRtcFlagDebug);
#endif
update_task_set_progress(update_task, UpdateTaskStageCompleted, 100);
success = true;
} while(false);