[Debugging] ERROR: “xxx” [.../xxx.ko] undefined appears when compiling the driver! Solution (details)

Phenomenon

  • When compiling the driver code, the following warning appears, and the driver module cannot be compiled
book@100ask:~/code/linux_driver/7_myuvc$ make
make -C /home/book/100ask_stm32mp157_pro-sdk/Linux-5.4 M=`pwd` modules
make[1]: 进入目录“/home/book/100ask_stm32mp157_pro-sdk/Linux-5.4”
  Building modules, stage 2.
  MODPOST 1 modules
ERROR: "video_ioctl2" [/home/book/code/linux_driver/7_myuvc/myuvc.ko] undefined!
ERROR: "__video_register_device" [/home/book/code/linux_driver/7_myuvc/myuvc.ko] undefined!
ERROR: "video_device_alloc" [/home/book/code/linux_driver/7_myuvc/myuvc.ko] undefined!
ERROR: "video_unregister_device" [/home/book/code/linux_driver/7_myuvc/myuvc.ko] undefined!
scripts/Makefile.modpost:93: recipe for target '__modpost' failed

reason

  • When the compiled module referenced the external symbol table, the specified symbol table was not found, and the used function could not be found.

Solution

1. First find the .c file that calls the "xxx function" in the error message, and then find that the header file of the defined "xxx function" is not included or the path is wrong, or add EXPORT_SYMBO (xx function) to export to the kernel symbol table.
2. The compilation rules in the Makefile of the current path of the .c file defining the relevant function or using EXPORT_SYMBOL (xxx function) do not add the dependency of the relevant .o file.
3. The compilation rule of the Makfile with the same path is obj-y or obj-m, but when make ARCH=arm menuconfig, the corresponding one is not selected to be compiled into y or m, resulting in no compilation, xx.c calls the one defined in this .c Function not found.

I am here because some drivers have not been compiled into the kernel and made an error.

How to configure the kernel to support a certain kernel file?

  • Find the corresponding makefile according to the directory where the kernel file is located
  • Search for the kernel file in the makefile, which contains its dependent configuration items
  • make menuconfig finds the corresponding symbol by/through the configuration item
  • Select the corresponding symbol to compile into the kernel

resolution process

  • Enter the top-level directory of the Linux source code
  • Execute make menuconfig
  • Enter the following interface (if not, go to install)
    insert image description here
  • Press / to enter the search interface, and find configuration items by path. Configure by space
    insert image description here
  • Exit after configuration
  • Execute make uImage in the top directory of the Linux source code to compile the kernel
  • Execute make modules to compile modules
  • Recompile the driver, the problem is solved

Guess you like

Origin blog.csdn.net/m0_61737429/article/details/129842585