The first part analyzes the role of two key macro U_BOOT_DRIVER and U_BOOT_DEVICES, with the basis of articles, this article will analyze:
How the information in Part 1 of uboot_list segment is used up?
2.uclass relationship between uclass_driver, udevice, driver,?
Board_r.c begin to analyze the function of initr_dm:
1 static const struct driver_info root_info = {
2 .name = "root_driver", 3 };
1 /* This is the root driver - all drivers are children of this */
2 U_BOOT_DRIVER(root_driver) = { 3 .name = "root_driver", 4 .id = UCLASS_ROOT, 5 .priv_auto_alloc_size = sizeof(struct root_priv), 6 }; 7 8 /* This is the root uclass */ 9 UCLASS_DRIVER(root) = { 10 .name = "root", 11 .id = UCLASS_ROOT, 12 };
initr_dm
ret = dm_init_and_scan(false);
dm_init
INIT_LIST_HEAD(&DM_UCLASS_ROOT_NON_CONST); //#define DM_UCLASS_ROOT_NON_CONST (((gd_t *)gd)->uclass_root) 创建头结点gd->uclass_root
ret = device_bind_by_name(NULL, false, &root_info, &DM_ROOT_NON_CONST);
drv = lists_driver_lookup_name(info->name); //lists_driver_lookup_name("root_driver")
DRV = ll_entry_start Driver * struct (struct Driver, Driver); // Part by analysis, here is the address of uboot_list_2_driver_1
ll_entry_count n_ents = int const (struct Driver, Driver); // uboot_list_2_driver_3- uboot_list_2_driver_1 obtain length
for (entry = DRV; entry = DRV + n_ents;! entry ++) { // iterate through the field name matching, the matching is successful to obtain the address driver structure
if (!strcmp(name, entry->name))
return entry;
}
device_bind_common(parent, drv, info->name, (void *)info->platdata, 0, ofnode_null(), platdata_size, devp);
ret = uclass_get(drv->id, &uc);
struct uclass * uc;
uc = uclass_find(id);
if (!uc)
uclass_add return (id, UCP); // drv obtained by matching the above-id field (UCLASS_ROOT), to give the corresponding uclass_driver successfully matched address structure
uc-> = uc_drv uc_drv; // uclass root的uclass_driver指向uclass_driver root
INIT_LIST_HEAD(&uc->sibling_node);
INIT_LIST_HEAD(&uc->dev_head);
list_add(&uc->sibling_node, &DM_UCLASS_ROOT_NON_CONST);
.......
// key code is as follows
INIT_LIST_HEAD(&dev->sibling_node);
INIT_LIST_HEAD(&dev->child_head);
INIT_LIST_HEAD(&dev->uclass_node);
dev->name = name;
dev->node = node;
dev->parent = parent;
dev->driver = drv;
dev-> uclass = uc;
......
ret = uclass_bind_device(dev);
uc = dev-> uclass;
list_add_tail(&dev->uclass_node, &uc->dev_head);
---------------------------------------------------------------------------------------------------------------------------------------------
After reading the above-mentioned source, the above-described relationship will be more intuitive form of FIG manifested:
Transfer from https://www.cnblogs.com/gs1008612/p/8253213.html