1 #!/bin/sh 2 3 # Bootlevels 4 # 1 - start only inetd 0000 0001 5 # 2 - load mav80211 0000 0010 6 # 4 - load driver 0000 0100 7 # 8 - up dev, load wpa_supplicant 0000 1000 8 # 16 - Settings for Android 0001 0000 9 # 32 - running AP 0010 0000 10 # 64 - 1-command calibration 0100 0000 11 12 go_version="0.91" 13 usage() 14 { 15 echo -e "\tUSAGE:\n\t `basename $0` <option> [value]" 16 echo -e "\t\t-b <value> - bootlevel, where\n\t\t\t7-PLT boot" 17 echo -e "\t\t\t15-full boot" 18 echo -e "\t\t-c <path to INI file> [path to install NVS] -" \ 19 "run calibration" 20 echo -e "\t\t-c2 <path to INI file> <path to INI file> -" \ 21 "run calibration with 2 FEMs" 22 echo -e "\t\t\twhere the default value for install path is " 23 echo -e "\t\t\t/lib/firmware/ti-connectivity/wl1271-nvs.bin" 24 echo -e "\t\t-d <value> - debuglevel, where" 25 echo -e "\t\t\t -1 - shows current value 26 \t\t\tDEBUG_IRQ = BIT(0) 27 \t\t\tDEBUG_SPI = BIT(1) 28 \t\t\tDEBUG_BOOT = BIT(2) 29 \t\t\tDEBUG_MAILBOX = BIT(3) 30 \t\t\tDEBUG_TESTMODE = BIT(4) 31 \t\t\tDEBUG_EVENT = BIT(5) 32 \t\t\tDEBUG_TX = BIT(6) 33 \t\t\tDEBUG_RX = BIT(7) 34 \t\t\tDEBUG_SCAN = BIT(8) 35 \t\t\tDEBUG_CRYPT = BIT(9) 36 \t\t\tDEBUG_PSM = BIT(10) 37 \t\t\tDEBUG_MAC80211 = BIT(11) 38 \t\t\tDEBUG_CMD = BIT(12) 39 \t\t\tDEBUG_ACX = BIT(13) 40 \t\t\tDEBUG_SDIO = BIT(14) 41 \t\t\tDEBUG_FILTERS = BIT(15) 42 \t\t\tDEBUG_ADHOC = BIT(16) 43 \t\t\tDEBUG_ALL = ~0" 44 echo -e "\t\t-m <value> - set MAC address" 45 echo -e "\t\t-ip [value] - set IP address" 46 echo -e "\t\t-v - get script version" 47 echo -e "\t\t-h - get this help" 48 } 49 50 i=0 51 nbr_args=$# 52 bootlevel=0 53 dbg_lvl=0 54 ref_clk=0 55 mac_addr="08:00:28:90:64:31" 56 ip_addr="192.168.1.1" 57 set_ip_addr=0 58 have_path_to_ini=0 59 path_to_ini="" 60 path_to_ini2="" 61 have_path_to_install=0 62 path_to_install="/lib/firmware/ti-connectivity/wl1271-nvs.bin" 63 is_android=0 64 prefix_path2modules= 65 while [ "$i" -lt "$nbr_args" ] 66 do 67 case $1 in 68 -b) bootlevel=$2 69 nbr_args=`expr $nbr_args - 1` 70 shift 71 ;; 72 #-r) ref_clk=$2 73 #nbr_args=`expr $nbr_args - 1` 74 #shift 75 #;; 76 -c) 77 if [ "$nbr_args" -lt "2" ]; then 78 echo -e "missing arguments" 79 exit 1 80 fi 81 82 bootlevel=66 83 have_path_to_ini=`expr $have_path_to_ini + 1` 84 path_to_ini=$2 85 if [ "$nbr_args" -eq "2" ]; then 86 echo -e " The install path not provided" 87 echo -e " Use default ($path_to_install)" 88 nbr_args=`expr $nbr_args - 1` 89 shift 90 break 91 fi 92 93 have_path_to_install=`expr $have_path_to_install + 1` 94 path_to_install=$3 95 nbr_args=`expr $nbr_args - 2` 96 shift 97 shift 98 ;; 99 -c2) # calibration with 2 FEMs 100 if [ "$nbr_args" -lt "3" ]; then 101 echo -e "missing arguments" 102 exit 1 103 fi 104 105 bootlevel=34 106 have_path_to_ini=`expr $have_path_to_ini + 1` 107 path_to_ini=$2 108 path_to_ini2=$3 109 nbr_args=`expr $nbr_args - 2` 110 shift 111 shift 112 ;; 113 -d) dbg_lvl=$2 114 nbr_args=`expr $nbr_args - 1` 115 shift 116 ;; 117 -m) mac_addr=$2 118 nbr_args=`expr $nbr_args - 1` 119 shift 120 ;; 121 -ip) set_ip_addr=`expr $set_ip_addr + 1` 122 case $2 in 123 "") echo -e "using default ip address" 124 ;; 125 -*) echo -e "this is another option" 126 ;; 127 *) ip_addr=$2 128 nbr_args=`expr $nbr_args - 1` 129 shift 130 ;; 131 esac 132 ;; 133 -ini) 134 have_path_to_ini=`expr $have_path_to_ini + 1` 135 path_to_ini=$2 136 nbr_args=`expr $nbr_args - 1` 137 shift 138 ;; 139 -v) 140 echo -e "\tgo.sh version $go_version" 141 ;; 142 -h) usage 143 exit 0 144 ;; 145 *) echo -e "\tNothing to do" 146 ;; 147 esac 148 i=`expr $i + 1` 149 shift 150 done 151 152 stage_uno=0 153 stage_due=0 154 stage_quattro=0 155 stage_otto=0 156 stage_sedici=0 157 stage_trentadue=0 158 stage_sessanta_quattro=0 159 case $bootlevel in 160 1) stage_uno=`expr $stage_uno + 1` 161 ;; 162 2) stage_due=`expr $stage_due + 1` 163 ;; 164 3) stage_uno=`expr $stage_uno + 1` 165 stage_due=`expr $stage_due + 1` 166 ;; 167 4) stage_quattro=`expr $stage_quattro + 1` 168 ;; 169 5) stage_uno=`expr $stage_uno + 1` 170 stage_quattro=`expr $stage_quattro + 1` 171 ;; 172 6) stage_due=`expr $stage_due + 1` 173 stage_quattro=`expr $stage_quattro + 1` 174 ;; 175 7) stage_uno=`expr $stage_uno + 1` 176 stage_due=`expr $stage_due + 1` 177 stage_quattro=`expr $stage_quattro + 1` 178 ;; 179 8) stage_otto=`expr $stage_otto + 1` 180 ;; 181 12) stage_quattro=`expr $stage_quattro + 1` 182 stage_otto=`expr $stage_otto + 1` 183 ;; 184 15) stage_uno=`expr $stage_uno + 1` 185 stage_due=`expr $stage_due + 1` 186 stage_quattro=`expr $stage_quattro + 1` 187 stage_otto=`expr $stage_otto + 1` 188 ;; 189 16) stage_sedici=`expr $stage_sedici + 1` 190 ;; 191 32) stage_trentadue=`expr $stage_trentadue + 1` 192 ;; 193 34) 194 stage_due=`expr $stage_due + 1` 195 stage_trentadue=`expr $stage_trentadue + 1` 196 ;; 197 64) stage_sessanta_quattro=`expr $stage_sessanta_quattro + 1` 198 ;; 199 66) 200 stage_due=`expr $stage_due + 1` 201 stage_sessanta_quattro=`expr $stage_sessanta_quattro + 1` 202 ;; 203 esac 204 205 echo -e "\t------------ ------------\n" 206 echo -e "\t---===<<<((( WELCOME )))>>>===---\n" 207 echo -e "\t------------ ------------\n" 208 209 insmod_path= 210 rmmod_path= 211 212 if [ $ANDROID_ROOT ]; then 213 is_android=`expr $is_android + 1` 214 prefix_path2modules="/system/" 215 insmod_path="/system/bin/" 216 rmmod_path="/system/bin/" 217 fi 218 219 if [ "$stage_uno" -ne "0" ]; then 220 echo -e "+++ Mount the debugfs on /sys/kernel/debug" 221 222 echo 8 > /proc/sys/kernel/printk 223 224 if [ -e /libexec/inetd ]; then 225 /libexec/inetd /etc/inetd.conf & 226 fi 227 228 if [ ! -e /sys/kernel/debug/tracing ]; then 229 mount -t debugfs none /sys/kernel/debug/ 230 fi 231 fi 232 233 if [ "$stage_due" -ne "0" ]; then 234 echo -e "+++ Load mac80211, cfg80211, crc7 and firmware_class" 235 236 run_it=`cat /proc/modules | grep "cfg80211"` 237 if [ "$run_it" == "" ]; then 238 "$insmod_path"insmod /lib/modules/`uname -r`/kernel/net/wireless/cfg80211.ko 239 fi 240 run_it=`cat /proc/modules | grep "mac80211"` 241 if [ "$run_it" == "" ]; then 242 insmod /lib/modules/`uname -r`/kernel/net/mac80211/mac80211.ko 243 fi 244 run_it=`cat /proc/modules | grep "crc7"` 245 if [ "$run_it" == "" ]; then 246 insmod /lib/modules/`uname -r`/kernel/lib/crc7.ko 247 fi 248 run_it=`cat /proc/modules | grep "firmware_class"` 249 if [ "$run_it" == "" ]; then 250 insmod /lib/modules/`uname -r`/kernel/drivers/base/firmware_class.ko 251 fi 252 fi 253 254 if [ "$stage_quattro" -ne "0" ]; then 255 echo -e "+++ Load wl12xx driver, enable mac80211 tracing" 256 257 run_it=`cat /proc/modules | grep "wl12xx"` 258 if [ "$run_it" == "" ]; then 259 if [ "$is_android" -eq "0" ]; then 260 "$insmod_path"insmod /lib/modules/`uname -r`/kernel/drivers/net/wireless/wl12xx/wl12xx.ko 261 else 262 "$insmod_path"insmod /system/lib/modules/wl12xx.ko 263 fi 264 if [ "$?" != "0" ]; then 265 echo -e "Fail to load wl12xx" 266 exit 1 267 fi 268 fi 269 270 run_it=`cat /proc/modules | grep "wl12xx_sdio"` 271 if [ "$run_it" == "" ]; then 272 if [ "$is_android" -eq "0" ]; then 273 "$insmod_path"insmod /lib/modules/`uname -r`/kernel/drivers/net/wireless/wl12xx/wl12xx_sdio.ko 274 else 275 insmod /system/lib/modules/wl12xx_sdio.ko 276 fi 277 if [ "$?" != "0" ]; then 278 echo -e "Fail to load wl12xx_sdio" 279 exit 1 280 fi 281 fi 282 283 sleep 1 284 if [ -e /sys/kernel/debug/tracing ]; then 285 echo 1 > /sys/kernel/debug/tracing/events/mac80211/enable 286 fi 287 288 #ifconfig wlan0 hw ether $mac_addr 289 #cat /sys/kernel/debug/mmc2/ios 290 fi 291 292 if [ "$stage_otto" -ne "0" ]; then 293 echo -e "+++ Start interface, enable monitoring events, run wpa_supplicant" 294 295 ifconfig wlan0 up 296 if [ "$?" != "0" ]; then 297 echo -e "Fail to start iface" 298 exit 1 299 fi 300 301 sleep 1 302 iw event > /var/log/iwevents & 303 304 #wpa_supplicant -P/var/run/wpa_supplicant.pid -iwlan0 305 # -c/etc/wpa_supplicant.conf -Dnl80211 -f/var/log/wpa_supplicant.log & 306 #iw wlan0 cqm rssi -55 2 307 #wpa_supplicant -ddt -iwlan0 -c/etc/wpa_supplicant.conf -Dnl80211 -f/var/log/wpa.log & 308 wpa_supplicant -iwlan0 -c/etc/wpa_supplicant.conf -Dnl80211 & 309 #python /usr/share/peripherals-test-autom/dut.py -v & 310 fi 311 312 if [ "$stage_sedici" -ne "0" ]; then 313 echo manual_lock > /sys/power/wake_lock 314 echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 315 echo 1 > /sys/devices/system/cpu/cpu1/online 316 echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor 317 fi 318 319 if [ "$stage_trentadue" -ne "0" ]; then 320 321 if [ "$have_path_to_ini" -eq "0" ]; then 322 echo -e "Missing ini file parameter" 323 exit 1 324 fi 325 326 # 1. unload wl12xx kernel modules 327 echo -e "+++ Unload wl12xx driver" 328 run_it=`cat /proc/modules | grep "wl12xx_sdio"` 329 if [ "$run_it" != "" ]; then 330 rmmod wl12xx_sdio 331 fi 332 run_it=`cat /proc/modules | grep "wl12xx"` 333 if [ "$run_it" != "" ]; then 334 rmmod wl12xx 335 fi 336 337 # 2. create reference NVS file with default MAC 338 echo -e "+++ Create reference NVS with $path_to_ini $path_to_ini2" 339 ./calibrator set ref_nvs2 $path_to_ini $path_to_ini2 340 if [ "$?" != "0" ]; then 341 echo -e "Fail to tune channel" 342 exit 1 343 fi 344 345 # 3. Set AutoFEM detection to auto 346 echo -e "+++ Set Auto FEM detection to auto" 347 run_it=`./calibrator set nvs_autofem 1 ./new-nvs.bin` 348 349 # 4. copy NVS to proper place 350 echo -e "+++ Copy reference NVS file to $path_to_install" 351 run_it=`cp -f ./new-nvs.bin $path_to_install` 352 353 # 5. load wl12xx kernel modules 354 sh $0 -b 4 355 356 # 6. calibrate 357 echo -e "+++ Calibrate" 358 ./calibrator wlan0 plt power_mode on 359 if [ "$?" != "0" ]; then 360 echo -e "Fail to set power mode to on" 361 exit 1 362 fi 363 364 ./calibrator wlan0 plt tune_channel 0 7 365 if [ "$?" != "0" ]; then 366 echo -e "Fail to tune channel" 367 exit 1 368 fi 369 370 run_it=`cat $path_to_ini | grep "RxTraceInsertionLoss_5G"` 371 if [ "$run_it" != "" ]; then 372 ./calibrator wlan0 plt tx_bip 1 1 1 1 1 1 1 1 $path_to_install 373 if [ "$?" != "0" ]; then 374 echo -e "Fail to calibrate" 375 exit 1 376 fi 377 else 378 ./calibrator wlan0 plt tx_bip 1 0 0 0 0 0 0 0 $path_to_install 379 if [ "$?" != "0" ]; then 380 echo -e "Fail to calibrate" 381 exit 1 382 fi 383 fi 384 385 ./calibrator wlan0 plt power_mode off 386 if [ "$?" != "0" ]; then 387 echo -e "Fail to set power mode to off" 388 exit 1 389 fi 390 391 # 7. unload wl12xx kernel modules 392 rmmod wl12xx_sdio wl12xx 393 394 # 8. update NVS file with random and valid MAC address 395 echo -e "+++ Update NVS file with random valid MAC address" 396 ./calibrator set nvs_mac ./new-nvs.bin 397 if [ "$?" != "0" ]; then 398 echo -e "Fail to set NVS MAC address" 399 exit 1 400 fi 401 402 # 9. copy calibrated NVS file to proper place 403 echo -e "+++ Copy calibrated NVS file to $path_to_install" 404 run_it=`cp -f ./new-nvs.bin $path_to_install` 405 406 # 10. load wl12xx kernel modules 407 if [ ! -e /sys/kernel/debug/tracing ]; then 408 mount -t debugfs none /sys/kernel/debug/ 409 fi 410 sh $0 -b 4 411 412 echo -e "\n\tDear Customer, you are ready to use our calibrated device\n" 413 fi 414 415 # 416 # 1-command calibration 417 # parameters are INI file, path where to install NVS (default /lib/firmware) 418 # 419 420 if [ "$stage_sessanta_quattro" -ne "0" ]; then 421 422 if [ "$have_path_to_ini" -eq "0" ]; then 423 echo -e "Missing ini file parameter" 424 exit 1 425 fi 426 427 # 1. unload wl12xx kernel modules 428 echo -e "+++ Unload wl12xx driver" 429 run_it=`cat /proc/modules | grep "wl12xx_sdio"` 430 if [ "$run_it" != "" ]; then 431 rmmod wl12xx_sdio 432 fi 433 run_it=`cat /proc/modules | grep "wl12xx"` 434 if [ "$run_it" != "" ]; then 435 rmmod wl12xx 436 fi 437 438 # 2. create reference NVS file with default MAC 439 echo -e "+++ Create reference NVS with INI $path_to_ini" 440 ./calibrator set ref_nvs $path_to_ini 441 if [ "$?" != "0" ]; then 442 echo -e "Fail to tune channel" 443 exit 1 444 fi 445 446 # 3. copy NVS to proper place 447 echo -e "+++ Copy reference NVS file to $path_to_install" 448 run_it=`cp -f ./new-nvs.bin $path_to_install` 449 450 # 4. load wl12xx kernel modules 451 sh $0 -b 4 452 453 # 5. calibrate 454 echo -e "+++ Calibrate" 455 ./calibrator wlan0 plt power_mode on 456 if [ "$?" != "0" ]; then 457 echo -e "Fail to set power mode to on" 458 exit 1 459 fi 460 461 ./calibrator wlan0 plt tune_channel 0 7 462 if [ "$?" != "0" ]; then 463 echo -e "Fail to tune channel" 464 exit 1 465 fi 466 467 run_it=`cat $path_to_ini | grep "RxTraceInsertionLoss_5G"` 468 if [ "$run_it" != "" ]; then 469 ./calibrator wlan0 plt tx_bip 1 1 1 1 1 1 1 1 $path_to_install 470 if [ "$?" != "0" ]; then 471 echo -e "Fail to calibrate" 472 exit 1 473 fi 474 else 475 ./calibrator wlan0 plt tx_bip 1 0 0 0 0 0 0 0 $path_to_install 476 if [ "$?" != "0" ]; then 477 echo -e "Fail to calibrate" 478 exit 1 479 fi 480 fi 481 482 ./calibrator wlan0 plt power_mode off 483 if [ "$?" != "0" ]; then 484 echo -e "Fail to set power mode to off" 485 exit 1 486 fi 487 488 # 6. unload wl12xx kernel modules 489 rmmod wl12xx_sdio wl12xx 490 491 # 7. update NVS file with random and valid MAC address 492 echo -e "+++ Update NVS file with random valid MAC address" 493 ./calibrator set nvs_mac ./new-nvs.bin 494 if [ "$?" != "0" ]; then 495 echo -e "Fail to set NVS MAC address" 496 exit 1 497 fi 498 499 # 8. copy calibrated NVS file to proper place 500 echo -e "+++ Copy calibrated NVS file to $path_to_install" 501 run_it=`cp -f ./new-nvs.bin $path_to_install` 502 503 # 9. load wl12xx kernel modules 504 if [ ! -e /sys/kernel/debug/tracing ]; then 505 mount -t debugfs none /sys/kernel/debug/ 506 fi 507 sh $0 -b 4 508 509 echo -e "\n\tDear Customer, you are ready to use our calibrated device\n" 510 fi 511 512 if [ "$dbg_lvl" -eq "-1" ] && [ -e /sys/module/wl12xx/parameters/debug_level ]; then 513 dbg_lvl=`cat /sys/module/wl12xx/parameters/debug_level` 514 echo -e "\ndbg lvl: $dbg_lvl\n" 515 elif [ "$dbg_lvl" -ne "0" ] && [ -e /sys/module/wl12xx/parameters/debug_level ]; then 516 echo "$dbg_lvl" > /sys/module/wl12xx/parameters/debug_level 517 518 echo 'module cfg80211 +p' > /sys/kernel/debug/dynamic_debug/control 519 echo 'module mac80211 +p' > /sys/kernel/debug/dynamic_debug/control 520 echo 'module wl12xx +p' > /sys/kernel/debug/dynamic_debug/control 521 echo 'module wl12xx_sdio +p' > /sys/kernel/debug/dynamic_debug/control 522 fi 523 524 if [ "$set_ip_addr" -ne "0" ]; then 525 echo -e "Going to set IP $ip_addr" 526 ifconfig wlan0 $ip_addr up 527 fi 528 529 exit 0 530