OpenWrt Forum Archive

Topic: Mounting 4GB SD card

The content of this topic has been archived on 23 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

i have problems to mount my 4GB SD Card, manufactor "extremememory". It works perfekt with a 512 MB SD card.

"insmod mmc" gives debug as follows:

mmc Hardware init
mmc Card init
mmc Card init *1*
mmc Card init *2*
Size = 3912704, hardsectsize = 2048, sectors = 1956352
mmca: p1
devfs_mk_dir(mmc/disc0): using old entry in dir: 80d094e0 "mmc"
devfs_register(disc): could not append to parent, err: -17
FAT: bogus logical sector size 0
VFS: Can't find a valid FAT filesystem on dev 79:01.

The strange thing is that Windows also cannot access the card, nor to format it. My digicam (Canon Ixus 50) works fine saving picutures and movies on it...

any idea?
thx

With another card reader (also on Windows XP) ist works fine too. I formated it using FAT32, but the same problem. ;(

What happens if you format it as ext2/3 in the router?

how i schould do that? I tried:  mke2fs, mkfs.ext2 and mkfs.ext3.  all of them result in segmentation fault or hanging....

mke2fs /dev/mmc/disc0/part1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1958400 inodes, 3912700 blocks
195635 blocks (5.00%) reserved for the super user
First data block=0
120 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: Segmentation fault
root@OpenWrt:~# mkf /dev/mmc/disc0/part1
mkfifo       mkfs.ext2    mkfs.ext3    mkfs.msdos   mkfs.vfat
root@OpenWrt:~# mkfs.ext2 /dev/mmc/disc0/part1
mke2fs 1.38 (30-Jun-2005)
Segmentation fault

Have you tried making a ext partition on the *entire* card (no partition table)?
How much RAM does your router have? Could it be running out of memory?

I have a WRt54G v. 4  Wlan-router. with the whiterussian RC. 5, jffs version.
I am not very familar with linux, especailly with this tiny ditriburtion, so can you tell me please exactly what i should try? (commands and required packages)

maybe i have to mount the card with specal params?

thx

I tried to make a hole ext part using fdisk: The strange thing is that 16GB are found??

Command (m for help): p

Disk /dev/mmc/disc0/part1: 16.0 GB, 16026419200 bytes
4 heads, 16 sectors/track, 122271 cylinders
Units = cylinders of 64 * 2048 = 131072 bytes

                Device Boot      Start         End      Blocks   Id  System
/dev/mmc/disc0/part1p1               1      122271    15650656    5  Extended

Check your wiring. A loose connection or a wire too long will cause signal problems and very strange behavior.

but the 512MB Card works fine?

Some cards are more sensitive than others. The 4GB card probably has a higher speed interface (high slew rate) that can cause oscillations.

Hi,
now i shortened up the wires as short as possible, but i still get error when mounting the card:

"insmod mmc" works fine, correct size is shown:

mmc Hardware init
mmc Card init
mmc Card init *1*
mmc Card init *2*
Size = 3912704, hardsectsize = 2048, sectors = 1956352
Partition check:
mmca: p1

mount gives error: " Mounting /dev/mmc/disc0/part1 on /mmc failed: Invalid argument"
and the dmesg:

FAT: bogus logical sector size 0
VFS: Can't find a valid FAT filesystem on dev 79:01.

so it is the same as before sad

Any ideas?

Now try formatting the card as ext. What happens?
Also try adding a capacitor between 3.3v and gnd as close to the card as possible. And make sure the two grounds go to the same point in the router, or there may be a ground loop.

I tried:

root@OpenWrt:~# mkfs.ext2 /dev/mmc/disc0/part1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1958400 inodes, 3912700 blocks
195635 blocks (5.00%) reserved for the super user
First data block=0
120 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: Segmentation fault


Groud wires have same lenght and are connected to same ground pin. I have no capacity here but I am afraid its another problem. Have you ever used a 4 GB SD-Card in the WRTG54 v4?

I have very similar issues with a pre-formatted 512M card on WRT54GS v1.0 (recognized card only after swapping DO and CLK, as on several
other models) here:

FAT: bogus logical sector size 0
VFS: Can't find a valid FAT filesystem on dev 79:01.

IIRC I formatted the card using FAT32.

dd'ing a couple sectors and scp'ing the dump file to my PC and hextype'ing it there shows exactly the same stuff
as when hextype'ing the card on my PC (where it mounts fine!!).

whiterussian RC5 here, too.

Hopefully further investigation will tell me what's wrong...

Now where did I put my 8M garbage SD card, pray tell?

.
.
.

Oops, just realized that I had formatted the card using ext3 (doh!), so this is most likely the problem here.
However after installing ext3 modules I get a nice OOPS when mounting the partition...

Anyway, I'll probably reformat using JFFS2 (if it makes sense!) or vfat.


Conclusion of this posting: are you sure the card has the filesystem/data content that you think it has?

Now i inserted a capacitor for buffering between ground and 3,3V directly next to the card, but the problem is still the same... do you have a 4 GB card running?

http://forum.openwrt.org/post.php?tid=6998

The mmc.o driver for OpenWrt only supports 2 GB SD cards because the byte address sent to the mmc/sd card is 32 bits, and the math used to calculate this from the block address uses a SIGNED number. Therefore, mmc.o only supports cards whose size is between -2 GB and +2 GB. I have made extensive changes to MY copy of mmc.c, and I fixed the math to support 4 GB cards. I do not have a 4 GB SD card to test this though.

My mmc driver has been optimized to leave interrupts ON where appropriate, so other sessions are not bogged down during lengthy SD card IO (such as using dd to copy a partition on the SD card). I also rewrote the SPI bitbang routines to use separate input-only and output-only subroutines, and to use word-based rather than bit-based IO, so I can output the clock and data at the same time (only 2 GPIO outputs per data bit). Input from the SD card requires 2 outputs plus an input, so it is a little slower.

I also output to both GPIO2 and GPIO5, so my driver works fine with either router wiring version. It does not take any extra time to output a clock bit plus 2 outputs to the sd card, when output an entire word to the GPIO port. My GPIO outputs are 32 bits, because testing showed this to be faster than 8-bit outputs to these ports.

There seems to be a hardware wait-state generated during GPIO output, because writing to the port is far slower than writing to RAM. Also, timing analysis shows that the SD card itself takes extra time during sequential reads or writes when it crosses an erase-block boundary. Diffierent SD cards have different timing boundaries.

Although I have not done it yet, I plan to also support using DI and DO sharing a single GPIO bit, as is commonly done using PIC microcontrollers, by tying the SD card output pin to its input pin via a resistor. My code changes will need to change the data direction on the shared GPIO pin between reads and writes to the SD card.

I turn off the WRT54G front panel amber LED before exiting from the mmc driver, so the LED doubles as a "disk access" light.

I have made numerous other small corrections to the code as well.

I am booting (pivotroot) from my SD card ext3 partition, and I also have a second partition formatted as JFFS2. In theory, the effective throughput should be faster sending COMPRESSED data over the slow bit-bang SPI bus. Because JFFS2 always does an integrity check during mount, it takes several minutes to mount, so my /etc/init.d startup script launches the mount in the background so booting can continue. The JFFS2 partition mount point is empty for several minutes after booting, until the background mount completes.

I have not yet submitted my extensive mmc.c changes, or my updated mmc.o. I plan to make more changes, but I have been using my current MUCH FASTER version since March 2006, with no glitches or other problems, so I should probably submit my current mmc driver as-is.

Where do I submit an updated mmc driver?

BTW, I discovered that an SD card plugs nicely into a floppy edge-connector (many of which are unused in most computers). All the MMC pins line up good, but the unused SD-only pins do not align. I use a small piece of plastic inserted into the connector to fill the unused pins and help align the card during insertion. I have a nice set of photos that show assembling and using this connector for mmc.

SD floppy details here:
http://uanr.com/sdfloppy/

Nice to see someone working on it. Can you please figure out how to read the write protect switch and handle hotswapping?

That's awesome. but where can I download the updated mmc driver

The write protect switch is a mechanical switch in an SD socket. The easy way to read it is to connect the switch pins across a switch in the router (i.e. reset switch or front panel switch). Then the device driver needs to know that it should use that switch as a write protect...

Regarding when the driver will be finished, I am reconstructing source code in my "spare" time, from various backup copies (XP ate it and many other files during a bootup scandisk after a system lockup -- thanks Microsoft)...   ;-(  I hope to be finished soon (a matter of days).

I lost some more code when I did a "tar -zcvf" when I meant to do a "tar -zxvf" -- thanks Linux...  ;-(

I do have an mmc.o that I have been using since February in one of my routers, and it is quite stable. I suppose I could release the binary only for now...

Instead of needing the mmc.o device driver handling the SD socket write-protect switch, perhaps the script that mounts the mmc device should decide whether to mount it "rw" (read-write) or "ro" (read-only), by checking the switch (with the GPIO utility). This would save needing to have a custom mmc.o driver module that handles the switch and the complexity of handling writes to a "read-only" device that Linux thinks is writable...

BTW, I added descriptions to the images on my web page, to answer questions I read on various message boards. The text is redundant though -- there are links to my webpage from all over the world, in multiple languages, and I have gotten hits from MANY countries (just since yesterday).

During my "15 minutes of fame" period, I was getting so much traffic (over 2 GB/hr), that my web host suspended my page. I had to switch providers, leaving my page down for several days.

   http://uanr.com/sdfloppy/

I will have the updated MMC driver available (which leaves interrupts ON while waiting for SD card ready, plus much faster port I/O, etc.), "Real Soon Now"... I am doing "source code reconstruction" due to a hard drive crash, with literally MANY hundreds of unindexed DVDs and CDs, containing various backups from my stack of 250 GB drives...  ;-) & ;-(

Robwen: When will you be posting your version of the driver?

Are you finished with mmc.c driver yet? can you post it please.

I sent an email to this guy, but he doesn't seem to respond to it. A dead shame!

remmeber the link to speedup the transfare rate to 300Kb/s? the link does not work! can someone repost that mmc.c?

Thank you

The discussion might have continued from here.