For devices with a NAND and a NOR chip, it was noticed that the order of
initialization can be different between various kernel versions (4.4 vs.
5.4). As result, the mtd index changes for the u-boot-env partition - but
the uboot-envtool still kept the old partition index.

And since some devices write (for example during sysupgrade) to the
u-boot-env, a unrelated partition would be overwritten. This would often
brick the device.

For example, a device with dualboot_datachk upgrade procedure with kernel A
(first intializes NOR and then NAND) which is upgrade to kernel B (first
initializes NAND and then NOR) would end up in a bricket state because the
device:

1. kernel A is (factory) installed on device
2. firstboot scripts initialize /etc/fw_env.config to point to mtd6
3. kernel B is installed on device via sysupgrade (no extra options)
   * during upgrade some information is written to mtd6 (u-boot-env)
4. firstboot script will not do anything when kernel B booted
   -> /etc/fw_env.config still points to mtd6 (now the "0:RPM" partition)
5. sysupgrade is started again
   * some information should be written to u-boot-env but the upgrade
     script will now overwrite some important information of "0:RPM" (mtd6)
6. boot fails because the secondary bootload is unable to load the iamge
   from 0:RPM. u-boot will then never be started because the SBL caused
   a panic before it was event tried to load it.

This scenario cannot happen when the /etc/fw_env.config is not preserved
and instead autogenerated after each firmware installation.

There might still be a good reason to restore the values from uci in case
there is no code to auto-generate the settings.

Fixes: 7f00e5ffc671 ("uboot-envtools: update to 2012.04.01")
Signed-off-by: Sven Eckelmann <s...@narfation.org>

---

The safest method to reproduce the problem without killing your system is
to use a board which usually doesn't use fw_setenv but has an accessible
u-boot-env.

1. flash the device with your test firmware
2. check that fw_printenv works
3. write bogus values in your u-boot-env configuration:

     echo '/dev/mtd99 0x0 0x00010000 0x00010000 1' > /etc/fw_env.config
     uci set ubootenv.@ubootenv[0].dev='/dev/mtd6'
     uci commit ubootenv

4. sysupgrade the device
5. check if fw_printenv works again

diff --git a/package/boot/uboot-envtools/Makefile 
b/package/boot/uboot-envtools/Makefile
index 
6840b9c586be1b6f41b72b18138143bd695dbfe6..ca76f528f8f93be46268f8132f50f93bc33025ea
 100644
--- a/package/boot/uboot-envtools/Makefile
+++ b/package/boot/uboot-envtools/Makefile
@@ -58,12 +58,6 @@ MAKE_FLAGS += \
        no-dot-config-targets=envtools \
        envtools
 
-define Package/uboot-envtools/conffiles
-/etc/config/ubootenv
-/etc/fw_env.config
-/etc/fw_sys.config
-endef
-
 define Package/uboot-envtools/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/tools/env/fw_printenv $(1)/usr/sbin
diff --git a/package/boot/uboot-envtools/files/apm821xx 
b/package/boot/uboot-envtools/files/apm821xx
index 
e73aaab7a0d73a4856d24ae20a39458797c8beb1..06241449717769b1e531763b597b9b980d14150d
 100644
--- a/package/boot/uboot-envtools/files/apm821xx
+++ b/package/boot/uboot-envtools/files/apm821xx
@@ -1,4 +1,4 @@
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -9,17 +9,19 @@ board=$(board_name)
 
 case "$board" in
 meraki,mr24)
+       ubootenv_clear_uci_config
        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"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000" "4"
        ;;
 netgear,wndap620|\
 netgear,wndap660)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000" "4"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000" "4"
        ;;
 wd,mybooklive)
+       ubootenv_clear_uci_config
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000" "1"
        ubootenv_add_uci_config "/dev/mtd1" "0x1000" "0x1000" "0x1000" "1"
        ;;
diff --git a/package/boot/uboot-envtools/files/ath79 
b/package/boot/uboot-envtools/files/ath79
index 
d9e504bf8949a5ef93e1641d01334fc61523bd68..194176527c84ed5c0418f3dc5940645a75f03c55
 100644
