Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ target_compile_options(lvgl PRIVATE
)

# LITTLEFS_SRC
add_definitions(-DLFS_THREADSAFE)
add_definitions(-DLFS_NAME_MAX=50)
add_library(littlefs STATIC ${LITTLEFS_SRC})
target_include_directories(littlefs SYSTEM PUBLIC . ../)
target_include_directories(littlefs SYSTEM PUBLIC ${INCLUDES_FROM_LIBS})
Expand Down
17 changes: 16 additions & 1 deletion src/components/fs/FS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ FS::FS(Pinetime::Drivers::SpiNorFlash& driver)
.prog = SectorProg,
.erase = SectorErase,
.sync = SectorSync,
.lock = LockFilesystem,
.unlock = UnlockFilesystem,

.read_size = 16,
.prog_size = 8,
Expand All @@ -23,8 +25,9 @@ FS::FS(Pinetime::Drivers::SpiNorFlash& driver)
.cache_size = 16,
.lookahead_size = 16,

.name_max = 50,
.name_max = LFS_NAME_MAX, // Note: LFS_NAME_MAX is defined in src/CMakeLists.txt
.attr_max = 50,
.metadata_max = 256,
} {
}

Expand All @@ -42,6 +45,8 @@ void FS::Init() {
return;
}
}
// Clean filesystem on boot
lfs_fs_gc(&lfs);

#ifndef PINETIME_IS_RECOVERY
VerifyResource();
Expand Down Expand Up @@ -109,6 +114,16 @@ lfs_ssize_t FS::GetFSSize() {
return lfs_fs_size(&lfs);
}

int FS::LockFilesystem(const struct lfs_config* c) {
Pinetime::Controllers::FS& lfs = *(static_cast<Pinetime::Controllers::FS*>(c->context));
return xSemaphoreTake(lfs.fsMutex, portMAX_DELAY) == pdTRUE ? 0 : -1;
}

int FS::UnlockFilesystem(const struct lfs_config* c) {
Pinetime::Controllers::FS& lfs = *(static_cast<Pinetime::Controllers::FS*>(c->context));
return xSemaphoreGive(lfs.fsMutex) == pdTRUE ? 0 : -1;
}

/*

----------- Interface between littlefs and SpiNorFlash -----------
Expand Down
5 changes: 5 additions & 0 deletions src/components/fs/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <cstdint>
#include "drivers/SpiNorFlash.h"
#include <littlefs/lfs.h>
#include <FreeRTOS.h>
#include <semphr.h>

namespace Pinetime {
namespace Controllers {
Expand Down Expand Up @@ -71,12 +73,15 @@ namespace Pinetime {
bool resourcesValid = false;
const struct lfs_config lfsConfig;

SemaphoreHandle_t fsMutex = xSemaphoreCreateMutex();
lfs_t lfs;

static int SectorSync(const struct lfs_config* c);
static int SectorErase(const struct lfs_config* c, lfs_block_t block);
static int SectorProg(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, const void* buffer, lfs_size_t size);
static int SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, void* buffer, lfs_size_t size);
static int LockFilesystem(const struct lfs_config* c);
static int UnlockFilesystem(const struct lfs_config* c);
};
}
}
70 changes: 54 additions & 16 deletions src/displayapp/LittleVgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,79 @@ namespace {
lv_theme_set_act(theme);
}

constexpr lv_fs_res_t MapError(int err) {
switch (err) {
case LFS_ERR_OK:
return LV_FS_RES_OK;
case LFS_ERR_IO:
return LV_FS_RES_HW_ERR;
case LFS_ERR_CORRUPT:
return LV_FS_RES_FS_ERR;
case LFS_ERR_NOENT:
return LV_FS_RES_NOT_EX;
case LFS_ERR_EXIST:
return LV_FS_RES_FS_ERR;
case LFS_ERR_NOTDIR:
return LV_FS_RES_FS_ERR;
case LFS_ERR_ISDIR:
return LV_FS_RES_FS_ERR;
case LFS_ERR_NOTEMPTY:
return LV_FS_RES_FS_ERR;
case LFS_ERR_BADF:
return LV_FS_RES_INV_PARAM;
case LFS_ERR_FBIG:
return LV_FS_RES_FULL;
case LFS_ERR_INVAL:
return LV_FS_RES_INV_PARAM;
case LFS_ERR_NOSPC:
return LV_FS_RES_FULL;
case LFS_ERR_NOMEM:
return LV_FS_RES_OUT_OF_MEM;
case LFS_ERR_NOATTR:
return LV_FS_RES_UNKNOWN;
case LFS_ERR_NAMETOOLONG:
return LV_FS_RES_INV_PARAM;
default:
return LV_FS_RES_UNKNOWN;
}
}

lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t /*mode*/) {
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
if (res == 0) {
if (file->type == 0) {
return LV_FS_RES_FS_ERR;
} else {
return LV_FS_RES_OK;
}
}
return LV_FS_RES_NOT_EX;
return MapError(res);
}

lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
filesys->FileClose(file);

return LV_FS_RES_OK;
int res = filesys->FileClose(file);
return MapError(res);
}

lv_fs_res_t lvglRead(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) {
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
*br = btr;
return LV_FS_RES_OK;
int res = filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
if (res >= 0) {
// br (bytes read) is allowed to be null
if (br != nullptr) {
*br = res;
}
return LV_FS_RES_OK;
}
return MapError(res);
}

lv_fs_res_t lvglSeek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) {
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
filesys->FileSeek(file, pos);
return LV_FS_RES_OK;
int res = filesys->FileSeek(file, pos);
if (res >= 0) {
return LV_FS_RES_OK;
}
return MapError(res);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/littlefs
Submodule littlefs updated 72 files
+4 −0 .gitattributes
+8 −3 .github/workflows/post-release.yml
+146 −98 .github/workflows/release.yml
+55 −8 .github/workflows/status.yml
+693 −232 .github/workflows/test.yml
+27 −5 .gitignore
+2 −2 DESIGN.md
+1 −0 LICENSE.md
+536 −56 Makefile
+84 −5 README.md
+101 −21 SPEC.md
+739 −0 bd/lfs_emubd.c
+244 −0 bd/lfs_emubd.h
+46 −84 bd/lfs_filebd.c
+17 −8 bd/lfs_filebd.h
+33 −55 bd/lfs_rambd.c
+17 −7 bd/lfs_rambd.h
+0 −302 bd/lfs_testbd.c
+0 −141 bd/lfs_testbd.h
+270 −0 benches/bench_dir.toml
+95 −0 benches/bench_file.toml
+56 −0 benches/bench_superblock.toml
+1,935 −819 lfs.c
+151 −45 lfs.h
+4 −0 lfs_util.c
+48 −19 lfs_util.h
+2,063 −0 runners/bench_runner.c
+146 −0 runners/bench_runner.h
+2,818 −0 runners/test_runner.c
+142 −0 runners/test_runner.h
+1,433 −0 scripts/bench.py
+181 −0 scripts/changeprefix.py
+661 −168 scripts/code.py
+828 −0 scripts/cov.py
+0 −254 scripts/coverage.py
+704 −0 scripts/data.py
+0 −383 scripts/explode_asserts.py
+1,344 −0 scripts/perf.py
+1,276 −0 scripts/perfbd.py
+1,592 −0 scripts/plot.py
+1,262 −0 scripts/plotmpl.py
+0 −61 scripts/prefix.py
+478 −0 scripts/prettyasserts.py
+47 −15 scripts/readmdir.py
+735 −0 scripts/stack.py
+652 −0 scripts/structs.py
+829 −0 scripts/summary.py
+177 −0 scripts/tailpipe.py
+73 −0 scripts/teepipe.py
+1,427 −797 scripts/test.py
+1,002 −0 scripts/tracebd.py
+265 −0 scripts/watch.py
+234 −115 tests/test_alloc.toml
+31 −19 tests/test_attrs.toml
+95 −76 tests/test_badblocks.toml
+248 −0 tests/test_bd.toml
+1,453 −0 tests/test_compat.toml
+377 −95 tests/test_dirs.toml
+59 −28 tests/test_entries.toml
+67 −49 tests/test_evil.toml
+157 −117 tests/test_exhaustion.toml
+172 −119 tests/test_files.toml
+53 −23 tests/test_interspersed.toml
+278 −188 tests/test_move.toml
+248 −28 tests/test_orphans.toml
+7,323 −218 tests/test_paths.toml
+185 −0 tests/test_powerloss.toml
+274 −68 tests/test_relocations.toml
+318 −36 tests/test_seek.toml
+109 −0 tests/test_shrink.toml
+564 −31 tests/test_superblocks.toml
+148 −84 tests/test_truncate.toml
Loading