# OpenWrt版本控制 ## 主要涉及文件 - `package/base-files/image-config.in`:`make menuconfig` 显示定义 ``` if VERSIONOPT config VERSION_DIST string prompt "Release distribution" default "OpenWrt" help This is the name of the release distribution. If unspecified, it defaults to OpenWrt. config VERSION_NICK string prompt "Release version nickname" help This is the release codename embedded in the image. If unspecified, it defaults to the name of source branch. config VERSION_NUMBER string prompt "Release version number" help This is the release version number embedded in the image. If unspecified, it defaults to the svn or git-svn revision of the build tree. ``` - `include/version.mk`:里面定义了从`.config`读取变量赋值给makefile变量的操作 并定义`VERSION_SED`脚本 ,用于别的文件调用的时候,替换%M为实际的makefile变量值 ``` VERSION_PRODUCT:=$(call qstrip_escape,$(CONFIG_VERSION_PRODUCT)) VERSION_PRODUCT:=$(if $(VERSION_PRODUCT),$(VERSION_PRODUCT),Generic) VERSION_HWREV:=$(call qstrip_escape,$(CONFIG_VERSION_HWREV)) VERSION_HWREV:=$(if $(VERSION_HWREV),$(VERSION_HWREV),v0) VERSION_SED:=$(SED) 's,%U,$(VERSION_REPO),g' \ -e 's,%V,$(VERSION_NUMBER),g' \ -e 's,%v,\L$(subst $(space),_,$(VERSION_NUMBER)),g' \ -e 's,%C,$(VERSION_CODE),g' \ -e 's,%c,\L$(subst $(space),_,$(VERSION_CODE)),g' \ -e 's,%N,$(VERSION_NICK),g' \ -e 's,%n,\L$(subst $(space),_,$(VERSION_NICK)),g' \ -e 's,%D,$(VERSION_DIST),g' \ -e 's,%d,\L$(subst $(space),_,$(VERSION_DIST)),g' \ -e 's,%R,$(REVISION),g' \ -e 's,%T,$(BOARD),g' \ -e 's,%S,$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic),g' \ -e 's,%t,$(VERSION_TAINTS),g' \ -e 's,%M,$(VERSION_MANUFACTURER),g' \ -e 's,%P,$(VERSION_PRODUCT),g' \ -e 's,%h,$(VERSION_HWREV),g'\ -e 's,%A,$(_KBUILD_BUILD_TIMESTAMP),g' VERSION_SED_SCRIPT:=$(subst '\'','\'\\\\\'\'',$(VERSION_SED)) ``` - `package/base-files/Makefile`:调用VERSION_SED脚本,把文件中%M替换为对应的makefile变量 ``` $(VERSION_SED) \ $(1)/etc/banner \ $(1)/etc/openwrt_version $(VERSION_SED_SCRIPT) \ $(1)/etc/openwrt_release \ $(1)/etc/device_info \ $(1)/etc/software_info ``` - package/base-files/files/etc/device_info:设备硬件信息 ``` DEVICE_MANUFACTURER='%M' DEVICE_PRODUCT='%P' DEVICE_REVISION='%h' ``` - package/base-files/files/etc/software_info ``` SOFTWART_VERSION='%C' SOFTWART_BUILD_INFO='%A' ``` - package/base-files/files/etc/banner ``` iiii i::::i iiii wwwwwww wwwww wwwwwwwiiiiiii mmmmmmm mmmmmmm w:::::w w:::::w w:::::w i:::::i mm:::::::m m:::::::mm w:::::w w:::::::w w:::::w i::::i m::::::::::mm::::::::::m w:::::w w:::::::::w w:::::w i::::i m::::::::::::::::::::::m w:::::w w:::::w:::::w w:::::w i::::i m:::::mmm::::::mmm:::::m w:::::w w:::::w w:::::w w:::::w i::::i m::::m m::::m m::::m w:::::w:::::w w:::::w:::::w i::::i m::::m m::::m m::::m w:::::::::w w:::::::::w i::::i m::::m m::::m m::::m w:::::::w w:::::::w i::::::im::::m m::::m m::::m w:::::w w:::::w i::::::im::::m m::::m m::::m w:::w w:::w i::::::im::::m m::::m m::::m www www iiiiiiiimmmmmm mmmmmm mmmmmm ------------------------------------------------------------------------- HW INFO: MANUFACTURER:%M PRODUCT :%P VERSION :%h SW INFO: REPOSITORY :%R VERSION :%C BUILD :%A ------------------------------------------------------------------------- ``` - `package/base-files/files/etc/openwrt_release` ``` DISTRIB_ID='%D' DISTRIB_RELEASE='%C' DISTRIB_REVISION='%R' DISTRIB_CODENAME='%n' DISTRIB_TARGET='%S' DISTRIB_DESCRIPTION='%D %N %V' DISTRIB_TAINTS='%t' ``` - `package/base-files/files/etc/openwrt_version` ``` %V ``` ## 变量对应关系 1. VERSION_DIST ``` VERSION_DIST:=$(call qstrip_escape,$(CONFIG_VERSION_DIST)) VERSION_DIST:=$(if $(VERSION_DIST),$(VERSION_DIST),OpenWrt) ``` ``` config VERSION_DIST string prompt "Release distribution" default "OpenWrt" help This is the name of the release distribution. If unspecified, it defaults to OpenWrt. ``` 2. VERSION_NICK ``` VERSION_NICK:=$(call qstrip_escape,$(CONFIG_VERSION_NICK)) VERSION_NICK:=$(if $(VERSION_NICK),$(VERSION_NICK),$(RELEASE)) ``` ``` string prompt "Release version nickname" help This is the release codename embedded in the image. If unspecified, it defaults to the name of source branch. ``` 注意:默认 `RELEASE:=Chaos Calmer` 3. VERSION_NUMBER ``` VERSION_NUMBER:=$(call qstrip_escape,$(CONFIG_VERSION_NUMBER)) VERSION_NUMBER:=$(if $(VERSION_NUMBER),$(VERSION_NUMBER),15.05.1) ``` ``` string prompt "Release version number" help This is the release version number embedded in the image. If unspecified, it defaults to the svn or git-svn revision of the build tree. ``` 4. VERSION_REPO:代码仓库,默认是openwrt的 ``` VERSION_REPO:=$(call qstrip_escape,$(CONFIG_VERSION_REPO)) VERSION_REPO:=$(if $(VERSION_REPO),$(VERSION_REPO),http://downloads.openwrt.org/%n/%v/%S/packages) ``` ``` string prompt "Release repository" default "http://downloads.openwrt.org/%n/%v/%S/packages" help This is the repository address embedded in the image, it defaults to the trunk snapshot repo; the url may contain the following placeholders: %R .. Revision number %V .. Release version or revision number, uppercase %v .. Release version or revision number, lowercase %C .. Release version or "Bleeding Edge", uppercase %c .. Release version or "bleeding_edge", lowercase %N .. Release name, uppercase %n .. Release name, lowercase %D .. Distribution name or "OpenWrt", uppercase %d .. Distribution name or "openwrt", lowercase %T .. Target name %S .. Target/Subtarget name %t .. Build taint flags, e.g. "no-all busybox" %M .. Manufacturer name or "OpenWrt" %P .. Product name or "Generic" %h .. Hardware revision or "v0" ``` 5. VERSION_MANUFACTURER:生产厂商名字 ``` VERSION_MANUFACTURER:=$(call qstrip_escape,$(CONFIG_VERSION_MANUFACTURER)) VERSION_MANUFACTURER:=$(if $(VERSION_MANUFACTURER),$(VERSION_MANUFACTURER),OpenWrt) ``` ``` string prompt "Manufacturer name" help This is the manufacturer name embedded in /etc/device_info Useful for OEMs building OpenWrt based firmware ``` 6. VERSION_PRODUCT:产品名称 ``` VERSION_PRODUCT:=$(call qstrip_escape,$(CONFIG_VERSION_PRODUCT)) VERSION_PRODUCT:=$(if $(VERSION_PRODUCT),$(VERSION_PRODUCT),Generic) ``` ``` string prompt "Product name" help This is the product name embedded in /etc/device_info Useful for OEMs building OpenWrt based firmware ``` 7. VERSION_HWREV:硬件版本 ``` VERSION_HWREV:=$(call qstrip_escape,$(CONFIG_VERSION_HWREV)) VERSION_HWREV:=$(if $(VERSION_HWREV),$(VERSION_HWREV),v0) ``` ``` string prompt "Hardware revision" help This is the hardware revision string embedded in /etc/device_info Useful for OEMs building OpenWrt based firmware ``` 8. VERSION_CODE:软件版本: ``` VERSION_CODE:=$(call qstrip_escape,$(CONFIG_VERSION_CODE)) VERSION_CODE:=$(if $(VERSION_CODE),$(VERSION_CODE),QSDK11.4-V1.0.0) ``` 9. VERSION_SED:脚本,用来替换文件中的%的 ``` VERSION_SED:=$(SED) 's,%U,$(VERSION_REPO),g' \ -e 's,%V,$(VERSION_NUMBER),g' \ -e 's,%v,\L$(subst $(space),_,$(VERSION_NUMBER)),g' \ -e 's,%C,$(VERSION_CODE),g' \ -e 's,%c,\L$(subst $(space),_,$(VERSION_CODE)),g' \ -e 's,%N,$(VERSION_NICK),g' \ -e 's,%n,\L$(subst $(space),_,$(VERSION_NICK)),g' \ -e 's,%D,$(VERSION_DIST),g' \ -e 's,%d,\L$(subst $(space),_,$(VERSION_DIST)),g' \ -e 's,%R,$(REVISION),g' \ -e 's,%T,$(BOARD),g' \ -e 's,%S,$(BOARD)/$(if $(SUBTARGET),$(SUBTARGET),generic),g' \ -e 's,%t,$(VERSION_TAINTS),g' \ -e 's,%M,$(VERSION_MANUFACTURER),g' \ -e 's,%P,$(VERSION_PRODUCT),g' \ -e 's,%h,$(VERSION_HWREV),g' VERSION_SED_SCRIPT:=$(subst '\'','\'\\\\\'\'',$(VERSION_SED)) ``` 总结: