OpenWrt Forum Archive

Topic: Problem when i built openwrt with my own kernel module

The content of this topic has been archived on 29 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

The problem is:
I just write a simple char dev module. call it mod1. I put the source file mod1.c in the $(LINUX_DIR)/drivers/char/ directory. But when I tried to build the image, the build system complaint:

ERROR: module '/home/zhbn/openwrt/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620/linux-3.18.45/drivers/char/mod1.ko' is missing.

what should i do to include my own modules in the build

What I tried was:

add these lines in package/kernel/linux/modules/other.mk:

    916  define KernelPackage/mod1
    917    SUBMENU:=$(OTHER_MENU)
    918    TITLE:=Practice module of char device driver
    919    KCONFIG:= \
    920        CONFIG_MOD1=y
    921    FILES:=$(LINUX_DIR)/drivers/char/mod1.ko
    922  endef

and these in build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620/linux-3.18.45/drivers/char/Makefile

    5    obj-$(CONFIG_MOD1) += mod1.o

and something into build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620/linux-3.18.45/drivers/char/Kconfig

    9    config MOD1
    10        bool "char device driver practice"
    11        default n
    12        help
    13            This is just a practice. don't select this

Don't ever copy any code into LINUX_DIR, either write a proper patch that gets applied or simply build your module like any other out of tree module. There are several examples under package/kernel.

sera wrote:

Don't ever copy any code into LINUX_DIR, either write a proper patch that gets applied or simply build your module like any other out of tree module. There are several examples under package/kernel.

Thanx. I'm still new to openwrt and things like contributing codes and packaging. I'll try and come back later

Your attempt wasn't all wrong, if you want to go this route all you need to do is convert your module / support files to a patch that you can drop into target/linux/generic/patches-x.y.

Small nags, name your Makefile Kbuild instead and use KCONFIG:=CONFIG_MOD1 without the =y. While this works for built-ins use the kernel config instead.

sera wrote:

Your attempt wasn't all wrong, if you want to go this route all you need to do is convert your module / support files to a patch that you can drop into target/linux/generic/patches-x.y.

Small nags, name your Makefile Kbuild instead and use KCONFIG:=CONFIG_MOD1 without the =y. While this works for built-ins use the kernel config instead.

Thanks. building it a kmod package works

are you sure about the path mentioned above is current? I also stuck on that.

The discussion might have continued from here.