An answer to my previous question: Making SD card corruption-proof suggested using mtd2block and formatting the SD card with yaffs2 or JFFS2.
I don't really have experience with creating images of these filesystems - we've been always using devices with manufacturer-created partitions with these. My groping in the dark got me this far:
SD reader with the card is autodetected:
[17346.289782] Initializing USB Mass Storage driver... [17346.290030] scsi2 : usb-storage 4-2:1.0 [17346.290213] usbcore: registered new interface driver usb-storage [17346.290222] USB Mass Storage support registered. [17347.292817] scsi 2:0:0:0: Direct-Access SD/MMC Card Reader 1.00 PQ: 0 ANSI: 0 [17347.293518] sd 2:0:0:0: Attached scsi generic sg3 type 0 [17347.539744] sd 2:0:0:0: [sdc] 1999872 512-byte logical blocks: (1.02 GB/976 MiB) [17347.544744] sd 2:0:0:0: [sdc] Write Protect is off [17347.544753] sd 2:0:0:0: [sdc] Mode Sense: 03 00 00 00 [17347.544761] sd 2:0:0:0: [sdc] Assuming drive cache: write through [17347.561735] sd 2:0:0:0: [sdc] Assuming drive cache: write through [17347.561745] sdc: sdc1
Then I attach block2mtd to the first partition. I'm not sure if attaching to the whole device would be better or not, I suppose the choice is moot and keeping it on partition will make the PC slightly less baffled seeing the card after it's formatted. If I'm wrong, set me straight here.
modprobe block2mtd block2mtd=/dev/sdc1,2048 [17441.290420] block2mtd: mtd0: [/dev/sdc1] erase_size = 2KiB 
Following the Yaffs2 utils page I create yaffs2 partition using a generic directory with some bogus files (actually, what I need is a blank image to serve as storage space... do I need to create a bogus file to pad the image to size, or will later tools allocate the rest of the partition to make it fit?)
The choice of yaffs2 is "because that's what we're using elsewhere already". If JFFS2 makes this significantly easier, a solution using it is completely okay.
./mkyaffs2 sd sd.raw mkyaffs2 0.2.9_20120815: image building tool for YAFFS2. stage 1: scanning directory 'sd'... [done] scanning complete, total objects: 2. stage 2: creating image 'sd.raw' [=======================================================] 2/2 100% operation complete, 2 objects in 1 NAND pages.
Then I try to write the image.
./nandwrite -a -o /dev/mtd0 ../sd.raw Writing data to block 0 at offset 0x0 libmtd: error!: MEMGETOOBSEL failed error 95 (Operation not supported) nandwrite: error!: /dev/mtd0: MTD write failure error 95 (Operation not supported) nandwrite: error!: Data was only partially written due to error error 95 (Operation not supported)
This is as far as I got. It seems mtd2block doesn't support some flags nandwrite needs, and the documentation is really laconic. Could anyone guide me how to format the SD card with yaffs2, or alternatively point me to documentation that would help in that?