Commit Graph

20 Commits

Author SHA1 Message Date
Daniel Leung b819a00b06 storage: rename shadow variables
Rename shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-22 11:39:58 +02:00
Gerard Marull-Paretas 5113c1418d subsystems: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all subsystems code to
the new prefix <zephyr/...>. Note that the conversion has been scripted,
refer to zephyrproject-rtos#45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-09 12:07:35 +02:00
Jonathan Nilsen e1891b3e9a storage/stream: Move fill value handling to flash_sync
Move the code responsible for aligning the flash write by writing fill
values - from stream_flash_buffered_write to flash_sync. This avoids
having to correct buf_bytes/buf_written after the write and thus
simplifies error handling.

This commit also fixes an issue where the write length passed to the
callback in flash_sync includes the fill length.

Signed-off-by: Jonathan Nilsen <Jonathan.Nilsen@nordicsemi.no>
2021-05-08 07:10:31 +02:00
Jonathan Nilsen 0e6ac008a0 storage/stream: Add persistent write progress to stream_flash
Add additional API to stream_flash that can be used to make
stream write progress persistent using the settings subsystem.
This functionality makes it possible to resume a write operation
after it was interrupted, e.g. by power loss.

Signed-off-by: Jonathan Nilsen <Jonathan.Nilsen@nordicsemi.no>
2021-04-23 15:01:32 -05:00
Andrzej Puzdrowski 45449c7b84 storage: remove flash_write_protection_set() usage
This patch removes scenario which was testing deprecated
API behaviors. Needed as As flash_write_protection_set() was
deprecated and became no-operation.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2021-03-29 13:43:55 -04:00
Dominik Ermel 32451230e2 storage/stream/flash: Failed write of reminder rewinds buffer offset
The stream_flash_buffered_write, when invoked to do flush write, will
attempt to write the tail bytes from the buffer, filling the required
minimal write block size with erase value bytes; after write it rewinds
the buffer offset, bytes_written, by number of the "filler bytes".
Doe to lack of return code processing from flash_sync call, two things
would happen to context in case of failure:
 1) the ctx->bytes_written would be rewind pass the value it had before
    function call as it gets decremented by "filler bytes" even if write
    failed;
 2) the ctx->buf_bytes offset would be accounting for added "filler
    bytes" which should not be counted as data in buffer.

Proper processing of return code has been added to remove effects
described above.

Unit tests have been expended to cover the scenarios.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel 07107f92c7 storage/stream/flash: Use flash_get_parameters to get flash erase_value
The stream_flash_buffered_write used to read byte from flash, in front
of the current buffer pointer, to obtain value of errased flash;
the code has been replaced with obtaining the value from flash
parameters.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel 5a1750b053 storage/stream/flash: flash_sync: Check if there is anything to write
The commit moves block that checks if flash_stream_ctx.buf_bytes
is non-zero out of CONFIG_STREAM_FLASH_ERASE specific code,  as that is
universal check and is valid also for not CONFIG_STREAM_FLASH_ERASE
code.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel cfb056901c storage/stream/flash: Fix flash_sync updating bytes_written on failure
The flash_sync function is able to call, if specified, write
verification callback to check whether data flash has been correctly
written to a flash.  Part of that procedure is to read date back of
the flash and call the verification callback on the buffer;
in case if the read would fail, the flash_sync would return,
with an error code, without updating stream_flash_ctx.

The same logic should be applied to failed verification, but, due to
missing return, the stream_flash_ctx gets updated with probably
incorrectly written bytes added to total bytes_written and buf_bytes,
representing number of bytes awaiting in buffer, being zeroed.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Dominik Ermel 94968dfee4 storage/stream/flash: Don't update last erased page offset on failure
The stream_flash_erase_page would update stream_flash_ctx member
last_erased_page_start_offset, to page offset it attempted to erase,
even if such operation failed.
The commit changes this behaviour so that in case of failure the
last_erased_page_start_offset would still hold previously, successfully,
erase page offset.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-03-03 11:40:11 +03:00
Martin Jäger 6fd8cbb9b4 storage: stream: flash: update log output
LOG_DBG is more appropriate for this logging output than LOG_INF.

Signed-off-by: Martin Jäger <martin@libre.solar>
2020-12-20 12:40:19 -05:00
Andrzej Puzdrowski 450b82aeb7 storage/stream: elimination of usage of the flash API internals
Module was using flash driver implementation API call
`page_layout()` which is part driver implementation
interface API.

This patch re-implement this part of code using
`flash_page_foreach()` public API function.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-11-17 11:34:35 +01:00
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka 98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Håkon Øye Amundsen a4957be25b storage/stream: allow NULL data pointer
This is done to support the idiomatic way of performing flush
operations, where the caller might not have access to the proper data
pointer. Also, there is no reason why reading from address 0 should
not be allowed.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-06-22 14:36:05 +02:00
Dominik Ermel 609b645ac7 drivers/flash: Move write_block_size into flash_parameters
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 <dominik.ermel@nordicsemi.no>
2020-06-22 14:35:03 +02:00
Andrzej Puzdrowski ac07694309 storag/stream: fix stream_flash_bytes_written() return value
stream_flash_bytes_written() returned number o bytes physically
written to the flash. This number might be bigger than the requested
number as is aligned to the device write-block-size.

stream_flash_bytes_written() should return number of bytes
written requested by the user.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-06-13 11:57:35 +02:00
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Andrzej Puzdrowski 06827ecd14 storage/stream: fix possible unaligned write on buffer 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.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-05-26 16:35:19 +02:00
Håkon Øye Amundsen a9676831cb storage: add stream flash library
This library supports stream writes to flash with
optinal progressive erase.

This module is a direct copy of the functionality found in
subsys/dfu/img_util/flash_img.c

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-05-06 11:14:00 +02:00