Links:
http://uanr.com/mmc/
http://uanr.com/sdfloppy/
http://wiki.openwrt.org/OpenWrtDocs/Customizing/Hardware/MMC
SD->Router Pinout:
1 CS - GPIO7 (CHIP SELECT)
2 DI - GPIO5 (DATA IN)
3 VSS - ground
4 VDD - 3.3V
5 CLK - GPIO3 (CLOCK)
6 VSS2 - ground
7 DO - GPIO4 (DATA OUT)
GPIO(3,4,5,7), 2 Ground, 1 3.3v
SD WRT54G v3
1 CS GPIO7 DMZ LED
2 DI GPIO5
3 VSS GND JP2 (9)
4 VDD PWR (3.3v) JP2 (1)
5 CLK GPIO3 Amber LED
6 VSS2 GND JP2 (10)
7 DO GPIO4 Cisco SW
GPIOs
Pin Direction v2.2 v3.0 SD Card
GPIO 0 Output WLAN LED unknown n/a
GPIO 1 Output POWER LED POWER LED n/a
GPIO 2 Output ADM_EECS WHITE LED n/a
GPIO 3 Output ADM_EESK AMBER LED CLK
GPIO 4 Input ADM_EEDO FRONT BTN DO
GPIO 5 Output ADM_EEDI unknown? DI
GPIO 6 Input Reset BTN reset? n/a
GPIO 7 Output DMZ LED DMZ LED CS
--------------------------------------------------------------------------------
Linksys WRT54G (hardware version 2)
What we will do is connect an SD card reader to some of the GPIO pins of the
CPU found inside the Linksys and with the help of a little driver we can use
as a block device from Linux. This means that if you compile your kernel for
the Linksys with e.g. support for MSDOS partitions and VFAT you will be able
to mount, read, write, partition and so on your normal SD cards. The speed
obtainable for reading and writing seems to be about 200 KB/s.
6 pins will be attached to the router.
We will be driving the SD card in SPI mode, meaning that only one of the four
data out pins are used (pin 7). Obtaining the specs for driving the card in
the native SD mode is VERY costly and furthermore the limited number of GPIO
pins available inside the router also mandates the use of some sort of serial
protocol. The two VSS pins can simply be wired together for this project (VSS2
is used to control the sleep mode of the card).
wire the card to the rotuer...
--------------------------------------------------------------------------------
Software
First of all we suggest that you configure a kernel with support for MSDOS
partitions and VFAT. Partition support must be built into the kernel whereas
VFAT can be built both as a module or into the kernel. These are some things
you may want to include in your .config:
CONFIG_PARTITION_ADVANCED=y
CONFIG_MSDOS_PARTITION=y
CONFIG_FAT_FS=y
CONFIG_MSDOS_FS=y
CONFIG_VFAT_FS=y
Now get the driver (mmc.c) and the Makefile. You will need to modify the
Makefile to point to where your OpenWRT linux kernel headers are and also the
mipsel compiler location. When that is done just type make (ignore the warnings
they are ok).
The module is now ready to be inserted. Make sure a card is placed in the
reader and then load the module. Check with dmesg that everything went ok, and
hopefully you should now have some new devices in /dev/mmc/...
root@radio:~# ls -al /lib/modules/2.4.20/
-rw-r--r-- 1 root root 50616 Jan 1 00:02 fat.o
-rw-r--r-- 1 root root 12780 Jan 1 00:08 mmc.o
-rw-r--r-- 1 root root 11244 Jan 1 00:03 msdos.o
-rw-r--r-- 1 root root 19156 Jan 1 00:05 vfat.o
root@radio:~# insmod mmc
Using /lib/modules/2.4.20/mmc.o
root@radio:~# dmesg | tail -7
mmc Hardware init
mmc Card init
mmc Card init *1*
mmc Card init *2*
Size = 249856, hardsectsize = 512, sectors = 499712
Partition check:
mmca: p1
root@radio:~# insmod fat
Using /lib/modules/2.4.20/fat.o
root@radio:~# insmod msdos
Using /lib/modules/2.4.20/msdos.o
root@radio:~# mount /dev/mmc/disc0/part1 /mnt -tmsdos
root@radio:~# ls -al /mnt
drwxr-xr-x 2 root root 16384 Jan 1 1970 .
drwxr-xr-x 1 root root 0 Jan 1 00:01 ..
-rwxr-xr-x 1 root root 0 Jan 1 00:07 bossepr0.pic
-rwxr-xr-x 1 root root 22646 Jan 1 00:02 ld-uclib.so
-rwxr-xr-x 1 root root 12780 Jan 1 2000 mmc.o
-rwxr-xr-x 1 root root 1048576 Jan 1 2000 temp.bin
-rwxr-xr-x 1 root root 16777216 Jan 1 2000 temp2.bin
-rwxr-xr-x 1 root root 16777216 Jan 1 2000 temp3.bin
-rwxr-xr-x 1 root root 693 Jan 1 2000 temp4.bin
root@radio:~# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/root 896 896 0 100% /rom
/dev/mtdblock/4 2176 1580 596 73% /
/dev/mmc/disc0/part1 249728 33856 215872 14% /mnt
--------------------------------------------------------------------------------
A little help with kernel compilation
The easiest way to get a kernel running with the needed fs support is probably
by downloading OpenWRT and building the flash image. When you are familar with
this process, it is quite easy to change the settings for your kernel. Just go
to buildroot/build_mipsel/linux and type make menuconfig. Go to file systems ->
Partition Types and check "Advanced partition selection" and "PC BIOS (MSDOS
partition tables) support". In "File systems" you should also check "DOS FAT fs
support" and optionally "VFAT (Windows 95) fs support". When done just exit
saving the changed and type make dep zImage to force a rebuild of the kernel.
Then you can just rebuild your OpenWRT image and the new kernel will be included
automatically.
http://wiki.openwrt.org/ImageBuilderHowTo
http://downloads.openwrt.org/whiterussian/rc5/
--------------------------------------------------------------------------------
Backing up the old OpenWrt as a firmware image
To backup an existing OpenWrt install, use the command:
dd if=/dev/mtdblock/1 of=/tmp/firmware.trx
This will produce a pseudo-trx file containing the firmware (trx) followed by a
dump of the JFFS2 filesystem -- basically everything except the bootloader and
NVRAM. Copy this to a safe place and only restore it to a device with the same
size flash chip.
Upgrading / Restoring
To reflash from within OpenWrt you will need to use a trx file:
mtd -r write firmware.trx linux
The "-r" will force an automatic reboot after the reflashing.
--------------------------------------------------------------------------------
MultiMedia Cards (MMC) and SecureDigital Cards (SD card) are small size
factored mass storage devices.
SD cards generally measure 32 mm × 24 mm × 2.1 mm, but can be as thin as
1.4 mm, just like MMC cards (see below). Devices with SD slots can use the
thinner MMC cards, but the standard SD cards will not fit into the thinner
MMC slots. SD cards can be used directly in CompactFlash or PC Card slots with
an adapter.
SD..: 24 x 32 x 2.1 mm
MMC.: 24 x 32 x 1.4 mm
As SD slots still support MMC cards, the separately-evolved smaller MMC
variants are also compatible with SD-supporting devices. Unlike miniSD and
microSD (which are sufficiently different from SD to make mechanical adapters
impractical), RS-MMC slots maintain backward compatibility with full-sized MMC
cards, because the RS-MMC cards are simply shorter MMC cards.
All SD memory and SDIO cards are required to support the older SPI/MMC mode
which supports the slightly slower four-wire serial interface (clock, serial
in, serial out, chip select) that is compatible with SPI ports on many
microcontrollers.
Nevertheless, since the complete MMC/SD card system has to have the
functionality to work with a low cost card stack and execute tasks (at least
for the high end applications) such as error correction and standard bus
connectivity, the concept is to have a flexible card system. This means the
card can operate in different modes.
o MMC/SD card mode
o SPI mode
o Emulated SPI mode, using port pins
There are three transfer modes supported by SD: SPI mode (separate serial in
and serial out), one-bit SD mode (separate command and data channels and a
proprietary transfer format), and four-bit SD mode (uses extra pins plus some
reassigned pins) to support four bit wide parallel transfers.
Low speed cards support 0 to 400 kbit/s data rate and SPI and one-bit SD
transfer modes. High speed cards support 0 to 100 Mbit/s data rate in four-bit
mode and 0–25 Mbit/s in SPI and one-bit SD modes.
The difference between MMC and SD cards are that SD cards can operate with a
higher clock frequency. The clock range can be between 0 – 25MHz, whereas MMCs
can only operate up to 20MHz. Another difference lay in the initialization of
these cards. There need to be initialized differently, but after initialization
they behave in the same way.
Since SD card standard is newer than the MMC standard, the SD card standard
defines more commands and extends the MMC standard, so that the SD card
standard is more flexible. Another reason why the SD card is more flexible is
that the SD standard defines an interface to be used with I/O card, such as
wireless adapter, modem device etc.
The next point where these card standard differ is in the count of pins. SD
cards have more pins than MMCs. Depending in which mode they are used the pin
are used or not. Additionally SD cards have a write protect switch, which can
be used to lock the data on the card.
In MMC/SD card mode:
MultiMedia Cards use a seven pin interface in Multimedia card mode
(Command, Clock, Data and 3x Power lines). In contrast to the
MultiMedia cards SD cards use a 9 pin interface (Command, Clock,
1 or 4 Data and 3 Power lines).
In SPI mode:
Both card systems uses the same the pin interface. (ChipSelect (CS),
DataIn, DataOut, Clock and 3 Power lines).
Pin description for MMC/SD card in Card mode:
1 CD/DAT3 - Input/Output using push pull drivers
After power up this line is input with 50 kOhm pull-up. This can be
used for card detection. Relevant only for SD cards, pull-up resistor
is disabled after initialization procedure for using this line as
DATA3 line for data transfer.
2 CMD - Push Pull
This is a bi-directional line. It is a bidirectional command channel
used for card initialization and data transfer commands. The CMD
signal has two operation modes: open-drain for initialization mode and
push-pull for fast command transfer. Commands are sent from the
MultiMediaCard bus master (card host controller) to the card and
responses from the cards to the host.
3 V SS - Power supply
Supply voltage ground.
4 V DD - Power supply
Supply voltage.
5 CLK - Input
With each cycle of this signal an one bit transfer on the command and
data lines is done. The frequency may vary between zero and the maximum
clock frequency..
6 V SS2 - Power supply
Supply voltage ground.
7 DAT[0] - Input/Output using push pull drivers
DAT is a bidirectional data channel. The DAT signal operates in
push-pull mode. Only one card or the host is driving this signal at a
time. Relevant only for SD cards: On data transfer, this is line is
DATA 0.
8 DAT[1] - Input/Output using push pull drivers
On MMC card this line does not exist. Relevant only for SD cards:
On data transfer, this is line is DATA 1.
9 DAT[2] - Input/Output using push pull drivers
On MMC card this line does not exist. Relevant only for SD cards:
On data transfer, this is line is DATA 2.
Pin description for MMC/SD card in SPI mode:
1 CS - Input Chip
Select sets the card active at low level and inactive at
high level.
2 DI - Input (DATA IN)
3 V SS - Supply ground
4 V DD - Supply voltage
5 SCLK Input
Clock signal must be generated by the target system.
The card is always in slave mode.
6 V SS2 Supply ground
7 DO Output (DATA OUT)
8 Reserved, Not used
9 Reserved, Not used
Additional information:
o Data transfer width is eight (8) bit.
o Data should be output on the falling edge and must remain valid
until the next period. Rising edge means data is sampled (i.e.
read).
o Bit order requires most significant bit (MSB) to be sent out first.
o Data polarity is normal, which means a logical “1” is represented
with a high level on the data line and a logical “0” is represented
with low level.
o MultiMedia & SD cards support different voltage ranges. Initial
voltage should be 3.3V.
o Power control should be considered when creating designs using the
MultiMedia Card and/or SD Card. The ability to have software power
control of the cards makes the design more flexible and robust.
The host will have the ability to turn power to the card on or off
independent of whether the card is inserted or removed. This can help
with card initialization when there is contact bounce during card
insertion. The host waits a specified time after the card is inserted
before powering up the card and starting the initialization process.
Also, if the card goes into an unknown state, the host can cycle the
power and start the initialization process again. When card access is
unnecessary, allowing the host to power-down the bus can reduce
overall power consumption.