uboot-tools: use ubootenv_add_* functions
authorPaweł Owoc <frut3k7@gmail.com>
Fri, 16 May 2025 14:19:05 +0000 (16:19 +0200)
committerHauke Mehrtens <hauke@hauke-m.de>
Thu, 26 Jun 2025 21:12:20 +0000 (23:12 +0200)
Use ubootenv_add_* functions for code simplification.

Signed-off-by: Paweł Owoc <frut3k7@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/18818
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
package/boot/uboot-tools/uboot-envtools/files/ath79
package/boot/uboot-tools/uboot-envtools/files/lantiq
package/boot/uboot-tools/uboot-envtools/files/mediatek_filogic
package/boot/uboot-tools/uboot-envtools/files/mediatek_mt7622
package/boot/uboot-tools/uboot-envtools/files/mvebu
package/boot/uboot-tools/uboot-envtools/files/qualcommax_ipq50xx
package/boot/uboot-tools/uboot-envtools/files/ramips
package/boot/uboot-tools/uboot-envtools/files/realtek

index dc46d5ed399932821af888f7343d706f054d86b4..f275244cbe80c480ae819b0382d3ac719cf1ac01 100644 (file)
@@ -101,9 +101,7 @@ glinet,gl-ar300m-nor|\
 glinet,gl-ar300m16|\
 glinet,gl-s200-nor|\
 glinet,gl-s200-nor-nand)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x10000" "0x10000"
        ;;
 buffalo,wzr-hp-ag300h)
        ubootenv_add_uci_config "/dev/mtd3" "0x0" "0x10000" "0x10000"
index 81af7e804f8a87eae4233e42a25caa0c64fe2083..4e6fb48b76e44b8afd2e46eeca9b8150dd0943f5 100644 (file)
@@ -25,9 +25,7 @@ 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"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x2000" "0x1000" "2"
        ;;
 esac
 
index 9654635bca04a3d663e7c77ffaa23bc78387917d..7ca793a8d492d9d2f1a4b6e554f0c8c90d38d6df 100644 (file)
@@ -12,15 +12,13 @@ touch /etc/config/ubootenv
 board=$(board_name)
 
 ubootenv_add_mmc_default() {
-       local envdev="$(find_mmc_part "ubootenv" "${1:-mmcblk0}")"
-       ubootenv_add_uci_config "$envdev" "0x0" "0x40000" "0x40000" "1"
-       ubootenv_add_uci_config "$envdev" "0x40000" "0x40000" "0x40000" "1"
+       ubootenv_add_mmc "ubootenv" "${1:-mmcblk0}" "0x0" "0x40000" "0x40000" "1"
+       ubootenv_add_mmc "ubootenv" "${1:-mmcblk0}" "0x40000" "0x40000" "0x40000" "1"
 }
 
 ubootenv_add_nor_default() {
-       local envdev="/dev/mtd$(find_mtd_index "u-boot-env")"
-       ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1"
-       ubootenv_add_uci_config "$envdev" "0x20000" "0x20000" "0x20000" "1"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x20000" "0x20000" "1"
+       ubootenv_add_mtd "u-boot-env" "0x20000" "0x20000" "0x20000" "1"
 }
 
 ubootenv_add_ubi_default() {
@@ -66,8 +64,7 @@ glinet,gl-x3000|\
 glinet,gl-xe3000|\
 huasifei,wh3000|\
 nradio,c8-668gl)
-       local envdev=$(find_mmc_part "u-boot-env")
-       ubootenv_add_uci_config "$envdev" "0x0" "0x80000"
+       ubootenv_add_mmc "u-boot-env" "" "0x0" "0x80000"
        ;;
 asus,rt-ax59u)
        ubootenv_add_uci_config "/dev/mtd0" "0x100000" "0x20000" "0x20000"
@@ -119,8 +116,7 @@ routerich,ax3000|\
 routerich,ax3000-v1|\
 tenbay,wr3000k|\
 tplink,re6000xd)
-       local envdev=/dev/mtd$(find_mtd_index "u-boot-env")
-       ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x20000" "1"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x20000" "0x20000" "1"
        ;;
 openembed,som7981)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x80000" "0x80000"
