#1355 closed defect (fixed)

SD card code rejects MMC and random blocks written sequentially

Reported by: Gene Smith Owned by: Joel Sherrill
Priority: normal Milestone: 4.10
Component: fs Version: 4.9
Severity: major Keywords:
Cc: sebastian.huber@… Blocked By:
Blocking:

Description

This describes two problems but my fix is a patch to one file so I describe them both here.

  1. An MMC (MultiMedia? Card) cannot be used in RTEMS 4.9.1 due to an initialization failure. Code in c/src/libchip/i2c/spi-sd-card.c initializes the card using commands that are not supported by MMC (41 and arguably 55). If the command combo 55/41 fails then the card is bad or an MMC since MMC definitely does not support 41. When this occurs, and you want to support SD and MMC, it is recommended to try again with CMD1, which is aways supported by MMC. If CMD1 succeeds then the card is an MMC. The rest of the RTEMS code works find for MMC and SD as is (except for item 2 below which affects SD and MMC the same).

I don't have a hardware slot to try an SD in RTEMS so this fix needs to be checked by someone with an SD slot to make sure it doesn't break anything. The patch assume the card is initially an SD and does the same commands as before (55/41) and only if a failure is seen for 55 or 41 is CMD1 tried.

  1. A bug is present in sd_card_disk_ioctl() that causes multiple SD/MMC blocks (512 bytes) to be written that are not in sequential order to be written into sequential blocks. This causes corruption of the FAT table in flash and failure to write the new directory entry and data cluster when a file is copied in the shell using cp command. There are probably other ways to see this problem but I only worked in the shell, not directly with the fileio api (read, write, open etc). The fix now correctly tells the cache layer to only request multiple/sequential SD/MMC block writes when the blocks are produced in order (e.g., when copying the data of a large file).

Attachments (3)

spi-sd-card.diff (2.6 KB) - added by Gene Smith on Jan 16, 2009 at 5:30:02 PM.
Thinks this fixes the problems described. Testing required.
sd-card-4.9.patch (2.5 KB) - added by Joel Sherrill on Jan 16, 2009 at 5:33:13 PM.
Sebastian's patch for 4.9
sd-card-HEAD.patch (3.1 KB) - added by Joel Sherrill on Jan 16, 2009 at 5:33:40 PM.
Sebastian's patch for CVS head

Download all attachments as: .zip

Change History (6)

Changed on Jan 16, 2009 at 5:30:02 PM by Gene Smith

Attachment: spi-sd-card.diff added

Thinks this fixes the problems described. Testing required.

comment:1 Changed on Jan 16, 2009 at 5:32:11 PM by Joel Sherrill

Cc: Sebastian Huber added

Changed on Jan 16, 2009 at 5:33:13 PM by Joel Sherrill

Attachment: sd-card-4.9.patch added

Sebastian's patch for 4.9

Changed on Jan 16, 2009 at 5:33:40 PM by Joel Sherrill

Attachment: sd-card-HEAD.patch added

Sebastian's patch for CVS head

comment:2 Changed on Jan 21, 2009 at 5:10:03 PM by Joel Sherrill

Resolution: fixed
Status: newclosed

comment:3 Changed on Jan 22, 2009 at 2:38:01 PM by Gene Smith

Marked as FIXED but this does not "fix" item 1 in original report. However, item 1 is actually an enhancement and not a bug. So item 1 should actually be under my enhancement request in bug 1356 and I will put it there.

Note: See TracTickets for help on using tickets.