Commit graph

133 commits

Author SHA1 Message Date
Ivan Grokhotkov
6f504deed0 nvs: run all test by default, exclude long tests by tag
Reduces the chance of new tests being skipped in CI
2018-04-19 15:08:08 +08:00
Ivan Grokhotkov
f8cb95d0b8 nvs: print progress in nvs API tests, reduce number of iterations 2018-04-19 15:08:08 +08:00
Ivan Grokhotkov
17ab60d642 Merge branch 'bugfix/nvs_failed_crc_assert' into 'master'
nvs: don’t expect items with bad CRC to be in cache

See merge request idf/esp-idf!2239
2018-04-18 11:01:21 +08:00
Sagar Bijwe
9a3c4b7134 nvs: Fix recovery after power-off during erase operation
Current code for recovery after power-off do not clean-up partially
erased items for FULL pages. If the erasure was part of modification
operation, this gets luckily cleaned-up because of duplicate detection
logic. For erase-only operation, the problem still exists. This patch
adds the recovery for FULL pages also.

Closes TW<20284>
2018-04-17 12:24:21 +05:30
Konstantin Kondrashov
6a4033b8a7 nvs: fix nvs_get_stats unit test
Changed check for the returned parameter from ESP_ERR_NVS_PART_NOT_FOUND to ESP_ERR_NVS_NOT_INITIALIZED.
2018-04-16 13:28:45 +00:00
Ivan Grokhotkov
2c3644a09f nvs: don’t expect items with bad CRC to be in cache
When erasing a variable length item with an incorrect CRC32, the span
value of the item can not be trusted, so the item will be erased with
span = 1. Subsequent entries represent the data of the variable
length item, and these will be treated as separate items. For each
entry CRC32 is checked, the check most likely fails (because the
entry contains arbitrary data, and not a proper NVS item), and the
entry is erased. Erase function assumed that every item should be
present in cache, but it is not the case for the entries which are
just parts of item’s payload. This change allows for the item to be
not found in the hashlist, if the CRC32 check fails.
2018-04-16 09:36:17 +00:00
Ivan Grokhotkov
20405fbbcc nvs: make nvs_flash_deinit useable from unit tests 2018-04-16 14:06:52 +08:00
Ivan Grokhotkov
fa3bd16d75 nvs: deinit NVS in nvs_stats unit test
This fixes the failure when this test runs after another test which
leaves NVS initialized.
2018-04-16 12:50:57 +08:00
Ivan Grokhotkov
d0d314d8f8 Merge branch 'bugfix/nvs_page_selection' into 'master'
nvs: Fix page selection algo to consider free entry counts as well

See merge request idf/esp-idf!2240
2018-04-16 10:32:01 +08:00
Sagar Bijwe
7e79471ece nvs: Fix page selection algo to consider free entry counts as well
Current page selection algorithm selects a page for compaction based on just erased counts
and gives up when it does not find any page with erased count greater than 0. This is
problematic since the current allocation procedure skips the active page if there is not
enough room for the item in that page leaving free chunks on the pages. This change modifies
the algorithm to consider both erased as well as free counts on the candidate pages.

Closes TW<20297>
2018-04-13 14:49:05 +05:30
konstantin
c93626db3f nvs:Add functions for calculating used/free entries
Users needs functions to count the number of free and used entries.

1. `nvs_get_stats()` This function return structure of statistic about the uspace NVS.
(Struct: used_entries, free_entries, total_entries and namespace_count)
2. `nvs_get_used_entry_count()` The second function return amount of entries in the namespace (by handler)
3. Added unit tests.

Closes TW<12282>
2018-04-13 10:34:13 +05:00
Roman Valls Guimera
519edc332d Fix compilation errors when using gcc-7.2.0 for the crosstool-ng toolchain
* Change snprintf for strlcat does not complain w/gcc7.2.0 and it is safer, thanks @projectgus
* Use proper quotes for character literals

