mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
FBT/SDK: New app flag UnloadAssetPacks to free RAM (#260)
* Store app flags in FAP header * Add app flag to UnloadAssetPacks to free RAM * Unload asset packs in NFC and MFKey * Clearer size units * Update changelog * Future proof logic * Sync apps
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
#include <stdbool.h>
|
||||
#include "elf/elf_api_interface.h"
|
||||
|
||||
#include <applications.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -42,7 +44,22 @@ typedef struct {
|
||||
char icon[FAP_MANIFEST_MAX_ICON_SIZE];
|
||||
} FlipperApplicationManifestV1;
|
||||
|
||||
typedef FlipperApplicationManifestV1 FlipperApplicationManifest;
|
||||
typedef FlipperApplicationManifestV1 FlipperApplicationManifestOfw;
|
||||
|
||||
typedef struct {
|
||||
FlipperApplicationManifestBase base;
|
||||
uint16_t stack_size;
|
||||
uint32_t app_version;
|
||||
char name[FAP_MANIFEST_MAX_APP_NAME_LENGTH];
|
||||
char has_icon;
|
||||
char icon[FAP_MANIFEST_MAX_ICON_SIZE];
|
||||
|
||||
FlipperApplicationFlag flags;
|
||||
} FlipperApplicationManifestV1Ex;
|
||||
|
||||
typedef FlipperApplicationManifestV1Ex FlipperApplicationManifestEx;
|
||||
|
||||
typedef FlipperApplicationManifestEx FlipperApplicationManifest;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ struct FlipperApplication {
|
||||
ELFFile* elf;
|
||||
FuriThread* thread;
|
||||
void* ep_thread_args;
|
||||
|
||||
bool preloaded_manifest;
|
||||
};
|
||||
|
||||
/********************** Debugger access to loader state **********************/
|
||||
@@ -127,7 +129,9 @@ static bool flipper_application_process_manifest_section(
|
||||
void* context) {
|
||||
FlipperApplicationManifest* manifest = context;
|
||||
|
||||
if(size < sizeof(FlipperApplicationManifest)) {
|
||||
// Support both OFW manifest and extended manifest with flags
|
||||
if(size < sizeof(FlipperApplicationManifestOfw) ||
|
||||
size > sizeof(FlipperApplicationManifestEx)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -135,8 +139,15 @@ static bool flipper_application_process_manifest_section(
|
||||
return true;
|
||||
}
|
||||
|
||||
return storage_file_seek(file, offset, true) &&
|
||||
storage_file_read(file, manifest, size) == size;
|
||||
bool result = storage_file_seek(file, offset, true) &&
|
||||
storage_file_read(file, manifest, size) == size;
|
||||
|
||||
// Default flags when loading OFW manifests that don't include flags
|
||||
if(result && size < sizeof(FlipperApplicationManifestEx)) {
|
||||
manifest->flags = FlipperApplicationFlagDefault;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// we can't use const char* as context because we will lose the const qualifier
|
||||
@@ -155,7 +166,7 @@ static bool flipper_application_process_assets_section(
|
||||
|
||||
static FlipperApplicationPreloadStatus
|
||||
flipper_application_load(FlipperApplication* app, const char* path, bool load_full) {
|
||||
if(!elf_file_open(app->elf, path)) {
|
||||
if(!app->preloaded_manifest && !elf_file_open(app->elf, path)) {
|
||||
return FlipperApplicationPreloadStatusInvalidFile;
|
||||
}
|
||||
|
||||
@@ -181,12 +192,18 @@ static FlipperApplicationPreloadStatus
|
||||
}
|
||||
|
||||
// load manifest section
|
||||
if(elf_process_section(
|
||||
if(!app->preloaded_manifest &&
|
||||
elf_process_section(
|
||||
app->elf, ".fapmeta", flipper_application_process_manifest_section, &app->manifest) !=
|
||||
ElfProcessSectionResultSuccess) {
|
||||
ElfProcessSectionResultSuccess) {
|
||||
return FlipperApplicationPreloadStatusInvalidFile;
|
||||
}
|
||||
|
||||
// Avoid preloading manifest twice, when user calls both preload_manifest() and preload()
|
||||
if(!load_full) {
|
||||
app->preloaded_manifest = true;
|
||||
}
|
||||
|
||||
return flipper_application_validate_manifest(app);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user