From patchwork Wed Feb 5 20:00:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Bormann X-Patchwork-Id: 317267 X-Patchwork-Delegate: panto@antoniou-consulting.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 621942C0091 for ; Thu, 6 Feb 2014 06:59:58 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 77F384B914; Wed, 5 Feb 2014 20:59:55 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NJjPAqe2E+ka; Wed, 5 Feb 2014 20:59:55 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 393604B8C7; Wed, 5 Feb 2014 20:59:53 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4F6C04B8C7 for ; Wed, 5 Feb 2014 20:59:49 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id evNS9b604fTt for ; Wed, 5 Feb 2014 20:59:46 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 IN_SPAMCOP=3.75 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from nm1-vm1.bullet.mail.bf1.yahoo.com (nm1-vm1.bullet.mail.bf1.yahoo.com [98.139.213.163]) by theia.denx.de (Postfix) with ESMTPS id 097744B8BE for ; Wed, 5 Feb 2014 20:59:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=gcom1024; t=1391630380; bh=WpONukaymwnrEWJVTBy09fXmo3vvq05B/P6nhrbHsWw=; h=Received:Received:Received:DKIM-Signature:X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; b=EVJ6C0Yf31zMcVGOVv3dmwCcbzTELQRg2PjYEdeHIUWvxevJG9uVjanp8WHk+YsdMn8xqfpqT3NgYbbPHF4txsuOMDBkqaN8X2YNcXayc54lWixEkQz+1jWfOyvQWABfm3FHEHfqyovfxuON4vxiV4fOxMpkjw/H2/Vpy3kY/sU= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=gcom1024; d=yahoo.com; b=Ff5hsytih8iPJPDYVz/H2c7Blw56K2faZxvHlgOc2Q8tnDt4n5OO3S/Il0TP5GC7hbN79OwtUJNina3kB06vM1BmZ9q+o5me/n2wpshjOq7jbs8Fq6mvxmvqTCwMUPB2RCQ7IS580lrQpc/r+Y2p/L07YjGIKFXw3J5aoZCFxV8=; Received: from [98.139.215.143] by nm1.bullet.mail.bf1.yahoo.com with NNFMP; 05 Feb 2014 19:59:40 -0000 Received: from [98.139.211.194] by tm14.bullet.mail.bf1.yahoo.com with NNFMP; 05 Feb 2014 19:59:40 -0000 Received: from [127.0.0.1] by smtp203.mail.bf1.yahoo.com with NNFMP; 05 Feb 2014 19:59:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1391630380; bh=WpONukaymwnrEWJVTBy09fXmo3vvq05B/P6nhrbHsWw=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Message-ID:Date:From:User-Agent:MIME-Version:To:Subject:Content-Type:Content-Transfer-Encoding; b=l6v77vK1b4PCIOpERr2OSnQR7FGkFAHMcswrJmV+Pp8hthcMwpD+L0DcpDSN8Bj2covIu27UYvZvHPmh6SFwUd6zWF4mqGnn+CQGd2/l5oZEVLySoPS0Wd3Upt5vpf/950kNvBVfDqVwWCe9QokKqe9ZUmiJ/ghQHWbQ05THWrY= X-Yahoo-Newman-Id: 62718.45129.bm@smtp203.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 7Yx29FUVM1kDLlnXikhdYWBLgomOmh5E.C06zh87cLXXnTa PyaaPwx2_6RkYUoO1pxR4l4aq0CgpnerZzqFkaL59UP1.TeXSk77NfHRowxf TKbuN5kdUJ7XKLcVAHBnnn_l0AlnELKay96iw1htlrO83TOuOu7xBdCkdJJk qeYOcO_89QtHUGJ1_Ak7CZXou2vljvxKWcoNR8tzw_XU4oxy0UewT3lA3P_N GArXgBNJOPevMXRTl5PulBmEpSnZFd5z.cRAIJUTAPMxBTf9hoZu7UbeSCwK AJkzYjF1RQ2meI9k.llaujFN6SbboohlADE0lfxnuIjypG0fw8kqzH6vaIXh 4A63.mmF6uCqDiiW5lxnVExpm.gitlHQHvV0TBlXgQWrpEexaM4NuKUCDzrF a15mwsJbmWbbSQUD1kiUlh7VkRszs.azvLOBVmOWDb3QibnCvteiPabBHCzN q1C2HW9dIfSlp8X14eTvJY09jnqFzVbmH7upIF99ycawVUmh_XzNTkUKxJO1 NmGTNWmDAxnV2FH5OXUkd X-Yahoo-SMTP: nTtOh.KswBBU9TGL67p_AhAvs5mh X-Rocket-Received: from [10.200.21.76] (fbormann@204.50.148.9 with plain [98.139.211.125]) by smtp203.mail.bf1.yahoo.com with SMTP; 05 Feb 2014 11:59:39 -0800 PST Message-ID: <52F2986A.1080805@yahoo.com> Date: Wed, 05 Feb 2014 15:00:42 -0500 From: Frank Bormann User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131103 Icedove/17.0.10 MIME-Version: 1.0 To: u-boot@lists.denx.de Subject: [U-Boot] [RFC PATCH 1/1] Read mmc device memory capacity from EXT_CSD if memory is addressed by sector X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Hello Everyone, I believe, there is a bug in the mmc driver code pertaining to how u-boot detects memory size of an mmc device. However, I am not 100% sure, my solution conforms to the JEDEC standard. So I am putting it up for discussion. Previously, sector count indicated by mmc devices in the EXT_CSD would only be used in u-boot if the size indicated is greater than 2 GB. This seems to be incorrect. I am working with a 4 GB Micron eMMC device that after partition configuration and setting the user data area to enhanced mode has a remaining capacity of less than 2 GB for the user data area. JESD84-B50 explicitly states in 6.2.4 that for these devices SEC_CNT from the EXT_CSD is still valid even if the memory size for that device has dropped below 2 GB by the partition configuration applied. The access mode bits from the OCR register seem to provide a better way to decide whether to use the CSD-based C_SIZE & C_MULT or the EXT_CSD-based SEC_CNT information when determining the device's capacity. In particular, this fixes a bug where u-boot SPL would assign 0 to mmc->block_dev.lba later on in the mmc_startup() function and subsequently fail to load u-boot from that mmc due to the original C_SIZE & C_MULT code assigning a 4 TB size to mmc->capacity, that incorrect capacity never being overwritten by the SEC_CNT capacity calculation (due to its size being less than 2 GB) and then finally lldiv(mmc->capacity, mmc->read_bl_len) exceeding the 32-bit result data type of mmc->block_dev.lba. Signed-off-by: Frank Bormann --- drivers/mmc/mmc.c | 10 +++++----- include/mmc.h | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index c6a1c23..c5d1efc 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -935,19 +935,19 @@ static int mmc_startup(struct mmc *mmc) if (!IS_SD(mmc) && (mmc->version >= MMC_VERSION_4)) { /* check ext_csd version and capacity */ err = mmc_send_ext_csd(mmc, ext_csd); - if (!err && (ext_csd[EXT_CSD_REV] >= 2)) { + if (!err && (ext_csd[EXT_CSD_REV] >= 2) && + (mmc->ocr & OCR_ACCESS_MODE) == OCR_ACCESS_BY_SECTOR) { /* * According to the JEDEC Standard, the value of - * ext_csd's capacity is valid if the value is more - * than 2GB + * ext_csd's capacity is valid if the device addresses + * its memory by sector */ capacity = ext_csd[EXT_CSD_SEC_CNT] << 0 | ext_csd[EXT_CSD_SEC_CNT + 1] << 8 | ext_csd[EXT_CSD_SEC_CNT + 2] << 16 | ext_csd[EXT_CSD_SEC_CNT + 3] << 24; capacity *= MMC_MAX_BLOCK_LEN; - if ((capacity >> 20) > 2 * 1024) - mmc->capacity_user = capacity; + mmc->capacity_user = capacity; } switch (ext_csd[EXT_CSD_REV]) { diff --git a/include/mmc.h b/include/mmc.h index e1060b9..816b580 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -104,6 +104,7 @@ #define OCR_HCS 0x40000000 #define OCR_VOLTAGE_MASK 0x007FFF80 #define OCR_ACCESS_MODE 0x60000000 +#define OCR_ACCESS_BY_SECTOR (1 << 30) #define SECURE_ERASE 0x80000000 _______________________________________________