From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (EUR05-DB8-obe.outbound.protection.outlook.com [40.107.20.71]) by mx.groups.io with SMTP id smtpd.web12.7221.1585905867089780769 for ; Fri, 03 Apr 2020 02:24:28 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nxp.com header.s=selector2 header.b=gs30kCOZ; spf=pass (domain: nxp.com, ip: 40.107.20.71, mailfrom: gaurav.jain@nxp.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DfR3r4lSF9kFkgOQn76vOaDNbvh5SIm1giTAE8I60FwbGgb1Ugv4cKcvALOwvp3E4lHsf3CkCLjZ+KptYbdyWCo8ilmWTYpGr8Z+MIu9+aFEuqWhPLMXU8vDDiAbtOTBj7uOuVZR+qrXTbyK9c+L2ccEQXrPJKHHKeUwM9F9HsFiyzrcYJ2hFJKPCUxP5W4i9Cp5I1lVQm+qPs4nd0FSY778ruU0arPXvhqZhjdRT1W21ImsWZ9xXZAoGxdcGCKhX4y4Xy0s7JmC5VK0H0tpmRoADxpAk56c0NA+1GQ9F3XnZ6SDaMHuXTKx8PfB1J4xYobyFuDUlKHMoiexK1bJpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=74Bblxu5WrNddl8eewjQ2soivr2AI4Xylkc4JV4+9Uc=; b=WJfMMbOUvvIDV7WPmFlBV2e92wPdwZalzd7HFqdBBktxxagSpTqp/wwePhyMCmpYtqa0AgqUrzrzuZ3N2mfyr5OlBks9EypDHd/TJfwjIDE2DfFNF2doi7z1KOmaEwhRs3oC71f6mif+QoXTA7TdHLp7mKAarSjVv0lfjK8f1pIAljT+kxSyDPTJY99brsK+wyv+15kS5FvZjL4fdeRrqHPQ7kZXSWvm5C5hV3hO6WpGEdGXZV/VSxX9NJ06CZLj5/znUHlqwDFmO7XmqQem4p2FPh+6+waxan8Zs9m6wv/XfvbhNs/0mA2jsQB8HtMvWPmeXJAPxr38xK339bMQCg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=74Bblxu5WrNddl8eewjQ2soivr2AI4Xylkc4JV4+9Uc=; b=gs30kCOZ9Uh6mj5w9BOJJUdMxAOndKGAtBcsdcuZyg8SzqTCefjepm7ggW56MFDYScpruWnPew2fVl1t38BQqzB5Rsta46I7qO/7tI8PtfF+w1/KEYdHq95T0iKJ9jKv4ySACFkks7d+GWwC7jsYwAWQciwCADPgIzHeE0gbWyY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=gaurav.jain@nxp.com; Received: from AM5PR04MB3074.eurprd04.prod.outlook.com (2603:10a6:206:4::16) by AM5PR04MB3186.eurprd04.prod.outlook.com (2603:10a6:206:f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2878.15; Fri, 3 Apr 2020 09:24:25 +0000 Received: from AM5PR04MB3074.eurprd04.prod.outlook.com ([fe80::e50b:610e:7080:e559]) by AM5PR04MB3074.eurprd04.prod.outlook.com ([fe80::e50b:610e:7080:e559%7]) with mapi id 15.20.2878.017; Fri, 3 Apr 2020 09:24:25 +0000 From: "Gaurav Jain" To: devel@edk2.groups.io CC: Leif Lindholm , Ard Biesheuvel , Pankaj Bansal , Gaurav Jain Subject: [PATCH 1/1] EmbeddedPkg/MmcDxe: Added MaxBlock Transfer Limit 65535 in R/W. Date: Fri, 3 Apr 2020 14:54:07 +0530 Message-ID: <1585905847-16380-1-git-send-email-gaurav.jain@nxp.com> X-Mailer: git-send-email 2.7.4 X-ClientProxiedBy: SG2PR01CA0115.apcprd01.prod.exchangelabs.com (2603:1096:4:40::19) To AM5PR04MB3074.eurprd04.prod.outlook.com (2603:10a6:206:4::16) Return-Path: gaurav.jain@nxp.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from lsv03032.swis.in-blr01.nxp.com (14.142.151.118) by SG2PR01CA0115.apcprd01.prod.exchangelabs.com (2603:1096:4:40::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.20.2878.15 via Frontend Transport; Fri, 3 Apr 2020 09:24:23 +0000 X-Mailer: git-send-email 2.7.4 X-Originating-IP: [14.142.151.118] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0015d384-57f8-4f3a-f065-08d7d7b0cce3 X-MS-TrafficTypeDiagnostic: AM5PR04MB3186:|AM5PR04MB3186: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0362BF9FDB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM5PR04MB3074.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(39860400002)(376002)(346002)(136003)(396003)(366004)(8936002)(81156014)(81166006)(316002)(55236004)(54906003)(7696005)(6916009)(44832011)(36756003)(6486002)(478600001)(2616005)(956004)(186003)(66556008)(86362001)(66946007)(52116002)(16526019)(26005)(4326008)(8676002)(2906002)(5660300002)(1006002)(66476007)(6666004)(110426005);DIR:OUT;SFP:1101; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7mc//nY1kj4XpXsYex5HeyTR1eYhqkdMOrtBXr7iE6T+xSB4LI4W6wvt5AU03xgQYdZJ8Fc11s1yKtUc8HCCmxEUfyLl1+QEeXY6xQOEYb7GB30coze8xJPA8gdPgVPQJGAMsBsme6W/Vvgyf5EYQLzAsNTe6MY6RPpd+u2VL4+t0tcleeGiOQ0g9gyhkdkDoQszxm38ex2euzY8JoKDKaQsQedeZPTlyIkKnY3kn4CEfRf4TxizTHX/aYNJat8EBWTLs9c6jBORN7FHiKomE114OeFsSpB4fxJgRgmQjbedgpMkoJhi+t4QAheSW0pUL5l1NIkZlbHrORUmqUQuhi7jKoqfp0ig5ORRZLygGJ3Dik/xgUfEPkprb2EAnzjKawBFdK4O0aBFx03JO002hSPq88laELJ54oAgiG2FEu/fXgsYteta3PXMUc1+77d/an9UOXyihbwtBVoFppcdCFjqoDk+8iy0HezJDIc/v4ypOpo8vIlossCdV2VmCcum X-MS-Exchange-AntiSpam-MessageData: uf5DpH0jbDZAPaglbL7piywlhBU4RvSS3yqhljqxlE9QIyqI+lHJ5KEGLR59FqN9tOovOm3tcVingAIGDYFLhwIMmHdj/AUCuTYnePv8j7SMHyQyxIyULV2aw3LDQoqclkoPYlGEAmuNj8Fii1zTzA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0015d384-57f8-4f3a-f065-08d7d7b0cce3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2020 09:24:24.9812 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Q6O5wsx8tBp7mjKoqy1LuPtw6GrL7HNgG4ijXquuPuTTfEzKoEvUajpwBu/Urfd3Bm2ralHSW9AgONI/JfRcNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR04MB3186 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Moved BlockCount calculation below BufferSize Validation checks. First Ensure Buffersize is Not Zero and multiple of Media BlockSize. then calculate BlockCount and perform Block checks. Corrected BlockCount calculation, as BufferSize is multiple of BlockSize, So adding (BlockSize-1) bytes to BufferSize and then divide by BlockSize will have no impact on BlockCount. Reading Large Images from MMC causes errors. As per SD Host Controller Spec version 4.20, Restriction of 16-bit Block Count transfer is 65535. Max block transfer limit in single cmd is 65535 blocks. Added Max Block check that can be processed is 0xFFFF. then Update BlockCount on the basis of MaxBlock. Signed-off-by: Gaurav Jain --- EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 38 ++++++++++++++++++++-------= ---- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Univer= sal/MmcDxe/MmcBlockIo.c index 17c20c0159ba..b508c466d9c5 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c @@ -242,6 +242,8 @@ MmcIoBlocks ( UINTN BytesRemainingToBeTransfered; UINTN BlockCount; UINTN ConsumeSize; + UINT32 MaxBlock; + UINTN RemainingBlock; =20 BlockCount =3D 1; MmcHostInstance =3D MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This); @@ -262,19 +264,6 @@ MmcIoBlocks ( return EFI_NO_MEDIA; } =20 - if (MMC_HOST_HAS_ISMULTIBLOCK(MmcHost) && MmcHost->IsMultiBlock(MmcHost)= ) { - BlockCount =3D (BufferSize + This->Media->BlockSize - 1) / This->Media= ->BlockSize; - } - - // All blocks must be within the device - if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBl= ock + 1)) { - return EFI_INVALID_PARAMETER; - } - - if ((Transfer =3D=3D MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly =3D= =3D TRUE)) { - return EFI_WRITE_PROTECTED; - } - // Reading 0 Byte is valid if (BufferSize =3D=3D 0) { return EFI_SUCCESS; @@ -285,14 +274,36 @@ MmcIoBlocks ( return EFI_BAD_BUFFER_SIZE; } =20 + if (MMC_HOST_HAS_ISMULTIBLOCK(MmcHost) && MmcHost->IsMultiBlock(MmcHost)= ) { + BlockCount =3D BufferSize / This->Media->BlockSize; + } + + // All blocks must be within the device + if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBl= ock + 1)) { + return EFI_INVALID_PARAMETER; + } + + if ((Transfer =3D=3D MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly =3D= =3D TRUE)) { + return EFI_WRITE_PROTECTED; + } + // Check the alignment if ((This->Media->IoAlign > 2) && (((UINTN)Buffer & (This->Media->IoAlig= n - 1)) !=3D 0)) { return EFI_INVALID_PARAMETER; } =20 + // Max block number in single cmd is 65535 blocks. + MaxBlock =3D 0xFFFF; + RemainingBlock =3D BlockCount; BytesRemainingToBeTransfered =3D BufferSize; while (BytesRemainingToBeTransfered > 0) { =20 + if (RemainingBlock <=3D MaxBlock) { + BlockCount =3D RemainingBlock; + } else { + BlockCount =3D MaxBlock; + } + // Check if the Card is in Ready status CmdArg =3D MmcHostInstance->CardInfo.RCA << 16; Response[0] =3D 0; @@ -338,6 +349,7 @@ MmcIoBlocks ( DEBUG ((EFI_D_ERROR, "%a(): Failed to transfer block and Status:%r\n= ", __func__, Status)); } =20 + RemainingBlock -=3D BlockCount; BytesRemainingToBeTransfered -=3D ConsumeSize; if (BytesRemainingToBeTransfered > 0) { Lba +=3D BlockCount; --=20 2.7.4