怎么建设信息网站,网站制作易捷网络,浏览器主页制作,专业seo站长工具编译OpenWrt内核驱动可以参考OpenWrt内部其它驱动的编写例程#xff0c;来修改成自己需要的驱动
一、OpenWrt源代码获取与编译
1.1、搭建环境 下载OpenWrt的官方源码#xff1a;
git clone https://github.com/openwrt/openwrt.git1.2、安装编译依赖项
sudo apt update -… 编译OpenWrt内核驱动可以参考OpenWrt内部其它驱动的编写例程来修改成自己需要的驱动
一、OpenWrt源代码获取与编译
1.1、搭建环境 下载OpenWrt的官方源码
git clone https://github.com/openwrt/openwrt.git
1.2、安装编译依赖项
sudo apt update -y
sudo apt full-upgrade -y
sudo apt install -y ack antlr3 asciidoc autoconf automake autopoint binutils bison build-essential \
bzip2 ccache cmake cpio curl device-tree-compiler fastjar flex gawk gettext gcc-multilib g-multilib \
git gperf haveged help2man intltool libc6-dev-i386 libelf-dev libglib2.0-dev libgmp3-dev libltdl-dev \
libmpc-dev libmpfr-dev libncurses5-dev libncursesw5-dev libreadline-dev libssl-dev libtool lrzsz \
mkisofs msmtp nano ninja-build p7zip p7zip-full patch pkgconf python2.7 python3 python3-pyelftools \
libpython3-dev qemu-utils rsync scons squashfs-tools subversion swig texinfo uglifyjs upx-ucl unzip \
vim wget xmlto xxd zlib1g-dev python3-setuptools
1.3、更新 feeds 进入openwrt目录后执行以下指令 ./scripts/feeds update -a
./scripts/feeds install -a
1.4、配置编译选项 根据自己的平台来选择编译选项
make menuconfig1.5、下载 dl 库 进入openwrt目录后执行以下指令
make download -j81.6、编译
make Vs -j1二、OpenWrt驱动源代码分析 OpenWrt驱动存放目录为openwrt\package\kernel 以gpio-button-hotplug驱动为例进行分析。在gpio-button-hotplug文件夹下面有一个Makefile文件和src文件夹而src文件夹下有模块源码gpio-button-hotplug.c和源码编译Makefile
2.1、顶层makefile分析 顶层makefile如下
#
# Copyright (C) 2008-2012 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.mkPKG_NAME:gpio-button-hotplug
PKG_RELEASE:3
PKG_LICENSE:GPL-2.0include $(INCLUDE_DIR)/package.mkdefine KernelPackage/gpio-button-hotplugSUBMENU:Other modulesTITLE:Simple GPIO Button Hotplug driverFILES:$(PKG_BUILD_DIR)/gpio-button-hotplug.koAUTOLOAD:$(call AutoLoad,30,gpio-button-hotplug,1)KCONFIG:
endefdefine KernelPackage/gpio-button-hotplug/descriptionThis is a replacement for the following in-kernel drivers:1) gpio_keys (KEYBOARD_GPIO)2) gpio_keys_polled (KEYBOARD_GPIO_POLLED)Instead of generating input events (like in-kernel drivers do) it generatesuevent-s and broadcasts them. This allows disabling input subsystem which isan overkill for OpenWrt simple needs.
endefdefine Build/Compile$(KERNEL_MAKE) M$(PKG_BUILD_DIR) modules
endef$(eval $(call KernelPackage,gpio-button-hotplug))
2.1.1、第一步 首先包含rules.mk、kernel.mk和package.mk文件。接着将驱动模块的名称定义为“gpio-button-hotplug”并设置版本编号为“3”。
2.1.2、第二步 在软件包定义中的一些变量赋值 SUBMENU我们内核模块放置于“Other modules”。我们在make menuconfig时可以在Kernel modules/other modules菜单下找到这个模块。 TITLE标题驱动模块的简短描述。 FILES生成的驱动模块的存放位置。此处为设置为在编译目录下就是编译过程中的临时目录build_dir。 AUTOLOAD代表是否在系统启动时自动装载到内核中后面括号内有3个参数参数1不变参数2为驱动模块的装载顺序(可以省略这个参数省略后系统自动分配状态顺序)参数3代表驱动模块名称。 DEPENDS如果驱动模块还需要依赖则此变量设置为依赖文件名此处没有依赖所以就未设置。
2.1.3、第三步 配置menuconfig时的描述信息
2.1.4、第四步 编译源代码选项在大多数情况下应该不用定义而使用默认值
2.1.5、第五步 最后KernelPackage将驱动模块的名称作为参数传递给KernelPackage
2.2、源码makefile
obj-m gpio-button-hotplug.o2.3、源码gpio-button-hotplug.c gpio-button-hotplug.c就是驱动的实际代码
三、编写自己的OpenWrt驱动代码 将gpio-button-hotplug文件夹复制为mykernel_test放置到gpio-button-hotplug相同的目录下
3.1、顶层makefile 修改顶层makefile如下
#
# Copyright (C) 2008-2012 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.mkPKG_NAME:mykernel_test
PKG_RELEASE:3
PKG_LICENSE:GPL-2.0include $(INCLUDE_DIR)/package.mkdefine KernelPackage/mykernel_testSUBMENU:Other modulesTITLE:Simple GPIO Button Hotplug driverFILES:$(PKG_BUILD_DIR)/mykernel_test.koAUTOLOAD:$(call AutoLoad,30,mykernel_test,1)KCONFIG:
endefdefine KernelPackage/mykernel_test/descriptionThis is a replacement for the following in-kernel drivers:1) gpio_keys (KEYBOARD_GPIO)2) gpio_keys_polled (KEYBOARD_GPIO_POLLED)Instead of generating input events (like in-kernel drivers do) it generatesuevent-s and broadcasts them. This allows disabling input subsystem which isan overkill for OpenWrt simple needs.
endefdefine Build/Compile$(KERNEL_MAKE) M$(PKG_BUILD_DIR) modules
endef$(eval $(call KernelPackage,mykernel_test))
3.2、源码makefile
obj-m mykernel_test.o3.3、源码mykernel_test.c.c
#include linux/init.h
#include linux/module.hstatic int __init mykernel_test_init(void)
{printk(KERN_INFO mykernel_test enter\n);return 0;
}static void __exit mykernel_test_exit(void)
{printk(KERN_INFO mykernel_test exit\n );
}
module_init(mykernel_test_init);
module_exit(mykernel_test_exit);
MODULE_LICENSE(GPL v2);
四、编译自己的OpenWrt驱动代码
4.1、配置 在OpenWrt源码顶级目录下输入下面的命令配置内核
make menuconfig依次按照如下顺序选择
4.2、编译 在OpenWrt源码顶级目录下输入下面的命令编译驱动模块
make package/kernel/mykernel_test/compile Vs编译完成之后会在下面的目录中看到我们的内核模块 此ko模块和普通的linux内核的驱动模块的装载方法一样不再赘述。 文章转载自: http://www.morning.nlnmy.cn.gov.cn.nlnmy.cn http://www.morning.fbmzm.cn.gov.cn.fbmzm.cn http://www.morning.zpyxl.cn.gov.cn.zpyxl.cn http://www.morning.bgdk.cn.gov.cn.bgdk.cn http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.sbjbs.cn.gov.cn.sbjbs.cn http://www.morning.ljzss.cn.gov.cn.ljzss.cn http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.rkjz.cn.gov.cn.rkjz.cn http://www.morning.krkwh.cn.gov.cn.krkwh.cn http://www.morning.xtrzh.cn.gov.cn.xtrzh.cn http://www.morning.jbpdk.cn.gov.cn.jbpdk.cn http://www.morning.ypdhl.cn.gov.cn.ypdhl.cn http://www.morning.dwmtk.cn.gov.cn.dwmtk.cn http://www.morning.hqgxz.cn.gov.cn.hqgxz.cn http://www.morning.rhkgz.cn.gov.cn.rhkgz.cn http://www.morning.stpkz.cn.gov.cn.stpkz.cn http://www.morning.pflpb.cn.gov.cn.pflpb.cn http://www.morning.rbbyd.cn.gov.cn.rbbyd.cn http://www.morning.pcxgj.cn.gov.cn.pcxgj.cn http://www.morning.tkyry.cn.gov.cn.tkyry.cn http://www.morning.dlwzm.cn.gov.cn.dlwzm.cn http://www.morning.fphbz.cn.gov.cn.fphbz.cn http://www.morning.xscpq.cn.gov.cn.xscpq.cn http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.lkkgq.cn.gov.cn.lkkgq.cn http://www.morning.ljbch.cn.gov.cn.ljbch.cn http://www.morning.zpjhh.cn.gov.cn.zpjhh.cn http://www.morning.tfcwj.cn.gov.cn.tfcwj.cn http://www.morning.mjzgg.cn.gov.cn.mjzgg.cn http://www.morning.kpcxj.cn.gov.cn.kpcxj.cn http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn http://www.morning.lgrkr.cn.gov.cn.lgrkr.cn http://www.morning.knczz.cn.gov.cn.knczz.cn http://www.morning.wttzp.cn.gov.cn.wttzp.cn http://www.morning.kldtf.cn.gov.cn.kldtf.cn http://www.morning.kqbzy.cn.gov.cn.kqbzy.cn http://www.morning.xkzmz.cn.gov.cn.xkzmz.cn http://www.morning.qhczg.cn.gov.cn.qhczg.cn http://www.morning.beiyishengxin.cn.gov.cn.beiyishengxin.cn http://www.morning.ccyjt.cn.gov.cn.ccyjt.cn http://www.morning.shangwenchao4.cn.gov.cn.shangwenchao4.cn http://www.morning.tcfhs.cn.gov.cn.tcfhs.cn http://www.morning.brbnc.cn.gov.cn.brbnc.cn http://www.morning.lmtbl.cn.gov.cn.lmtbl.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.zkdmk.cn.gov.cn.zkdmk.cn http://www.morning.rcqyk.cn.gov.cn.rcqyk.cn http://www.morning.rzscb.cn.gov.cn.rzscb.cn http://www.morning.qlwfz.cn.gov.cn.qlwfz.cn http://www.morning.grbgn.cn.gov.cn.grbgn.cn http://www.morning.bfrff.cn.gov.cn.bfrff.cn http://www.morning.ldcsw.cn.gov.cn.ldcsw.cn http://www.morning.glnmm.cn.gov.cn.glnmm.cn http://www.morning.hpmzs.cn.gov.cn.hpmzs.cn http://www.morning.rwpfb.cn.gov.cn.rwpfb.cn http://www.morning.jfcbs.cn.gov.cn.jfcbs.cn http://www.morning.gbxxh.cn.gov.cn.gbxxh.cn http://www.morning.tjkth.cn.gov.cn.tjkth.cn http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.crsqs.cn.gov.cn.crsqs.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.paxkhqq.cn.gov.cn.paxkhqq.cn http://www.morning.zgpgl.cn.gov.cn.zgpgl.cn http://www.morning.sgbk.cn.gov.cn.sgbk.cn http://www.morning.sfwfk.cn.gov.cn.sfwfk.cn http://www.morning.lbssg.cn.gov.cn.lbssg.cn http://www.morning.yprnp.cn.gov.cn.yprnp.cn http://www.morning.tnbsh.cn.gov.cn.tnbsh.cn http://www.morning.mftzm.cn.gov.cn.mftzm.cn http://www.morning.dpplr.cn.gov.cn.dpplr.cn http://www.morning.mbmtn.cn.gov.cn.mbmtn.cn http://www.morning.llxns.cn.gov.cn.llxns.cn http://www.morning.zlgth.cn.gov.cn.zlgth.cn http://www.morning.swimstaracademy.cn.gov.cn.swimstaracademy.cn http://www.morning.wfyqn.cn.gov.cn.wfyqn.cn http://www.morning.yslfn.cn.gov.cn.yslfn.cn http://www.morning.psxxp.cn.gov.cn.psxxp.cn http://www.morning.cplym.cn.gov.cn.cplym.cn