u-boot lists_bind_fdt函数
函数位置driver/core/lists.c文件
int lists_bind_fdt(struct udevice *parent, ofnode node, struct udevice **devp, bool pre_reloc_only) { struct driver *driver = ll_entry_start(struct driver, driver); const int n_ents = ll_entry_count(struct driver, driver); const struct udevice_id *id; struct driver *entry; struct udevice *dev; bool found = false; const char *name, *compat_list, *compat; int compat_length, i; int result = 0; int ret = 0; //链表添加的父节点是root if (devp) *devp = NULL;
//获得节点的名称 name = ofnode_get_name(node); log_debug("bind node %s\n", name); //获得节点属性compatible的属性列表指针和长度 compat_list = ofnode_get_property(node, "compatible", &compat_length);
//无compatible属性返回处理 if (!compat_list) { if (compat_length == -FDT_ERR_NOTFOUND) { log_debug("Device '%s' has no compatible string\n", name); return 0; } dm_warn("Device tree error at node '%s'\n", name); return compat_length; } /* * Walk through the compatible string list, attempting to match each * compatible string in order such that we match in order of priority * from the first string to the last. */
//compatible属性匹配
for (i = 0; i < compat_length; i += strlen(compat) + 1) { compat = compat_list + i; log_debug(" - attempt to match compatible string '%s'\n", compat); for (entry = driver; entry != driver + n_ents; entry++) { ret = driver_check_compatible(entry->of_match, &id, compat); if (!ret) break; } if (entry == driver + n_ents) continue; //判断是否预先加载:1,pre_reloc_only为真,直接加载。2,fdt节点属性设置 if (pre_reloc_only) { if (!ofnode_pre_reloc(node) && !(entry->flags & DM_FLAG_PRE_RELOC)) { log_debug("Skipping device pre-relocation\n"); return 0; } } log_debug(" - found match at '%s': '%s' matches '%s'\n", entry->name, entry->of_match->compatible, id->compatible); ret = device_bind_with_driver_data(parent, entry, name, id->data, node, &dev); if (ret == -ENODEV) { log_debug("Driver '%s' refuses to bind\n", entry->name); continue; } if (ret) { dm_warn("Error binding driver '%s': %d\n", entry->name, ret); return log_msg_ret("bind", ret); } else { found = true; if (devp) *devp = dev; } break; } if (!found && !result && ret != -ENODEV) log_debug("No match for node '%s'\n", name); return result; }