这里内核模块分两中,一种是模块代码本身就在kernel.org官方内核中的,另一种是外加模块如额外驱动的需求。(在这里吐槽一下openwrt把内核本身的模块也搞的这么麻烦,还需要在另外的文件中加配置,不然就算内核本身选上并编译成了.ko但就是不给你install到根文件系统,对于习惯直接以内核config文件为准的来说着实别扭)。
1. 外层Makefile编写
# Copyright (C) 2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=wsmp-prool
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define KernelPackage/wsmp-prool
SUBMENU:=Other modules
TITLE:=Support Module for wsmp-prool
FILES:=$(PKG_BUILD_DIR)/*.$(LINUX_KMOD_SUFFIX)
KCONFIG:=
endef
define KernelPackage/wsmp-prool/description
Kernel module wsmp-prool.
endef
EXTRA_KCONFIG:= \
CONFIG_WSMP_PROOL=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/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Compile
$(MAKE) -C "$(LINUX_DIR)" \
$(MAKE_OPTS) \
modules
endef
$(eval $(call KernelPackage,wsmp-prool))
2. 内层makefile
obj-$(CONFIG_WSMP_PROOL) += wsmp_prool.o
wsmp_prool-objs := wsmp.o
3. Kconfig文件编写
config BRCM-prool
tristate "Brcm Support"
---help---
Select this and you will be able to create brcm interfaces
on your ethernet interfaces.
To compile this code as a module, choose M here: the module.
If unsure, say N.
在此每个模块都有单独的目录,根据需要在其中添加src目录,Makefile、.c源文件、Kconfig等。
具体内容请参考已有模块目录,以此为模版修改就行了。
阅读(2442) | 评论(0) | 转发(0) |