3 ms·
Yes USB drive and SD card firmware is just crap as with any embedded software... Firmware is always crap... That said, NAND Flash storage is quirky. Individual
by numpad0 7y ago
Yes USB drive and SD card firmware is just crap as with any embedded software... Firmware is always crap... That said, NAND Flash storage is quirky.
Individual bits on a NAND flash can be addressed or read out in kB "page". Each pages can be "programmed" aka written to, by repeatedly applying desired bit patterns (0b11001001 ... 0b11001001 ... and it sticks). Bits can only be set by writes, not unset. "Depth" of write can be deepened for longer storage or can be used to represent multiple state in the same bit(e.g. 0V means zero, 0.5V means one, 1.0V means two ... that's ternary). State of the art of multi-level write is something like 256 or 1024 levels per cell(bit).
Above is for read and write operations. As said, write ops can set bits, but cannot unset(0b0010 can be overwritten to 0b1111 but not 0b1101). So, in real life, all data in the page is wiped clean before writing. However in erasing context, erase operations take "blocks", of dozens of "pages" together in few MB size where you'd love to specify individual cells or pages. This means a one byte change in a file on a disk necessitate few MB worth of erase. To make it even worse, one cell of the flash lasts only up to 10k program-erase cycles on ancient chips or could be little as 300 cycles on modern designs. Clearly a naive approach destroys NAND way faster that what is commercially acceptable pace. Error margins are even worse, I've read that ECC correction is part of normal read operations or something.
Concerning all these quirks combined, clearly the flash chip interfaces cannot be directly exposed to OS driver, disk LBA addresses cannot be linearly mapped to chip banks in the ways DIP EEPROMs might have been wired in the 80s. Write ops must be cached to minimize reprogramming, and also must be constantly redirected to least used areas. Erase ops must be substituted by marking pages safe to discard. Defragmentation must be handled disk-local to avoid stray active pages scattering. These features called Wear Leveling are present on virtually any flash storage devices, since around high capacity cards started to exceed 16GB in size. From then, the controllers grew to support MLC/TLC/QLC technology(256 level per bit thing) or DRAM-less SLC caching(use part of TLC/QLC chip as SLC as substitute for DRAM write cache - used to be multiple GB of DDR3 in itself at one point) etc etc.
In short, you're completely right that SD cards and USB sticks are "not disks". Large erase units and low endurance of NAND chips, that necessitate intricate nursing, is what makes them "not".
(I'm only a PC nerd, not a NAND expert. Especially numbers above are through my Google-fu so can be off)