The development environment is Ubuntu. First build the environment of compilation.
sudo apt-get install gcc g++ binutils patch bzip2 Flex bison make autoconf gettext texinfo unzip sharutils subversion libn Curses5-dev ncurses-term zlib1g-dev gawk asciidoc libz-dev git-core build-essential Libssl-dev
The following is the download source code, the source is divided into two, one is the latest version but unstable, is the trunk version, a relatively stable version, backfire version
Trunk version download command: SVN co svn://svn.openwrt.org/openwrt/trunk/
Backfire version download command: SVN co svn://svn.openwrt.org/openwrt/branches/backfire/
If it is not the latest download, it is best to update the code regularly, command
./scripts/feeds Update–a
./scripts/feeds Install–a
Then it's compiled. The compilation method is as follows:
Make Defconfig
Make Menuconfig enters the custom interface and chooses its own device type.
Make v=99
Here's how to add a kernel module.
Enter the package directory to create the module directory
CD Backfire/package
mkdir Example
Enter example directory, create makefile file and code path
CD Example
Touch Makefile
mkdir SRC
Makefile specific contents are as follows:
#
# 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:=example
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define KernelPackage/example
SUBMENU:=Other modules
TITLE:=example driver
DEPENDS:=@LINUX_2_6
FILES:=$(PKG_BUILD_DIR)/*.$(LINUX_KMOD_SUFFIX)
KCONFIG:=
endef
define KernelPackage/example/description
Kernel module to example
endef
EXTRA_KCONFIG:= \
CONFIG_EXAMPLE=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,example))
3. Enter the SRC directory, create the code path and related source files
CD src
Touch example.c Kconfig Makefile
Example.c specific contents are as follows:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>/
* Hello _init----initialization function, which is called when the module is loaded, returns a non-0 value/
static int __init hello_init (void)
{
printk ("I bear a") if a successful mount returns 0 Charmed life.\n ");
return 0;
}
/* hello_exit----Exit function, which is invoked when the module is unloaded */
static void __exit hello_exit (void)
{
PRINTK ("Out, out, brief candle\ n ");
}
Module_init (hello_init);
Module_exit (hello_exit);
Module_license ("GPL");
Module_author ("Zhangjiefeng");
Kconfig specific contents are as follows:
Config EXAMPLE
tristate "Just a EXAMPLE" help this
is a EXAMPLE, for debugging kernel model.
If unsure, say N.
Makefile specific inside as follows:
obj-$ (config_example) + + EXAMPLE.O
Back to main path backfire/, compile option configuration save and compile
Make Menuconfig
Kernel Modules--->
Other Modules--->
Kmod-example
option is set to M, save exit
Then compile the module:
Make Package/example/compile
5. The compiled file can be found in the following path of the main path
./staging_dir/target-mips_r2_uclibc-0.9.30.1/root-lantiq/lib/modules/2.6.32.33/example.ko
./build_dir/linux-lantiq_ar9/example/ipkg-lantiq/kmod-example/lib/modules/2.6.32.33/example.ko
./build_dir/linux-lantiq_ar9/example/example.ko
./build_dir/target-mips_r2_uclibc-0.9.30.1/openwrt-sdk-lantiq-for-linux-x86_64-gcc-4.3.3+cs_uclibc-0.9.30.1/ Staging_dir/target-mips_r2_uclibc-0.9.30.1/root-lantiq/lib/modules/2.6.32.33/example.ko
./build_dir/target-mips_r2_uclibc-0.9.30.1/root-lantiq/lib/modules/2.6.32.33/example.ko
Note: we use./build_dir/linux-lantiq_ar9/example/example.ko
Reference Documentation:
Http://blog.chinaunix.net/uid-9217288-id-3060464.html
http://downloads.openwrt.org/kamikaze/docs/openwrt.html#x1-470002.1.3
http://blog.csdn.net/gubenpeiyuan/article/details/8024247