|
|
|
@ -6,26 +6,6 @@ |
|
|
|
|
#include <ftl.h> |
|
|
|
|
#include <macros.h> |
|
|
|
|
|
|
|
|
|
static size_t ftl_flash_get_size(struct flash_dev *dev); |
|
|
|
|
static size_t ftl_flash_get_capacity(struct flash_dev *dev); |
|
|
|
|
static size_t ftl_flash_read(struct flash_dev *dev, uint32_t addr, void *data, |
|
|
|
|
size_t len); |
|
|
|
|
static size_t ftl_flash_write(struct flash_dev *dev, uint32_t addr, |
|
|
|
|
const void *data, size_t len); |
|
|
|
|
static int ftl_flash_erase(struct flash_dev *dev, uint32_t addr); |
|
|
|
|
static void ftl_flash_release(struct flash_dev *dev); |
|
|
|
|
|
|
|
|
|
static struct flash_ops ftl_flash_ops = { |
|
|
|
|
.release = ftl_flash_release, |
|
|
|
|
.get_size = ftl_flash_get_size, |
|
|
|
|
.get_capacity = ftl_flash_get_capacity, |
|
|
|
|
.read = ftl_flash_read, |
|
|
|
|
.write = ftl_flash_write, |
|
|
|
|
/* TODO: implement default function to perform a copy. */ |
|
|
|
|
.copy = NULL, |
|
|
|
|
.erase = ftl_flash_erase, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
static size_t ftl_flash_get_size(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
struct ftl_map *map = dev->priv; |
|
|
|
@ -59,6 +39,13 @@ static size_t ftl_flash_write(struct flash_dev *dev, uint32_t addr, |
|
|
|
|
return len; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int ftl_flash_sync(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
struct ftl_map *map = dev->priv; |
|
|
|
|
|
|
|
|
|
return ftl_sync(map); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int ftl_flash_erase(struct flash_dev *dev, uint32_t addr) |
|
|
|
|
{ |
|
|
|
|
struct ftl_map *map = dev->priv; |
|
|
|
@ -66,6 +53,29 @@ static int ftl_flash_erase(struct flash_dev *dev, uint32_t addr) |
|
|
|
|
return ftl_trim(map, addr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ftl_flash_release(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
struct ftl_map *map; |
|
|
|
|
|
|
|
|
|
map = dev->priv; |
|
|
|
|
|
|
|
|
|
flash_release(map->dev); |
|
|
|
|
free(map); |
|
|
|
|
free(dev); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static struct flash_ops ftl_flash_ops = { |
|
|
|
|
.release = ftl_flash_release, |
|
|
|
|
.get_size = ftl_flash_get_size, |
|
|
|
|
.get_capacity = ftl_flash_get_capacity, |
|
|
|
|
.read = ftl_flash_read, |
|
|
|
|
.write = ftl_flash_write, |
|
|
|
|
/* TODO: implement default function to perform a copy. */ |
|
|
|
|
.copy = NULL, |
|
|
|
|
.erase = ftl_flash_erase, |
|
|
|
|
.sync = ftl_flash_sync, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
struct flash_dev *ftl_mount(struct flash_dev *raw_dev) |
|
|
|
|
{ |
|
|
|
|
struct flash_dev *dev; |
|
|
|
@ -95,14 +105,3 @@ err_free_dev: |
|
|
|
|
free(dev); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void ftl_flash_release(struct flash_dev *dev) |
|
|
|
|
{ |
|
|
|
|
struct ftl_map *map; |
|
|
|
|
|
|
|
|
|
map = dev->priv; |
|
|
|
|
|
|
|
|
|
flash_release(map->dev); |
|
|
|
|
free(map); |
|
|
|
|
free(dev); |
|
|
|
|
} |
|
|
|
|