3

What happen if an SDHC card gets a write error (damaged cell / bad sector)?

Will the whole card be unusable (to trash, all data written to that sector now and in future will be lost)? Or rewrite sector (flash memory get corrupted when writing so maybe have any function to check if sector was written successfully) to another and mark as fault as unusable what will be seen as reduction of capacity but no data lost.

I have to do some research about SD cards on disk-less machines.

1
  • Typically a data error during write will go undetected unless the host software chooses to perform an explicit read-after-write (aka verification). A "bad sector" can only be detected when it is read or when the page is erased. The "function to check if sector was written successfully" is the normal read-sector command requested by the host. See superuser.com/questions/1554322/…
    – sawdust
    Feb 7, 2023 at 20:00

3 Answers 3

2

In general, SD cards run with a FAT filesystem. This will detect and mark/flag bad sectors so end result is data is not lost but the amount of available space on the card is reduced slightly. It's not perfect, of course. Some newer cards have error correction code built in (ECC) that does a similar job at a lower level, so in theory should make it even less likely to lose info being written to a card. It's still possible, just less likely.

1
  • 1
    "Some newer cards have error correction code built in (ECC)" -- Inaccurate & misleading. All NAND chips require use of ECC for reliability. As chip density has increased and quality gone down the past decade, NAND chip manufacturers have increased the ECC requirements.
    – sawdust
    Feb 7, 2023 at 19:27
2

The way NAND flash works is by providing a number of "eraseblocks" - each "eraseblock" has a number of "pages."

For example, there could be 128 Kbyte eraseblocks divided into 64 2 Kbyte pages.

Each page can be written to, changing bits from 1 to 0. If you want to change any bits back from 0 to 1, you have to issue an erase command to the whole eraseblock which resets all bits to 1 (unless the block is worn).

Writing isn't perfect and some bits may fail to change from 1 to 0, or flip by themselves.

What saves the say is this: there is also an "out of band area", or an extra page, per eraseblock. There, ECC data can be written. ECC allows recovery of a certain number of bits depending on the type of ECC (such as Reed Solomon, BCH) and makes it OK for some of the bits to be wrong.

Internally with the raw NAND this is how things work.

But: SD cards do not provide raw NAND access - there's an internal microcontroller inside each SD card that talks to the NAND on behalf of the host. The internal microcontroller is responsible for processing standard SD commands, implementing wear leveling (making sure all pages are written to evenly), and generating the correct ECC codes.

Unfortunately you can't really verify or confirm how an SD card is implementing wear leveling--or it's exact behavior under a given situation--without examining the SD card controller firmware, and this is information difficult to get.

This suggests that SD cards can report an unrecoverable ECC error to the host in response to read commands. I would venture to say that if an SD card is doing this, it means any internal wear leveling/error correction has failed and the card should not be relied on any longer.

2
  • Your distinction between "ECC codes" and "BCH codes" is incorrect and misleading. BCH codes are a type of ECC. i.e. error correcting code. "But SD does use ECC or BCH" -- That's like choosing between a fruit and an apple.
    – sawdust
    Feb 7, 2023 at 19:37
  • I've updated it.
    – LawrenceC
    Feb 9, 2023 at 15:40
1

Does an SDHC card have any write (ECC) error recovery?

Modern NAND relies heavily on ECC correction, so generally yes.

A great resource on NAND based storage devices, not just with regards to data recovery, is the NAND-Flash-Data-Recovery-Cookbook

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .