Skip to content

Commit ddefc42

Browse files
maass-hamburgkartben
authored andcommitted
storage: flash_map: add flash_area_copy()
add flash_area_copy() function based on flash_copy(). Signed-off-by: Fin Maaß <[email protected]>
1 parent 77bdc8a commit ddefc42

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/zephyr/storage/flash_map.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,28 @@ int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
188188
int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
189189
size_t len);
190190

191+
/**
192+
* @brief Copy flash memory from one flash area to another.
193+
*
194+
* Copy data to flash area. Area boundaries are asserted before copy
195+
* request.
196+
*
197+
* For more information, see flash_copy().
198+
*
199+
* @param[in] src_fa Source Flash area
200+
* @param[in] src_off Offset relative from beginning of source flash area.
201+
* @param[in] dst_fa Destination Flash area
202+
* @param[in] dst_off Offset relative from beginning of destination flash area.
203+
* @param[in] len Number of bytes to copy, in bytes.
204+
* @param[out] buf Pointer to a buffer of size @a buf_size.
205+
* @param[in] buf_size Size of the buffer pointed to by @a buf.
206+
*
207+
* @return 0 on success, negative errno code on fail.
208+
*/
209+
int flash_area_copy(const struct flash_area *src_fa, off_t src_off,
210+
const struct flash_area *dst_fa, off_t dst_off,
211+
off_t len, uint8_t *buf, size_t buf_size);
212+
191213
/**
192214
* @brief Erase flash area
193215
*

subsys/storage/flash_map/flash_map.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ int flash_area_erase(const struct flash_area *fa, off_t off, size_t len)
8282
return flash_erase(fa->fa_dev, fa->fa_off + off, len);
8383
}
8484

85+
int flash_area_copy(const struct flash_area *src_fa, off_t src_off,
86+
const struct flash_area *dst_fa, off_t dst_off,
87+
off_t len, uint8_t *buf, size_t buf_size)
88+
{
89+
if (!(is_in_flash_area_bounds(src_fa, src_off, len) &&
90+
is_in_flash_area_bounds(dst_fa, dst_off, len))) {
91+
return -EINVAL;
92+
}
93+
94+
return flash_copy(src_fa->fa_dev, src_fa->fa_off + src_off,
95+
dst_fa->fa_dev, dst_fa->fa_off + dst_off, len, buf,
96+
buf_size);
97+
}
98+
8599
int flash_area_flatten(const struct flash_area *fa, off_t off, size_t len)
86100
{
87101
if (!is_in_flash_area_bounds(fa, off, len)) {

0 commit comments

Comments
 (0)