From 28beff1ab66892bafe73769b0c46dd56523bec4a Mon Sep 17 00:00:00 2001 From: hedger Date: Thu, 15 Sep 2022 17:40:26 +0400 Subject: [PATCH 1/3] Fbt: fixed gdb-py path for MacOS, docs: spelling fixes, codeowners (#1736) * fbt: fixed gdb-py path for MacOS, docs: spelling fixes * Gtihub: update codeowners Co-authored-by: Aleksandr Kutuzov --- .github/CODEOWNERS | 102 +++++++++++++--------------------- .vscode/example/settings.json | 2 +- applications/ReadMe.md | 5 +- documentation/AppsOnSDCard.md | 20 +++---- documentation/OTA.md | 22 ++++---- 5 files changed, 63 insertions(+), 88 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 6dac0496a..c9b8ff3f5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,82 +2,58 @@ * @skotopes @DrZlo13 @hedger # Apps -/applications/about/ @skotopes @DrZlo13 @hedger -/applications/accessor/ @skotopes @DrZlo13 @hedger -/applications/archive/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/bad_usb/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/bt/ @skotopes @DrZlo13 @hedger @gornekich -/applications/cli/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/crypto/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/debug_tools/ @skotopes @DrZlo13 @hedger -/applications/desktop/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/dialogs/ @skotopes @DrZlo13 @hedger -/applications/dolphin/ @skotopes @DrZlo13 @hedger -/applications/gpio/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/gui/ @skotopes @DrZlo13 @hedger -/applications/ibutton/ @skotopes @DrZlo13 @hedger @gsurkov -/applications/infrared/ @skotopes @DrZlo13 @hedger @gsurkov -/applications/input/ @skotopes @DrZlo13 @hedger -/applications/lfrfid/ @skotopes @DrZlo13 @hedger -/applications/lfrfid_debug/ @skotopes @DrZlo13 @hedger -/applications/loader/ @skotopes @DrZlo13 @hedger -/applications/music_player/ @skotopes @DrZlo13 @hedger -/applications/nfc/ @skotopes @DrZlo13 @hedger @gornekich -/applications/notification/ @skotopes @DrZlo13 @hedger -/applications/power/ @skotopes @DrZlo13 @hedger -/applications/rpc/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/snake_game/ @skotopes @DrZlo13 @hedger -/applications/storage/ @skotopes @DrZlo13 @hedger -/applications/storage_settings/ @skotopes @DrZlo13 @hedger -/applications/subghz/ @skotopes @DrZlo13 @hedger @Skorpionm -/applications/system/ @skotopes @DrZlo13 @hedger -/applications/u2f/ @skotopes @DrZlo13 @hedger @nminaylov -/applications/unit_tests/ @skotopes @DrZlo13 @hedger -/applications/updater/ @skotopes @DrZlo13 @hedger +/applications/debug/bt_debug_app/ @skotopes @DrZlo13 @hedger @gornekich +/applications/debug/accessor/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/battery_test_app/ @skotopes @DrZlo13 @hedger @gornekich +/applications/debug/bt_debug_app/ @skotopes @DrZlo13 @hedger @gornekich +/applications/debug/file_browser_test/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/lfrfid_debug/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/text_box_test/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/uart_echo/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/usb_mouse/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/debug/usb_test/ @skotopes @DrZlo13 @hedger @nminaylov -# Assets -/assets/ @skotopes @DrZlo13 @hedger +/applications/main/archive/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/main/bad_usb/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/main/gpio/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/main/ibutton/ @skotopes @DrZlo13 @hedger @gsurkov +/applications/main/infrared/ @skotopes @DrZlo13 @hedger @gsurkov +/applications/main/nfc/ @skotopes @DrZlo13 @hedger @gornekich +/applications/main/subghz/ @skotopes @DrZlo13 @hedger @Skorpionm +/applications/main/u2f/ @skotopes @DrZlo13 @hedger @nminaylov -# Furi Core -/furi/ @skotopes @DrZlo13 @hedger +/applications/plugins/bt_hid_app/ @skotopes @DrZlo13 @hedger @gornekich +/applications/plugins/picopass/ @skotopes @DrZlo13 @hedger @gornekich -# Debug tools and plugins -/debug/ @skotopes @DrZlo13 @hedger +/applications/services/bt/ @skotopes @DrZlo13 @hedger @gornekich +/applications/services/cli/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/crypto/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/desktop/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/dolphin/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/power/ @skotopes @DrZlo13 @hedger @gornekich +/applications/services/rpc/ @skotopes @DrZlo13 @hedger @nminaylov + +/applications/services/bt_settings_app/ @skotopes @DrZlo13 @hedger @gornekich +/applications/services/desktop_settings/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/dolphin_passport/ @skotopes @DrZlo13 @hedger @nminaylov +/applications/services/power_settings_app/ @skotopes @DrZlo13 @hedger @gornekich + +/applications/system/storage_move_to_sd/ @skotopes @DrZlo13 @hedger @nminaylov # Documentation /documentation/ @skotopes @DrZlo13 @hedger @drunkbatya - -# Firmware targets -/firmware/ @skotopes @DrZlo13 @hedger +/scripts/toolchain/ @skotopes @DrZlo13 @hedger @drunkbatya # Lib -/lib/FreeRTOS-Kernel/ @skotopes @DrZlo13 @hedger -/lib/FreeRTOS-glue/ @skotopes @DrZlo13 @hedger /lib/ST25RFAL002/ @skotopes @DrZlo13 @hedger @gornekich /lib/STM32CubeWB/ @skotopes @DrZlo13 @hedger @gornekich -/lib/app-scened-template/ @skotopes @DrZlo13 @hedger -/lib/callback-connector/ @skotopes @DrZlo13 @hedger /lib/digital_signal/ @skotopes @DrZlo13 @hedger @gornekich -/lib/drivers/ @skotopes @DrZlo13 @hedger -/lib/fatfs/ @skotopes @DrZlo13 @hedger -/lib/flipper_format/ @skotopes @DrZlo13 @hedger -/lib/fnv1a-hash/ @skotopes @DrZlo13 @hedger -/lib/heatshrink/ @skotopes @DrZlo13 @hedger /lib/infrared/ @skotopes @DrZlo13 @hedger @gsurkov +/lib/lfrfid/ @skotopes @DrZlo13 @hedger @nminaylov /lib/libusb_stm32/ @skotopes @DrZlo13 @hedger @nminaylov -/lib/littlefs/ @skotopes @DrZlo13 @hedger -/lib/lfs_config.h @skotopes @DrZlo13 @hedger +/lib/mbedtls/ @skotopes @DrZlo13 @hedger @nminaylov /lib/micro-ecc/ @skotopes @DrZlo13 @hedger @nminaylov -/lib/microtar/ @skotopes @DrZlo13 @hedger -/lib/mlib/ @skotopes @DrZlo13 @hedger -/lib/nanopb/ @skotopes @DrZlo13 @hedger +/lib/nanopb/ @skotopes @DrZlo13 @hedger @nminaylov /lib/nfc/ @skotopes @DrZlo13 @hedger @gornekich -/lib/one_wire/ @skotopes @DrZlo13 @hedger -/lib/qrcode/ @skotopes @DrZlo13 @hedger +/lib/one_wire/ @skotopes @DrZlo13 @hedger @gsurkov /lib/subghz/ @skotopes @DrZlo13 @hedger @Skorpionm -/lib/toolbox/ @skotopes @DrZlo13 @hedger -/lib/u8g2/ @skotopes @DrZlo13 @hedger -/lib/update_util/ @skotopes @DrZlo13 @hedger - -# Helper scripts -/scripts/ @skotopes @DrZlo13 @hedger diff --git a/.vscode/example/settings.json b/.vscode/example/settings.json index 0a05da67c..d2917a90e 100644 --- a/.vscode/example/settings.json +++ b/.vscode/example/settings.json @@ -14,7 +14,7 @@ "cortex-debug.openocdPath.osx": "${workspaceFolder}/toolchain/x86_64-darwin/openocd/bin/openocd", "cortex-debug.gdbPath.windows": "${workspaceFolder}/toolchain/i686-windows/bin/arm-none-eabi-gdb-py.bat", "cortex-debug.gdbPath.linux": "${workspaceFolder}/toolchain/x86_64-linux/bin/arm-none-eabi-gdb-py", - "cortex-debug.gdbPath.osx": "${workspaceFolder}/toolchain/x86_64-darwin/bin/arm-none-eabi-gdb", + "cortex-debug.gdbPath.osx": "${workspaceFolder}/toolchain/x86_64-darwin/bin/arm-none-eabi-gdb-py", "editor.formatOnSave": true, "files.associations": { "*.scons": "python", diff --git a/applications/ReadMe.md b/applications/ReadMe.md index aee612578..6224cb45a 100644 --- a/applications/ReadMe.md +++ b/applications/ReadMe.md @@ -1,8 +1,5 @@ # Structure -- `application.h` - Firmware application list header - - ## debug Applications for factory testing the Flipper. @@ -53,6 +50,8 @@ Extra apps for Plugins & App Loader menus. Background services providing system APIs to applications. +- `applications.h` - Firmware application list header + - `bt` - BLE service and application - `cli` - Console service and API - `crypto` - Crypto cli tools diff --git a/documentation/AppsOnSDCard.md b/documentation/AppsOnSDCard.md index 42d3871f4..525821530 100644 --- a/documentation/AppsOnSDCard.md +++ b/documentation/AppsOnSDCard.md @@ -1,20 +1,20 @@ -### FAP (Flipper Application Package) +# FAP (Flipper Application Package) [fbt](./fbt.md) has support for building applications as FAP files. FAP are essentially .elf executables with extra metadata and resources bundled in. FAPs are built with `firmware_extapps` (or `plugin_dist`) **`fbt`** targets. -FAPs do not depend on being ran on a specific firmware version. Compatibility is determined by the FAP's metadata, which includes the required [API version](#api-versioning). +FAPs do not depend on being run on a specific firmware version. Compatibility is determined by the FAP's metadata, which includes the required [API version](#api-versioning). ## How to set up an application to be built as a FAP FAPs are created and developed the same way as internal applications that are part of the firmware. -To build your application as a FAP, just create a folder with your app's source code in `applications_user` folder, then write its code the way you'd do when creating a regular built-in application. Then configure its `application.fam` manifest — and set its *apptype* to FlipperAppType.EXTERNAL. See [Application Manifests](./AppManifests.md#application-definition) for more details. +To build your application as a FAP, just create a folder with your app's source code in `applications_user`, then write its code the way you'd do when creating a regular built-in application. Then configure its `application.fam` manifest — and set its *apptype* to FlipperAppType.EXTERNAL. See [Application Manifests](./AppManifests.md#application-definition) for more details. * To build your application, run `./fbt firmware_{APPID}`, where APPID is your application's ID in its manifest. - * To build your app, upload it over USB & run it on Flipper, run `./fbt launch_app APPSRC=applications/path/to/app`. This action is configured in default [VSCode profile](../.vscode/ReadMe.md) as "Launch App on Flipper" build action (Ctrl+Shift+B menu). + * To build your app, then upload it over USB & run it on Flipper, use `./fbt launch_app APPSRC=applications/path/to/app`. This command is configured in default [VSCode profile](../.vscode/ReadMe.md) as "Launch App on Flipper" build action (Ctrl+Shift+B menu). * To build all FAPs, run `./fbt plugin_dist`. @@ -40,18 +40,18 @@ It is **important** that firmware and application build type (debug/release) mat ## How Flipper runs an application from SD card -Flipper's MCU cannot run code directly from external storage, so it needs to be copied to RAM first. This is done by the App Loader application, which is responsible for loading the FAP from SD card, verifying its integrity and compatibility and copying it to RAM. +Flipper's MCU cannot run code directly from external storage, so it needs to be copied to RAM first. That is done by the App Loader application, which is responsible for loading the FAP from SD card, verifying its integrity and compatibility, copying it to RAM and adjusting it for its new location. -Since FAP has to be loaded to RAM to be executed, the amount of RAM available for allocations from heap is reduced compared to running the same app from flash, as a part of firmware. Note that amount of occupied RAM is less than total FAP file size, since only code and data sections are allocated, and FAP file includes extra information only used at app load time. +Since FAP has to be loaded to RAM to be executed, the amount of RAM available for allocations from heap is reduced compared to running the same app from flash, as a part of firmware. Note that the amount of occupied RAM is less than total FAP file size, since only code and data sections are allocated, while FAP file includes extra information only used at app load time. -Applications are built for a specific API version. It is a part of hardware target's definition and contains a major and minor version number. Application loader checks if the application's major API version matches firmware's major API version. +Applications are built for a specific API version. It is a part of the hardware target's definition and contains a major and minor version number. Application loader checks if the application's major API version matches firmware's major API version. App loader allocates memory for the application and copies it to RAM, processing relocations and providing concrete addresses for imported symbols using the [symbol table](#symbol-table). Then it starts the application. ## API Versioning -Not all parts of firmware are available for external applications. Subset of available functions and variables is defined in "api_symbols.csv" file, which is a part of firmware target definition in `firmware/targets/` directory. +Not all parts of firmware are available for external applications. A subset of available functions and variables is defined in "api_symbols.csv" file, which is a part of firmware target definition in `firmware/targets/` directory. **`fbt`** uses semantic versioning for API versioning. Major version is incremented when there are breaking changes in the API, minor version is incremented when there are new features added. @@ -59,7 +59,7 @@ Breaking changes include: - removal of a function or a global variable; - changing the signature of a function. -API versioning is mostly automated by **`fbt`**. When rebuilding the firmware, **`fbt`** checks if there are any changes in the API exposed by headers gathered from `SDK_HEADERS`. If there are, it stops the build, adjusts API version and asks the user to go through the changes in .csv file. New entries are marked with "`?`" mark, and the user is supposed to change the mark to "`+`" for the entry to be exposed for FAPs, "`-`" for it to be unavailable. +API versioning is mostly automated by **`fbt`**. When rebuilding the firmware, **`fbt`** checks if there are any changes in the API exposed by headers gathered from `SDK_HEADERS`. If there are, it stops the build, adjusts the API version and asks the user to go through the changes in .csv file. New entries are marked with "`?`" mark, and the user is supposed to change the mark to "`+`" for the entry to be exposed for FAPs, "`-`" for it to be unavailable. **`fbt`** will not allow building a firmware until all "`?`" entries are changed to "`+`" or "`-`". @@ -67,6 +67,6 @@ API versioning is mostly automated by **`fbt`**. When rebuilding the firmware, * ### Symbol Table -Symbol table is a list of symbols exported by firmware and available for external applications. It is generated by **`fbt`** from the API symbols file and is used by the App Loader to resolve addresses of imported symbols. It is build as a part of the `fap_loader` application. +The symbol table is a list of symbols exported by firmware and available for external applications. It is generated by **`fbt`** from the API symbols file and is used by the App Loader to resolve addresses of imported symbols. It is build as a part of the `fap_loader` application. **`fbt`** also checks if all imported symbols are present in the symbol table. If there are any missing symbols, it will issue a warning listing them. Such application won't be able to run on the device until all requires symbols are provided in the symbol table. diff --git a/documentation/OTA.md b/documentation/OTA.md index 2a6b09846..836bc1b71 100644 --- a/documentation/OTA.md +++ b/documentation/OTA.md @@ -1,8 +1,8 @@ # Executing code from RAM -In Flipper firmware, we have a special boot mode that loads a specially crafted system image into RAM and transfers control to it. System image executing in RAM has full write access to whole Flipper's flash memory — something that's not possible when running main code from same flash. +In Flipper firmware, we have a special boot mode that loads a specially crafted system image into RAM and transfers control to it. System image executing in RAM has full write access to whole Flipper's flash memory — something that's not possible when running main code from the same flash. -We leverage that boot mode to perform OTA firmware updates, including operations on radio stack running on second MCU core. +We leverage that boot mode to perform OTA firmware updates, including operations on a radio stack running on the second MCU core. # How does Flipper OTA work? @@ -22,16 +22,16 @@ For that, main firmware loads an updater image - a customized build of main Flip First, if there's a Radio stack image bundled with the update, updater compares its version with currently installed one. If they don't match, updater performs stack deinstallation followed by writing and installing a new one. The installation itself is performed by proprietary software, FUS, running on Core2, and leads to a series of system restarts. -Then updater validates and corrects Option Bytes — a special memory region containing low-level configuration for Flipper's MCU. +Then, updater validates and corrects Option Bytes — a special memory region containing low-level configuration for Flipper's MCU. After that, updater loads a `.dfu` file with firmware to be flashed, checks its integrity using CRC32, writes it to system flash and validates written data. ## 3. Restoring internal storage and updating resources -After performing operations on flash memory, system restarts into newly flashed firmware. Then it performs restoration of previously backed up `/int` contents. +After performing operations on flash memory, the system restarts into newly flashed firmware. Then it performs restoration of previously backed up `/int` contents. -If update package contains an additional resources archive, it is extracted onto SD card. +If the update package contains an additional resources archive, it is extracted onto SD card. # Update manifest @@ -40,13 +40,13 @@ Update packages come with a manifest that contains a description of its contents ## Mandatory fields -Update manifest must contain the following keys in given order: +An update manifest must contain the following keys in given order: * __Filetype__: a constant string, "Flipper firmware upgrade configuration"; * __Version__: manifest version. Current value is 2; -* __Info__: arbitraty string, describing package contents; +* __Info__: arbitrary string, describing package contents; * __Target__: hardware revision the package is built for; @@ -56,7 +56,7 @@ Update manifest must contain the following keys in given order: ## Optional fields -Other fields may have empty values, is such case updater skips all operations related to such values. +Other fields may have empty values, is such case, updater skips all operations related to such values. * __Radio__: file name of radio stack image, provided by STM; @@ -66,16 +66,16 @@ Other fields may have empty values, is such case updater skips all operations re * __Radio CRC__: CRC32 of radio image; -* __Resources__: file name of TAR acrhive with resources to be extracted on SD card; +* __Resources__: file name of TAR archive with resources to be extracted on SD card; * __OB reference__, __OB mask__, __OB write mask__: reference values for validating and correcting option bytes. # OTA update error codes -We designed the OTA update process to be as fail-safe as possible. We don't start any risky operation before validating all related pieces of data to ensure we don't leave the device in partially updated, or bricked, state. +We designed the OTA update process to be as fail-safe as possible. We don't start any risky operation before validating all related pieces of data to ensure we don't leave the device in a partially updated, or bricked, state. -Even if something goes wrong, Updater gives you an option to retry failed operations, and reports its state with an error code. These error codes have an `[XX-YY]` format, where `XX` encodes an operation that failed, and `YY` contains extra details on its progress where the error occured. +Even if something goes wrong, Updater gives you an option to retry failed operations, and reports its state with an error code. These error codes have an `[XX-YY]` format, where `XX` encodes an operation that failed, and `YY` contains extra details on its progress where the error occurred. | Stage description | Code | Progress | Description | |:-----------------------:|-------:|------------|--------------------------------------------| From 007a3d295ebe340617e2f6db8498c17a379f8eea Mon Sep 17 00:00:00 2001 From: hedger Date: Thu, 15 Sep 2022 17:55:55 +0400 Subject: [PATCH 2/3] [FL-2819] updater: fixed failing backups on /int with empty files in it #1735 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- lib/toolbox/tar/tar_archive.c | 1 + lib/update_util/lfs_backup.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/toolbox/tar/tar_archive.c b/lib/toolbox/tar/tar_archive.c index 5ac89a0fd..0d42d162c 100644 --- a/lib/toolbox/tar/tar_archive.c +++ b/lib/toolbox/tar/tar_archive.c @@ -294,6 +294,7 @@ bool tar_archive_add_file( break; } + success = true; // if file is empty, that's not an error uint16_t bytes_read = 0; while((bytes_read = storage_file_read(src_file, file_buffer, FILE_BLOCK_SIZE))) { success = tar_archive_file_add_data_block(archive, file_buffer, bytes_read); diff --git a/lib/update_util/lfs_backup.c b/lib/update_util/lfs_backup.c index b4a0aaabb..089f032d4 100644 --- a/lib/update_util/lfs_backup.c +++ b/lib/update_util/lfs_backup.c @@ -42,8 +42,7 @@ bool lfs_backup_create(Storage* storage, const char* destination) { bool lfs_backup_exists(Storage* storage, const char* source) { const char* final_source = source && strlen(source) ? source : LFS_BACKUP_DEFAULT_LOCATION; - FileInfo fi; - return storage_common_stat(storage, final_source, &fi) == FSE_OK; + return storage_common_stat(storage, final_source, NULL) == FSE_OK; } bool lfs_backup_unpack(Storage* storage, const char* source) { From a6052be0f16934b854293bc9241329b1d675586f Mon Sep 17 00:00:00 2001 From: Nikolay Minaylov Date: Thu, 15 Sep 2022 17:13:48 +0300 Subject: [PATCH 3/3] Charging icon update fix (#1733) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Power: refresh battery indicator on charger plug/unplug Co-authored-by: SG Co-authored-by: あく --- applications/services/power/power_service/power.c | 2 ++ applications/services/power/power_service/power.h | 1 + 2 files changed, 3 insertions(+) diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 3a2c6cf3b..85d217f29 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -127,6 +127,7 @@ static void power_check_charging_state(Power* power) { static bool power_update_info(Power* power) { PowerInfo info; + info.is_charging = furi_hal_power_is_charging(); info.gauge_is_ok = furi_hal_power_gauge_is_ok(); info.charge = furi_hal_power_get_pct(); info.health = furi_hal_power_get_bat_health_pct(); @@ -142,6 +143,7 @@ static bool power_update_info(Power* power) { furi_mutex_acquire(power->api_mtx, FuriWaitForever); bool need_refresh = power->info.charge != info.charge; + need_refresh |= power->info.is_charging != info.is_charging; power->info = info; furi_mutex_release(power->api_mtx); diff --git a/applications/services/power/power_service/power.h b/applications/services/power/power_service/power.h index b623452ee..bdf5fa529 100644 --- a/applications/services/power/power_service/power.h +++ b/applications/services/power/power_service/power.h @@ -36,6 +36,7 @@ typedef struct { typedef struct { bool gauge_is_ok; + bool is_charging; float current_charger; float current_gauge;