13#ifndef ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
14#define ZEPHYR_INCLUDE_DRIVERS_FLASH_H_
34#if defined(CONFIG_FLASH_PAGE_LAYOUT)
73 bool no_explicit_erase: 1;
81#define FLASH_ERASE_C_EXPLICIT 0x01
85#define FLASH_ERASE_CAPS_UNSET (int)-1
87#define FLASH_ERASE_C_SUPPORTED 0x02
88#define FLASH_ERASE_C_VAL_BIT 0x04
89#define FLASH_ERASE_UNIFORM_PAGE 0x08
108#if defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE)
109#if defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
140 const void *
data,
size_t len);
172#if defined(CONFIG_FLASH_PAGE_LAYOUT)
196 size_t *layout_size);
200 void *
data,
size_t len);
211#if defined(CONFIG_FLASH_PAGE_LAYOUT)
214#if defined(CONFIG_FLASH_JESD216_API)
218#if defined(CONFIG_FLASH_EX_OP_ENABLED)
248static inline int z_impl_flash_read(
const struct device *dev,
off_t offset,
255 return api->read(dev, offset, data, len);
280static inline int z_impl_flash_write(
const struct device *dev,
off_t offset,
281 const void *data,
size_t len)
287 rc = api->write(dev, offset, data, len);
322static inline int z_impl_flash_erase(
const struct device *dev,
off_t offset,
330 if (api->erase != NULL) {
331 rc = api->erase(dev, offset, size);
352static inline int z_impl_flash_get_size(
const struct device *dev,
uint64_t *size)
357 if (api->get_size != NULL) {
358 rc = api->get_size(dev, size);
426#if defined(CONFIG_FLASH_PAGE_LAYOUT)
490#if defined(CONFIG_FLASH_JESD216_API)
512 void *data,
size_t len);
514static inline int z_impl_flash_sfdp_read(
const struct device *dev,
516 void *data,
size_t len)
522 if (api->sfdp_read != NULL) {
523 rv = api->sfdp_read(dev, offset, data, len);
541static inline int z_impl_flash_read_jedec_id(
const struct device *dev,
548 if (api->read_jedec_id != NULL) {
549 rv = api->read_jedec_id(dev,
id);
568static inline size_t z_impl_flash_get_write_block_size(
const struct device *dev)
573 return api->get_parameters(dev)->write_block_size;
595 return api->get_parameters(dev);
670#define FLASH_EX_OP_VENDOR_BASE 0x8000
671#define FLASH_EX_OP_IS_VENDOR(c) ((c) & FLASH_EX_OP_VENDOR_BASE)
683static inline int z_impl_flash_ex_op(
const struct device *dev,
uint16_t code,
686#if defined(CONFIG_FLASH_EX_OP_ENABLED)
690 if (api->ex_op == NULL) {
694 return api->ex_op(dev, code, in, out);
713#include <zephyr/syscalls/flash.h>
Incorrect memory layout
Definition bindesc.h:314
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_flatten(const struct device *dev, off_t offset, size_t size)
Erase part or all of a flash memory or level it.
void flash_page_foreach(const struct device *dev, flash_page_cb cb, void *data)
Iterate over all flash pages on a device.
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:472
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.
#define FLASH_ERASE_C_EXPLICIT
Set for ordinary Flash where erase is needed before write of random data.
Definition flash.h:81
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.
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)
Definition flash.h:106
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:676
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_EX_OP_RESET
Definition flash.h:680
int(* flash_api_read_jedec_id)(const struct device *dev, uint8_t *id)
Definition flash.h:201
int(* flash_api_erase)(const struct device *dev, off_t offset, size_t size)
Flash erase implementation handler type.
Definition flash.h:155
const struct flash_parameters *(* flash_api_get_parameters)(const struct device *dev)
Definition flash.h:170
int(* flash_api_read)(const struct device *dev, off_t offset, void *data, size_t len)
Definition flash.h:128
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:194
int(* flash_api_get_size)(const struct device *dev, uint64_t *size)
Get device size in bytes.
Definition flash.h:168
int(* flash_api_sfdp_read)(const struct device *dev, off_t offset, void *data, size_t len)
Definition flash.h:199
int(* flash_api_ex_op)(const struct device *dev, uint16_t code, const uintptr_t in, void *out)
Definition flash.h:202
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:139
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define ENOTSUP
Unsupported value.
Definition errno.h:114
__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:411
void * data
Address of the device instance private data.
Definition device.h:421
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
flash_api_sfdp_read sfdp_read
Definition flash.h:215
flash_api_get_parameters get_parameters
Definition flash.h:209
flash_api_pages_layout page_layout
Definition flash.h:212
flash_api_read read
Definition flash.h:206
flash_api_get_size get_size
Definition flash.h:210
flash_api_write write
Definition flash.h:207
flash_api_erase erase
Definition flash.h:208
flash_api_read_jedec_id read_jedec_id
Definition flash.h:216
size_t size
Definition flash.h:422
off_t start_offset
Definition flash.h:421
uint32_t index
Definition flash.h:423
size_t pages_size
Definition flash.h:37
size_t pages_count
Definition flash.h:36
Flash memory parameters.
Definition flash.h:59
uint8_t erase_value
Value the device is filled in erased areas.
Definition flash.h:77
const size_t write_block_size
Minimal write alignment and size.
Definition flash.h:61