1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/littlefs2: use page-addressed MTD operations

This commit is contained in:
Benjamin Valentin 2020-05-07 15:10:07 +02:00
parent 68a47b63e3
commit c2492209d8

View File

@ -72,7 +72,8 @@ static int _dev_read(const struct lfs_config *c, lfs_block_t block,
DEBUG("lfs_read: c=%p, block=%" PRIu32 ", off=%" PRIu32 ", buf=%p, size=%" PRIu32 "\n",
(void *)c, block, off, buffer, size);
return mtd_read(mtd, buffer, ((fs->base_addr + block) * c->block_size) + off, size);
return mtd_read_page(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
}
static int _dev_write(const struct lfs_config *c, lfs_block_t block,
@ -84,17 +85,8 @@ static int _dev_write(const struct lfs_config *c, lfs_block_t block,
DEBUG("lfs_write: c=%p, block=%" PRIu32 ", off=%" PRIu32 ", buf=%p, size=%" PRIu32 "\n",
(void *)c, block, off, buffer, size);
const uint8_t *buf = buffer;
uint32_t addr = ((fs->base_addr + block) * c->block_size) + off;
for (const uint8_t *part = buf; part < buf + size; part += c->prog_size,
addr += c->prog_size) {
int ret = mtd_write(mtd, part, addr, c->prog_size);
if (ret != 0) {
return ret;
}
}
return 0;
return mtd_write_page(mtd, buffer, (fs->base_addr + block) * mtd->pages_per_sector,
off, size);
}
static int _dev_erase(const struct lfs_config *c, lfs_block_t block)
@ -104,12 +96,7 @@ static int _dev_erase(const struct lfs_config *c, lfs_block_t block)
DEBUG("lfs_erase: c=%p, block=%" PRIu32 "\n", (void *)c, block);
int ret = mtd_erase(mtd, ((fs->base_addr + block) * c->block_size), c->block_size);
if (ret >= 0) {
return 0;
}
return ret;
return mtd_erase_sector(mtd, fs->base_addr + block, 1);
}
static int _dev_sync(const struct lfs_config *c)