Commit graph

78 commits

Author SHA1 Message Date
Dominik Ermel 26bf1e34b6 subsys/storage/flash_map: Inline flash_area_layout
Inlined into flash_area_get_sectors and removed.

Fixes #19880

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2024-03-22 08:58:48 +01:00
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
Maurits Fassaert 42507c69c2 storage: flash_map list partition labels
Add the labels from the device tree fixed flash partitions
as a column to the flash_map list shell command.

Signed-off-by: Maurits Fassaert <maurits.fassaert@sensorfy.ai>
2023-05-05 10:02:19 +02:00
Paul He 322f5ad4ef storage: flash_map: shell: fix error 'sh' undeclared
Some of `shell` were missed to be updated with `sh`.

Signed-off-by: Paul He <pawpawhe@gmail.com>
2023-04-30 12:48:55 -05:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Dmytro Semenets e169f7cc12 subsys/storage/flash_map: remove unnecessary includes
Those files includes soc.h header which exists not for all boards.
soc.h consists soc-depended defenitions and need to be included by
soc-depended sources

Signed-off-by: Dmytro Semenets <dmytro_semenets@epam.com>
2023-03-03 15:34:59 +01:00
Gerson Fernando Budke 358ad431b8 storage: flash_map: Add name for select integrity backend
Currently choice for FLASH_AREA_CHECK_INTEGRITY does not have a
denomination. Without that it is not possible select a default
backend hash backend for integrity check at project configuration.
This add a name to allow select flash area check integrity backend.

Signed-off-by: Gerson Fernando Budke <gerson.budke@ossystems.com.br>
2023-01-09 15:24:10 +00:00
Dominik Ermel 77f21ce966 storage: flash_map: shell: Show device pointer instead of ID
The commit changes flash_map list output to display flash_map
assigned pointer instead of device ID which was not propagated
anyway.
The commit also fixes formatting of the output.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-12-27 13:24:55 +01:00
Gerard Marull-Paretas e63b0bb3fe include: add missing errno.h include
With the incoming removal of kernel.h/types.h from init.h, lots of files
start to show compile errors because they relied on indirect
definitions, including errno.h.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-11 18:05:17 +02:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Steven Slupsky fd1423620e storage: flash_map: fix incomplete type
A pointer is not properly declared properly which causes the
build to fail.

flash_map_shell.c and flash_map.h do not include device.h so
the device struct has an incomplete type hence the build error.
Including device.h resolves the problem.

Also fixes a Wformat warning when referencing fa_off which is a pointer.
Cast the pointer to an uint32_t.

Fixes #48722

Signed-off-by: Steven Slupsky <sslupsky@gmail.com>
2022-08-18 11:20:26 +02:00
Jordan Yates a593a733e8 storage: flash_map: handle disabled flash nodes
Don't fail to compile when `fixed-partition`'s exist on a flash device
that is disabled. This does not fix the case where a `fixed-partition`
is on a flash device with `status = "okay"` but with no driver compiled
in.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-04 10:28:41 +02:00
Jordan Yates 75680f7ae0 treewide: update flash_area name retrieval
Update usage of `flash_area->fa_dev_name` to `flash_area->fa_dev->name`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-02 16:04:16 +02:00
Jordan Yates 4543f82c12 storage: flash_map: remove device_get_binding
Remove all usage of `device_get_binding` in the subsys by directly
storing the `const struct device*` in the `struct flash_area`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2022-07-02 16:04:16 +02:00
Dominik Ermel aa5d20aaef storage/flash_map: Return -ENODEV from flash_area_open
The commit adds check, to flash_area_open, whether there is any
device driver attached and returns -ENODEV if there isn't any.
This works around a problem where flash_area_open succeeds but
consecutive read/write causes crash.
It is enough to check the condition, and return error, here as
the flash_area_open has to precede, and be checked for success,
any read/write operations.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2022-06-05 14:28: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
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
David Brown fac2c22824 storage/flash_map: Use larger type for alignment
In MCUboot:
    commit 4aa286d2db2d02a8f0ff29cdc3304f3185dbe261
    Author: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
    Date:   Wed Nov 24 14:54:56 2021 -0300

        flash_map: Increase minimum supported write align via
            flash_area_align

MCUboot changed the type of the alignment value in flash from a uint8_t
to a uint32_t.  Indeed, Zephyr contains flash devices that have a larger
alignment than will fit in an 8-bit value.  This generally means that
`flash_area_align` will just return 0 on these platforms.

