14#ifndef ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
15#define ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
81 bool no_explicit_erase: 1;
89#define FLASH_ERASE_C_EXPLICIT 0x01
93#define FLASH_ERASE_CAPS_UNSET (int)-1
96#define FLASH_ERASE_C_SUPPORTED 0x02
98#define FLASH_ERASE_C_VAL_BIT 0x04
100#define FLASH_ERASE_UNIFORM_PAGE 0x08
119#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
120#if defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
166 const void *
data,
size_t len);
184#if defined(CONFIG_FLASH_HAS_DRIVER_FILL)
204typedef int (*flash_api_fill)(
const struct device *dev,
uint8_t val,
205 off_t offset,
size_t size);
251 size_t *layout_size);
258 void *
data,
size_t len);
281#if defined(CONFIG_FLASH_HAS_DRIVER_FILL)
289#if defined(CONFIG_FLASH_PAGE_LAYOUT) || defined(__DOXYGEN__)
296#if defined(CONFIG_FLASH_JESD216_API) || defined(__DOXYGEN__)
308#if defined(CONFIG_FLASH_EX_OP_ENABLED) || defined(__DOXYGEN__)
340static inline int z_impl_flash_read(
const struct device *dev,
off_t offset,
369static inline int z_impl_flash_write(
const struct device *dev,
off_t offset,
370 const void *data,
size_t len)
405static inline int z_impl_flash_erase(
const struct device *dev,
off_t offset,
413 rc = api->
erase(dev, offset, size);
434static inline int z_impl_flash_get_size(
const struct device *dev,
uint64_t *size)
511#if defined(CONFIG_FLASH_PAGE_LAYOUT) || defined(__DOXYGEN__)
585#if defined(CONFIG_FLASH_JESD216_API) || defined(__DOXYGEN__)
604 void *data,
size_t len);
606static inline int z_impl_flash_sfdp_read(
const struct device *dev,
608 void *data,
size_t len)
614 rv = api->
sfdp_read(dev, offset, data, len);
633static inline int z_impl_flash_read_jedec_id(
const struct device *dev,
659static inline size_t z_impl_flash_get_write_block_size(
const struct device *dev)
661 return DEVICE_API_GET(flash, dev)->get_parameters(dev)->write_block_size;
757#define FLASH_EX_OP_VENDOR_BASE 0x8000
764#define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE)
803static inline int z_impl_flash_ex_op(
const struct device *dev,
uint16_t code,
806#if defined(CONFIG_FLASH_EX_OP_ENABLED)
813 return api->
ex_op(dev, code, in, out);
832#include <zephyr/syscalls/flash.h>
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1449
int flash_fill(const struct device *dev, uint8_t val, off_t offset, size_t size)
Fill selected range of device with specified value.
int flash_erase(const struct device *dev, off_t offset, size_t size)
Erase part or all of a flash memory.
const struct flash_parameters * flash_get_parameters(const struct device *dev)
Get pointer to flash_parameters structure.
int(* flash_api_read_jedec_id)(const struct device *dev, uint8_t *id)
Read the JEDEC ID of the device.
Definition flash.h:263
int flash_flatten(const struct device *dev, off_t offset, size_t size)
Erase part or all of a flash memory or level it.
int(* flash_api_erase)(const struct device *dev, off_t offset, size_t size)
Flash erase implementation handler type.
Definition flash.h:181
void flash_page_foreach(const struct device *dev, flash_page_cb cb, void *data)
Iterate over all flash pages on a device.
const struct flash_parameters *(* flash_api_get_parameters)(const struct device *dev)
Get device parameters.
Definition flash.h:226
int(* flash_api_read)(const struct device *dev, off_t offset, void *data, size_t len)
@def_driverbackendgroup{Flash,flash_interface}
Definition flash.h:154
bool(* flash_page_cb)(const struct flash_pages_info *info, void *data)
Callback type for iterating over flash pages present on a device.
Definition flash.h:565
int flash_get_size(const struct device *dev, uint64_t *size)
Get device size in bytes.
int flash_ex_op(const struct device *dev, uint16_t code, const uintptr_t in, void *out)
Execute flash extended operation on given device.
void(* flash_api_pages_layout)(const struct device *dev, const struct flash_pages_layout **layout, size_t *layout_size)
Retrieve a flash device's layout.
Definition flash.h:249
#define FLASH_ERASE_C_EXPLICIT
Set for ordinary Flash where erase is needed before write of random data.
Definition flash.h:89
int flash_write(const struct device *dev, off_t offset, const void *data, size_t len)
Write buffer into flash memory.
int flash_copy(const struct device *src_dev, off_t src_offset, const struct device *dst_dev, off_t dst_offset, off_t size, uint8_t *buf, size_t buf_size)
Copy flash memory from one device to another.
int flash_sfdp_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from Serial Flash Discoverable Parameters.
flash_block_status
Enumeration for flash block status.
Definition flash.h:791
int(* flash_api_get_size)(const struct device *dev, uint64_t *size)
Get device size in bytes.
Definition flash.h:218
int flash_read(const struct device *dev, off_t offset, void *data, size_t len)
Read data from flash.
size_t flash_get_write_block_size(const struct device *dev)
Get the minimum write block size supported by the driver.
int flash_get_page_info_by_idx(const struct device *dev, uint32_t page_index, struct flash_pages_info *info)
Get the size and start offset of flash page of certain index.
static int flash_params_get_erase_cap(const struct flash_parameters *p)
Parser for flash_parameters for retrieving erase capabilities.
Definition flash.h:117
int(* flash_api_sfdp_read)(const struct device *dev, off_t offset, void *data, size_t len)
Read data from Serial Flash Discoverable Parameters.
Definition flash.h:257
int(* flash_api_ex_op)(const struct device *dev, uint16_t code, const uintptr_t in, void *out)
Perform an extended operation.
Definition flash.h:268
int flash_read_jedec_id(const struct device *dev, uint8_t *id)
Read the JEDEC ID from a compatible flash device.
flash_ex_op_types
Enumeration for extra flash operations.
Definition flash.h:769
int(* flash_api_write)(const struct device *dev, off_t offset, const void *data, size_t len)
Flash write implementation handler type.
Definition flash.h:165
size_t flash_get_page_count(const struct device *dev)
Get the total number of flash pages.
int flash_get_page_info_by_offs(const struct device *dev, off_t offset, struct flash_pages_info *info)
Get the size and start offset of flash page at certain flash offset.
@ FLASH_BLOCK_GOOD
Block is functional.
Definition flash.h:795
@ FLASH_BLOCK_BAD
Block is marked as bad.
Definition flash.h:800
@ FLASH_EX_OP_MARK_BAD_BLOCK
Marks a block as bad.
Definition flash.h:785
@ FLASH_EX_OP_RESET
Reset flash device.
Definition flash.h:773
@ FLASH_EX_OP_IS_BAD_BLOCK
Checks whether a block is marked as bad.
Definition flash.h:779
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define ENOTSUP
Unsupported value.
Definition errno.h:115
#define NULL
Definition iar_missing_defs.h:20
__INTPTR_TYPE__ off_t
Definition types.h:36
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:105
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
@driver_ops{Flash}
Definition flash.h:274
flash_api_sfdp_read sfdp_read
@driver_ops_optional Read data from Serial Flash Discoverable Parameters.
Definition flash.h:301
flash_api_get_parameters get_parameters
@driver_ops_mandatory Get pointer to flash_parameters structure.
Definition flash.h:286
flash_api_pages_layout page_layout
@driver_ops_mandatory Retrieve a flash device's layout.
Definition flash.h:294
flash_api_ex_op ex_op
@driver_ops_optional Vendor-specific extended operations for flash drivers.
Definition flash.h:313
flash_api_read read
@driver_ops_mandatory Read data from flash.
Definition flash.h:276
flash_api_get_size get_size
@driver_ops_optional Get device size in bytes.
Definition flash.h:288
flash_api_write write
@driver_ops_mandatory Write buffer into flash memory.
Definition flash.h:278
flash_api_erase erase
@driver_ops_optional Erase part or all of a flash memory.
Definition flash.h:280
flash_api_read_jedec_id read_jedec_id
@driver_ops_optional Read the JEDEC ID from a compatible flash device.
Definition flash.h:306
Information about a flash page.
Definition flash.h:505
size_t size
Size of the page in bytes.
Definition flash.h:507
off_t start_offset
Offset of the page from the base of the flash address space.
Definition flash.h:506
uint32_t index
Index of the page, counted from 0.
Definition flash.h:508
Describes a sequence of flash pages of the same size.
Definition flash.h:38
size_t pages_size
Size of each page in the sequence, in bytes.
Definition flash.h:40
size_t pages_count
Number of pages of the same size in the sequence.
Definition flash.h:39
Flash memory parameters.
Definition flash.h:67
uint8_t erase_value
Value the device is filled in erased areas.
Definition flash.h:85
const size_t write_block_size
Minimal write alignment and size.
Definition flash.h:69