1
0

nvram-bcm47xx.init 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh /etc/rc.common
  2. # NVRAM setup
  3. #
  4. # This file handles the NVRAM quirks of various hardware of the bcm47xx target.
  5. START=02
  6. alias debug=${DEBUG:-:}
  7. nvram_default() {
  8. [ -z "$(nvram get $1)" ] && nvram set "$1=$2"
  9. }
  10. nvram_set() { # for the linksys fixup part
  11. [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || {
  12. COMMIT=1
  13. /usr/sbin/nvram set "$1=$2"
  14. }
  15. }
  16. fixup_linksys() {
  17. # work around braindead CFE defaults in linksys routers
  18. boardtype=$(nvram get boardtype)
  19. boardnum=$(nvram get boardnum)
  20. boardflags=$(($(nvram get boardflags)))
  21. adm_switch="$(( ($boardflags & 0x80) >> 7 ))"
  22. [ -n "$(nvram get vxkilled)" ] && boardtype=0 # don't mess with the ram settings on the hacked cfe
  23. case "$(( $boardtype ))" in
  24. "1800") #0x708
  25. if [ "$adm_switch" = 0 ]; then
  26. nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
  27. [ "$COMMIT" = 1 ] && {
  28. nvram_set clkfreq 216
  29. nvram_set sdram_ncdl 0x0
  30. nvram_set pa0itssit 62
  31. nvram_set pa0b0 0x15eb
  32. nvram_set pa0b1 0xfa82
  33. nvram_set pa0b2 0xfe66
  34. nvram_set pa0maxpwr 0x4e
  35. }
  36. fi
  37. ;;
  38. "1127") #0x467
  39. nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))"
  40. [ "$COMMIT" = 1 ] && {
  41. nvram_set sdram_ncdl 0x0
  42. nvram_set pa0itssit 62
  43. nvram_set pa0b0 0x168b
  44. nvram_set pa0b1 0xfabf
  45. nvram_set pa0b2 0xfeaf
  46. nvram_set pa0maxpwr 0x4e
  47. }
  48. ;;
  49. "1071") #0x042f
  50. # do sanity check first! max 0x0011 = 128mb
  51. SDRAM_INIT=$(printf %d $(/usr/sbin/nvram get sdram_init))
  52. [ "$SDRAM_INIT" -lt "9" -o "$SDRAM_INIT" -gt "17" ] && {
  53. # set this to default: 0x09 only if value is invaild like 16MB on Asus WL-500GP
  54. echo "sdram_init is invaild: $(printf 0x%04x $SDRAM_INIT), force to default!"
  55. nvram_set sdram_init 0x0009
  56. }
  57. # on WRT54G3GV2 set flag, so checksum errors of firmware image 2 don't stop the boot process
  58. noset_try_flag=$(nvram get noset_try_flag)
  59. [ "$noset_try_flag" = 0 ] && {
  60. echo "setting noset_try_flag to 1."
  61. nvram_set noset_try_flag 1
  62. }
  63. [ "$COMMIT" = 1 ] && {
  64. nvram_set sdram_ncdl 0x0
  65. }
  66. esac
  67. }
  68. boot() {
  69. # Don't do any fixups on the WGT634U
  70. [ "$(cat /proc/diag/model)" = "Netgear WGT634U" ] && return
  71. fixup_linksys
  72. # OFDM Power Offset is set incorrectly on many boards.
  73. # Setting it to 0 will increase the tx power to normal levels.
  74. nvram_set opo 0x0
  75. [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && {
  76. # if default wifi mac, set two higher than the lan mac
  77. nvram set il0macaddr=$(nvram get et0macaddr|
  78. awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
  79. }
  80. [ "$(nvram get et0macaddr)" = "00:90:4c:c0:00:08" ] && {
  81. # OvisLink WL-1600GL mac workaround
  82. nvram set et0macaddr=$(hexdump -n 6 -s 130976 -e '5/1 "%02x:" "%02x" ' /dev/mtd/0)
  83. nvram set il0macaddr=$(nvram get et0macaddr|
  84. awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}')
  85. }
  86. [ "$COMMIT" = "1" ] && nvram commit
  87. }