pkg/spiffs: add multi-partitions support#8273
Conversation
jnohlgard
left a comment
There was a problem hiding this comment.
I like the general idea, but I did not do any testing.
Is it possible to test this in a good way with the unit tests? I think at least on native with the MTD emulation it would be good to be able to verify this functionality somehow.
sys/include/fs/spiffs_fs.h
Outdated
| #endif | ||
| #if (SPIFFS_SINGLETON == 0) || defined(DOXYGEN) | ||
| uint32_t base_addr; /**< Base address of partition */ | ||
| uint32_t part_block_count; /**< Number of blocks in current partition, |
There was a problem hiding this comment.
would not block_count be sufficient as the name?
|
comments addressed. I added a unit test to check nothing is written outside the partition. |
|
ping @gebart |
|
ping |
| fs_desc->config.log_block_size = dev->page_size * dev->pages_per_sector; | ||
| fs_desc->config.log_page_size = dev->page_size; | ||
| fs_desc->config.phys_addr = 0; | ||
| fs_desc->config.phys_addr = fs_desc->base_addr; |
There was a problem hiding this comment.
please add an assert that checks that the partition does not begin or end outside of the physical device limits.
There was a problem hiding this comment.
added 2 assert to check:
base_addr + sector_countis inside memory boundariesbase_addris aligned on a sector
jnohlgard
left a comment
There was a problem hiding this comment.
Please add a safeguard assert and fix the minor typo. Looks good, tests pass on native but fail on mulle:
spiffs_tests.tests_spiffs_partition (tests/unittests/tests-spiffs/tests-spiffs.c 379) buf[0] != 0xff
|
|
||
| #if SPIFFS_USE_MAGIC | ||
| /* if SPIFFS_USE_MAGIC is used, a magic word is written at the end of the | ||
| * firt page of each sector */ |
|
not sure why the tests fail on mulle though. |
e2bd0d0 to
2e799e9
Compare
might be fixed by #8400. Since I rebased, could you give another try? |
|
Retried with the latest PR branch, a new error: Edit: -19 is -ENODEV |
|
Ah there is a missing vfs_format in the test |
Yep, it has been introduced in between ;) This should be fixed! |
|
I added the vfs_format and ran a test, new error: |
|
Can't reproduce on native nor on our hardware (with spi flash). On which board do you have this issue? |
|
OK, I reproduced by changing the layout of my flash. |
|
The errors were on mulle with the default config. I don't know if there may be a configuration issue with the mtd or spiffs? |
|
@gebart could you check again with the last commit? I changed the test, because my guess with the magic word was wrong. It seems it depends on the config. I now read the whole sector to check if it has been written or not. |
|
Will test again tonight or tomorrow morning |
jnohlgard
left a comment
There was a problem hiding this comment.
Tests pass on Mulle now, but see inline comment about memcmp
| res = 0; | ||
| for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) { | ||
| mtd_read(_dev, buf, (2 * _dev->page_size * _dev->pages_per_sector) + i, sizeof(buf)); | ||
| res += memcmp(buf, buf_erased, sizeof(buf)); |
There was a problem hiding this comment.
|= is more robust here since memcmp may return anything non-zero value, both positive and negative, so the sum may end up being 0 with some bad luck
| TEST_ASSERT(res != 0); | ||
| res = 0; | ||
| for (size_t i = 0; i < _dev->page_size * _dev->pages_per_sector; i += sizeof(buf)) { | ||
| mtd_read(_dev, buf, (2 * _dev->page_size * _dev->pages_per_sector) + i, sizeof(buf)); |
There was a problem hiding this comment.
we need to either check the return value, or memset buf to zero between each mtd_read to avoid hiding errors
There was a problem hiding this comment.
return value check added
| /* if SPIFFS_USE_MAGIC is used, a magic word is written in each sector */ | ||
| uint8_t buf[4]; | ||
| const uint8_t buf_erased[4] = {0xff, 0xff, 0xff, 0xff}; | ||
| int read; |
There was a problem hiding this comment.
Change the name to nread to avoid name collision with the posix read function
jnohlgard
left a comment
There was a problem hiding this comment.
Tests succeed on native and on Mulle.
Please squash
Two new fileds added in spiffs descriptor: - base_addr: base address of the partition - part_block_count: number of sectors in the partition If part_block_count is 0, the whole underlying MTD is used
d9076a4 to
647133f
Compare
|
Squashed |
|
All green, go! |
Contribution description
Add the possibility of using multiple partitions (i.e. not use the whole memory for a spiffs partition).
Two new fileds added in spiffs descriptor:
If part_block_count is 0, the whole underlying MTD is used
Issues/PRs references
None