Skip to content
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

storage/stream: fix possible unaligned write on buffer flush request #25584

Merged
merged 3 commits into from
May 26, 2020

Conversation

nvlsianpu
Copy link
Collaborator

On buffer flush request it is very probably that write buffer
contains amount of data which is non write-block-size aligned.
Flash memory need to be write at minimal by write-block-size chunks.
This patch addresses mechanism which ensure such behavior by adding
missing bytes.

fixes #25471

Signed-off-by: Andrzej Puzdrowski andrzej.puzdrowski@nordicsemi.no

@nvlsianpu nvlsianpu added bug The issue is a bug, or the PR is fixing a bug area: Storage Storage subsystem labels May 25, 2020
subsys/storage/stream/stream_flash.c Outdated Show resolved Hide resolved
subsys/storage/stream/stream_flash.c Outdated Show resolved Hide resolved
@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch from 4aa4b5e to bb5dc9f Compare May 25, 2020 12:12
@nvlsianpu nvlsianpu added this to the v2.3.0 milestone May 25, 2020
@carlescufi carlescufi requested a review from pabigot May 25, 2020 12:27
subsys/storage/stream/stream_flash.c Outdated Show resolved Hide resolved
subsys/storage/stream/stream_flash.c Outdated Show resolved Hide resolved
subsys/storage/stream/stream_flash.c Show resolved Hide resolved
@nandojve
Copy link
Member

I was wondering if a regression test for this would not be good.

@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch from bb5dc9f to 1885501 Compare May 25, 2020 12:34
@zephyrbot
Copy link
Collaborator

zephyrbot commented May 25, 2020

All checks are passing now.

checkpatch (informational only, not a failure)

-:61: WARNING:LONG_LINE_STRING: line over 80 characters
#61: FILE: subsys/storage/stream/stream_flash.c:195:
+		LOG_ERR("Buffer size is not aligned to minimal write-block-size");

- total: 0 errors, 1 warnings, 116 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Your patch has style problems, please review.

NOTE: Ignored message types: AVOID_EXTERNS BRACES CONFIG_EXPERIMENTAL CONST_STRUCT DATE_TIME FILE_PATH_CHANGES MINMAX NETWORKING_BLOCK_COMMENT_STYLE PRINTK_WITHOUT_KERN_LEVEL SPDX_LICENSE_TAG SPLIT_STRING VOLATILE

NOTE: If any of the errors are false positives, please report
      them to the maintainers.

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

@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch from 1885501 to 514b6b8 Compare May 25, 2020 12:48
@nvlsianpu
Copy link
Collaborator Author

I was wondering if a regression test for this would not be good.

Yes it is possible.

* should be erased in order to get the erased
* byte-value.
*/
rc = flash_read(ctx->fdev,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is side note: We should consider adding some API call for returning the 'erased' byte value for the device. It is at least second time when I see that the value is needed and is either read from device (here) or predefined in code, e.g. in mcuboot.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

have this on my API request change list

Copy link
Collaborator

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

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

Notes left. otherwise I think that the solution is fine.

@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch from 92ba864 to 69d9656 Compare May 25, 2020 15:27
@nvlsianpu nvlsianpu requested a review from nashif as a code owner May 25, 2020 15:27
@nvlsianpu
Copy link
Collaborator Author

@nandojve Test added

@zephyrbot zephyrbot added the area: Tests Issues related to a particular existing or missing test label May 25, 2020
@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch 2 times, most recently from 7d120b3 to 64d46a4 Compare May 25, 2020 15:44
Copy link
Collaborator

@hakonfam hakonfam left a comment

Choose a reason for hiding this comment

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

There is a typo in the last commit "steram" -> "stream"

@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch 2 times, most recently from 4e0b926 to 46b5abd Compare May 25, 2020 19:26
Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

After apply changes, the board disco_l475_iot1 started to work properly.

@nvlsianpu
Copy link
Collaborator Author

In the last commit added note on requirements for size of the stream buffer.

@zephyrbot zephyrbot added the area: API Changes to public APIs label May 26, 2020
nvlsianpu added 3 commits May 26, 2020 11:32
On buffer flush request it is very probably that write buffer
contains amount of data which is non write-block-size aligned.
Flash memory need to be write at minimal by write-block-size chunks.
This patch addresses mechanism which ensure such behavior by adding
missing bytes.

fixes zephyrproject-rtos#25471

streamer buffer size should be multiple write-block-size of
the flash device in order to avoid unaligned flash write
request.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Added test for check proper service of flush-write when buffer
contains unaligned amount of data.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
Implementation requires that streamer buffer size must be
multiple of the flash device wbs.
This patch reflects this in API documentation

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
@nvlsianpu nvlsianpu force-pushed the bugfix/issue_25471 branch from d7ab2dc to d8956a3 Compare May 26, 2020 09:33
@carlescufi carlescufi merged commit 50ecfd2 into zephyrproject-rtos:master May 26, 2020
joerchan pushed a commit to joerchan/sdk-zephyr that referenced this pull request May 27, 2020
… flush

On buffer flush request it is very probably that write buffer
contains amount of data which is non write-block-size aligned.
Flash memory need to be write at minimal by write-block-size chunks.
This patch addresses mechanism which ensure such behavior by adding
missing bytes.

fixes #25471

streamer buffer size should be multiple write-block-size of
the flash device in order to avoid unaligned flash write
request.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
joerchan pushed a commit to joerchan/sdk-zephyr that referenced this pull request May 27, 2020
… test

Added test for check proper service of flush-write when buffer
contains unaligned amount of data.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
joerchan pushed a commit to joerchan/sdk-zephyr that referenced this pull request May 27, 2020
requirements

Implementation requires that streamer buffer size must be
multiple of the flash device wbs.
This patch reflects this in API documentation

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
… flush

On buffer flush request it is very probably that write buffer
contains amount of data which is non write-block-size aligned.
Flash memory need to be write at minimal by write-block-size chunks.
This patch addresses mechanism which ensure such behavior by adding
missing bytes.

fixes #25471

streamer buffer size should be multiple write-block-size of
the flash device in order to avoid unaligned flash write
request.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit 642dc37)
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
… test

Added test for check proper service of flush-write when buffer
contains unaligned amount of data.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit 911bc79)
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
…rements

Implementation requires that streamer buffer size must be
multiple of the flash device wbs.
This patch reflects this in API documentation

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit b7e535c)
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
… flush

On buffer flush request it is very probably that write buffer
contains amount of data which is non write-block-size aligned.
Flash memory need to be write at minimal by write-block-size chunks.
This patch addresses mechanism which ensure such behavior by adding
missing bytes.

fixes #25471

streamer buffer size should be multiple write-block-size of
the flash device in order to avoid unaligned flash write
request.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit 642dc37)
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
… test

Added test for check proper service of flush-write when buffer
contains unaligned amount of data.

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit 911bc79)
mbolivar-nordic pushed a commit to mbolivar-nordic/sdk-zephyr that referenced this pull request Jun 1, 2020
…rements

Implementation requires that streamer buffer size must be
multiple of the flash device wbs.
This patch reflects this in API documentation

upstream: zephyrproject-rtos/zephyr#25584

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit b7e535c)
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: Storage Storage subsystem area: Tests Issues related to a particular existing or missing test bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

disco_l475_iot1 don't write last small block
7 participants