OpenWrt之自定义Firmware Version
首先,找到显示Firmware Version的代码,在/usr/lib/lua/luci/version.lua
中:
root@OpenWrt:/usr/lib/lua/luci# cat version.lua
local pcall, dofile, _G = pcall, dofile, _G
module "luci.version"
if pcall(dofile, "/etc/openwrt_release") and _G.DISTRIB_DESCRIPTION then
distname = ""
distversion = _G.DISTRIB_DESCRIPTION
if _G.DISTRIB_REVISION then
distrevision = _G.DISTRIB_REVISION
if not distversion:find(distrevision,1,true) then
distversion = distversion .. " " .. distrevision
end
end
else
distname = "OpenWrt"
distversion = "Development Snapshot"
end
luciname = "LuCI Master"
luciversion = "git-23.279.81765-f7ab758"
故需要修改/etc/openwrt_release
文件,查看其原本内容,可以直接在package/base-files
这个package中修改此文件。
但是这样就是每次都需要重新编译base-files
这个package。
最好应该是在打包文件系统时修改,这样每次打包rootfs
都会重新编译。
根据打包的日志,找到执行打包的地方,在include/image.mk
中,做如下修改:
diff --git a/include/image.mk b/include/image.mk
index 096ccb5..83b6ce6 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -237,6 +237,7 @@ $(eval $(foreach S,$(JFFS2_BLOCKSIZE),$(call Image/mkfs/jffs2/template,$(S))))
$(eval $(foreach S,$(NAND_BLOCKSIZE),$(call Image/mkfs/jffs2-nand/template,$(S))))
define Image/mkfs/squashfs-common
+ $(STAGING_DIR_HOST)/bin/version_maker.sh $(call mkfs_target_dir,$(1))
$(STAGING_DIR_HOST)/bin/mksquashfs4 $(call mkfs_target_dir,$(1)) $@ \
-nopad -noappend -root-owned \
-comp $(SQUASHFSCOMP) $(SQUASHFSOPT)
即在staging/host/bin
目录下,新增脚本version_maker.sh
,具体如下:
#!/bin/sh
main() {
local file=`find $1 -name openwrt_release`
# echo "file:$file"
[ ! -f $file ] && return
local D=$(TZ=UTC-8 date +%Y%m%d)
local T=$(TZ=UTC-8 date +%H%M%S)
sed -i "s/^DISTRIB_RELEASE=.*/DISTRIB_RELEASE='Adam Build $D Rel\. $T'/g" $file
sed -i "s/^DISTRIB_DESCRIPTION=.*/DISTRIB_DESCRIPTION=\'Adam Build $D Rel\. $T\'/g" $file
}
main $1
注意给文件添加可执行权限:
chmod +x version_maker.sh
然后替换对应的行即可。
标签:version,自定义,image,Firmware,mk,Version,file,DISTRIB,include From: https://www.cnblogs.com/adam-ma/p/18003081