做过android平台的同仁大多都知道android原生态只支持了一个sd卡,默认的挂载点也就是/mnt/sdcard,所以在应用中使用getExternalStorageDirectory()得到的都是/mnt/sdcard,通常会symlink 到/sdcard目录。做过全志平台的童鞋也知道全志android SDK支持2个sd卡,通常是一个内置的,一个外置的,内置的一般是从nand上或者emmc上的用户数据区,因为现在的nand、emmc容量都比较大,存放android程序、cache、backup、download等之外,还有大量的空间剩余,因此这部分大多都会做成一个sd卡来使用,通常挂载到/mnt/sdcard上;外置的是挂载在/mnt/extsd节点上。但是,如何在全志平台上使用三个sd卡呢?即再增加一个外置的SD卡支持。
为了多支持一个SD卡,我们有以下基本需要做:
1、 在系统配置文件里,打开对应的SD卡驱动支持,设置好检测方式,如果是gpio方式的要配置好gpio引脚;笔者测试过,如果两个外置的SD卡,都使用gpio polling的方式,系统只识别一个SD卡,笔者把两个SD卡一个配置成gpio polling,另外一个配置成了GPIO IRQ中断模式;
[plain] view plain copy print ?
- [mmc0_para]
- sdc_used = 1
- sdc_detmode = 2
- sdc_buswidth = 4
- sdc_clk = port:PF02<2><1><2><default>
- sdc_cmd = port:PF03<2><1><2><default>
- sdc_d0 = port:PF01<2><1><2><default>
- sdc_d1 = port:PF00<2><1><2><default>
- sdc_d2 = port:PF05<2><1><2><default>
- sdc_d3 = port:PF04<2><1><2><default>
- sdc_det = port:PH3<6><1><default><default>
- sdc_use_wp = 0
- sdc_wp =
- sdc_isio = 0
- sdc_regulator = "none"
-
- [mmc1_para]
- sdc_used = 1
- sdc_detmode = 1
- sdc_buswidth = 4
- sdc_clk = port:PH23<5><1><2><default>
- sdc_cmd = port:PH22<5><1><2><default>
- sdc_d0 = port:PH24<5><1><2><default>
- sdc_d1 = port:PH25<5><1><2><default>
- sdc_d2 = port:PH26<5><1><2><default>
- sdc_d3 = port:PH27<5><1><2><default>
- sdc_det = port:PH2<0><1><default><default>
- sdc_use_wp = 0
- sdc_wp =
- sdc_isio = 0
- sdc_regulator = "none"
[mmc0_para]
sdc_used = 1
sdc_detmode = 2
sdc_buswidth = 4
sdc_clk = port:PF02<2><1><2><default>
sdc_cmd = port:PF03<2><1><2><default>
sdc_d0 = port:PF01<2><1><2><default>
sdc_d1 = port:PF00<2><1><2><default>
sdc_d2 = port:PF05<2><1><2><default>
sdc_d3 = port:PF04<2><1><2><default>
sdc_det = port:PH3<6><1><default><default>
sdc_use_wp = 0
sdc_wp =
sdc_isio = 0
sdc_regulator = "none"
[mmc1_para]
sdc_used = 1
sdc_detmode = 1
sdc_buswidth = 4
sdc_clk = port:PH23<5><1><2><default>
sdc_cmd = port:PH22<5><1><2><default>
sdc_d0 = port:PH24<5><1><2><default>
sdc_d1 = port:PH25<5><1><2><default>
sdc_d2 = port:PH26<5><1><2><default>
sdc_d3 = port:PH27<5><1><2><default>
sdc_det = port:PH2<0><1><default><default>
sdc_use_wp = 0
sdc_wp =
sdc_isio = 0
sdc_regulator = "none"
2、 在vold.fstab里,需要修改一下,如下:
[plain] view plain copy print ?
- ## Vold 2.0 fstab for HTC Passion
- #
- ## - San Mehat ([email protected])
- ##
- #######################
- ## Regular device mount
- ##
- ## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
- ## label - Label for the volume
- ## mount_point - Where the volume will be mounted
- ## part - Partition # (1 based), or 'auto' for first usable partition.
- ## <sysfs_path> - List of sysfs paths to source devices
- ######################
-
- # Mounts the first usable partition of the specified device
- #/devices/platform/awsmc.3/mmc_host for sdio
- dev_mount sdcard /mnt/sdcard auto /devices/virtual/block/nandk /devices/platform/sunxi-mmc.2/mmc_host
- dev_mount extsd /mnt/extsd auto /devices/platform/sunxi-mmc.1/mmc_host
- dev_mount extsd2 /mnt/extsd2 auto /devices/platform/sunxi-mmc.0/mmc_host
- dev_mount usbhost1 /mnt/usbhost1 auto /devices/platform/sw-ehci.1 /devices/platform/sw_hcd_host0 /devices/platform/sw-ohci.1
## Vold 2.0 fstab for HTC Passion
#
## - San Mehat ([email protected])
##
#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
## label - Label for the volume
## mount_point - Where the volume will be mounted
## part - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
######################
# Mounts the first usable partition of the specified device
#/devices/platform/awsmc.3/mmc_host for sdio
dev_mount sdcard /mnt/sdcard auto /devices/virtual/block/nandk /devices/platform/sunxi-mmc.2/mmc_host
dev_mount extsd /mnt/extsd auto /devices/platform/sunxi-mmc.1/mmc_host
dev_mount extsd2 /mnt/extsd2 auto /devices/platform/sunxi-mmc.0/mmc_host
dev_mount usbhost1 /mnt/usbhost1 auto /devices/platform/sw-ehci.1 /devices/platform/sw_hcd_host0 /devices/platform/sw-ohci.1
这三个SD卡挂载点都是可以随便交换的;
3、 如果完成了上面两步,extsd2对应的SD卡热插拔是可以自动挂载,如果是开机启动前就在sd卡槽里面的话,就不会自动识别,因此我们得明确告诉系统storage配置,配置在storage_list.xml文件中,如下:
[html] view plain copy print ?
- <storage android:mountPoint="/mnt/extsd"
-
- android:storageDescription="extsd"
-
- android:primary="false"
-
- android:removable="true"
-
- android:emulated="false"
-
- android:mtpReserve="0"
-
- android:allowMassStorage="true"
-
- android:maxFileSize="0"/>
-
<storage android:mountPoint="/mnt/extsd"
android:storageDescription="extsd"
android:primary="false"
android:removable="true"
android:emulated="false"
android:mtpReserve="0"
android:allowMassStorage="true"
android:maxFileSize="0"/>
4、 在system/vold下面做一些处理,类似extsd处理,加上即可,如下:
[plain] view plain copy print ?
- diff --git a/DirectVolume.cpp b/DirectVolume.cpp
- index 16ac2d8..43ce612 100755
- --- a/DirectVolume.cpp
- +++ b/DirectVolume.cpp
- @@ -346,7 +346,7 @@ void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt
- * Yikes, our mounted partition is going away!
- */
-
- - if(!strstr(getLabel(),"usb")&&!strstr(getLabel(),"extsd")){
- + if(!strstr(getLabel(),"usb")&&!strstr(getLabel(),"extsd")&&!strstr(getLabel(),"extsd2")){
- snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
- getLabel(), getMountpoint(), major, minor);
- mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
- diff --git a/Volume.cpp b/Volume.cpp
- old mode 100644
- new mode 100755
- index 23556ea..a1f059a
- --- a/Volume.cpp
- +++ b/Volume.cpp
- @@ -864,7 +864,7 @@ int Volume::unmountVol(bool force, bool revert) {
- setState(Volume::State_Unmounting);
- usleep(1000 * 1000); // Give the framework some time to react
-
- - if(getMountpoint()!=NULL&&!strstr(getMountpoint(),"usb")&&!strstr(getMountpoint(),"extsd")){
- + if(getMountpoint()!=NULL&&!strstr(getMountpoint(),"usb")&&!strstr(getMountpoint(),"extsd")&&!strstr(getMountpoint(),"extsd2")){
- /*
- * Remove the bindmount we were using to keep a reference to
- * the previously obscured directory.
diff --git a/DirectVolume.cpp b/DirectVolume.cpp
index 16ac2d8..43ce612 100755
--- a/DirectVolume.cpp
+++ b/DirectVolume.cpp
@@ -346,7 +346,7 @@ void DirectVolume::handlePartitionRemoved(const char *devpath, NetlinkEvent *evt
* Yikes, our mounted partition is going away!
*/
- if(!strstr(getLabel(),"usb")&&!strstr(getLabel(),"extsd")){
+ if(!strstr(getLabel(),"usb")&&!strstr(getLabel(),"extsd")&&!strstr(getLabel(),"extsd2")){
snprintf(msg, sizeof(msg), "Volume %s %s bad removal (%d:%d)",
getLabel(), getMountpoint(), major, minor);
mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeBadRemoval,
diff --git a/Volume.cpp b/Volume.cpp
old mode 100644
new mode 100755
index 23556ea..a1f059a
--- a/Volume.cpp
+++ b/Volume.cpp
@@ -864,7 +864,7 @@ int Volume::unmountVol(bool force, bool revert) {
setState(Volume::State_Unmounting);
usleep(1000 * 1000); // Give the framework some time to react
- if(getMountpoint()!=NULL&&!strstr(getMountpoint(),"usb")&&!strstr(getMountpoint(),"extsd")){
+ if(getMountpoint()!=NULL&&!strstr(getMountpoint(),"usb")&&!strstr(getMountpoint(),"extsd")&&!strstr(getMountpoint(),"extsd2")){
/*
* Remove the bindmount we were using to keep a reference to
* the previously obscured directory.
完成了以上几步,三个SD卡已经可以自动识别挂载了,mount的信息如下:
[plain] view plain copy print ?
- root@android:/ # mount
-
- rootfs / rootfs rw 0 0
- tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
- devpts /dev/pts devpts rw,relatime,mode=600 0 0
- proc /proc proc rw,relatime 0 0
- sysfs /sys sysfs rw,relatime 0 0
- debugfs /sys/kernel/debug debugfs rw,relatime 0 0
- none /acct cgroup rw,relatime,cpuacct 0 0
- tmpfs /mnt/secure tmpfs rw,relatime,mode=700 0 0
- tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
- tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
- none /dev/cpuctl cgroup rw,relatime,cpu 0 0
- /dev/block/nandd /system ext4 rw,nodev,noatime,nobarrier,data=ordered 0 0
- /dev/block/nande /data ext4 rw,nosuid,nodev,noatime,journal_checksum,nobarrier,noauto_da_alloc,data=ordered 0 0
- /dev/block/nandh /cache ext4 rw,nosuid,nodev,noatime,journal_checksum,nobarrier,noauto_da_alloc,data=ordered 0 0
- /dev/block/vold/179:16 /mnt/extsd vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1023,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
- /dev/block/vold/179:0 /mnt/extsd2 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1023,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
- /dev/block/vold/93:80 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
- /dev/block/vold/93:80 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 0
- tmpfs /mnt/sdcard/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
- root@android:/ #