BATMAN.adv系列03:修改并编译BATMAN.adv
原创文章,转发请注明链接和作者。(而且作者很懒,没有检查错别字)
本文工作于1年多前完成,由于记忆缺失可能有部分疏漏
先编译好openwrt系统,此处不再赘述
原本openwrt工程路径:./package/feeds/routing/batman-adv/。仔细查看会发现其实时一个链接到../../../../project/batman-advs/的软链接,也就时链接到./feeds/routing/batman-adv/。查看内部的Makefile,可以知道,其实在系统编译的时候openwrt将会从网络下载源码然后编译BATMAN.adv(下载路径为./dl/,里面有一个诸如batman-adv-xxxx.x.tar.gz的压缩包)。但是如果我们希望自己修改源码,则希望在本地编译自己的源码,而不是从网络下载。
下面将展开具体实时步骤,编译过程中很有可能遇到奇怪的问题可以通过下面三步(大概),本人两次搭建环境编译BATMAN.adv都遇到了问题而且都是这么解决的:
- make clean
- 删除.config
- make menuconfig重新配置
- make
注:为避免歧义将用“batman-adv”目录(有加粗)代指BATMAN.adv工程目录,具体用户是准备自己创建还是就在./feeds/routing/batman-adv/里面改自行决定。
1、新建文件夹(可选/推荐)
建议新建一个文件夹,而不是在./feeds/routing/batman-adv/里面乱改。
将./package/feeds/routing/batman-adv/连接至./package/feeds/routing/batman-adv/文件夹。
将./feeds/routing/batman-adv/里的东西全部复制到新建的文件夹。
新建一个src文件夹。
替换./package/feeds/routing/batman-adv/这个软链接为新的路径。
2、将./dl/里面的BATMAN.adv源码包解压到batman-adv目录的src(推荐自己创建,方便管理)里面。
源码大多在batman-adv/src/net/batman-adv/下,而batman-adv/patches/下的是补丁
3、修改Makefile文件
很遗憾,这里怎么修改我已经忘记了,在文末我将贴出我的Makefile供参考。相关的可以查看openwrt官网。、
4、配置中勾选BATMAN.adv
BATMAN.adv的位置会给根据Makefile中填写的内容有所变化,默认在:Kernel modules ---> Network Support ---> kmod-batman-adv
5、编译BATMAN.adv
命令:make ./package/feeds/routing/batman-adv/compile V=s
如果出现了奇奇怪怪的问题,可以尝试用上文提到的方法解决。
6、获取安装包
编译完成后里面会写XXX.ipk安装包的位置,例如:./bin/targets/ar71xx/nand/packages/kmod-batman-adv_4.9.172+0.0.0-7_mips_24kc.ipk。然后你就可以将这个安装包拷贝到路由器了。卸载路由器上之前的BATMAN.adv后,就可以在路由器运行 opkg install kmod-batman-adv_4.9.172+0.0.0-7_mips_24kc.ipk安装BATMAN.adv了。
确认上述步骤没有问题后:
7、用git命令应用batman-adv/patches/下的补丁。具体步骤自行搜索。
8、在batman-adv/src/net/batman-adv/下添加新文件后,记得需要修改batman-adv/src/net/batman-adv/Makefile
附件
源码目录下的Makefile
#
# Copyright (C) 2010 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=batman-adv
PKG_VERSION:=0.0.0
PKG_RELEASE:=7
PKG_LICENSE:=GPL-2.0
PKG_EXTMOD_SUBDIRS=net/batman-adv
STAMP_CONFIGURED_DEPENDS := $(STAGING_DIR)/usr/include/mac80211-backport/backport/autoconf.h
include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk
define KernelPackage/batman-adv
MAINTAINER:=CuSO4Gem
SUBMENU:=Other modules
DEPENDS:=+KMOD_BATMAN_ADV_BLA:kmod-lib-crc16 +kmod-crypto-crc32c +kmod-lib-crc32c +kmod-cfg80211 +kmod-ecdsa_support
TITLE:=B.A.T.M.A.N. Adv S
FILES:=$(PKG_BUILD_DIR)/net/batman-adv/batman-adv.$(LINUX_KMOD_SUFFIX)
AUTOLOAD:=$(call AutoProbe,batman-adv)
endef
define KernelPackage/batman-adv/description
B.A.T.M.A.N. advanced is a kernel module which allows to
build layer 2 mesh networks. This package builds
version $(PKG_VERSION) of the kernel module.
endef
define KernelPackage/batman-adv/config
source "$(SOURCE)/Config.in"
endef
define Package/kmod-batman-adv/conffiles
/etc/config/batman-adv
endef
PKG_EXTRA_KCONFIG:= \
CONFIG_BATMAN_ADV=m \
CONFIG_BATMAN_ADV_DEBUG=$(if $(CONFIG_KMOD_BATMAN_ADV_DEBUG_LOG),y,n) \
CONFIG_BATMAN_ADV_DEBUGFS=$(if $(CONFIG_KMOD_BATMAN_ADV_DEBUGFS),y,n) \
CONFIG_BATMAN_ADV_BLA=$(if $(CONFIG_KMOD_BATMAN_ADV_BLA),y,n) \
CONFIG_BATMAN_ADV_DAT=$(if $(CONFIG_KMOD_BATMAN_ADV_DAT),y,n) \
CONFIG_BATMAN_ADV_MCAST=$(if $(CONFIG_KMOD_BATMAN_ADV_MCAST),y,n) \
CONFIG_BATMAN_ADV_NC=$(if $(CONFIG_KMOD_BATMAN_ADV_NC),y,n) \
CONFIG_BATMAN_ADV_BATMAN_V=$(if $(CONFIG_KMOD_BATMAN_ADV_BATMAN_V),y,n) \
PKG_EXTRA_CFLAGS:= \
$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=m,%,$(filter %=m,$(PKG_EXTRA_KCONFIG)))) \
$(patsubst CONFIG_%, -DCONFIG_%=1, $(patsubst %=y,%,$(filter %=y,$(PKG_EXTRA_KCONFIG)))) \
NOSTDINC_FLAGS = \
-I$(PKG_BUILD_DIR)/net/batman-adv \
-I$(STAGING_DIR)/usr/include/mac80211-backport \
-I$(STAGING_DIR)/usr/include/mac80211-backport/uapi \
-I$(STAGING_DIR)/usr/include/mac80211 \
-I$(STAGING_DIR)/usr/include/mac80211/uapi \
-I$(PKG_BUILD_DIR)/include/ \
-include backport/backport.h \
-include $(PKG_BUILD_DIR)/compat-hacks.h \
-DBATADV_SOURCE_VERSION=\\\"openwrt-$(PKG_VERSION)-$(PKG_RELEASE)\\\"
COMPAT_SOURCES = \
$(if $(CONFIG_KMOD_BATMAN_ADV_MCAST),../../compat-sources/net/core/skbuff.o,) \
$(if $(CONFIG_KMOD_BATMAN_ADV_MCAST),../../compat-sources/net/ipv4/igmp.o,) \
$(if $(CONFIG_KMOD_BATMAN_ADV_MCAST),../../compat-sources/net/ipv6/mcast_snoop.o,) \
define Build/Compile
+env "batman-adv-y=$(COMPAT_SOURCES)" \
$(MAKE) $(PKG_JOBS) -C "$(LINUX_DIR)" \
ARCH="$(LINUX_KARCH)" \
CROSS_COMPILE="$(TARGET_CROSS)" \
SUBDIRS="$(PKG_BUILD_DIR)/net/batman-adv" \
$(PKG_EXTRA_KCONFIG) \
EXTRA_CFLAGS="$(PKG_EXTRA_CFLAGS)" \
NOSTDINC_FLAGS="$(NOSTDINC_FLAGS)" \
modules
endef
define Build/Prepare
$(call Build/Prepare/Default)
$(CP) ./files/compat-hacks.h $(PKG_BUILD_DIR)/
endef
define Build/Clean
rm -rf $(BUILD_DIR)/$(PKG_NAME)/
endef
define KernelPackage/batman-adv/install
$(INSTALL_DIR) $(1)/etc/config $(1)/etc/hotplug.d/net $(1)/etc/hotplug.d/iface $(1)/lib/batman-adv $(1)/usr/sbin $(1)/lib/netifd/proto
$(INSTALL_DATA) ./files/etc/config/batman-adv $(1)/etc/config
$(INSTALL_DATA) ./files/lib/batman-adv/config.sh $(1)/lib/batman-adv
$(INSTALL_BIN) ./files/etc/hotplug.d/net/99-batman-adv $(1)/etc/hotplug.d/net
$(INSTALL_BIN) ./files/lib/netifd/proto/batadv.sh $(1)/lib/netifd/proto
$(INSTALL_BIN) ./files/lib/netifd/proto/batadv_vlan.sh $(1)/lib/netifd/proto
endef
$(eval $(call KernelPackage,batman-adv))