Skip to content

Conversation

@de-nordic
Copy link
Contributor

@de-nordic de-nordic commented Jun 3, 2020

Provided call returns const pointer to flash_parameters structure that can be used for passing memory parameters from drivers.

Resolves #22063

@de-nordic de-nordic requested review from hakonfam and nvlsianpu and removed request for nvlsianpu June 3, 2020 18:40
@de-nordic de-nordic self-assigned this Jun 3, 2020
@zephyrbot zephyrbot added area: File System area: Tests Issues related to a particular existing or missing test labels Jun 3, 2020
@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch 4 times, most recently from eaaef7e to 5c9169e Compare June 4, 2020 12:45
@zephyrbot
Copy link

zephyrbot commented Jun 4, 2020

All checks passed.

Tip: The bot edits this comment instead of posting a new one, so you can check the comment's history to see earlier messages.

@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from 5c9169e to 2560b16 Compare June 4, 2020 15:03
@de-nordic de-nordic requested a review from nvlsianpu June 5, 2020 04:52
@nvlsianpu nvlsianpu requested a review from Laczen June 5, 2020 06:40
Copy link
Contributor

@nvlsianpu nvlsianpu 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 how code looks like now.
Is it possible to make erased_val configurable for flash simulator via DTS?
Is it then possible to add test-case with either 0xff and 0x00 erase_value for nvs test (https://github.com/zephyrproject-rtos/zephyr/blob/master/tests/subsys/fs/nvs/testcase.yaml)?

@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from 2560b16 to 4932e9a Compare June 8, 2020 11:03
@zephyrbot zephyrbot added area: Devicetree area: Boards area: native port Host native arch port (native_sim) labels Jun 8, 2020
@nvlsianpu nvlsianpu added the Enhancement Changes/Updates/Additions to existing features label Jun 8, 2020
@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from 4932e9a to e0dc705 Compare June 8, 2020 12:00
@de-nordic de-nordic requested a review from nvlsianpu June 8, 2020 12:01
@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from e0dc705 to 6e12dbd Compare June 8, 2020 12:06
@de-nordic de-nordic marked this pull request as ready for review June 8, 2020 12:08
@Laczen
Copy link
Contributor

Laczen commented Jun 16, 2020

Yes, this is completely what I was thinking. I don't know if it is possible to use a const struct *flash_parameters.

@Laczen How do you want to use it? I do not encourage anyone to modify contents of flash_parameters outside of drivers.

Exactly how you are using it. Probably my remark is a result of limited c knowledge, can you assign the const struct *flash_parameters in nvs_init() ?

@de-nordic
Copy link
Contributor Author

Yes, this is completely what I was thinking. I don't know if it is possible to use a const struct *flash_parameters.

@Laczen How do you want to use it? I do not encourage anyone to modify contents of flash_parameters outside of drivers.

Exactly how you are using it. Probably my remark is a result of limited c knowledge, can you assign the const struct *flash_parameters in nvs_init() ?

Yes, const qualifier 'protects' here the structure as it is in the part that declares pointed type. If you want to protect pointer, you need to move const:
struct *const flash_parameters
or you can have both:
const struct *const flash_parameters

@de-nordic
Copy link
Contributor Author

@pabigot

(...) I'd like to document that the caller has the choice of caching the pointer, or copying the information desired to a different data structure with a guarantee it will never change.

You want this in the doxygen of the flash_get_parameters() ?

@pabigot
Copy link
Contributor

pabigot commented Jun 16, 2020

(...) I'd like to document that the caller has the choice of caching the pointer, or copying the information desired to a different data structure with a guarantee it will never change.

You want this in the doxygen of the flash_get_parameters() ?

I think so, yes, assuming you and others think this is worth making clear. I'd like to have this API raised during the API telecon today for visibility. But also we should confirm that nobody has a use case for the values changing for a given device while the system is running.

@de-nordic
Copy link
Contributor Author

I think so, yes, assuming you and others think this is worth making clear. I'd like to have this API raised during the API telecon today for visibility. But also we should confirm that nobody has a use case for the values changing for a given device while the system is running.

I do not think there is a case for the contents of flash_parameters to get modified at runtime. I will add the note to documentation, but we will need to wait until it gets clarified.

@Laczen
Copy link
Contributor

Laczen commented Jun 16, 2020

Yes, this is completely what I was thinking. I don't know if it is possible to use a const struct *flash_parameters.

@Laczen How do you want to use it? I do not encourage anyone to modify contents of flash_parameters outside of drivers.

Exactly how you are using it. Probably my remark is a result of limited c knowledge, can you assign the const struct *flash_parameters in nvs_init() ?

Yes, const qualifier 'protects' here the structure as it is in the part that declares pointed type. If you want to protect pointer, you need to move const:
struct *const flash_parameters
or you can have both:
const struct *const flash_parameters

OK, thanks for the clarification

@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from e76e380 to e13c9d8 Compare June 16, 2020 11:42
@nvlsianpu
Copy link
Contributor

NVS changes looks ok

Copy link
Member

Choose a reason for hiding this comment

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

This doesn't apply to all series.
On a handfull, this should be 0x00.
I'll get back to you with the references

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, thanks for looking into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@utzig has mentioned same thing here: #25947 (comment) though I do not know how does it apply to our stm32 drivers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erwango Can you advise me on the stm32 characteristic values for erase_value?

Copy link
Member

Choose a reason for hiding this comment

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

@de-nordic After check, only L0/L1 use 0x00 as erase value (I guess reason is they have an EEPROM and this is easier to use same erase value for both).
Since L0/L1 have no flash driver yet, proposed code is fine. Maybe adding a warning comment in case of L0/L1 future addition would be a nice thing though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@erwango Thanks for the information. Will add warning information.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a PR for an L0 driver (#25245) that will hit this issue. The easiest way to distinguish between the EEPROM and FLASH implementations is probably to check for the FLASH_CR_LOCK (erase value 0xff) or FLASH_PECR_PELOCK (erase value 0x00). It's not exactly pretty, but it avoids hard-coding the SOC family.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a PR for an L0 driver (#25245) that will hit this issue. The easiest way to distinguish between the EEPROM and FLASH implementations is probably to check for the FLASH_CR_LOCK (erase value 0xff) or FLASH_PECR_PELOCK (erase value 0x00). It's not exactly pretty, but it avoids hard-coding the SOC family.

@andysan, does this mean that also for L0 the flash erase value is 0xff?

@carlescufi
Copy link
Member

@pabigot @nvlsianpu could you take another look please?

Copy link
Contributor

@pabigot pabigot left a comment

Choose a reason for hiding this comment

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

OK as is, a couple minor cleanups identified.

Copy link
Contributor

Choose a reason for hiding this comment

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

Placement of this one isn't the same as the others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make this end at "copy its contents." The rest is opinion that isn't good advice for some uses. If you want it anyway just change "if preferred" to "is the preferred".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from 68607a7 to eba084c Compare June 19, 2020 19:44
@de-nordic de-nordic requested a review from nvlsianpu June 19, 2020 19:44
@de-nordic
Copy link
Contributor Author

@Laczen @pabigot Thanks for reviewing.

@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from eba084c to 051eeaa Compare June 22, 2020 07:10
Adds flash_get_parameters call to API that returns pointer to structure
describing flash parameters.
Currently only erase_value parameter is provided via the structure.

Signed-off-by: Dominik Ermel <[email protected]>
With addition of flash_get_parameters API call, it is needed to provide
support for the API to flash drivers.

Signed-off-by: Dominik Ermel <[email protected]>
Use new flash API call to obtain erase value instead of relaying on
hardcoded literals.

Signed-off-by: Dominik Ermel <[email protected]>
With addition of flash_parameters structure, and supporting API call
to retrieve it, it is no longer needed to store write_block_size as
a part of flash_driver_api and it should be part of flash_parameters.

Signed-off-by: Dominik Ermel <[email protected]>
Pointer to flash_parameters have been added to nvs_fs structure and it
is no longer needed to store write_block_size within the nvs_fs.

Signed-off-by: Dominik Ermel <[email protected]>
@de-nordic de-nordic force-pushed the flash-api-get-erase-val branch from 051eeaa to a946de6 Compare June 22, 2020 10:07
@carlescufi carlescufi merged commit 38f623d into zephyrproject-rtos:master Jun 22, 2020
@de-nordic de-nordic deleted the flash-api-get-erase-val branch June 25, 2020 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: API Changes to public APIs area: Boards area: Devicetree area: Drivers area: File System area: Flash area: native port Host native arch port (native_sim) area: Storage Storage subsystem area: Tests Issues related to a particular existing or missing test Enhancement Changes/Updates/Additions to existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs/NVS: NVS is not compatible with flash memories which have 0x00 as erased