Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate littlefs into mbed OS #5538

Merged
merged 58 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8fae391
Initial commit
geky Jul 12, 2017
c906259
Merge commit '98af79f087e8d95b28614e982a144a122f2dcbda' as 'littlefs'
geky Jul 12, 2017
98af79f
Squashed 'littlefs/' content from commit 663e953
geky Jul 12, 2017
c586879
Tweaked littlefs to fit into mbed
geky Jul 12, 2017
953e19e
Added README and LICENSE
geky Jul 12, 2017
64ff4b6
Added support for Travis CI
geky Jul 12, 2017
76d00eb
Squashed 'littlefs/' changes from 663e953..c2283a2
geky Jul 23, 2017
2e9f87d
Updated littlefs to '76d00eb38cddfcc267f323c470142b9f4588d3ff'
geky Jul 23, 2017
c9117d8
Increased default lookahead to 512 blocks
geky Jul 23, 2017
6e99fa9
Squashed 'littlefs/' changes from c2283a2..9843402
geky Sep 27, 2017
37edc35
Merge commit '6e99fa9319d17f0aef418ae3989befc04ecf9096' into new-update
geky Sep 27, 2017
b6455a3
Brought over additional testing configurations from littlefs
geky Sep 22, 2017
3a98733
Added user flag to pip install in travis
geky Sep 22, 2017
9408f2b
Converted tests into mbed-style integration tests
geky Sep 22, 2017
c390e89
Added self-hosting fuzz test using littlefs-fuse
geky Sep 27, 2017
301232e
Ported lfs_util functions to IAR intrinsics
geky Oct 10, 2017
3c3b032
Squashed 'littlefs/' changes from 9843402..454b588
geky Oct 13, 2017
383677f
Merge commit '3c3b0329d44d44a2d47a28c755658d7f1db6a085'
geky Oct 13, 2017
6fc33f4
Fixed incorrect instruction in IAR ctz implementation
geky Oct 16, 2017
11440f6
Removed toolchain specific warnings
geky Oct 17, 2017
adbd029
Added implementation of FileSystem::reformat
geky Oct 26, 2017
0171b57
Squashed 'littlefs/' changes from 454b588..2ab150c
geky Oct 30, 2017
26ade62
Merge commit '0171b57a04c3eb6444fdf1163e0e21993445bfd8'
geky Oct 30, 2017
5e4ef9f
Added simple high-level thread safety
geky Oct 31, 2017
72fab82
Added API level logging and logging configuration options
geky Oct 31, 2017
71b429b
Cleaned up compilation with logging enabled
geky Nov 10, 2017
785b0b4
Fixed issue with aggressively rounding down lookahead configuration
geky Nov 10, 2017
d3b2efe
Fixed corner case with immediate exhaustion and lookahead==block_count
geky Nov 10, 2017
3778759
Squashed 'littlefs/' changes from 2ab150c..3f31c8c
geky Nov 10, 2017
ee52d6d
Merge commit '3778759979a1c6bc141e9ced8c28df2a1d4a9848' into fix-look…
geky Nov 10, 2017
0f4e334
Squashed 'littlefs/' changes from 3f31c8c..78c79ec
geky Nov 17, 2017
9f8d0d6
Merge commit '0f4e334388e0e05554a78d14d0a5ef73f02209b2'
geky Nov 17, 2017
7eaf61c
Fixed memory leak when files/dirs error
geky Nov 16, 2017
bb155ad
Add filesystem recovery tests
c1728p9 Nov 17, 2017
2d374ce
Add unexpected reset test
c1728p9 Nov 17, 2017
3bdb80f
Merge pull request #9 from c1728p9/resilience_and_wear_leveling
geky Nov 17, 2017
5afec68
Renamed "parallel" tests to "intersperesed"
geky Nov 17, 2017
3c9f2be
Added test configuration support for block devices
geky Nov 18, 2017
9b79136
Merge commit '0a197465d33900a5ac2ef41486410d44f3d15ad3'
geky Nov 20, 2017
0a19746
Squashed 'littlefs/' changes from 78c79ec..996cd8a
geky Nov 20, 2017
8d336f2
Updated documentation to match other info around littlefs
geky Nov 20, 2017
b958997
Update unexpected reset host test for htrun
c1728p9 Nov 20, 2017
fa5e34e
Merge pull request #10 from c1728p9/htrun_update
geky Nov 22, 2017
3eb2f38
Squashed 'littlefs/' changes from 996cd8a..5ee20e8
geky Nov 22, 2017
ad07da0
Merge commit '3eb2f38279aadb35234c5df1fb8e54fd2a035be1'
geky Nov 22, 2017
9da2475
Cleaned up doxygen warnings
geky Nov 22, 2017
91a4f44
Enforced style consistency with mbed
geky Nov 22, 2017
d02b312
Removed warnings about format strings when running littlefs tests
geky Nov 22, 2017
314995f
Add 'features/filesystem/littlefs/' from commit 'd02b3122f006aa201bca…
geky Nov 22, 2017
9bc4ea6
littlefs: Removed mbed namespace leaks
geky Nov 22, 2017
4adf75c
littlefs: Moved test block devices into general block devices
geky Nov 22, 2017
ea0fee0
littlefs: Integrated littlefs's .travis.yml into mbed OS
geky Nov 22, 2017
2cf4715
littlefs: Increased test timeout to 4 minutes
geky Nov 22, 2017
b52575b
littlefs: Added checks for __CLZ instruction in IAR
geky Nov 27, 2017
47684d8
Added test config for simulated block devices
geky Nov 27, 2017
ff25681
Separated out logical Travis jobs
geky Nov 28, 2017
634fcf0
Copy edit littlefs
Nov 28, 2017
c613030
littlefs: Removed links to previous repository locations
geky Nov 30, 2017
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
199 changes: 159 additions & 40 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,163 @@
python:
- "2.7"
script:
- mkdir BUILD
# Assert that the Doxygen build produced no warnings.
# The strange command below asserts that the Doxygen command had an
# output of zero length
- |
doxygen doxyfile_options 2>&1 | tee BUILD/doxygen.out && [ ! -s BUILD/doxygen.out ]
# Assert that all binary libraries are named correctly
# The strange command below asserts that there are exactly 0 libraries that do
# not start with lib
- |
find "(" -name "*.a" -or -name "*.ar" ")" -and -not -name "lib*" | tee BUILD/badlibs | sed -e "s/^/Bad library name found: /" && [ ! -s BUILD/badlibs ]
# Assert that all assebler files are named correctly
# The strange command below asserts that there are exactly 0 libraries that do
# end with .s
- |
find -name "*.s" | tee BUILD/badasm | sed -e "s/^/Bad Assembler file name found: /" && [ ! -s BUILD/badasm ]
- make -C events/equeue test clean
- PYTHONPATH=. coverage run -a -m pytest tools/test
- python2 tools/test/pylint.py
- coverage run -a tools/project.py -S
- python2 tools/build_travis.py
- coverage html
after_success:
- coveralls

