I'm trying to build a hello_world kernel module following this guide.
Here is the source code (some blank spaces should be hard tab):
Makefile:
#Kernel module example
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=example
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
EXTRA_KCONFIG:= \
CONFIG_BUTTON_HOTPLUG=m
EXTRA_CFLAGS:= \
$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(EXTRA_KCONFIG)))) \
$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(EXTRA_KCONFIG)))) \
MAKE_OPTS:=$(KERNEL_MAKE_FLAGS) \
SUBDIRS="$(PKG_BUILD_DIR)" \
EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \
CONFIG_EXAMPLE=m
define KernelPackage/example
SUBMENU:=Other modules
TITLE:=Support Module for example
FILES:=$(PKG_BUILD_DIR)/example.ko
AUTOLOAD:=$(call AutoLoad,81,example)
KCONFIG:=
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)/
$(CP) -R ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C "$(LINUX_DIR)" $(MAKE_OPTS) modules
endef
$(eval $(call KernelPackage,example))
src/Makefile
obj-${CONFIG_EXAMPLE} += example.o
src/Kconfig
config EXAMPLE
tristate "Just a example"
help
This is a example, for debugging kernel model.
If unsure, say N.
src/example.c
#include <linux/module.h>
#include <linux/version.h>
#include <linux/kmod.h>
#define DRV_NAME "example"
static int __init example_init(void)
{
printk("hello example openwrt\n");
return 0;
}
static void __exit example_exit(void)
{
printk("hello example openwrt exit\n");
}
module_init(example_init);
module_exit(example_exit);
MODULE_AUTHOR("hello world");
MODULE_DESCRIPTION("example driver");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:" DRV_NAME);
After menuconfig
, complied the toolchain and updated and installed my custom feeds, I tap:
chn@chn-PC:~/router/openwrt$ make package/example/compile V=sc
(under home/chn/router/openwrt
is openwrt source code)
It says:
make[2]: *** No rule to make target '/home/chn/router/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_nand/linux-4.9.124/.config', needed by '/home/chn/router/openwrt/build_dir/target-mips_24kc_musl/linux-ar71xx_nand/example/.built'. Stop.
Who can please tell me how to correct the error?
THANKS very much!