[En-Nut-Discussion] Phat-FS corrupts SD-Card

Harald Kipp harald.kipp at egnite.de
Tue Dec 20 10:46:20 CET 2011

Hi all,

While trying to improve SD-Card access, I came across a reproducible
problem. When running three threads that are concurrently creating and
then reading a simple text file in an endless loop, you'll soon end up
with a corrupted file system.

What I found out so far:

If the SPI bus driver is used in polling mode (no interrupts, no context
switch) it seems to work fine.

If PHAT_SECTOR_BUFFERS is not defined (only a single buffer is used) it
seems to work fine, even with an interrupt driven SPI bus driver.

If writing to the card is disabled by replacing the write function in
the MMC driver with a simple 'return 1' (successfully written 1 block),
then the stdio read does not always return the right data. Of course,
the card will not become corrupted, because no data is ever written back
to the card.

It looks to me that not all parts of the Phat driver are properly
protected by the vol_io_mutex semaphore when accessing the sector
buffers. If a context switch takes place in the low level hardware
driver, another thread may corrupt their contents.



More information about the En-Nut-Discussion mailing list