Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers/mtd_sdmmc: remove MTD_DRIVER_FLAG_DIRECT_WRITE #21169

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabian18
Copy link
Contributor

Contribution description

Removing MTD_DRIVER_FLAG_DIRECT_WRITE for mtd_sdmmc_driver as the MTD driver does not expect to have no dev->work_area.

static int mtd_sdmmc_write_page(mtd_dev_t *dev, const void *buff, uint32_t page,
uint32_t offset, uint32_t size)
{
mtd_sdmmc_t *mtd_sd = (mtd_sdmmc_t*)dev;
DEBUG("mtd_sdmmc_write_page: page:%" PRIu32 " offset:%" PRIu32 " size:%" PRIu32 "\n",
page, offset, size);
if (offset || size % SDMMC_SDHC_BLOCK_SIZE) {
#if IS_USED(MODULE_MTD_WRITE_PAGE)
if (dev->work_area == NULL) {
DEBUG("mtd_sdmmc_write_page: no work area\n");
return -ENOTSUP;
}
if (sdmmc_read_blocks(mtd_sd->sdmmc, page, SDMMC_SDHC_BLOCK_SIZE,
1, dev->work_area, NULL)) {
return -EIO;
}
size = MIN(size, SDMMC_SDHC_BLOCK_SIZE - offset);
DEBUG("mtd_sdmmc_write_page: write %" PRIu32 " bytes at offset %" PRIu32 "\n",
size, offset);
memcpy((uint8_t *)dev->work_area + offset, buff, size);
if (sdmmc_write_blocks(mtd_sd->sdmmc, page, SDMMC_SDHC_BLOCK_SIZE,
1, dev->work_area, NULL)) {
return -EIO;
}
#else
return -ENOTSUP;
#endif

The work area is only allocated when the flag is not set.

RIOT/drivers/mtd/mtd.c

Lines 77 to 84 in e8be6ee

#ifdef MODULE_MTD_WRITE_PAGE
if ((mtd->driver->flags & MTD_DRIVER_FLAG_DIRECT_WRITE) == 0) {
mtd->work_area = malloc(mtd->pages_per_sector * mtd->page_size);
if (mtd->work_area == NULL) {
res = -ENOMEM;
}
}
#endif

Testing procedure

Custom board with an eMMC. I can craete a fatfs filesystem on it with:

ifneq (,$(filter mtd,$(USEMODULE)))
  USEMODULE += mtd_write_page
  USEMODULE += mtd_sdmmc_default
  USEMODULE += sdmmc_mmc
endif

ifneq (,$(filter vfs_default,$(USEMODULE)))
  USEMODULE += fatfs_vfs
  USEMODULE += mtd
endif

Issues/PRs references

@github-actions github-actions bot added the Area: drivers Area: Device drivers label Jan 28, 2025
@benpicco
Copy link
Contributor

MTD_DRIVER_FLAG_DIRECT_WRITE is still correct - you don't need to erase a sector to write it.
I do wonder how fatfs does unaligned writes though, mtd_diskio.c always operates on whole pages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants