在Linux系统开发与运维中,Component框架的核心作用是确保功能系统能够按顺序完整构建。它通过同步所有组件的加载状态,仅在所有组件准备就绪后才启动子系统的初始化过程。
具体工作流程如下:
- Master组件将所有需要控制的组件添加到
component_match数组中。
- 子系统Component则将自身添加到
component_list链表中。
无论是Master还是Component,都会尝试调用aggregate_device的ops.bind函数。但关键点在于:只有当所有组件都添加完毕时,bind函数才会被调用。

通常,Master的probe函数会首先调用component_match_add()函数来创建component_match对象,并将设备添加到compare数组中。
compare函数用于比较compare->compare[i]中的data与component_list中的元素。
compare_data通常是驱动设备。
void component_match_add(struct device *parent,
struct component_match **matchptr,
int (*compare)(struct device *, void *), void *compare_data);

此时,compare_match对象已保存所有驱动设备信息。接着,调用component_master_add_with_match()函数将compare_match对象添加到aggregate_device中。
try_to_bring_up_aggregate_device()函数会尝试调用bind函数,但前提是:match->compare数组中的所有成员都能在component_list中找到对应项。

各个Component在probe函数中通过调用component_add()将自己添加到component_list链表中,并同样尝试调用try_to_bring_up_aggregate_device()函数。
最终,无论是最后一个Component添加完成,还是Master最后执行添加操作,bind函数都会在条件满足时被触发。
Master的bind函数会调用component_bind_all(),按照数组顺序依次调用每个Component的bind函数,从而开始系统的初始化工作。
|