Browse Source

storage: flash_map: add flash_area_copy()

add flash_area_copy() function based on
flash_copy().

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
pull/88599/head
Fin Maaß 5 months ago committed by Benjamin Cabé
parent
commit
ddefc4222b
  1. 22
      include/zephyr/storage/flash_map.h
  2. 14
      subsys/storage/flash_map/flash_map.c

22
include/zephyr/storage/flash_map.h

@ -188,6 +188,28 @@ int flash_area_read(const struct flash_area *fa, off_t off, void *dst, @@ -188,6 +188,28 @@ int flash_area_read(const struct flash_area *fa, off_t off, void *dst,
int flash_area_write(const struct flash_area *fa, off_t off, const void *src,
size_t len);
/**
* @brief Copy flash memory from one flash area to another.
*
* Copy data to flash area. Area boundaries are asserted before copy
* request.
*
* For more information, see flash_copy().
*
* @param[in] src_fa Source Flash area
* @param[in] src_off Offset relative from beginning of source flash area.
* @param[in] dst_fa Destination Flash area
* @param[in] dst_off Offset relative from beginning of destination flash area.
* @param[in] len Number of bytes to copy, in bytes.
* @param[out] buf Pointer to a buffer of size @a buf_size.
* @param[in] buf_size Size of the buffer pointed to by @a buf.
*
* @return 0 on success, negative errno code on fail.
*/
int flash_area_copy(const struct flash_area *src_fa, off_t src_off,
const struct flash_area *dst_fa, off_t dst_off,
off_t len, uint8_t *buf, size_t buf_size);
/**
* @brief Erase flash area
*

14
subsys/storage/flash_map/flash_map.c

@ -82,6 +82,20 @@ int flash_area_erase(const struct flash_area *fa, off_t off, size_t len) @@ -82,6 +82,20 @@ int flash_area_erase(const struct flash_area *fa, off_t off, size_t len)
return flash_erase(fa->fa_dev, fa->fa_off + off, len);
}
int flash_area_copy(const struct flash_area *src_fa, off_t src_off,
const struct flash_area *dst_fa, off_t dst_off,
off_t len, uint8_t *buf, size_t buf_size)
{
if (!(is_in_flash_area_bounds(src_fa, src_off, len) &&
is_in_flash_area_bounds(dst_fa, dst_off, len))) {
return -EINVAL;
}
return flash_copy(src_fa->fa_dev, src_fa->fa_off + src_off,
dst_fa->fa_dev, dst_fa->fa_off + dst_off, len, buf,
buf_size);
}
int flash_area_flatten(const struct flash_area *fa, off_t off, size_t len)
{
if (!is_in_flash_area_bounds(fa, off, len)) {

Loading…
Cancel
Save