--- a/package/boot/uboot-envtools/files/ath79
+++ b/package/boot/uboot-envtools/files/ath79
@@ -2,7 +2,7 @@
 # Copyright (C) 2011-2014 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -77,17 +77,17 @@ yuncore,xd3200|\
 yuncore,xd4200|\
 ziking,cpe46b|\
 zyxel,nbg6616)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
        ;;
 buffalo,wzr-hp-ag300h)
-       ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
        ;;
 buffalo,wzr-hp-g300nh-rb|\
 buffalo,wzr-hp-g300nh-s)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
        ;;
 domywifi,dw33d)
-       ubootenv_add_uci_config "/dev/mtd4" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd4" "0x0" "0x10000" "0x10000"
        ;;
 dongwon,dw02-412h-64m|\
 dongwon,dw02-412h-128m|\
@@ -95,24 +95,25 @@ glinet,gl-ar300m-lite|\
 glinet,gl-ar300m-nand|\
 glinet,gl-ar300m-nor|\
 glinet,gl-ar300m16)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
        ;;
 glinet,gl-ar150)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x8000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x8000" "0x10000"
        ;;
 netgear,wndr3700|\
 netgear,wndr3700-v2|\
 netgear,wndrmac-v1)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x10000"
        ;;
 netgear,pgzng1|\
 netgear,wndr3700-v4|\
 netgear,wndr4300|\
 netgear,wndr4300tn|\
 netgear,wndr4300sw)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
        ;;
 openmesh,om2p-v1|\
 openmesh,om2p-v2|\
@@ -124,29 +125,29 @@ openmesh,om2p-hs-v4|\
 openmesh,om2p-lc|\
 plasmacloud,pa300|\
 plasmacloud,pa300e)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x40000" "0x40000"
        ;;
 qihoo,c301)
-       ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd9" "0x0" "0x10000" "0x10000"
        ;;
 ruckus,zf7321|\
 ruckus,zf7372)
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x40000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x40000" "0x10000"
        ;;
 sophos,ap15|\
 sophos,ap55|\
 sophos,ap55c|\
 sophos,ap100|\
 sophos,ap100c)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
        ;;
 wallys,dr531)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0xf800" "0x10000"
        ;;
 zte,mf286|\
 zte,mf286a|\
 zte,mf286r)
-       ubootenv_add_uci_config "/dev/mtd7" "0x0" "0x20000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd7" "0x0" "0x20000" "0x10000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/cns3xxx 
b/package/boot/uboot-envtools/files/cns3xxx
index 
c8cca3091d6a6a2a5633634cf0b919597d059462..ebb24d390e0bfe9b4c5f55d7ea919967a9549629
 100644
--- a/package/boot/uboot-envtools/files/cns3xxx
+++ b/package/boot/uboot-envtools/files/cns3xxx
@@ -2,7 +2,7 @@
 # Copyright (C) 2013 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -16,7 +16,7 @@ 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"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x$size" "0x$erasesize"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/imx_cortexa7 
b/package/boot/uboot-envtools/files/imx_cortexa7
index 
df6a4362607511d6f52fef2fdd7f7c31d5b8d76d..c63622dcf6123560b67c59df77b2e6f536c00d23
 100644
--- a/package/boot/uboot-envtools/files/imx_cortexa7
+++ b/package/boot/uboot-envtools/files/imx_cortexa7
@@ -1,4 +1,4 @@
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -9,7 +9,7 @@ board=$(board_name)
 
 case "$board" in
 technexion,imx7d-pico-pi)
-       ubootenv_add_uci_config "/dev/mmcblk2" "0xc0000" "0x2000" "0x2000"
+       ubootenv_set_uci_config "/dev/mmcblk2" "0xc0000" "0x2000" "0x2000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/imx_cortexa9 
b/package/boot/uboot-envtools/files/imx_cortexa9
index 
c6d6d94d1642c9652ca61c0d3f618e788e765a3f..e15ea2912b3cb48c954d46a25be5df7e535d4cec
 100644
--- a/package/boot/uboot-envtools/files/imx_cortexa9
+++ b/package/boot/uboot-envtools/files/imx_cortexa9
@@ -2,7 +2,7 @@
 # Copyright (C) 2013-2014 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -38,6 +38,7 @@ gw,imx6q-gw5907|\
 gw,imx6q-gw5910|\
 gw,imx6q-gw5912|\
 gw,imx6q-gw5913)
