From 735e36ce8e39edfe78c0491e7f3612bbfd63844f Mon Sep 17 00:00:00 2001 From: Javier Viguera Date: Tue, 10 Sep 2013 14:38:40 +0200 Subject: [PATCH] atheros: update script to get the mac from the device tree https://jira.digi.com/browse/DEL-637 Signed-off-by: Javier Viguera --- .../ccardimx28js/atheros | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/meta-digi-arm/recipes-kernel/kernel-module-atheros/kernel-module-atheros/ccardimx28js/atheros b/meta-digi-arm/recipes-kernel/kernel-module-atheros/kernel-module-atheros/ccardimx28js/atheros index 1dc23cbb8..27e479d84 100644 --- a/meta-digi-arm/recipes-kernel/kernel-module-atheros/kernel-module-atheros/ccardimx28js/atheros +++ b/meta-digi-arm/recipes-kernel/kernel-module-atheros/kernel-module-atheros/ccardimx28js/atheros @@ -20,27 +20,20 @@ set -e [ "${IFACE}" != "wlan0" ] && exit 0 FIRMWARE_DIR="/lib/firmware/ath6k/AR6003/hw2.1.1" -RAM_DRIVE="/var/run" -MAC_FILENAME="softmac" # # Get the wlan MAC address from kernel command line. Use a default # value if the address has not been set. # -MAC_ADDR="$(sed -ne 's,.\+ethaddr2=\([^[:blank:]]\+\)[[:blank:]].*,\1,g;T;p' /proc/cmdline)" +if [ -f "/proc/device-tree/wireless/mac-address" ]; then + MAC_ADDR="$(hexdump -ve '1/1 "%02X" ":"' /proc/device-tree/wireless/mac-address | sed 's/:$//g')" +else + MAC_ADDR="$(sed -ne 's,^.*ethaddr2=\([^[:blank:]]\+\)[:blank:]*.*,\1,g;T;p' /proc/cmdline)" +fi if [ -z "${MAC_ADDR}" -o "${MAC_ADDR}" = "00:00:00:00:00:00" ]; then MAC_ADDR="00:04:F3:4C:B1:D3" fi -mac1="$(echo ${MAC_ADDR} | cut -d':' -f1)" -mac2="$(echo ${MAC_ADDR} | cut -d':' -f2)" -mac3="$(echo ${MAC_ADDR} | cut -d':' -f3)" -mac4="$(echo ${MAC_ADDR} | cut -d':' -f4)" -mac5="$(echo ${MAC_ADDR} | cut -d':' -f5)" -mac6="$(echo ${MAC_ADDR} | cut -d':' -f6)" - -printf "\x${mac1}\x${mac2}\x${mac3}\x${mac4}\x${mac5}\x${mac6}" > ${RAM_DRIVE}/${MAC_FILENAME} - # We need to write the WLAN MAC address to softmac in the ath6k firmware # directory. However, we don't want to rewrite the file if it already exists # and the address is the same because we don't want to wear out NAND flash. @@ -48,10 +41,19 @@ printf "\x${mac1}\x${mac2}\x${mac3}\x${mac4}\x${mac5}\x${mac6}" > ${RAM_DRIVE}/$ # So create the file on the RAM DRIVE first and compare the two. Only update # the copy on NAND if the address has changed. # -if ! cmp -s ${RAM_DRIVE}/${MAC_FILENAME} ${FIRMWARE_DIR}/${MAC_FILENAME}; then - cp ${RAM_DRIVE}/${MAC_FILENAME} ${FIRMWARE_DIR}/${MAC_FILENAME} +mac1="$(echo ${MAC_ADDR} | cut -d':' -f1)" +mac2="$(echo ${MAC_ADDR} | cut -d':' -f2)" +mac3="$(echo ${MAC_ADDR} | cut -d':' -f3)" +mac4="$(echo ${MAC_ADDR} | cut -d':' -f4)" +mac5="$(echo ${MAC_ADDR} | cut -d':' -f5)" +mac6="$(echo ${MAC_ADDR} | cut -d':' -f6)" + +TMP_MACFILE="$(mktemp -t softmac.XXXXXX)" +printf "\x${mac1}\x${mac2}\x${mac3}\x${mac4}\x${mac5}\x${mac6}" > ${TMP_MACFILE} +if ! cmp -s ${TMP_MACFILE} ${FIRMWARE_DIR}/softmac; then + cp ${TMP_MACFILE} ${FIRMWARE_DIR}/softmac fi -rm -f ${RAM_DRIVE}/${MAC_FILENAME} +rm -f ${TMP_MACFILE} # Figure out which wireless region we are in. The US has rules for # what channels can be used and at what power level. We use a different set of @@ -59,13 +61,10 @@ rm -f ${RAM_DRIVE}/${MAC_FILENAME} # in OTP will be set to 0x0 for the US. Once we know the region, make sure the # appropriate calibration file is loaded. # -if [ -e "/sys/kernel/machine/name" ]; then - MACHINE="$(cat /sys/kernel/machine/name)" - REGION_CODE="$(cat /sys/kernel/${MACHINE}/mod_cert)" -elif [ -e "/proc/device-tree/digi,hwid,cert" ]; then - REGION_CODE="$(cat /proc/device-tree/digi,hwid,cert)" -fi - +MACHINE="$(cat /proc/device-tree/digi,machine,name 2>/dev/null || \ + cat /sys/kernel/machine/name)" +REGION_CODE="$(cat /proc/device-tree/digi,hwid,cert 2>/dev/null || \ + cat /sys/kernel/${MACHINE}/mod_cert)" US_CODE="0x0" BDATA_SOURCE="Digi_6203-6233-World.bin" if [ -n "${REGION_CODE}" -a "${US_CODE}" = "${REGION_CODE}" ]; then