1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-13 05:19:50 +04:00

[FL-3097] fbt, faploader: minimal app module implementation (#2420)

* fbt, faploader: minimal app module implementation
* faploader, libs: moved API hashtable core to flipper_application
* example: compound api
* lib: flipper_application: naming fixes, doxygen comments
* fbt: changed `requires` manifest field behavior for app extensions
* examples: refactored plugin apps; faploader: changed new API naming; fbt: changed PLUGIN app type meaning
* loader: dropped support for debug apps & plugin menus
* moved applications/plugins -> applications/external
* Restored x bit on chiplist_convert.py
* git: fixed free-dap submodule path
* pvs: updated submodule paths
* examples: example_advanced_plugins.c: removed potential memory leak on errors
* examples: example_plugins: refined requires
* fbt: not deploying app modules for debug/sample apps; extra validation for .PLUGIN-type apps
* apps: removed cdefines for external apps
* fbt: moved ext app path definition
* fbt: reworked fap_dist handling; f18: synced api_symbols.csv
* fbt: removed resources_paths for extapps
* scripts: reworked storage
* scripts: reworked runfap.py & selfupdate.py to use new api
* wip: fal runner
* fbt: moved file packaging into separate module
* scripts: storage: fixes
* scripts: storage: minor fixes for new api
* fbt: changed internal artifact storage details for external apps
* scripts: storage: additional fixes and better error reporting; examples: using APP_DATA_PATH()
* fbt, scripts: reworked launch_app to deploy plugins; moved old runfap.py to distfap.py
* fbt: extra check for plugins descriptors
* fbt: additional checks in emitter
* fbt: better info message on SDK rebuild
* scripts: removed requirements.txt
* loader: removed remnants of plugins & debug menus
* post-review fixes
This commit is contained in:
hedger
2023-03-14 18:29:28 +04:00
committed by GitHub
parent 4bd3dca16f
commit 53435579b3
376 changed files with 2041 additions and 1036 deletions

View File

@@ -10,6 +10,7 @@ struct FlipperApplication {
FlipperApplicationManifest manifest;
ELFFile* elf;
FuriThread* thread;
void* ep_thread_args;
};
/* For debugger access to app state */
@@ -20,9 +21,14 @@ FlipperApplication*
FlipperApplication* app = malloc(sizeof(FlipperApplication));
app->elf = elf_file_alloc(storage, api_interface);
app->thread = NULL;
app->ep_thread_args = NULL;
return app;
}
bool flipper_application_is_plugin(FlipperApplication* app) {
return app->manifest.stack_size == 0;
}
void flipper_application_free(FlipperApplication* app) {
furi_assert(app);
@@ -31,9 +37,16 @@ void flipper_application_free(FlipperApplication* app) {
furi_thread_free(app->thread);
}
last_loaded_app = NULL;
if(!flipper_application_is_plugin(app)) {
last_loaded_app = NULL;
}
elf_file_clear_debug_info(&app->state);
if(elf_file_is_init_complete(app->elf)) {
elf_file_call_fini(app->elf);
}
elf_file_free(app->elf);
free(app);
}
@@ -140,7 +153,9 @@ const FlipperApplicationManifest* flipper_application_get_manifest(FlipperApplic
}
FlipperApplicationLoadStatus flipper_application_map_to_memory(FlipperApplication* app) {
last_loaded_app = app;
if(!flipper_application_is_plugin(app)) {
last_loaded_app = app;
}
ELFFileLoadStatus status = elf_file_load_sections(app->elf);
switch(status) {
@@ -157,9 +172,15 @@ FlipperApplicationLoadStatus flipper_application_map_to_memory(FlipperApplicatio
}
static int32_t flipper_application_thread(void* context) {
elf_file_pre_run(last_loaded_app->elf);
int32_t result = elf_file_run(last_loaded_app->elf, context);
elf_file_post_run(last_loaded_app->elf);
furi_assert(context);
FlipperApplication* app = (FlipperApplication*)context;
elf_file_call_init(app->elf);
FlipperApplicationEntryPoint entry_point = elf_file_get_entry_point(app->elf);
int32_t ret_code = entry_point(app->ep_thread_args);
elf_file_call_fini(app->elf);
// wait until all notifications from RAM are completed
NotificationApp* notifications = furi_record_open(RECORD_NOTIFICATION);
@@ -169,17 +190,17 @@ static int32_t flipper_application_thread(void* context) {
notification_message_block(notifications, &sequence_empty);
furi_record_close(RECORD_NOTIFICATION);
return result;
return ret_code;
}
FuriThread* flipper_application_spawn(FlipperApplication* app, void* args) {
furi_check(app->thread == NULL);
furi_check(!flipper_application_is_plugin(app));
app->ep_thread_args = args;
const FlipperApplicationManifest* manifest = flipper_application_get_manifest(app);
furi_check(manifest->stack_size > 0);
app->thread = furi_thread_alloc_ex(
manifest->name, manifest->stack_size, flipper_application_thread, args);
manifest->name, manifest->stack_size, flipper_application_thread, app);
return app->thread;
}
@@ -213,3 +234,28 @@ const char* flipper_application_load_status_to_string(FlipperApplicationLoadStat
}
return load_status_strings[status];
}
const FlipperAppPluginDescriptor*
flipper_application_plugin_get_descriptor(FlipperApplication* app) {
if(!flipper_application_is_plugin(app)) {
return NULL;
}
if(!elf_file_is_init_complete(app->elf)) {
elf_file_call_init(app->elf);
}
typedef const FlipperAppPluginDescriptor* (*get_lib_descriptor_t)(void);
get_lib_descriptor_t lib_ep = elf_file_get_entry_point(app->elf);
furi_check(lib_ep);
const FlipperAppPluginDescriptor* lib_descriptor = lib_ep();
FURI_LOG_D(
TAG,
"Library for %s, API v. %lu loaded",
lib_descriptor->appid,
lib_descriptor->ep_api_version);
return lib_descriptor;
}