Skip to content

Commit 2e1c2a1

Browse files
authored
Merge pull request ARMmbed#5538 from geky/littlefs-staging
Integrate littlefs into mbed OS
2 parents 41591eb + c613030 commit 2e1c2a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+15359
-41
lines changed

.travis.yml

+159-40
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,163 @@
1-
python:
2-
- "2.7"
3-
script:
4-
- mkdir BUILD
5-
# Assert that the Doxygen build produced no warnings.
6-
# The strange command below asserts that the Doxygen command had an
7-
# output of zero length
8-
- |
9-
doxygen doxyfile_options 2>&1 | tee BUILD/doxygen.out && [ ! -s BUILD/doxygen.out ]
10-
# Assert that all binary libraries are named correctly
11-
# The strange command below asserts that there are exactly 0 libraries that do
12-
# not start with lib
13-
- |
14-
find "(" -name "*.a" -or -name "*.ar" ")" -and -not -name "lib*" | tee BUILD/badlibs | sed -e "s/^/Bad library name found: /" && [ ! -s BUILD/badlibs ]
15-
# Assert that all assebler files are named correctly
16-
# The strange command below asserts that there are exactly 0 libraries that do
17-
# end with .s
18-
- |
19-
find -name "*.s" | tee BUILD/badasm | sed -e "s/^/Bad Assembler file name found: /" && [ ! -s BUILD/badasm ]
20-
- make -C events/equeue test clean
21-
- PYTHONPATH=. coverage run -a -m pytest tools/test
22-
- python2 tools/test/pylint.py
23-
- coverage run -a tools/project.py -S
24-
- python2 tools/build_travis.py
25-
- coverage html
26-
after_success:
27-
- coveralls
1+
2+
env:
3+
global:
4+
- >
5+
STATUS=$'curl -so/dev/null --user $MBED_BOT --request POST
6+
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT}
7+
--data @- << DATA\n{
8+
"state": "$0",
9+
"description": "$1",
10+
"context": "travis-ci/$NAME",
11+
"target_url": "https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID"
12+
}\nDATA'
13+
2814
before_install:
15+
- bash -c "$STATUS" pending "Local $NAME testing is in progress"
16+
# Make sure pipefail
17+
- set -o pipefail
18+
# Setup ppa to make sure arm-none-eabi-gcc is correct version
2919
- sudo add-apt-repository -y ppa:team-gcc-arm-embedded/ppa
3020
- sudo add-apt-repository -y ppa:libreoffice/libreoffice-4-2
3121
- sudo apt-get update -qq
32-
- sudo apt-get install -qq gcc-arm-embedded doxygen --force-yes
33-
# Print versions we use
34-
- arm-none-eabi-gcc --version
35-
- python --version
36-
- doxygen --version
37-
install:
38-
- pip install --user -r requirements.txt
39-
- pip install --user pytest
40-
- pip install --user pylint
41-
- pip install --user hypothesis
42-
- pip install --user mock
43-
- pip install --user coverage
44-
- pip install --user coveralls
22+
23+
after_success:
24+
- bash -c "$STATUS" success "Local $NAME testing has passed"
25+
26+
after_failure:
27+
- bash -c "$STATUS" failure "Local $NAME testing has failed"
28+
29+
matrix:
30+
include:
31+
- python: '2.7'
32+
env:
33+
- NAME=tools
34+
install:
35+
# Install dependencies
36+
- sudo apt-get install gcc-arm-embedded doxygen
37+
- pip install --user -r requirements.txt
38+
- pip install --user pytest
39+
- pip install --user pylint
40+
- pip install --user hypothesis
41+
- pip install --user mock
42+
- pip install --user coverage
43+
- pip install --user coveralls
44+
# Print versions we use
45+
- arm-none-eabi-gcc --version
46+
- python --version
47+
- doxygen --version
48+
before_script:
49+
# Create BUILD directory for tests
50+
- mkdir BUILD
51+
script:
52+
# Assert that the Doxygen build produced no warnings.
53+
# The strange command below asserts that the Doxygen command had an
54+
# output of zero length
55+
- |
56+
doxygen doxyfile_options 2>&1 | tee BUILD/doxygen.out && [ ! -s BUILD/doxygen.out ]
57+
# Assert that all binary libraries are named correctly
58+
# The strange command below asserts that there are exactly 0 libraries that do
59+
# not start with lib
60+
- |
61+
find "(" -name "*.a" -or -name "*.ar" ")" -and -not -name "lib*" | tee BUILD/badlibs | sed -e "s/^/Bad library name found: /" && [ ! -s BUILD/badlibs ]
62+
# Assert that all assebler files are named correctly
63+
# The strange command below asserts that there are exactly 0 libraries that do
64+
# end with .s
65+
- |
66+
find -name "*.s" | tee BUILD/badasm | sed -e "s/^/Bad Assembler file name found: /" && [ ! -s BUILD/badasm ]
67+
# Run local testing on tools
68+
# Note: These take ~40 minutes to run
69+
- PYTHONPATH=. coverage run -a -m pytest tools/test
70+
- python2 tools/test/pylint.py
71+
- coverage run -a tools/project.py -S | sed -n '/^Total/p'
72+
# - python2 -u tools/build_travis.py | sed -n '/^Executing/p'
73+
- coverage html
74+
after_success:
75+
# Coverage for tools
76+
- coveralls
77+
# Report success since we have overridden default behaviour
78+
- bash -c "$STATUS" success "Local $NAME testing has passed"
79+
80+
- python: '2.7'
81+
env:
82+
- NAME=events
83+
- EVENTS=events
84+
install:
85+
# Install dependencies
86+
- sudo apt-get install gcc-arm-embedded
87+
- pip install --user -r requirements.txt
88+
# Print versions we use
89+
- arm-none-eabi-gcc --version
90+
- gcc --version
91+
- python --version
92+
script:
93+
# Check that example compiles
94+
- sed -n '/``` cpp/,/```/{/```$/Q;/```/d;p;}' $EVENTS/README.md > main.cpp
95+
- python tools/make.py -t GCC_ARM -m K64F --source=. --build=BUILD/K64F/GCC_ARM -j0
96+
# Run local equeue tests
97+
- make -C $EVENTS/equeue test
98+
99+
- python: '2.7'
100+
env:
101+
- NAME=littlefs
102+
- LITTLEFS=features/filesystem/littlefs
103+
install:
104+
# Install dependencies
105+
- sudo apt-get install gcc-arm-embedded fuse libfuse-dev
106+
- pip install --user -r requirements.txt
107+
- git clone https://github.com/armmbed/spiflash-driver.git
108+
# Print versions
109+
- arm-none-eabi-gcc --version
110+
- gcc --version
111+
- python --version
112+
- fusermount --version
113+
before_script:
114+
# Setup and patch littlefs-fuse
115+
- git clone https://github.com/geky/littlefs-fuse littlefs_fuse
116+
- echo '*' > littlefs_fuse/.mbedignore
117+
- rm -rf littlefs_fuse/littlefs/*
118+
- cp -r $(git ls-tree --name-only HEAD $LITTLEFS/littlefs/) littlefs_fuse/littlefs
119+
# Create file-backed disk
120+
- mkdir MOUNT
121+
- sudo chmod a+rw /dev/loop0
122+
- dd if=/dev/zero bs=512 count=2048 of=DISK
123+
- losetup /dev/loop0 DISK
124+
script:
125+
# Check that example compiles
126+
- sed -n '/``` c++/,/```/{/```/d;p;}' $LITTLEFS/README.md > main.cpp
127+
- python tools/make.py -t GCC_ARM -m K82F --source=. --build=BUILD/K82F/GCC_ARM -j0
128+
# Run local littlefs tests
129+
- CFLAGS="-Wno-format" make -C$LITTLEFS/littlefs test QUIET=1
130+
# Run local littlefs tests with set of variations
131+
- CFLAGS="-Wno-format -DLFS_READ_SIZE=64 -DLFS_PROG_SIZE=64" make -C$LITTLEFS/littlefs test QUIET=1
132+
- CFLAGS="-Wno-format -DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1" make -C$LITTLEFS/littlefs test QUIET=1
133+
- CFLAGS="-Wno-format -DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512" make -C$LITTLEFS/littlefs test QUIET=1
134+
- CFLAGS="-Wno-format -DLFS_BLOCK_COUNT=1023" make -C$LITTLEFS/littlefs test QUIET=1
135+
- CFLAGS="-Wno-format -DLFS_LOOKAHEAD=2048" make -C$LITTLEFS/littlefs test QUIET=1
136+
# Self-hosting littlefs fuzz test with littlefs-fuse
137+
- make -Clittlefs_fuse
138+
- littlefs_fuse/lfs --format /dev/loop0
139+
- littlefs_fuse/lfs /dev/loop0 MOUNT
140+
- ls MOUNT
141+
- mkdir MOUNT/littlefs
142+
- cp -r $(git ls-tree --name-only HEAD $LITTLEFS/littlefs/) MOUNT/littlefs
143+
- ls MOUNT/littlefs
144+
- CFLAGS="-Wno-format" make -CMOUNT/littlefs -B test_dirs QUIET=1
145+
146+
- python: '2.7'
147+
env:
148+
- NAME=mbed2
149+
install:
150+
# Install dependencies
151+
- sudo apt-get install gcc-arm-embedded
152+
- pip install --user -r requirements.txt
153+
# Print versions we use
154+
- arm-none-eabi-gcc --version
155+
- python --version
156+
before_script:
157+
# Create BUILD directory for tests
158+
- mkdir BUILD
159+
script:
160+
# Run local mbed 2 testing
161+
# Note: These take ~40 minutes to run
162+
- python2 -u tools/build_travis.py | sed -n '/^Executing/p'
163+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "ExhaustibleBlockDevice.h"
18+
#include "mbed.h"
19+
20+
21+
ExhaustibleBlockDevice::ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles)
22+
: _bd(bd), _erase_array(NULL), _erase_cycles(erase_cycles)
23+
{
24+
}
25+
26+
ExhaustibleBlockDevice::~ExhaustibleBlockDevice()
27+
{
28+
delete[] _erase_array;
29+
}
30+
31+
int ExhaustibleBlockDevice::init()
32+
{
33+
int err = _bd->init();
34+
if (err) {
35+
return err;
36+
}
37+
38+
if (!_erase_array) {
39+
// can only be allocated after initialization
40+
_erase_array = new uint32_t[_bd->size() / _bd->get_erase_size()];
41+
for (size_t i = 0; i < _bd->size() / _bd->get_erase_size(); i++) {
42+
_erase_array[i] = _erase_cycles;
43+
}
44+
}
45+
46+
return 0;
47+
}
48+
49+
int ExhaustibleBlockDevice::deinit()
50+
{
51+
// _erase_array is lazily cleaned up in destructor to allow
52+
// data to live across de/reinitialization
53+
return _bd->deinit();
54+
}
55+
56+
int ExhaustibleBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
57+
{
58+
return _bd->read(buffer, addr, size);
59+
}
60+
61+
int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
62+
{
63+
MBED_ASSERT(is_valid_program(addr, size));
64+
65+
if (_erase_array[addr / get_erase_size()] == 0) {
66+
// TODO possibly something more destructive here
67+
return 0;
68+
}
69+
70+
return _bd->program(buffer, addr, size);
71+
}
72+
73+
int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
74+
{
75+
MBED_ASSERT(is_valid_erase(addr, size));
76+
77+
// use an erase cycle
78+
if (_erase_array[addr / get_erase_size()] > 0) {
79+
_erase_array[addr / get_erase_size()] -= 1;
80+
}
81+
82+
if (_erase_array[addr / get_erase_size()] == 0) {
83+
// TODO possibly something more destructive here
84+
return 0;
85+
}
86+
87+
return _bd->erase(addr, size);
88+
}
89+
90+
bd_size_t ExhaustibleBlockDevice::get_read_size() const
91+
{
92+
return _bd->get_read_size();
93+
}
94+
95+
bd_size_t ExhaustibleBlockDevice::get_program_size() const
96+
{
97+
return _bd->get_program_size();
98+
}
99+
100+
bd_size_t ExhaustibleBlockDevice::get_erase_size() const
101+
{
102+
return _bd->get_erase_size();
103+
}
104+
105+
bd_size_t ExhaustibleBlockDevice::size() const
106+
{
107+
return _bd->size();
108+
}

0 commit comments

Comments
 (0)