+       ubootenv_clear_uci_config
        if [ -c /dev/mtd1 ]; then
                # board boots from NAND
                ubootenv_add_uci_config /dev/mtd1 0x0 0x20000 0x40000
@@ -51,10 +52,10 @@ gw,imx6q-gw5913)
 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
+       ubootenv_set_uci_config $(bootdev_from_uuid)boot0 -0x2200 0x2000 0x200 
10
        ;;
 wand,imx6dl-wandboard)
-       ubootenv_add_uci_config "/dev/mmcblk0" "0x60000" "0x2000" "0x2000"
+       ubootenv_set_uci_config "/dev/mmcblk0" "0x60000" "0x2000" "0x2000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/ipq40xx 
b/package/boot/uboot-envtools/files/ipq40xx
index 
823a33ca1b113de5ee74204a03e373e82ac70640..0eee84867ea4d9c25d37e5bef40cba432069f812
 100644
--- a/package/boot/uboot-envtools/files/ipq40xx
+++ b/package/boot/uboot-envtools/files/ipq40xx
@@ -2,7 +2,7 @@
 # Copyright (C) 2016 LEDE
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -44,29 +44,29 @@ openmesh,a62|\
 pakedge,wr-1|\
 plasmacloud,pa1200|\
 plasmacloud,pa2200)
-       ubootenv_add_uci_config "/dev/mtd5" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd5" "0x0" "0x10000" "0x10000"
        ;;
 aruba,ap-303)
-       ubootenv_add_uci_config "/dev/mtd13" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd13" "0x0" "0x10000" "0x10000"
        ;;
 aruba,ap-365)
-       ubootenv_add_uci_config "/dev/mtd8" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd8" "0x0" "0x10000" "0x10000"
        ;;
 buffalo,wtr-m2133hp)
-       ubootenv_add_uci_config "/dev/mtd8" "0x0" "0x40000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd8" "0x0" "0x40000" "0x20000"
        ;;
 linksys,ea6350v3)
-       ubootenv_add_uci_config "/dev/mtd7" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd7" "0x0" "0x20000" "0x20000"
        ;;
 linksys,ea8300|\
 linksys,mr8300)
-       ubootenv_add_uci_config "/dev/mtd7" "0x0" "0x40000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd7" "0x0" "0x40000" "0x20000"
        ;;
 linksys,whw01-v1)
-       ubootenv_add_uci_config "/dev/mtd6" "0x0" "0x40000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd6" "0x0" "0x40000" "0x10000"
        ;;
 zyxel,nbg6617)
-       ubootenv_add_uci_config "/dev/mtd6" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd6" "0x0" "0x10000" "0x10000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/ipq806x 
b/package/boot/uboot-envtools/files/ipq806x
index 
77dfefbcd8196bf2a6edd55fb6936c60890cf70d..1cff4c4fbccd8894818e7b7841446903bb6a43af
 100644
--- a/package/boot/uboot-envtools/files/ipq806x
+++ b/package/boot/uboot-envtools/files/ipq806x
@@ -2,7 +2,7 @@
 # Copyright (C) 2016 LEDE
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -33,25 +33,25 @@ ubootenv_mtdinfo () {
 case "$board" in
 arris,tr4400-v2|\
 askey,rt4230w-rev6)
-       ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x40000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd9" "0x0" "0x40000" "0x20000"
        ;;
 edgecore,ecw5410)
-       ubootenv_add_uci_config "/dev/mtd11" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd11" "0x0" "0x10000" "0x10000"
        ;;
 linksys,ea7500-v1|\
 linksys,ea8500)
-       ubootenv_add_uci_config "/dev/mtd10" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd10" "0x0" "0x20000" "0x20000"
        ;;
 netgear,r7800)
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x040000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x040000" "0x20000"
        ;;
 qcom,ipq8064-ap148|\
 qcom,ipq8064-db149)
-       ubootenv_add_uci_config $(ubootenv_mtdinfo)
+       ubootenv_set_uci_config $(ubootenv_mtdinfo)
        ;;
 ubnt,unifi-ac-hd|\
 zyxel,nbg6817)
-       ubootenv_add_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtdblock9" "0x0" "0x10000" "0x10000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/kirkwood 
b/package/boot/uboot-envtools/files/kirkwood
index 
240371f48d85ed8795de53cdb852aa7a60be9629..5fb54f6d60f69888e7ada5f802d796797eb944c7
 100644
--- a/package/boot/uboot-envtools/files/kirkwood
+++ b/package/boot/uboot-envtools/files/kirkwood
@@ -2,7 +2,7 @@
 # Copyright (C) 2012-2014 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -25,10 +25,10 @@ seagate,dockstar|\
 zyxel,nsa310b|\
 zyxel,nsa310s|\
 zyxel,nsa325)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
        ;;
 linksys,ea3500)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x4000" "0x4000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/lantiq 
b/package/boot/uboot-envtools/files/lantiq
index 
81af7e804f8a87eae4233e42a25caa0c64fe2083..0b93cae3be417dd3236e505300fe504fc08e671f
 100644
--- a/package/boot/uboot-envtools/files/lantiq
+++ b/package/boot/uboot-envtools/files/lantiq
@@ -2,7 +2,7 @@
 # Copyright (C) 2012 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -13,18 +13,19 @@ board=$(board_name)
 
 case "$board" in
 bt,homehub-v2b)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
        ;;
 bt,homehub-v3a)
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x4000" "0x4000" "1"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x4000" "0x4000" "1"
        ;;
 siemens,gigaset-sx76x)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000" "1"
        ;;
 zyxel,p-2812hnu-f1)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x2000" "0x20000" "1"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x2000" "0x20000" "1"
        ;;
 buffalo,wbmr-300hpd)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x2000" "0x1000" 
"2"
diff --git a/package/boot/uboot-envtools/files/layerscape 
b/package/boot/uboot-envtools/files/layerscape
index 
b11587d8765fd0c892e9479639099f65240c1d13..87a165d865f0310a7aba3800a80618cea700666f
 100644
--- a/package/boot/uboot-envtools/files/layerscape
+++ b/package/boot/uboot-envtools/files/layerscape
@@ -2,7 +2,7 @@
 # Copyright (C) 2016 LEDE
 #
 
-[ -f /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -14,7 +14,7 @@ board=$(board_name)
 case "$board" in
        traverse,ls1043v|\
        traverse,ls1043s)
-               ubootenv_add_uci_config "/dev/mtd1" "0x40000" "0x2000"  
"0x20000"
+               ubootenv_set_uci_config "/dev/mtd1" "0x40000" "0x2000"  
"0x20000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/mediatek_filogic 
b/package/boot/uboot-envtools/files/mediatek_filogic
index 
a82f140a6e58b36a75ac49f18eb49ab24ba7b878..17b4717042cd6180d22fbadd7510fc0b98448c9a
 100644
--- a/package/boot/uboot-envtools/files/mediatek_filogic
+++ b/package/boot/uboot-envtools/files/mediatek_filogic
@@ -2,7 +2,7 @@
 # Copyright (C) 2021 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -19,11 +19,13 @@ bananapi,bpi-r3)
        case "$rootdev" in
        mmc*)
                local envdev=$(find_mmc_part "ubootenv" $rootdev)
+               ubootenv_clear_uci_config
                ubootenv_add_uci_config "$envdev" "0x0" "0x40000" "0x40000" "1"
                ubootenv_add_uci_config "$envdev" "0x40000" "0x40000" "0x40000" 
"1"
                ;;
        mtd*)
                local envdev=/dev/mtd$(find_mtd_index "u-boot-env")
+               ubootenv_clear_uci_config
                ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1"
                ubootenv_add_uci_config "$envdev" "0x20000" "0x20000" "0x20000" 
"1"
                ;;
@@ -32,6 +34,7 @@ bananapi,bpi-r3)
                local envubi=$(nand_find_ubi ubi)
                local envdev=/dev/$(nand_find_volume $envubi ubootenv)
                local envdev2=/dev/$(nand_find_volume $envubi ubootenv2)
+               ubootenv_clear_uci_config
                ubootenv_add_uci_config "$envdev" "0x0" "0x1f000" "0x1f000" "1"
                ubootenv_add_uci_config "$envdev2" "0x0" "0x1f000" "0x1f000" "1"
                ;;
diff --git a/package/boot/uboot-envtools/files/mediatek_mt7622 
b/package/boot/uboot-envtools/files/mediatek_mt7622
index 
654f78056a8ab71ded7da52d7d8089ffbc199cce..dedfea399941bd746706d27df3fec86a8d7364fc
 100644
