mynewt-core icon indicating copy to clipboard operation
mynewt-core copied to clipboard

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

Open FabienLep opened this issue 6 years ago • 1 comments

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!

FabienLep avatar Sep 12 '19 01:09 FabienLep

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.

utzig avatar Sep 12 '19 12:09 utzig