Monky vold extension

1,746 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,746
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
43
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • device_add() ,其用于將一个 device 注册到 device model ,其中使用了 kobject_uevent (&dev->kobj, KOBJ_ADD) 向 user space 發出 KOBJ_ADD 事件並輸出環境變數,以表明一个 device 被添加了。
  • 由 socket 收到的 uevent A: 0 表示為 action 是 add P 則是路徑
  • Netlink 相對於系統調用, ioctl 以及 /proc 檔案系統而言具有以下優點︰ 1. 為了使用 netlink ,用戶僅需要在 include/linux/netlink.h 中增加一個新類型的 netlink 協議定義即可, 如 #define NETLINK_MYTEST 17 然後,內核和用戶態應用就可以立即透過 socket API 使用該 netlink 協議類型進行數據交換。但系統調用需要增加新的系統調用, ioctl 則需要增加設備或檔案, 那需要不少代碼, proc 檔案系統則需要在 /proc 下添加新的檔案或目錄,那將使本來就混亂的 /proc 更加混亂。 2. netlink 是一種異步通信機制,在內核與用戶態應用之間傳遞的消息儲存在 socket 緩沖隊列中,發送消息只是把消息儲存在接收者的 socket 的接收隊列,而不需要等待接收者收到消息,但系統調用與 ioctl 則是同步通信機制,如果傳遞的數據太長,將影響調度。 3. netlink 支援多播,內核模塊或應用可以把消息多播給一個 netlink 組,屬於該 neilink 組的任何內核模塊或應用都能接收到該消息,內核事件向用戶態的通知機製就使用了這一特性,任何對內核事件感興趣的應用都能收到該子系統發送的內核事件,在後面的文章中將介紹這一機製的使用。 4. 內核可以使用 netlink 首先發起會話,但系統調用和 ioctl 只能由用戶應用發起調用。 5. netlink 使用標準的 socket API ,因此很容易使用,但系統調用和 ioctl 則需要專門的培養訓練才能使用。
  • 一開始使用 netlink socket 開啟 uevent_sock ,並且註冊 netlink family 為 NETLINK_KOBJECT_UEVENT 利用這個協定來將 kernel space message 傳給 user space 將與位址 bind 之後,就可以 recv() 。
  • power_supply: 判斷是否在 low battery 的狀態,讓 sd 進去 safe mode block: create blkdev 在 /dev/block/vold 下,並且依照路徑去做 mount 的動作 usb event: host event
  • Mount Service: /framework/base/services/java/com/android/server/MountService.java
  • Monky vold extension

    1. 1. More than Vold & mmc driver Monky 2010/04/21
    2. 2. Outline <ul><li>Recap (curtsey of Wilson’s ppt) </li></ul><ul><ul><li>IPC </li></ul></ul><ul><ul><ul><li>Uevent </li></ul></ul></ul><ul><ul><ul><li>Netlink </li></ul></ul></ul><ul><ul><li>Volume daemon (VOLD) </li></ul></ul><ul><li>Mount Service </li></ul><ul><li>File System </li></ul>
    3. 3. Block Diagram System Server Volume daemon Mount Listener Mount Service MMC Driver Packages uevent intent I/O Scheduler Generic Block Layer Mapping Layer VFS YAFFS2 VFAT EXT3.. Host Controller
    4. 4. udev <ul><li>udev is the device manager for linux 2.6.x </li></ul><ul><li>Devfs (2.4)  udev (2.6) </li></ul><ul><li>Manage device nodes in /dev </li></ul><ul><li>As a daemon in user space </li></ul><ul><li>Dynamically provides only the nodes for the devices actually present on a syste </li></ul><ul><li>Listen to uevents the kernel sends out (via netlink socket) </li></ul>
    5. 5. Uevent <ul><li>One of ways to do IPC </li></ul><ul><li>Based on Udev </li></ul><ul><li>Send environmental data from kernel space to user space </li></ul><ul><li>One of important KernelObject </li></ul>
    6. 6. Example of uevent in kernel <ul><li>mmc driver </li></ul><ul><li>Add device info ,using add_uevent_var() </li></ul>
    7. 7. Example of uevent in kernel <ul><li>Information from ddms </li></ul><ul><li>01-01 01:46:26.293: ERROR/vold(1152): [UEVENT] Sq: 1148 S: mmc A: 0 P: /devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa 01-01 01:46:26.293: ERROR/vold(1152): DEVPATH=/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa 01-01 01:46:26.293: ERROR/vold(1152): MMC_TYPE=SD 01-01 01:46:26.293: ERROR/vold(1152): MMC_NAME=SU02G 01-01 01:46:26.303: ERROR/vold(1152): [UEVENT] Sq: 1149 S: block A: 0 P: /devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0 01-01 01:46:26.303: ERROR/vold(1152): DEVPATH=/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0 01-01 01:46:26.303: ERROR/vold(1152): MAJOR=179 01-01 01:46:26.303: ERROR/vold(1152): MINOR=0 01-01 01:46:26.303: ERROR/vold(1152): DEVTYPE=disk 01-01 01:46:26.323: ERROR/vold(1152): [UEVENT] Sq: 1150 S: block A: 0 P: /devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0/mmcblk0p1 01-01 01:46:26.323: ERROR/vold(1152): DEVPATH=/devices/platform/msm_sdcc.1/mmc_host/mmc0/mmc0:aaaa/block/mmcblk0/mmcblk0p1 01-01 01:46:26.323: ERROR/vold(1152): MAJOR=179 01-01 01:46:26.323: ERROR/vold(1152): MINOR=1 01-01 01:46:26.323: ERROR/vold(1152): DEVTYPE=partition </li></ul>
    8. 8. Netlink <ul><li>Socket-like mechanism for IPC between kernel and user space processes </li></ul><ul><li>Standard socket-based interface </li></ul><ul><li>Asynchronous </li></ul><ul><li>More flexible successor to ioctl </li></ul><ul><li>Kernel can start session </li></ul>
    9. 9. Netlink <ul><li>Receive message in user space </li></ul><ul><li>Same as using net socket method (API) </li></ul>
    10. 10. Volume daemon <ul><li>Vold and mountd </li></ul>fw_sock uevent_sock Send_msg(MESSAGE) process_framework_command(int socket)
    11. 11. Volume daemon <ul><li>Bootstrap </li></ul><ul><ul><li>Load configuration, vold.conf </li></ul></ul><ul><ul><li>Read files and simulate uevent </li></ul></ul>
    12. 12. Volume daemon <ul><li>Config file: Vold.conf </li></ul><ul><li>Some configs </li></ul><ul><ul><li>media_path </li></ul></ul><ul><ul><li>media_type </li></ul></ul><ul><ul><li>mount_point </li></ul></ul><ul><ul><li>ums_path </li></ul></ul>
    13. 13. Volume daemon <ul><li>Handle uevents </li></ul><ul><ul><li>1.handle power_supply event </li></ul></ul><ul><ul><li>2.handle block event </li></ul></ul><ul><ul><li>3.handle usb event </li></ul></ul>
    14. 14. Volume daemon <ul><li>Handle framework events(where?) </li></ul><ul><ul><li>mount/dismount </li></ul></ul><ul><ul><li>format </li></ul></ul><ul><ul><li>send state </li></ul></ul>
    15. 15. Mount Service <ul><li>System server </li></ul><ul><li>init a ‘server thread’ (java) </li></ul>try { // MountService must start after NotificationManagerService Log.i(TAG, &quot;Starting Mount Service.&quot;); ServiceManager.addService(&quot;mount&quot;, new MountService(context)); } catch (Throwable e) { Log.e(TAG, &quot;Failure starting Mount Service&quot;, e); } public void run() { } … … Create by Linux system call – fork A process create by ‘Zygote’
    16. 16. Mount Service <ul><li>Broadcast intents for any interests </li></ul><ul><li>ACTION_UMS_CONNECTED, </li></ul><ul><li>ACTION_UMS_DISCONNECTED, </li></ul><ul><li>ACTION_MEDIA_REMOVED, </li></ul><ul><li>ACTION_MEDIA_UNMOUNTED, </li></ul><ul><li>ACTION_MEDIA_MOUNTED, </li></ul><ul><li>ACTION_MEDIA_SHARED, </li></ul><ul><li>ACTION_MEDIA_BAD_REMOVAL, </li></ul><ul><li>ACTION_MEDIA_UNMOUNTABLE, </li></ul><ul><li>ACTION_MEDIA_EJECT, </li></ul><ul><li>ACTION_MEDIA_SCANNER_STARTED </li></ul><ul><li>ACTION_MEDIA_SCANNER_FINISHED </li></ul><ul><li>ACTION_MEDIA_CHECKING </li></ul><ul><li>ACTION_MEDIA_NOFS </li></ul>
    17. 17. Mount Service <ul><li>Packages that install SD intents </li></ul><ul><li>Setting: SDCardSettings.java </li></ul><ul><li>Gallery: VideoCamera.java </li></ul><ul><li>MeidaProvider: MediaProvider.java </li></ul><ul><li>SoundRecorder: SoundRecorder.java </li></ul><ul><li>Gallery3D: BootReceiver.java </li></ul><ul><li>Camera: ImageGallery.java/GalleryPicker.java </li></ul><ul><li>… </li></ul>
    18. 18. File System http://stackoverflow.com/questions/2421826/whats-android-file-system (check our system..)
    19. 19. <ul><li>Q&A </li></ul>
    20. 20. Reference http://en.wikipedia.org/wiki/Udev http://kezeodsnx.pixnet.net/blog/post/26089951 http://tw.myblog.yahoo.com/chimei-015/article?mid=948&prev=949&next=938&l=f&fid=19

    ×