Skip to content

pkg/spiffs: add multi-partitions support#8273

Merged
vincent-d merged 2 commits intoRIOT-OS:masterfrom
OTAkeys:pr/spiffs-multi-partitions
Mar 2, 2018
Merged

pkg/spiffs: add multi-partitions support#8273
vincent-d merged 2 commits intoRIOT-OS:masterfrom
OTAkeys:pr/spiffs-multi-partitions

Conversation

@vincent-d
Copy link
Member

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:

  • 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

Issues/PRs references

None

@vincent-d vincent-d added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Dec 18, 2017
@vincent-d vincent-d requested a review from jnohlgard December 18, 2017 12:46
@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 Dec 18, 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.

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.

#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,
Copy link
Member

Choose a reason for hiding this comment

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

would not block_count be sufficient as the name?

Copy link
Member Author

Choose a reason for hiding this comment

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

renamed to block_count

@vincent-d
Copy link
Member Author

vincent-d commented Jan 4, 2018

comments addressed. I added a unit test to check nothing is written outside the partition.

@smlng smlng added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: pkg Area: External package ports labels Jan 12, 2018
@vincent-d
Copy link
Member Author

ping @gebart

@vincent-d
Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

please add an assert that checks that the partition does not begin or end outside of the physical device limits.

Copy link
Member Author

Choose a reason for hiding this comment

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

added 2 assert to check:

  • base_addr + sector_count is inside memory boundaries
  • base_addr is aligned on a sector

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.

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 */
Copy link
Member

Choose a reason for hiding this comment

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

firt -> first

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@jnohlgard
Copy link
Member

not sure why the tests fail on mulle though.

@vincent-d vincent-d force-pushed the pr/spiffs-multi-partitions branch from e2bd0d0 to 2e799e9 Compare February 27, 2018 15:40
@vincent-d
Copy link
Member Author

not sure why the tests fail on mulle though.

might be fixed by #8400. Since I rebased, could you give another try?

@jnohlgard
Copy link
Member

jnohlgard commented Feb 28, 2018

Retried with the latest PR branch, a new error:

INFO # spiffs_tests.tests_spiffs_partition (tests/unittests/tests-spiffs/tests-spiffs.c 397) exp 0 was -19

Edit: -19 is -ENODEV

@jnohlgard
Copy link
Member

Ah there is a missing vfs_format in the test

@vincent-d
Copy link
Member Author

Ah there is a missing vfs_format in the test

Yep, it has been introduced in between ;) This should be fixed!

@jnohlgard
Copy link
Member

I added the vfs_format and ran a test, new error:

2018-02-28 09:54:22,951 - INFO # spiffs_tests.tests_spiffs_partition (tests/unittests/tests-spiffs/tests-spiffs.c 407) buf[0] != 0xff

@vincent-d
Copy link
Member Author

Can't reproduce on native nor on our hardware (with spi flash). On which board do you have this issue?

@vincent-d
Copy link
Member Author

OK, I reproduced by changing the layout of my flash.
I changed the test to check the whole sectors. I guess the magic word is not always written in the same place.

@jnohlgard
Copy link
Member

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?

@vincent-d
Copy link
Member Author

@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.

@jnohlgard
Copy link
Member

Will test again tonight or tomorrow morning

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.

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));
Copy link
Member

Choose a reason for hiding this comment

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

|= 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

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

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));
Copy link
Member

Choose a reason for hiding this comment

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

we need to either check the return value, or memset buf to zero between each mtd_read to avoid hiding errors

Copy link
Member Author

Choose a reason for hiding this comment

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

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;
Copy link
Member

Choose a reason for hiding this comment

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

Change the name to nread to avoid name collision with the posix read function

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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.

Tests succeed on native and on Mulle.
Please squash

Samantha Wojtowicz and others added 2 commits March 2, 2018 13:45
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
@vincent-d vincent-d force-pushed the pr/spiffs-multi-partitions branch from d9076a4 to 647133f Compare March 2, 2018 12:47
@vincent-d
Copy link
Member Author

Squashed

@vincent-d
Copy link
Member Author

All green, go!

@vincent-d vincent-d merged commit dcc4a5a into RIOT-OS:master Mar 2, 2018
@vincent-d vincent-d deleted the pr/spiffs-multi-partitions branch March 2, 2018 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: pkg Area: External package ports CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants