flash: change prototype of flash_copy() and use the default implementation in the sandbox

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent d21b5addff
commit c38413dc90
  1. 4
      include/flash.h
  2. 4
      source/core/flash.c
  3. 27
      source/drivers/sandbox_flash.c
  4. 2
      source/ftl/ftl.c
  5. 2
      source/ftl/gc.c

@ -12,7 +12,7 @@ struct flash_ops {
size_t (* read)(struct flash_dev *dev, uint32_t addr, void *data, size_t len);
size_t (* write)(struct flash_dev *dev, uint32_t addr, const void *data,
size_t len);
int (* copy)(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len);
size_t (* copy)(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len);
int (* is_erased)(struct flash_dev *dev, uint32_t addr);
int (* erase)(struct flash_dev *dev, uint32_t addr);
};
@ -34,6 +34,6 @@ size_t flash_get_capacity(struct flash_dev *dev);
size_t flash_read(struct flash_dev *dev, uint32_t addr, void *data, size_t len);
size_t flash_write(struct flash_dev *dev, uint32_t addr, const void *data,
size_t len);
int flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len);
size_t flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len);
int flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len);
int flash_erase(struct flash_dev *dev, uint32_t addr, size_t len);

@ -96,10 +96,10 @@ size_t flash_write(struct flash_dev *dev, uint32_t addr, const void *data,
return dev->ops->write(dev, addr, data, len);
}
int flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len)
size_t flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len)
{
if (!dev)
return -1;
return 0;
return dev->ops->copy(dev, dst, src, len);
}

@ -23,8 +23,6 @@ static size_t stdio_flash_read(struct flash_dev *dev, uint32_t addr, void *data,
size_t len);
static size_t stdio_flash_write(struct flash_dev *dev, uint32_t addr,
const void *data, size_t len);
static int stdio_flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src,
size_t len);
static int stdio_flash_erase(struct flash_dev *dev, uint32_t addr);
static void stdio_flash_release(struct flash_dev *dev);
@ -33,7 +31,7 @@ static struct flash_ops stdio_flash_ops = {
.get_size = stdio_flash_get_size,
.read = stdio_flash_read,
.write = stdio_flash_write,
.copy = stdio_flash_copy,
.copy = default_flash_copy,
.is_erased = default_flash_is_erased,
.erase = stdio_flash_erase,
};
@ -85,29 +83,6 @@ static size_t stdio_flash_write(struct flash_dev *dev, uint32_t addr,
return len;
}
static int stdio_flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src,
size_t len)
{
uint8_t data[64];
size_t nbytes;
while (len) {
nbytes = min(sizeof data, len);
if (stdio_flash_read(dev, src, data, nbytes) == 0)
return -1;
if (stdio_flash_write(dev, dst, data, nbytes) == 0)
return -1;
dst += nbytes;
src += nbytes;
len -= nbytes;
}
return 0;
}
static int stdio_flash_erase(struct flash_dev *dev, uint32_t addr)
{
struct stdio_flash_priv *priv = dev->priv;

@ -122,7 +122,7 @@ int ftl_trim(struct ftl_map *map, uint32_t va)
}
if (flash_copy(map->dev, map->head << map->log2_page_size,
alt_page << map->log2_page_size, 1 << map->log2_page_size) < 0)
alt_page << map->log2_page_size, 1 << map->log2_page_size) == 0)
return -1;
return write_upage(map, NULL, &page_desc);

@ -36,7 +36,7 @@ static int free_page(struct ftl_map *map, uint32_t upage)
page_desc.nused_pages = map->nused_pages;
if (flash_copy(map->dev, map->head << map->log2_page_size,
upage << map->log2_page_size, 1 << map->log2_page_size) < 0)
upage << map->log2_page_size, 1 << map->log2_page_size) == 0)
return -1;
return write_upage(map, NULL, &page_desc);

Loading…
Cancel
Save