Skip to content

Commit bb48dd3

Browse files
authored
Merge pull request #11624 from geky/littlefs-v1.7.2
LittleFS: Update to v1.7.2
2 parents 4876172 + de8df75 commit bb48dd3

File tree

11 files changed

+406
-220
lines changed

11 files changed

+406
-220
lines changed

features/storage/filesystem/littlefs/littlefs/.travis.yml

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ script:
3535
if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
3636
then
3737
CURR=$(tail -n1 sizes | awk '{print $1}')
38-
PREV=$(curl -u $GEKY_BOT_STATUSES https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
38+
PREV=$(curl -u "$GEKY_BOT_STATUSES" https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
3939
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
4040
| .statuses[] | select(.context == \"$STAGE/$NAME\").description
4141
| capture(\"code size is (?<size>[0-9]+)\").size" \
@@ -100,6 +100,7 @@ jobs:
100100
env:
101101
- STAGE=test
102102
- NAME=littlefs-fuse
103+
if: branch !~ -prefix$
103104
install:
104105
- sudo apt-get install libfuse-dev
105106
- git clone --depth 1 https://github.com/geky/littlefs-fuse
@@ -128,56 +129,88 @@ jobs:
128129
- ls
129130
- make -B test_dirs test_files QUIET=1
130131

131-
# Automatically update releases
132+
# Automatically create releases
132133
- stage: deploy
133134
env:
134135
- STAGE=deploy
135136
- NAME=deploy
136137
script:
137-
# Find version defined in lfs.h
138-
- LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
139-
- LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
140-
- LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
141-
# Grab latests patch from repo tags, default to 0
142-
- LFS_VERSION_PATCH=$(curl -f -u "$GEKY_BOT_RELEASES"
143-
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs
144-
| jq 'map(.ref | match(
145-
"refs/tags/v'"$LFS_VERSION_MAJOR"'\\.'"$LFS_VERSION_MINOR"'\\.(.*)$")
146-
.captures[].string | tonumber + 1) | max // 0')
147-
# We have our new version
148-
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
149-
- echo "VERSION $LFS_VERSION"
150138
- |
139+
bash << 'SCRIPT'
140+
set -ev
141+
# Find version defined in lfs.h
142+
LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
143+
LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
144+
LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
145+
# Grab latests patch from repo tags, default to 0, needs finagling
146+
# to get past github's pagination api
147+
PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
148+
PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I \
149+
| sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1' \
150+
|| echo $PREV_URL)
151+
LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" \
152+
| jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
153+
.captures[].string | tonumber) | max + 1' \
154+
|| echo 0)
155+
# We have our new version
156+
LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
157+
echo "VERSION $LFS_VERSION"
151158
# Check that we're the most recent commit
152159
CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
153-
https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
154-
| jq -re '.sha')
155-
if [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ]
160+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
161+
| jq -re '.sha')
162+
[ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ] || exit 0
163+
# Create major branch
164+
git branch v$LFS_VERSION_MAJOR HEAD
165+
# Create major prefix branch
166+
git config user.name "geky bot"
167+
git config user.email "[email protected]"
168+
git fetch https://github.com/$TRAVIS_REPO_SLUG.git \
169+
--depth=50 v$LFS_VERSION_MAJOR-prefix || true
170+
./scripts/prefix.py lfs$LFS_VERSION_MAJOR
171+
git branch v$LFS_VERSION_MAJOR-prefix $( \
172+
git commit-tree $(git write-tree) \
173+
$(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
174+
-p HEAD \
175+
-m "Generated v$LFS_VERSION_MAJOR prefixes")
176+
git reset --hard
177+
# Update major version branches (vN and vN-prefix)
178+
git push https://[email protected]/$TRAVIS_REPO_SLUG.git \
179+
v$LFS_VERSION_MAJOR \
180+
v$LFS_VERSION_MAJOR-prefix
181+
# Create patch version tag (vN.N.N)
182+
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
183+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
184+
-d "{
185+
\"ref\": \"refs/tags/$LFS_VERSION\",
186+
\"sha\": \"$TRAVIS_COMMIT\"
187+
}"
188+
# Create minor release?
189+
[[ "$LFS_VERSION" == *.0 ]] || exit 0
190+
# Build release notes
191+
PREV=$(git tag --sort=-v:refname -l "v*.0" | head -1)
192+
if [ ! -z "$PREV" ]
156193
then
157-
# Build release notes
158-
PREV=$(git tag --sort=-v:refname -l "v*" | head -1)
159-
if [ ! -z "$PREV" ]
160-
then
161-
echo "PREV $PREV"
162-
CHANGES=$'### Changes\n\n'$( \
163-
git log --oneline $PREV.. --grep='^Merge' --invert-grep)
164-
printf "CHANGES\n%s\n\n" "$CHANGES"
165-
fi
166-
# Create the release
167-
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
168-
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
169-
-d "{
170-
\"tag_name\": \"$LFS_VERSION\",
171-
\"target_commitish\": \"$TRAVIS_COMMIT\",
172-
\"name\": \"${LFS_VERSION%.0}\",
173-
\"body\": $(jq -sR '.' <<< "$CHANGES")
174-
}"
194+
echo "PREV $PREV"
195+
CHANGES=$'### Changes\n\n'$( \
196+
git log --oneline $PREV.. --grep='^Merge' --invert-grep)
197+
printf "CHANGES\n%s\n\n" "$CHANGES"
175198
fi
199+
# Create the release
200+
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
201+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
202+
-d "{
203+
\"tag_name\": \"$LFS_VERSION\",
204+
\"name\": \"${LFS_VERSION%.0}\",
205+
\"draft\": true,
206+
\"body\": $(jq -sR '.' <<< "$CHANGES")
207+
}" #"
208+
SCRIPT
176209
177210
# Manage statuses
178211
before_install:
179212
- |
180-
curl -u $GEKY_BOT_STATUSES -X POST \
213+
curl -u "$GEKY_BOT_STATUSES" -X POST \
181214
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
182215
-d "{
183216
\"context\": \"$STAGE/$NAME\",
@@ -188,7 +221,7 @@ before_install:
188221
189222
after_failure:
190223
- |
191-
curl -u $GEKY_BOT_STATUSES -X POST \
224+
curl -u "$GEKY_BOT_STATUSES" -X POST \
192225
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
193226
-d "{
194227
\"context\": \"$STAGE/$NAME\",
@@ -199,7 +232,7 @@ after_failure:
199232
200233
after_success:
201234
- |
202-
curl -u $GEKY_BOT_STATUSES -X POST \
235+
curl -u "$GEKY_BOT_STATUSES" -X POST \
203236
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
204237
-d "{
205238
\"context\": \"$STAGE/$NAME\",

features/storage/filesystem/littlefs/littlefs/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ ifdef WORD
2525
override CFLAGS += -m$(WORD)
2626
endif
2727
override CFLAGS += -I.
28-
override CFLAGS += -std=c99 -Wall -pedantic -Wshadow -Wunused-parameter
28+
override CFLAGS += -std=c99 -Wall -pedantic
29+
override CFLAGS += -Wshadow -Wunused-parameter -Wjump-misses-init -Wsign-compare
2930

3031

3132
all: $(TARGET)

features/storage/filesystem/littlefs/littlefs/README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ filesystem until sync or close is called on the file.
111111
112112
## Other notes
113113
114-
All littlefs have the potential to return a negative error code. The errors
115-
can be either one of those found in the `enum lfs_error` in [lfs.h](lfs.h),
116-
or an error returned by the user's block device operations.
114+
All littlefs calls have the potential to return a negative error code. The
115+
errors can be either one of those found in the `enum lfs_error` in
116+
[lfs.h](lfs.h), or an error returned by the user's block device operations.
117117
118118
In the configuration struct, the `prog` and `erase` function provided by the
119119
user may return a `LFS_ERR_CORRUPT` error if the implementation already can
@@ -175,3 +175,18 @@ handy.
175175
[littlefs-js](https://github.com/geky/littlefs-js) - A JavaScript wrapper for
176176
littlefs. I'm not sure why you would want this, but it is handy for demos.
177177
You can see it in action [here](http://littlefs.geky.net/demo.html).
178+
179+
[mklfs](https://github.com/whitecatboard/Lua-RTOS-ESP32/tree/master/components/mklfs/src) -
180+
A command line tool built by the [Lua RTOS](https://github.com/whitecatboard/Lua-RTOS-ESP32)
181+
guys for making littlefs images from a host PC. Supports Windows, Mac OS,
182+
and Linux.
183+
184+
[SPIFFS](https://github.com/pellepl/spiffs) - Another excellent embedded
185+
filesystem for NOR flash. As a more traditional logging filesystem with full
186+
static wear-leveling, SPIFFS will likely outperform littlefs on small
187+
memories such as the internal flash on microcontrollers.
188+
189+
[Dhara](https://github.com/dlbeer/dhara) - An interesting NAND flash
190+
translation layer designed for small MCUs. It offers static wear-leveling and
191+
power-resilience with only a fixed O(|address|) pointer structure stored on
192+
each block and in RAM.

features/storage/filesystem/littlefs/littlefs/emubd/lfs_emubd.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) {
4747

4848
// Load stats to continue incrementing
4949
snprintf(emu->child, LFS_NAME_MAX, "stats");
50+
5051
FILE *f = fopen(emu->path, "r");
51-
if (!f) {
52+
if (!f && errno != ENOENT) {
5253
return -errno;
5354
}
5455

55-
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
56-
if (res < 1) {
57-
return -errno;
58-
}
56+
if (errno == ENOENT) {
57+
memset(&emu->stats, 0x0, sizeof(emu->stats));
58+
} else {
59+
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
60+
if (res < 1) {
61+
return -errno;
62+
}
5963

60-
err = fclose(f);
61-
if (err) {
62-
return -errno;
64+
err = fclose(f);
65+
if (err) {
66+
return -errno;
67+
}
6368
}
6469

6570
return 0;

0 commit comments

Comments
 (0)