mirror of
				https://github.com/Telecominfraproject/wlan-ap.git
				synced 2025-10-30 18:07:52 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			258 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			258 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From b4de8243ca22d160f9cad42ed0f145e90ac98249 Mon Sep 17 00:00:00 2001
 | |
| From: John Crispin <john@phrozen.org>
 | |
| Date: Sat, 15 Jul 2023 16:10:26 +0200
 | |
| Subject: [PATCH 61/68] ipq807x: add uboot-envtools support
 | |
| 
 | |
| Signed-off-by: John Crispin <john@phrozen.org>
 | |
| ---
 | |
|  package/base-files/files/lib/functions.sh | 13 ++++
 | |
|  package/boot/uboot-envtools/Makefile      |  6 --
 | |
|  package/boot/uboot-envtools/files/ipq50xx | 37 +++++++++++
 | |
|  package/boot/uboot-envtools/files/ipq60xx | 53 ++++++++++++++++
 | |
|  package/boot/uboot-envtools/files/ipq807x | 76 +++++++++++------------
 | |
|  5 files changed, 141 insertions(+), 44 deletions(-)
 | |
|  create mode 100644 package/boot/uboot-envtools/files/ipq50xx
 | |
|  create mode 100644 package/boot/uboot-envtools/files/ipq60xx
 | |
| 
 | |
| diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh
 | |
| index 4b1b838572..87e2edee7a 100644
 | |
| --- a/package/base-files/files/lib/functions.sh
 | |
| +++ b/package/base-files/files/lib/functions.sh
 | |
| @@ -32,6 +32,19 @@ xor() {
 | |
|  	printf "%0${retlen}x" "$ret"
 | |
|  }
 | |
|  
 | |
| +find_mmc_part() {
 | |
| +        local DEVNAME PARTNAME
 | |
| +        if grep -q "$1" /proc/mtd; then
 | |
| +                echo "" && return 0
 | |
| +        fi
 | |
| +
 | |
| +        for DEVNAME in /sys/block/mmcblk*/mmcblk*p*; do
 | |
| +                PARTNAME=$(grep PARTNAME ${DEVNAME}/uevent | cut -f2 -d'=')
 | |
| +                [ "$PARTNAME" = "$1" ] && echo "/dev/$(basename $DEVNAME)" && return 0
 | |
| +        done
 | |
| +}
 | |
| +
 | |
| +
 | |
|  append() {
 | |
|  	local var="$1"
 | |
|  	local value="$2"
 | |
| diff --git a/package/boot/uboot-envtools/Makefile b/package/boot/uboot-envtools/Makefile
 | |
| index 2e4c1ac39e..b9d8895e76 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/ipq50xx b/package/boot/uboot-envtools/files/ipq50xx
 | |
| new file mode 100644
 | |
| index 0000000000..84ed73f288
 | |
| --- /dev/null
 | |
| +++ b/package/boot/uboot-envtools/files/ipq50xx
 | |
| @@ -0,0 +1,37 @@
 | |
| +[ -e /etc/config/ubootenv ] && rm /etc/config/ubootenv
 | |
| +
 | |
| +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
 | |
| +*)
 | |
| +	ubootenv_add_uci_config $(ubootenv_mtdinfo)
 | |
| +	;;
 | |
| +esac
 | |
| +
 | |
| +config_load ubootenv
 | |
| +config_foreach ubootenv_add_app_config ubootenv
 | |
| +
 | |
| +exit 0
 | |
| diff --git a/package/boot/uboot-envtools/files/ipq60xx b/package/boot/uboot-envtools/files/ipq60xx
 | |
| new file mode 100644
 | |
| index 0000000000..8863df4225
 | |
| --- /dev/null
 | |
| +++ b/package/boot/uboot-envtools/files/ipq60xx
 | |
| @@ -0,0 +1,53 @@
 | |
| +[ -e /etc/config/ubootenv ] && rm /etc/config/ubootenv
 | |
| +
 | |
| +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})
 | |
| +    	found_emmc=0
 | |
| +    
 | |
| +         if [ -z "$UBOOTENV_PART" ]; then
 | |
| +                mtd_dev=$(echo $(find_mmc_part "0:APPSBLENV") | sed 's/^.\{5\}//')
 | |
| +                if [ -n "$mtd_dev" ]; then
 | |
| +                        EMMC_UBOOTENV_PART=$(cat /proc/partitions | grep $mtd_dev)
 | |
| +                        #convert block to bytes
 | |
| +                        emmc_ubootenv_size=`expr $(echo $EMMC_UBOOTENV_PART | awk '{print $3}') \* 1024`
 | |
| +                        ubootenv_size=0x`printf "%x" $emmc_ubootenv_size`
 | |
| +			found_emmc=1
 | |
| +                fi
 | |
| +                mtd_erase=""
 | |
| +        
 | |
| +	elif [ -n "$nor_flash" ]; then
 | |
| +		ubootenv_size=$mtd_size
 | |
| +	else
 | |
| +		# size is fixed to 0x40000 in u-boot
 | |
| +		ubootenv_size=0x40000
 | |
| +	fi
 | |
| +	if [ $found_emmc -eq 0 ]; then
 | |
| +                sectors=$(printf '0x%x' $(( $ubootenv_size / $mtd_erase )))
 | |
| +                echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
 | |
| +	else
 | |