Change call in Zephyr as well.

This shouldn't cause any observable behavior changes in Zephyr, other
than making some cases that don't work currently begin to work.  If a
client is storing these results in a u8, it will be truncated, the same
as things were previously.  If, however, the caller is prepared to
handle a larger type, this will result in having correct information,
instead of the truncated value.

Signed-off-by: David Brown <david.brown@linaro.org>
2021-12-30 16:32:02 -05:00
Yong Cong Sin 113c6f249e storage/flash_map: Add option to use MBEDTLS for img integrity check.
Add option to use MBEDTLS library to perform the flash area
integrity check.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-11-24 21:52:08 -05:00
Dominik Ermel 5f0dff61be storage/flash_map: Separate layout and integrity functions
The commit separates conditionally compiled API calls to separate
C files and moves conditional compilation to CMakeLists.txt.
Inline helpers have been moved to flash_map_priv.h.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-10-21 17:18:44 -04:00
Dominik Ermel 51e8db228b storage/flash_map: Switch flash_area_layout to use flash_area_open
The function should use flash_area_open rather than directly
using get_flash_area_from_id.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-10-21 17:18:44 -04:00
Dominik Ermel f20cc4b7a4 storage/flash_map: Fix flash area bounds checking
The commit adds check if offset is positive; previously negative
offset would be allowed, which means that writing flash before flash
area start was possible.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2021-05-25 16:59:01 -05: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
Peter Bigot e571c88565 devicetree: flash-partitions: expose helper macros
Make generally available the macro that provides the flash device in
which a particular partition can be found.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-27 18:16:20 +01: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
Andrzej Puzdrowski 053857e09a storage/flash_map: Added function for get erased byte value
Added flash_area_erased_val() function for get value of erased
byte of memory which is under flash area.
This function already exist in MCUBoot and zephyr dfu subsystem
which makes simultaneous usage of both impossible.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2020-10-30 15:53:38 +01:00
Dominik Ermel b75616733b storage: flash_map: Unify partition processing macros name
Rename *_PART and *_PARTION identifiers to *_PARTITION.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-09-21 16:42:29 -05:00
Dominik Ermel 4e76da8ab1 storage: flash_map: Fix checking unsigned for negative value
The unsigned size_t type variables have been checked for having
negative values.

Fixes #28171, Coverity-CID: 214224

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-09-15 12:44:13 +02:00
Parthiban Nallathambi 4b6316da4e storage: flash_map: use const struct device
use const struct device in place to solve CI failure

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2020-09-03 14:28:22 -05:00
Gerson Fernando Budke eb0f571790 storage: flash_map: Add SHA-256 integrity method
Add SHA-256 flash integrity method.  It reads flash data from a
device giving an offset creating a SHA-256 hash to be compared
with a reference.  On sucess match, zero is returned, otherwise
a negative errno value.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
2020-09-03 17:56:02 +02: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
Jordan Yates 07fd28397e storage: flash_map: Fix partition device retrieval
Change the default behaviour of the flash partition choice when no
matching compatible is found. The new default is the grandparent node
of the fixed-partition.

As the grandparent node is what the jedec_spi_nor and nordic_qspi_nor
compatibles were selecting, remove these as separate checks.

This allows the flash_map API to be used for implementations of the
flash API other than the 3 originally specified (soc_nv_flash,
jedec_spi_nor & nordic_qspi_nor).

Fixes #26397

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2020-07-16 11:51:46 -05: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
Kumar Gala 7310eb9e4a storage: flash_map_default: Convert to new dts macros
Convert to use new DTS macros to populate default flash map

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-05-13 21:22:53 +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
Ulf Magnusson bd6e04411e kconfig: Clean up header comments and make them consistent
Use this short header style in all Kconfig files:

    # <description>

    # <copyright>
    # <license>

    ...

Also change all <description>s from

    # Kconfig[.extension] - Foo-related options

to just

    # Foo-related options

It's clear enough that it's about Kconfig.

The <description> cleanup was done with this command, along with some
manual cleanup (big letter at the start, etc.)

    git ls-files '*Kconfig*' | \
        xargs sed -i -E '1 s/#\s*Kconfig[\w.-]*\s*-\s*/# /'

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-11-04 17:31:27 -05:00