Commit graph

37 commits

Author SHA1 Message Date
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
Peter A. Bigot e3ba01ec76 subsys/storage/flash_map: detect missing flash device
If the flash device is not configured, return an error rather than
dereferencing a null device pointer.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-24 09:20:56 -04:00
Anas Nashif fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 83508a5677 cleanup: include/: move flash_map.h to storage/flash_map.h
move flash_map.h to storage/flash_map.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Radoslaw Koppel 3fd417a1c9 subsys/storage/flash_map: Fix returned error codes
Fix that removes magic numbers from the code that
leaded to the error codes that was hard to explain.

Signed-off-by: Radoslaw Koppel <radoslaw.koppel@nordicsemi.no>
2019-05-24 11:13:41 +02:00
Anas Nashif 5c6efa011a flash_map: add shell interface
Add shell for flash_map currently supporting listing the configurated
flash_map for a device.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-19 13:41:02 -05:00
Anas Nashif 1e5d02fcd2 flash_map: add function to iterate over areas
A new foreach iterator to go over all flash areas in a flash map.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-19 13:41:02 -05:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrzej Puzdrowski 3fe98838c9 storage/flash_map: API for get driver belongs to the flash_area.
Introduce API for get driver structure belongs to the flash_area.

Some more complex operation on flash areas might want to be done using
driver directly. It not make sense to wrap every possible flash related
operation by flash_map API.

For instance mcuboot will require this patch.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2019-03-19 17:11:52 +01:00
Marti Bolivar 8bf2a4c246 storage: flash_map: fix copyright assignment
Zephyr's flash_map code is largely copied wholesale from MCUboot, but
the copyrights were done incorrectly when the copy/pasting happened.

The current copyright holders are listed as Nordic and Runtime. This
is the patch which removed it from MCUboot; there is no copyright
holder explicitly named:

b788c71c08 (diff-e4c0c184210793513328934f14840a4c)

In fact, I was the author of a nontrivial portion of it, introduced
here:

dc4c42bf62 (diff-e4c0c184210793513328934f14840a4c)

At the time, I was working for Linaro, so add their copyright to the
copy of this file introduced into Zephyr.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2019-02-11 20:40:47 -06:00
Findlay Feng 69c15f0ed1 dts: flash_map: Automatically generate of the list of flash area
This Patch add functionality for automatic generation of the flash map
using DTS description. Automatic generation allows to replace
C-hardcoded flash_map.

We generate a set of defines based on the index of a partiion:
	#define DT_FLASH_AREA_<IDX>_OFFSET	0
	#define DT_FLASH_AREA_<IDX>_SIZE	131072
	#define DT_FLASH_AREA_<IDX>_DEV		"FLASH_CTRL"
	#define DT_FLASH_AREA_<IDX>_LABEL	MCUBOOT

Additionally we also define:
	#define DT_FLASH_AREA_NUM		4

and:
	#define DT_FLASH_AREA_<PARTNAME>_ID	0

Signed-off-by: Findlay Feng <i@fengch.me>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-07 10:31:27 -06:00
Anas Nashif 70e4c8346c flash_map: fix SPI_NOR DT label define
Label coming from DTS changed recently.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-04 08:00:30 -05:00
Rajavardhan Gundi 75f6f1b279 drivers: flash: spi_nor: Enable Flash Page Layout and Map
This patch enables the support for FLASH_PAGE_LAYOUT and
FLASH_MAP for the generic spin nor flash driver.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2019-01-16 21:22:56 -05:00
Patrik Flykt b97db52de7 misra-c: Add 'U' to unsigned variable assignments in subsys/
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Rajavardhan Gundi 4e8e0748e8 storage: flash_map: Make flash_map as extern
flash_map should be made extern in flash_map.c since it is defined
in flash_map_default.c. Not having flash_map as extern will result
in build errors.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-11-20 11:15:16 +01:00
Andrzej Głąbek 20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Andrzej Puzdrowski 5df93af87a subsys: storage: flash_map: add API for check flash driver support
Some applications might want to check whether flash_areas binds to
any flash drive in the system. It might be better to do that while
sanity check at application start-up then while regular run process.
Example of such application is the mcuboot.

This patch introduce such API for checking whether device bindings
were resolved properly during system startup.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-09-27 16:24:21 +02:00
Ulf Magnusson 1073882998 subsys: kconfig: Remove 'default n' properties and clean up a bit
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Remove some 'default ""' properties on string symbols too.

Also make definitions more consistent by converting some

  config FOO
  	<type>
  	prompt "foo"

