From 7d2818e1e1b49b9172c66171e9a96f4cdb9418ff Mon Sep 17 00:00:00 2001 From: Ken Date: Tue, 7 Feb 2023 14:39:52 +0800 Subject: [PATCH 1/9] Add fw_printenv support for EMMC --- package/base-files/files/lib/functions.sh | 13 ++++++++++++ package/boot/uboot-envtools/files/ipq60xx | 24 +++++++++++++++++++---- package/boot/uboot-envtools/files/ipq807x | 24 +++++++++++++++++++---- 3 files changed, 53 insertions(+), 8 deletions(-) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index 2bad45324f..415e0763ed 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/files/ipq60xx b/package/boot/uboot-envtools/files/ipq60xx index 84ed73f288..8863df4225 100644 --- a/package/boot/uboot-envtools/files/ipq60xx +++ b/package/boot/uboot-envtools/files/ipq60xx @@ -13,16 +13,32 @@ ubootenv_mtdinfo () { 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 + 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 - sectors=$(( $ubootenv_size / $mtd_erase )) - echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors } case "$board" in diff --git a/package/boot/uboot-envtools/files/ipq807x b/package/boot/uboot-envtools/files/ipq807x index 2dcd294964..8863df4225 100644 --- a/package/boot/uboot-envtools/files/ipq807x +++ b/package/boot/uboot-envtools/files/ipq807x @@ -13,16 +13,32 @@ ubootenv_mtdinfo () { 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 + 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 - sectors=$(printf '0x%x' $(( $ubootenv_size / $mtd_erase ))) - echo /dev/$mtd_dev 0x0 $ubootenv_size $mtd_erase $sectors } case "$board" in -- 2.34.1