關於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.
確認Kernel folder
注意Version magic (下面有note可以參考)
Kernel build
$sudo make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-/
make modules_prepare
$sudo make modules_prepare ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu-/
$make -C <path_to_kernel_src> M=$PWD
Where are *.ko
Install
把 .ko 複製到 /lib/modules/5.4.0-xilinx-v2020.1/extra/
再用 modprobe 去 load module
測試一下,Ping一下看是否有通
make menuconfig → 要指定arch, if cross-compile
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.`
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