Discussion:
[PATCH] mmc: subtract boot sectors from disk size for eMMC 4.3+ devices
Linus Walleij
2011-03-05 12:15:44 UTC
Permalink
This patch is a squash of patches from Gary King and Ulf
Hansson done in Android trees, hopefully fixing the issue properly.

The csd sector count reported by eMMC 4.3+ cards includes the boot
partition size; subtract this from the size reported to the disk
since the boot partition is inaccessible.

Signed-off-by: Gary King <***@nvidia.com>
Signed-off-by: Ulf Hansson <***@stericsson.com>
Signed-off-by: Linus Walleij <***@linaro.org>
---
drivers/mmc/core/mmc.c | 7 +++++++
include/linux/mmc/mmc.h | 1 +
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 14e95f3..03c3283 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -255,6 +255,13 @@ static int mmc_read_ext_csd(struct mmc_card *card)
/* Cards with density > 2GiB are sector addressed */
if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
mmc_card_set_blockaddr(card);
+
+ if (card->ext_csd.sectors) {
+ unsigned boot_sectors;
+ /* size is in 256K chunks, i.e. 512 sectors each */
+ boot_sectors = ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 512;
+ card->ext_csd.sectors -= boot_sectors;
+ }
}

switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) {
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 264ba54..4516fc1 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -267,6 +267,7 @@ struct _mmc_csd {
#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */
#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
+#define EXT_CSD_BOOT_SIZE_MULTI 226 /* RO */
#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */
#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */
#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
--
1.7.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrei Warkentin
2011-03-06 03:35:51 UTC
Permalink
Post by Linus Walleij
This patch is a squash of patches from Gary King and Ulf
Hansson done in Android trees, hopefully fixing the issue properly.
The csd sector count reported by eMMC 4.3+ cards includes the boot
partition size; subtract this from the size reported to the disk
since the boot partition is inaccessible.
---
drivers/mmc/core/mmc.c | 7 +++++++
include/linux/mmc/mmc.h | 1 +
2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 14e95f3..03c3283 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -255,6 +255,13 @@ static int mmc_read_ext_csd(struct mmc_card *card)
/* Cards with density > 2GiB are sector addressed */
if (card->ext_csd.sectors > (2u * 1024 * 1024 * 1024) / 512)
mmc_card_set_blockaddr(card);
+
+ if (card->ext_csd.sectors) {
+ unsigned boot_sectors;
+ /* size is in 256K chunks, i.e. 512 sectors each */
+ boot_sectors = ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 512;
+ card->ext_csd.sectors -= boot_sectors;
+ }
}
switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) {
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 264ba54..4516fc1 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -267,6 +267,7 @@ struct _mmc_csd {
#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */
#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */
#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
+#define EXT_CSD_BOOT_SIZE_MULTI 226 /* RO */
#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */
#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */
#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
--
1.7.3.2
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
More majordomo info at http://vger.kernel.org/majordomo-info.html
+Colin Cross

I think Colin mentioned the emmc spec doesn't subtract the boot
sectors, just that some out of spec devices do... (sounds like another
use for mmc blk quirks)

(I really hope this gets sent as plain text)
Thanks,
A
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Linus Walleij
2011-03-06 12:22:30 UTC
Permalink
Post by Andrei Warkentin
I think Colin mentioned the emmc spec doesn't subtract the boot
sectors, just that some out of spec devices do... (sounds like another
use for mmc blk quirks)
In which case it sounds like it will be the majority of them deviating from
the spec right now given that there aren't very many of them around :-(

Details on this Colin?

Certainly we can come up with some card quirks for this.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Colin Cross
2011-03-06 16:00:45 UTC
Permalink
Post by Linus Walleij
Post by Andrei Warkentin
I think Colin mentioned the emmc spec doesn't subtract the boot
sectors, just that some out of spec devices do... (sounds like another
use for mmc blk quirks)
In which case it sounds like it will be the majority of them deviating from
the spec right now given that there aren't very many of them around :-(
Details on this Colin?
Certainly we can come up with some card quirks for this.
Yours,
Linus Walleij
I don't know how this is supposed to work. I was told by one person
(Gary King) that the subtraction was necessary, and by another person
(drambo) that it was not correct according to the manufacturer of
their eMMC device. See
http://www.mail-archive.com/linux-***@vger.kernel.org/msg00079.html
for the previous discussion.

Have you verified that the area of the eMMC device between CSD_SECTORS
- BOOT_SECTORS and CSD_SECTORS is not accessible on your device?
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Linus Walleij
2011-04-28 10:33:46 UTC
Permalink
Post by Linus Walleij
This patch is a squash of patches from Gary King and Ulf
Hansson done in Android trees, hopefully fixing the issue properly.
The csd sector count reported by eMMC 4.3+ cards includes the boot
partition size; subtract this from the size reported to the disk
since the boot partition is inaccessible.
I'm trying to get somewhere with this.

AFAICT reading the spec it does not say anything about the
boot sectors being subtracted from the pool of available sectors,
i.e. either you set these sectors aside permanently or you do not
support the feature.

So the behaviour fixed in this patch should be a per-card quirk,
not generic.
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* size is in 256K chun=
ks, i.e. 512 sectors each */
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 boot_sectors =3D ext_cs=
d[EXT_CSD_BOOT_SIZE_MULTI] * 512;

This is not what the spec says. It states that the size is
in 128KB chunks, so the correct code shoul be:

boot_sectors =3D ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 256;

Any comments on this? I guess it's been working, the
patch prent in the Android kernels simply remove twice as
many sectors as required from the card sector pool :-/

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Colin Cross
2011-04-28 18:00:29 UTC
Permalink
Post by Linus Walleij
Post by Linus Walleij
This patch is a squash of patches from Gary King and Ulf
Hansson done in Android trees, hopefully fixing the issue properly.
The csd sector count reported by eMMC 4.3+ cards includes the boot
partition size; subtract this from the size reported to the disk
since the boot partition is inaccessible.
I'm trying to get somewhere with this.
AFAICT reading the spec it does not say anything about the
boot sectors being subtracted from the pool of available sectors,
i.e. either you set these sectors aside permanently or you do not
support the feature.
So the behaviour fixed in this patch should be a per-card quirk,
not generic.
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* size is in 256K chu=
nks, i.e. 512 sectors each */
Post by Linus Walleij
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 boot_sectors =3D ext_c=
sd[EXT_CSD_BOOT_SIZE_MULTI] * 512;
Post by Linus Walleij
This is not what the spec says. It states that the size is
boot_sectors =3D ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 256;
Any comments on this? I guess it's been working, the
patch prent in the Android kernels simply remove twice as
many sectors as required from the card sector pool :-/
This patch was dropped from the Android tree, it is clearly not
correct for all eMMC devices. We have worked around the problem on
the affected by letting the bootloader tell us where it put the GPT
near the end of the device, in which case the actual size of the
device becomes irrelevant.

I'm not convinced that any eMMC chip has this problem, it may have
just been confusion on the part of nVidia caused by their bootloader's
"logical block" addressing system, where the boot sectors are
addressed as 0, and the regular area starts at sizeof(boot sector).
The off-by-two error may have been caused by the affected eMMC having
two boot sectors.

I would suggest forgetting about this patch unless someone can prove
that there is a device that fails to write at the end.
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Andrei Warkentin
2011-04-28 19:05:49 UTC
Permalink
Post by Colin Cross
Post by Linus Walleij
Post by Linus Walleij
This patch is a squash of patches from Gary King and Ulf
Hansson done in Android trees, hopefully fixing the issue properly.
The csd sector count reported by eMMC 4.3+ cards includes the boot
partition size; subtract this from the size reported to the disk
since the boot partition is inaccessible.
I'm trying to get somewhere with this.
AFAICT reading the spec it does not say anything about the
boot sectors being subtracted from the pool of available sectors,
i.e. either you set these sectors aside permanently or you do not
support the feature.
So the behaviour fixed in this patch should be a per-card quirk,
not generic.
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 /* size is in 256K ch=
unks, i.e. 512 sectors each */
Post by Colin Cross
Post by Linus Walleij
Post by Linus Walleij
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 boot_sectors =3D ext_=
csd[EXT_CSD_BOOT_SIZE_MULTI] * 512;
Post by Colin Cross
Post by Linus Walleij
This is not what the spec says. It states that the size is
boot_sectors =3D ext_csd[EXT_CSD_BOOT_SIZE_MULTI] * 256;
Any comments on this? I guess it's been working, the
patch prent in the Android kernels simply remove twice as
many sectors as required from the card sector pool :-/
This patch was dropped from the Android tree, it is clearly not
correct for all eMMC devices. =A0We have worked around the problem on
the affected by letting the bootloader tell us where it put the GPT
near the end of the device, in which case the actual size of the
device becomes irrelevant.
I'm not convinced that any eMMC chip has this problem, it may have
just been confusion on the part of nVidia caused by their bootloader'=
s
Post by Colin Cross
"logical block" addressing system, where the boot sectors are
addressed as 0, and the regular area starts at sizeof(boot sector).
The off-by-two error may have been caused by the affected eMMC having
two boot sectors.
I would suggest forgetting about this patch unless someone can prove
that there is a device that fails to write at the end.
Plus as far as linux-mmc tree, the boot size calculation is now
correct for enabling the boot hardware partitions as separate logical
devices...
All the cards I've tested (granted, wasn't too many) handled boot
partitions correctly, and the user partition area size never included
the boot partitions.

So I think we can forget about Gary's patch. For broken hardware we
now have the quirk hooks in block.c to work around this if said broken
hardware actually exists...

A
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
the body of a message to ***@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Loading...