From 010702bc1a87b2c716f3e4dc9906f47a4931f03f Mon Sep 17 00:00:00 2001 From: Hugo Yuan <429632952@163.com> Date: Sat, 27 Nov 2021 18:14:36 +0800 Subject: [PATCH] base-file: Add mmc support (#8329) --- package/base-files/files/lib/functions.sh | 19 ++++++++++++ .../base-files/files/lib/functions/caldata.sh | 15 +++++++++- .../base-files/files/lib/functions/system.sh | 29 ++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh index d8604415c..33efc852c 100644 --- a/package/base-files/files/lib/functions.sh +++ b/package/base-files/files/lib/functions.sh @@ -313,6 +313,25 @@ find_mtd_part() { echo "${INDEX:+$PREFIX$INDEX}" } +find_mmc_part() { + local DEVNAME PARTNAME ROOTDEV + + if grep -q "$1" /proc/mtd; then + echo "" && return 0 + fi + + if [ -n "$2" ]; then + ROOTDEV="$2" + else + ROOTDEV="mmcblk*" + fi + + for DEVNAME in /sys/block/$ROOTDEV/mmcblk*p*; do + PARTNAME="$(grep PARTNAME ${DEVNAME}/uevent | cut -f2 -d'=')" + [ "$PARTNAME" = "$1" ] && echo "/dev/$(basename $DEVNAME)" && return 0 + done +} + group_add() { local name="$1" local gid="$2" diff --git a/package/base-files/files/lib/functions/caldata.sh b/package/base-files/files/lib/functions/caldata.sh index 2177cf841..a1a60ee38 100644 --- a/package/base-files/files/lib/functions/caldata.sh +++ b/package/base-files/files/lib/functions/caldata.sh @@ -48,6 +48,19 @@ caldata_extract_ubi() { caldata_die "failed to extract calibration data from $ubi" } +caldata_extract_mmc() { + local part=$1 + local offset=$(($2)) + local count=$(($3)) + local mmc_part + + mmc_part=$(find_mmc_part $part) + [ -n "$mmc_part" ] || caldata_die "no mmc partition found for partition $part" + + caldata_dd $mmc_part /lib/firmware/$FIRMWARE $count $offset || \ + caldata_die "failed to extract calibration data from $mmc_part" +} + caldata_extract_reverse() { local part=$1 local offset=$2 @@ -168,4 +181,4 @@ ath10k_patch_mac() { local target=$2 caldata_patch_mac "$mac" 0x6 0x2 "$target" -} +} \ No newline at end of file diff --git a/package/base-files/files/lib/functions/system.sh b/package/base-files/files/lib/functions/system.sh index 80e417182..fb3a3b6d1 100644 --- a/package/base-files/files/lib/functions/system.sh +++ b/package/base-files/files/lib/functions/system.sh @@ -79,6 +79,24 @@ mtd_get_mac_ascii() { [ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" } +mtd_get_mac_ascii_mmc() { + local mtdname="$1" + local key="$2" + local part + local mac_dirty + + part=$(find_mmc_part "$mtdname") + if [ -z "$part" ]; then + echo "mtd_get_mac_ascii: partition $mtdname not found!" >&2 + return + fi + + mac_dirty=$(strings "$part" | sed -n 's/^'"$key"'=//p') + + # "canonicalize" mac + [ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" +} + mtd_get_mac_text() { local mtdname=$1 local offset=$(($2)) @@ -123,6 +141,15 @@ mtd_get_mac_binary_ubi() { get_mac_binary "/dev/$part" "$offset" } +mtd_get_mac_binary_mmc() { + local mtdname="$1" + local offset="$2" + local part + + part=$(find_mmc_part "$mtdname") + get_mac_binary "$part" "$offset" +} + mtd_get_part_size() { local part_name=$1 local first dev size erasesize name @@ -223,4 +250,4 @@ macaddr_canonicalize() { [ ${#canon} -ne 17 ] && return printf "%02x:%02x:%02x:%02x:%02x:%02x" 0x${canon// / 0x} 2>/dev/null -} +} \ No newline at end of file