Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
flash_map.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017-2024 Nordic Semiconductor ASA
3 * Copyright (c) 2015 Runtime Inc
4 * Copyright (c) 2023 Sensorfy B.V.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
14#ifndef ZEPHYR_INCLUDE_STORAGE_FLASH_MAP_H_
15#define ZEPHYR_INCLUDE_STORAGE_FLASH_MAP_H_
16
27/*
28 * This API makes it possible to operate on flash areas easily and
29 * effectively.
30 *
31 * The system contains global data about flash areas. Every area
32 * contains an ID number, offset, and length.
33 */
34
38#include <zephyr/types.h>
39#include <stddef.h>
40#include <sys/types.h>
41#include <zephyr/device.h>
42#include <zephyr/devicetree.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
49#define SOC_FLASH_0_ID 0
51#define SPI_FLASH_0_ID 1
52
59struct flash_area {
66 size_t fa_size;
68 const struct device *fa_dev;
69#if CONFIG_FLASH_MAP_LABELS
71 const char *fa_label;
72#endif
73};
74
85 size_t fs_size;
86};
87
88#if defined(CONFIG_FLASH_AREA_CHECK_INTEGRITY)
95struct flash_area_check {
96 const uint8_t *match;
97 size_t clen;
98 size_t off;
99 uint8_t *rbuf;
100 size_t rblen;
101};
102
112int flash_area_check_int_sha256(const struct flash_area *fa,
113 const struct flash_area_check *fac);
114#endif
115
129int flash_area_open(uint8_t id, const struct flash_area **fa);
130
139void flash_area_close(const struct flash_area *fa);
140
155int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
156 size_t len);
157
172int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
173 size_t len);
174
188int flash_area_erase(const struct flash_area *fa, off_t off, size_t len);
189
201
214int flash_area_get_sectors(int fa_id, uint32_t *count,
215 struct flash_sector *sectors);
216
224typedef void (*flash_area_cb_t)(const struct flash_area *fa,
225 void *user_data);
226
233void flash_area_foreach(flash_area_cb_t user_cb, void *user_data);
234
243int flash_area_has_driver(const struct flash_area *fa);
244
252const struct device *flash_area_get_device(const struct flash_area *fa);
253
254#if CONFIG_FLASH_MAP_LABELS
262const char *flash_area_label(const struct flash_area *fa);
263#endif
264
275
276#if USE_PARTITION_MANAGER
277#include <flash_map_pm.h>
278#else
279
288#define FIXED_PARTITION_EXISTS(label) DT_FIXED_PARTITION_EXISTS(DT_NODELABEL(label))
289
297#define FIXED_PARTITION_ID(label) DT_FIXED_PARTITION_ID(DT_NODELABEL(label))
298
306#define FIXED_PARTITION_OFFSET(label) DT_REG_ADDR(DT_NODELABEL(label))
307
315#define FIXED_PARTITION_NODE_OFFSET(node) DT_REG_ADDR(node)
316
324#define FIXED_PARTITION_SIZE(label) DT_REG_SIZE(DT_NODELABEL(label))
325
333#define FIXED_PARTITION_NODE_SIZE(node) DT_REG_SIZE(node)
334
342#define FLASH_AREA_DEVICE(label) \
343 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODE_BY_FIXED_PARTITION_LABEL(label)))
344
352#define FIXED_PARTITION_DEVICE(label) \
353 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(DT_NODELABEL(label)))
354
362#define FIXED_PARTITION_NODE_DEVICE(node) \
363 DEVICE_DT_GET(DT_MTD_FROM_FIXED_PARTITION(node))
364
365#endif /* USE_PARTITION_MANAGER */
366
367#ifdef __cplusplus
368}
369#endif
370
375#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
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)
Get the value expected to be read when accessing any erased flash byte.
void flash_area_foreach(flash_area_cb_t user_cb, void *user_data)
Iterate over flash map.
int flash_area_has_driver(const struct flash_area *fa)
Check whether given flash area has supporting flash driver in the system.
int flash_area_get_sectors(int fa_id, uint32_t *count, struct flash_sector *sectors)
Retrieve info about sectors within the area.
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)
Flash map iteration callback.
Definition: flash_map.h:224
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)
Get driver for given flash area.
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:399
Flash partition.
Definition: flash_map.h:59
off_t fa_off
Start offset from the beginning of the flash device.
Definition: flash_map.h:64
size_t fa_size
Total size.
Definition: flash_map.h:66
const struct device * fa_dev
Backing flash device.
Definition: flash_map.h:68
uint8_t fa_id
ID number.
Definition: flash_map.h:61
uint16_t pad16
Definition: flash_map.h:62
Structure for transfer flash sector boundaries.
Definition: flash_map.h:81
off_t fs_off
Sector offset from the beginning of the flash device.
Definition: flash_map.h:83
size_t fs_size
Sector size in bytes.
Definition: flash_map.h:85