Skip to content

Commit

Permalink
finish littlefs support
Browse files Browse the repository at this point in the history
  • Loading branch information
idolpx committed Jul 5, 2023
1 parent 6f6ec91 commit e5413bb
Show file tree
Hide file tree
Showing 86 changed files with 27,509 additions and 37 deletions.
11 changes: 7 additions & 4 deletions build_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import subprocess
import sys

# Don't do anything if this is an 'uploadfs' or 'erase' target
if sys.argv[9] == 'buildfs' or sys.argv[9] == 'uploadfs' or sys.argv[9] == 'erase':
# Change build tool if we are using LittleFS
if any("FLASH_LITTLEFS" in x for x in env['BUILD_FLAGS']):
print("\033[1;31mReplaceing MKSPIFFSTOOL with mklittlefs\033[1;37m")
env.Replace (MKSPIFFSTOOL = "mklittlefs")

# Disable automatic versioning
if 1:
print("Automatic versioning disabled")

# Don't do anything if this is an 'uploadfs' or 'erase' target
elif sys.argv[9] == 'uploadfs' or sys.argv[9] == 'erase':
print("This isn't a build target")

# Don't do anything if nothing has changed
elif len(subprocess.check_output(["git", "diff", "--name-only"], universal_newlines=True)) == 0:
print("Nothing has changed")
Expand Down
34 changes: 34 additions & 0 deletions components/esp_littlefs/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[bumpversion]
current_version = 1.5.5
commit = True
tag = True

[bumpversion:file:README.md]
search = littlefs=={current_version}
replace = littlefs=={new_version}

[bumpversion:file:idf_component.yml]
search = "{current_version}"
replace = "{new_version}"

[bumpversion:file(number):include/esp_littlefs.h]
search = ESP_LITTLEFS_VERSION_NUMBER "{current_version}"
replace = ESP_LITTLEFS_VERSION_NUMBER "{new_version}"

[bumpversion:file(major):include/esp_littlefs.h]
parse = (?P<major>\d+)
serialize = {major}
search = ESP_LITTLEFS_VERSION_MAJOR {current_version}
replace = ESP_LITTLEFS_VERSION_MAJOR {new_version}

[bumpversion:file(minor):include/esp_littlefs.h]
parse = (?P<minor>\d+)
serialize = {minor}
search = ESP_LITTLEFS_VERSION_MINOR {current_version}
replace = ESP_LITTLEFS_VERSION_MINOR {new_version}

[bumpversion:file(patch):include/esp_littlefs.h]
parse = (?P<patch>\d+)
serialize = {patch}
search = ESP_LITTLEFS_VERSION_PATCH {current_version}
replace = ESP_LITTLEFS_VERSION_PATCH {new_version}
11 changes: 11 additions & 0 deletions components/esp_littlefs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
build/
sdkconfig
sdkconfig.old

example/build/
example/sdkconfig
example/sdkconfig.old
example/dependencies.lock

*.DS_Store
*/.cache
6 changes: 6 additions & 0 deletions components/esp_littlefs/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "main/littlefs"]
path = src/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "mklittlefs"]
path = mklittlefs
url = https://github.com/BrianPugh/mklittlefs.git
20 changes: 20 additions & 0 deletions components/esp_littlefs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.10)

