關於Linux kernel driver module如何進行,剛好最近PO AX88179的Driver到ARMv9,將步驟記下以備不時之需,直接進入主題。

文件中有提到

To build external modules, you must have a prebuilt kernel available that contains the configuration and header files used in the build. Also, the kernel must have been built with modules enabled. If you are using a distribution kernel, there will be a package for the kernel you are running provided by your distribution.An alternative is to use the “make” target “modules_prepare.” This will make sure the kernel contains the information required. The target exists solely as a simple way to prepare a kernel source tree for building external modules.

步驟

部署方式

把 .ko 複製到 /lib/modules/5.4.0-xilinx-v2020.1/extra/

再用 modprobe 去 load module

NoteS

  1. make menuconfig → 要指定arch, if cross-compile

  2. make modules and modules_prepare, modules.order

    `make -C $KDIR M=$PWD Same as if 'modules' was specified. See description of modules target below.

    make -C $KDIR M=$PWD modules Will build the module(s) located in current directory. All output files will be located in the same directory as the module source. No attemps are made to update the kernel source, and it is expected that a successfully make has been executed for the kernel.`

    `Prepare the kernel for building external modules

    When building external modules the kernel is expected to be prepared. This includes the precense of certain binaries, the kernel configuration and the symlink to include/asm. To do this a convinient target is made:

     make modules_prepare
    

    For a typical distribution this would look like the follwoing:

     make modules_prepare O=/lib/modules/linux-/build`
    

kbuild: Documentation – how to build external modules

參考這篇引導: https://unix.stackexchange.com/questions/649904/linux-kernel-compilation-successful-but-no-image-image-generated-nowhere-to-be