博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
编译内核驱动模块出错(./arch/x86/include/asm/xxx fatal error: asm/xxx: No such file or directory)
阅读量:3898 次
发布时间:2019-05-23

本文共 14250 字,大约阅读时间需要 47 分钟。

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

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

make  -C /mnt/hgfs/Ubuntu/ebf_6ull_linux M=/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source modulesmake[1]: Entering directory '/mnt/hgfs/Ubuntu/ebf_6ull_linux'  CC [M]  /mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.oIn 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 directorycompilation terminated.scripts/Makefile.build:264: recipe for target '/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.o' failedmake[2]: *** [/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source/mydevice.o] Error 1Makefile:1383: recipe for target '_module_/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source' failedmake[1]: *** [_module_/mnt/hgfs/Ubuntu/imx6ULL/imx6ULL/source] Error 2make[1]: Leaving directory '/mnt/hgfs/Ubuntu/ebf_6ull_linux'Makefile:10: recipe for target 'kernel_modules' failedmake: *** [kernel_modules] Error 2

解决办法

修改内核源码Makefile文件

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

修改方法

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

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

修改为:

ARCH		    ?= armCROSS_COMPILE	?= arm-linux-gnueabihf-

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

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

假如你的Makefile如下:

KERNELDIR := /mnt/hgfs/Ubuntu/ebf_6ull_linuxCURRENT_PATH := $(shell pwd)obj-m := xxx.obuild: kernel_moduleskernel_modules:	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modulesclean:	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

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

KERNELDIR := /mnt/hgfs/Ubuntu/ebf_6ull_linuxCURRENT_PATH := $(shell pwd)ENV:=ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-obj-m := xxx.obuild: kernel_moduleskernel_modules:	$(MAKE) $(ENV) -C $(KERNELDIR) M=$(CURRENT_PATH) modulesclean:	$(MAKE) $(ENV) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

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

转载地址:http://uqfen.baihongyu.com/

你可能感兴趣的文章
WebKit之MediaPlayer之底层调度的源码分析
查看>>
WIFI之系统模块列表介绍
查看>>
C++之数据库处理代理模块
查看>>
C++之编码实现ping的功能
查看>>
C++之动态配置ip信息
查看>>
生活之工资条(薪资结构参考)
查看>>
Makefile之通用模板
查看>>
Makefile之常用函数介绍
查看>>
Makefile之自动变量介绍
查看>>
C++之位测试练习的相关代码
查看>>
C++之IPC测试单元
查看>>
C++之测试snmp的注册模块
查看>>
WebKit之WebSocket的初步源码分析2
查看>>
WebKit之Canvas的源码初步分析1
查看>>
WebKit之Canvas源码分析2
查看>>
WebKit之CSSValue的继承关系
查看>>
WebKit之ScriptWrapper继承关系图
查看>>
Perl之默认变量
查看>>
Linux之ARM/Linux与单片机开发差异
查看>>
Linux之内存泄露的检测工具
查看>>