Project

General

Profile

Building out-of-tree Kernel Modules

In the case where a driver needs to be built out of the kernel tree we have found that the following guide is very helpful in accomplishing this:

https://www.kernel.org/doc/Documentation/kbuild/modules.txt

Example

The following example shows building an ASIX driver module for USB ethernet adapters on the Linux Virtual Machine (https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Linux_Build_Virtual_Machine) from CL. In the case where you want to load the driver module yourself instead of having the kernel make sure that in your kernel configuration (menuconfig) the driver is not being built in, (*) option.

  1. Complete a kernel build on the virtual machine from this wiki (https://support.criticallink.com/redmine/projects/mityarm-5cs/wiki/Linux_Kernel). In this example the kernel source is located at /home/user/linux-socfgpa/
  2. Open a terminal window and navigate to the directory containing your driver source files and make file, /home/user/Downloads/AX88772C_Source/ in this example.
  3. Change into the Altera Embedded Shell.
    Quartus 14.1 Installed
    ~/altera/14.1/embedded/embedded_command_shell.sh
    

    Quartus 13.1 Installed
    ~/altera/13.1/embedded/embedded_command_shell.sh
    
  4. Build your driver using the make file included specifying the ARM cross compile parameters as shown below as well as the location of your MitySOM-5CSx linux kernel.
    user@MitySOM-Dev:~/Downloads/AX88772C_Source$ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C ~/linux-socfpga M=$PWD
    make: Entering directory `/home/user/linux-socfpga'
      LD      /home/user/Downloads/AX88772C_Source/built-in.o
      CC [M]  /home/user/Downloads/AX88772C_Source/asix.o
      Building modules, stage 2.
      MODPOST 1 modules
    WARNING: "__dev_kfree_skb_any" [/home/user/Downloads/AX88772C_Source/asix.ko] undefined!
    WARNING: "__gnu_mcount_nc" [/home/user/Downloads/AX88772C_Source/asix.ko] undefined!
      CC      /home/user/Downloads/AX88772C_Source/asix.mod.o
      LD [M]  /home/user/Downloads/AX88772C_Source/asix.ko
    make: Leaving directory `/home/user/linux-socfpga'
    
  5. Once the process has completed you can do a file listing, ls, to see that your kernel module, .ko, has been created.
    user@MitySOM-Dev:~/Downloads/AX88772C_Source$ ls
    asix.c  asix.ko     asix.mod.o  axusbnet.c  built-in.o  modules.order   readme
    asix.h  asix.mod.c  asix.o      axusbnet.h  Makefile    Module.symvers
    

Troubleshooting

  1. Do NOT use the 'sudo' command when performing the make otherwise the build will fail as it will not be able to find the specified compiler for the ARM processor as seen below.
    user@MitySOM-5CSX-dev:~/Desktop/asix/source$ sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -C /home/user/linux-socfpga/ M=$PWD
    make: arm-linux-gnueabihf-gcc: Command not found
    make: Entering directory `/home/user/linux-socfpga'
      LD      /home/user/Desktop/asix/source/built-in.o
    /bin/sh: 1: arm-linux-gnueabihf-ar: not found
    make[1]: *** [/home/user/Desktop/asix/source/built-in.o] Error 127
    make: *** [_module_/home/user/Desktop/asix/source] Error 2
    make: Leaving directory `/home/user/linux-socfpga'
    
  2. Ensure you include the cross-compile options otherwise it will attempt to build the driver for your Linux PC/VM host operating system. The build will most likely fail as it will try and use the wrong compiler against your ARM linux kernel.
    user@MitySOM-5CSX-dev:~/Desktop/asix/source$ sudo make -C /home/user/linux-socfpga/ M=$PWD
    make: Entering directory `/home/user/linux-socfpga'
      CC [M]  /home/user/Desktop/asix/source/asix.o
    In file included from /home/user/linux-socfpga/arch/x86/include/asm/bitops.h:512:0,
                     from include/linux/bitops.h:22,
                     from include/linux/kernel.h:10,
                     from include/linux/cache.h:4,
                     from include/linux/time.h:4,
                     from include/linux/stat.h:18,
                     from include/linux/module.h:10,
                     from /home/user/Desktop/asix/source/asix.c:30:
    /home/user/linux-socfpga/arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:
    /home/user/linux-socfpga/arch/x86/include/asm/arch_hweight.h:53:7: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
    

Go to top
Add picture from clipboard (Maximum size: 1 GB)