# [Solved] SD cardr only work if card is inserted before boot

## brianhsu

Hardware Info:

Laptop Model: Sony Vaio Pro 13 

Problematic Hardware: Bulti-in Realtek Semiconductor Co., Ltd. RTS5209 PCI Express Card Reader 

Problem description:

Here is the problem, if I boot with my SD card inserted into the card reader, my Gentoo correctly load kernel module and detected SD card, assigned it to /dev/mmcblk0 according to dmesg output, XFCE also show an SD icon on desktop so I could mount it without any problem.

But if I boot without any SD card in card reader instead, and insert SD card after boot nothing happened. No SD card been detected, dmesg shows nothing.

Since SystemRescueCD (which is also based on Gentoo) correctly work as expected (boot without SD card inserted, insert SD card after boot, SystemResuceCD could detected it correctly and assign it to /dev/mmcblock0. So I guess I must miss some configuration on my Gentoo.  

What have I tried:

I tried to compare lsmod output from both configuration, and found if I boot with SD card inserted, the following additional kernel module will be loaded. 

```

rtsx_pci_sdmmc         13679  0 

rtsx_pci_ms             7218  0 

mmc_core               91689  2 mmc_block,rtsx_pci_sdmmc

memstick                6896  1 rtsx_pci_ms

rtsx_pci               31487  2 rtsx_pci_ms,rtsx_pci_sdmmc

```

I also confirmed these module been loaded after I insert my SD card into card reader when I using SystemRescueCD.

I also tried load these module manually on my Gentoo system, but nothing happens after I load them, no new print out in dmesg. 

lspci output:

```
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 09)

00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)

00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 09)

00:14.0 USB controller: Intel Corporation 8 Series USB xHCI HC (rev 04)

00:16.0 Communication controller: Intel Corporation 8 Series HECI #0 (rev 04)

00:1b.0 Audio device: Intel Corporation 8 Series HD Audio Controller (rev 04)

00:1c.0 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 3 (rev e4)

00:1c.3 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 4 (rev e4)

00:1c.4 PCI bridge: Intel Corporation 8 Series PCI Express Root Port 6 (rev e4)

00:1d.0 USB controller: Intel Corporation 8 Series USB EHCI #1 (rev 04)

00:1f.0 ISA bridge: Intel Corporation 8 Series LPC Controller (rev 04)

00:1f.3 SMBus: Intel Corporation 8 Series SMBus Controller (rev 04)

01:00.0 Network controller: Intel Corporation Wireless 7260 (rev 6b)

02:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. RTS5209 PCI Express Card Reader (rev 01)

03:00.0 SATA controller: Samsung Electronics Co Ltd XP941 PCIe SSD (rev 01)

```

Kernel configuration:

1. Everything inside MMC/SD/SDIO card support (except MMC debugging / MMC host clock gating / MMC host test driver) is compiled as kernel module.

2. CONFIG_MEMSTICK=m

3. CONFIG_MEMSTICK_REALTEK_PCI=m

I'm totally stuck and have no idea what next step should I take to fix this problem, where should I check now?Last edited by brianhsu on Fri Jun 06, 2014 9:19 am; edited 1 time in total

----------

## i92guboj

Did you try building it into the kernel OR putting those modules into /etc/conf.d/modules?

----------

## brianhsu

 *i92guboj wrote:*   

> Did you try building it into the kernel OR putting those modules into /etc/conf.d/modules?

 

Yes, but has no luck. Both method still only show mmcblk0 if I insert SD card before boot.   :Sad: 

I will try switch to genkernel instead of manually configured kernel to see if it can solve this problem.

----------

## i92guboj

The kernel is detecting the memory reader, and the modules are being loaded, so I don't think the problem is there.

It might be your device hotplugger, whatever that is. Do you use the standard udev or something else (eudev, mdev...)?

Try running this as root in an xterm or whatever term emulator you prefer, and then try plugging in the card:

```
$ udevadm monitor
```

Do you get any output?

----------

## brianhsu

 *i92guboj wrote:*   

> The kernel is detecting the memory reader, and the modules are being loaded, so I don't think the problem is there.
> 
> It might be your device hotplugger, whatever that is. Do you use the standard udev or something else (eudev, mdev...)?
> 
> 

 

I use default sys-fs/udev come from clean install, the following related package is installed:

```

VaioPro13 ~ # equery list '*udev*'

 * Searching for *udev* ...

[IP-] [  ] sys-fs/udev-213:0

[IP-] [  ] sys-fs/udev-init-scripts-26-r2:0

[IP-] [  ] virtual/libgudev-208:0/0

[IP-] [  ] virtual/libudev-208:0/1

[IP-] [  ] virtual/udev-208-r2:0

```

Use flag on sys-dev/udev:

```

[ebuild   R    ] sys-fs/udev-213  USE="acl firmware-loader gudev kmod -doc -introspection (-selinux) -static-libs" ABI_X86="(64) -32 (-x32)" 0 kB

[ebuild   R    ] virtual/udev-208-r2  USE="gudev -introspection -static-libs" ABI_X86="(64) -32 (-x32)" 0 kB

```

 *Quote:*   

> 
> 
> Try running this as root in an xterm or whatever term emulator you prefer, and then try plugging in the card:
> 
> ```
> ...

 

No any output if I boot without SD card in card reader slot.

But if I boot with SD card in card slot, and then remove sd card from it, it will shows the following output:

```

KERNEL[396.221432] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368/block/mmcblk0/mmcblk0p1 (block)

KERNEL[396.221455] remove   /devices/virtual/bdi/179:0 (bdi)

KERNEL[396.221578] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368/block/mmcblk0 (block)

KERNEL[396.221610] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368 (mmc)

UDEV  [396.222186] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368/block/mmcblk0/mmcblk0p1 (block)

UDEV  [396.222214] remove   /devices/virtual/bdi/179:0 (bdi)

UDEV  [396.222360] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368/block/mmcblk0 (block)

UDEV  [396.222547] remove   /devices/pci0000:00/0000:00:1c.3/0000:02:00.0/rtsx_pci_sdmmc.0/mmc_host/mmc0/mmc0:b368 (mmc)

```

----------

## i92guboj

Mmm this drives me to think that udev fails to register the memory bay.

What happens if you restart the udev service after inserting the card? Does it pick it then?

If so, it's clearly an issue with udev.

Note that your desktop might not like you restarting that daemon. So if you use any of the big desktops I advise doing that from outside X

----------

## brianhsu

 *i92guboj wrote:*   

> What happens if you restart the udev service after inserting the card? Does it pick it then?

 

Still nothing happens, no output in both udevadm and dmesg.

Another thing I noticed is that I will got the following output in dmesg when I boot with SD card inserted.

```

[    3.834717] mmc0: new high speed SDHC card at address b368

[    3.836213] mmcblk0: mmc0:b368 00001 3.73 GiB 

[    3.837117]  mmcblk0: p1

```

But these message will not display if I do the following step:

1. Boot without SD card

2. Insert SD card into card reader

3. modprobe all those related module

I've also tried downgrade my udev to 208 (which is the same version on SystemRescueCD) or switch to eudev, but still not working.

----------

## i92guboj

Maybe the order in which the m9dules are loaded matters?

Your kernel seems to see the card before it actually sees the card reader.

----------

## brianhsu

 *i92guboj wrote:*   

> Maybe the order in which the m9dules are loaded matters?
> 
> Your kernel seems to see the card before it actually sees the card reader.

 

Confirmed I miss something when configuration my kernel.

I pulled /proc/config.gz and use it to build kernel, everything is working correctly now.   :Wink: 

Now I only need to find out which configruation caused this strange behavior.

Update:

Figure out that I should enable the following kernel configurtion:

CONFIG_HOTPLUG_PCIE=y

CONFIG_HOTPLUG_PCI=y

CONFIG_HOTPLUG_PCI_ACPI=y

After added these three configuration based to my old config, everything is working as expected.

----------

