#include #include "usecfs_dev.h" #include "spi_flash.h" static uint32_t part_base = 0xFFFFFFFF; static uint32_t part_size = 0; void *block_open(void *args_ptr) { uint32_t *args = (uint32_t *)args_ptr; part_base = args[0]; part_size = args[1]; return &part_base; } int block_read(void *dev, void *_buf, uint32_t lba) { if (part_size == 0) return -1; return spi_flash_read(part_base + (lba * BLOCK_SIZE), _buf, BLOCK_SIZE); } int block_write(void *dev, const void *_buf, uint32_t lba) { if (part_size == 0) return -1; spi_flash_sector_erase(part_base + lba * BLOCK_SIZE); return spi_flash_write(part_base + lba * BLOCK_SIZE, _buf, BLOCK_SIZE); } void block_close(void *dev) { (void)dev; part_base = 0xFFFFFFFF; part_size = 0; }