1
votes

I'm trying to cross compile a Linux Kernel module (a driver) for linux-sunxi (Cubieboard 2, A20, Arm Cortex A8). What I've done:

  1. Read the article about how to build a kernel for A20: http://linux-sunxi.org/Linux_Kernel#Compilation. I've done it and the kernel has been built successfully.

  2. Tried to build my simple (just "Hello, World!") module using the following Makefile:

    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
    

I successfully used such a Makefile to build the kernel for the host (KERNELDIR=/lib/modules/$(CURRENT)/build). But this is my first time I'm doing a cross-compilation using a kernel source tree for Linux headers. And I have the following error:

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)

And a lot of other errors from the Linux source code...

I'm a new in Linux Kernel and device drivers, that's why I feel, I've missed something. In summary, what I did:

  1. Cloned the source code repo.

  2. Installed necessary packages.

  3. Configured the kmake:

    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun7i_defconfig
    
  4. Built the tree:

    make -j8 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
    
  5. Created the tree:

    make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
    
  6. Tried to make the module using the Makefile above.

Also, I know that it's not necessary to build a whole kernel tree to make a module. It's just enough to have completed Linux headers. Am I right?

And why make goes to /arch/x86/? I'm building this one for ARM...

What have I missed?

1

1 Answers

2
votes

It must be specified a compiler and an architecture I'm building the module for. Just launch make with the following args:

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