如何让 Android 自动挂载 SD 卡

1. History about mountd and vold.
a.   in older version, Android use mountd daemon to manage SD card.
b.   from cupcake version, vold is used.
from the cupcake source code, there is mountd folder in /system/core source code.
but from the Android.mk, we can see mountd is not built by default, 
and from the comment, we can see vold replaces mountd.
# disabled - we are using vold now instead
# include $(BUILD_EXECUTABLE)
c.  in eclair version, there is no mountd source code in /system/core.

2. Pre-condition.
we need make sure SD card can be mounted manually.
a.  firstly, make sure the feature is supported in kernel layer.
b.   we can use mount command to mount or umount the SD card.
the below is a example.
mount -t vfat /dev/block/mmcblk0p1 /sdcard

3. uevent format.
for vold daemon, it receives uevent from kernel space. and the below function processes block device related event.
/system/core/vold/uevent.c: handle_block_event().
it requests specific event format, and it is not compatible with the old userspace tools.
so we need disable the below option in kernel configuration.
General Setup -> Create deprecated sysfs layout for older userspace tools
it is very important, if the above option is enable, v->dev will be none, and the log shows "Cannot start volume /sdard (volume is not bound)"
    } else if (v->media_type == media_mmc) {
        if (!v->dev) {
            LOGE("Cannot start volume '%s' (volume is not bound)", mount_point);
            pthread_mutex_unlock(&v->lock);
            return -ENOENT;
        }

        if (_volmgr_consider_disk_and_vol(v, v->dev->disk) < 0) {
            LOGE("volmgr failed to start volume '%s'", v->mount_point);
        }
    }

the below is my log for this issue:
/ARMAssembler(  823): generated scanline__00000077:03515105_00000A01_00000000 [ 42 ipp] (63 ins) at [0x342098:0x342194] in 213623 ns
D/vold    (  803): [UEVENT] Sq: 770 S: uids A: 0 P: /kernel/uids/10016
D/vold    (  803): DEVPATH=/kernel/uids/10016
D/vold    (  803): No uevent handlers registered for 'uids' subsystem
I/ActivityManager(  823): Start proc com.android.bluetooth for broadcast com.android.bluetooth/.opp.BluetoothOppReceiver: pid=917 uid=10016}
D/vold    (  803): Accepted connection from framework
D/vold    (  803): dispatch_cmd(send_ums_status):
D/vold    (  803): dispatch_cmd(mount_volume:/sdcard):
E/vold    (  803): Cannot start volume '/sdcard' (volume is not bound)
D/MountListener(  823): handleEvent volume_nomedia:/sdcard
D/MountListener(  823): handleEvent ums_disabled
D/MountListener(  823): handleEvent ums_disconnected

4. prepare vold configuration.
vold.conf is in /development/data/etc of Eclair's build environment.
and in phone, the file is in /system/etc/.
I add the below items for my phone.
volume_sdcard {
    media_path     /devices/platform/pxa2xx-mci.0/mmc_host/mmc0
    media_type     mmc
    mount_point    /sdcard
    ums_path       devices/platform/usb_mass_storage/lun0
}

5. reboot the phone, and enjor it.

----

Appendx:
i. one exception.
I have enabled some debug switches to debug, there is one place which has issue.
/system/core/vold/volmgr_vfat.c: vfat_mount()
the original source code is:
   LOG_VOL("vfat_mount(%s, %d:%d): mount rc = %d", dev->major,k dev->minor,
           vol->mount_point, rc);
it can not be built, I found there is a more 'k' character. 
if we delete this 'k', build is ok, but in fact, the sequence of four varibles are wrong, and exception will happen.
we need adjust the sequence of the third varible to the first place.

the belos is my log for this issue:
D/vold    (  824): Filesystem check completed OK
I/vold    (  824): vfat filesystem check of 179:1 OK
D/vold    (  824): vfat_mount(179:1, /sdcard, 1):
I/DEBUG   (  798): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (  798): Build fingerprint: 'generic/generic/generic/:2.1-update1/ERE27/eng.amuhong.20100504.104022:eng/test-keys'
I/DEBUG   (  798): pid: 824, tid: 1042  >>> /system/bin/vold <<<
I/DEBUG   (  798): signal 11 (SIGSEGV), fault addr 000000b3
I/DEBUG   (  798):  r0 000000b3  r1 ffffffff  r2 100ffe00  r3 00000003
I/DEBUG   (  798):  r4 ffffffff  r5 00000002  r6 100ff754  r7 00000000
I/DEBUG   (  798):  r8 00100000  r9 0000bcdd  10 10000000  fp 00013160
I/DEBUG   (  798):  ip afbc30e8  sp 100ff6c0  lr afe15ee7  pc afe0e780  cpsr 20000010
I/DEBUG   (  798):          #00  pc 0000e780  /system/lib/libc.so
I/DEBUG   (  798):          #01  pc 00015ee4  /system/lib/libc.so
I/DEBUG   (  798):          #02  pc 00017466  /system/lib/libc.so
I/DEBUG   (  798):          #03  pc 000011dc  /system/lib/liblog.so
I/DEBUG   (  798):          #04  pc 0000d014  /system/bin/vold
I/DEBUG   (  798):          #05  pc 0000bdf8  /system/bin/vold
I/DEBUG   (  798):          #06  pc 00010000  /system/lib/libc.so
I/DEBUG   (  798):          #07  pc 0000fad4  /system/lib/libc.so

ii. SD related source code.
a.   SD card settings source code:
packages/apps/Settings/src/com/android/settings/SdCardSettings.java

b.   MountService source code:
frameworks/base/services/java/com/android/server/MountService.java
frameworks/base/services/java/com/android/server/MountListener.java
frameworks/base/core/java/android/os/IMountService.aidl

c.   Native layer:
system/core/vold
hardware/libhardware_legacy/mount/IMountService.cpp
hardware/libhardware_legacy/include/hardware_legacy/IMountService.h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值