如何手动mount sdcard和检测到sd card

1. mount -t vfat /dev/block/mmcblk0p1 /mnt/sdcard; 不好用!
2. [Framework 层]主要分析 system/vold/main.cpp, DirectVolume.cpp, Volume.cpp[void Volume::setState(int state); int Volume::mountVol()]
3. [Framework 层]system/vold/main.cpp->main函数-->初始化VolumeManager,NetlinkManager,CommandListener;
4. [Framework 层]system/vold/commandlistener.cpp-->FrameworkListener("vold") 和registerCmd(new VolumeCmd())[VolumeCmd 的过滤关键字为volume];
5. [Framework 层]system/core/libsysutils/src/frameworklistener.cpp; FrameworkListener->dispatchCommand
6. [Framework 层]system/core/libsysutils/src/socketlistener.cpp; startListener-->android_get_control_socket(mSocketName)其中mSocketName="vold",该socket已经通过init.rc 中的socket vold stream 0660 root mount 开始就创建了,绑定后就开始listen(mSock, 4)
7. [Framework 层]system/vold/netlinkmanager.cpp;在NetlinkManager::start() 中会新创建一个socket; 最后设置了 mHandler = new NetlinkHandler(mSock);
8. [Framework 层]system/vold/netlinkhandler.cpp;中onEvent函数会处理收到的消息;而NetlinkHandler继承于NetlinkListener又继承于SocketListener(socket, false),由false可知该socket不是监听socket;在SocketListener::startListener()中会增加 mClients->push_back(new SocketClient(mSock));
9. [Framework 层]system/vold/directvolume.cpp;中handleBlockEvent-->mVm->getBroadcaster()->sendBroadcast(ResponseCode::VolumeDiskInserted,msg,false);会发送VolumeDiskInserted给CommandListener[mVm],然后逐个对其mClients中的SocketClient发送消息;
10. [Framework 层]谁触发的 DirectVolume::handleBlockEvent? 由NetlinkHandler::onEvent;--> vm->handleBlockEvent(evt);-->VolumeManager::handleBlockEvent;-->mVolumes中逐个volume->handleBlockEvent;
11. [Framework 层]而VolumeManager中的mVolumes 中元素,是在main.cpp中process_config函数分析手机上的文件/etc/vold.fstab而得到的;
12. [Framework 层]又是谁触发NetlinkHandler::onEvent的? 又回到了NetlinkManager::start() 创建了nladdr.nl_pid = getpid();的socket。也就是必须有其他socket主动连接到该 NetlinkManager的socket(NetlinkManager::mSock);然后由SocketListener::runListener()--> NetlinkListener::onDataAvailable(c)-->NetlinkHandler::onEvent;
13. [Framework 层]现在必须查明 谁给NetlinkManager::mSock请求连接并发送消息subsys=“block”???????应该是kernel发出的,./drivers/base/core.c-->device_add-->kobject_uevent(&dev->kobj, KOBJ_ADD);
14. [Framework 层]在SocketListener::runListener()中如果是可以监听的socket[mListen=true],会增加 mClients->push_back(new SocketClient(c)); 如果需要收到VolumeDiskInserted的消息,你就首先需要申请和SocketListener[名称为vold]连接。比如某些应用需要获取该消息

1. [Kernel 层]主要分析 kernel/drivers/mmc/core/bus.c, mmc的driver注册到/sys/bus/mmc/devices下mmc3:aaaa, 实际对应的路径又为/sys/devices/sdi3/mmc_host/mmc3/mmc3:aaaa,这正好与前面dev_mount xxxx 中的设备点一致
2. [Kernel 层]kernel/drivers/mmc/core/bus.c [int mmc_add_card(struct mmc_card *card)];
   kernel/drivers/mmc/core/sd.c [mmc_attach_sd]
   kernel/drivers/mmc/core/core.c [mmc_rescan_try_freq <---mmc_rescan]    
   kernel/drivers/mmc/core/host.c [mmc_alloc_host: INIT_DELAYED_WORK(&host->detect, mmc_rescan);]
   EXPORT_SYMBOL(mmc_alloc_host) : 内核"导出"的符号表,这个表在insmod 时候会用到,可通过cat /proc/kallsyms查看
   kernel/drivers/mmc/core/core.c [mmc_detect_change]
   kernel/drivers/mmc/core/sd.c    [mmc_sd_detect]
   kernel/drivers/mmc/host/mmci.c  [mmci_cd_irq]  根据查kernel/arch/arm/configs/semc_lotus_defconfig中关于mmc 的config 和Makefile选择
   kernel/drivers/mmc/host/mmci.c  [mmci_probe]  注册中断监听函数mmci_cd_irq,还有mmc = mmc_alloc_host(sizeof(struct mmci_host), &dev->dev);初始化mmc_host;
   kernel/drivers/mmc/core/core.c  [mmc_detect_change]-->mmc_schedule_delayed_work(&host->detect, delay); ????
   host->detect = mmc_rescan;在kernel/drivers/mmc/core/host.c中mmc_alloc_host函数有INIT_DELAYED_WORK(&host->detect, mmc_rescan);其中mmc_rescan在kernel/drivers/mmc/core/core.c中
   似乎不太重要mmc_rescan-->host->bus_ops->detect(host)[该函数在/kernel/driver/mmc/core/mmc.c中赋值为mmc_detect]-->mmc_claim_host(host);-->__mmc_claim_host-->add_wait_queue(&host->wq, &wait);
3. [Kernel 层]kernel的sd卡插入和拔出的detect event 如何传递到 user space的vold->NetlinkManager::mSock的?????
4. [Kernel 层]kernel/lib/kobject_uevent.c中uevent_net_init函数会创建netlink_kernel_create(net, NETLINK_KOBJECT_UEVENT,...), 而kobject_uevent_env->netlink_broadcast_filtered-->do_one_broadcast[单一广播]会发送uevent到user space
5. [Kernel 层]/drivers/base/core.c;中device_add函数有kobject_uevent(&dev->kobj, KOBJ_ADD) 该处是所找的向user space发送消息
6. [Kernel 层]kernel/lib/kobject_uevent.c中kobject_uevent->kobject_uevent_env(kobj, action, NULL);
7. [Kernel 层]/drivers/mmc/core/bus.c有mmc_add_card->device_add函数
8. [Kernel 层]/drivers/mmc/core/sd.c有mmc_attach_sd函数->mmc_add_card(host->card);
9. [Kernel 层]/drivers/mmc/core/core.c有mmc_rescan_try_freq函数->mmc_attach_sd; 注意其attch顺序为sdio,sd,mmc; 而mmc_rescan会调用mmc_rescan_try_freq

你可能感兴趣的:(socket,struct,Stream,user,makefile,Lotus)