env:
global:
- >
STATUS=$'curl -so/dev/null --user $MBED_BOT --request POST
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT}
--data @- << DATA\n{
"state": "$0",
"description": "$1",
"context": "travis-ci/$NAME",
"target_url": "https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID"
}\nDATA'

before_install:
- bash -c "$STATUS" pending "Local $NAME testing is in progress"
# Make sure pipefail
- set -o pipefail
# Setup ppa to make sure arm-none-eabi-gcc is correct version
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
- sudo add-apt-repository -y ppa:libreoffice/libreoffice-4-2
- sudo apt-get update -qq
- sudo apt-get install -qq gcc-arm-embedded doxygen --force-yes
# Print versions we use
- arm-none-eabi-gcc --version
- python --version
- doxygen --version
install:
- pip install --user -r requirements.txt
- pip install --user pytest
- pip install --user pylint
- pip install --user hypothesis
- pip install --user mock
- pip install --user coverage
- pip install --user coveralls

after_success:
- bash -c "$STATUS" success "Local $NAME testing has passed"

after_failure:
- bash -c "$STATUS" failure "Local $NAME testing has failed"

matrix:
include:
- python: '2.7'
env:
- NAME=tools
install:
# Install dependencies
- sudo apt-get install gcc-arm-embedded doxygen
- pip install --user -r requirements.txt
- pip install --user pytest
- pip install --user pylint
- pip install --user hypothesis
- pip install --user mock
- pip install --user coverage
- pip install --user coveralls
# Print versions we use
- arm-none-eabi-gcc --version
- python --version
- doxygen --version
before_script:
# Create BUILD directory for tests
- mkdir BUILD
script:
# Assert that the Doxygen build produced no warnings.
# The strange command below asserts that the Doxygen command had an
# output of zero length
- |
doxygen doxyfile_options 2>&1 | tee BUILD/doxygen.out && [ ! -s BUILD/doxygen.out ]
# Assert that all binary libraries are named correctly
# The strange command below asserts that there are exactly 0 libraries that do
# not start with lib
- |
find "(" -name "*.a" -or -name "*.ar" ")" -and -not -name "lib*" | tee BUILD/badlibs | sed -e "s/^/Bad library name found: /" && [ ! -s BUILD/badlibs ]
# Assert that all assebler files are named correctly
# The strange command below asserts that there are exactly 0 libraries that do
# end with .s
- |
find -name "*.s" | tee BUILD/badasm | sed -e "s/^/Bad Assembler file name found: /" && [ ! -s BUILD/badasm ]
# Run local testing on tools
# Note: These take ~40 minutes to run
- PYTHONPATH=. coverage run -a -m pytest tools/test
- python2 tools/test/pylint.py
- coverage run -a tools/project.py -S | sed -n '/^Total/p'
# - python2 -u tools/build_travis.py | sed -n '/^Executing/p'
- coverage html
after_success:
# Coverage for tools
- coveralls
# Report success since we have overridden default behaviour
- bash -c "$STATUS" success "Local $NAME testing has passed"

