2015-07-03 107 views
0

我正在嘗試爲linux-sunxi(Cubieboard 2,A20,Arm Cortex A8)交叉編譯Linux內核模塊(驅動程序)。我做了什麼:從源代碼樹構建Linux內核模塊

  1. 閱讀關於如何建立一個內核爲A20的文章:http://linux-sunxi.org/Linux_Kernel#Compilation。我已經完成了,並且內核已經成功構建。

    ifeq ($(KERNELRELEASE),) 
        KERNELDIR = /home/nikita/linux-sunxi/output/lib/modules/3.4.61/build 
        PWD =$(shell pwd) 
    modules: 
        $(MAKE) -C $(KERNELDIR) M=$(PWD) modules 
    clean:      
        rm -rf *.o *.ko .tmp_versions *.mod.c modules.order Module.symvers 
    else      
        obj-m :=my_mod.o 
    endif 
    

我成功地用這樣一個Makefile建立主機內核(KERNELDIR:

  • 使用下面的Makefile模塊試圖建立我的簡單(只是「你好,世界!」) =/LIB /模塊/ $(CURRENT)/版本)。但這是我第一次使用Linux頭文件的內核源代碼樹進行交叉編譯。我有以下錯誤:

    CC [M] /home/nikita/Kernel_Study/linaro_first_module/my_mod.o 
    In file included from /home/nikita/linux-sunxi/arch/x86/include/asm/bitops.h:16:0, 
           from include/linux/bitops.h:22, 
           from include/linux/kernel.h:19, 
           from include/linux/cache.h:4, 
           from include/linux/time.h:7, 
           from include/linux/stat.h:60, 
           from include/linux/module.h:10, 
           from /home/nikita/Kernel_Study/linaro_first_module/my_mod.c:2: 
    /home/nikita/linux-sunxi/arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’: 
    /home/nikita/linux-sunxi/arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’ 
        asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) 
                 ^
    /home/nikita/linux-sunxi/arch/x86/include/asm/alternative.h:93:18: note: in definition of macro ‘ALTERNATIVE’ 
         "663:\n\t" newinstr "\n664:\n" /* replacement  */ \ 
           ^
    In file included from include/linux/cache.h:5:0, 
           from include/linux/time.h:7, 
           from include/linux/stat.h:60, 
           from include/linux/module.h:10, 
           from /home/nikita/Kernel_Study/linaro_first_module/my_mod.c:2: 
    /home/nikita/linux-sunxi/arch/x86/include/asm/processor.h: At top level: 
    /home/nikita/linux-sunxi/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) 
    

    和很多從Linux的源代碼其他錯誤...

    我是一個新的Linux內核和設備驅動程序,這就是爲什麼我覺得,我錯過了一些東西。總之,我做了什麼:

    1. 克隆了源代碼回購。

    2. 安裝必要的軟件包。

    3. 配置kmake:

      make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig 
      
    4. 內置樹:

      make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules 
      
    5. 創建的樹:

      make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install 
      
    6. 把我的使用Makefile上面的模塊。

    此外,我知道沒有必要構建一個完整的內核樹來創建一個模塊。這足以完成Linux頭文件。我對嗎?

    爲什麼要去/arch/x86/?我正在爲ARM構建這個...

    我錯過了什麼?

  • 回答

    2

    必須指定一個編譯器和我正在構建模塊的體系結構。剛剛推出使用以下參數:

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