p4trykx
Posts: 127
Joined: Wed Jan 11, 2012 2:55 pm

Quickly check for SD Card badblocks

Tue Jul 22, 2014 6:54 pm

Hello
I was wondering if there is a fast way to check a SD card for badblock
I've got a Kingston class 4 card and I want to check if for badblocks. I use my laptop SD Card reader and a command badblocks

Code: Select all

sudo  badblocks -nsv /dev/mmcblk0
but it take ages, 40% takes 2,5 hours.
I figure that badblocks uses very short reads and writes and SD cards aren't very good at that. Is there some faster nondestructive way to test a SD Card?

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Quickly check for SD Card badblocks

Tue Jul 22, 2014 7:23 pm

Hi,
p4trykx wrote:I was wondering if there is a fast way to check a SD card for badblock
I don't believe that a reliable method exists at all (not even slow one).

The reason is that SD cards map (and mask) internal memory array to the outside world.
The prices of SD cards are so low, that there is no room to throw away anything... SD cards have slightly more physical memory blocks and if some of them are bad, they are substituted with ones from the spare blocks pool... and you purchase a 100% error-free SD card. (This is not unique to SD cards, it was initially used in hard disks)

The price war is so "bloody" that if a SD card has more bad blocks then available spares, it is "downgraded" to lower capacity.
So, the extreme example would be that you buy 4GB SD card which is actually 8GB card but has 1GB bad (physical) blocks.

All this handling is performed by internal controller inside SD card, which does the masquerade to the outside world... Consequently, various test tools are unable to give real information about the SD cards.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

drgeoff
Posts: 12417
Joined: Wed Jan 25, 2012 6:39 pm

Re: Quickly check for SD Card badblocks

Tue Jul 22, 2014 7:27 pm

p4trykx wrote: Is there some faster nondestructive way to test a SD Card?
The only way to check if a bit is stuck high or low is to do something like:

1. Read the bit
2. Invert the value and write it
3. Read the bit and check it is the same as what was written
4. Invert the value and write it
5. Read the bit and check it is the same as what was written

But that doesn't check for "joined" bits. That is you write a bit but other(s) get changed too.

It is essentially the same as those memory test programs for PC RAM. You know how long they take to do a complete test. An SD card will take much longer because:

1. PC SD RAM is much faster than the flash memory in SD cards

2. SD cards typically have more Mbytes than PCs have RAM
Quis custodiet ipsos custodes?

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Quickly check for SD Card badblocks

Tue Jul 22, 2014 8:58 pm

Hi,
drgeoff wrote:It is essentially the same as those memory test programs for PC RAM.
SD cards cannot be compared with RAMs in this context.


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

drgeoff
Posts: 12417
Joined: Wed Jan 25, 2012 6:39 pm

Re: Quickly check for SD Card badblocks

Tue Jul 22, 2014 9:09 pm

FLYFISH TECHNOLOGIES wrote:
drgeoff wrote:It is essentially the same as those memory test programs for PC RAM.
SD cards cannot be compared with RAMs in this context.
Yes they can, in the sense that memory is memory irrespective of the technology. Testing any read/write memory, including RAM, flash, magnetic disk, optical disk and tape requires at least two writes and two reads of every bit.
Quis custodiet ipsos custodes?

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Quickly check for SD Card badblocks

Wed Jul 23, 2014 12:01 pm

Hi,
drgeoff wrote:
FLYFISH TECHNOLOGIES wrote:SD cards cannot be compared with RAMs in this context.
Yes they can, in the sense that memory is memory irrespective of the technology. Testing any read/write memory, including RAM, flash, magnetic disk, optical disk and tape requires at least two writes and two reads of every bit.
The "problem" with SD cards is that you don't know which physical bit you actually test.

You don't have control over physical bits due to an embedded processor each SD card has, which performs mapping between physical bits and bits you think they are physical. This mapping is dynamic, so even if you loop trough all address space bit by bit, it could happen that some physical bits are tested twice and some of them not at all.

Some more related text:
http://www.raspberrypi.org/forums/viewt ... 58#p489458
http://www.raspberrypi.org/forums/viewt ... 82#p547582


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

drgeoff
Posts: 12417
Joined: Wed Jan 25, 2012 6:39 pm

Re: Quickly check for SD Card badblocks

Wed Jul 23, 2014 2:34 pm

FLYFISH TECHNOLOGIES wrote: The "problem" with SD cards is that you don't know which physical bit you actually test.

You don't have control over physical bits due to an embedded processor each SD card has, which performs mapping between physical bits and bits you think they are physical. This mapping is dynamic, so even if you loop trough all address space bit by bit, it could happen that some physical bits are tested twice and some of them not at all.
I agree that because of bad block mapping and wear levelling it isn't possible to be certain of testing every physical bit once and only once.

I think you are reading too much into what I was trying to say to the OP. He seemed to be concerned about speed and I was trying to explain that fully testing every bit of any storage medium is a lengthy process and doing it on flash memory is much slower than eg running memtest86 on PC RAM because flash is much slower then PC RAM (and there is probably more of it). The specifics of mapping in SD cards is an added complication but it doesn't make matters any easier or faster.
Quis custodiet ipsos custodes?

Return to “Beginners”