Once upon a time, many years ago, I was paid to retrieve a set of graduation photos and videos from a SD card for a rather distraught mother. Upon close inspection, the card had somehow been physically damaged with a visible crack in the outer case and had several bad sectors, most notably several early, critical sectors, which made even the most reliable recovery programs at the time completely fail to read the card. Also, forensic data tools back then cost a fortune.
I ended up obtaining an identical brand/size SD card and writing my own custom raw data dump and restore utility to copy the data from the bad card to the good one. Every time the utility hit a bad sector, it would retry a number of times before writing all zeroes for that sector and, instead of giving up and stopping, ignore the failure and move on to the next sector. The retry attempts were made since I had also noticed that some sectors still had around a 40% read success rate. Once the data was on the new SD card, the recovery tools that had failed before worked flawlessly with minimal data loss/corruption. Overall, about 98% of all of the files were recovered. A number of items that had been previously deleted were also recovered because nothing is ever actually deleted - just marked as such and slowly overwritten. What started out as a slightly boring data recovery exercise became one of my more memorable and interesting personal software development projects. In case you were wondering, the mother was thrilled.
At any rate, this story goes to show that it is possible to physically damage a SD card such that data is still accessible but has sectors that are only barely functioning and anything attempting to read from it has difficulties doing so. SD card plastic tends to be pretty flimsy, so bending or cutting into some cheap ones might do the trick. Your mileage may vary.
You could also ask around at some data recovery places in your area. Since they specialize in data recovery from various failing or failed devices, they should have some useful input/tips and might even have some pre-busted SD cards on hand (e.g. for training purposes) that you could obtain from them.
20Can you change the low-level SD driver to pretend there is a bad block, or is that out of the question? – None – 2017-09-11T19:39:38.067
3@MarkYisri, I don't think the driver is very accessible. Whatever driver we are using is ultra-rudimentary to maximize memory allocation to the rest of the firmware. Also, if it was possible, that would likely be beyond my capability. – Gabe Krause – 2017-09-11T20:51:09.117
3Can you build an SD card emulator? Not the simplest project, mind you. – user253751 – 2017-09-12T00:03:51.737
11Given the goal, you could buy some second-hand SD cards for little money and you may easily get a faulty one, or put an "looking for..." announce to specifically look for faulty cards. Or search eBay for defective cards. Then you test the card and you'll know the position of the defective areas. – FarO – 2017-09-12T09:18:54.980
Presumably your SD card read functionality is wrapped in an abstraction layer? If so, insert some test s/w into that – Mawg says reinstate Monica – 2017-09-12T09:21:17.463
28Ask any professional photographer. They'll have a pile of sketchy SD cards, surely. – J... – 2017-09-12T10:56:36.347
1Get a raspberry pi; they're notorious for breaking sd cards. Write a script to just write and delete files to it over and over. – None – 2017-09-12T14:15:49.723
2Perhaps you could contact an SD card vendor and ask them if you can buy bad SD cards along with information on which sectors are bad on each faulty card? – Kevin – 2017-09-12T17:57:01.470
2I have one that does that itself constantly. Want it? – T.E.D. – 2017-09-12T19:21:48.220
2
I feel like this is an XY Problem
– jkd – 2017-09-13T22:55:11.0701@Mehrdad Actually you are not that far off. Not sure if this is still true with the latest flash media, but it used to be that if you removed power at just the right point (during a flash write) you would lose the entire erase block. Industrial grade devices would have a capacitor to allow any write in progress to complete when power was lost to protect against this failure mode. – Michael – 2017-09-15T20:48:39.543
1The cheapest no-name ones off Amazon usually don't last long if they even work at all – Mark K Cowan – 2017-09-19T16:25:20.397
Icepick? Electrostatic discharge? Carefully targeted drill? What do you mean that's not the kind of breaking you were thinking of? – Kaithar – 2017-09-20T08:39:43.047
1Yes, @jakekimdsΨ, this is definitely an XY Problem. What OP really needs is a good test environment for their code, what they think they want is bad SD cards (which there are plenty of people offering). OP is going to have to provide more information on their development environment for us to get them a real solution. – NH. – 2017-09-25T14:51:30.867
You're right. We need a better test environment. But I never requested bad SD cards, in general. Randomly bad cards are not going to contribute to a repeatable testing procedure in a reasonable time frame. I needed to test a known bad sector, which we have since learned is near impossible with built-in SD wear balancing. The right answer (for me) is most likely to be a controllable hardware interface between SD and Device to be tested. But I hesitate to select that as the Right Answer because there are several great solutions posed here for different environments. – Gabe Krause – 2017-09-25T19:28:42.737