From 8aae84757d645096d7348acbf599da34d792f991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Owoc?= Date: Fri, 16 May 2025 16:19:05 +0200 Subject: [PATCH] uboot-tools: use ubootenv_add_* functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use ubootenv_add_* functions for code simplification. Signed-off-by: Paweł Owoc Link: https://github.com/openwrt/openwrt/pull/18818 Signed-off-by: Hauke Mehrtens --- .../uboot-tools/uboot-envtools/files/ath79 | 4 +-- .../uboot-tools/uboot-envtools/files/lantiq | 4 +-- .../uboot-envtools/files/mediatek_filogic | 22 +++++------- .../uboot-envtools/files/mediatek_mt7622 | 7 ++-- .../uboot-tools/uboot-envtools/files/mvebu | 3 +- .../uboot-envtools/files/qualcommax_ipq50xx | 24 ++----------- .../uboot-tools/uboot-envtools/files/ramips | 16 +++------ .../uboot-tools/uboot-envtools/files/realtek | 36 +++++-------------- 8 files changed, 30 insertions(+), 86 deletions(-) diff --git a/package/boot/uboot-tools/uboot-envtools/files/ath79 b/package/boot/uboot-tools/uboot-envtools/files/ath79 index dc46d5ed399..f275244cbe8 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/ath79 +++ b/package/boot/uboot-tools/uboot-envtools/files/ath79 @@ -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" diff --git a/package/boot/uboot-tools/uboot-envtools/files/lantiq b/package/boot/uboot-tools/uboot-envtools/files/lantiq index 81af7e804f8..4e6fb48b76e 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/lantiq +++ b/package/boot/uboot-tools/uboot-envtools/files/lantiq @@ -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 diff --git a/package/boot/uboot-tools/uboot-envtools/files/mediatek_filogic b/package/boot/uboot-tools/uboot-envtools/files/mediatek_filogic index 9654635bca0..7ca793a8d49 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/mediatek_filogic +++ b/package/boot/uboot-tools/uboot-envtools/files/mediatek_filogic @@ -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" diff --git a/package/boot/uboot-tools/uboot-envtools/files/mediatek_mt7622 b/package/boot/uboot-tools/uboot-envtools/files/mediatek_mt7622 index fd40b664e4c..ce796a6d00b 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/mediatek_mt7622 +++ b/package/boot/uboot-tools/uboot-envtools/files/mediatek_mt7622 @@ -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) diff --git a/package/boot/uboot-tools/uboot-envtools/files/mvebu b/package/boot/uboot-tools/uboot-envtools/files/mvebu index a55ce3649f8..c78c1b97e1f 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/mvebu +++ b/package/boot/uboot-tools/uboot-envtools/files/mvebu @@ -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 diff --git a/package/boot/uboot-tools/uboot-envtools/files/qualcommax_ipq50xx b/package/boot/uboot-tools/uboot-envtools/files/qualcommax_ipq50xx index c2fc03da099..3a830039561 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/qualcommax_ipq50xx +++ b/package/boot/uboot-tools/uboot-envtools/files/qualcommax_ipq50xx @@ -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" diff --git a/package/boot/uboot-tools/uboot-envtools/files/ramips b/package/boot/uboot-tools/uboot-envtools/files/ramips index 02e4d30ae6d..8d53524a2c2 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/ramips +++ b/package/boot/uboot-tools/uboot-envtools/files/ramips @@ -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|\ diff --git a/package/boot/uboot-tools/uboot-envtools/files/realtek b/package/boot/uboot-tools/uboot-envtools/files/realtek index 055730eb27b..49921da151c 100644 --- a/package/boot/uboot-tools/uboot-envtools/files/realtek +++ b/package/boot/uboot-tools/uboot-envtools/files/realtek @@ -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