| +                echo /dev/$mtd_dev 0x0 $ubootenv_size
 | |
| +	fi
 | |
| +
 | |
| +}
 | |
| +
 | |
| +case "$board" in
 | |
| +*)
 | |
| +	ubootenv_add_uci_config $(ubootenv_mtdinfo)
 | |
| +	;;
 | |
| +esac
 | |
| +
 | |
| +config_load ubootenv
 | |
| +config_foreach ubootenv_add_app_config ubootenv
 | |
| +
 | |
| +exit 0
 | |
| diff --git a/package/boot/uboot-envtools/files/ipq807x b/package/boot/uboot-envtools/files/ipq807x
 | |
| index 2064bfc6f2..8863df4225 100644
 | |
| --- a/package/boot/uboot-envtools/files/ipq807x
 | |
| +++ b/package/boot/uboot-envtools/files/ipq807x
 | |
| @@ -1,4 +1,4 @@
 | |
| -[ -e /etc/config/ubootenv ] && exit 0
 | |
| +[ -e /etc/config/ubootenv ] && rm /etc/config/ubootenv
 | |
|  
 | |
|  touch /etc/config/ubootenv
 | |
|  
 | |
| @@ -7,47 +7,47 @@ touch /etc/config/ubootenv
 | |
|  
 | |
|  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})
 | |
| +    	found_emmc=0
 | |
| +    
 | |
| +         if [ -z "$UBOOTENV_PART" ]; then
 | |
| +                mtd_dev=$(echo $(find_mmc_part "0:APPSBLENV") | sed 's/^.\{5\}//')
 | |
| +                if [ -n "$mtd_dev" ]; then
 | |
| +                        EMMC_UBOOTENV_PART=$(cat /proc/partitions | grep $mtd_dev)
 | |
| +                        #convert block to bytes
 | |
| +                        emmc_ubootenv_size=`expr $(echo $EMMC_UBOOTENV_PART | awk '{print $3}') \* 1024`
 | |
| +                        ubootenv_size=0x`printf "%x" $emmc_ubootenv_size`
 | |
| +			found_emmc=1
 | |
| +                fi
 | |
| +                mtd_erase=""
 | |
| +        
 | |
| +	elif [ -n "$nor_flash" ]; then
 | |
| +		ubootenv_size=$mtd_size
 | |
| +	else
 | |
| +		# size is fixed to 0x40000 in u-boot
 | |
| +		ubootenv_size=0x40000
 | |
| +	fi
 | |
| +	if [ $found_emmc -eq 0 ]; then
 | |
| +                sectors=$(printf '0x%x' $(( $ubootenv_size / $mtd_erase )))
 | |
| +                echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors
 | |
| +	else
 | |
| +                echo /dev/$mtd_dev 0x0 $ubootenv_size
 | |
| +	fi
 | |
| +
 | |
| +}
 | |
| +
 | |
|  case "$board" in
 | |
| -dynalink,dl-wrx36|\
 | |
| -netgear,wax218)
 | |
| -	idx="$(find_mtd_index 0:appsblenv)"
 | |
| -	[ -n "$idx" ] && \
 | |
| -		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x40000" "0x20000" "2"
 | |
| -	;;
 | |
| -edgecore,eap102|\
 | |
| -zyxel,nbg7815)
 | |
| -	idx="$(find_mtd_index 0:appsblenv)"
 | |
| -	[ -n "$idx" ] && \
 | |
| -		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x10000" "1"
 | |
| -	;;
 | |
| -edimax,cax1800)
 | |
| -	idx="$(find_mtd_index 0:appsblenv)"
 | |
| -	[ -n "$idx" ] && \
 | |
| -		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x20000"
 | |
| -	;;
 | |
| -redmi,ax6|\
 | |
| -xiaomi,ax3600|\
 | |
| -xiaomi,ax9000)
 | |
| -	idx="$(find_mtd_index 0:appsblenv)"
 | |
| -	[ -n "$idx" ] && \
 | |
| -		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x10000" "0x20000"
 | |
| -	idx2="$(find_mtd_index bdata)"
 | |
| -	[ -n "$idx2" ] && \
 | |
| -		ubootenv_add_uci_sys_config "/dev/mtd$idx2" "0x0" "0x10000" "0x20000"
 | |
| -	;;
 | |
| -prpl,haze)
 | |
| -	mmcpart="$(find_mmc_part 0:APPSBLENV)"
 | |
| -	[ -n "$mmcpart" ] && \
 | |
| -		ubootenv_add_uci_config "$mmcpart" "0x0" "0x40000" "0x400" "0x100"
 | |
| -	;;
 | |
| -qnap,301w)
 | |
| -	idx="$(find_mtd_index 0:appsblenv)"
 | |
| -	[ -n "$idx" ] && \
 | |
| -		ubootenv_add_uci_config "/dev/mtd$idx" "0x0" "0x20000" "0x20000" "1"
 | |
| +*)
 | |
| +	ubootenv_add_uci_config $(ubootenv_mtdinfo)
 | |
|  	;;
 | |
|  esac
 | |
|  
 | |
|  config_load ubootenv
 | |
| -config_foreach ubootenv_add_app_config
 | |
| +config_foreach ubootenv_add_app_config ubootenv
 | |
|  
 | |
|  exit 0
 | |
| -- 
 | |
| 2.34.1
 | |
| 
 | 
