Zephyr Project API  3.3.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 {
63 size_t fa_size;
65 const struct device *fa_dev;
66};
67
78 size_t fs_size;
79};
80
81#if defined(CONFIG_FLASH_AREA_CHECK_INTEGRITY)
88struct flash_area_check {
89 const uint8_t *match;
90 size_t clen;
91 size_t off;
92 uint8_t *rbuf;
93 size_t rblen;
94};
95
105int flash_area_check_int_sha256(const struct flash_area *fa,
106 const struct flash_area_check *fac);
107#endif
108
122int flash_area_open(uint8_t id, const struct flash_area **fa);
123
132void flash_area_close(const struct flash_area *fa);
133
148int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
149 size_t len);
150
165int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
166 size_t len);
167
181int flash_area_erase(const struct flash_area *fa, off_t off, size_t len);
182
194
208 struct flash_sector *sectors);
209
217typedef void (*flash_area_cb_t)(const struct flash_area *fa,
218 void *user_data);
219
227
236int flash_area_has_driver(const struct flash_area *fa);
237
245const struct device *flash_area_get_device(const struct flash_area *fa);
246
257
258#define FLASH_AREA_LABEL_EXISTS(label) __DEPRECATED_MACRO \
259 DT_HAS_FIXED_PARTITION_LABEL(label)
260
261#define FLASH_AREA_LABEL_STR(lbl) __DEPRECATED_MACRO \
262 DT_PROP(DT_NODE_BY_FIXED_PARTITION_LABEL(lbl), label)
263
264#define FLASH_AREA_ID(label) __DEPRECATED_MACRO \
265 DT_FIXED_PARTITION_ID(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
266
267#define FLASH_AREA_OFFSET(label) __DEPRECATED_MACRO \
268 DT_REG_ADDR(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
269
270#define FLASH_AREA_SIZE(label) __DEPRECATED_MACRO \
271 DT_REG_SIZE(DT_NODE_BY_FIXED_PARTITION_LABEL(label))
272
281#define FIXED_PARTITION_EXISTS(label) DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label))
282
290#define FIXED_PARTITION_ID(label) DT_FIXED_PARTITION_ID(DT_NODELABEL(label))
291
299#define FIXED_PARTITION_OFFSET(label) DT_REG_ADDR(DT_NODELABEL(label))
300
308#define FIXED_PARTITION_SIZE(label) DT_REG_SIZE(DT_NODELABEL(label))
309
317#define FLASH_AREA_DEVICE(label) \
318 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODE_BY_FIXED_PARTITION_LABEL(label)))
319
327#define FIXED_PARTITION_DEVICE(label) \
328 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))
329
330#ifdef __cplusplus
331}
332#endif
333
338#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:217
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:378
Flash partition.
Definition: flash_map.h:56
off_t fa_off
Definition: flash_map.h:61
size_t fa_size
Definition: flash_map.h:63
const struct device * fa_dev
Definition: flash_map.h:65
uint8_t fa_id
Definition: flash_map.h:58
uint16_t pad16
Definition: flash_map.h:59
Structure for transfer flash sector boundaries.
Definition: flash_map.h:74
off_t fs_off
Definition: flash_map.h:76
size_t fs_size
Definition: flash_map.h:78
static const intptr_t user_data[5]
Definition: main.c:588