Merges https://github.com/espressif/esp-idf/pull/1163
2017-12-04 10:18:40 +11:00
Ivan Grokhotkov
ab13db0e45 nvs: fix nvs_flash_init_partition initializing default partition
Fixes https://github.com/espressif/esp-idf/issues/1052.

Ref TW15698.
2017-10-13 07:19:16 +08:00
Ivan Grokhotkov
9325f2a7a4 nvs_flash: emulator: fix issues in load function, add save function 2017-09-19 10:39:44 +08:00
Ivan Grokhotkov
fe30789149 nvs_flash: delete Storage if init fails
Previously, nvs_flash_init_custom would not be called if Storage for a
particular partition was already created. This caused issues if the
first call to nvs_flash_init failed due to Storage init error. This issue
exhibited itself as random failures of NVS CI test.

With this change, storage object is deleted (and not added to storage
list) if initialization fails.
2017-09-19 10:39:44 +08:00
Ivan Grokhotkov
f32b25ebe2 nvs_flash: add functions to deinitialize storage 2017-09-19 10:39:44 +08:00
Amey Inamdar
c8945bb82a nvs: minor - removed unused header inclusion
Signed-off-by: Amey Inamdar <amey.inamdar@gmail.com>
2017-09-18 17:02:32 +05:30
baohongde
87031f9457 component/bt: fix nvs_get_str_or_blob length output error 2017-09-08 12:02:35 +08:00
baohongde
e1bd51af80 component/bt: fix nvs_get_str_or_blob length output error 2017-09-08 12:02:35 +08:00
baohongde
f3be0395d2 component/bt: fix nvs_get_str_or_blob length output error 2017-09-08 12:02:35 +08:00
Ivan Grokhotkov
c0269bc1cd nvs: check CRC of items on full pages
Previously NVS did check CRC values of key-value pairs on the active
page, but the check for full pages was missing. This adds the necessary
check and a test for it.
2017-09-04 14:37:33 +08:00
Amey Inamdar
a2dcf7faa8 nvs: Support for handling multiple NVS partitions
This commit adds support for multiple NVS partitions. This provides application a flexibility to have multiple NVS
partitions such as separate partition with read-only manufacturing data and read-write partition with configuration.
Application can also use this to separate out application's configuration storage from system configuration.

This feature does not change any of the basic property of NVS subsystem. The same-named namespaces across partitions are
considered to be different namespaces. The original NVS API available for the applications remains unchanged. The only
difference is that instead of first NVS partition in the partition table, it now operates on the partition with label
"nvs" (which is default in the IDF provided partition table files). Additional APIs are provided to open a handle and
erase NVS with partition name as a parameter.

A test case is added in the host tests and it is made sure that all the host tests pass. nvs_rw_value app is also tested
with multiple partitions.

Signed-off-by: Amey Inamdar <amey.inamdar@gmail.com>
2017-08-22 13:48:14 +05:30
Amey Inamdar
3e4e4dd07a nvs_flash: Reduced visibility of handle counter
Monotonically increasing handle counter need not be visible outside the HandleEntry class.

Signed-off-by: Amey Inamdar <amey.inamdar@gmail.com>
2017-08-22 12:58:56 +05:30
Ivan Grokhotkov
979fce0df5 bt: call nvs_flash_init in examples, show error if NVS is not initialized
NVS is used to store PHY calibration data, WiFi configuration, and BT
configuration. Previously BT examples did not call nvs_flash_init,
relying on the fact that it is called during PHY init. However PHY init
did not handle possible NVS initialization errors.