- python: '2.7'
env:
- NAME=events
- EVENTS=events
install:
# Install dependencies
- sudo apt-get install gcc-arm-embedded
- pip install --user -r requirements.txt
# Print versions we use
- arm-none-eabi-gcc --version
- gcc --version
- python --version
script:
# Check that example compiles
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
# Run local equeue tests
- make -C $EVENTS/equeue test

- python: '2.7'
env:
- NAME=littlefs
- LITTLEFS=features/filesystem/littlefs
install:
# Install dependencies
- sudo apt-get install gcc-arm-embedded fuse libfuse-dev
- pip install --user -r requirements.txt
- git clone https://github.com/armmbed/spiflash-driver.git
# Print versions
- arm-none-eabi-gcc --version
- gcc --version
- python --version
- fusermount --version
before_script:
# Setup and patch littlefs-fuse
- git clone https://github.com/geky/littlefs-fuse littlefs_fuse
- echo '*' > littlefs_fuse/.mbedignore
- rm -rf littlefs_fuse/littlefs/*
- cp -r $(git ls-tree --name-only HEAD $LITTLEFS/littlefs/) littlefs_fuse/littlefs
# Create file-backed disk
- mkdir MOUNT
- sudo chmod a+rw /dev/loop0
- dd if=/dev/zero bs=512 count=2048 of=DISK
- losetup /dev/loop0 DISK
script:
# Check that example compiles
- sed -n '/``` c++/,/```/{/```/d;p;}' $LITTLEFS/README.md > main.cpp
- python tools/make.py -t GCC_ARM -m K82F --source=. --build=BUILD/K82F/GCC_ARM -j0
# Run local littlefs tests
- CFLAGS="-Wno-format" make -C$LITTLEFS/littlefs test QUIET=1
# Run local littlefs tests with set of variations
- CFLAGS="-Wno-format -DLFS_READ_SIZE=64 -DLFS_PROG_SIZE=64" make -C$LITTLEFS/littlefs test QUIET=1
- CFLAGS="-Wno-format -DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1" make -C$LITTLEFS/littlefs test QUIET=1
- CFLAGS="-Wno-format -DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512" make -C$LITTLEFS/littlefs test QUIET=1
- CFLAGS="-Wno-format -DLFS_BLOCK_COUNT=1023" make -C$LITTLEFS/littlefs test QUIET=1
- CFLAGS="-Wno-format -DLFS_LOOKAHEAD=2048" make -C$LITTLEFS/littlefs test QUIET=1
# Self-hosting littlefs fuzz test with littlefs-fuse
- make -Clittlefs_fuse
- littlefs_fuse/lfs --format /dev/loop0
- littlefs_fuse/lfs /dev/loop0 MOUNT
- ls MOUNT
- mkdir MOUNT/littlefs
- cp -r $(git ls-tree --name-only HEAD $LITTLEFS/littlefs/) MOUNT/littlefs
- ls MOUNT/littlefs
- CFLAGS="-Wno-format" make -CMOUNT/littlefs -B test_dirs QUIET=1

- python: '2.7'
env:
- NAME=mbed2
install:
# Install dependencies
- sudo apt-get install gcc-arm-embedded
- pip install --user -r requirements.txt
# Print versions we use
- arm-none-eabi-gcc --version
- python --version
before_script:
# Create BUILD directory for tests
- mkdir BUILD
script:
# Run local mbed 2 testing
# Note: These take ~40 minutes to run
- python2 -u tools/build_travis.py | sed -n '/^Executing/p'

108 changes: 108 additions & 0 deletions features/filesystem/bd/ExhaustibleBlockDevice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "ExhaustibleBlockDevice.h"
#include "mbed.h"


ExhaustibleBlockDevice::ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles)
: _bd(bd), _erase_array(NULL), _erase_cycles(erase_cycles)
{
}

ExhaustibleBlockDevice::~ExhaustibleBlockDevice()
{
delete[] _erase_array;
}

int ExhaustibleBlockDevice::init()
{
int err = _bd->init();
if (err) {
return err;
}

if (!_erase_array) {
// can only be allocated after initialization
_erase_array = new uint32_t[_bd->size() / _bd->get_erase_size()];
for (size_t i = 0; i < _bd->size() / _bd->get_erase_size(); i++) {
_erase_array[i] = _erase_cycles;
}
}

return 0;
}

int ExhaustibleBlockDevice::deinit()
{
// _erase_array is lazily cleaned up in destructor to allow
// data to live across de/reinitialization
return _bd->deinit();
}

int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
{
return _bd->read(buffer, addr, size);
}

int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_program(addr, size));

if (_erase_array[addr / get_erase_size()] == 0) {
// TODO possibly something more destructive here
return 0;
}

return _bd->program(buffer, addr, size);
}

int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_erase(addr, size));

// use an erase cycle
if (_erase_array[addr / get_erase_size()] > 0) {
_erase_array[addr / get_erase_size()] -= 1;
}

if (_erase_array[addr / get_erase_size()] == 0) {
// TODO possibly something more destructive here
return 0;
}

return _bd->erase(addr, size);
}

bd_size_t ExhaustibleBlockDevice::get_read_size() const
{
return _bd->get_read_size();
}

bd_size_t ExhaustibleBlockDevice::get_program_size() const
{
return _bd->get_program_size();
}

bd_size_t ExhaustibleBlockDevice::get_erase_size() const
{
return _bd->get_erase_size();
}

bd_size_t ExhaustibleBlockDevice::size() const
{
return _bd->size();
}
Loading