PowerPC上的Linux驱动程序
问题描述:
我正在尝试使用交叉编译工具powerpc-linux-gnu编译一个非常简单的powerpc驱动程序。PowerPC上的Linux驱动程序
这里是代码,driver.c
:
#include <linux/init.h>
#include <linux/module.h>
static int __init test_driver_init(void) {
printk("hello world.");
return 0;
}
static void __exit test_driver_exit(void){
/* deregister this driver*/
printk("goodbye.");
}
module_init(test_driver_init);
module_exit(test_driver_exit);
MODULE_LICENSE("GPL");
和Makefile
obj-m := driver.o
KDIR = /usr/src/linux-2.6.32.69/
all:
$(MAKE) ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- -Wall -C $(KDIR) M=$(PWD)
clean:
rm -f *.order *.symvers *.mod.c *.mod.o *.ko *.o *.tmp_versionample driver module
当我做make
,它会发生一些错误:
make ARCH=powerpc CROSS_COMPILE=powerpc-linux-gnu- -Wall -C /usr/src/linux-2.6.32.69/ M=/home/sqzhang/tdriver
make[1]: 正在进入目录 `/usr/src/linux-2.6.32.69'
CC [M] /home/sqzhang/tdriver/driver.o
In file included from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/bitops.h:267:0,
from include/linux/bitops.h:17,
from include/linux/kernel.h:15,
from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/system.h:7,
from include/linux/list.h:7,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
include/asm-generic/bitops/find.h:12:50: error: expected declaration specifiers or ‘...’ before ‘(’ token
#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
^
include/linux/bitops.h:164:22: note: in expansion of macro ‘find_first_bit’
extern unsigned long find_first_bit(const unsigned long *addr,
^
include/asm-generic/bitops/find.h:12:58: error: expected declaration specifiers or ‘...’ before ‘(’ token
#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
^
include/linux/bitops.h:164:22: note: in expansion of macro ‘find_first_bit’
extern unsigned long find_first_bit(const unsigned long *addr,
^
include/asm-generic/bitops/find.h:12:66: error: expected declaration specifiers or ‘...’ before numeric constant
#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
^
include/linux/bitops.h:164:22: note: in expansion of macro ‘find_first_bit’
extern unsigned long find_first_bit(const unsigned long *addr,
^
include/asm-generic/bitops/find.h:13:60: error: expected declaration specifiers or ‘...’ before ‘(’ token
#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
^
include/linux/bitops.h:174:22: note: in expansion of macro ‘find_first_zero_bit’
extern unsigned long find_first_zero_bit(const unsigned long *addr,
^
include/asm-generic/bitops/find.h:13:68: error: expected declaration specifiers or ‘...’ before ‘(’ token
#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
^
include/linux/bitops.h:174:22: note: in expansion of macro ‘find_first_zero_bit’
extern unsigned long find_first_zero_bit(const unsigned long *addr,
^
include/asm-generic/bitops/find.h:13:76: error: expected declaration specifiers or ‘...’ before numeric constant
#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
^
include/linux/bitops.h:174:22: note: in expansion of macro ‘find_first_zero_bit’
extern unsigned long find_first_zero_bit(const unsigned long *addr,
^
In file included from include/linux/kernel.h:16:0,
from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/system.h:7,
from include/linux/list.h:7,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/log2.h:32:5: error: redefinition of ‘__ilog2_u32’
int __ilog2_u32(u32 n)
^
In file included from include/linux/bitops.h:17:0,
from include/linux/kernel.h:15,
from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/system.h:7,
from include/linux/list.h:7,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
/usr/src/linux-2.6.32.69/arch/powerpc/include/asm/bitops.h:179:5: note: previous definition of ‘__ilog2_u32’ was here
int __ilog2_u32(u32 n)
^
In file included from include/linux/module.h:9:0,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/list.h: In function ‘list_del’:
include/linux/list.h:106:2: error: implicit declaration of function ‘_AC’ [-Werror=implicit-function-declaration]
entry->next = LIST_POISON1;
^
In file included from include/linux/list.h:5:0,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:22:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
^
include/linux/list.h:106:16: note: in expansion of macro ‘LIST_POISON1’
entry->next = LIST_POISON1;
^
include/linux/poison.h:12:65: note: each undeclared identifier is reported only once for each function it appears in
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:22:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
^
include/linux/list.h:106:16: note: in expansion of macro ‘LIST_POISON1’
entry->next = LIST_POISON1;
^
include/linux/list.h: In function ‘hlist_del’:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:22:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
^
include/linux/list.h:579:12: note: in expansion of macro ‘LIST_POISON1’
n->next = LIST_POISON1;
^
In file included from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/atomic.h:474:0,
from include/linux/spinlock.h:321,
from include/linux/seqlock.h:29,
from include/linux/time.h:8,
from include/linux/stat.h:60,
from include/linux/module.h:10,
from /home/sqzhang/tdriver/driver.c:2:
include/asm-generic/atomic64.h: At top level:
include/asm-generic/atomic64.h:17:3: error: conflicting types for ‘atomic64_t’
} atomic64_t;
^
In file included from include/linux/prefetch.h:13:0,
from include/linux/list.h:6,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/types.h:197:3: note: previous declaration of ‘atomic64_t’ was here
} atomic64_t;
^
In file included from include/linux/sched.h:63:0,
from /usr/src/linux-2.6.32.69/arch/powerpc/include/asm/elf.h:5,
from include/linux/elf.h:7,
from include/linux/module.h:14,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/mm_types.h:248:2: error: unknown type name ‘mm_context_t’
mm_context_t context;
^
In file included from include/linux/list.h:5:0,
from include/linux/module.h:9,
from /home/sqzhang/tdriver/driver.c:2:
include/linux/rculist.h: In function ‘list_del_rcu’:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:23:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
^
include/linux/rculist.h:97:16: note: in expansion of macro ‘LIST_POISON2’
entry->prev = LIST_POISON2;
^
include/linux/rculist.h: In function ‘list_replace_rcu’:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:23:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
^
include/linux/rculist.h:143:14: note: in expansion of macro ‘LIST_POISON2’
old->prev = LIST_POISON2;
^
include/linux/rculist.h: In function ‘hlist_del_rcu’:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:23:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
^
include/linux/rculist.h:286:13: note: in expansion of macro ‘LIST_POISON2’
n->pprev = LIST_POISON2;
^
include/linux/rculist.h: In function ‘hlist_replace_rcu’:
include/linux/poison.h:12:65: error: ‘UL’ undeclared (first use in this function)
# define POISON_POINTER_DELTA _AC(CONFIG_ILLEGAL_POINTER_VALUE, UL)
^
include/linux/poison.h:23:46: note: in expansion of macro ‘POISON_POINTER_DELTA’
#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
^
include/linux/rculist.h:306:15: note: in expansion of macro ‘LIST_POISON2’
old->pprev = LIST_POISON2;
^
cc1: some warnings being treated as errors
make[2]: *** [/home/sqzhang/tdriver/driver.o] 错误 1
make[1]: *** [_module_/home/sqzhang/tdriver] 错误 2
make[1]:正在离开目录 `/usr/src/linux-2.6.32.69'
make: *** [all] 错误 2
任何人可以帮助我吗?谢谢!
答
好消息:您的驱动程序代码对于最近的内核来说看起来很不错。
坏消息:您的工具链和/或基本内核树设置中可能存在问题。
看起来您正在编译的内核头文件与另一组头文件(/usr/src/linux-2.6.32.69
与include/
)冲突。检查/usr/src/linux-2.6.32.69
是否不采用非PowerPC架构。它使用powerpc .config
?
此外,您构建的内核源代码树(2.6.32)超级老 - 我们目前在4.3。是否有任何理由需要使用此版本?如果没有,我会建议更新。
感谢您的回复。我检查了我的系统的内核。它是一样的,所以它可能不是因为内核头文件冲突。而且我不知道如何“检查/usr/src/linux-2.6.32.69是否没有采用非powerpc架构”。你能告诉我更多吗? ps:我必须使用这个版本,这是一个很长的故事。谢谢你的建议:D –