file(GLOB SOURCES src/littlefs/*.c)
list(APPEND SOURCES src/esp_littlefs.c src/littlefs_api.c src/lfs_config.c)

if(IDF_VERSION_MAJOR GREATER_EQUAL 5)
list(APPEND pr esp_partition)
endif()

idf_component_register(
SRCS ${SOURCES}
INCLUDE_DIRS include
PRIV_INCLUDE_DIRS src
PRIV_REQUIRES ${pr} esptool_py spi_flash vfs
)

set_source_files_properties(
${SOURCES}
PROPERTIES COMPILE_FLAGS "-DLFS_CONFIG=lfs_config.h"
)
150 changes: 150 additions & 0 deletions components/esp_littlefs/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
menu "LittleFS"

config LITTLEFS_MAX_PARTITIONS
int "Maximum Number of Partitions"
default 3
range 1 10
help
Define maximum number of partitions that can be mounted.

config LITTLEFS_PAGE_SIZE
int "LITTLEFS logical page size"
default 256
range 256 1024
help
Logical page size of LITTLEFS partition, in bytes. Must be multiple
of flash page size (which is usually 256 bytes).
Larger page sizes reduce overhead when storing large files, and
improve filesystem performance when reading large files.
Smaller page sizes reduce overhead when storing small (< page size)
files.

config LITTLEFS_OBJ_NAME_LEN
int "Maximum object name length including NULL terminator."
default 64
range 16 1022
help
Includes NULL-terminator. If flashing a prebuilt filesystem image,
rebuild the filesystem image if this value changes.
mklittlefs, the tool that generates the image will automatically be rebuilt.
If downloading a pre-built release of mklittlefs, it was most-likely
built with LFS_NAME_MAX=32 and should not be used.

config LITTLEFS_READ_SIZE
int "Minimum size of a block read."
default 128
help
Minimum size of a block read. All read operations will be a
multiple of this value.

config LITTLEFS_WRITE_SIZE
int "Minimum size of a block write."
default 128
help
Minimum size of a block program. All write operations will be a
multiple of this value.

config LITTLEFS_LOOKAHEAD_SIZE
int "Look ahead size."
default 128
help
Look ahead size. Must be a multiple of 8.

config LITTLEFS_CACHE_SIZE
int "Cache Size"
default 512
help
Size of block caches. Each cache buffers a portion of a block in RAM.
The littlefs needs a read cache, a program cache, and one additional
cache per file. Larger caches can improve performance by storing more
data and reducing the number of disk accesses. Must be a multiple of
the read and program sizes, and a factor of the block size (4096).

config LITTLEFS_BLOCK_CYCLES
int "LittleFS wear-leveling block cycles"
default 512
range -1 1024
help
Number of erase cycles before littlefs evicts metadata logs and moves
the metadata to another block. Suggested values are in the
range 100-1000, with large values having better performance at the cost
of less consistent wear distribution.
Set to -1 to disable block-level wear-leveling.

config LITTLEFS_USE_MTIME
bool "Save file modification time"
default "y"
help
Saves timestamp on modification. Uses an additional 4bytes.

config LITTLEFS_USE_ONLY_HASH
bool "Don't store filepath in the file descriptor"
default "n"
help
Records the filepath only as a 32-bit hash in the file descriptor instead
of the entire filepath. Saves approximately `sizeof(filepath)` bytes
per file descriptor.
If enabled, functionality (like fstat) that requires the file path
from the file descriptor will not work.
In rare cases, may cause unlinking or renaming issues (unlikely) if
there's a hash collision between an open filepath and a filepath
to be modified.

config LITTLEFS_HUMAN_READABLE
bool "Make errno human-readable"
default "n"
help
Converts LittleFS error codes into human readable strings.
May increase binary size depending on logging level.

choice LITTLEFS_MTIME
prompt "mtime attribute options"
depends on LITTLEFS_USE_MTIME
default LITTLEFS_MTIME_USE_SECONDS
help
Save an additional 4-byte attribute. Options listed below.

config LITTLEFS_MTIME_USE_SECONDS
bool "Use Seconds"
help
Saves timestamp on modification.

config LITTLEFS_MTIME_USE_NONCE
bool "Use Nonce"
help
Saves nonce on modification; intended for detecting filechanges
on systems without access to a RTC.

A file who's nonce is the same as it was at a previous time has
high probability of not having been modified.

Upon file modification, the nonce is incremented by one. Upon file
creation, a random nonce is assigned.

There is a very slim chance that a file will have the same nonce if
it is deleted and created again (approx 1 in 4 billion).

endchoice

config LITTLEFS_SPIFFS_COMPAT
bool "Improve SPIFFS drop-in compatability"
default "n"
help
Enabling this feature allows for greater drop-in compatability
when replacing SPIFFS. Since SPIFFS doesn't have folders, and
folders are just considered as part of a file name, enabling this
will automatically create folders as necessary to create a file
instead of throwing an error. Similarly, upon the deletion of the
last file in a folder, the folder will be deleted. It is recommended
to only enable this flag as a stop-gap solution.

config LITTLEFS_FLUSH_FILE_EVERY_WRITE
bool "Flush file to flash after each write operation"
default "n"
help
Enabling this feature extends SPIFFS capability.
In SPIFFS data is written immediately to the flash storage when fflush() function called.
In LittleFS flush() does not write data to the flash, and fsync() call needed after.
With this feature fflush() will write data to the storage.

endmenu
7 changes: 7 additions & 0 deletions components/esp_littlefs/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2020 Brian Pugh

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions components/esp_littlefs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
PROJECT_NAME := littlefs

EXTRA_COMPONENT_DIRS := \
$(abspath .) \
$(abspath unit_tester) \
$(IDF_PATH)/tools/unit-test-app/components/

CFLAGS += \
-Werror

include $(IDF_PATH)/make/project.mk

.PHONY: tests

tests-build:
$(MAKE) \
TEST_COMPONENTS='src'

tests:
$(MAKE) \
TEST_COMPONENTS='src' \
flash monitor;

tests-enc:
$(MAKE) \
TEST_COMPONENTS='src' \
encrypted-flash monitor;

0 comments on commit e5413bb

Please sign in to comment.