openwrt配置内核驱动_OpenWrt添加驱动模块

1. 添加模块目录

在package/kernel/下执行命令:

mkdir example

2. 建立Makefile

在package/kernel/example建立Makefile文件,命令:vim Makefile,内容如下:

#Kernel module example

include $(TOPDIR)/rules.mk

include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=example

PKG_RELEASE:=1

include $(INCLUDE_DIR)/package.mk

define KernelPackage/example

SUBMENU:=Other modules

TITLE:=Support Module for example

FILES:=$(PKG_BUILD_DIR)/$(PKG_NAME).ko

AUTOLOAD:=$(call AutoLoad,81,$(PKG_NAME))

endef

EXTRA_KCONFIG:= \

CONFIG_$(PKG_NAME)=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:= \

ARCH="$(LINUX_KARCH)" \

CROSS_COMPILE="$(TARGET_CROSS)" \

SUBDIRS="$(PKG_BUILD_DIR)" \

EXTRA_CFLAGS="$(EXTRA_CFLAGS)" \

$(EXTRA_KCONFIG)

define Build/Compile

$(MAKE) -C "$(LINUX_DIR)" \

$(MAKE_OPTS) \

modules

endef

$(eval $(call KernelPackage,$(PKG_NAME)))

3. 建立src目录

在package/kernel/example下建立src目录,命令:mkdir src,在src目录下建立Kconfig、Makefile和example.c文件。

3.1 Kconfig文件内容

config EXAMPLE

tristate "Just a example"

help

This is a example, for debugging kernel model.

If unsure, say N.

3.2 Makefile文件内容

obj-${CONFIG_EXAMPLE} += example.o

3.3 example.c文件内容

#include

#include

#include

static int __init example_init(void)

{

printk("hello example lede init!\n");

return 0;

}

static void __exit example_exit(void)

{

printk("hello example lede exit!\n");

}

module_init(example_init);

module_exit(example_exit);

MODULE_AUTHOR("hello world");

MODULE_DESCRIPTION("example driver");

MODULE_LICENSE("GPL");

4. 配置make menuconfig

在openwrt目录make menuconfig–>kernel module–>other module–>kmod-example选中,执行编译命令:make package/kernel/example/compile V=s

你可能感兴趣的:(openwrt配置内核驱动)