1

I have programmed a simple module that can be loaded into the kernel to control a simple led. It works fine. The source files are two C files and one header file:

gpio_handler_ws.c nct5104d_access.c nct5104d_access.h

I decided to add it to kernel sources doing these steps:

 1. In drivers/char modify the Kconfig file adding:

    config GPIO0_DEVICE
        tristate "GPIO0 device"
        default y
        help
            "Creates /dev/wsgpio0 char device to control GPIO0"

 2. In drivers/char modify the Makefile file adding:

       obj-$(CONFIG_GPIO0_DEVICE)   += wsgpio_udev.o
       wsgpio_udev-objs := gpio_handler_ws.o nct5104d_access.o

 3. Copy source and headers files to drivers/char directory

Then, if I select the m option in menuconfig to compile it as a module, it creates the wsgpio_udev.ko file that works as expected, I can load it and it creates de /dev/wsgpio0 device that controls the LED.

BUT if I select the built-in option it compiles and generates the wsgpio_udev.o file but after rebooting with the new kernel no /dev/wsgpio0 device is created. As far as I know, the built-in modules are listed in /lib/modules/$(uname -r)/modules.builtin but I don't see wsgpio_udev.ko there

Am I missing something?

jap jap
  • 320
  • 2
  • 15
  • is the "triestate" typo in your kernel source, or just in this post? – Alex Zeffertt Jun 22 '17 at 10:15
  • Use 'lsmod' command to list loaded modules. or $cat /proc/modules to check your module is loaded into kernel. – beparas Jun 22 '17 at 10:18
  • @AlexZeffertt it was a typo in the post, I edited it – jap jap Jun 22 '17 at 10:20
  • @beparas that just shows the loaded modules, not the ones that are built into the kernel – jap jap Jun 22 '17 at 10:22
  • 2
    Looked for an example of what you want to do in drivers/char/Makefile and found this. Note, they didn't use the -objs suffix: obj-$(CONFIG_JS_RTC) += js-rtc.o js-rtc-y = rtc.o – Alex Zeffertt Jun 22 '17 at 10:24
  • @AlexZeffertt thanks Alex, I'll try it that way – jap jap Jun 22 '17 at 10:26
  • 1
    *"generates the wsgpio_udev.o file but after rebooting with the new kernel no /dev/wsgpio0 device is created."* -- You need to do more debugging between those two steps. Inspect **System.map** for the init entry point of your driver. If your driver is in the kernel, then use `initcall_debug` parameter to check if your driver's init routine is called. See https://stackoverflow.com/questions/37272109/how-to-get-details-of-all-modules-drivers-got-initialized-probed-during-kernel-b/37283021#37283021 – sawdust Jun 22 '17 at 18:46

0 Answers0