definitions to a shorter form:

  config FOO
  	<type> "foo"

This shorthand works for int/hex/string symbols too, not just for bool
symbols.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-07-12 23:13:22 -04:00
Andrzej Puzdrowski 4954fe06f2 subsys: fs: fix generic storage partition selection
FS_FLASH_MAP_STORAGE keyword enables the storage partition,
but it was depend on flash_map module which is unused by
NFFS. This patch makes it independent thanks
to it is possible to enable the storage partition
without flash_map module.

FS_FLASH_MAP_STORAGE was renamed to
CONFIG_FS_FLASH_STORAGE_PARTITION
as it is independent for flash_map.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-05-04 10:14:01 -04:00
Johan Hedberg 9968cda453 fs: Convert NFFS partition to a generic one
The NFFS partition at the end of flash is also useful for any other
file system or even the Flash Circular Buffer (FCB). Rename the
partition from 'nffs_partition' to 'storage_partition' and make it
depend on a new hidden Kconfig entry which the relevant users will
select (such as NFFS and FCB).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2018-04-26 16:06:55 +05:30
Andrzej Puzdrowski 80a99fa450 subsys: storage: flash_map: enable only if any flash driver is enable
It was possible to have enable flash module while no flash driver
implementation was enabled. This cause coverity issues and unnecessary
initialization call.

This pat introduce FLASH_HAS_DRIVER_ENABLED Kconfig keyword which is
selected once any flash driver is enabled. flash_map switch its
dependency to this keyword.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-03-08 10:18:57 +01:00
Andrzej Puzdrowski 51527e07ef subsys: storage: flash_map: Fix Coverity issues
Loop counter was type of signed int while it was compared
to unsigned lvalue in loop condition.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-03-08 10:18:57 +01:00
Christopher Collins 821dc37f3f subsys: storage: flash_map: Fix warning
Prior to this commit, `flash_area_layout()` was being passed a pointer
to the incorrect type (`uint32_t *` where `int *` was expected).  This
caused the following warning to be reported:

```
[...]/subsys/storage/flash_map/flash_map.c: In
function 'flash_area_get_sectors':
[...]/subsys/storage/flash_map/flash_map.c:191:32:
warning: passing argument 2 of 'flash_area_layout' from incompatible
pointer type [-Wincompatible-pointer-types]
  return flash_area_layout(idx, cnt, ret, get_sectors_cb, &data);
                                ^~~
[...]/subsys/storage/flash_map/flash_map.c:136:12:
note: expected 'int *' but argument is of type 'uint32_t * {aka long
unsigned int *}'
 static int flash_area_layout(int idx, int *cnt, void *ret,
            ^~~~~~~~~~~~~~~~~
```

This commit changes the argument type to `u32_t` for both functions.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-14 14:36:52 -05:00
Christopher Collins aa8850b42a subsys: storage: flash_map - Use correct macro
Prior to this commit, the old `FLASH_DRIVER_NAME` macro was being used
in the definition of the flash drivers array.  This caused the array to
have a size of 0.

This commit changes the code to use the newer `FLASH_DEV_NAME` macro,
causing the configured flash device to be present in the table.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-08 23:29:23 -05:00
Christopher Collins ffc90dd496 subsys: storage: flash_map - Remove some code duplication
This patch cleans up flash_map code.

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Christopher Collins ffef30d39a storage: flash_map - Fix typo
get_flah_dev_from_id --> get_flash_dev_from_id

Signed-off-by: Christopher Collins <ccollins@apache.org>
2018-02-07 09:51:26 -05:00
Erwan Gouriou c734c2972f flash: remove obsolete FLASH_DRIVER_NAME
Replace seldom occurrences of FLASH_DRIVER_NAME by equivalent
and commonly used FLASH_DEV_NAME.

Fixes #5919.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-02-06 11:48:53 -06:00
Andrzej Puzdrowski f8a674b45e subsys: storage: flash_map: devices bindings fetch optimalization
Moved fetch of flash device bindings to early initialization of the
application.
Device bindings are constant while the application is running so
it is better to fetch it at startup, and not every time flash_map
procedures are called.


Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-01-15 15:46:37 -05:00
Andrzej Puzdrowski 25269fb0ed subsys: storage: Add flash_map abstraction module
Introduce flas_map module is abstraction over flash memory and its
driver for using flash memories along with description of
available flash areas.
Module provides simple API for write/read/erase and so one.

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
2018-01-15 15:46:37 -05:00