Merge develop into main (#304)
## New - Read property files with `PropertiesFile` - Support `boot.properties` so the user can specify the launcher app and an optional app to start after the launcher finishes. (see `BootProperties.cpp`) - Create registry for CPU affinity and update code to make use of it - `AppRegistration` and `ServiceRegistration` now also ensure that the `/data` directories always exist for all apps - `Notes` is now the default app for opening text files. `TextViewer` is removed entirely. Created `tt::app::notes::start(path)` function. - WiFi settings moved from NVS to properties file. - Specify `*.ap.properties` file on the SD card for automatic WiFi settings import on start-up. - Added `file::getLock(path)` and `file::withLock(path, function)` to do safe file operations on SD cards ## Improvements - Update TinyUSB to `1.7.6~1` - Improved `Boot.cpp` code. General code quality fixes and some restructuring to improve readability. - `tt::string` functionality improvements - Rename `AppRegistry` to `AppRegistration` - Rename `ServiceRegistry` to `ServiceRegistration` - Cleanup in `Notes.cpp` - `FileTest.cpp` fix for PC - Created `TestFile` helper class for tests, which automatically deletes files after the test. - Renamed `Partitions.h` to `MountPoints.h` - Created `std::string getMountPoints()` function for easy re-use - Other code quality improvements - `SdCardDevice`'s `getState()` and `isMounted()` now have a timeout argument ## Fixes - ELF loading now has a lock so to avoid a bug when 2 ELF apps are loaded in parallel
This commit is contained in:
committed by
GitHub
parent
fbaff8cbac
commit
ee5a5a7181
@@ -2,9 +2,9 @@
|
||||
|
||||
#include "Tactility/app/ElfApp.h"
|
||||
#include "Tactility/file/File.h"
|
||||
#include "Tactility/file/FileLock.h"
|
||||
#include "Tactility/service/loader/Loader.h"
|
||||
|
||||
#include "Tactility/hal/sdcard/SdCardDevice.h"
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/StringUtils.h>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace tt::app {
|
||||
|
||||
#define TAG "elf_app"
|
||||
constexpr auto* TAG = "ElfApp";
|
||||
|
||||
struct ElfManifest {
|
||||
/** The user-readable name of the app. Used in UI. */
|
||||
@@ -33,6 +33,7 @@ struct ElfManifest {
|
||||
|
||||
static size_t elfManifestSetCount = 0;
|
||||
static ElfManifest elfManifest;
|
||||
static std::shared_ptr<Lock> elfManifestLock = std::make_shared<Mutex>();
|
||||
|
||||
class ElfApp : public App {
|
||||
|
||||
@@ -48,7 +49,7 @@ class ElfApp : public App {
|
||||
assert(elfFileData == nullptr);
|
||||
|
||||
size_t size = 0;
|
||||
hal::sdcard::withSdCardLock<void>(filePath, [this, &size](){
|
||||
file::withLock<void>(filePath, [this, &size]{
|
||||
elfFileData = file::readBinary(filePath, size);
|
||||
});
|
||||
|
||||
@@ -56,25 +57,30 @@ class ElfApp : public App {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_elf_init(&elf) < 0) {
|
||||
if (esp_elf_init(&elf) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to initialize");
|
||||
shouldCleanupElf = true;
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_elf_relocate(&elf, elfFileData.get()) < 0) {
|
||||
if (esp_elf_relocate(&elf, elfFileData.get()) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to load executable");
|
||||
esp_elf_deinit(&elf);
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
int argc = 0;
|
||||
char* argv[] = {};
|
||||
|
||||
if (esp_elf_request(&elf, 0, argc, argv) < 0) {
|
||||
if (esp_elf_request(&elf, 0, argc, argv) != ESP_OK) {
|
||||
TT_LOG_W(TAG, "Executable returned error code");
|
||||
esp_elf_deinit(&elf);
|
||||
elfFileData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
shouldCleanupElf = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,10 +101,16 @@ public:
|
||||
explicit ElfApp(std::string filePath) : filePath(std::move(filePath)) {}
|
||||
|
||||
void onCreate(AppContext& appContext) override {
|
||||
// Because we use global variables, we have to ensure that we are not starting 2 apps in parallel
|
||||
// We use a ScopedLock so we don't have to safeguard all branches
|
||||
auto lock = elfManifestLock->asScopedLock();
|
||||
lock.lock();
|
||||
|
||||
auto initial_count = elfManifestSetCount;
|
||||
if (startElf()) {
|
||||
if (elfManifestSetCount > initial_count) {
|
||||
manifest = std::make_unique<ElfManifest>(elfManifest);
|
||||
lock.unlock();
|
||||
|
||||
if (manifest->createData != nullptr) {
|
||||
data = manifest->createData();
|
||||
@@ -181,7 +193,7 @@ void registerElfApp(const std::string& filePath) {
|
||||
if (findAppById(filePath) == nullptr) {
|
||||
auto manifest = AppManifest {
|
||||
.id = getElfAppId(filePath),
|
||||
.name = tt::string::removeFileExtension(tt::string::getLastPathSegment(filePath)),
|
||||
.name = string::removeFileExtension(string::getLastPathSegment(filePath)),
|
||||
.type = Type::User,
|
||||
.location = Location::external(filePath)
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user