2015-12-22 84 views
0

我正在嘗試使用交叉編譯工具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 

任何人可以幫助我嗎?謝謝!

回答

0

好消息:您的驅動程序代碼對於最近的內核來說看起來很不錯。

壞消息:您的工具鏈和/或基本內核樹設置中可能存在問題。

看起來您正在編譯的內核頭文件與另一組頭文件(/usr/src/linux-2.6.32.69include/)衝突。檢查/usr/src/linux-2.6.32.69是否不採用非PowerPC架構。它使用powerpc .config

此外,您構建的內核源代碼樹(2.6.32)超級老 - 我們目前在4.3。是否有任何理由需要使用此版本?如果沒有,我會建議更新。

+0

感謝您的回覆。我檢查了我的系統的內核。它是一樣的,所以它可能不是因爲內核頭文件衝突。而且我不知道如何「檢查/usr/src/linux-2.6.32.69是否沒有采用非powerpc架構」。你能告訴我更多嗎? ps:我必須使用這個版本,這是一個很長的故事。謝謝你的建議:D –