[笔记分享] [eMMC] 内核eMMC分区及对应名字读取

Chipset: msm8926 
OS: Android4.4 
Kernel: 3.4.0

在N久之前的会议上留下了两个问题: 
1. 内核在加载emmc驱动时是如何知道当前有几个分区的? 
2. 如何知道/dev/mmcblkXpX对应的是哪个分区呢?

读取分区

加载sd/emmc驱动的时候,有如下流程: 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第1张图片

来看看Check_partition(): 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第2张图片

核心的部分是check_part这个结构体,里面放的都是对应的解析分区的算法: 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第3张图片

算法不是我们需要关注的,解析哪一块区域等小弟看了partition再给大家解释吧。 
解析完成之后放到struct parsed_partitions也就是这里的state变量的parts元素里: 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第4张图片

然后通过add_partition()将这些part信息添加到disk里去。

有多少分区可以从开机Log看到: 
 这里写图片描述
确实我们在8926平台上定义的分区个数是34个: 
[non_hlos\common\build\partition_f5.xml] 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第5张图片
分区对应label

其实Linux已经在/dev/block下提供了查看方法: 

[笔记分享] [eMMC] 内核eMMC分区及对应名字读取_第6张图片

从本质上来说,这些信息是从解析出来的struct parsed_partitions中的info变量获取的: 

这里写图片描述
emmc分区初始化

emmc卡检测到后先从mmc_init_card得到并构建card参数,如向mmc控制器获取boot0 boot1 rpmb物理节点分区再通过mmc_part_add加入card中,card->nr_parts显示有几块物理分区(emmc 出厂就有的)

[    0.612375] <3>.(0)[6:kworker/u8:0]mmcblk0: mmc0:0001 M62704 3.53 GiB 
[    0.612631] <3>.(0)[6:kworker/u8:0]mmcblk0boot0: mmc0:0001 M62704 partition 1 2.00 MiB
[    0.612896] <3>.(0)[6:kworker/u8:0]mmcblk0boot1: mmc0:0001 M62704 partition 2 2.00 MiB
[    0.613142] <3>.(0)[6:kworker/u8:0]mmcblk0rpmb: mmc0:0001 M62704 partition 3

再通过读取 userdata区的MBR分区表(软件分区表)****rescan_partitions得到软件的分区信息(用户自己定义,加入软件分区表这里为efi_partition,调用流程如下

[    0.615795] <3>.(1)[6:kworker/u8:0] mmcblk0: p1 p2 p3 p4 p5 p6 p7 p8 p9 p10
0.745744] <1>-(1)[6:kworker/u8:0]Call trace:
[    0.746312] <1>-(1)[6:kworker/u8:0][] dump_backtrace+0x0/0x158
[    0.747244] <1>-(1)[6:kworker/u8:0][] show_stack+0x14/0x20
[    0.748132] <1>-(1)[6:kworker/u8:0][] dump_stack+0x90/0xb0
[    0.749022] <1>-(1)[6:kworker/u8:0][] warn_slowpath_common+0x98/0xd0
[    0.750019] <1>-(1)[6:kworker/u8:0][] warn_slowpath_null+0x18/0x20
[    0.750994] <1>-(1)[6:kworker/u8:0][] efi_partition+0x494/0x5f8
[    0.751937] <1>-(1)[6:kworker/u8:0][] check_partition+0xf8/0x210
[    0.752890] <1>-(1)[6:kworker/u8:0][] rescan_partitions+0xc8/0x2d0
[    0.753866] <1>-(1)[6:kworker/u8:0][] __blkdev_get+0x214/0x310
[    0.754798] <1>-(1)[6:kworker/u8:0][] blkdev_get+0xf8/0x340
[    0.755697] <1>-(1)[6:kworker/u8:0][] add_disk+0x338/0x440
[    0.756586] <1>-(1)[6:kworker/u8:0][] mmc_add_disk+0x24/0x110
[    0.757507] <1>-(1)[6:kworker/u8:0][] mmc_blk_probe+0x1d4/0x2b0
[    0.758451] <1>-(1)[6:kworker/u8:0][] mmc_bus_probe+0x1c/0x28
[    0.759373] <1>-(1)[6:kworker/u8:0][] driver_probe_device+0x1fc/0x348
[    0.760381] <1>-(1)[6:kworker/u8:0][] __device_attach_driver+0x90/0xd8
[    0.761400] <1>-(1)[6:kworker/u8:0][] bus_for_each_drv+0x58/0x98
[    0.762353] <1>-(1)[6:kworker/u8:0][] __device_attach+0xc4/0x148
[    0.763306] <1>-(1)[6:kworker/u8:0][] device_initial_probe+0x10/0x18
[    0.764302] <1>-(1)[6:kworker/u8:0][] bus_probe_device+0x94/0xa0
[    0.765255] <1>-(1)[6:kworker/u8:0][] device_add+0x354/0x548
[    0.766164] <1>-(1)[6:kworker/u8:0][] mmc_add_card+0xdc/0x278
[    0.767086] <1>-(1)[6:kworker/u8:0][] mmc_attach_mmc+0xb0/0x170
[    0.768029] <1>-(1)[6:kworker/u8:0][] mmc_rescan+0x2a4/0x2f8
[    0.768941] <1>-(1)[6:kworker/u8:0][] process_one_work+0x1e0/0x478
[    0.769916] <1>-(1)[6:kworker/u8:0][] worker_thread+0x134/0x4f0
[    0.770860] <1>-(1)[6:kworker/u8:0][] kthread+0xd0/0xe8
[    0.771717] <1>-(1)[6:kworker/u8:0][] ret_from_fork+0x10/0x40
[    0.772648] <1>.(1)[6:kworker/u8:0]---[ end trace 30179c718ee802dd ]--

 

你可能感兴趣的:(Android驱动)