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

Fatfs + mynewt_glue + mmc issue if we write data addressed above 4GB in memory #1995

Open
FabienLep opened this issue Sep 12, 2019 · 1 comment

Comments

@FabienLep
Copy link
Contributor

Hi,
I've been doing some tests writing (a lot of) data to an SD card using mynewt_glue.c.
I found a bug the corrupts the entire FS if we cross the 4GB addressing space.
The issue:
in mynewt_glue.c:

  • disk_read() and disk_write() both pass to dops->read() address = sector * 512.
    Both sector and address being 32 bits, that's an issue if we cross sector 8388607 which is 4GB.
  • Behind, mmc_write() and mmc_read() (called by dops->read()/write() in mmc case) both proceed to divide the address by BLOCK_LEN (defined as 512 in mmc.c).

One solution would be to change mmc_write() and mmc_read() to expect a 64bits address (and change mynewt_glue accordingly).
Or to just remove this addr*512 and addr/512 parts (which is not very optimized...)

I can do the modifications myself and PR as soon as we agree on which way to fix this issue.
Thanks!

@utzig
Copy link
Member

utzig commented Sep 12, 2019

One solution would be to change mmc_write() and mmc_read() to expect a 64bits address (and change mynewt_glue accordingly).

That would be a correct change I think. It would also need to change the interfaces in fs/disk and possibly other places.

Or to just remove this addr*512 and addr/512 parts

This would assume that MMC and FAT are glued, while the idea is to have separation, because we might want to use other FS (eg NFFS) on a MMC card.

I can do the modifications myself and PR as soon as we agree on which way to fix this issue.

I'll think a bit more about it and can suggest changes later.

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

No branches or pull requests

2 participants