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

pkg: add SPIFFS support #5625

Merged
merged 3 commits into from
Mar 31, 2017
Merged

pkg: add SPIFFS support #5625

merged 3 commits into from
Mar 31, 2017

Conversation

vincent-d
Copy link
Member

@vincent-d vincent-d commented Jul 12, 2016

This PR adds support for SPIFFS as a package based on @gebart recent VFS work.

This is still WIP and all functions are not implemented right now.
Some unit tests may be used to test it.

This is based on #5616 and uses #5624 for the low level.

@vincent-d vincent-d mentioned this pull request Jul 13, 2016
55 tasks
@jnohlgard jnohlgard added State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Jul 13, 2016
@jnohlgard jnohlgard added this to the Release 2016.10 milestone Jul 13, 2016
@jnohlgard
Copy link
Member

The patch for the const buffer in spiffs_write should be upstreamed, if possible. I don't see a reason for why a source buffer in a write situation should be writable.

@vincent-d
Copy link
Member Author

@gebart I agree, I'll open a PR on the upstream project, but I wanted to have something working.

@vincent-d
Copy link
Member Author

opendir/readdir/closedir support added. No support for mkdir/rmdir as SPIFFS does not support directory, but has a flat structure and I'm not 100% sure about the behavior of readdir.

Still TODO: find a better way to use spiffs_config.h. Some part of this file should be set in a common part instead of in the board.

@jnohlgard
Copy link
Member

Still TODO: find a better way to use spiffs_config.h. Some part of this file should be set in a common part instead of in the board.

How about since all defines in spiffs_config.h are already surrounded by #ifndef, we add #include "spiffs_board_config.h" to the top and let the board specifics come first, then fall back to the defaults?

@jnohlgard
Copy link
Member

just realized that the above idea will cause problems with missing files. We could just add #include "board.h" at the top instead

@jnohlgard
Copy link
Member

for reference: pellepl/spiffs#94

@vincent-d
Copy link
Member Author

Added rename support and rebased on top of #5616

@vincent-d vincent-d force-pushed the pr/spiffs branch 2 times, most recently from 2d53838 to 9535de5 Compare July 14, 2016 12:45
@vincent-d
Copy link
Member Author

OTAkeys#1 merged and rebased on top of #5616

vfs_dirent_t entry;
res = vfs_readdir(&dirp, &entry);
TEST_ASSERT(res == 1);
TEST_ASSERT_EQUAL_STRING("/test0.txt", &(entry.d_name[0]));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of these files may not be the same order as the order in which they were created. It is also possible that there are other files left over from previous runs or failed tests in the same run which interfere with this check. The test should only verify that all the created files are reported back by readdir, the order should be irrelevant.

@jnohlgard
Copy link
Member

There's a problem with the unit test: Running it after a failed run may have left files around in the SPIFFS file system, so there should be some clean up at the beginning of each test to ensure that no leftover files are interfering with the outcome.

@vincent-d vincent-d force-pushed the pr/spiffs branch 2 times, most recently from 66e0fe4 to 2a85197 Compare July 19, 2016 14:26
@vincent-d
Copy link
Member Author

Unit tests improved.
Rebased with last mtd commits.

@vincent-d
Copy link
Member Author

rebased on top of #5616

@vincent-d
Copy link
Member Author

Done, thanks @kaspar030

@vincent-d
Copy link
Member Author

Unittests seem OK now

@jnohlgard
Copy link
Member

The unit tests take ages to run on Mulle with a real SPI NOR flash memory. Will do some more investigation.

@jnohlgard
Copy link
Member

@vincent-d what's the run time length on your platform?
Mulle took several minutes to run the entire spiffs unit tests, most of it was spent in the write2 test.

@vincent-d
Copy link
Member Author

@gebart the write2 test was initially there to ensure erase works correctly, so we need to fill the whole memory before the first erase actually happen, that's why it takes ages... Maybe we should just remove that test

@jnohlgard
Copy link
Member

@vincent-d I think it makes sense as a test, but it slows down the execution of the unit tests too much. Maybe only enable it on native for now?

I think it would be great if we had a separate benchmark test for spiffs, to compare read/write speeds between commits and between platforms. The write2 test could be a part of that kind of application as well.

Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments on the unit tests.
The write2 test needs some comment describing what it does.

vfs_umount(&_test_spiffs_mount);
}

static void test_spiffs_mount_umount(void)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be renamed to match the other tests. tests_spiffs_mount_umount (pluralis "tests")


static void test_spiffs_teardown(void)
{
vfs_mount(&_test_spiffs_mount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of mounting and unmounting going on, what do you think about mounting in the setup phase, saving the result to a file-global (i.e. static global) variable and just checking the variable inside the mount_unmount test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unmount would need to be tested inside the mount_unmount test though

Copy link
Member Author

@vincent-d vincent-d Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could mount in the test_spiffs_setup, unmount in the test_spiffs_teardown and change the mount_unmount test to a unmount_mount. What do you think ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that would work I guess. I forgot, do we handle unmounting an already unmounted fs in VFS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess either the fs implementation or removing the mountpoint from the list will fail, but it will fail silently.

vfs_unlink("/test-spiffs/test0.txt");
vfs_unlink("/test-spiffs/test1.txt");
vfs_unlink("/test-spiffs/a/test2.txt");
vfs_umount(&_test_spiffs_mount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... and a flag variable to tell whether we need to unmount or not.

TEST_ASSERT(mp >= 0);

int res;
for (int j = 0; j < 5; j++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a comment explaining what we want to test.
I don't really see how the magic numbers in this test ensure that we fill the memory and need to erase sectors..

TEST_ASSERT_EQUAL_INT(sizeof(buf), res);
}

res = vfs_lseek(fd, 0, SEEK_SET);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line necessary?

@vincent-d
Copy link
Member Author

For the write2 test, I used the magic numbers with my memory. But I already reduced them to avoid the timeout on native, which does not really make sense, I agree.
I propose we just drop this test for now to not block that PR and we prepare a separate test app which could be used for benchmarking.

@vincent-d
Copy link
Member Author

Fix unittests

  • write2 removed
  • comments addressed

@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Mar 31, 2017
Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK, OK to squash

Vincent Dupont added 3 commits March 31, 2017 17:17
@vincent-d
Copy link
Member Author

Squashed

@vincent-d vincent-d added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: waiting for other PR State: The PR requires another PR to be merged first labels Mar 31, 2017
@jnohlgard
Copy link
Member

Did another test run on Mulle and native, both work fine.

@jnohlgard jnohlgard merged commit f4dd0a3 into RIOT-OS:master Mar 31, 2017
@jnohlgard
Copy link
Member

Murdock is fine, go!

@jnohlgard
Copy link
Member

Thanks, @vincent-d! Finally RIOT has a file system out of the box! 🎉

@vincent-d
Copy link
Member Author

Great! Thanks @gebart

@vincent-d vincent-d deleted the pr/spiffs branch April 3, 2017 08:03
@jnohlgard jnohlgard added the Area: fs Area: File systems label Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: fs Area: File systems CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants