您的位置:首页 > 运维架构 > Linux

在编写最简单的linux 内核驱动, 编译后出现的问题以及解决方法。

2017-04-18 09:18 821 查看
一、make 过后,出现的问题。

make -C /home/ubuntu/Downloads/linux-3.12.72 M=/home/ubuntu/Desktop/haoba/3th modules

make[1]: Entering directory `/home/ubuntu/Downloads/linux-3.12.72'

  CC [M]  /home/ubuntu/Desktop/haoba/3th/usb_register.o

In file included from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/bitops.h:16:0,

                 from include/linux/bitops.h:22,

                 from include/linux/kernel.h:10,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:2:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’

  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)

                                          ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/alternative.h:98:31: note: in definition of macro ‘ALTINSTR_REPLACEMENT’

  b_replacement(number)":\n\t" newinstr "\n" e_replacement(number) ":\n\t"

                               ^

/home/ubuntu/Downloads/linux-3.12.72/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 /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/segment.h:148:0,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/ptrace.h:4,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/alternative.h:8,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/bitops.h:16,

                 from include/linux/bitops.h:22,

                 from include/linux/kernel.h:10,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:2:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h: At top level:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/cache.h:7:25: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)

 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)

                         ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/cache.h:8:30: note: in expansion of macro ‘L1_CACHE_SHIFT’

 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)

                              ^

include/linux/cache.h:12:25: note: in expansion of macro ‘L1_CACHE_BYTES’

 #define SMP_CACHE_BYTES L1_CACHE_BYTES

                         ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:131:30: note: in expansion of macro ‘SMP_CACHE_BYTES’

 } __attribute__((__aligned__(SMP_CACHE_BYTES))

In file included from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/thread_info.h:22:0,

                 from include/linux/thread_info.h:54,

                 from include/linux/preempt.h:9,

                 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:17,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:4:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:131:1: error: requested alignment is not an integer constant

 } __attribute__((__aligned__(SMP_CACHE_BYTES)));

 ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:164:0: warning: "cache_line_size" redefined [enabled by default]

 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)

 ^

In file included from include/linux/time.h:4:0,

                 from include/uapi/linux/timex.h:56,

                 from include/linux/timex.h:56,

                 from include/linux/sched.h:17,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:4:

include/linux/cache.h:64:0: note: this is the location of the previous definition

 #define cache_line_size() L1_CACHE_BYTES

 ^

In file included from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/thread_info.h:22:0,

                 from include/linux/thread_info.h:54,

                 from include/linux/preempt.h:9,

                 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:17,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:4:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:253:1: error: requested alignment is not an integer constant

 } __attribute__((packed)) ____cacheline_aligned;

 ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:284:1: error: requested alignment is not an integer constant

 } ____cacheline_aligned;

 ^

In file included from include/asm-generic/percpu.h:6:0,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/percpu.h:531,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/current.h:5,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:15,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/thread_info.h:22,

                 from include/linux/thread_info.h:54,

                 from include/linux/preempt.h:9,

                 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:17,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:4:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:433:32: error: requested alignment is not an integer constant

 DECLARE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);

                                ^

include/linux/percpu-defs.h:79:38: note: in definition of macro ‘DECLARE_PER_CPU_SECTION’

  extern __PCPU_ATTRS(sec) __typeof__(type) name

                                      ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/processor.h:433:1: note: in expansion of macro ‘DECLARE_PER_CPU_ALIGNED’

 DECLARE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);

 ^

In file included from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/atomic.h:274:0,

                 from include/linux/atomic.h:4,

                 from /home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/thread_info.h:23,

                 from include/linux/thread_info.h:54,

                 from include/linux/preempt.h:9,

                 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:17,

                 from /home/ubuntu/Desktop/haoba/3th/usb_register.c:4:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/atomic64_64.h:19:1: error: unknown type name ‘atomic64_t’

 static inline long atomic64_read(const atomic64_t *v)

 ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/atomic64_64.h: In function ‘atomic64_read’:

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/atomic64_64.h:21:32: error: request for member ‘counter’ in something not a structure or union

  return (*(volatile long *)&(v)->counter);

                                ^

/home/ubuntu/Downloads/linux-3.12.72/arch/x86/include/asm/atomic64_64.h: At top level:

/home/ubuntu/Downloads/linux-3.12.72/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)

截取了大部分的问题。

二、解决问题的方式。

在网上说找的错误是默认的是生成的X86平台的。

解决的方式在编译的时候使用 make ARCH=arm CROSS_COMPILE=arm-linux-,然后 是编译的ARCH 和CROSS_COMPILE 变量没有设定,那么就在默认编译,所以就不是编译交叉编译成arm 上可以插入的模块。

为了不每次编译的时候都写的这么麻烦,我采用修改   路径/linux源码/ Makefile ,用vim Makefile 打开, 找到

ARCH            ?= $(SUBARCH)

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

然后修改为

        ARCH            := arm
       CROSS_COMPILE   := arm-linux-
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 源码 驱动 内核
相关文章推荐