@@ -132,8 +128,7 @@ openwrt,one)
 smartrg,sdg-8733|\
 smartrg,sdg-8733a|\
 smartrg,sdg-8734)
-       local envdev=$(find_mmc_part "u-boot-env" "mmcblk0")
-       ubootenv_add_uci_config "$envdev" "0x0" "0x8000" "0x8000"
+       ubootenv_add_mmc "u-boot-env" "mmcblk0" "0x0" "0x8000" "0x8000"
        ;;
 tplink,archer-ax80-v1)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x20000" "0x20000" "8"
@@ -148,8 +143,7 @@ xiaomi,redmi-router-ax6000-stock)
        ubootenv_add_uci_sys_config "/dev/mtd2" "0x0" "0x10000" "0x20000"
        ;;
 zyxel,ex5601-t0)
-       local envdev=/dev/mtd$(find_mtd_index "u-boot-env")
-       ubootenv_add_uci_config "$envdev" "0x0" "0x20000" "0x40000" "2"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x20000" "0x40000" "2"
        ;;
 zyxel,ex5700-telenor)
        ubootenv_add_uci_config "/dev/ubootenv" "0x0" "0x4000" "0x4000" "1"
index fd40b664e4c0a678f1d29f6b96015eef86e9a381..ce796a6d00b5fa0592acab871331639fa755a443 100644 (file)
@@ -10,9 +10,8 @@ touch /etc/config/ubootenv
 . /lib/functions.sh
 
 ubootenv_add_mmc_default() {
-       local envdev="$(find_mmc_part "ubootenv" "${1:-mmcblk0}")"
-       ubootenv_add_uci_config "$envdev" "0x0" "0x80000" "0x80000" "1"
-       ubootenv_add_uci_config "$envdev" "0x80000" "0x80000" "0x80000" "1"
+       ubootenv_add_mmc "ubootenv" "${1:-mmcblk0}" "0x0" "0x80000" "0x80000" "1"
+       ubootenv_add_mmc "ubootenv" "${1:-mmcblk0}" "0x80000" "0x80000" "0x80000" "1"
 }
 
 ubootenv_add_ubi_default() {
@@ -54,7 +53,7 @@ ruijie,rg-ew3200gx-pro)
 ubnt,unifi-6-lr-v1-ubootmod|\
 ubnt,unifi-6-lr-v2-ubootmod|\
 ubnt,unifi-6-lr-v3-ubootmod)
-       ubootenv_add_uci_config "/dev/mtd$(find_mtd_index "u-boot-env")" "0x0" "0x4000" "0x1000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x4000" "0x1000"
        ;;
 ubnt,unifi-6-lr-v2|\
 ubnt,unifi-6-lr-v3)
index a55ce3649f884925a1aac613365da5488a72514f..c78c1b97e1f897436fb76686f477f118300e3b65 100644 (file)
@@ -73,8 +73,7 @@ methode,edpu)
        fi
        ;;
 synology,ds213j)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x10000" "0x10000"
        ;;
 esac
 
index c2fc03da0996f3db15aa14dc9ee235102d1f1a03..3a8300395612d9d4c159d52101ed77c5b8b93e2e 100644 (file)
@@ -7,37 +7,19 @@ touch /etc/config/ubootenv
 
 board=$(board_name)
 
-ubootenv_add_mtd() {
-       local idx="$(find_mtd_index "${1}")"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "${2}" "${3}" "${4}"
-}
-
-ubootenv_add_sys_mtd() {
-       local idx="$(find_mtd_index "${1}")"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_sys_config "/dev/mtd$idx" "${2}" "${3}" "${4}"
-}
-
 case "$board" in
 elecom,wrc-x3000gs2|\
 iodata,wn-dax3000gr)
-       idx="$(find_mtd_index 0:appsblenv)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x40000" "0x20000"
+       ubootenv_add_mtd "0:appsblenv" "0x0" "0x40000" "0x20000"
        ;;
 glinet,gl-b3000)
-       idx="$(find_mtd_index 0:APPSBLENV)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x40000" "0x20000"
+       ubootenv_add_mtd "0:APPSBLENV" "0x0" "0x40000" "0x20000"
        ;;
 linksys,mr5500|\
 linksys,mx2000|\
 linksys,mx5500|\
 linksys,spnmx56)
