OpenWrt Forum Archive

Topic: [Howto] Compile the MMC driver (module) for the SD card mod

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.

Compile the MMC driver (module) for the SD card mod


This should describe howto compile and include the MMC driver in OpenWrt WhiteRussian

1. Build OpenWrt WhiteRussian
2. Compile the mmc driver


Ok, let's start.

1. How to build OpenWrt with the free VMware player on Windows is described in another howto.

Run 'make menuconfig' and select Kernel Configuration / Device Support ->
<*> VFAT filesystem support -- (fat.o, vfat.o), creates the kmod-vfat package
<*> MSDOS filesystem support -- (msdos.o), creates the kmod-msdos package

Now continue building OpenWrt WhiteRussian. Simply run 'make world'. After the build process finished flash the image to your router.


2. It is time to compile the MMC driver kernel module. It is nothing magic here.

2.1. Create a directory for the driver

cd ~/whiterussian
mkdir mmc

2.2. Download the driver source code (mmc.c) and the its Makefile

cd ~/whiterussian/mmc
wget http://kiel.kool.dk/mmc.c
wget http://kiel.kool.dk/Makefile

2.3. Next edit the Makefile. If you used my howto to build WhiteRussian you can patch the Makefile. Save the following patch as Makefile.patch (fix the spaces and convert them into tabs).

--- Makefile.orig    2006-12-11 18:00:00.000000000 +0100
+++ Makefile    2006-12-11 18:17:23.000000000 +0100
@@ -1,7 +1,12 @@
 TARGET  := mmc
 WARN    := -W -Wall -Wstrict-prototypes -Wmissing-prototypes -fno-strict-aliasing -mips32
-INCLUDE := -isystem /home/rohde/buildroot/build_mipsel/linux/include 
+INCLUDE := -isystem /home/ubuntu/whiterussian/build_mipsel/linux-2.4-brcm/linux-2.4.30/include
 CFLAGS  := -O2 -DMODULE -D__KERNEL__ ${WARN} ${INCLUDE} -fno-pic -mno-abicalls -mlong-calls
-CC      := /home/rohde/develop/buildroot/build_mipsel/staging_dir/bin/mipsel-linux-uclibc-gcc
+CC      := /home/ubuntu/whiterussian/staging_dir_mipsel/bin/mipsel-linux-uclibc-gcc
 
-${TARGET}.o: ${TARGET}.c
+
+all:
+        $(CC) ${CFLAGS} -c -o ${TARGET}.o ${TARGET}.c
+
+clean:
+        rm -f mmc.o

2.4. Apply the patch:

cd ~/whiterussian/mmc
patch -p0 < Makefile.patch

2.5. Next step is to edit mmc.c and adjust the 4 required GPIO lines. You have to change the hex value at the end of the following four lines in mmc.c

#define SD_DI 0x20
#define SD_DO 0x10
#define SD_CLK 0x08
#define SD_CS 0x80

Here is a list with the GPIOs and its hex values:
GPIO PIN 0: 0x01
GPIO PIN 1: 0x02
GPIO PIN 2: 0x04
GPIO PIN 3: 0x08
GPIO PIN 4: 0x10
GPIO PIN 5: 0x20
GPIO PIN 6: 0x40
GPIO PIN 7: 0x80
GPIO PIN 8: 0x100
GPIO PIN 9: 0x200
GPIO PIN 10: 0x400
GPIO PIN 11: 0x800
GPIO PIN 12: 0x1000
GPIO PIN 13: 0x2000
GPIO PIN 14: 0x4000
GPIO PIN 15: 0x8000

2.6. Compile the driver with make (you can ignore the warnings) and copy mmc.o to the ~/public_html directory

cd ~/whiterussian/mmc
make clean all
cp -fpR mmc.o ~/public_html

Now, the driver is ready. A new file exists in the directory, mmc.o. You can check it with 'file mmc.o' if the file is correctly cross-compiled.

2.7. On the router create /etc/modules.d/20-mmc to automatically load the driver

echo "mmc" > /etc/modules.d/20-mmc

2.8. Transfer the driver to your router (use wget or whatever)

