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>
This commit is contained in:
parent
969f8f1c68
commit
fe051a9055
50 changed files with 335 additions and 320 deletions
|
@ -10,7 +10,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <em_msc.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <soc.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_FLASH_LOG_LEVEL
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <syscall_handler.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
Z_SYSCALL_HANDLER(flash_read, dev, offset, data, len)
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
static int flash_get_page_info(struct device *dev, off_t offs,
|
||||
bool use_addr, struct flash_pages_info *info)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <kernel.h>
|
||||
#include <soc.h>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
LOG_MODULE_REGISTER(flash_sam0);
|
||||
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <kernel.h>
|
||||
#include <soc.h>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "flash.h"
|
||||
#include <drivers/flash.h>
|
||||
#include <soc.h>
|
||||
|
||||
#define FLASH_SHELL_MODULE "flash"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <kernel.h>
|
||||
#include <misc/util.h>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(LOG_DOMAIN);
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
#include <misc/__assert.h>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <errno.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <errno.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <device.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <string.h>
|
||||
#include <nrfx_nvmc.h>
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <device.h>
|
||||
#include <init.h>
|
||||
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <misc/util.h>
|
||||
#include "flash_priv.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <kernel.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <errno.h>
|
||||
#include <init.h>
|
||||
#include <soc.h>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <errno.h>
|
||||
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <spi.h>
|
||||
#include <init.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <spi.h>
|
||||
#include <init.h>
|
||||
#include <string.h>
|
||||
|
|
283
include/drivers/flash.h
Normal file
283
include/drivers/flash.h
Normal file
|
@ -0,0 +1,283 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for FLASH drivers
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
|
||||
#define ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
|
||||
|
||||
/**
|
||||
* @brief FLASH Interface
|
||||
* @defgroup flash_interface FLASH Interface
|
||||
* @ingroup io_interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
struct flash_pages_layout {
|
||||
size_t pages_count; /* count of pages sequence of the same size */
|
||||
size_t pages_size;
|
||||
};
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
typedef int (*flash_api_read)(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
typedef int (*flash_api_write)(struct device *dev, off_t offset,
|
||||
const void *data, size_t len);
|
||||
typedef int (*flash_api_erase)(struct device *dev, off_t offset, size_t size);
|
||||
typedef int (*flash_api_write_protection)(struct device *dev, bool enable);
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
/**
|
||||
* @brief Retrieve a flash device's layout.
|
||||
*
|
||||
* A flash device layout is a run-length encoded description of the
|
||||
* pages on the device. (Here, "page" means the smallest erasable
|
||||
* area on the flash device.)
|
||||
*
|
||||
* For flash memories which have uniform page sizes, this routine
|
||||
* returns an array of length 1, which specifies the page size and
|
||||
* number of pages in the memory.
|
||||
*
|
||||
* Layouts for flash memories with nonuniform page sizes will be
|
||||
* returned as an array with multiple elements, each of which
|
||||
* describes a group of pages that all have the same size. In this
|
||||
* case, the sequence of array elements specifies the order in which
|
||||
* these groups occur on the device.
|
||||
*
|
||||
* @param dev Flash device whose layout to retrieve.
|
||||
* @param layout The flash layout will be returned in this argument.
|
||||
* @param layout_size The number of elements in the returned layout.
|
||||
*/
|
||||
typedef void (*flash_api_pages_layout)(struct device *dev,
|
||||
const struct flash_pages_layout **layout,
|
||||
size_t *layout_size);
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
struct flash_driver_api {
|
||||
flash_api_read read;
|
||||
flash_api_write write;
|
||||
flash_api_erase erase;
|
||||
flash_api_write_protection write_protection;
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
flash_api_pages_layout page_layout;
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
const size_t write_block_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read data from flash
|
||||
*
|
||||
* @param dev : flash dev
|
||||
* @param offset : Offset (byte aligned) to read
|
||||
* @param data : Buffer to store read data
|
||||
* @param len : Number of bytes to read.
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_flash_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->read(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write buffer into flash memory.
|
||||
*
|
||||
* Prior to the invocation of this API, the flash_write_protection_set needs
|
||||
* to be called first to disable the write protection.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : starting offset for the write
|
||||
* @param data : data to write
|
||||
* @param len : Number of bytes to write
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_write(struct device *dev, off_t offset, const void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_flash_write(struct device *dev, off_t offset,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase part or all of a flash memory
|
||||
*
|
||||
* Acceptable values of erase size and offset are subject to
|
||||
* hardware-specific multiples of page size and offset. Please check
|
||||
* the API implemented by the underlying sub driver, for example by
|
||||
* using flash_get_page_info_by_offs() if that is supported by your
|
||||
* flash driver.
|
||||
*
|
||||
* Prior to the invocation of this API, the flash_write_protection_set needs
|
||||
* to be called first to disable the write protection.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : erase area starting offset
|
||||
* @param size : size of area to be erased
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*
|
||||
* @see flash_get_page_info_by_offs()
|
||||
* @see flash_get_page_info_by_idx()
|
||||
*/
|
||||
__syscall int flash_erase(struct device *dev, off_t offset, size_t size);
|
||||
|
||||
static inline int z_impl_flash_erase(struct device *dev, off_t offset,
|
||||
size_t size)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->erase(dev, offset, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable write protection for a flash memory
|
||||
*
|
||||
* This API is required to be called before the invocation of write or erase
|
||||
* API. Please note that on some flash components, the write protection is
|
||||
* automatically turned on again by the device after the completion of each
|
||||
* write or erase calls. Therefore, on those flash parts, write protection needs
|
||||
* to be disabled before each invocation of the write or erase API. Please refer
|
||||
* to the sub-driver API or the data sheet of the flash component to get details
|
||||
* on the write protection behavior.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param enable : enable or disable flash write protection
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_write_protection_set(struct device *dev, bool enable);
|
||||
|
||||
static inline int z_impl_flash_write_protection_set(struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write_protection(dev, enable);
|
||||
}
|
||||
|
||||
struct flash_pages_info {
|
||||
off_t start_offset; /* offset from the base of flash address */
|
||||
size_t size;
|
||||
u32_t index;
|
||||
};
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
/**
|
||||
* @brief Get the size and start offset of flash page at certain flash offset.
|
||||
*
|
||||
* @param dev flash device
|
||||
* @param offset Offset within the page
|
||||
* @param info Page Info structure to be filled
|
||||
*
|
||||
* @return 0 on success, -EINVAL if page of the offset doesn't exist.
|
||||
*/
|
||||
__syscall int flash_get_page_info_by_offs(struct device *dev, off_t offset,
|
||||
struct flash_pages_info *info);
|
||||
|
||||
/**
|
||||
* @brief Get the size and start offset of flash page of certain index.
|
||||
*
|
||||
* @param dev flash device
|
||||
* @param page_index Index of the page. Index are counted from 0.
|
||||
* @param info Page Info structure to be filled
|
||||
*
|
||||
* @return 0 on success, -EINVAL if page of the index doesn't exist.
|
||||
*/
|
||||
__syscall int flash_get_page_info_by_idx(struct device *dev, u32_t page_index,
|
||||
struct flash_pages_info *info);
|
||||
|
||||
/**
|
||||
* @brief Get the total number of flash pages.
|
||||
*
|
||||
* @param dev flash device
|
||||
*
|
||||
* @return Number of flash pages.
|
||||
*/
|
||||
__syscall size_t flash_get_page_count(struct device *dev);
|
||||
|
||||
/**
|
||||
* @brief Callback type for iterating over flash pages present on a device.
|
||||
*
|
||||
* The callback should return true to continue iterating, and false to halt.
|
||||
*
|
||||
* @param info Information for current page
|
||||
* @param data Private data for callback
|
||||
* @return True to continue iteration, false to halt iteration.
|
||||
* @see flash_page_foreach()
|
||||
*/
|
||||
typedef bool (*flash_page_cb)(const struct flash_pages_info *info, void *data);
|
||||
|
||||
/**
|
||||
* @brief Iterate over all flash pages on a device
|
||||
*
|
||||
* This routine iterates over all flash pages on the given device,
|
||||
* ordered by increasing start offset. For each page, it invokes the
|
||||
* given callback, passing it the page's information and a private
|
||||
* data object.
|
||||
*
|
||||
* @param dev Device whose pages to iterate over
|
||||
* @param cb Callback to invoke for each flash page
|
||||
* @param data Private data for callback function
|
||||
*/
|
||||
void flash_page_foreach(struct device *dev, flash_page_cb cb, void *data);
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
/**
|
||||
* @brief Get the minimum write block size supported by the driver
|
||||
*
|
||||
* The write block size supported by the driver might differ from the write
|
||||
* block size of memory used because the driver might implements write-modify
|
||||
* algorithm.
|
||||
*
|
||||
* @param dev flash device
|
||||
*
|
||||
* @return write block size in bytes.
|
||||
*/
|
||||
__syscall size_t flash_get_write_block_size(struct device *dev);
|
||||
|
||||
static inline size_t z_impl_flash_get_write_block_size(struct device *dev)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write_block_size;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <syscalls/flash.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_DRIVERS_FLASH_H_ */
|
276
include/flash.h
276
include/flash.h
|
@ -1,283 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2017 Nordic Semiconductor ASA
|
||||
* Copyright (c) 2016 Intel Corporation
|
||||
* Copyright (c) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Public API for FLASH drivers
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_INCLUDE_FLASH_H_
|
||||
#define ZEPHYR_INCLUDE_FLASH_H_
|
||||
|
||||
/**
|
||||
* @brief FLASH Interface
|
||||
* @defgroup flash_interface FLASH Interface
|
||||
* @ingroup io_interfaces
|
||||
* @{
|
||||
*/
|
||||
|
||||
#include <zephyr/types.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
#include <device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#ifndef CONFIG_COMPAT_INCLUDES
|
||||
#warning "This header file has moved, include <drivers/flash.h> instead."
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
struct flash_pages_layout {
|
||||
size_t pages_count; /* count of pages sequence of the same size */
|
||||
size_t pages_size;
|
||||
};
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
typedef int (*flash_api_read)(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
typedef int (*flash_api_write)(struct device *dev, off_t offset,
|
||||
const void *data, size_t len);
|
||||
typedef int (*flash_api_erase)(struct device *dev, off_t offset, size_t size);
|
||||
typedef int (*flash_api_write_protection)(struct device *dev, bool enable);
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
/**
|
||||
* @brief Retrieve a flash device's layout.
|
||||
*
|
||||
* A flash device layout is a run-length encoded description of the
|
||||
* pages on the device. (Here, "page" means the smallest erasable
|
||||
* area on the flash device.)
|
||||
*
|
||||
* For flash memories which have uniform page sizes, this routine
|
||||
* returns an array of length 1, which specifies the page size and
|
||||
* number of pages in the memory.
|
||||
*
|
||||
* Layouts for flash memories with nonuniform page sizes will be
|
||||
* returned as an array with multiple elements, each of which
|
||||
* describes a group of pages that all have the same size. In this
|
||||
* case, the sequence of array elements specifies the order in which
|
||||
* these groups occur on the device.
|
||||
*
|
||||
* @param dev Flash device whose layout to retrieve.
|
||||
* @param layout The flash layout will be returned in this argument.
|
||||
* @param layout_size The number of elements in the returned layout.
|
||||
*/
|
||||
typedef void (*flash_api_pages_layout)(struct device *dev,
|
||||
const struct flash_pages_layout **layout,
|
||||
size_t *layout_size);
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
struct flash_driver_api {
|
||||
flash_api_read read;
|
||||
flash_api_write write;
|
||||
flash_api_erase erase;
|
||||
flash_api_write_protection write_protection;
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
flash_api_pages_layout page_layout;
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
const size_t write_block_size;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Read data from flash
|
||||
*
|
||||
* @param dev : flash dev
|
||||
* @param offset : Offset (byte aligned) to read
|
||||
* @param data : Buffer to store read data
|
||||
* @param len : Number of bytes to read.
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_flash_read(struct device *dev, off_t offset, void *data,
|
||||
size_t len)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->read(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write buffer into flash memory.
|
||||
*
|
||||
* Prior to the invocation of this API, the flash_write_protection_set needs
|
||||
* to be called first to disable the write protection.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : starting offset for the write
|
||||
* @param data : data to write
|
||||
* @param len : Number of bytes to write
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_write(struct device *dev, off_t offset, const void *data,
|
||||
size_t len);
|
||||
|
||||
static inline int z_impl_flash_write(struct device *dev, off_t offset,
|
||||
const void *data, size_t len)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write(dev, offset, data, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Erase part or all of a flash memory
|
||||
*
|
||||
* Acceptable values of erase size and offset are subject to
|
||||
* hardware-specific multiples of page size and offset. Please check
|
||||
* the API implemented by the underlying sub driver, for example by
|
||||
* using flash_get_page_info_by_offs() if that is supported by your
|
||||
* flash driver.
|
||||
*
|
||||
* Prior to the invocation of this API, the flash_write_protection_set needs
|
||||
* to be called first to disable the write protection.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param offset : erase area starting offset
|
||||
* @param size : size of area to be erased
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*
|
||||
* @see flash_get_page_info_by_offs()
|
||||
* @see flash_get_page_info_by_idx()
|
||||
*/
|
||||
__syscall int flash_erase(struct device *dev, off_t offset, size_t size);
|
||||
|
||||
static inline int z_impl_flash_erase(struct device *dev, off_t offset,
|
||||
size_t size)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->erase(dev, offset, size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable write protection for a flash memory
|
||||
*
|
||||
* This API is required to be called before the invocation of write or erase
|
||||
* API. Please note that on some flash components, the write protection is
|
||||
* automatically turned on again by the device after the completion of each
|
||||
* write or erase calls. Therefore, on those flash parts, write protection needs
|
||||
* to be disabled before each invocation of the write or erase API. Please refer
|
||||
* to the sub-driver API or the data sheet of the flash component to get details
|
||||
* on the write protection behavior.
|
||||
*
|
||||
* @param dev : flash device
|
||||
* @param enable : enable or disable flash write protection
|
||||
*
|
||||
* @return 0 on success, negative errno code on fail.
|
||||
*/
|
||||
__syscall int flash_write_protection_set(struct device *dev, bool enable);
|
||||
|
||||
static inline int z_impl_flash_write_protection_set(struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write_protection(dev, enable);
|
||||
}
|
||||
|
||||
struct flash_pages_info {
|
||||
off_t start_offset; /* offset from the base of flash address */
|
||||
size_t size;
|
||||
u32_t index;
|
||||
};
|
||||
|
||||
#if defined(CONFIG_FLASH_PAGE_LAYOUT)
|
||||
/**
|
||||
* @brief Get the size and start offset of flash page at certain flash offset.
|
||||
*
|
||||
* @param dev flash device
|
||||
* @param offset Offset within the page
|
||||
* @param info Page Info structure to be filled
|
||||
*
|
||||
* @return 0 on success, -EINVAL if page of the offset doesn't exist.
|
||||
*/
|
||||
__syscall int flash_get_page_info_by_offs(struct device *dev, off_t offset,
|
||||
struct flash_pages_info *info);
|
||||
|
||||
/**
|
||||
* @brief Get the size and start offset of flash page of certain index.
|
||||
*
|
||||
* @param dev flash device
|
||||
* @param page_index Index of the page. Index are counted from 0.
|
||||
* @param info Page Info structure to be filled
|
||||
*
|
||||
* @return 0 on success, -EINVAL if page of the index doesn't exist.
|
||||
*/
|
||||
__syscall int flash_get_page_info_by_idx(struct device *dev, u32_t page_index,
|
||||
struct flash_pages_info *info);
|
||||
|
||||
/**
|
||||
* @brief Get the total number of flash pages.
|
||||
*
|
||||
* @param dev flash device
|
||||
*
|
||||
* @return Number of flash pages.
|
||||
*/
|
||||
__syscall size_t flash_get_page_count(struct device *dev);
|
||||
|
||||
/**
|
||||
* @brief Callback type for iterating over flash pages present on a device.
|
||||
*
|
||||
* The callback should return true to continue iterating, and false to halt.
|
||||
*
|
||||
* @param info Information for current page
|
||||
* @param data Private data for callback
|
||||
* @return True to continue iteration, false to halt iteration.
|
||||
* @see flash_page_foreach()
|
||||
*/
|
||||
typedef bool (*flash_page_cb)(const struct flash_pages_info *info, void *data);
|
||||
|
||||
/**
|
||||
* @brief Iterate over all flash pages on a device
|
||||
*
|
||||
* This routine iterates over all flash pages on the given device,
|
||||
* ordered by increasing start offset. For each page, it invokes the
|
||||
* given callback, passing it the page's information and a private
|
||||
* data object.
|
||||
*
|
||||
* @param dev Device whose pages to iterate over
|
||||
* @param cb Callback to invoke for each flash page
|
||||
* @param data Private data for callback function
|
||||
*/
|
||||
void flash_page_foreach(struct device *dev, flash_page_cb cb, void *data);
|
||||
#endif /* CONFIG_FLASH_PAGE_LAYOUT */
|
||||
|
||||
/**
|
||||
* @brief Get the minimum write block size supported by the driver
|
||||
*
|
||||
* The write block size supported by the driver might differ from the write
|
||||
* block size of memory used because the driver might implements write-modify
|
||||
* algorithm.
|
||||
*
|
||||
* @param dev flash device
|
||||
*
|
||||
* @return write block size in bytes.
|
||||
*/
|
||||
__syscall size_t flash_get_write_block_size(struct device *dev);
|
||||
|
||||
static inline size_t z_impl_flash_get_write_block_size(struct device *dev)
|
||||
{
|
||||
const struct flash_driver_api *api = dev->driver_api;
|
||||
|
||||
return api->write_block_size;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <syscalls/flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_FLASH_H_ */
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <shell/shell.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <dfu/mcuboot.h>
|
||||
#include <dfu/flash_img.h>
|
||||
#include <updatehub.h>
|
||||
|
|
|
@ -17,7 +17,7 @@ LOG_MODULE_REGISTER(updatehub);
|
|||
#include <net/udp.h>
|
||||
#include <net/coap.h>
|
||||
#include <net/dns_resolve.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <misc/reboot.h>
|
||||
#include <tinycrypt/sha256.h>
|
||||
#include <data/json.h>
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#ifndef __UPDATEHUB_FIRMWARE_H__
|
||||
#define __UPDATEHUB_FIRMWARE_H__
|
||||
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <dfu/mcuboot.h>
|
||||
#include <dfu/flash_img.h>
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <gpio.h>
|
||||
#include <display/cfb.h>
|
||||
#include <misc/printk.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <sensor.h>
|
||||
|
||||
#include <string.h>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <logging/log.h>
|
||||
#include <shell/shell.h>
|
||||
#include <shell/shell_uart.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <device.h>
|
||||
#include <soc.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <device.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <device.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <shell/shell.h>
|
||||
|
||||
#define PR_SHELL(shell, fmt, ...) \
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include <misc/reboot.h>
|
||||
#include <device.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <fs/nvs.h>
|
||||
|
||||
static struct nvs_fs fs;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <storage/flash_map.h>
|
||||
#include <zephyr.h>
|
||||
#include <init.h>
|
||||
|
|
|
@ -20,7 +20,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
|||
|
||||
#ifdef CONFIG_IMG_ERASE_PROGRESSIVELY
|
||||
#include <dfu/mcuboot.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#endif
|
||||
|
||||
#include <generated_dts_board.h>
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <errno.h>
|
||||
#include <init.h>
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
#define SECTOR_SIZE 512
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <zephyr/types.h>
|
||||
#include <errno.h>
|
||||
#include <init.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <fs/fs.h>
|
||||
#include <sys/crc.h>
|
||||
#include <misc/__assert.h>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <kernel.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
|
||||
#include "platform-zephyr.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <device.h>
|
||||
#include <storage/flash_map.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <soc.h>
|
||||
#include <init.h>
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
#include <kernel.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <storage/flash_map.h>
|
||||
#include <dfu/mcuboot.h>
|
||||
#include <dfu/flash_img.h>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <zephyr.h>
|
||||
#include <kernel.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <device.h>
|
||||
#include <ztest.h>
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <storage/flash_map.h>
|
||||
#include <device.h>
|
||||
#include <stdio.h>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <device.h>
|
||||
|
||||
/* configuration derived from DT */
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <nffs/queue.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <ztest_assert.h>
|
||||
#include "nffs_test_utils.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <nffs/queue.h>
|
||||
#include <nffs/nffs.h>
|
||||
#include <nffs/os.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <ztest_assert.h>
|
||||
#include "nffs_test_utils.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <device.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <ztest_assert.h>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <string.h>
|
||||
#include <ztest.h>
|
||||
|
||||
#include "flash.h"
|
||||
#include <drivers/flash.h>
|
||||
#include <storage/flash_map.h>
|
||||
#include <stats/stats.h>
|
||||
#include <fs/nvs.h>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <ztest.h>
|
||||
#include <flash.h>
|
||||
#include <drivers/flash.h>
|
||||
#include <storage/flash_map.h>
|
||||
|
||||
extern int flash_map_entries;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue