编译内核驱动模块出错(./arch/x86/include/asm/xxx fatal error: asm/xxx: No such file or directory)

今天编译驱动时突然出现以下错误信息,后面经检查是因为我更换了之前的内核源码导致的。

点击直接查看解决办法

以下是编译错误输出信息:

make  -C /mnt/hgfs/Ubuntu/ebf_6ull_linux M=/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source modules
make[1]: Entering directory '/mnt/hgfs/Ubuntu/ebf_6ull_linux'
  CC [M]  /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.o
In file included from ./arch/x86/include/asm/bitops.h:16:0,
                 from include/linux/bitops.h:36,
                 from include/linux/kernel.h:10,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:2:
./arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:
./arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
                                          ^
./arch/x86/include/asm/alternative.h:125:28: note: in definition of macro ‘ALTINSTR_REPLACEMENT’
  b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n\t"
                            ^
./arch/x86/include/asm/arch_hweight.h:53:7: note: in expansion of macro ‘ALTERNATIVE’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
       ^
In file included from ./arch/x86/include/asm/pgtable_types.h:250:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:49,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
include/asm-generic/pgtable-nopud.h: At top level:
include/asm-generic/pgtable-nopud.h:15:0: warning: "PUD_SHIFT" redefined
 #define PUD_SHIFT PGDIR_SHIFT
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:205:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:49,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
./arch/x86/include/asm/pgtable_64_types.h:33:0: note: this is the location of the previous definition
 #define PUD_SHIFT 30
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:250:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:49,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
include/asm-generic/pgtable-nopud.h:16:0: warning: "PTRS_PER_PUD" redefined
 #define PTRS_PER_PUD 1
...
...
./arch/x86/include/asm/processor.h:270:27: note: in expansion of macro ‘____cacheline_aligned’
 } __attribute__((packed)) ____cacheline_aligned;
                           ^
In file included from ./arch/x86/include/asm/preempt.h:5:0,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
./arch/x86/include/asm/processor.h: In function ‘current_top_of_stack’:
./arch/x86/include/asm/processor.h:594:30: error: ‘cpu_current_top_of_stack’ undeclared (first use in this function)
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \
         ^
./arch/x86/include/asm/processor.h:594:9: note: in expansion of macro ‘this_cpu_read_stable’
  return this_cpu_read_stable(cpu_current_top_of_stack);
         ^
./arch/x86/include/asm/processor.h:594:30: note: each undeclared identifier is reported only once for each function it appears in
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \
         ^
./arch/x86/include/asm/processor.h:594:9: note: in expansion of macro ‘this_cpu_read_stable’
  return this_cpu_read_stable(cpu_current_top_of_stack);
         ^
In file included from ./arch/x86/include/asm/atomic.h:235:0,
                 from include/linux/atomic.h:4,
                 from ./arch/x86/include/asm/thread_info.h:50,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
./arch/x86/include/asm/atomic64_64.h: At top level:
./arch/x86/include/asm/atomic64_64.h:19:40: error: unknown type name ‘atomic64_t’
 static inline long atomic64_read(const atomic64_t *v)
                                        ^
In file included from include/uapi/linux/stddef.h:1:0,
                 from include/linux/stddef.h:4,
                 from ./include/uapi/linux/posix_types.h:4,
                 from include/uapi/linux/types.h:13,
                 from include/linux/types.h:5,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:1:
./arch/x86/include/asm/atomic64_64.h: In function ‘atomic64_read’:
./arch/x86/include/asm/atomic64_64.h:21:24: error: request for member ‘counter’ in something not a structure or union
  return ACCESS_ONCE((v)->counter);
                        ^
include/linux/compiler.h:456:25: note: in definition of macro ‘__ACCESS_ONCE’
   __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
                         ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘ACCESS_ONCE’
  return ACCESS_ONCE((v)->counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:24: error: request for member ‘counter’ in something not a structure or union
  return ACCESS_ONCE((v)->counter);
                        ^
include/linux/compiler.h:456:52: note: in definition of macro ‘__ACCESS_ONCE’
   __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
                                                    ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘ACCESS_ONCE’
  return ACCESS_ONCE((v)->counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:24: error: request for member ‘counter’ in something not a structure or union
  return ACCESS_ONCE((v)->counter);
                        ^
include/linux/compiler.h:457:19: note: in definition of macro ‘__ACCESS_ONCE’
  (volatile typeof(x) *)&(x); })
                   ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘ACCESS_ONCE’
  return ACCESS_ONCE((v)->counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:24: error: request for member ‘counter’ in something not a structure or union
  return ACCESS_ONCE((v)->counter);
                        ^
include/linux/compiler.h:457:26: note: in definition of macro ‘__ACCESS_ONCE’
  (volatile typeof(x) *)&(x); })
                          ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘ACCESS_ONCE’
  return ACCESS_ONCE((v)->counter);
         ^
In file included from ./arch/x86/include/asm/atomic.h:235:0,
                 from include/linux/atomic.h:4,
                 from ./arch/x86/include/asm/thread_info.h:50,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
./arch/x86/include/asm/atomic64_64.h: At top level:
./arch/x86/include/asm/atomic64_64.h:31:33: error: unknown type name ‘atomic64_t’
 static inline void atomic64_set(atomic64_t *v, long i)
                                 ^
./arch/x86/include/asm/atomic64_64.h:43:41: error: unknown type name ‘atomic64_t’
 static inline void atomic64_add(long i, atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:57:41: error: unknown type name ‘atomic64_t’
 static inline void atomic64_sub(long i, atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:73:49: error: unknown type name ‘atomic64_t’
 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
                                                 ^
./arch/x86/include/asm/atomic64_64.h:84:33: error: unknown type name ‘atomic64_t’
 static inline void atomic64_inc(atomic64_t *v)
                                 ^
./arch/x86/include/asm/atomic64_64.h:97:33: error: unknown type name ‘atomic64_t’
 static inline void atomic64_dec(atomic64_t *v)
                                 ^
./arch/x86/include/asm/atomic64_64.h:112:41: error: unknown type name ‘atomic64_t’
 static inline int atomic64_dec_and_test(atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:125:41: error: unknown type name ‘atomic64_t’
 static inline int atomic64_inc_and_test(atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:139:49: error: unknown type name ‘atomic64_t’
 static inline int atomic64_add_negative(long i, atomic64_t *v)
                                                 ^
./arch/x86/include/asm/atomic64_64.h:151:48: error: unknown type name ‘atomic64_t’
 static inline long atomic64_add_return(long i, atomic64_t *v)
                                                ^
./arch/x86/include/asm/atomic64_64.h:156:48: error: unknown type name ‘atomic64_t’
 static inline long atomic64_sub_return(long i, atomic64_t *v)
                                                ^
./arch/x86/include/asm/atomic64_64.h:164:37: error: unknown type name ‘atomic64_t’
 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
                                     ^
./arch/x86/include/asm/atomic64_64.h:169:34: error: unknown type name ‘atomic64_t’
 static inline long atomic64_xchg(atomic64_t *v, long new)
                                  ^
./arch/x86/include/asm/atomic64_64.h:183:39: error: unknown type name ‘atomic64_t’
 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
                                       ^
./arch/x86/include/asm/atomic64_64.h:207:45: error: unknown type name ‘atomic64_t’
 static inline long atomic64_dec_if_positive(atomic64_t *v)
                                             ^
In file included from include/linux/sched.h:32:0,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.c:4:
include/linux/cputime.h:4:25: fatal error: asm/cputime.h: No such file or directory
compilation terminated.
scripts/Makefile.build:264: recipe for target '/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.o' failed
make[2]: *** [/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.o] Error 1
Makefile:1383: recipe for target '_module_/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source' failed
make[1]: *** [_module_/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source] Error 2
make[1]: Leaving directory '/mnt/hgfs/Ubuntu/ebf_6ull_linux'
Makefile:10: recipe for target 'kernel_modules' failed
make: *** [kernel_modules] Error 2

解决办法

修改内核源码Makefile文件

我个人是不推荐这样做的,因为之前图方便就直接修改了内核源码根目录下的Makefile文件,导致时间久了忘记这回事,今天突然更换内核源码后就报错了。

修改方法

打开内核源码根目录下的Makefile,定位到如下位置:

ARCH		    ?= $(SUBARCH)
CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)

修改为:

ARCH		    ?= arm
CROSS_COMPILE	?= arm-linux-gnueabihf-

上述位置的arm/arm-linux-gnueabihf-取决你你自己使用的架构和交叉编译工具

修改驱动程序工程下的Makefile文件(推荐)

假如你的Makefile如下:

KERNELDIR := /mnt/hgfs/Ubuntu/ebf_6ull_linux
CURRENT_PATH := $(shell pwd)
obj-m := xxx.o

build: kernel_modules

kernel_modules:
	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:
	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

请添加两个编译变量在make命令后方

KERNELDIR := /mnt/hgfs/Ubuntu/ebf_6ull_linux
CURRENT_PATH := $(shell pwd)
ENV:=ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
obj-m := xxx.o

build: kernel_modules

kernel_modules:
	$(MAKE) $(ENV) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:
	$(MAKE) $(ENV) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

这样的话无论内核源码如何替换都不会影响驱动程序的正常编译

<think>好的,用户遇到了i2c_driver.c编译时找不到irq_ctrl.h头文件的问题,需要帮忙解决。首先,我需要了解这个头文件irq_ctrl.h的来源。根据用户的描述,项目涉及Synopsys DesignWare (SNPS-DW) I2C平台设备,所以应该检查Linux内核源码中相关驱动的部分。 用户提供的引用内容提到i2c-designware-platdrv.c的代码路径,以及platform_driver的定义,其中.of_match_table和.probe函数的设置。另外,引用了of_i2c_register_devices函数和i2c_dw_algo结构体。这些信息可以帮助定位相关驱动代码的位置,进而找到可能需要的头文件。 接下来,我需要确认irq_ctrl.h是否属于Linux内核的标准头文件。通常在Linux内核中,IRQ相关的头文件位于include/linux/interrupt.h或include/linux/irq.h,而特定于平台的IRQ控制可能会放在arch/目录下,比如arch/arm/include/asm/irq.h等。但irq_ctrl.h这个文件名并不常见,可能是一个特定于项目的自定义头文件,或者是某个驱动模块内部使用的头文件。 考虑到用户提到的是SNPS-DW I2C平台设备,可能需要检查DesignWare I2C控制器的相关驱动代码。例如,在drivers/i2c/busses/i2c-designware-*.c文件中查找是否有引用irq_ctrl.h。如果该头文件是驱动程序内部的一部分,可能在同目录下或邻近目录中存在。如果不存在,可能需要确认是否配置了正确的内核选项,或者是否有补丁需要应用。 另外,用户可能在移植或修改内核代码时遗漏了某些文件,或者项目中有自定义的irq_ctrl.h需要包含。这时候需要检查项目代码结构,确认该头文件的位置,并确保编译时的头文件搜索路径正确包含该目录。 可能的解决步骤包括: 1.内核源码中搜索irq_ctrl.h,确认是否存在。 2. 如果存在,检查Makefile中的包含路径是否正确。 3. 如果不存在,可能需要从其他部分获取该头文件,或者替换为正确的内核API。 4. 检查是否启用了相关的内核配置选项,例如CONFIG_I2C_DESIGNWARE_PLATFORM。 此外,用户提供的引用[4]提到了i2c_dw_algo结构体,其中master_xfer函数可能涉及中断处理。如果irq_ctrl.h与中断控制相关,可能需要确认是否使用了正确的中断子系统接口,例如使用request_irq()函数,并包含相应的头文件。 最后,建议用户检查代码中对irq_ctrl.h的引用位置,查看是否有拼写错误或路径错误,并确保内核配置正确,所有必要的驱动模块已启用。</think>根据SNPS-DW I2C平台设备驱动的实现逻辑,编译错误涉及缺失头文件的分析步骤如下: ### 一、头文件定位分析 1. **内核标准头文件验证** 检查内核标准路径`include/linux/`和`arch/*/include/`下是否存在`irq_ctrl.h`。当前Linux 5.4内核中该文件不是标准头文件[^1][^2] 2. **驱动专用头文件追踪** 在DW I2C驱动代码路径`drivers/i2c/busses/i2c-designware-*`中未发现该头文件引用,驱动使用标准中断API如`devm_request_irq()`[^4] 3. **硬件厂商SDK验证** `irq_ctrl.h`可能属于Synopsys平台SDK中的私有头文件,需检查是否: - 需要从芯片厂商获取配套SDK - 需将SDK路径加入编译器的头文件搜索路径(通过`-I`参数) ### 二、代码适配建议 ```c // 典型DW I2C中断处理代码段 static irqreturn_t i2c_dw_isr(int irq, void *dev_id) { struct dw_i2c_dev *dev = dev_id; // 使用标准内核中断接口 ... } ``` ### 三、解决方案 1. **验证编译环境配置** 确认Makefile包含: ```makefile ccflags-y += -I$(SDK_PATH)/include/ # 添加SDK头文件路径 ``` 2. **替代方案(标准内核API)** 若无法获取原始SDK,可将私有中断控制接口替换为: ```c #include <linux/interrupt.h> ret = request_irq(irq_num, handler, flags, name, dev); ```
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值