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

编译小米SM8550内核时出现类型未定义错误求助

编译小米SM8550 Lineage-21内核时cs35l41.h头文件编译错误的解决方法

问题描述

编译小米SM8550的Lineage-21分支内核时,出现以下编译错误:

HDRTEST usr/include/audio/sound/msmcal-hwdep.h
In file included from <built-in>:1:
./usr/include/audio/sound/cs35l41.h:17:2: error: unknown type name 'bool'
        bool classh_bst_override;
        ^
./usr/include/audio/sound/cs35l41.h:18:2: error: unknown type name 'bool'
        bool classh_algo_enable;
        ^
./usr/include/audio/sound/cs35l41.h:28:2: error: unknown type name 'bool'
        bool is_present;
        ^
./usr/include/audio/sound/cs35l41.h:29:2: error: unknown type name 'bool'
        bool irq_pol_inv;
        ^
./usr/include/audio/sound/cs35l41.h:30:2: error: unknown type name 'bool'
        bool irq_out_en;
        ^
./usr/include/audio/sound/cs35l41.h:35:2: error: unknown type name 'bool'
        bool sclk_frc;
        ^
./usr/include/audio/sound/cs35l41.h:36:2: error: unknown type name 'bool'
        bool lrclk_frc;
        ^
./usr/include/audio/sound/cs35l41.h:37:2: error: unknown type name 'bool'
        bool right_channel;
        ^
./usr/include/audio/sound/cs35l41.h:38:2: error: unknown type name 'bool'
        bool amp_gain_zc;
        ^
./usr/include/audio/sound/cs35l41.h:39:2: error: unknown type name 'bool'
        bool dsp_ng_enable;
        ^
./usr/include/audio/sound/cs35l41.h:40:2: error: unknown type name 'bool'
        bool tuning_has_prefix;
        ^
./usr/include/audio/sound/cs35l41.h:41:2: error: unknown type name 'bool'
        bool invert_pcm;
        ^
./usr/include/audio/sound/cs35l41.h:42:2: error: unknown type name 'bool'
        bool hibernate_enable;
        ^
./usr/include/audio/sound/cs35l41.h:43:2: error: unknown type name 'bool'
        bool fwname_use_revid;
        ^
./usr/include/audio/sound/cs35l41.h:61:2: error: unknown type name 'bool'
        bool extclk_cfg;
        ^
./usr/include/audio/sound/cs35l41.h:73:21: error: field has incomplete type 'struct work_struct'
        struct work_struct ramp_work;
                           ^
./usr/include/audio/sound/cs35l41.h:73:9: note: forward declaration of 'struct work_struct'
        struct work_struct ramp_work;
               ^
./usr/include/audio/sound/cs35l41.h:74:15: error: field has incomplete type 'struct mutex'
        struct mutex vol_mutex; /* Protect set volume */
                     ^
./usr/include/audio/sound/cs35l41.h:74:9: note: forward declaration of 'struct mutex'
        struct mutex vol_mutex; /* Protect set volume */
               ^
./usr/include/audio/sound/cs35l41.h:75:2: error: unknown type name 'atomic_t'
        atomic_t manual_ramp; /* boolean */
        ^
./usr/include/audio/sound/cs35l41.h:76:2: error: unknown type name 'atomic_t'
        atomic_t ramp_abort; /* boolean */
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

涉及文件:cs35l41.h 位于内核模块源码的 qcom/opensource/audio-kernel/include/uapi/audio/sound 目录下。

已尝试操作及新错误

尝试在cs35l41.h中添加<linux/types.h>和<linux/workqueue.h>头文件引用后,出现新错误:

./usr/include/audio/sound/cs35l41.h:16:10: fatal error: 'linux/workqueue.h' file not found
#include <linux/workqueue.h>

解决方法

1. 区分用户空间与内核空间头文件差异

cs35l41.h位于uapi目录下,属于用户空间API头文件,不能直接引用内核专属头文件(如<linux/workqueue.h>、<linux/mutex.h>)——这些头文件仅在内核编译环境中可见,用户空间无法访问。

2. 修正类型定义与头文件引用

针对类型缺失问题,按以下方式调整:

  • 对于bool类型,添加用户空间标准头文件<stdbool.h>,或使用内核uapi兼容的_Bool类型;
  • atomic_t、struct work_struct、struct mutex属于内核内部实现细节,不应出现在uapi头文件中,用户空间API头文件仅需暴露用户程序可直接调用的接口和类型。

3. 拆分头文件结构

如果cs35l41.h包含内核内部使用的结构体(如带struct work_struct的部分),需拆分代码:

  • 将用户空间需要的API定义保留在uapi/audio/sound/cs35l41.h中;
  • 将内核内部使用的结构体、类型移至内核专属头文件(如audio-kernel/include/audio/sound/cs35l41.h,非uapi目录下的文件),仅在内核代码中引用该内部头文件。

4. 配置编译路径

确保编译内核模块时,正确指定内核源码的头文件路径。可在模块Makefile中添加:

EXTRA_CFLAGS += -I$(KERNEL_DIR)/include
EXTRA_CFLAGS += -I$(MODULE_DIR)/qcom/opensource/audio-kernel/include

其中KERNEL_DIR为内核源码根目录,MODULE_DIR为模块源码根目录。

5. 参考主线内核实现

对比主线Linux内核中cs35l41驱动的头文件结构,确保uapi头文件仅包含用户空间可见的定义,内核内部逻辑使用独立头文件。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 15:34:51