apache / apache/mynewt-core

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

Open
#1,995 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
891
Forks
381
Avg merge
2d 7h
Merged PRs (30d)
14

Description

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!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in mynewt_glue.c at disk_read() and disk_write(), then trace their dops->read()/write() calls into mmc.c and mmc_read()/mmc_write(). Compare the 32-bit address calculations around sector 8388607 and determine the agreed addressing approach; done means writing and reading data beyond 4GB without filesystem corruption.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.