Hacking "SD Formatter" voodoo partitioning?

romanaOne

Well-Known Member
OP
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Why do special "SD Formatter" programs (currently for Mac OS X and Windows only) create strange, small gaps (~2-10MB) before or after the partition containing the filesystem?

I'm asking in this forum because I have noticed that my Supercard DSTWO seems to require SD cards formatted with this util, otherwise I get "NO FIND SYSTEM FILE" or some such Engrish ellol message.

If I just format with the Ubuntu's "Disks" application or "Disk Utility" in OS X, it uses the whole card w/o any freespace at the beginning or end.
 

TBx

New Member
Newbie
Joined
Jan 4, 2016
Messages
1
Trophies
0
XP
55
Country
United States
I imagine it's similar to TRIM for SSDs. Need some extra unused space to elongate the life of the flash memory.
 

romanaOne

Well-Known Member
OP
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
I doubt cheap (micro)SD cards (or the generic card readers in most PCs) can do any type of wear leveling. Besides, the details would vary from card to card. (Even name brand SSDs vary a lot, sometimes with disastrous results for the unsuspecting user who might think this a mature technology with standards. As a customer, you pay a big company so you can do their QC testing for them b/c they don't care.) Aaaanyway....

2MB (or the biggest gap I've seen) 4MB is not much overprovisioning for a 16GB card.

I've been looking into this and I now think the voodoo is that "SD Formatter" has a way of figuring out how to align the partition for better speed. The details of how to do this in Linux are described here under "finding page, erase block, and segment sizes."

Speed isn't just for recording video or junky flashcards: I've had FreeBSD fail to boot from a slow microSD card. (You'd want to boot FreeBSD from the SD in order to use all the SATA controllers for hard drives if you are setting up a system for network attached storage (NAS).)

For sneakernet though, I think even the dumb formatters like "Disks" and "Disk Utility" do well enough.
 

urherenow

Well-Known Member
Member
Joined
Mar 8, 2009
Messages
4,752
Trophies
2
Age
48
Location
Japan
XP
3,644
Country
United States
usually, the space at the beginning is for a backup MFT, isn't it? But Windows also takes all of the space if you make it a PRIMARY partition...
 

d0k3

3DS Homebrew Legend
Member
Joined
Dec 3, 2004
Messages
2,786
Trophies
1
XP
3,896
Country
Germany
Why do special "SD Formatter" programs (currently for Mac OS X and Windows only) create strange, small gaps (~2-10MB) before or after the partition containing the filesystem?

I'm asking in this forum because I have noticed that my Supercard DSTWO seems to require SD cards formatted with this util, otherwise I get "NO FIND SYSTEM FILE" or some such Engrish ellol message.

If I just format with the Ubuntu's "Disks" application or "Disk Utility" in OS X, it uses the whole card w/o any freespace at the beginning or end.
If you're really interested in knowing about what these gaps are, here's a recommended read:
http://wiki.laptop.org/go/How_to_Damage_a_FLASH_Storage_Device

the Supercard issue is a different one, might have to do with the file system or the cluster sizes... whatever.

And, by the way, my EmuNAND9 implements all these techniques to optimze the performance and lifetime of your SD cards :wink: :wink:.
 

romanaOne

Well-Known Member
OP
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
the Supercard issue is a different one, might have to do with the file system or the cluster sizes... whatever.

After reading the link above, I have to go home and recheck to be absolutely sure, but I think the only difference (using fdisk -l /dev/mmcblk0 to check) between partitioning+formatting with "Disks" and "SD Formatter" (Mac OS X) was the size of the partition+filesystem; Id, Type, sector size 512 were unchanged. I think.... :)
 

romanaOne

Well-Known Member
OP
Member
Joined
Apr 18, 2014
Messages
453
Trophies
0
Age
49
Location
where the potential goes to zero
XP
1,024
Country
United States
Well, it appears that Ubuntu's "Disks" formats everything (SSDs, SD cards, USB sticks) with the first partition start at block 2048.

Typical example (a 16GB card I use in DSTWO+, not DSTWO):
Code:
sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 14.9 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb847d94e

Device  Boot Start  End  Sectors  Size Id Type
/dev/mmcblk0p1  2048 31116287 31114240 14.9G  c W95 FAT32 (LBA)

I had used a friend's windows 10 computer to use the windows version of the SD formatter to format my uSD for the Supercard DSTWO and it did not even have a partition table: it mounts as /dev/mmcblck0 and fdisk -l reports nothing at all except for "Disklabel type: dos"
Ubuntu Disks says the filesystem type is FAT32 (32-bit) type b.

The article linked below says an SD data parition should start on an erase block boundary and the the FTL(controller, voodoo, whatever you wanna call it) assumes there is a FAT and gives special priority to those first couple blocks. Crazy.
Are you doing something like this (summarized here for convenience):

0. Set heads and sectors to sane (I guess) value (sudo fdisk -H 255 -S 63 -u -c /dev/mmcblk0)
1. Use flashbench to determine erase_block_size (or just guess 4MB (8192 blocks) or 8MB (16384 blocks)
2. Determine FAT_size (using dosfsck)
3. data_start_block = erase_block_size - 2*FAT_size
4. sudo mkdosfs -n NAME -s 128 -R data_start_block -v /dev/mmcblk0p1

I tried this on a well-used Sandisk Cruzer Blade 8GB USB stick. Flashbench seemed to indicate that the erase block size was 8MB, so I used 16384 for erase block size. I threw a few large files at it and there was no huge speed difference. Then I tried it with probably wrong erase block size of 8192. It seemed a little slower, but nothing to go crazy over.
All of this is for MBR + FAT32 SD cards. I wonder what to do with ext4?


EDIT: It looks like emunand9 guesses 4MB here:
Code:
#define PARTITION_ALIGN ((4 * 1024 * 1024) / 0x200) // align at 4MB

Do all (u)SD cards likely to be used in (n)3DS (eg. 8-32GB) have 4MB erase block size?

I guess so. I have 2,4,8,16 GB Sandisk and Lexar cards and they all say this when I stick them in a linux pc:
Code:
cat /sys/block/mmcblk0/device/preferred_erase_size
4194304
 
Last edited by romanaOne,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Xdqwerty @ Xdqwerty:
    also gonna install twilight menu in my r4 flashcard
  • Psionic Roshambo @ Psionic Roshambo:
    One thing that just occurred to me.... The sound on the 2600 sucked less back then the harsh sound we hear now is from infinitely better speakers we have now, back when the 2600 was new speakers produced a almost muffled sound, like CRTs made old graphics look slightly better.
  • Psionic Roshambo @ Psionic Roshambo:
    I wonder if I could recommend that to some emulation devs that perhaps the sound could use some smoothing out to simulate those old TVs
  • Psionic Roshambo @ Psionic Roshambo:
    I think a few of the early systems could benefit from that, at least up to the 8 bit generation, by the 16 bit generation I think TVs had gotten a lot better in almost every way
  • Xdqwerty @ Xdqwerty:
    i dont have an sd card adapter but I have an usb sd card adapter
  • K3Nv2 @ K3Nv2:
    Old people games
  • Xdqwerty @ Xdqwerty:
    its not the one that comes with the r4
  • Xdqwerty @ Xdqwerty:
    doesnt work (my flashcard is from r4isdhc.com)
  • Xdqwerty @ Xdqwerty:
    might install ysmenu first
  • Psionic Roshambo @ Psionic Roshambo:
    Try Wood firmware
  • Psionic Roshambo @ Psionic Roshambo:
    For your R4
  • Psionic Roshambo @ Psionic Roshambo:
    It's old but it's the best firmware out for DS stuff
  • Xdqwerty @ Xdqwerty:
    it says it only works for the original R4, R4i Gold (r4ids.cn), R4iDSN (r4idsn.com) and Acekard R.P.G.
  • Xdqwerty @ Xdqwerty:
    nvm it does support mine
  • Xdqwerty @ Xdqwerty:
    but why choose it over ysmenu @Psionic Roshambo?
  • Xdqwerty @ Xdqwerty:
    bc im stupid?
  • Xdqwerty @ Xdqwerty:
    yea ik im stupid
  • Xdqwerty @ Xdqwerty:
    good night
  • Psionic Roshambo @ Psionic Roshambo:
    Just give it a try, but honestly if you have a 3DS you can play DS games without a card just off the internal SD card
  • Psionic Roshambo @ Psionic Roshambo:
    Slightly slower loading but a bit more convenient
  • BakerMan @ BakerMan:
    guys, my fuckin headphones have an out of place speaker
  • K3Nv2 @ K3Nv2:
    Did you try wearing them?
    K3Nv2 @ K3Nv2: https://youtube.com/shorts/eJV6GaIEgd4?si=ciLPnlhfd7XcrxQn