EmbeddedPkg: Fix Command Argument for SD/eMMC R/W operation.

Issue : SD read failure for high capacity cards e.g. 64 GB

Reason : Command argument value exceeds 32 bit for block number 0x3787FFF
and cant be fit into 32 bit wide SD host controller register.

Fix :
AccessMode bits [29:30] of OCR is a valid definition to calculate
data address for eMMC cards.

For SD cards, data address is calculated on the basis of
card capacity status bit[30] of OCR.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
This commit is contained in:
Meenakshi Aggarwal 2019-01-24 19:35:18 +05:30 committed by Leif Lindholm
parent d5788777bc
commit b566259c8a
2 changed files with 18 additions and 5 deletions

View File

@ -70,6 +70,8 @@
#define SD_HIGH_SPEED 50000000
#define SWITCH_CMD_SUCCESS_MASK 0x0f000000
#define SD_CARD_CAPACITY 0x00000002
#define BUSWIDTH_4 4
typedef enum {

View File

@ -148,12 +148,23 @@ MmcTransferBlock (
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
MmcHost = MmcHostInstance->MmcHost;
//Set command argument based on the card access mode (Byte mode or Block mode)
if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) ==
MMC_OCR_ACCESS_SECTOR) {
CmdArg = Lba;
if (MmcHostInstance->CardInfo.CardType != EMMC_CARD) {
//Set command argument based on the card capacity
//if 0 : SDSC card
//if 1 : SDXC/SDHC
if (MmcHostInstance->CardInfo.OCRData.AccessMode & SD_CARD_CAPACITY) {
CmdArg = Lba;
} else {
CmdArg = Lba * This->Media->BlockSize;
}
} else {
CmdArg = Lba * This->Media->BlockSize;
//Set command argument based on the card access mode (Byte mode or Block mode)
if ((MmcHostInstance->CardInfo.OCRData.AccessMode & MMC_OCR_ACCESS_MASK) ==
MMC_OCR_ACCESS_SECTOR) {
CmdArg = Lba;
} else {
CmdArg = Lba * This->Media->BlockSize;
}
}
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);