-       idx="$(find_mtd_index u_env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x40000" "0x20000"
+       ubootenv_add_mtd "u_env" "0x0" "0x40000" "0x20000"
        ;;
 xiaomi,ax6000)
        ubootenv_add_mtd "0:appsblenv" "0x0" "0x10000" "0x20000"
index 02e4d30ae6da796df9d1f3649200325beb5185ff..8d53524a2c2ef0488b01be11fc3f87e0498cf88a 100644 (file)
@@ -52,9 +52,7 @@ rostelecom,rt-sf-1)
 beeline,smartbox-pro|\
 tplink,ec330-g5u-v1|\
 wifire,s1500-nbn)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x1000" "0x20000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x1000" "0x20000"
        ;;
 buffalo,wsr-1166dhp|\
 buffalo,wsr-600dhp|\
@@ -93,9 +91,7 @@ sim,simax1800t)
        ;;
 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"
+       ubootenv_add_mtd "u-boot-env" "0x4000" "0x1000" "0x1000"
        ;;
 beeline,smartbox-flash|\
 iptime,t5004|\
@@ -113,9 +109,7 @@ ubnt,edgerouter-x-sfp)
 snr,snr-cpe-me1|\
 snr,snr-cpe-me2-sfp|\
 snr,cpe-w4n-mt)
-       idx="$(find_mtd_index uboot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x1000" "0x1000"
+       ubootenv_add_mtd "uboot-env" "0x0" "0x1000" "0x1000"
        ;;
 xiaomi,miwifi-mini)
        ubootenv_add_uci_config "/dev/mtd1" "0x0" "0x1000" "0x10000"
@@ -141,9 +135,7 @@ zyxel,lte3301-plus)
 zyxel,lte5398-m904|\
 zyxel,lte7490-m904|\
 zyxel,nr7101)
-       idx="$(find_mtd_index Config)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x1000" "0x80000"
+       ubootenv_add_mtd "Config" "0x0" "0x1000" "0x80000"
        ;;
 bolt,arion|\
 xiaomi,mi-router-cr6606|\
index 055730eb27b3d299bc97fa5de6cdd94f27cbe284..49921da151ce3f8b16ae986946679f45ab0d9df0 100644 (file)
@@ -9,12 +9,8 @@ board=$(board_name)
 
 case "$board" in
 apresia,aplgs120gtss)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x40000" "0x10000"
-       idx2="$(find_mtd_index u-boot-env2)"
-       [ -n "$idx2" ] && \
-               ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x40000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x40000" "0x10000"
+       ubootenv_add_sys_mtd "u-boot-env2" "0x0" "0x40000" "0x10000"
        ;;
 d-link,dgs-1210-10mp|\
 d-link,dgs-1210-10p|\
@@ -31,35 +27,21 @@ zyxel,gs1900-24e|\
 zyxel,gs1900-24ep|\
 zyxel,gs1900-24hp-v1|\
 zyxel,gs1900-24hp-v2)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x400" "0x10000"
-       idx2="$(find_mtd_index u-boot-env2)"
-       [ -n "$idx2" ] && \
-               ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x1000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x400" "0x10000"
+       ubootenv_add_sys_mtd "u-boot-env2" "0x0" "0x1000" "0x10000"
        ;;
 tplink,sg2008p-v1|\
 tplink,sg2210p-v3|\
 tplink,sg2452p-v4)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x20000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x20000" "0x10000"
        ;;
 iodata,bsh-g24mb)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
-       idx2="$(find_mtd_index u-boot-env2)"
-       [ -n "$idx2" ] && \
-               ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x3800" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x10000" "0x10000"
+       ubootenv_add_sys_mtd "u-boot-env2" "0x0" "0x3800" "0x10000"
        ;;
 *)
-       idx="$(find_mtd_index u-boot-env)"
-       [ -n "$idx" ] && \
-               ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000"
-       idx2="$(find_mtd_index u-boot-env2)"
-       [ -n "$idx2" ] && \
-               ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x1000" "0x10000"
+       ubootenv_add_mtd "u-boot-env" "0x0" "0x10000" "0x10000"
+       ubootenv_add_sys_mtd "u-boot-env2" "0x0" "0x1000" "0x10000"
        ;;
 esac