#include #include #include int default_flash_is_erased(struct flash_dev *dev, uint32_t addr) { uint8_t data[1 << dev->log2_block_size]; size_t i; if (flash_read(dev, addr << dev->log2_block_size, data, sizeof(data)) == 0) return 0; for (i = 0; i < sizeof(data); ++i) { if (data[i] != 0xff) return 0; } return 1; } void flash_release(struct flash_dev *dev) { if (!dev) return; dev->ops->release(dev); } size_t flash_get_size(struct flash_dev *dev) { if (!dev) return 0; return dev->ops->get_size(dev); } size_t flash_get_capacity(struct flash_dev *dev) { if (!dev) return 0; return dev->ops->get_capacity(dev); } size_t flash_read(struct flash_dev *dev, uint32_t addr, void *data, size_t len) { if (!dev) return -1; return dev->ops->read(dev, addr, data, len); } size_t flash_write(struct flash_dev *dev, uint32_t addr, const void *data, size_t len) { if (!dev) return -1; return dev->ops->write(dev, addr, data, len); } int flash_copy(struct flash_dev *dev, uint32_t dst, uint32_t src, size_t len) { if (!dev) return -1; return dev->ops->copy(dev, dst, src, len); } int flash_is_erased(struct flash_dev *dev, uint32_t addr, size_t len) { if (!dev) return -1; while (len--) { if (!dev->ops->is_erased(dev, addr)) return 0; ++addr; } return 1; } int flash_erase(struct flash_dev *dev, uint32_t addr, size_t len) { if (!dev) return -1; while (len--) { if (dev->ops->erase(dev, addr) < 0) return -1; ++addr; } return 0; }