--- a/package/boot/uboot-envtools/files/mediatek_mt7622
+++ b/package/boot/uboot-envtools/files/mediatek_mt7622
@@ -2,7 +2,7 @@
 # Copyright (C) 2021 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -13,6 +13,7 @@ board=$(board_name)
 
 case "$board" in
 linksys,e8450-ubi)
+       ubootenv_clear_uci_config
        ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x1f000" "0x1f000" "1"
        ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x1f000" "0x1f000" "1"
        ;;
@@ -23,26 +24,28 @@ bananapi,bpi-r64)
        case "$rootdev" in
        mmc*)
                local envdev=$(find_mmc_part "ubootenv" $rootdev)
+               ubootenv_clear_uci_config
                ubootenv_add_uci_config "$envdev" "0x0" "0x80000" "0x80000" "1"
                ubootenv_add_uci_config "$envdev" "0x80000" "0x80000" "0x80000" 
"1"
                ;;
        *)
+               ubootenv_clear_uci_config
                ubootenv_add_uci_config "/dev/ubi0_0" "0x0" "0x1f000" "0x1f000" 
"1"
                ubootenv_add_uci_config "/dev/ubi0_1" "0x0" "0x1f000" "0x1f000" 
"1"
                ;;
        esac
        ;;
 buffalo,wsr-2533dhp2)
-       ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x1000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd3" "0x0" "0x1000" "0x20000"
        ;;
 ruijie,rg-ew3200gx-pro)
-       ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd3" "0x0" "0x20000" "0x20000"
        ;;
 ubnt,unifi-6-lr-ubootmod)
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x4000" "0x1000"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x4000" "0x1000"
        ;;
 xiaomi,redmi-router-ax6s)
-       ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x40000"
+       ubootenv_set_uci_config "/dev/mtd3" "0x0" "0x10000" "0x40000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/mediatek_mt7623 
b/package/boot/uboot-envtools/files/mediatek_mt7623
index 
fd2a01006a8e08436106788b022a90f136ba3ea5..e7be0047eee8e18307574f63259024f11fe5de85
 100644
--- a/package/boot/uboot-envtools/files/mediatek_mt7623
+++ b/package/boot/uboot-envtools/files/mediatek_mt7623
@@ -2,7 +2,7 @@
 # Copyright (C) 2021 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -16,10 +16,10 @@ bananapi,bpi-r2)
        . /lib/upgrade/common.sh
        export_bootdevice
        export_partdevice ubootpart 1
-       ubootenv_add_uci_config "/dev/$ubootpart" "0xb0000" "0x10000" "0x10000" 
"1"
+       ubootenv_set_uci_config "/dev/$ubootpart" "0xb0000" "0x10000" "0x10000" 
"1"
        ;;
 unielec,u7623-02)
-       ubootenv_add_uci_config "/dev/mmcblk0p1" "0xc0000" "0x10000" "0x10000" 
"1"
+       ubootenv_set_uci_config "/dev/mmcblk0p1" "0xc0000" "0x10000" "0x10000" 
"1"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/mediatek_mt7629 
b/package/boot/uboot-envtools/files/mediatek_mt7629
index 
a5aa2b58a61de7a79a26004a2116c3e91560223d..949523e4832a031f39380192043e438267c01617
 100644
--- a/package/boot/uboot-envtools/files/mediatek_mt7629
+++ b/package/boot/uboot-envtools/files/mediatek_mt7629
@@ -2,7 +2,7 @@
 # Copyright (C) 2021 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -13,7 +13,7 @@ board=$(board_name)
 
 case "$board" in
 iptime,a6004mx)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/mpc85xx 
b/package/boot/uboot-envtools/files/mpc85xx
index 
36d9f753a11c4c539c6994735613af053dfdc822..40a35f705edb679f8ffdc2c7ce388872ce967491
 100644
--- a/package/boot/uboot-envtools/files/mpc85xx
+++ b/package/boot/uboot-envtools/files/mpc85xx
@@ -1,4 +1,4 @@
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -9,15 +9,15 @@ board=$(board_name)
 
 case "$board" in
 extreme-networks,ws-ap3825i)
