0

The goal is to put an existing (in-source kernel) device driver into an external kernel module. The device driver is put together into a struct platform_driver instance, then is registered with module_platform_driver() macro. The macro is supposed to be implementing the module_init() and module_exit() functions necessary for a Linux kernel module definition, however with below Makefile Yocto throws multiple errors, one of them being: aarch64-poky-linux-ld.bfd: no input files

The Makefile:

obj-m += my-mod-lkm.o 
my-mod-lkm-y := my-mod.c

SRC := $(shell pwd)

all:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules

modules_install:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) modules_install

clean:
    $(MAKE) -C $(KERNEL_SRC) M=$(SRC) clean

Does Yocto not support the module_init/module_exit macros? I noticed that it does compile a simple module:

#include <linux/module.h> /* Needed by all modules */ 
#include <linux/kernel.h>
#include <linux/printk.h> /* Needed for pr_info() */ 

int init_module(void)
{
    pr_info("My module initiated!");
    return 0;
}

void cleanup_module(void)
{
    pr_info("My module exited!");
}
MODULE_LICENSE("GPL");

Why would the latter work and the more recent way of using module_init() / module_exit() not? Is it right to assume that simple call to module_platform_driver() is enough to put a platform_driver into a kernel module?

0andriy
  • 4,183
  • 1
  • 24
  • 37
Antoni
  • 176
  • 10
  • I think I just discovered the error, instead of `my-mod-lkm-y := my-mod.c` put `my-mod-lkm-y := my-mod.o`. Right now, that helps a lot. – Antoni Apr 07 '23 at 12:44
  • You missed `\n`:s in your strings, don't be puzzled with the messages. – 0andriy Apr 07 '23 at 13:31
  • It's better to use `module_init()`/`module_exit()` macros (or even `module_platform_driver()`) than reinventing a wheel. – 0andriy Apr 07 '23 at 13:34
  • Agreed, I had problems with making these macros work with Yocto, apparently fixing the typo in the `Makefile` made things work. It seems that `module_platform_driver()` indeed calls these macros and creates a module. – Antoni Apr 12 '23 at 09:02

0 Answers0