From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web11.11381.1586182103316309301 for ; Mon, 06 Apr 2020 07:08:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=oYmhzU8F; spf=pass (domain: nuviainc.com, ip: 209.85.221.68, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f68.google.com with SMTP id w15so11388028wrv.10 for ; Mon, 06 Apr 2020 07:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=N28hU6nUL1OMrhc0LfebINhncbhKMzoM3+BoLP2kpzk=; b=oYmhzU8F/wH8HrUIqUMOCiNIm9A8lIsDlPKszxZZYU39EGf2sI8B0ZLpt8z+pQ2ZqT cKJapQUzG46Go56kCqO8XIwE69chNUV6sz86FtdcdenTWhLbLLZm1A50gJJqQ1aZOUKo 4AzqBwm5BNktgGiD/U3blRv6veFtD5TIR38ITEEJiD+eofjSn7DP30iF+N3dffJdDg9g nwGMkzndb3/P7y8cvAy5XlOt1cBRKnn38W856wdp6VUklEtqgs0r/WwhSiAqVoNfDCWZ uZ+tAA2S15opTnaEnviE0bMDQ1V/uCieO8Hi/3m1wo/lw5yVkNQ2CcWtizC9b/aucrDL tDLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=N28hU6nUL1OMrhc0LfebINhncbhKMzoM3+BoLP2kpzk=; b=MzbtPzjloBqhuMghshoOHz778Uad0N+1KsY7sd7AuAS+/FzF7dpB7PjyZ7UW+JrdEb HmLAFvllLUJwWBT+XEsjOeJOPrZfoxNNd5XKKy3NC5I+T7I9Ycne5mDNPCQEPt1GMU8c L0ddI3mdu0fDHLtKOs7gm340wURKaLtnnlWrBna+yv25k4FzQVxS9uD08l4V3zs6x0aO +2j+HzH09X3F/gQTiw0OCkv2UQ9X6SCWv/gMrlob4/bWwnKpKm4EqcA+qcOiWEyhUuyu L1AOKkH4yJEo9BW0gywtuOGJ+OVWNzu2pPQD6nXw1QqhP+xFDHk+EpEhag7vsq22lwI7 epXA== X-Gm-Message-State: AGi0PubPkK1dgReLkRRHFLPl35ASdT6hrxR1W8UU4UAdgk4cK8aDLJSQ AVs6p4Iy53fX9IoCeFW8o/Frwg== X-Google-Smtp-Source: APiQypLEDsdheEPN1gelL2kI9hqbeoo5QPpQk3/NBzpNC72HnneLzQyy2ADH89T4DBY82fcJmvTrSQ== X-Received: by 2002:a5d:4ac2:: with SMTP id y2mr725977wrs.340.1586182101810; Mon, 06 Apr 2020 07:08:21 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id o13sm4260372wrm.74.2020.04.06.07.08.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 07:08:21 -0700 (PDT) Date: Mon, 6 Apr 2020 15:08:19 +0100 From: "Leif Lindholm" To: Gaurav Jain Cc: devel@edk2.groups.io, Ard Biesheuvel , Pankaj Bansal , Haojian Zhuang , "Loh, Tien Hock" Subject: Re: [PATCH 1/1] EmbeddedPkg/MmcDxe: Added MaxBlock Transfer Limit 65535 in R/W. Message-ID: <20200406140819.GI14075@vanye> References: <1585905847-16380-1-git-send-email-gaurav.jain@nxp.com> MIME-Version: 1.0 In-Reply-To: <1585905847-16380-1-git-send-email-gaurav.jain@nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi Gaurav, Haojian, Tien Hock - can you help review/test this change? Best Regards, Leif On Fri, Apr 03, 2020 at 14:54:07 +0530, Gaurav Jain wrote: > 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/Universal/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; > > BlockCount = 1; > MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This); > @@ -262,19 +264,6 @@ MmcIoBlocks ( > return EFI_NO_MEDIA; > } > > - if (MMC_HOST_HAS_ISMULTIBLOCK(MmcHost) && MmcHost->IsMultiBlock(MmcHost)) { > - BlockCount = (BufferSize + This->Media->BlockSize - 1) / This->Media->BlockSize; > - } > - > - // All blocks must be within the device > - if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)) { > - return EFI_INVALID_PARAMETER; > - } > - > - if ((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) { > - return EFI_WRITE_PROTECTED; > - } > - > // Reading 0 Byte is valid > if (BufferSize == 0) { > return EFI_SUCCESS; > @@ -285,14 +274,36 @@ MmcIoBlocks ( > return EFI_BAD_BUFFER_SIZE; > } > > + if (MMC_HOST_HAS_ISMULTIBLOCK(MmcHost) && MmcHost->IsMultiBlock(MmcHost)) { > + BlockCount = BufferSize / This->Media->BlockSize; > + } > + > + // All blocks must be within the device > + if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)) { > + return EFI_INVALID_PARAMETER; > + } > + > + if ((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) { > + return EFI_WRITE_PROTECTED; > + } > + > // Check the alignment > if ((This->Media->IoAlign > 2) && (((UINTN)Buffer & (This->Media->IoAlign - 1)) != 0)) { > return EFI_INVALID_PARAMETER; > } > > + // Max block number in single cmd is 65535 blocks. > + MaxBlock = 0xFFFF; > + RemainingBlock = BlockCount; > BytesRemainingToBeTransfered = BufferSize; > while (BytesRemainingToBeTransfered > 0) { > > + if (RemainingBlock <= MaxBlock) { > + BlockCount = RemainingBlock; > + } else { > + BlockCount = MaxBlock; > + } > + > // Check if the Card is in Ready status > CmdArg = MmcHostInstance->CardInfo.RCA << 16; > Response[0] = 0; > @@ -338,6 +349,7 @@ MmcIoBlocks ( > DEBUG ((EFI_D_ERROR, "%a(): Failed to transfer block and Status:%r\n", __func__, Status)); > } > > + RemainingBlock -= BlockCount; > BytesRemainingToBeTransfered -= ConsumeSize; > if (BytesRemainingToBeTransfered > 0) { > Lba += BlockCount; > -- > 2.7.4 >