0027-ar71xx-fix-model-string-detection-on-NETGEAR-WNDR3700-3800-WNDRMAC.patch 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 29 Mar 2015 13:23:26 +0200
  3. Subject: ar71xx: fix model string detection on NETGEAR WNDR3700/3800/WNDRMAC
  4. There were a few issues with the existing code to detect the model string:
  5. * Always using the string starting with byte 56 would cut off the W of WNDR when
  6. the ID starts with 29763654+16+64 instead of 29763654+16+128
  7. * The string contained garbage after the zero byte instead of cutting it off
  8. after the zero (which wasn't always visible using busybox tools, but could
  9. confuse other scripts)
  10. Tested on a WNDR3700v1 and a WNDR3700v2 using the new 29763654+16+64 ID in the
  11. ART. Furthermore, tested against ART dumps of a WNDR3700v2 using the old
  12. $'\xff...' value and a WNDR3800.
  13. The [ -z "$model" ] check was dropped as there is no way to actually hit this
  14. unless no ART partition is found at all.
  15. The awk command was carefully crafted to work both with gawk and the (horribly
  16. broken) busybox awk.
  17. Fixes #18992.
  18. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  19. diff --git a/target/linux/ar71xx/base-files/lib/ar71xx.sh b/target/linux/ar71xx/base-files/lib/ar71xx.sh
  20. index a698ce5..1838cb4 100755
  21. --- a/target/linux/ar71xx/base-files/lib/ar71xx.sh
  22. +++ b/target/linux/ar71xx/base-files/lib/ar71xx.sh
  23. @@ -37,16 +37,26 @@ wndr3700_board_detect() {
  24. machine="NETGEAR WNDR3700"
  25. ;;
  26. "33373031")
  27. - local model
  28. - model=$(ar71xx_get_mtd_offset_size_format art 56 10 %c)
  29. - if [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' ]; then
  30. - machine="NETGEAR WNDR3700v2"
  31. - elif [ -z "$model" ] || [ "$model" = $'\xff\xff\xff\xff\xff\xff\xff\xff\xffN' ]; then
  32. - machine="NETGEAR WNDRMAC"
  33. - else
  34. + # Use awk to remove everything after the first zero byte
  35. + model="$(ar71xx_get_mtd_offset_size_format art 41 32 %c | awk 'BEGIN{FS="[[:cntrl:]]"} {print $1; exit}')"
  36. + case $model in
  37. + $'\xff'*)
  38. + if [ "${model:24:1}" = 'N' ]; then
  39. + machine="NETGEAR WNDRMAC"
  40. + else
  41. + machine="NETGEAR WNDR3700v2"
  42. + fi
  43. + ;;
  44. + '29763654+16+64'*)
  45. + machine="NETGEAR ${model:14}"
  46. + ;;
  47. + '29763654+16+128'*)
  48. + machine="NETGEAR ${model:15}"
  49. + ;;
  50. + *)
  51. + # Unknown ID
  52. machine="NETGEAR $model"
  53. - fi
  54. - ;;
  55. + esac
  56. esac
  57. AR71XX_BOARD_NAME="$name"