Skip to content

Commit

Permalink
Storage: remove LFS (#3577)
Browse files Browse the repository at this point in the history
* Storage: drop internal storage

* Storage: rollback some unnecessary changes

* Storage: rollback some unnecessary changes part 2

* Storage: cleanup various defines and int handling. Ble: allow short connection interval if internal flash is not used.

* Storage: do not return storage if it is not ready

* Save PIN code to RTC, update settings

* Simplify the code, clean up includes

* Rearrange some code

* apps: storage_move_to_sd: conditionally enable with --extra-define=STORAGE_INT_ON_LFS

* Load Desktop settings automatically

* Redirect /any to /ext

* Abolish storage_move_to_sd app

* Remove as many mentions of ANY_PATH as possible

* Fix desktop settings wrongly not loading

* Improve desktop settings handling and strings

* Load BLE settings and keys automatically

* Improve BLE configuration procedure

* Do not load bluetooth keys twice if they were already loaded

* Load dolphin state automatically

* Fix merge artifact

* Load notification settings automatically

* Update desktop settings strings

* Load expansion settings automatically

* Do not use thread signals to reload desktop settings

* Load region data automatically, separate to its own hook

* Improve ble behaviour with no keys

* Fix Dolphin state not resetting correctly

* Add a status check

* Make Desktop save its own settings

* Check result when taking and releasing mutex

* Improve default thread signal handling in FuriEventLoop

* Make bt service in charge of saving settings, add settings api

* Fix a deadlock due to timer thread not receiving time

* Lock core2 when reinitialising bt

* Update clang-format

* Revert "Update clang-format"

This reverts commit d61295a.

* Format sources with clang-format

* Revert old stack size for desktop settings

* Allocate big struct dynamically

* Simplify PIN comparison

* Save pointer to storage in Desktop object

* Fix region provisioning for hardware regions

* Remove stale TODO + siimplify code

* Clean up region.c

* Use sizeof instead of macro define

* Limit PIN length to 10 for consistency

* Emit a warning upon usage of /any

* Add delay after finding flipper

* Remove unnecessary delay

* Remove all mentions of STORAGE_INT_ON_LFS

* Remove littlefs and internal storage

* Remove all possible LittleFS mentions

* Fix browser tab in Archive

* Ble: fix connection interval explanation

* Bump API Symbols

* BLE: Update comments interval connection comments

* Storage: clear FuriHalRtcFlagStorageFormatInternal if set

---------

Co-authored-by: Georgii Surkov <[email protected]>
Co-authored-by: hedger <[email protected]>
Co-authored-by: Georgii Surkov <[email protected]>
  • Loading branch information
4 people authored Aug 4, 2024
1 parent 4f46032 commit 4d985ba
Show file tree
Hide file tree
Showing 117 changed files with 1,385 additions and 2,118 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "lib/mlib"]
path = lib/mlib
url = https://github.com/P-p-H-d/mlib.git
[submodule "lib/littlefs"]
path = lib/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "lib/nanopb"]
path = lib/nanopb
url = https://github.com/nanopb/nanopb.git
Expand Down
2 changes: 1 addition & 1 deletion .pvsoptions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
--ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/cmsis_core -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/littlefs -e lib/mbedtls -e lib/microtar -e lib/mlib -e lib/stm32wb_cmsis -e lib/stm32wb_copro -e lib/stm32wb_hal -e lib/u8g2 -e lib/nanopb -e lib/mjs -e */arm-none-eabi/*
--ignore-ccache -C gccarm --rules-config .pvsconfig -e lib/cmsis_core -e lib/fatfs -e lib/fnv1a-hash -e lib/FreeRTOS-Kernel -e lib/heatshrink -e lib/libusb_stm32 -e lib/mbedtls -e lib/microtar -e lib/mlib -e lib/stm32wb_cmsis -e lib/stm32wb_copro -e lib/stm32wb_hal -e lib/u8g2 -e lib/nanopb -e lib/mjs -e */arm-none-eabi/*
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool file_browser_scene_start_on_event(void* context, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
furi_string_set(app->file_path, ANY_PATH("badusb/demo_windows.txt"));
furi_string_set(app->file_path, EXT_PATH("badusb/demo_windows.txt"));
scene_manager_next_scene(app->scene_manager, FileBrowserSceneBrowser);
consumed = true;
} else if(event.type == SceneManagerEventTypeTick) {
Expand Down
8 changes: 4 additions & 4 deletions applications/main/archive/helpers/archive_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ bool archive_app_is_available(void* context, const char* path) {
bool file_exists = false;
Storage* storage = furi_record_open(RECORD_STORAGE);

if(storage_file_exists(storage, ANY_PATH("u2f/key.u2f"))) {
file_exists = storage_file_exists(storage, ANY_PATH("u2f/cnt.u2f"));
if(storage_file_exists(storage, EXT_PATH("u2f/key.u2f"))) {
file_exists = storage_file_exists(storage, EXT_PATH("u2f/cnt.u2f"));
}

furi_record_close(RECORD_STORAGE);
Expand Down Expand Up @@ -68,8 +68,8 @@ void archive_app_delete_file(void* context, const char* path) {

if(app == ArchiveAppTypeU2f) {
Storage* fs_api = furi_record_open(RECORD_STORAGE);
res = (storage_common_remove(fs_api, ANY_PATH("u2f/key.u2f")) == FSE_OK);
res |= (storage_common_remove(fs_api, ANY_PATH("u2f/cnt.u2f")) == FSE_OK);
res = (storage_common_remove(fs_api, EXT_PATH("u2f/key.u2f")) == FSE_OK);
res |= (storage_common_remove(fs_api, EXT_PATH("u2f/cnt.u2f")) == FSE_OK);
furi_record_close(RECORD_STORAGE);

if(archive_is_favorite("/app:u2f/U2F Token")) {
Expand Down
12 changes: 5 additions & 7 deletions applications/main/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,14 @@ void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
}

static bool archive_is_dir_exists(FuriString* path) {
if(furi_string_equal(path, STORAGE_ANY_PATH_PREFIX)) {
return true;
}
bool state = false;
FileInfo file_info;
Storage* storage = furi_record_open(RECORD_STORAGE);
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
if(file_info_is_dir(&file_info)) {
state = true;
}

if(furi_string_equal(path, STORAGE_EXT_PATH_PREFIX)) {
state = storage_sd_status(storage) == FSE_OK;
} else if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
state = file_info_is_dir(&file_info);
}
furi_record_close(RECORD_STORAGE);
return state;
Expand Down
16 changes: 8 additions & 8 deletions applications/main/archive/helpers/archive_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

static const char* tab_default_paths[] = {
[ArchiveTabFavorites] = "/app:favorites",
[ArchiveTabIButton] = ANY_PATH("ibutton"),
[ArchiveTabNFC] = ANY_PATH("nfc"),
[ArchiveTabSubGhz] = ANY_PATH("subghz"),
[ArchiveTabLFRFID] = ANY_PATH("lfrfid"),
[ArchiveTabInfrared] = ANY_PATH("infrared"),
[ArchiveTabBadUsb] = ANY_PATH("badusb"),
[ArchiveTabIButton] = EXT_PATH("ibutton"),
[ArchiveTabNFC] = EXT_PATH("nfc"),
[ArchiveTabSubGhz] = EXT_PATH("subghz"),
[ArchiveTabLFRFID] = EXT_PATH("lfrfid"),
[ArchiveTabInfrared] = EXT_PATH("infrared"),
[ArchiveTabBadUsb] = EXT_PATH("badusb"),
[ArchiveTabU2f] = "/app:u2f",
[ArchiveTabApplications] = ANY_PATH("apps"),
[ArchiveTabBrowser] = STORAGE_ANY_PATH_PREFIX,
[ArchiveTabApplications] = EXT_PATH("apps"),
[ArchiveTabBrowser] = STORAGE_EXT_PATH_PREFIX,
};

static const char* known_ext[] = {
Expand Down
4 changes: 2 additions & 2 deletions applications/main/archive/helpers/archive_favorites.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <storage/storage.h>

#define ARCHIVE_FAV_PATH ANY_PATH("favorites.txt")
#define ARCHIVE_FAV_TEMP_PATH ANY_PATH("favorites.tmp")
#define ARCHIVE_FAV_PATH EXT_PATH("favorites.txt")
#define ARCHIVE_FAV_TEMP_PATH EXT_PATH("favorites.tmp")

uint16_t archive_favorites_count(void* context);
bool archive_favorites_read(void* context);
Expand Down
2 changes: 1 addition & 1 deletion applications/main/bad_usb/bad_usb_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "views/bad_usb_view.h"
#include <furi_hal_usb.h>

#define BAD_USB_APP_BASE_FOLDER ANY_PATH("badusb")
#define BAD_USB_APP_BASE_FOLDER EXT_PATH("badusb")
#define BAD_USB_APP_PATH_LAYOUT_FOLDER BAD_USB_APP_BASE_FOLDER "/assets/layouts"
#define BAD_USB_APP_SCRIPT_EXTENSION ".txt"
#define BAD_USB_APP_LAYOUT_EXTENSION ".kl"
Expand Down
2 changes: 1 addition & 1 deletion applications/main/ibutton/ibutton_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "ibutton_custom_event.h"
#include "scenes/ibutton_scene.h"

#define IBUTTON_APP_FOLDER ANY_PATH("ibutton")
#define IBUTTON_APP_FOLDER EXT_PATH("ibutton")
#define IBUTTON_APP_FILENAME_PREFIX "iBtn"
#define IBUTTON_APP_FILENAME_EXTENSION ".ibtn"

Expand Down
2 changes: 1 addition & 1 deletion applications/main/infrared/infrared_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define INFRARED_MAX_BUTTON_NAME_LENGTH 22
#define INFRARED_MAX_REMOTE_NAME_LENGTH 22

#define INFRARED_APP_FOLDER ANY_PATH("infrared")
#define INFRARED_APP_FOLDER EXT_PATH("infrared")
#define INFRARED_APP_EXTENSION ".ir"

#define INFRARED_DEFAULT_REMOTE_NAME "Remote"
Expand Down
2 changes: 1 addition & 1 deletion applications/main/lfrfid/lfrfid_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define LFRFID_KEY_NAME_SIZE 22
#define LFRFID_TEXT_STORE_SIZE 40

#define LFRFID_APP_FOLDER ANY_PATH("lfrfid")
#define LFRFID_APP_FOLDER EXT_PATH("lfrfid")
#define LFRFID_SD_FOLDER EXT_PATH("lfrfid")
#define LFRFID_APP_FILENAME_PREFIX "RFID"
#define LFRFID_APP_FILENAME_EXTENSION ".rfid"
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/helpers/mf_user_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <nfc/protocols/mf_classic/mf_classic.h>
#include <furi/furi.h>

#define NFC_APP_FOLDER ANY_PATH("nfc")
#define NFC_APP_FOLDER EXT_PATH("nfc")
#define NFC_APP_MF_CLASSIC_DICT_USER_PATH (NFC_APP_FOLDER "/assets/mf_classic_dict_user.nfc")

struct MfUserDict {
Expand Down
2 changes: 1 addition & 1 deletion applications/main/nfc/nfc_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define NFC_TEXT_STORE_SIZE 128
#define NFC_BYTE_INPUT_STORE_SIZE 10
#define NFC_LOG_SIZE_MAX (1024)
#define NFC_APP_FOLDER ANY_PATH("nfc")
#define NFC_APP_FOLDER EXT_PATH("nfc")
#define NFC_APP_EXTENSION ".nfc"
#define NFC_APP_SHADOW_EXTENSION ".shd"
#define NFC_APP_FILENAME_PREFIX "NFC"
Expand Down
1 change: 1 addition & 0 deletions applications/main/subghz/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ App(
"!subghz_cli.c",
"!helpers/subghz_chat.c",
],
requires=["region"],
resources="resources",
fap_libs=["assets", "hwdrivers"],
fap_icon="icon.png",
Expand Down
100 changes: 2 additions & 98 deletions applications/main/subghz/subghz_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@
#include <notification/notification_messages.h>
#include <flipper_format/flipper_format_i.h>

#include <flipper.pb.h>
#include <pb_decode.h>

#define SUBGHZ_FREQUENCY_RANGE_STR \
"299999755...348000000 or 386999938...464000000 or 778999847...928000000"

#define SUBGHZ_REGION_FILENAME "/int/.region_data"

#define TAG "SubGhzCli"

static void subghz_cli_radio_device_power_on(void) {
Expand Down Expand Up @@ -480,7 +475,7 @@ void subghz_cli_command_decode_raw(Cli* cli, FuriString* args, void* context) {
UNUSED(context);
FuriString* file_name;
file_name = furi_string_alloc();
furi_string_set(file_name, ANY_PATH("subghz/test.sub"));
furi_string_set(file_name, EXT_PATH("subghz/test.sub"));

Storage* storage = furi_record_open(RECORD_STORAGE);
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);
Expand Down Expand Up @@ -595,7 +590,7 @@ void subghz_cli_command_tx_from_file(Cli* cli, FuriString* args, void* context)
UNUSED(context);
FuriString* file_name;
file_name = furi_string_alloc();
furi_string_set(file_name, ANY_PATH("subghz/test.sub"));
furi_string_set(file_name, EXT_PATH("subghz/test.sub"));
uint32_t repeat = 10;
uint32_t device_ind = 0; // 0 - CC1101_INT, 1 - CC1101_EXT

Expand Down Expand Up @@ -1199,47 +1194,6 @@ static void subghz_cli_command(Cli* cli, FuriString* args, void* context) {
furi_string_free(cmd);
}

static bool
subghz_on_system_start_istream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
File* file = istream->state;
size_t ret = storage_file_read(file, buf, count);
return count == ret;
}

static bool subghz_on_system_start_istream_decode_band(
pb_istream_t* stream,
const pb_field_t* field,
void** arg) {
(void)field;
FuriHalRegion* region = *arg;

PB_Region_Band band = {0};
if(!pb_decode(stream, PB_Region_Band_fields, &band)) {
FURI_LOG_E("SubGhzOnStart", "PB Region band decode error: %s", PB_GET_ERROR(stream));
return false;
}

region->bands_count += 1;
region = realloc( //-V701
region,
sizeof(FuriHalRegion) + sizeof(FuriHalRegionBand) * region->bands_count);
size_t pos = region->bands_count - 1;
region->bands[pos].start = band.start;
region->bands[pos].end = band.end;
region->bands[pos].power_limit = band.power_limit;
region->bands[pos].duty_cycle = band.duty_cycle;
*arg = region;

FURI_LOG_I(
"SubGhzOnStart",
"Add allowed band: start %luHz, stop %luHz, power_limit %ddBm, duty_cycle %u%%",
band.start,
band.end,
band.power_limit,
band.duty_cycle);
return true;
}

void subghz_on_system_start(void) {
#ifdef SRV_CLI
Cli* cli = furi_record_open(RECORD_CLI);
Expand All @@ -1250,54 +1204,4 @@ void subghz_on_system_start(void) {
#else
UNUSED(subghz_cli_command);
#endif

#ifdef SRV_STORAGE
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
FileInfo fileinfo = {0};
PB_Region pb_region = {0};
pb_region.bands.funcs.decode = subghz_on_system_start_istream_decode_band;

do {
if(storage_common_stat(storage, SUBGHZ_REGION_FILENAME, &fileinfo) != FSE_OK ||
fileinfo.size == 0) {
FURI_LOG_W("SubGhzOnStart", "Region data is missing or empty");
break;
}

if(!storage_file_open(file, SUBGHZ_REGION_FILENAME, FSAM_READ, FSOM_OPEN_EXISTING)) {
FURI_LOG_E("SubGhzOnStart", "Unable to open region data");
break;
}

pb_istream_t istream = {
.callback = subghz_on_system_start_istream_read,
.state = file,
.errmsg = NULL,
.bytes_left = fileinfo.size,
};

pb_region.bands.arg = malloc(sizeof(FuriHalRegion));
if(!pb_decode(&istream, PB_Region_fields, &pb_region)) {
FURI_LOG_E("SubGhzOnStart", "Invalid region data");
free(pb_region.bands.arg);
break;
}

FuriHalRegion* region = pb_region.bands.arg;
memcpy(
region->country_code,
pb_region.country_code->bytes,
pb_region.country_code->size < 4 ? pb_region.country_code->size : 3);
furi_hal_region_set(region);
} while(0);

pb_release(PB_Region_fields, &pb_region);
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
#else
UNUSED(subghz_cli_command);
UNUSED(subghz_on_system_start_istream_decode_band);
UNUSED(subghz_on_system_start_istream_read);
#endif
}
7 changes: 5 additions & 2 deletions applications/main/u2f/u2f.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_random.h>
#include <littlefs/lfs_util.h> // for lfs_tobe32

#include <mbedtls/sha256.h>
#include <mbedtls/md.h>
Expand Down Expand Up @@ -319,6 +318,10 @@ static uint16_t u2f_register(U2fData* U2F, uint8_t* buf) {
return sizeof(U2fRegisterResp) + cert_len + signature_len + 2;
}

static inline uint32_t u2f_to_big_endian(uint32_t a) {
return __builtin_bswap32(a);
}

static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) {
U2fAuthReq* req = (U2fAuthReq*)buf;
U2fAuthResp* resp = (U2fAuthResp*)buf;
Expand Down Expand Up @@ -348,7 +351,7 @@ static uint16_t u2f_authenticate(U2fData* U2F, uint8_t* buf) {
U2F->user_present = false;

// The 4 byte counter is represented in big endian. Increment it before use
be_u2f_counter = lfs_tobe32(U2F->counter + 1);
be_u2f_counter = u2f_to_big_endian(U2F->counter + 1);

// Generate hash
{
Expand Down
Loading

0 comments on commit 4d985ba

Please sign in to comment.