You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过configfs应用设备树overlay后Linux内核模块无法自动加载排查

问题排查方向

以下是针对设备树overlay应用时驱动未自动加载问题的排查要点:

1. 验证兼容性字符串的完全匹配

  • 核对驱动代码中of_device_id结构体的compatible字段,比如:
    static const struct of_device_id sample_dac_of_match[] = {
        { .compatible = "vendor,sample-dac" },
        { /* Sentinel */ }
    };
    MODULE_DEVICE_TABLE(of, sample_dac_of_match);
    
  • 对比设备树overlay中对应节点的compatible属性,必须完全一致(包括大小写、标点、字符串顺序),示例overlay节点:
    fragment@0 {
        target-path = "/";
        __overlay__ {
            sample_dac: sample-dac {
                compatible = "vendor,sample-dac";
                /* 其他必要属性 */
            };
        };
    };
    
  • 应用overlay后,查看/sys/bus/platform/devices/<你的设备节点名>/modalias文件,确认内容格式为platform:<compatible字符串>,且与/lib/modules/$(uname -r)/modules.alias中的条目完全匹配(例如alias platform:vendor,sample-dac sample-driver)。

2. 确保depmod执行正确

  • 多内核环境下,必须指定当前运行的内核版本执行depmod,避免匹配错误:
    depmod -a $(uname -r)
    
  • 检查/lib/modules/$(uname -r)/modules.dep文件,确认其中存在sample-driver.ko的条目,确保模块路径被正确识别。

3. 检查内核配置与自动加载机制

  • 通过zcat /proc/config.gz | grep <配置项>验证以下内核配置是否开启:
    • CONFIG_MODULES=y:启用模块支持
    • CONFIG_MODULE_ALIAS=y:启用模块别名匹配
    • CONFIG_DEVTMPFS=y:自动创建设备节点
    • CONFIG_OF_OVERLAY=y:启用设备树overlay支持
  • 若使用systemd-udevd,检查服务状态确认无异常:
    systemctl status systemd-udevd
    

4. 验证设备树overlay是否正确应用

  • 应用overlay后,检查/sys/firmware/devicetree/base下是否存在新增的设备节点,或导出当前设备树排查:
    dtc -I fs /sys/firmware/devicetree/base > current.dts
    grep -A5 -B5 "sample-dac" current.dts
    
    确认节点已被正确添加且属性完整。

5. 排除无效操作

modules.order是内核编译时生成的编译顺序记录文件,手动添加条目对模块自动加载无任何作用,无需修改该文件。


内容的提问来源于stack exchange,提问作者Juraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 13:07:29