This change moves PHY init procedure into the application, and adds
diagnostic messages to BT config management routines if NVS is not
initialized.
2017-07-17 21:29:50 +08:00
Ivan Grokhotkov
f045123691 nvs: add test for ESP_ERR_NVS_INVALID_LENGTH 2017-06-27 11:28:37 +08:00
Simon Werner
dacb053546 ESP_ERR_NVS_VALUE_TOO_LONG had conflicting value.
`ESP_ERR_NVS_VALUE_TOO_LONG` had conflicting value, its original value was `0x0c`, which is the same as `ESP_ERR_NVS_INVALID_LENGTH`
2017-06-27 11:58:49 +12:00
Ivan Grokhotkov
a25a4a0a7c nvs: check value size before writing, document limitations
Writing values longer than half of the page size (with header taken into
account) causes fragmentation issues. Previously it was suggested on the
forum that using long values may cause issues, but this wasn’t checked
in the library itself, and wasn’t documented. This change adds necessary
checks and introduces the new error code.

Documentation is also fixed to reflect the fact that the maximum length
of the key is 15 characters, not 16.
2017-05-31 12:59:24 +08:00
Ivan Grokhotkov
bf01525fc1 nvs: remove search cache at page level
Since read cache was introduced at page level, search cache became
useless in terms of reducing the number of flash read operations.
In addition to that, search cache used an assumption that if pointers to
keys are identical, the keys are also identical, which was proven wrong
by applications which generate key names dynamically.

This change removes CachedFindInfo, and all its uses. This is done at
expense of a small extra number of CPU operations (looking up a value in
the read cache is slightly more expensive) but no extra flash read
operations.

Ref TW12505
Ref https://github.com/espressif/arduino-esp32/issues/365
2017-05-12 12:18:08 +08:00
Ivan Grokhotkov
8f76fe1d7f move Catch framework header into tools directory 2017-04-17 11:01:18 +08:00
Ivan Grokhotkov
57e380fa99 nvs_flash, wear_levelling: ignore host test files 2017-04-17 11:01:18 +08:00
Ivan Grokhotkov
447ffb23d5 nvs: print page state as text in nvs_dump 2017-03-15 17:28:07 +08:00
Ivan Grokhotkov
4813ab2d28 examples: check return value of nvs_flash_init
nvs_flash_init may return an error code in some cases, and applications
should check this error code (or at least assert on it being ESP_OK, to
make potential issues more immediately obvious).

This change modifies all the examples which use NVS to check the error
code. Most examples get a simple ESP_ERROR_CHECK assert, while NVS
examples, OTA example, and NVS unit tests get a more verbose check which
may be used in real applications.
2017-03-15 10:44:54 +08:00
Ivan Grokhotkov
5a23ec4dc4 nvs: check that storage has at least one free page
This change adds a check for the free page count to nvs_flash_init.
Under normal operation, NVS keeps at least one free page available,
except for transient states such as freeing up new page. Due to external
factors (such as NVS partition size reduction) this free page could be
lost, making NVS operation impossible. Previously this would cause an
error when performing any nvs_set operation or opening a new namespace.
With this change, an error is returned from nvs_flash_init to indicate
that NVS partition is in such a state.
2017-03-14 22:03:39 +08:00
Ivan Grokhotkov
817bbb4bf9 nvs: add missing error code descriptions 2017-03-14 22:03:39 +08:00
Angus Gratton
d6f183fbb9 esp_err: Use separate code path for ESP_ERROR_CHECK assertion
* Minimum code size overhead
* Makes function safe to use when flash cache is disabled

Builds on #339 https://github.com/espressif/esp-idf/pull/339
2017-03-03 15:33:23 +11:00
Ivan Grokhotkov
c47cc63489 newlib: change definition of assert for release builds
One common pattern of using assert function looks as follows:
    int ret = do_foo();
    assert(ret == 0);   // which reads as: “do_foo should never fail here, by design”
The problem with such code is that if ‘assert’ is removed by the preprocessor in release build,
variable ret is no longer used, and the compiler issues a warning about this.
Changing assert definition in the way done here make the variable used, from language syntax perspective.
Semantically, the variable is still unused at run time (as sizeof can be evaluated at compile time), so the compiler
can optimize things away if possible.
2017-01-17 00:49:38 +08:00
antti
83a3ce882f add updated nvs flash test 2016-11-23 11:29:36 +08:00
antti
d390449371 add unit tests to esp-idf
rename nvs host test folder, modify .gitlab-ci.yml

remove unit-test-app build

re-format unit test files

remove extra newlines in project.mk

some refactoring for unit test part in project.mk

add build files of unit-test-app in gitignore

add README.md for unit test app

correct headings in README.md

remove files and make minor tweaks in unit test app

update .gitlab-ci.yml to use unit test app

delete unused lines in component_wrapper.mk

delete periph_i2s.h and lcd test

add text floating point in components/esp32/test/Kconfig

correct idf test build paths in .gitlab-ci.yml
2016-11-22 14:45:50 +08:00
Ivan Grokhotkov
0b265dc2a7 nvs, spi_flash: handle case when source data is in DROM 2016-11-18 20:11:17 +08:00
Ivan Grokhotkov
541b142654 phy_init: reduce the amount of hardwired logic, add coexist init 2016-11-18 20:11:17 +08:00
Ivan Grokhotkov
6e97936bac nvs: allow nvs_flash_init to be called more than once
Also don’t assert in nvs_* functions if nvs_flash_init wasn’t called,
and make nvs_flash_init_custom an internal API for unit tests.
2016-11-18 20:11:16 +08:00
Ivan Grokhotkov
51021b06f8 nvs: initialize using layout from partition table 2016-11-18 20:11:16 +08:00
Ivan Grokhotkov
3bbe41c34d Merge branch 'feature/docs_general_notes' into 'master'
Docs: new documentation and warnings cleanup

This change set

- adds a high-level description of application startup flow. Some parts are missing, but hopefully we can use this description as a base to expand on.
- adds a few notes about memory regions and their use in ESP-IDF.
- add SPI flash and partition APIs page
- fixes all Doxygen warnings in header files
- enables build failures on new Doxygen warnings

See merge request !201
2016-11-17 19:00:03 +08:00
Liu Zhi Fu
936b02216b docs/nvs_flash: update the nvs flash offset comment according review 2016-11-17 11:44:39 +08:00
Liu Zhi Fu
f12be7ebd8 nvs_flash: adjust the nvs_flash start sector number
Modify the nvs flash start sector from 6 to 9
2016-11-17 11:22:20 +08:00
Ivan Grokhotkov
13d4734399 docs: fix Doxygen warnings, fail CI build on Doxygen warnings 2016-11-16 22:44:22 +08:00
Angus Gratton
c15024e629 Merge branch 'master' into feature/build_component_project_vars 2016-11-14 14:54:41 +11:00
Angus Gratton
208e83def7 build system: Refactor component.mk to not need component_common.mk
New makefile component_wrapper.mk allows some variables to be set
before component.mk is evaluated. This properly fixes problems with
sdkconfig being hard to access in all phases of the build.

Including component_common.mk is no longer necessary and will print a
deprecation warning for components which use it.
2016-11-10 15:52:22 +11:00
Ivan Grokhotkov
e314f42b0c nvs: fix Page::findItem and Storage::findItem regression
When read caching was added, Page::findItem started modifying itemIndex reference argument even if item wasn't found.
Incidentally, Storage::findItem reused itemIndex when starting search at next page.
So,
- if the first page had a cached index (findItem was called for that page), and it pointed to a non-zero index,
- first page has a few empty items at the end (but is marked full),
- next search looked up the item on the second page,
- index of the item on the second page was less than the cached index on the first page,
then the search would fail because cached starting index was reused.

This change fixes both sides of the problem:
- Page::findItem shouldn't modify itemIndex argument if item is not found
- Storage::findItem should not reuse itemIndex between pages

Two tests have been added.
2016-11-03 20:18:30 +08:00
Ivan Grokhotkov
b8e940d645 Merge branch 'bugfix/nvs_write_failure' into 'master'
Fix spi_flash_write regression and nvs error recovery

In the previous set of changes related to spi_flash, new alignment checks were added. One of these checks, word alignment of `src` buffer in `nvs_flas_write`, was unnecessary.  ROM `SPIWrite` function can handle unaligned source buffers.