-       ubootenv_add_uci_config "$(find_mtd_part 'cfg1')" "0x0" "0x10000" 
"0x20000"
-       ubootenv_add_uci_config "$(find_mtd_part 'cfg2')" "0x0" "0x10000" 
"0x20000"
+       ubootenv_set_uci_config "$(find_mtd_part 'cfg1')" "0x0" "0x10000" 
"0x20000"
+       ubootenv_set_uci_config "$(find_mtd_part 'cfg2')" "0x0" "0x10000" 
"0x20000"
        ;;
 ocedo,panda)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000"
        ;;
 aerohive,hiveap-330)
-       ubootenv_add_uci_config "$(find_mtd_part 'u-boot-env')" "0x0" "0x20000" 
"0x10000"
+       ubootenv_set_uci_config "$(find_mtd_part 'u-boot-env')" "0x0" "0x20000" 
"0x10000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/mvebu 
b/package/boot/uboot-envtools/files/mvebu
index 
cc1c648f246a5c39cad9fe94056bc8d1ba59604d..03c127a1bb6f44fb8323ced82a0ee503b304404a
 100644
--- a/package/boot/uboot-envtools/files/mvebu
+++ b/package/boot/uboot-envtools/files/mvebu
@@ -3,7 +3,7 @@
 # Copyright (C) 2016 LEDE-Project.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -14,20 +14,20 @@ board=$(board_name)
 
 case "$board" in
 buffalo,ls421de)
-       ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd3" "0x0" "0x10000"
        ;;
 cznic,turris-omnia)
        idx="$(find_mtd_index u-boot-env)"
        if [ -n "$idx" ]; then
-               ubootenv_add_uci_config "/dev/mtd${idx}" "0x0" "0x10000" 
"0x10000"
+               ubootenv_set_uci_config "/dev/mtd${idx}" "0x0" "0x10000" 
"0x10000"
        elif grep -q 'U-Boot 2015.10-rc2' /dev/mtd0; then
-               ubootenv_add_uci_config "/dev/mtd0" "0xc0000" "0x10000" 
"0x40000"
+               ubootenv_set_uci_config "/dev/mtd0" "0xc0000" "0x10000" 
"0x40000"
        else
-               ubootenv_add_uci_config "/dev/mtd0" "0xf0000" "0x10000" 
"0x10000"
+               ubootenv_set_uci_config "/dev/mtd0" "0xf0000" "0x10000" 
"0x10000"
        fi
        ;;
 glinet,gl-mv1000)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x8000" "0x8000" "1"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x8000" "0x8000" "1"
        ;;
 globalscale,espressobin|\
 globalscale,espressobin-emmc|\
@@ -37,34 +37,34 @@ globalscale,espressobin-v7-emmc|\
 globalscale,mochabin)
        idx="$(find_mtd_index u-boot-env)"
        if [ -n "$idx" ]; then
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" 
"0x10000" "1"
+               ubootenv_set_uci_config "/dev/mtd$idx" "0x0" "0x10000" 
"0x10000" "1"
        else
-               ubootenv_add_uci_config "/dev/mtd0" "0x3f0000" "0x10000" 
"0x10000" "1"
+               ubootenv_set_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"
+       ubootenv_set_uci_config "/dev/mtd0" "0x3f0000" "0x10000" "0x10000" "1"
        ;;
 linksys,wrt1200ac|\
 linksys,wrt1900ac-v2|\
 linksys,wrt1900acs)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x40000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x40000"
        ;;
 linksys,wrt1900ac-v1)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x40000" "0x20000"
        ;;
 linksys,wrt3200acm|\
 linksys,wrt32x)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
        ;;
 methode,udpu|\
 methode,edpu)
        idx="$(find_mtd_index u-boot-env)"
        if [ -n "$idx" ]; then
-       ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000" "1"
+       ubootenv_set_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000" "1"
        else
-       ubootenv_add_uci_config "/dev/mtd0" "0x180000" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd0" "0x180000" "0x10000" "0x10000"
        fi
        ;;
 esac
diff --git a/package/boot/uboot-envtools/files/mxs 
b/package/boot/uboot-envtools/files/mxs
index 
fc5cd54078079253f05e00161801d70b4baba4b1..2ebbdf55f81a91673f9d8d3b166d01a89e531c4d
 100644