cd /lib/modules/2.4.30
wget http://ubuntu/~ubuntu/mmc.o

2.9. Reboot the router and 'lsmod' should show the MMC driver loaded

I worte a guide for changing mini_fo's storage directory (/jffs) to external media like MMC/SD card or USB stick. No more need to mess around with environment variables for libraries.

Also look at:
- Changing mini_fo's storage directory (/jffs on external media)
- kiel.kool.dk
- OpenWrtDocs/Customizing/Hardware/MMC

(Last edited by forum2006 on 21 May 2007, 10:19)

using /proc/diag/gpiomask to mask the GPIOs used by the MMC driver

Linksys WRT54GL
mmc.c:

/* for WRT54GL */
#define SD_DI 0x04  // GPIO 2
#define SD_DO 0x10  // GPIO 4
#define SD_CLK 0x08 // GPIO 3
#define SD_CS 0x80  // GPIO 7

Alright, I found a solution how to calculate the hex values. You have to use bitwise left shift. This makes it clear. Use this calculator.

For the example above we have:

1 << 2 =   4
1 << 3 =   8
1 << 4 =  16
1 << 7 = 128
         ---
         156 in hex is 0x9c

Create a init script e.g. /etc/init.d/S30gpiomask and make it executable:

echo "0x9c" > /proc/diag/gpiomask

(Last edited by forum2006 on 11 Dec 2006, 13:24)

The GPIO utility

Use the GPIO utility for finding/testing GPIO solder points. No idea how it works.

Maybe someone can write up notes here how to use the GPIO utility...

Use the GPIO utility at your own risk!

(Last edited by forum2006 on 17 Dec 2006, 12:48)

I'm using GPIO utility to find I/O in my Buffalo WHR-G54S AP
it's quite easy to use it, syntax:
gpio <poll | enable | disable> <pin>

where ENABLE/DISABLE are I/O levels you want to raise into your MoBo, PIN is the GPIO you're looking for. For example:
gpio disable 7    turns my DIAG light on
gpio enable 7    turns my DIAG light off

you can think of an odd response (when i try enable i want led on) but it's working and it's not so bad, i've created a bash script to generate a square wave so my O'scope can find it easily, i'm trying to find two additional IO for a serial port on Buffalo APs
Have fun

Ben

I added a SD card to my WRT54GL however every time I loaded the mmc module or read/wrote to the card, I would get numerous hotplug button processes.  Adding the correct gpiomask corrected the problem but I need to use a script containing the following:

echo 9c > /proc/diag/gpiomask

and NOT

echo "0x9c" > /proc/diag/gpiomask

One can check that the mask is set to the expected value with 'cat /proc/diag/gpiomask'.  It should show the correct decimal number (in this case 156).

(Last edited by jvl001 on 7 Jan 2007, 05:14)

ben72 wrote:

I'm using GPIO utility to find I/O in my Buffalo WHR-G54S AP
it's quite easy to use it, syntax:
gpio <poll | enable | disable> <pin>

where ENABLE/DISABLE are I/O levels you want to raise into your MoBo, PIN is the GPIO you're looking for. For example:
gpio disable 7    turns my DIAG light on
gpio enable 7    turns my DIAG light off

you can think of an odd response (when i try enable i want led on) but it's working and it's not so bad, i've created a bash script to generate a square wave so my O'scope can find it easily, i'm trying to find two additional IO for a serial port on Buffalo APs
Have fun

Ben

Can you publish some foto with location GPIO on WHR-G54S? Please

Just finished porting and photos, i've set two WHR-G54S APs with SD/MMC hack, give me some days (i'm far from home) and i'll rip down some notes on Wiki page

Andrea (Ben) Benini

i will wait, thanks!

Does this work with SD cards as well was MMC cards?
And does it use the SPI mod?
The reason I was wondering is I am trying to get an SD card working with a PXA255 SBC under 2.4 and I was hoping this might get it up and working.
Thanks

hello folks ,

with a little help from my  friends i get the SD card build in my WRT:

http://farm3.static.flickr.com/2046/173 … 1e8e_b.jpg
http://farm3.static.flickr.com/2360/173 … 310a_b.jpg

