Zephyr Project API  3.2.0
A Scalable Open Source RTOS
flash_map.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13#ifndef ZEPHYR_INCLUDE_STORAGE_FLASH_MAP_H_
14#define ZEPHYR_INCLUDE_STORAGE_FLASH_MAP_H_
15
24/*
25 * This API makes it possible to operate on flash areas easily and
26 * effectively.
27 *
28 * The system contains global data about flash areas. Every area
29 * contains an ID number, offset, and length.
30 */
31
35#include <zephyr/types.h>
36#include <stddef.h>
37#include <sys/types.h>
38#include <zephyr/device.h>
39#include <zephyr/devicetree.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
46#define SOC_FLASH_0_ID 0
48#define SPI_FLASH_0_ID 1
49
56struct flash_area {
65 size_t fa_size;
67 const struct device *fa_dev;
68};
69
80 size_t fs_size;
81};
82
83#if defined(CONFIG_FLASH_AREA_CHECK_INTEGRITY)
90struct flash_area_check {
91 const uint8_t *match;
92 size_t clen;
93 size_t off;
94 uint8_t *rbuf;
95 size_t rblen;
96};
97
107int flash_area_check_int_sha256(const struct flash_area *fa,
108 const struct flash_area_check *fac);
109#endif
110
124int flash_area_open(uint8_t id, const struct flash_area **fa);
125
134void flash_area_close(const struct flash_area *fa);
135
150int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
151 size_t len);
152
167int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
168 size_t len);
169
183int flash_area_erase(const struct flash_area *fa, off_t off, size_t len);
184
196
210 struct flash_sector *sectors);
211
219typedef void (*flash_area_cb_t)(const struct flash_area *fa,
220 void *user_data);
221
229
238int flash_area_has_driver(const struct flash_area *fa);
239
247const struct device *flash_area_get_device(const struct flash_area *fa);
248
259
260#define FLASH_AREA_LABEL_EXISTS(label) __DEPRECATED_MACRO \
261 DT_HAS_FIXED_PARTITION_LABEL(label)
262
263#define FLASH_AREA_LABEL_STR(lbl) __DEPRECATED_MACRO \
264 DT_PROP(DT_NODE_BY_FIXED_PARTITION_LABEL(lbl), label)
265
266#define FLASH_AREA_ID(label) __DEPRECATED_MACRO \
267 DT_FIXED_PARTITION_ID(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
268
269#define FLASH_AREA_OFFSET(label) __DEPRECATED_MACRO \
270 DT_REG_ADDR(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
271
272#define FLASH_AREA_SIZE(label) __DEPRECATED_MACRO \
273 DT_REG_SIZE(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
274
283#define FIXED_PARTITION_EXISTS(label) DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label))
284
292#define FIXED_PARTITION_ID(label) DT_FIXED_PARTITION_ID(DT_NODELABEL(label))
293
301#define FIXED_PARTITION_OFFSET(label) DT_REG_ADDR(DT_NODELABEL(label))
302
310#define FIXED_PARTITION_SIZE(label) DT_REG_SIZE(DT_NODELABEL(label))
311
319#define FLASH_AREA_DEVICE(label) \
320 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODE_BY_FIXED_PARTITION_LABEL(label)))
321
329#define FIXED_PARTITION_DEVICE(label) \
330 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))
331
332#ifdef __cplusplus
333}
334#endif
335
340#endif /* ZEPHYR_INCLUDE_STORAGE_FLASH_MAP_H_ */
irp nz macro MOVR cc s mov cc s endm endr irp aw macro LDR aa off
Definition: asm-macro-32-bit-gnu.h:17
ZTEST_BMEM int count
Definition: main.c:33
Devicetree main header.
uint32_t flash_area_align(const struct flash_area *fa)
Get write block size of the flash area.
uint8_t flash_area_erased_val(const struct flash_area *fa)
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data)
int flash_area_has_driver(const struct flash_area *fa)
int flash_area_get_sectors(int fa_id, uint32_t *count, struct flash_sector *sectors)
int flash_area_open(uint8_t id, const struct flash_area **fa)
Retrieve partitions flash area from the flash_map.
int flash_area_read(const struct flash_area *fa, off_t off, void *dst, size_t len)
Read flash area data.
int flash_area_write(const struct flash_area *fa, off_t off, const void *src, size_t len)
Write data to flash area.
void(* flash_area_cb_t)(const struct flash_area *fa, void *user_data)
Definition: flash_map.h:219
int flash_area_erase(const struct flash_area *fa, off_t off, size_t len)
Erase flash area.
const struct device * flash_area_get_device(const struct flash_area *fa)
void flash_area_close(const struct flash_area *fa)
Close flash_area.
__INTPTR_TYPE__ off_t
Definition: types.h:36
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:435
Flash partition.
Definition: flash_map.h:56
off_t fa_off
Definition: flash_map.h:63
uint8_t fa_device_id
Definition: flash_map.h:60
size_t fa_size
Definition: flash_map.h:65
const struct device * fa_dev
Definition: flash_map.h:67
uint8_t fa_id
Definition: flash_map.h:58
uint16_t pad16
Definition: flash_map.h:61
Structure for transfer flash sector boundaries.
Definition: flash_map.h:76
off_t fs_off
Definition: flash_map.h:78
size_t fs_size
Definition: flash_map.h:80
static const intptr_t user_data[5]
Definition: main.c:588