Skip to content

NVStore: fix area calculation function #9445

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

Merged
merged 1 commit into from
Jan 31, 2019

Conversation

davidsaada
Copy link
Contributor

@davidsaada davidsaada commented Jan 21, 2019

Description

NVStore includes a function (calc_validate_area_params) that either calculates or validates the addresses and sizes of both areas. This function allocates a sector map array used in both calculation/validation of areas. While this generally worked, it had a few problems: First of all, it allocated and deallocated the sector map inside the function, while a more efficient code wouldn't need it. Second, it had a potential bug - number of of entries in the array was calculated according to the first sector size, but in case of a variant sector size, with a large first sector, the array size could have been smaller than required (this probably will never happen, but it's still a bug).
This PR removes the allocation and usage of sector map array. Instead it traverses the flash sectors on the fly (forwards in the validation case, backwards in the calculation case).
In addition, fix tests to get over failures in low end boards.
Tested with K64F (both default and user configured), K82F, K66F, NUCLEO_F429ZI and UBLOX_EVK_ODIN_W2.

Resolves #8513.

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@jeromecoutant

@ciarmcom
Copy link
Member

@davidsaada, thank you for your changes.
@ARMmbed/mbed-os-storage @ARMmbed/mbed-os-maintainers please review.

sector_map[num_sectors++] = flash_addr;
if (user_config) {
flash_addr = flash_start_addr;
while (left_size) {

Choose a reason for hiding this comment

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

while (left_size) does not seems safe. Maybe int left_size = flash_size; and while (left_size>0)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do, though:

  • Will probably need a few casts as all the rest of the variables are of size_t types.
  • The scenario you're afraid of is pretty erroneous: It can only happen if the flash driver exposes a flash size which is not a sum of its own sectors.

@jeromecoutant
Copy link
Collaborator

Hi

(Probably) resolves #8513.

No, I'm sorry...

Target Toolchain TestSuite TestCase #9445 mbed-os-5.11.2
NUCLEO_F070RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F070RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test ERROR ERROR
NUCLEO_F070RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F070RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F070RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F070RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F070RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality FAIL OK
NUCLEO_F070RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F070RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F072RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F072RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test ERROR ERROR
NUCLEO_F072RB ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F072RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F072RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F072RB GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F072RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality FAIL OK
NUCLEO_F072RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F072RB IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F091RC ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F091RC ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F091RC ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F091RC GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK
NUCLEO_F091RC GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Multiple thread test OK OK
NUCLEO_F091RC GCC_ARM features-storage-nvstore-tests-nvstore-functionality NVStore: Race test OK OK
NUCLEO_F091RC IAR features-storage-nvstore-tests-nvstore-functionality NVStore: Basic functionality OK OK

@0xc0170 0xc0170 requested a review from jeromecoutant January 22, 2019 08:32
@davidsaada
Copy link
Contributor Author

Hi

(Probably) resolves #8513.

No, I'm sorry...

Ugh... Will work with you offline on this.
PR should proceed regardless of this failure though (as resolving it wasn't its only purpose).

@adbridge adbridge requested a review from bulislaw January 23, 2019 11:00
@davidsaada davidsaada force-pushed the david_nvstore_fix_area_calc branch from 68cefcd to e6ed079 Compare January 23, 2019 13:26
@davidsaada
Copy link
Contributor Author

Pushed a fix to the tests, as it seems that this change worsened the state of test in low memory boards.
@jeromecoutant I believe that at least few of the issues you had are addressed now. Please retest.
If this works, will update the commit message and PR description.

Copy link
Collaborator

@jeromecoutant jeromecoutant left a comment

Choose a reason for hiding this comment

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

All green!

Thx

@davidsaada davidsaada force-pushed the david_nvstore_fix_area_calc branch from e6ed079 to 8d2bb17 Compare January 24, 2019 14:16
Don't allocate the sector map array in this function,
as it was buggy and redundant. Separate user config vs. automatic allocation
cases instead (which was essentially the case anyway).
In addition, fix tests to get over failures in low end boards
@davidsaada davidsaada force-pushed the david_nvstore_fix_area_calc branch from 8d2bb17 to 765b483 Compare January 24, 2019 14:18
@davidsaada
Copy link
Contributor Author

Thanks @jeromecoutant for verifying that. Description and commit message modified.

@jeromecoutant
Copy link
Collaborator

Maybe we can start CI ? :-)

@cmonr
Copy link
Contributor

cmonr commented Jan 30, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Jan 31, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 1
Build artifacts

@cmonr cmonr merged commit 66792b4 into ARMmbed:master Jan 31, 2019
@davidsaada davidsaada deleted the david_nvstore_fix_area_calc branch February 22, 2019 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NVSTORE deinit function doesn't free memory
6 participants