i saw the Site with the SD  driver and make file dissapeard so i copyed it on my server:

Compile the MMC driver (module) for the SD card mod

2.2. Download the driver source code (mmc.c) and the its Makefile

cd ~/whiterussian/mmc
wget http://www.lettv.de/mmc.c
wget http://www.lettv.de/Makefile

bye for now

http://www.lettv.de/WRt54G_SD.html

(Last edited by macbroadcast on 6 Nov 2007, 03:46)

hi folks

what does this errors mean ? Is the driver not working or installed ?

  _______                     ________        __
|       |.-----.-----.-----.|  |  |  |.----.|  |_
|   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
|_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
WHITE RUSSIAN (0.9) -------------------------------
  * 2 oz Vodka   Mix the Vodka and Kahlua together
  * 1 oz Kahlua  over ice, then float the cream or
  * 1/2oz cream  milk on the top.
---------------------------------------------------
root@OpenWrt:~# insmod mmc
Using /lib/modules/2.4.30/mmc.o
insmod: A module named mmc already exists
root@OpenWrt:~# rmmod mmc
root@OpenWrt:~# insmod mmc
Using /lib/modules/2.4.30/mmc.o
root@OpenWrt:~# dmesg
CPU revision is: 00029007
Primary instruction cache 8kB, physically tagged, 2-way, linesize 16 bytes.
Primary data cache 4kB, 2-way, linesize 16 bytes.
Linux version 2.4.30 (nbd@ds10) (gcc version 3.4.4 (OpenWrt-1.0)) #1 Sat Feb 3 13:16:08 CET 2007
Setting the PFC value as 0x15
Determined physical RAM map:
memory: 01000000 @ 00000000 (usable)
On node 0 totalpages: 4096
zone(0): 4096 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: root=/dev/mtdblock2 rootfstype=squashfs,jffs2 init=/etc/preinit noinitrd console=ttyS0,115200
CPU: BCM4712 rev 1 at 200 MHz
Using 100.000 MHz high precision timer.
Calibrating delay loop... 199.47 BogoMIPS
Memory: 14228k/16384k available (1455k kernel code, 2156k reserved, 104k data, 80k init, 0k highmem)
Dentry cache hash table entries: 2048 (order: 2, 16384 bytes)
Inode cache hash table entries: 1024 (order: 1, 8192 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 4096 (order: 2, 16384 bytes)
Checking for 'wait' instruction...  unavailable.
POSIX conformance testing by UNIFIX
PCI: Fixing up bus 0
PCI: Fixing up bridge
PCI: Setting latency timer of device 01:00.0 to 64
PCI: Fixing up bus 1
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
Registering mini_fo version $Id$
devfs: v1.12c (20020818) Richard Gooch (rgooch@atnf.csiro.au)
devfs: boot_options: 0x1
JFFS2 version 2.1. (C) 2001 Red Hat, Inc., designed by Axis Communications AB.
Squashfs 2.1-r2 (released 2004/12/15) (C) 2002-2004 Phillip Lougher
pty: 256 Unix98 ptys configured
Serial driver version 5.05c (2001-07-08) with MANY_PORTS SHARE_IRQ SERIAL_PCI enabled
ttyS00 at 0xb8000300 (irq = 3) is a 16550A
ttyS01 at 0xb8000400 (irq = 0) is a 16550A
b44.c:v0.93 (Mar, 2004)
PCI: Setting latency timer of device 00:02.0 to 64
eth0: Broadcom 47xx 10/100BaseT Ethernet 00:0f:66:a7:2d:48
Physically mapped flash: Found an alias at 0x400000 for the chip at 0x0
Physically mapped flash: Found an alias at 0x800000 for the chip at 0x0
Physically mapped flash: Found an alias at 0xc00000 for the chip at 0x0
Physically mapped flash: Found an alias at 0x1000000 for the chip at 0x0
Physically mapped flash: Found an alias at 0x1400000 for the chip at 0x0
Physically mapped flash: Found an alias at 0x1800000 for the chip at 0x0
Physically mapped flash: Found an alias at 0x1c00000 for the chip at 0x0
cfi_cmdset_0001: Erase suspend on write enabled
0: offset=0x0,size=0x2000,blocks=8
1: offset=0x10000,size=0x10000,blocks=63
Using word write method
Flash device: 0x400000 at 0x1c000000
bootloader size: 262144
Physically mapped flash: Filesystem type: squashfs, size=0xfb158
Creating 5 MTD partitions on "Physically mapped flash":
0x00000000-0x00040000 : "cfe"
0x00040000-0x003f0000 : "linux"
0x000be400-0x001c0000 : "rootfs"
mtd: partition "rootfs" doesn't start on an erase block boundary -- force read-only
0x003f0000-0x00400000 : "nvram"
0x001c0000-0x003f0000 : "OpenWrt"
Initializing Cryptographic API
NET4: Linux TCP/IP 1.0 for NET4.0
IP Protocols: ICMP, UDP, TCP, IGMP
IP: routing cache hash table of 512 buckets, 4Kbytes
TCP: Hash tables configured (established 1024 bind 2048)
ip_conntrack version 2.1 (5953 buckets, 5953 max) - 332 bytes per conntrack
ip_tables: (C) 2000-2002 Netfilter core team
NET4: Unix domain sockets 1.0/SMP for Linux NET4.0.
NET4: Ethernet Bridge 008 for NET4.0
802.1Q VLAN Support v1.8 Ben Greear <greearb@candelatech.com>
All bugs added by David S. Miller <davem@redhat.com>
VFS: Mounted root (squashfs filesystem) readonly.
Mounted devfs on /dev
Freeing unused kernel memory: 80k freed
Algorithmics/MIPS FPU Emulator v1.5
diag: Detected 'Linksys WRT54G/GS/GL'
Probing device eth0: No Robo switch in managed mode found
Probing device eth1: No such device
Probing device eth2: No such device
Probing device eth3: No such device
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
mini_fo: using base directory: /
mini_fo: using storage directory: /jffs
jffs2.bbc: SIZE compression mode activated.
PCI: Setting latency timer of device 00:01.0 to 64
eth1: Broadcom BCM4320 802.11 Wireless Controller 3.90.37.0
Journalled Block Device driver loaded
Probing device eth0: No Robo switch in managed mode found
Probing device eth1: [switch-robo.c:90] SIOCGETCPHYRD failed!
[switch-robo.c:90] SIOCGETCPHYRD failed!
No Robo switch in managed mode found
Probing device eth2: No such device
Probing device eth3: No such device
usb.c: registered new driver usbdevfs
usb.c: registered new driver hub
SCSI subsystem driver Revision: 1.00
Initializing USB Mass Storage driver...
usb.c: registered new driver usb-storage
USB Mass Storage support registered.
device eth0 entered promiscuous mode
b44: eth0: Link is up at 100 Mbps, full duplex.
b44: eth0: Flow control is off for TX and off for RX.
vlan0: add 01:00:5e:00:00:01 mcast address to master interface
vlan0: dev_set_promiscuity(master, 1)
vlan0: dev_set_allmulti(master, 1)
device eth1 entered promiscuous mode
br0: port 2(eth1) entering learning state
br0: port 1(vlan0) entering learning state
br0: port 2(eth1) entering forwarding state
br0: topology change detected, propagating
br0: port 1(vlan0) entering forwarding state
br0: topology change detected, propagating
vlan1: add 01:00:5e:00:00:01 mcast address to master interface
[INFO] mmc_hardware_init: initializing GPIOs
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 524 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 43602 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[INFO] mmc_card_init: the period of a 380KHz frequency lasts 524 CPU cycles
[INFO] mmc_card_init: powering card on. sending 80 CLK
[INFO] mmc_card_init: 80 CLK sent in 43267 CPU cycles
[INFO] mmc_card_init: resetting card (CMD0)
[FATAL] mmc_card_init: invalid response from card: ff found, waiting for 01
[ERROR] mmc_init: got an error calling mmc_card_init: 01
[ERROR] mmc_check_media: change detected but was not able to initialize new card: ffffffff


thanks

(Last edited by macbroadcast on 13 Nov 2007, 00:06)

The discussion might have continued from here.