--- a/package/boot/uboot-envtools/files/mxs
+++ b/package/boot/uboot-envtools/files/mxs
@@ -2,7 +2,7 @@
 # Copyright (C) 2013 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -13,11 +13,12 @@ board=$(board_name)
 
 case "$board" in
 i2se,duckbill)
+       ubootenv_clear_uci_config
        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"
+       ubootenv_set_uci_config "/dev/mmcblk0" "0x40000" "0x4000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/oxnas 
b/package/boot/uboot-envtools/files/oxnas
index 
bd407c67d531fa3613d55b9ff48e4253780cdc23..d12f6015f4521ee2e639f106c8dcb100d601ab32
 100644
--- a/package/boot/uboot-envtools/files/oxnas
+++ b/package/boot/uboot-envtools/files/oxnas
@@ -2,7 +2,7 @@
 # Copyright (C) 2013 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -14,10 +14,10 @@ board=$(board_name)
 case "$board" in
 "cloudengines,pogoplug"*|\
 "shuttle,kd20")
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x2000" "0x20000" "1"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x2000" "0x20000" "1"
        ;;
 "mitrastar,stg-212")
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000" "1"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x20000" "0x20000" "1"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/pistachio 
b/package/boot/uboot-envtools/files/pistachio
index 
53515641bcd36cc17071ba120a26efe7e152ce1c..a01b9d9a035015b5a7d0f5551667a0066d820b4e
 100644
--- a/package/boot/uboot-envtools/files/pistachio
+++ b/package/boot/uboot-envtools/files/pistachio
@@ -5,7 +5,7 @@
 # See /LICENSE for more information.
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -16,7 +16,7 @@ board=$(board_name)
 
 case "$board" in
 img,pistachio-marduk)
-       ubootenv_add_uci_config "/dev/mtd2" "0x0" "0x2000" "0x1000"
+       ubootenv_set_uci_config "/dev/mtd2" "0x0" "0x2000" "0x1000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/qoriq 
b/package/boot/uboot-envtools/files/qoriq
index 
d024a7f00868e26c9d095671ef7282d54b2acc6f..023a463bcef58b62e2056b31eef621d33c5ab29f
 100644
--- a/package/boot/uboot-envtools/files/qoriq
+++ b/package/boot/uboot-envtools/files/qoriq
@@ -1,4 +1,4 @@
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
 
 touch /etc/config/ubootenv
 
@@ -9,7 +9,7 @@ board=$(board_name)
 
 case "$board" in
 watchguard,firebox-m300)
-       ubootenv_add_uci_config "/dev/mtd9" "0x0" "0x2000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd9" "0x0" "0x2000" "0x10000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/ramips 
b/package/boot/uboot-envtools/files/ramips
index 
194f6561d46e382d74ce72f20c5074e43b9098a7..4635f4ba59510b42934e7baa3002e69a3e9b2f1a
 100644
--- a/package/boot/uboot-envtools/files/ramips
+++ b/package/boot/uboot-envtools/files/ramips
@@ -2,7 +2,8 @@
 # Copyright (C) 2011-2012 OpenWrt.org
 #
 
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
+rm -f /etc/fw_sys.config
 
 touch /etc/config/ubootenv
 
@@ -19,21 +20,21 @@ alfa-network,r36m-e4g|\
 alfa-network,tube-e4g|\
 engenius,esr600h|\
 sitecom,wlr-4100-v1-002)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x1000"
        ;;
 allnet,all0256n-4m|\
 allnet,all0256n-8m|\
 allnet,all5002|\
 yuncore,ax820)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x10000" "0x10000"
        ;;
 ampedwireless,ally-00x19k|\
 ampedwireless,ally-r1900k)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000" "4"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000" "4"
        ;;
 beeline,smartbox-giga|\
 beeline,smartbox-turbo)
-       ubootenv_add_uci_config "/dev/mtd0" "0x80000" "0x1000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd0" "0x80000" "0x1000" "0x20000"
        ;;
 buffalo,wsr-1166dhp|\
 buffalo,wsr-600dhp|\
@@ -45,7 +46,7 @@ xiaomi,mi-router-4c|\
 xiaomi,miwifi-nano|\
 zbtlink,zbt-wg2626|\
 zte,mf283plus)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
        ;;
 belkin,rt1800|\
 h3c,tx1800-plus|\
