ASR_BASE

Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/package/boot/uboot-envtools/files/apm821xx b/package/boot/uboot-envtools/files/apm821xx
new file mode 100644
index 0000000..6bcc3ad
--- /dev/null
+++ b/package/boot/uboot-envtools/files/apm821xx
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+meraki,mr24)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000" "4"
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x4000" "0x4000" "4"
+	;;
+meraki,mx60)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000" "4"
+	;;
+netgear,wndap620|\
+netgear,wndap660)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000" "4"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/ath79 b/package/boot/uboot-envtools/files/ath79
new file mode 100644
index 0000000..abcb996
--- /dev/null
+++ b/package/boot/uboot-envtools/files/ath79
@@ -0,0 +1,118 @@
+#!/bin/sh
+#
+# Copyright (C) 2011-2014 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+alfa-network,ap121f|\
+alfa-network,ap121fe|\
+alfa-network,n2q|\
+alfa-network,n5q|\
+alfa-network,pi-wifi4|\
+alfa-network,r36a|\
+allnet,all-wap02860ac|\
+arduino,yun|\
+buffalo,bhr-4grv2|\
+devolo,magic-2-wifi|\
+engenius,eap1200h|\
+engenius,eap300-v2|\
+engenius,eap350-v1|\
+engenius,eap600|\
+engenius,ecb1200|\
+engenius,ecb1750|\
+engenius,ecb350-v1|\
+engenius,ecb600|\
+engenius,enh202-v1|\
+engenius,ens202ext-v1|\
+engenius,enstationac-v1|\
+etactica,eg200|\
+glinet,gl-ar750s-nor|\
+glinet,gl-ar750s-nor-nand|\
+librerouter,librerouter-v1|\
+netgear,ex6400|\
+netgear,ex7300|\
+netgear,wndr4300-v2|\
+netgear,wndr4500-v3|\
+netgear,wnr1000-v2|\
+netgear,wnr2000-v3|\
+netgear,wnr2200-8m|\
+netgear,wnr2200-16m|\
+netgear,wnr612-v2|\
+ocedo,koala|\
+ocedo,raccoon|\
+openmesh,mr600-v1|\
+openmesh,mr600-v2|\
+openmesh,mr900-v1|\
+openmesh,mr900-v2|\
+openmesh,mr1750-v1|\
+openmesh,mr1750-v2|\
+openmesh,om5p|\
+openmesh,om5p-ac-v2|\
+samsung,wam250|\
+ubnt,nanostation-m|\
+yuncore,a770|\
+yuncore,a782|\
+yuncore,xd4200|\
+zyxel,nbg6616)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
+	;;
+buffalo,wzr-hp-ag300h)
+	ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
+	;;
+domywifi,dw33d)
+	ubootenv_add_uci_config "/dev/mtd4" "0x0" "0x10000" "0x10000"
+	;;
+glinet,gl-ar150)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x8000" "0x10000"
+	;;
+glinet,gl-ar300m-lite|\
+glinet,gl-ar300m-nand|\
+glinet,gl-ar300m-nor|\
+glinet,gl-ar300m16)
+	idx="$(find_mtd_index u-boot-env)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
+	;;
+netgear,wndr3700|\
+netgear,wndr3700-v2|\
+netgear,wndrmac-v1)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
+	;;
+netgear,wndr3700-v4|\
+netgear,wndr4300|\
+netgear,wndr4300tn|\
+netgear,wndr4300sw)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
+	;;
+openmesh,om2p-v2|\
+openmesh,om2p-v4|\
+openmesh,om2p-hs-v1|\
+openmesh,om2p-hs-v2|\
+openmesh,om2p-hs-v3|\
+openmesh,om2p-hs-v4|\
+openmesh,om2p-lc|\
+plasmacloud,pa300|\
+plasmacloud,pa300e)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
+	;;
+qihoo,c301)
+	ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x10000" "0x10000"
+	;;
+wallys,dr531)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/cns3xxx b/package/boot/uboot-envtools/files/cns3xxx
new file mode 100644
index 0000000..f998de4
--- /dev/null
+++ b/package/boot/uboot-envtools/files/cns3xxx
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+laguna)
+	# Laguna uboot env size/erasesize vary depending on NOR vs SPI FLASH
+	size=$(grep mtd1 /proc/mtd | awk '{print $2}')
+	erasesize=$(grep mtd1 /proc/mtd | awk '{print $3}')
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x$size" "0x$erasesize"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/imx6 b/package/boot/uboot-envtools/files/imx6
new file mode 100644
index 0000000..5d960df
--- /dev/null
+++ b/package/boot/uboot-envtools/files/imx6
@@ -0,0 +1,65 @@
+#!/bin/sh
+#
+# Copyright (C) 2013-2014 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/imx6.sh
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+gw,imx6dl-gw51xx |\
+gw,imx6dl-gw52xx |\
+gw,imx6dl-gw53xx |\
+gw,imx6dl-gw54xx |\
+gw,imx6dl-gw551x |\
+gw,imx6dl-gw552x |\
+gw,imx6dl-gw553x |\
+gw,imx6dl-gw5904 |\
+gw,imx6dl-gw5907 |\
+gw,imx6dl-gw5910 |\
+gw,imx6dl-gw5912 |\
+gw,imx6dl-gw5913 |\
+gw,imx6q-gw51xx |\
+gw,imx6q-gw52xx |\
+gw,imx6q-gw53xx |\
+gw,imx6q-gw5400-a |\
+gw,imx6q-gw54xx |\
+gw,imx6q-gw551x |\
+gw,imx6q-gw552x |\
+gw,imx6q-gw553x |\
+gw,imx6q-gw5904 |\
+gw,imx6q-gw5907 |\
+gw,imx6q-gw5910 |\
+gw,imx6q-gw5912 |\
+gw,imx6q-gw5913 )
+	if [ -c /dev/mtd1 ]; then
+		# board boots from NAND
+		ubootenv_add_uci_config /dev/mtd1 0x0 0x20000 0x40000
+		ubootenv_add_uci_config /dev/mtd1 0x80000 0x20000 0x40000
+	else
+		# board boots from microSD
+		ubootenv_add_uci_config /dev/mmcblk0 0xb1400 0x20000
+		ubootenv_add_uci_config /dev/mmcblk0 0xd1400 0x20000
+	fi
+	;;
+toradex,apalis_imx6q-eval |\
+toradex,apalis_imx6q-ixora |\
+toradex,apalis_imx6q-ixora-v1.1 )
+	ubootenv_add_uci_config $(bootdev_from_uuid)boot0 -0x2200 0x2000 0x200 10
+	;;
+wand,imx6dl-wandboard)
+	ubootenv_add_uci_config "/dev/mmcblk0" "0x60000" "0x2000" "0x2000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/ipq40xx b/package/boot/uboot-envtools/files/ipq40xx
new file mode 100644
index 0000000..b24cbf9
--- /dev/null
+++ b/package/boot/uboot-envtools/files/ipq40xx
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 LEDE
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+ubootenv_mtdinfo () {
+	UBOOTENV_PART=$(cat /proc/mtd | grep APPSBLENV)
+	mtd_dev=$(echo $UBOOTENV_PART | awk '{print $1}' | sed 's/:$//')
+	mtd_size=$(echo $UBOOTENV_PART | awk '{print "0x"$2}')
+	mtd_erase=$(echo $UBOOTENV_PART | awk '{print "0x"$3}')
+	nor_flash=$(find /sys/bus/spi/devices/*/mtd -name ${mtd_dev})
+
+	if [ -n "$nor_flash" ]; then
+		ubootenv_size=$mtd_size
+	else
+		# size is fixed to 0x40000 in u-boot
+		ubootenv_size=0x40000
+	fi
+
+	sectors=$(( $ubootenv_size / $mtd_erase ))
+	echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
+}
+
+case "$board" in
+alfa-network,ap120c-ac |\
+devolo,magic-2-wifi-next |\
+edgecore,ecw5211 |\
+glinet,gl-ap1300 |\
+glinet,gl-b1300 |\
+luma,wrtq-329acn |\
+openmesh,a42 |\
+openmesh,a62 |\
+plasmacloud,pa1200 |\
+plasmacloud,pa2200)
+	ubootenv_add_uci_config "/dev/mtd5" "0x0" "0x10000" "0x10000"
+	;;
+aruba,ap-303)
+	ubootenv_add_uci_config "/dev/mtd13" "0x0" "0x10000" "0x10000"
+	;;
+aruba,ap-365)
+	ubootenv_add_uci_config "/dev/mtd8" "0x0" "0x10000" "0x10000"
+	;;
+buffalo,wtr-m2133hp)
+	ubootenv_add_uci_config "/dev/mtd8" "0x0" "0x40000" "0x20000"
+	;;
+linksys,ea6350v3)
+	ubootenv_add_uci_config "/dev/mtd7" "0x0" "0x20000" "0x20000"
+	;;
+linksys,ea8300 |\
+linksys,mr8300)
+	ubootenv_add_uci_config "/dev/mtd7" "0x0" "0x40000" "0x20000"
+	;;
+zyxel,nbg6617)
+	ubootenv_add_uci_config "/dev/mtd6" "0x0" "0x10000" "0x10000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/ipq806x b/package/boot/uboot-envtools/files/ipq806x
new file mode 100644
index 0000000..96a4ee6
--- /dev/null
+++ b/package/boot/uboot-envtools/files/ipq806x
@@ -0,0 +1,57 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 LEDE
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+ubootenv_mtdinfo () {
+	UBOOTENV_PART=$(cat /proc/mtd | grep APPSBLENV)
+	mtd_dev=$(echo $UBOOTENV_PART | awk '{print $1}' | sed 's/:$//')
+	mtd_size=$(echo $UBOOTENV_PART | awk '{print "0x"$2}')
+	mtd_erase=$(echo $UBOOTENV_PART | awk '{print "0x"$3}')
+	nor_flash=$(find /sys/bus/spi/devices/*/mtd -name ${mtd_dev})
+
+	if [ -n "$nor_flash" ]; then
+		ubootenv_size=$mtd_size
+	else
+		# size is fixed to 0x40000 in u-boot
+		ubootenv_size=0x40000
+	fi
+
+	sectors=$(( $ubootenv_size / $mtd_erase ))
+	echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
+}
+
+case "$board" in
+edgecore,ecw5410)
+	ubootenv_add_uci_config "/dev/mtd11" "0x0" "0x10000" "0x10000"
+	;;
+linksys,ea7500-v1 |\
+linksys,ea8500)
+	ubootenv_add_uci_config "/dev/mtd10" "0x0" "0x20000" "0x20000"
+	;;
+netgear,r7800)
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x040000" "0x20000"
+	;;
+qcom,ipq8064-ap148 |\
+qcom,ipq8064-db149)
+	ubootenv_add_uci_config $(ubootenv_mtdinfo)
+	;;
+ubnt,unifi-ac-hd |\
+zyxel,nbg6817)
+	ubootenv_add_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/kirkwood b/package/boot/uboot-envtools/files/kirkwood
new file mode 100644
index 0000000..401df74
--- /dev/null
+++ b/package/boot/uboot-envtools/files/kirkwood
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Copyright (C) 2012-2014 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+checkpoint,l-50|\
+cloudengines,pogoe02|\
+cloudengines,pogoplugv4|\
+iom,ix2-200|\
+linksys,e4200-v2|\
+linksys,ea4500|\
+raidsonic,ib-nas62x0|\
+seagate,dockstar|\
+zyxel,nsa310b|\
+zyxel,nsa310s|\
+zyxel,nsa325)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+	;;
+linksys,ea3500)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/lantiq b/package/boot/uboot-envtools/files/lantiq
new file mode 100644
index 0000000..87dfac8
--- /dev/null
+++ b/package/boot/uboot-envtools/files/lantiq
@@ -0,0 +1,38 @@
+#!/bin/sh
+#
+# Copyright (C) 2012 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+bt,homehub-v2b)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
+	;;
+bt,homehub-v3a)
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x4000" "0x4000" "1"
+	;;
+siemens,gigaset-sx76x)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
+	;;
+zyxel,p-2812hnu-f1)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x2000" "0x20000" "1"
+	;;
+buffalo,wbmr-300hpd)
+	idx="$(find_mtd_index u-boot-env)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x2000" "0x1000" "2"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/layerscape b/package/boot/uboot-envtools/files/layerscape
new file mode 100644
index 0000000..732f148
--- /dev/null
+++ b/package/boot/uboot-envtools/files/layerscape
@@ -0,0 +1,25 @@
+#!/bin/sh
+#
+# Copyright (C) 2016 LEDE
+#
+
+[ -f /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+	traverse,ls1043v | \
+	traverse,ls1043s)
+		ubootenv_add_uci_config "/dev/mtd1" "0x40000" "0x2000"  "0x20000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/mpc85xx b/package/boot/uboot-envtools/files/mpc85xx
new file mode 100644
index 0000000..d219b57
--- /dev/null
+++ b/package/boot/uboot-envtools/files/mpc85xx
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+ocedo,panda)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/mvebu b/package/boot/uboot-envtools/files/mvebu
new file mode 100644
index 0000000..92b1443
--- /dev/null
+++ b/package/boot/uboot-envtools/files/mvebu
@@ -0,0 +1,66 @@
+#!/bin/sh
+#
+# Copyright (C) 2014-2016 OpenWrt.org
+# Copyright (C) 2016 LEDE-Project.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+buffalo,ls421de)
+	ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000"
+	;;
+cznic,turris-omnia)
+	if grep -q 'U-Boot 2015.10-rc2' /dev/mtd0; then
+		ubootenv_add_uci_config "/dev/mtd0" "0xc0000" "0x10000" "0x40000"
+	else
+		ubootenv_add_uci_config "/dev/mtd0" "0xf0000" "0x10000" "0x10000"
+	fi
+	;;
+glinet,gl-mv1000)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x8000" "0x8000" "1"
+	;;
+globalscale,espressobin|\
+globalscale,espressobin-emmc|\
+globalscale,espressobin-ultra|\
+globalscale,espressobin-v7|\
+globalscale,espressobin-v7-emmc)
+	idx="$(find_mtd_index u-boot-env)"
+	if [ -n "$idx" ]; then
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000" "1"
+	else
+		ubootenv_add_uci_config "/dev/mtd0" "0x3f0000" "0x10000" "0x10000" "1"
+	fi
+	;;
+marvell,armada8040-mcbin-doubleshot|\
+marvell,armada8040-mcbin-singleshot)
+	ubootenv_add_uci_config "/dev/mtd0" "0x3f0000" "0x10000" "0x10000" "1"
+	;;
+linksys,wrt1200ac|\
+linksys,wrt1900ac-v2|\
+linksys,wrt1900acs)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x40000"
+	;;
+linksys,wrt1900ac-v1)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
+	;;
+linksys,wrt3200acm|\
+linksys,wrt32x)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+	;;
+methode,udpu)
+	ubootenv_add_uci_config "/dev/mtd0" "0x180000" "0x10000" "0x10000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/mxs b/package/boot/uboot-envtools/files/mxs
new file mode 100644
index 0000000..e087d60
--- /dev/null
+++ b/package/boot/uboot-envtools/files/mxs
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+i2se,duckbill)
+	ubootenv_add_uci_config "/dev/mmcblk0" "0x20000" "0x20000"
+	ubootenv_add_uci_config "/dev/mmcblk0" "0x40000" "0x20000"
+	;;
+olimex,imx23-olinuxino)
+	ubootenv_add_uci_config "/dev/mmcblk0" "0x40000" "0x4000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/oxnas b/package/boot/uboot-envtools/files/oxnas
new file mode 100644
index 0000000..4427bb5
--- /dev/null
+++ b/package/boot/uboot-envtools/files/oxnas
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+"cloudengines,pogoplug"* | \
+"shuttle,kd20")
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x2000" "0x2000" "1"
+	;;
+"mitrastar,stg-212")
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000" "1"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/pistachio b/package/boot/uboot-envtools/files/pistachio
new file mode 100644
index 0000000..e4aa7b0
--- /dev/null
+++ b/package/boot/uboot-envtools/files/pistachio
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Copyright (C) 2017 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+img,pistachio-marduk)
+	ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x2000" "0x1000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/ramips b/package/boot/uboot-envtools/files/ramips
new file mode 100644
index 0000000..0de062b
--- /dev/null
+++ b/package/boot/uboot-envtools/files/ramips
@@ -0,0 +1,75 @@
+#!/bin/sh
+#
+# Copyright (C) 2011-2012 OpenWrt.org
+#
+
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+alfa-network,ac1200rm|\
+alfa-network,awusfree1|\
+alfa-network,quad-e4g|\
+alfa-network,r36m-e4g|\
+alfa-network,tube-e4g|\
+engenius,esr600h)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000"
+	;;
+allnet,all0256n-4m|\
+allnet,all0256n-8m|\
+allnet,all5002)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
+	;;
+ampedwireless,ally-00x19k|\
+ampedwireless,ally-r1900k)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000" "4"
+	;;
+buffalo,wsr-1166dhp|\
+buffalo,wsr-600dhp|\
+mediatek,linkit-smart-7688|\
+samknows,whitebox-v8|\
+xiaomi,mi-router-3g-v2|\
+xiaomi,mi-router-4a-gigabit|\
+xiaomi,mi-router-4c|\
+xiaomi,miwifi-nano|\
+zbtlink,zbt-wg2626|\
+zte,mf283plus)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
+	;;
+hootoo,ht-tm05|\
+ravpower,rp-wd03)
+	idx="$(find_mtd_index u-boot-env)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x4000" "0x1000" "0x1000"
+	;;
+jcg,q20)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+	;;
+linksys,ea7300-v1|\
+linksys,ea7300-v2|\
+linksys,ea7500-v2|\
+linksys,ea8100-v1|\
+xiaomi,mi-router-3g|\
+xiaomi,mi-router-3-pro|\
+xiaomi,mi-router-4|\
+xiaomi,mi-router-ac2100|\
+xiaomi,redmi-router-ac2100)
+	ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
+	;;
+zyxel,nr7101)
+	idx="$(find_mtd_index Config)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x1000" "0x80000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/realtek b/package/boot/uboot-envtools/files/realtek
new file mode 100644
index 0000000..a91ca82
--- /dev/null
+++ b/package/boot/uboot-envtools/files/realtek
@@ -0,0 +1,32 @@
+[ -e /etc/config/ubootenv ] && exit 0
+
+touch /etc/config/ubootenv
+
+. /lib/uboot-envtools.sh
+. /lib/functions.sh
+
+board=$(board_name)
+
+case "$board" in
+d-link,dgs-1210-16|\
+d-link,dgs-1210-28|\
+d-link,dgs-1210-10p|\
+zyxel,gs1900-8|\
+zyxel,gs1900-8hp-v1|\
+zyxel,gs1900-8hp-v2|\
+zyxel,gs1900-10hp)
+	idx="$(find_mtd_index u-boot-env)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x400" "0x10000"
+	;;
+*)
+	idx="$(find_mtd_index u-boot-env)"
+	[ -n "$idx" ] && \
+		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
+	;;
+esac
+
+config_load ubootenv
+config_foreach ubootenv_add_app_config ubootenv
+
+exit 0
diff --git a/package/boot/uboot-envtools/files/uboot-envtools.sh b/package/boot/uboot-envtools/files/uboot-envtools.sh
new file mode 100644
index 0000000..9218bc4
--- /dev/null
+++ b/package/boot/uboot-envtools/files/uboot-envtools.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+#
+# Copyright (C) 2011-2012 OpenWrt.org
+#
+
+ubootenv_add_uci_config() {
+	local dev=$1
+	local offset=$2
+	local envsize=$3
+	local secsize=$4
+	local numsec=$5
+	uci batch <<EOF
+add ubootenv ubootenv
+set ubootenv.@ubootenv[-1].dev='$dev'
+set ubootenv.@ubootenv[-1].offset='$offset'
+set ubootenv.@ubootenv[-1].envsize='$envsize'
+set ubootenv.@ubootenv[-1].secsize='$secsize'
+set ubootenv.@ubootenv[-1].numsec='$numsec'
+EOF
+	uci commit ubootenv
+}
+
+ubootenv_add_app_config() {
+	local dev
+	local offset
+	local envsize
+	local secsize
+	local numsec
+	config_get dev "$1" dev
+	config_get offset "$1" offset
+	config_get envsize "$1" envsize
+	config_get secsize "$1" secsize
+	config_get numsec "$1" numsec
+	grep -q "^[[:space:]]*${dev}[[:space:]]*${offset}" /etc/fw_env.config || echo "$dev $offset $envsize $secsize $numsec" >>/etc/fw_env.config
+}
+