编译内核驱动为模块,没有指定架构的时候出现错误

使用整点原子开发版学习Linux驱动,跳看的视频,直接上手编译一个例程出现如下error:

alientek@ubuntu16:~/linux/driver/broaddriver/01_chrdevbase$ make
make -C /home/alientek/linux/linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7 M=/home/alientek/linux/driver/broaddriver/01_chrdevbase modules
make[1]: Entering directory '/home/alientek/linux/linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7'
  CC [M]  /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopud.h:16:0: warning: "PTRS_PER_PUD" redefined
 #define PTRS_PER_PUD 1
 ^
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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:34:0: note: this is the location of the previous definition
 #define PTRS_PER_PUD 512
 ^
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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopud.h:17:0: warning: "PUD_SIZE" redefined
 #define PUD_SIZE   (1UL << PUD_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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:50:0: note: this is the location of the previous definition
 #define PUD_SIZE (_AC(1, UL) << PUD_SHIFT)
 ^
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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopud.h:18:0: warning: "PUD_MASK" redefined
 #define PUD_MASK   (~(PUD_SIZE-1))
 ^
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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:51:0: note: this is the location of the previous definition
 #define PUD_MASK (~(PUD_SIZE - 1))
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:271: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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopmd.h:19:0: warning: "PMD_SHIFT" redefined
 #define PMD_SHIFT PUD_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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:40:0: note: this is the location of the previous definition
 #define PMD_SHIFT 21
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:271: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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopmd.h:20:0: warning: "PTRS_PER_PMD" redefined
 #define PTRS_PER_PMD 1
 ^
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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:41:0: note: this is the location of the previous definition
 #define PTRS_PER_PMD 512
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:271: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 /home/alientek/linux/driver/broaddriver/01_chrdevbase/chrdevbase.c:4:
include/asm-generic/pgtable-nopmd.h:21:0: warning: "PMD_SIZE" redefined
 #define PMD_SIZE   (1UL << PMD_SHIFT)

因为直接使用的历程,并且跳过了一些内容,所以猜想不是代码抄错了,是配置原因。
跨平台需要交叉编译,命令展开后make -C /home/alientek/linux/linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7 M=/home/alientek/linux/driver/broaddriver/01_chrdevbase modules 并没有指定编译架构
将makefile文件改为

KERNELDIR :=/home/alientek/linux/linux-imx-4.1.15-2.1.0-g3dc0a4b-v2.7

CURRENT_PATH := $(shell pwd)
obj-m := chrdevbase.o

MAKE = make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

build: kernel_modules

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

解决!

你可能感兴趣的:(嵌入式Linux,linux,ubuntu,嵌入式硬件)