@@ -54,10 +55,11 @@ h3c,tx1806|\
 jcg,q20|\
 linksys,e7350|\
 netgear,wax202)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000"
        ;;
 hootoo,ht-tm05|\
 ravpower,rp-wd03)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x4000" "0x1000" 
"0x1000"
@@ -70,11 +72,12 @@ linksys,ea7500-v2|\
 linksys,ea8100-v1|\
 linksys,ea8100-v2|\
 mts,wg430223)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
        ;;
 xiaomi,mi-router-3g-v2|\
 xiaomi,mi-router-4a-gigabit|\
 xiaomi,miwifi-3c)
+       ubootenv_clear_uci_config
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
        ubootenv_add_uci_sys_config "/dev/mtd2" "0x0" "0x4000" "0x10000"
        ;;
@@ -83,13 +86,15 @@ xiaomi,mi-router-3-pro|\
 xiaomi,mi-router-4|\
 xiaomi,mi-router-ac2100|\
 xiaomi,redmi-router-ac2100)
+       ubootenv_clear_uci_config
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x20000"
        ubootenv_add_uci_sys_config "/dev/mtd2" "0x0" "0x4000" "0x20000"
        ;;
 zyxel,lte3301-plus)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x80000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x1000" "0x80000"
        ;;
 zyxel,nr7101)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index Config)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x1000" "0x80000"
@@ -98,7 +103,7 @@ bolt,arion|\
 xiaomi,mi-router-cr6606|\
 xiaomi,mi-router-cr6608|\
 xiaomi,mi-router-cr6609)
-       ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x10000" "0x20000"
+       ubootenv_set_uci_config "/dev/mtd1" "0x0" "0x10000" "0x20000"
        ;;
 esac
 
diff --git a/package/boot/uboot-envtools/files/realtek 
b/package/boot/uboot-envtools/files/realtek
index 
f191503876822b42d960f2e7ea8d2610009ae5e8..39f17a7e2de15337c5e7bda6c5945a2c801ab3ec
 100644
--- a/package/boot/uboot-envtools/files/realtek
+++ b/package/boot/uboot-envtools/files/realtek
@@ -1,4 +1,5 @@
-[ -e /etc/config/ubootenv ] && exit 0
+rm -f /etc/fw_env.config
+rm -f /etc/fw_sys.config
 
 touch /etc/config/ubootenv
 
@@ -22,6 +23,7 @@ zyxel,gs1900-24-v1|\
 zyxel,gs1900-24e|\
 zyxel,gs1900-24hp-v1|\
 zyxel,gs1900-24hp-v2)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x400" "0x10000"
@@ -32,11 +34,13 @@ zyxel,gs1900-24hp-v2)
 tplink,sg2008p-v1|\
 tplink,sg2210p-v3|\
 tplink,sg2452p-v4)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x20000" "0x10000"
        ;;
 iodata,bsh-g24mb)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
@@ -45,6 +49,7 @@ iodata,bsh-g24mb)
                ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x3800" 
"0x10000"
        ;;
 *)
+       ubootenv_clear_uci_config
        idx="$(find_mtd_index u-boot-env)"
        [ -n "$idx" ] && \
                ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
diff --git a/package/boot/uboot-envtools/files/uboot-envtools.sh 
b/package/boot/uboot-envtools/files/uboot-envtools.sh
index 
980c9962b17c5d0a5f26e5ee456f33ebfca9697d..72e7591ee353d24f867aa80ad9781b6cfa1590e9
 100644
--- a/package/boot/uboot-envtools/files/uboot-envtools.sh
+++ b/package/boot/uboot-envtools/files/uboot-envtools.sh
@@ -21,10 +21,20 @@ EOF
        uci commit ubootenv
 }
 
+ubootenv_clear_uci_config() {
+       rm -f /etc/config/ubootenv
+       touch /etc/config/ubootenv
+}
+
 ubootenv_add_uci_config() {
        _ubootenv_add_uci_config "ubootenv" "$@"
 }
 
+ubootenv_set_uci_config() {
+       ubootenv_clear_uci_config
+       _ubootenv_add_uci_config "ubootenv" "$@"
+}
+
 ubootenv_add_uci_sys_config() {
        _ubootenv_add_uci_config "ubootsys" "$@"
 }

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to