This change caused an error to be returned to nvs for some legitimate write operations. Due to a bug in nvs, further write operations were possible, while the internal state of `Page` instance was broken. In WiFi functional tests, this inflicted havoc on the nvs partition, creating multiple duplicate items in the affected page. Because multiple duplicate items per page were never supposed to be handled during page load, duplicates were not removed. Thankfully this caused an assert at a later point in the loading process, otherwise this bug would be very difficult to detect.

This change set fixes the original spi_flash regression, handling of `INVALID` state of `nvs::Page`, and handling of duplicate items.

See merge request !161
2016-11-01 22:26:37 +08:00
Krzysztof
12efd96fb4 Corrected documentation style
This is for better visuaization with Sphinx
2016-11-01 01:21:18 +08:00
Krzysztof
fa002b4909 Fixed headers to match python doc standard 2016-11-01 01:20:04 +08:00
Krzysztof
1263cd340e Add missing annotations 2016-11-01 01:20:04 +08:00
Ivan Grokhotkov
abea6c50f1 nvs_flash: delete all duplicate entries in a page while loading
Due to previous flash write bug it was possible to create multiple duplicate entries in a single page.
Recovery logic detected that case and bailed out with an assert.
This change adds graceful recovery from this condition.
Tests included.
2016-10-31 21:10:47 +08:00
Ivan Grokhotkov
d9cdc7de58 nvs_flash: don't allow more operation to be done on page in PageState::INVALID
Currently a restart is required to recover a page from invalid state.
The long-term solution is to detect such a condition and recover automatically (without a restart). This will be implemented in a separate change set.
2016-10-31 19:48:28 +08:00
Ivan Grokhotkov
413f2c00f6 nvs_flash: introduce write failures after each word written
Previously the test bench would check failure recovery by introducing error after each write operation.
This makes checks a bit more extensive (and much longer) by failing after every word written. Surprisingly, this change didn't expose any bugs.
2016-10-31 19:17:25 +08:00
Ivan Grokhotkov
269332f473 nvs_flash: use CRC-32 routine compatible with ROM version
Host tests used different flavour of CRC-32, which made it impossible to load NVS partition dumps created on the chip
2016-10-31 19:11:40 +08:00
Ivan Grokhotkov
e34fc7a46c Merge branch 'bugfix/nvs_leaks' into 'master'
nvs: fix memory leaks in HashList and nvs_close

Fixes TW8162.
Associated test case is run under Instruments on macOS, until I set up valgrind to test this automatically on Linux.

See merge request !150
2016-10-31 17:30:00 +08:00
Ivan Grokhotkov
9f0f05d520 spi_flash: change pointer type to void* 2016-10-27 17:58:42 +08:00
Ivan Grokhotkov
2c5340d47e spi_flash: change argument types
spi_flash_read and spi_flash_write currently have a limitation that source and destination must be word-aligned.
This can be fixed by adding code paths for various unaligned scenarios, but function signatures also need to be adjusted.
As a first step (since we are pre-1.0 and can still change function signatures) alignment checks are added, and pointer types are relaxed to uint8_t.
Later we will add handling of unaligned operations.
This change also introduces spi_flash_erase_range and spi_flash_get_chip_size functions.

We probably need something like spi_flash_chip_size_detect which will detect actual chip size.
This is to allow single application binary to be used on a variety of boards and modules.
2016-10-27 17:58:42 +08:00
Ivan Grokhotkov
74a658c765 nvs: fix memory leaks in HashList and nvs_close
Fixes TW8162.
Associated test case is run under Instruments on macOS, until I set up valgrind to test this automatically on Linux.
2016-10-26 12:25:53 +08:00
Ivan Grokhotkov
1cd572c7b9 Add test for compiling in release mode, fix warnings and errors which appeared 2016-10-17 13:40:10 +08:00
Angus Gratton
a98ab8d801 nvs: Remove flash layout arguments from nvs_init()
Add notes that current NVS layout defaults are a Work In Progress and
not yet integrated with the partition table.
2016-09-27 13:28:45 +10:00
Ivan Grokhotkov
6f2ed934d2 components/nvs: fix broken sentences in comment blocks 2016-09-26 12:41:04 +08:00
Ivan Grokhotkov
1c7508885c components/nvs: fix build, use log library instead of printf 2016-09-23 09:00:28 +08:00
Ivan Grokhotkov
2a68f60874 components/nvs: add erase function
This change exposes functions to erase single key and to erase all keys from namespace.
TW6769, TW6839
2016-09-23 08:08:03 +08:00
Ivan Grokhotkov
e87d80d478 components/nvs: fix formatting 2016-09-22 21:05:47 +08:00
Ivan Grokhotkov
076141aab9 components/nvs: batch writes when possible
Introduces new internal function, Page::alterEntryRangeState, which gathers changes to multiple elements of entry state table into a single write, provided that these changes fall into a single word. This allows changing state of up to 16 entries in a single write.
Also adds new function, writeEntryData, which writes the whole payload of SZ and BLOB type entries in one go, instead of splitting it into multiple 32-byte writes.
This reduces number of writes required for SZ and BLOB entries.
2016-09-22 21:05:17 +08:00
Ivan Grokhotkov
12a0786e2a components/nvs: maintain item hash list at page level 2016-09-21 18:02:52 +08:00
Ivan Grokhotkov
f06ebeba86 components/nvs: avoid reading just-erased page 2016-09-21 18:02:52 +08:00
Angus Gratton
3b1c3dab4b Name component makefiles component.mk instead of Makefile
Fixes problems with Eclipse trying to build in directories it shouldn't.

This is a breaking change for existing repositories, they need to rename
any component Makefiles to component.mk and rename their references to
$(IDF_PATH)/make/component.mk to $(IDF_PATH)/make/component_common.mk
2016-09-08 13:41:19 +10:00
Ivan Grokhotkov
9ef827ae20 components/nvs: strlcpy is not available on Linux, replace with strncpy and terminate strings explicitly 2016-08-23 15:14:13 +08:00
Ivan Grokhotkov
3df4130eb7 components/nvs: run small number of tests as part of CI builds 2016-08-23 12:56:10 +08:00
Ivan Grokhotkov
b783e2ffab components/nvs: fix typos in readme 2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
a65e019451 components/nvs: fix host build with GCC 4.9, add coverage report generation 2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
7998b6ca2e components/nvs: handle more cases where sudden power off may happen
This commit fixes several issues with state handling in nvs::Page. It also adds extra consistency checks in nvs::PageManger initialization.
These changes were verified with a new long-running test ("test recovery from sudden poweroff"). This test works by repeatedly performing same pseudorandom sequence of calls to nvs_ APIs. Each time it repeats the sequence, it introduces a failure into one of flash operations (write or erase). So if one iteration of this test needs, say, 25000 flash operations, then this test will run 25000 iterations, each time introducing the failure point at different location.
2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
7447d08605 components/nvs: clear handles list on init, fix returning *length in nvs_get_{str,blob} 2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
35d50643bc components/nvs: fix infinite loop when loading namespaces 2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
f04c894123 components/nvs: add debugging facilities and runtime checks
Extra runtime sanity checks run when compiled for the host (i.e. with no ESP_PLATFORM define)
2016-08-23 12:08:00 +08:00
Ivan Grokhotkov
3ce433cfd1 components/nvs: make some methods const 2016-08-23 12:08:00 +08:00
Angus Gratton
f853f94335 Use IDF_PATH instead of SDK_PATH for the environment variable pointing to esp-idf
This will require a matching change in all projects using ESP-IDF.
2016-08-19 15:01:49 +08:00
Angus Gratton
9ec0e1545d Standardise remaining uses of SDK to ESP-IDF 2016-08-19 15:01:15 +08:00
Ivan Grokhotkov
bd6ea4393c Initial public version 2016-08-17 23:08:22 +08:00