summaryrefslogtreecommitdiffstats
path: root/src/tools/occtoolp9
blob: 837d74a5558c2b632c88cbb9c84f228e90c88ecb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
#!/bin/bash
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/tools/occtoolp9 $
#
# OpenPOWER OnChipController Project
#
# Contributors Listed Below - COPYRIGHT 2017,2018
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG

blue=""
red=""
green=""
bold=""
normal=""
if [ $TERM == "xterm-color" ] || [ $TERM == "xterm" ]; then
    blue="\033[34;1m";
    red="\033[31;1m";
    green="\033[32;1m";
    bold="\033[1m";
    normal="\033[0m";
fi
binfile="binary.bin"
inputfile=""
G_powerArch="p9";
cmd_sram_addr="fffbe000"
doorbell_addr="6d035"
rsp_sram_addr="fffbf000"
poll_version="20"
occ_cmd=""
occ_cmd_data=""
action=""
newFlags=""
let in_safe=0
let toolkit=0
guidList=()
guidListCount=0

temp_filename="/tmp/${USER}_occtoolp9.tmp";

interface="cronus"
if [ -z "$BMCIP" ]; then
    if [ -n "$BMC_IP_ADDRESS" ]; then
        BMCIP=$BMC_IP_ADDRESS
        interface="bmc"
    fi
else
    interface="bmc"
fi

sudo=""
if [ -e /usr/sbin/opal-prd ]; then
    if [ "$USER" != "root" ]; then
        sudo="sudo"
    fi
    interface="opal"
fi

function convertToBinary
{
    infile=$1
    outfile=$2
    hexStringBuffer=""

    if [ -n "$outfile" ]; then
        if [ $verbose -ne 0 ]; then
            echo "convertToBinary: Reading ${infile}..."
        fi
        let skipped_bytes=0
        while IFS= read -r line
        do
            if [ ${#line} -ge 2 ]; then
                if [[ "${line}" =~ "~[" ]]; then
                    # Strip off header data
                    #~[0x0000] 07000002 09801003 14010000 00000000    *................*
                    #echo "LINE : $line"
                    strippedLine=`echo $line | sed 's/.*~\[//'`
                    #echo "LINE2: $strippedLine"
                    # strip off offset and only keep hex data
                    strippedLine=`echo ${strippedLine:8:36} | sed 's#\s##g'`
                    #echo "LINE3: $strippedLine"
                    #strippedLine=`echo ${strippedLine:10:36} | sed 's#\s##g'`
                    if [ $skipped_bytes -eq 0 ]; then
                        # Skip response header
                        let rsp_length=0x${strippedLine:6:4}
                        #echo "Rsp Length: $rsp_length"
                        strippedLine="${strippedLine:10}";
                        let skipped_bytes=5
                    fi
                else
                    strippedLine=`echo $line | sed 's#\s##g'`
                fi
                #if [ $verbose -ne 0 ]; then
                #    echo "READ: $line / $strippedLine"
                #fi
                hexStringBuffer="${hexStringBuffer}$strippedLine"
            fi
        done < $infile

        if [ -e "$outfile" ]; then
            rm $outfile
        fi
        for ((i = 0; i < ${#hexStringBuffer}; i+=2)); do
            byte="${hexStringBuffer:$i:2}"
            echo -n -e "\x$byte" >> $outfile
        done
        if [ -e "$outfile" ]; then
            if [ $verbose -ne 0 ]; then
                echo "Converted $infile to binary: $outfile";
            fi
        fi
    else
        echo "ERROR: No output file name specified for convertToBinary"
    fi
} # end convertToBinary()

function usage
{
    echo "Usage: occtoolp9 <options> <command>"
    echo "       OCC Debug Tool (via opal-prd or CRONUS)"
    echo ""
    echo "       commands:"
    echo "           -h = help"
    echo "           -p = Send POLL command to the OCC"
    echo "           -X CC DDDDDD... = Send CC command to the OCC with specified cmd data (all data in hex)"
#    echo "              -X 53 0500000001LLLLTTTT = list first 50 OCC sensors (LLLL=Location,TTTT=Type)"
#    echo "              -X 53 0600003d = get sensor details for GUID 0x003d"
    echo "           -S type=0xTT,loc=0xLL = List specified sensors"
    echo "              Sensor Types: 0xFF=All, 0x1=Generic, 0x2=Current, 0x4=Voltage, 0x8=Temperature,"
    echo "                     0x10=Utilization, 0x20=Time, 0x40=Frequency, 0x80=Power, 0x200=Performance"
    echo "              Sensor Locations: 0xFF=All, 0x1=System, 0x2=Processor, 0x4=Partition, 0x8=Memory,"
    echo "                     0x10=VRM, 0x20=OCC 0x40=Core"
    echo "           -S guid=0xGGGG = Get sensor details for specified GUID"
    echo "           -SL = List all OCC sensors"
    echo "           -SL0 = List all OCC sensors (including sensors with 0 readings)"
    echo "           -trace  Collect OCC Trace hex trace data"
    echo "              -s stringFile = specify string file for parsing traces (CRONUS only)"
    echo "           -wof    Display WOF status"
    echo ""
    echo "         OPAL-PRD Only Commands:"
    echo "           -I = HTMGT info"
    echo "           -IF <newValue> = Read/Set HTMGT internalFlags"
    echo "           -ES = Attempt to Exit Safe mode"
    echo "           -W  = Get WOF reset reasons for ALL OCCs"
    echo ""
    echo "         CRONUS Only Commands:"
    echo "           -P = Send POLL command to the OCC and collect/purge any elog, if found"
    echo "           -CMDRSP = Dump OCC Command/Response buffers from SRAM"
    echo ""
    echo "       options:"
#    echo "           -b <BMC-ip-address> = send poll via IPMI/BMC"
#    echo "              address is optional if BMCIP is set"
    echo "           -o # = send command to OCC# (default 0)"
    echo "           -v = verbose (dump raw data)"
#    echo "           -f <filename> = parse response from specified filename"
#    echo "           -A = force IPMI userid of admin (vs ADMIN)"
#    echo "           -SM = use ADMIN/ADMIN (SuperMicro default)"
#    echo "           -pw BMC_PW = specified BMC password"
    echo "           -pt = parse OCC response w/o seq/cmd/rsp/len/csum (from opal-prd passthru or syslog)"
#    echo "           -oldbmc = send IPMI cmds without OCC instance number (prior to Aug 2015)"
    echo "           -nocolor = skip highlighting"
    echo "           -ch # = which cronus channel to use (default is 3)"
    echo ""
#    echo "       TODO:"
#    echo "           -OF OCC FFDC"
    exit 0
}

bmc="";
let verbose=0
quiet="-quiet"
let purge=0
# Default OCC/Processor
let occ=0
let node=0
let bmcFound=0
number=$RANDOM
let "number %= 126"
let number=$number+1
sequence=$(printf "%02x" $number)
let seqMismatch=0
let channel=3
let only_non_zero_sensors=1
let skip_header=0
let sensor_summary=0
let use_gpe_string=1
string_file=""

if [ -n "$bmcId" ]; then
    bmcId="$bmcId"
elif [ -n "$adminId" ]; then
    bmcId="$adminId"
else
    bmcId="ADMIN"
fi

if [ -n "$bmcPw" ]; then
    bmcPw="$bmcPw"
else
    bmcPw="admin"
fi
let sendOccInstance=1
let sensor_type=0xFFFF # all types
let sensor_loc=0xFFFF  # all locations
let sensor_guid=0xFFFF

let passThru=0
while [ -n "$(echo $1 | grep '-')" ]; do
    case $1 in

        #### COMMANDS:

    -h ) usage; exit 0;;

    -p ) occ_cmd="00"
         occ_cmd_data=$poll_version
         ;;

    -s )
        shift
        if [ -s "$1" ]; then
            string_file="$1"
        else
            echo "ERROR: -s option requires occStringFile location"
            exit 16
        fi
        ;;

    -S )
        shift
        if [[ "$1" =~ "type=" ]] || [[ "$1" =~ "loc=" ]]; then
            action="SensorList"
            if [[ "$1" =~ "type=" ]]; then
                let sensor_type=${1#*type=};
            fi
            if [[ "$1" =~ "loc=" ]]; then
                let sensor_loc=${1##*loc=};
            fi
            # If user specified type/loc then list all sensors
            let only_non_zero_sensors=0
        elif [[ "$1" =~ "guid=" ]]; then
            action="SensorDump"
            let sensor_guid=${1#*guid=};
        elif [[ "$1" =~ "GUID=" ]]; then
            action="SensorDump"
            let sensor_summary=1
            let skip_header=1
            let sensor_guid=${1#*guid=};
        else
            echo "ERROR: -S option requires Type/Location (-S type=0xFF,loc=0xFF)"
            echo "  Sensor Types: 0xFF=All, 0x1=Generic, 0x2=Current, 0x4=Voltage, 0x8=Temperature,"
            echo "         0x10=Utilization, 0x20=Time, 0x40=Frequency, 0x80=Power, 0x200=Performance"
            echo "  Sensor Locations: 0xFF=All, 0x1=System, 0x2=Processor, 0x4=Partition, 0x8=Memory,"
            echo "         0x10=VRM, 0x20=OCC 0x40=Core"
            exit 13
        fi
        ;;

    -SL )
        action="SensorList"
        ;;

    -SL0 )
        action="SensorList"
        let only_non_zero_sensors=0
        ;;

    -tk )
        let toolkit=1
        let channel=2
        ;;

    -trace )
        action="trace"
        ;;

    -TRACE )
        let use_gpe_string=0
        action="trace"
        ;;

    -wof )
        occ_cmd="40"
        occ_cmd_data="01" # WOF Data Structure
        ;;

    -X )
        if [ -n "$2" ] && [ "${2:0:1}" != "-" ] && ( [ ${#2} -eq 2 ] || [ ${#2} -eq 4 ] ); then
            shift
            if [ "${1:0:2}" == "0x" ]; then
                occ_cmd="${1:2:2}"
            else
                occ_cmd="$1"
            fi
            if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
                # Command Data
                shift
                let odd_length="${#1} & 1"
                if [ $odd_length -eq 0 ]; then
                    if [ "${1:0:2}" == "0x" ]; then
                        occ_cmd_data="${1:2}"
                    else
                        occ_cmd_data="$1"
                    fi
                else
                    echo -e "${red}ERROR: OCC command data must be even number of HEX digits${normal}"
                    exit 12
                fi
            fi
         else
             echo -e "${red}ERROR: -X requires 2 byte command (in HEX)${normal}"
             exit 12
         fi
         ;;

        #### OPAL-PRD ONLY COMMANDS/OPTIONS:

    -ES )
        action="ExitSafe"
        ;;

    -I )
        action="TMGTInfo"
        ;;

    -W )
        action="WOFRR"
        ;;

    -IF )
        action="TMGTFlags"
        if [ -n "$2" ]; then
            let newFlags=$2
        fi
        ;;

        #### CRONUS ONLY COMMANDS/OPTIONS:

    -ch )
        if [ -n "$2" ]; then
            let channel=$2
            shift;
        else
            echo -e "${red}ERROR: -ch requires channel number${normal}"
            exit 13
        fi
        ;;

    -CMDRSP )
        if [ "$interface" == "cronus" ]; then
            action="CmdRspBuffer"
        else
            echo "ERROR: -CMDRSP only supported via CRONUS"
            exit 1
        fi
        ;;

    -P ) occ_cmd="00"
        occ_cmd_data=$poll_version
        let purge=1
        ;;

        ### OPTIONS:

    -A ) bmcId="admin"
        ;;

    -b )
        if [ -z "$2" ] || [ "`echo $2 | cut -c1`" == "-" ]; then
            if [ "$BMCIP" != "" ]; then
                bmc=$BMCIP
                interface="bmc"
            else
                echo -e "${red}ERROR: -b requires BMCIP${normal}"
                exit 12
            fi
        else
            bmc=$2
            interface="bmc"
            shift
        fi
        if [ $verbose -ne 0 ]; then
            echo "BMC: $bmc";
        fi
        ;;

    -f )
        if [ -n "$2" ] && [ -e "$2" ]; then
            inputfile="$2"
            shift
        else
            echo -e "${red}ERROR: -f requires a input filename${normal}"
            exit -2;
        fi;;

    -nocolor ) blue=""; red=""; green=""; bold=""; normal=""
        ;;

    -o )
        if [ -z "$2" ] || [ "`echo $2 | cut -c1`" == "-" ]; then
            echo -e "${red}ERROR: -o requires OCC instance number${normal}"
            exit 13
        else
            let occ=$2
            shift
        fi;;

    -oldbmc ) let sendOccInstance=0
        ;;

    -pt ) let passThru=1
        ;;

    -pw )
        if [ -n "$2" ]; then
            bmcPw="$2"
            shift
        else
            echo -e "${red}ERROR: -pw requires BMC password${normal}"
            exit 13
        fi
        ;;

    -SM ) bmcPw="ADMIN"
        ;;

    -v ) let verbose=1; quiet=""
        ;;

    * ) echo -e "${red}ERROR: unknown option $1${normal}"; exit 1
        ;;

    esac
    shift
done

#echo "OCC${occ}, BMC: ${bmc}, purge=$purge, verbose=$verbose"



# Force Call Home: ipmitool -H 9.3.29.129 -I lanplus -U admin -P admin raw 0x3a 0x0d 0x40 0x24
# For Error w/Reset (pmc failure): putscom pu 1010842 1000000000180000 -p0

function sendOccCmdBmc
{
    let bmcOccInstance=$occ+1
    outName="/tmp/occ_cmd.txt"

    if [ -z "$inputfile" ]; then

        if [ -e "${outName}" ]; then
            if [ $verbose -ne 0 ]; then
                echo "--> removing ${outName}"
            fi
            rm ${outName}
        fi
        if [ $sendOccInstance -ne 0 ]; then
            occInstance=$(printf "0x%02x" $bmcOccInstance)
        else
            occInstance=""
        fi
        #if [ $verbose -ne 0 ]; then
        echo -e "${bold}==> ipmitool -H $bmc -I lanplus -U $bmcId -P $bmcPw raw 0x3a 0x0d ${occInstance} 0x00 0x10${normal}"
        #fi
        ipmitool -H $bmc -I lanplus -U $bmcId -P $bmcPw raw 0x3a 0x0d ${occInstance} 0x00 0x10 > ${outName}
        let rc=$?

    else
        outName="$inputfile"
        echo "grep -q 'opal-prd: HBRT: HTMGT:' $inputfile"
        grep -q 'opal-prd: HBRT: HTMGT:' $inputfile
        if [ $? -eq 0 ]; then
            echo "Converting $inputfile"
            # Convert opal-prd poll rsp to "XX XX XX XX" format
            cat $inputfile  | sed 's/.*HBRT: HTMGT:.*\] //' | sed 's/    .*//' | sed 's/ //g' | sed 's/\(..\)/\1 /g' > ${inputfile}.filtered
        else
            cat $inputfile | sed 's/ //g' | sed 's/\(..\)/\1 /g' > ${inputfile}.filtered
        fi
        if [ -s "${inputfile}.filtered" ]; then
            outName="${inputfile}.filtered"
        fi
        echo -e "${bold}==> Reading data from ${outName}${normal}"
        let rc=0;
    fi

    if [ $verbose -ne 0 ]; then
        echo "--> cat ${outName}"
        cat ${outName}
        #let occRspLength=`wc -w ${outName} | awk '{print $1}'`
        #echo "<-- $occRspLength bytes"
    fi

    if [ $rc -ne 0 ]; then
        echo -e "${red}ERROR: failed sending POLL to OCC via IPMI/BMC (rc=$rc)${normal}"
        exit 8
    fi
    if [ -e "${outName}" ]; then
        options=""
        if [ $verbose -eq 0 ]; then
            options="-q"
        else
            echo -e "${bold}==> /afs/rch/usr2/cjcain/bin/asm2bin.new -s:1 $options ${outName}${normal}"
        fi
        /afs/rch/usr2/cjcain/bin/asm2bin.new -s:1 $options  ${outName}
        if [ -e "${outName}.bin" ]; then
            binfile="${outName}.bin"
        else
            echo -e "${red}ERROR: ${outName}.bin not found...${normal}"
            exit 7
        fi
    else
        echo -e "${red}ERROR: ${outName} not found...${normal}"
        exit 9
    fi
} # end sendOccCmdBmc()

function sendOccCmd
{
    cmd=$1
    data=$2
    let dataLength=${#data}/2
    dataLenStr=$(printf "%04x" $dataLength)
    # Checksum Calculation
    let csum=0x"$sequence"+0x"$cmd";
    let csum="$csum + ( $dataLength >> 8 ) + ( $dataLength & 0xFF )"
    let index=0
    while [ $index -lt ${#data} ]; do
        echo "adding $csum+${data:$index:2}"
        let csum=$csum+0x${data:$index:2}
        let index=$index+2
    done
    csumStr=$(printf "%04x" $csum)

    # First, store the command in command buffer in SRAM
    if [ $verbose -ne 0 ]; then
        echo -e "${bold}==> putsram $cmd_sram_addr ${sequence}${cmd}${dataLenStr}${data}${csumStr} -p${occ} -ch $channel $quiet  (write $cmd command to OCC SRAM)${normal}"
    fi
    putsram $cmd_sram_addr ${sequence}${cmd}${dataLenStr}${data}${csumStr} -p${occ} -ch $channel $quiet
    let rc=$?
    if [ $rc -ne 0 ]; then
        echo -e "${red}ERROR: failed writing $cmd command to OCC SRAM (rc=$rc)${normal}"
        exit 1;
    fi

    # Second, send a doorbell to OCC
    if [ $verbose -ne 0 ]; then
        echo -e "${bold}==> putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet  (send doorbell to OCC)${normal}"
    fi
    putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet
    let rc=$?
    if [ $rc -ne 0 ]; then
        echo -e "${red}ERROR: failed sendingn doorbell to OCC (rc=$rc)${normal}"
    fi

    # Third, collect response from response buffer in SRAM
    if [ $verbose -ne 0 ]; then
        echo -e "${bold}==> getsram $rsp_sram_addr 4096 -p${occ} -ch $channel $quiet  (read $cmd response from SRAM)${normal}"
    fi
    if [ -e "${binfile}" ]; then
        rm ${binfile}
    fi
    getsram $rsp_sram_addr 4096 -p${occ} -ch $channel $quiet -fb ${binfile}
    let rc=$?
    if [ $rc -ne 0 ]; then
        echo -e "${red}ERROR: failed reading $cmd response from SRAM (rc=$rc)${normal}"
        exit 2;
    fi

    ### Response Header
    let offset=0
    let rspSeq=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
    let expSeq=0x"${sequence}"
    if [ $rspSeq -eq $expSeq ]; then
        printf "Rsp Sequence: 0x%02X\n" $rspSeq;
    else
        echo -e "${red}"
        printf "Rsp Sequence: 0x%02X  MISMATCH - expected 0x%02X\n" $rspSeq $sequence;
        echo -e "${normal}"
        let seqMismatch=1
    fi
    let offset=$offset+1
    let rspCmd=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
    printf "     Command: 0x%02X\n" $rspCmd;
    let offset=$offset+1
    let rspStatus=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
    printf "      Status: 0x%02X\n" $rspStatus;
    let offset=$offset+1
    let rspLength=0x`hexdump -s $offset -n 2 -e '2/1 "%02X"' ${binfile}`
    printf "      Length: 0x%04X\n" $rspLength;
    let offset=$offset+2
    echo   "        Data:"
    hexdump -C -s $offset ${binfile}

} # end sendOccCmd()


function send_occ_cmd
{
    #if [ -z "$bmc" ] && [ -z "$inputfile" ] && [ -n "$occ_cmd" ]; then
    # Clean up rsp file if still exists
    if [ -e "${binfile}" ]; then
        rm -f ${binfile}
    fi

    if [ "$interface" == "cronus" ]; then
        echo -e "${blue}Sending 0x$occ_cmd command to OCC${occ} (via cronus)...${normal}"
        # First, store the command in command buffer in SRAM
        let cmd_data_length=${#occ_cmd_data}/2
        let csum=0x"$sequence"+0x$occ_cmd+$cmd_data_length; # seq# + cmd + length
        #TODO: Checksums for lengths > 255 bytes!!
        if [ $cmd_data_length -gt 0 ]; then
            for ((i = 0; i < ${#occ_cmd_data}; i+=2)); do
                let byte=0x${occ_cmd_data:$i:2}
                let csum=$csum+$byte
            done
        fi
        cmdString=`printf "%s%s%04X${occ_cmd_data}%04X" $sequence $occ_cmd $cmd_data_length $csum`
        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> putsram $cmd_sram_addr ${cmdString} -p${occ} -ch $channel $quiet  (write $occ_cmd command to OCC SRAM)${normal}"
        fi
        putsram $cmd_sram_addr ${cmdString} -p${occ} -ch $channel $quiet
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed writing $occ_cmd command to OCC SRAM (rc=$rc)${normal}"

            echo -e "${bold}==> getsram $rsp_sram_addr 128 -all -ch $channel $quiet  (read OCC rsp buffer from SRAM)${normal}"
            getsram $rsp_sram_addr -ch 3 128 -all

            exit 1;
        fi

        # Second, send a doorbell to OCC
        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet  (send doorbell to OCC)${normal}"
        fi
        putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed sending doorbell to OCC (rc=$rc)${normal}"
        fi

        # Third, collect response from response buffer in SRAa
        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> getsram $rsp_sram_addr 1024 -p${occ} -ch $channel $quiet  (read POLL response from SRAM)${normal}"
        fi
        getsram $rsp_sram_addr 1024 -p${occ} -ch $channel $quiet -fb ${binfile}
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed reading POLL response from SRAM (rc=$rc)${normal}"
            exit 2;
        fi
    elif [ "$interface" == "opal" ]; then
        if [ $sensor_summary -eq 0 ]; then
            echo -e "${blue}Sending 0x$occ_cmd command to OCC${occ} (via opal-prd)...${normal}"
        fi
        # First, store the command in command buffer in SRAM
        let cmd_data_length=${#occ_cmd_data}/2
        let csum=0x"$sequence"+0x$occ_cmd+$cmd_data_length; # seq# + cmd + length

        opal_occ_cmd_data=`printf "0x%02X 0x%s" $occ $occ_cmd`
        if [ $cmd_data_length -gt 0 ]; then
            for ((i = 0; i < ${#occ_cmd_data}; i+=2)); do
                let byte=0x${occ_cmd_data:$i:2}
                opal_occ_cmd_data=`printf "%s 0x%02X" "$opal_occ_cmd_data" $byte`
            done
        fi

        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> $sudo opal-prd --expert-mode htmgt-passthru 0x03 $opal_occ_cmd_data${normal}"
        fi
        rsp_file="/tmp/occtoolp9_rsp.txt"
        $sudo opal-prd --expert-mode htmgt-passthru 0x03 $opal_occ_cmd_data | sed 's/\s//g' > $rsp_file
        # get status of first cmd in piped cmdline
        let rc=${PIPESTATUS[0]}
        #let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: opal-prd passthrough failed sending $occ_cmd command to OCC$occ (rc=$rc)${normal}"
            if [ -e /var/log/syslog ]; then
                echo "==> tail /var/log/syslog"
                $sudo tail /var/log/syslog
            fi
            exit 30
        else
            #echo "Parsing poll data:"
            #./occ_poll -pt -f /tmp/htmgt.bin
            if [ $verbose -ne 0 ]; then
                echo "Converting $rsp_file to $binfile..."
            fi
            convertToBinary $rsp_file $binfile
        fi
    else
        if [ -z "$inputfile" ]; then
            echo -e "${blue}Polling OCC${occ} (via BMC)...${normal}"
            sendOccCmdBmc
        fi
    fi
} # end send_occ_cmd()


function parse_rsp_poll
{
    # Response Data
    let rstatus="0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`"
    flags="";
    let bitset="$rstatus & 0x80";
    if [ $bitset -ne 0 ]; then flags=" Master"; fi
    let bitset="$rstatus & 0x40";
    if [ $bitset -ne 0 ]; then flags="$flags CollectFIR"; fi
    let bitset="$rstatus & 0x10";
    if [ $bitset -ne 0 ]; then flags="$flags OCCPmcrOwner"; fi
    let bitset="$rstatus & 0x08";
    if [ $bitset -ne 0 ]; then flags="$flags SIMICS"; fi
    let bitset="$rstatus & 0x02";
    if [ $bitset -ne 0 ]; then flags="$flags ObsReady"; fi
    let bitset="$rstatus & 0x01";
    if [ $bitset -ne 0 ]; then flags="$flags ActReady"; fi
    if [ -n "$flags" ]; then flags="($flags)"; fi
    printf "       Status: 0x%02X $flags\n" $rstatus
    let offset=$offset+1
    let xstatus="0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`"
    flags=""
    let bitset="$xstatus & 0x80";
    if [ $bitset -ne 0 ]; then flags=" DVFS-OT"; fi
    let bitset="$xstatus & 0x40";
    if [ $bitset -ne 0 ]; then flags="$flags DVFS-power"; fi
    let bitset="$xstatus & 0x20";
    if [ $bitset -ne 0 ]; then flags="$flags MemThrottle-OT"; fi
    let bitset="$xstatus & 0x10";
    if [ $bitset -ne 0 ]; then flags="$flags QckPwrDrop"; fi
    let bitset="$xstatus & 0x08";
    if [ $bitset -ne 0 ]; then flags="$flags DVFS-Vdd-OT"; fi
    if [ -n "$flags" ]; then
        flags="($flags )";
        echo -en "$bold";
    fi
    printf "    ExtStatus: 0x%02X $flags\n" $xstatus
    echo -en "$normal";
    let offset=$offset+1
    hexdump -s $offset -n 1 -e '"         OCCs: 0x%02X\n"' ${binfile}
    let offset=$offset+1
    hexdump -s $offset -n 1 -e '"      CfgNeed: 0x%02X\n"' ${binfile}
    let offset=$offset+1
    let state="0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`"
    flags="UNKNOWN";
    if [ $state -eq 1 ]; then flags="STANDBY";
    elif [ $state -eq 2 ]; then flags="OBSERVATION";
    elif [ $state -eq 3 ]; then flags="ACTIVE";
    elif [ $state -eq 4 ]; then
        flags="SAFE";
        echo -en "$red";
    elif [ $state -eq 5 ]; then flags="CHARACTERIZATION";
    fi
    printf "        State: 0x%02X ($flags)\n" $state
    echo -en "$normal";
    let offset=$offset+1
    hexdump -s $offset -n 2 -e '"     reserved: 0x" 2/1 "%02X" "\n"' ${binfile}
    let offset=$offset+2
    let elogId=0x`hexdump -s $offset -n 1 -e '1/1 "%02X"' ${binfile}`
    if [ $elogId -ne 0 ]; then
        echo -en "$red";
    fi
    printf "       ElogID: 0x%02X\n" $elogId
    let offset=$offset+1
    let elogAddr="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
    printf "     ElogAddr: 0x%08X\n" $elogAddr
    let offset=$offset+4
    let elogLen="0x`hexdump -s $offset -n 2 -e '2/1 "%02X"' ${binfile}`"
    printf "     Elog Len: 0x%04X\n" $elogLen
    let offset=$offset+2
    echo -en "$normal";
    hexdump -s $offset -n 1 -e '"  Elog Source: 0x%02X\n"' ${binfile}
    let offset=$offset+1
    hexdump -s $offset -n 1 -e '"   GPU config: 0x%02X\n"' ${binfile}
    let offset=$offset+1
    if [ $occRspLength -gt 17 ]; then
        hexdump -s $offset -n 16 -e '"   Code Level: " 16 "%_p" "\n"' ${binfile}
        let offset=$offset+16
        hexdump -s $offset -n 6 -e '"   Sensor Tag: " 6 "%_p" "\n"' ${binfile}
        let offset=$offset+6

        if [ $occRspLength -gt 39 ]; then
            #let offset=43
            let numSensorBlocks="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
            echo "Sensor Blocks: $numSensorBlocks"
            let offset=$offset+1
            let sensorVers="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
            echo "  Sensor Vers: $sensorVers"
            let offset=$offset+1

            if [ $verbose -ne 0 ]; then
                echo "Raw Sensor Data:"
                hexdump -C -s $offset ${binfile}
            fi

            while [ $numSensorBlocks -gt 0 ]; do
                sensor="`hexdump -s $offset -n 4 -e '4/1 "%_u"' ${binfile}`"
                let offset=$offset+5
                let sensorFormat="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
                let offset=$offset+1
                let sensorLength="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
                let offset=$offset+1
                let numSensors="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
                let offset=$offset+1

                # TEMP: degrees C, FREQ: MHz, POWR: 4Byte tag, 4Byte accumulator, 2Byte current reading
                echo -e  "       ${bold}Sensor: $sensor - format:$sensorFormat / $numSensors sensors ($sensorLength bytes/sensor)${normal}"
                indent="       ";

                if [ $G_powerArch == "p9" ]; then
                    if [ "$sensor" == "TEMP" ]; then
                        echo "$indent  SSSSSSSS FF TT  (SSSS = Sensor ID, FF is FRU type, TT is temp in C)";
                    elif [ "$sensor" == "FREQ" ]; then
                        echo "$indent  SSSSSSSS FFFF  (SSSS = Sensor ID, FFFF is freq in MHz)";
                    elif [ "$sensor" == "POWR" ]; then
                        if [ $sensorFormat -ne $((0xA0)) ]; then
                            echo "$indent  SSSSSSSS FF CH rrrr TTTTTTTT AAAAAAAAAAAAAAAA CCCC  (SS=Sensor ID, FF=Function ID,"
                            echo "               CH=APSS Channel, TT=Update Tag, AA=Accumulator, CC=current reading (W)"
                        else
                            echo "$indent          SSSSSSSS UUUU CCCC TTTTTTTT AAAAAAAAAAAAAAAA  (SS=Sensor ID,"
                            echo "                UU=Update Time (us), CC=current reading (W), TT=Update Tag, AA=Accumulator)"
                        fi
                    elif [ "$sensor" == "EXTN" ]; then
                        echo "$indent  NNNNNNNN FF 00 DDDDDDDDDDDD (NNNN = Name/Sensor ID, FF is flags, DDDD is value)";
                    fi
                else
                    #p8
                    if [ "$sensor" == "TEMP" ]; then
                        echo "$indent  SSSS TTTT  (SSSS = Sensor ID, TTTT is temp in C)";
                    elif [ "$sensor" == "FREQ" ]; then
                        echo "$indent  SSSS FFFF  (SSSS = Sensor ID, FFFF is freq in MHz)";
                    elif [ "$sensor" == "POWR" ]; then
                        echo "$indent  SSSS TTTTTTTT AAAAAAAA CCCC  (SS = Sensor ID, TT = Update Tag";
                        echo "                                AA = Accumulator, CC = current reading in Watts)";
                    fi
                fi
                while [ $numSensors -gt 0 ]; do
                    if [ $G_powerArch == "p9" ]; then
                        #hexdump -s $offset -n $sensorLength -e '"  " 16/1 "%02X" "\n"' ${binfile}
                        if [ "$sensor" == "TEMP" ]; then
                            #hexdump -s $offset -n $sensorLength -e '"=0x" 2/1 "%02X" " "1/2 "%d" "\n"' ${binfile}
                            #hexdump -s $offset -n $sensorLength -e '"         " 4/1 "%02X" " " 1/1 "%02X" " " 1/1 "%02X""\n"' ${binfile}
                            for ((i = 0; i < $sensorLength; i+=6)); do
                                let index=$offset+$i
                                sensor_id=`hexdump -s $index -n 4 -e '4/1 "%02X"' ${binfile}`;
                                let index+=4
                                let fru_type=0x`hexdump -s $index -n 1 -e '1/1 "%02X"' ${binfile}`;
                                get_fru_string $fru_type
                                let index+=1
                                let value=0x`hexdump -s $index -n 1 -e '1/1 "%02X"' ${binfile}`;
                                printf "         $sensor_id %02X %02X  " $fru_type $value;
                                if [ $fru_type -eq 3 ]; then # vrm ot
                                    if [ $value -eq 0 ]; then
                                        printf "(VRM not over-temperature)\n" $fru_type $value;
                                    else
                                        printf "(VRM Over-Temperature)\n" $fru_type $value;
                                    fi
                                else
                                    if [ $value -eq 0 ]; then
                                        printf "(N/A %s)\n" $fru_string;
                                    elif [ $value -ne $((0xFF)) ]; then
                                        printf "(%2dC %s)\n" $value $fru_string;
                                    else
                                        printf "(ERROR)\n" $fru_type $value;
                                    fi
                                fi
                            done
                        elif [ "$sensor" == "FREQ" ]; then
                            #hexdump -s $offset -n $sensorLength -e '"         " 4/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
                            for ((i = 0; i < $sensorLength; i+=6)); do
                                let index=$offset+$i
                                sensor_id=`hexdump -s $index -n 4 -e '4/1 "%02X"' ${binfile}`;
                                let index+=4
                                let value=0x`hexdump -s $index -n 2 -e '2/1 "%02X"' ${binfile}`;
                                printf "         $sensor_id %04X" $value;
                                if [ $value -ne 0 ]; then
                                    printf "  (%dMHz)\n" $value;
                                else
                                    printf "\n";
                                fi
                            done
                        elif [ "$sensor" == "POWR" ]; then
                            if [ $sensorFormat -ne $((0xA0)) ]; then
                                #hexdump -s $offset -n $sensorLength -e '"         " 4/1 "%02X" " " 1/1 "%02X" " " 1/1 "%02X" " " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
                                pwr="`hexdump -s $offset -n 22 -e '4/1 "%02X" " " 1/1 "%02X" " " 1/1 "%02X" " " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " " 2/1 "%02X"' ${binfile}`"
                                let func=0x${pwr:9:2}
                                get_function_id $func
                                printf "         $pwr    $funcid_name\n";
                            else
                                # APSS-less
                                let reading_offset=$offset+6
                                let power="0x`hexdump -s $reading_offset -n 2 -e '2/1 "%02X"' ${binfile}`";
                                hexdump -s $offset -n 20       -e '"         System: " 4/1 "%02X" " " 2/1 "%02X" " " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " ('$power' W)\n"' ${binfile}
                                let power_offset=$offset+20
                                let reading_offset=$power_offset+6
                                let power="0x`hexdump -s $reading_offset -n 2 -e '2/1 "%02X"' ${binfile}`";
                                hexdump -s $power_offset -n 20 -e '"      Processor: " 4/1 "%02X" " " 2/1 "%02X" " " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " ('$power' W)\n"' ${binfile}
                                let power_offset=$power_offset+20
                                let power="0x`hexdump -s $power_offset -n 2 -e '2/1 "%02X"' ${binfile}`";
                                hexdump -s $power_offset -n 14 -e '"            Vdd:               " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " ('$power' W)\n"' ${binfile}
                                let power_offset=$power_offset+14
                                let power="0x`hexdump -s $power_offset -n 2 -e '2/1 "%02X"' ${binfile}`";
                                hexdump -s $power_offset -n 14 -e '"            Vdn:               " 2/1 "%02X" " " 4/1 "%02X" " " 8/1 "%02X" " ('$power' W)\n"' ${binfile}
                            fi
                        elif [ "$sensor" == "CAPS" ]; then
                            let capoffset=$offset
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent  Current Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent      Current Power: %6d Watts (output power)\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent        N Power Cap: %6d Watts (cap without redundant power)\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent      Max Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent Hard Min Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            if [ $sensorFormat -gt 2 ]; then
                                printf "$indent Soft Min Power Cap: %6d Watts\n" $pcap;
                                let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                                let capoffset+=2
                            fi
                            printf "$indent     User Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 1 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=1
                            printf "$indent User Power Limit Source: %d\n" $pcap;
                        elif [ "$sensor" == "EXTN" ]; then
                            sensor_id=`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`;
                            let flag_offset=$offset+4
                            let flags="0x`hexdump -s $flag_offset -n 1 -e '"%02X"' ${binfile}`";
                            let is_sensor="$flags & 0x80";
                            if [ $is_sensor -eq 0 ]; then
                                # Dump name as ASCII
                                if [ $sensor_id == "45525248" ]; then # ERRH (error history)
                                    #hexdump -s $offset -n $sensorLength -e '"           " 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 2/1 "%02X" " " 2/1 "%02X" " " 2/1 "%02X""\n"' ${binfile}
                                    hist_data=`hexdump -s $offset -n $sensorLength -e ' 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}`
                                    let hist_id=0x${hist_data:13:2}
                                    let hist_count=0x${hist_data:15:2}
                                    get_history_name $hist_id
                                    history_desc="${hist_name}:${hist_count}"
                                    let hist_id=0x${hist_data:17:2}
                                    if [ $hist_id -gt 0 ]; then
                                        let hist_count=0x${hist_data:19:2}
                                        get_history_name $hist_id
                                        history_desc="$history_desc, ${hist_name}:${hist_count}"
                                        let hist_id=0x${hist_data:21:2}
                                        if [ $hist_id -gt 0 ]; then
                                            let hist_count=0x${hist_data:23:2}
                                            get_history_name $hist_id
                                            history_desc="$history_desc, ${hist_name}:${hist_count}"
                                        fi
                                    fi
                                    printf "           $hist_data    $history_desc\n";
                                    #printf "         $pwr    $funcid_name\n";
                                elif [ $sensor_id == "464D494E" ] || [ $sensor_id == "464E4F4D" ] || [ $sensor_id == "46540000" ] || [ $sensor_id == "46555400" ]; then # FMIN,FNOM,FT,FUT
                                    freq_data=`hexdump -s $offset -n $sensorLength -e ' 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}`
                                    let freq_pstate=0x${freq_data:13:2}
                                    let freq_value=0x${freq_data:15:4}
                                    if [ $freq_value != 0 ]; then
                                        printf "           $freq_data    pSstate: %3d / %d MHz\n" $freq_pstate $freq_value;
                                    else
                                        printf "           $freq_data    N/A\n";
                                    fi
                                elif [ $sensor_id == "434C4950" ]; then # CLIP
                                    freq_data=`hexdump -s $offset -n $sensorLength -e ' 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}`
                                    let freq_pstate=0x${freq_data:13:2}
                                    comment=""
                                    if [ $freq_pstate -eq 0 ]; then
                                        comment=" OCC is NOT clipping the pstate"
                                        hexdump -s $offset -n $sensorLength -e '"           " 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""    OCC is NOT clipping the pstate\n"' ${binfile}
                                    else
                                        hexdump -s $offset -n $sensorLength -e '"           " 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}
                                    fi
                                else
                                    hexdump -s $offset -n $sensorLength -e '"           " 4/1 "%_p" "   " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}
                                fi
                            else
                                # Dump sensor number in hex
                                hexdump -s $offset -n $sensorLength -e '"         " 4/1 "%02X" " " 1/1 "%02X" " " 1/1 "%02X" " " 6/1 "%02X""\n"' ${binfile}
                            fi
                        else
                            echo -e "${red}ERROR: Unknown sensor eye catcher: $sensor${normal}";
                        fi
                    else
                        #p8
                        #hexdump -s $offset -n $sensorLength -e '"  " 16/1 "%02X" "\n"' ${binfile}
                        if [ "$sensor" == "TEMP" ]; then
                            hexdump -s $offset -n $sensorLength -e '"         " 2/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
                            #hexdump -s $offset -n $sensorLength -e '"=0x" 2/1 "%02X" " "1/2 "%d" "\n"' ${binfile}
                        elif [ "$sensor" == "FREQ" ]; then
                            hexdump -s $offset -n $sensorLength -e '"         " 2/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
                        elif [ "$sensor" == "POWR" ]; then
                            hexdump -s $offset -n $sensorLength -e '"         " 2/1 "%02X" " " 4/1 "%02X" " " 4/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
                        elif [ "$sensor" == "CAPS" ]; then
                            let capoffset=$offset
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent  Current Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent      Current Power: %6d Watts (output power)\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent        N Power Cap: %6d Watts (cap without redundant power)\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent      Max Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent      Min Power Cap: %6d Watts\n" $pcap;
                            let pcap="0x`hexdump -s $capoffset -n 2 -e '4/1 "%02X"' ${binfile}`";
                            let capoffset+=2
                            printf "$indent     User Power Cap: %6d Watts\n" $pcap;
                        else
                            echo -e "${red}ERROR: Unknown sensor eye catcher: $sensor${normal}";
                        fi
                    fi
                    let offset=$offset+$sensorLength
                    let numSensors=$numSensors-1
                done
                let numSensorBlocks=$numSensorBlocks-1
            done # end sensors
        else
            echo "...rsp truncated (only read $occRspLength bytes)"
        fi
    else
        echo "...rsp truncated (only read $occRspLength bytes)"
    fi
} # end parse_rsp_poll()


# Determine name/description associated with APSS Function IDs
function get_function_id
{
    let funcid=$1
    case $funcid in
           1 ) funcid_name="Mem Proc 0" ;;
           2 ) funcid_name="Mem Proc 1" ;;
           3 ) funcid_name="Mem Proc 2" ;;
           4 ) funcid_name="Mem Proc 3" ;;
           5 ) funcid_name="Proc 0" ;;
           6 ) funcid_name="Proc 1" ;;
           7 ) funcid_name="Proc 2" ;;
           8 ) funcid_name="Proc 3" ;;
           9 ) funcid_name="Proc 0 cache/io/pcie" ;;
          10 ) funcid_name="Proc 1 cache/io/pcie" ;;
          11 ) funcid_name="Proc 2 cache/io/pcie" ;;
          12 ) funcid_name="Proc 3 cache/io/pcie" ;;
          13 ) funcid_name="IO A" ;;
          14 ) funcid_name="IO B" ;;
          15 ) funcid_name="IO C" ;;
          16 ) funcid_name="Fans A" ;;
          17 ) funcid_name="Fans B" ;;
          18 ) funcid_name="Storage A" ;;
          19 ) funcid_name="Storage B" ;;
          20 ) funcid_name="(12V voltage sense)" ;;
          21 ) funcid_name="(ground remote sense)" ;;
          22 ) funcid_name="Total System Power" ;;
          23 ) funcid_name="Memory Cache (Centaur)" ;;
          24 ) funcid_name="Proc 0 GPU 0" ;;
          25 ) funcid_name="Mem Proc 0-0" ;;
          26 ) funcid_name="Mem Proc 0-1" ;;
          27 ) funcid_name="Mem Proc 0-2" ;;
          28 ) funcid_name="(12V standby current)" ;;
          29 ) funcid_name="Proc 0 GPU 1" ;;
          30 ) funcid_name="Proc 0 GPU 2" ;;
          31 ) funcid_name="Proc 1 GPU 0" ;;
          32 ) funcid_name="Proc 1 GPU 1" ;;
          33 ) funcid_name="Proc 1 GPU 2" ;;
           * ) funcid_name="" ;;
    esac
    #printf "$funcid => $funcid_name\n";
}

# Determine name/description associated with APSS Function IDs
function get_history_name
{
    let id=$1
    case $id in
           1 ) hist_name="VddCurrent" ;;
           2 ) hist_name="VddVoltage" ;;
           3 ) hist_name="VdnCurrent" ;;
           4 ) hist_name="VdnVoltage" ;;
           5 ) hist_name="DimmI2cPort0" ;;
           6 ) hist_name="DimmI2cPort1" ;;
           7 ) hist_name="VddOverTemp" ;;
           8 ) hist_name="VdnOverTemp" ;;
           9 ) hist_name="VddOverCurrent" ;;
          10 ) hist_name="VdnOverCurrent" ;;
          11 ) hist_name="ApssData" ;;
          12 ) hist_name="ApssComplete" ;;
          13 ) hist_name="ApssTimeout" ;;
          14 ) hist_name="DcomTxSlvInbox" ;;
          15 ) hist_name="DcomRxSlvInbox" ;;
          16 ) hist_name="DcomTxSlvOutbox" ;;
          17 ) hist_name="DcomRxSlvOutbox" ;;
          18 ) hist_name="DcomMstPbaxSend" ;;
          19 ) hist_name="DcomSlvPbaxSend" ;;
          20 ) hist_name="DcomMstPbaxRead" ;;
          21 ) hist_name="DcomSlvPbaxRead" ;;
          22 ) hist_name="Gpe0NotIdle" ;;
          23 ) hist_name="Gpe1NotIdle" ;;
          24 ) hist_name="24x7Disabled" ;;
          25 ) hist_name="CeffRatioVdd" ;;
          26 ) hist_name="VddTemp" ;;
          27 ) hist_name="OverPcapIgn" ;;
          28 ) hist_name="VFRTTimeoutIgn" ;;
          29 ) hist_name="WOFControlTimeoutIgn" ;;
          30 ) hist_name="PstateChangeIngored" ;;
          31 ) hist_name="VddCurrentRolloverMax" ;;
          32 ) hist_name="CoreSmallDroop" ;;
          33 ) hist_name="CoreLargeDroop" ;;
           * ) hist_name="" ;;
    esac
    #printf "$funcid => $funcid_name\n";
}

function get_fru_string
{
    let fru=$1
    case $fru in
        0 ) fru_string="core" ;;
        1 ) fru_string="centaur" ;;
        2 ) fru_string="dimm" ;;
        3 ) fru_string="vrm-ot" ;;
        4 ) fru_string="gpu" ;;
        5 ) fru_string="gpu-mem" ;;
        6 ) fru_string="vrm-vdd" ;;
        * ) fru_string="" ;;
    esac
}

let displayed_header=0
function parse_rsp_mfg
{
    # Response Data
    let subcmd="0x${occ_cmd_data:0:2}"

    if [ $subcmd -eq 5 ]; then # LIST SENSORS
        printf "  MFG Sub Cmd: 0x%02X  (List Sensors)\n" $subcmd

        let more_sensors="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
        if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
            printf "   truncated?: %d  (1 = list was truncated due to space)\n" $more_sensors
        fi
        let offset=$offset+1
        let count="0x`hexdump -s $offset -n 1 -e '4/1 "%02X"' ${binfile}`"
        printf "  Num Sensors: %d\n" $count
        let offset=$offset+1
        let index=0
        while [ $index -lt $count ];
        do
            let index=$index+1
            let guid="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            #printf "         GUID[%2d]: 0x%04X\n" $index $guid
            let offset=$offset+2
            name="`hexdump -s $offset -n 16 -v -e '"%_p"' ${binfile}`"
            #printf "  Sensor Name[%2d]: %s\n" $index $name
            let offset=$offset+16
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            #printf "Latest Sample[%2d]: %6d $units (0x%04X)\n" $index $sample $sample
            printf "    [%2d] GUID: 0x%04X / %s  Sample: %6d $units (0x%04X)\n" $index $guid $name $sample $sample
            let guidList[$guidListCount]=$guid
            let guidListCount=$guidListCount+1
            let offset=$offset+2
            let last_sensor=$guid
        done
    elif [ $subcmd -eq 6 ]; then # GET SENSOR INFO
        if [ $sensor_summary -eq 0 ]; then
            printf "  MFG Sub Cmd: 0x%02X  (Get Sensor Info)\n" $subcmd
        fi

        let unit_offset=$offset+29
        units="`hexdump -s $unit_offset -n  4 -v -e '"%_p"' ${binfile} | sed 's/\\.//g'`"
        if [ "$units" == "%" ]; then
            units="%%"
        fi
        let guid="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
        let offset=$offset+2
        if [ $sensor_summary -eq 0 ]; then
            printf "         GUID: 0x%04X\n" $guid
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            printf "Latest Sample: %6d $units (0x%04X)\n" $sample $sample
            let offset=$offset+2
            let sensStatus="0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`"
            printf "       Status: 0x%02X\n" $sensStatus
            let offset=$offset+1
            let sample="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            printf "  Accumulator: %d  (0x%08X)\n" $sample $sample
            let offset=$offset+4
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            printf "   Min Sample: %6d $units (0x%04X)\n" $sample $sample
            let offset=$offset+2
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            printf "   Max Sample: %6d $units (0x%04X)\n" $sample $sample
            let offset=$offset+2
            name="`hexdump -s $offset -n 16 -v -e '"%_p"' ${binfile}`"
            echo   "  Sensor Name: $name"
            let offset=$offset+16
            #units="`hexdump -s $offset -n  4 -v -e '"%_p"' ${binfile}`"
            echo "        Units: $units"
            let offset=$offset+4
            let sample="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            printf "  Update Freq: 0x%08X\n" $sample
            let offset=$offset+4
            let sample="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            let mantissa="($sample >> 8)";
            let exponent="($sample & 0xFF)";
            if [ $exponent -gt 128 ]; then
                let exponent=$exponent-256;
            fi
            printf " Scale Factor: 0x%08X  (%dx10^%d)\n" $sample $mantissa $exponent
            let offset=$offset+4
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            printf " Sen Location: 0x%04X\n" $sample
            let offset=$offset+2
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            printf "  Sensor Type: 0x%04X\n" $sample
            let offset=$offset+2
        else
            let sample="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+2
            let sensStatus="0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`"
            let offset=$offset+1
            let acc="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+4
            let sample_min="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+2
            let sample_max="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+2
            name="`hexdump -s $offset -n 16 -v -e '"%_p"' ${binfile}`"
            let offset=$offset+16
            let offset=$offset+4
            let freq="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+4
            let scale="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+4
            let sloc="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            let offset=$offset+2
            let stype="0x`hexdump -s $offset -n 2 -e '4/1 "%02X"' ${binfile}`"
            if [ $displayed_header -eq 0 ]; then
                printf "    GUID Name             Sample     Min    Max U    Stat   Accum     UpdFreq   ScaleFactr   Loc   Type\n"
                let displayed_header=1
            fi
            if [ $sensStatus -eq 0 ]; then
                printf "  0x%04X %s %6d  %6d %6d %-4s 0x%02X 0x%08X 0x%08X 0x%08X 0x%04X 0x%04X\n" \
                    $guid $name $sample $sample_min $sample_max $units $sensStatus $acc $freq $scale $sloc $stype
            fi
            # ignore any extra bytes
            let offset=$end_of_rsp_data
        fi
    else
        printf "  MFG Sub Cmd: 0x%02X\n" $subcmd
        let remaining_bytes=$end_of_rsp_data-$offset
        #hexdump -C    -s $offset ${binfile}
        hexdump -C -s $offset -n $remaining_bytes ${binfile}
        let offset=$offset+$remaining_bytes
    fi

    let remaining_bytes=$end_of_rsp_data-$offset
    if [ $remaining_bytes -gt 0 ]; then
        echo "Remaining data:"
        hexdump -C -s $offset -n $remaining_bytes ${binfile}
    fi

} # end parse_rsp_mfg()


function parse_rsp_debugpt
{
    # Response Data
    let offset=0
    let subcmd="0x${occ_cmd_data:0:2}"

    if [ $subcmd -eq 3 ]; then # Trace Buffer
        printf "  DEBUG Sub Cmd: 0x%02X  (Trace Buffer)\n" $subcmd
        printf "   Trace Buffer: $ascii  (0x%s)\n" ${occ_cmd_data:6:8}
        echo -e $(echo "${occ_cmd_data:6:6}" | sed -e 's/\(..\)/\\x\1/g')
        #if [ "${occ_cmd_data:6:4}" == "4750" ]; then # "GP"
        #    echo "==> ppe2fsp ${binfile} ${binfile}.bin"
        #    ppe2fsp ${binfile} ${binfile}.bin
        #    echo "==> xxd ${bindfile}.bin"
        #    xxd ${bindfile}.bin
        #fi
    elif [ $subcmd -eq 1 ]; then # WOF Data Structure
        #let elogAddr="0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`"
        #xxd -l 32 ${binfile}
        #echo "WOF status:"
        let offset=0
        if [ "$interface" == "cronus" ]; then
            let offset=4
        fi
        let wof_status=0x`hexdump -s $offset -n 4 -e '4/1 "%02X"' ${binfile}`
        #echo "wof_status=$wof_status";
        flags=""
        if [ $wof_status -eq 0 ]; then
            flags="Enabled";
        else
            let bitset="$wof_status & 0x04000000";
            if [ $bitset -ne 0 ]; then flags="$flags DivideByZeroVdn"; fi
            let bitset="$wof_status & 0x02000000";
            if [ $bitset -ne 0 ]; then flags="$flags ResetDebugCmd"; fi
            let bitset="$wof_status & 0x01000000";
            if [ $bitset -ne 0 ]; then flags="$flags UserDisabledWof"; fi
            let bitset="$wof_status & 0x00800000";
            if [ $bitset -ne 0 ]; then flags="$flags IpcFailure"; fi
            let bitset="$wof_status & 0x00400000";
            if [ $bitset -ne 0 ]; then flags="$flags NoConfiguredCores"; fi
            let bitset="$wof_status & 0x00200000";
            if [ $bitset -ne 0 ]; then flags="$flags UnsupportedFreq"; fi
            let bitset="$wof_status & 0x00100000";
            if [ $bitset -ne 0 ]; then flags="$flags ResetLimitReached"; fi
            let bitset="$wof_status & 0x00080000";
            if [ $bitset -ne 0 ]; then flags="$flags SystemWofDisabled"; fi
            let bitset="$wof_status & 0x00040000";
            if [ $bitset -ne 0 ]; then flags="$flags OppbWofDisabled"; fi
            let bitset="$wof_status & 0x00020000";
            if [ $bitset -ne 0 ]; then flags="$flags OccWofDisabled"; fi
            let bitset="$wof_status & 0x00010000";
            if [ $bitset -ne 0 ]; then flags="$flags UTurboIsZero"; fi
            let bitset="$wof_status & 0x00008000";
            if [ $bitset -ne 0 ]; then flags="$flags DriverWofDisabled"; fi
            let bitset="$wof_status & 0x00004000";
            if [ $bitset -ne 0 ]; then flags="$flags VfrtAlignmentError"; fi
            let bitset="$wof_status & 0x00002000";
            if [ $bitset -ne 0 ]; then flags="$flags ControlReqFailure"; fi
            let bitset="$wof_status & 0x00001000";
            if [ $bitset -ne 0 ]; then flags="$flags VfrtReqFailure"; fi
            let bitset="$wof_status & 0x00000800";
            if [ $bitset -ne 0 ]; then flags="$flags DivideByZeroVdd"; fi
            let bitset="$wof_status & 0x00000400";
            if [ $bitset -ne 0 ]; then flags="$flags ModeNoSupport"; fi
            let bitset="$wof_status & 0x00000200";
            if [ $bitset -ne 0 ]; then flags="$flags ModeChange"; fi
            let bitset="$wof_status & 0x00000100";
            if [ $bitset -ne 0 ]; then flags="$flags StateChange"; fi
            let bitset="$wof_status & 0x00000080";
            if [ $bitset -ne 0 ]; then flags="$flags ControLReqTimeout"; fi
            let bitset="$wof_status & 0x00000040";
            if [ $bitset -ne 0 ]; then flags="$flags VfrtReqTimeout"; fi
            let bitset="$wof_status & 0x00000020";
            if [ $bitset -ne 0 ]; then flags="$flags PstateProtocolOff"; fi
            let bitset="$wof_status & 0x00000010";
            if [ $bitset -ne 0 ]; then flags="$flags PgpeWofDisabled"; fi
            let bitset="$wof_status & 0x00000008";
            if [ $bitset -ne 0 ]; then flags="$flags PgpeReqNotIdle"; fi
            let bitset="$wof_status & 0x00000004";
            if [ $bitset -ne 0 ]; then flags="$flags InvalidVddVdn"; fi
            let bitset="$wof_status & 0x00000002";
            if [ $bitset -ne 0 ]; then flags="$flags InvalidActiveQuads"; fi
            let bitset="$wof_status & 0x00000001";
            if [ $bitset -ne 0 ]; then flags="$flags NoWofHeaderMask"; fi
        fi
        printf "   WOF Status: 0x%08X  ($flags )\n" $wof_status
        # Set verbose flag so full dump of data is done (including repeated lines)
        let verbose=1
    fi

    if [ $offset -lt $end_of_rsp_data ]; then
        # Dump response as hex data
        let remaining_bytes=$end_of_rsp_data-$offset
        if [ $verbose -ne 0 ]; then
            # -v to display all repeated data (like remaining 00s)
            hexdump -C -v -s $offset -n $remaining_bytes ${binfile}
        else
            hexdump -C    -s $offset -n $remaining_bytes ${binfile}
        fi
    fi
}


function handle_occ_rsp
{
    if [ -e "$binfile" ]; then
        let occRspLength=`wc -c ${binfile} | awk '{print $1}'`
    else
        let occRspLength=0
    fi
    if [ "$interface" == "cronus" ]; then
        if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
            echo ""
            if [ "$occ_cmd" == "00" ]; then
                echo -e "${blue}POLL Response:${normal}"
            else
                echo -e "${blue}$occ_cmd Command Response:${normal}"
            fi

            if [ $verbose -ne 0 ]; then
                #echo "==> wc -c ${binfile} | awk '{print $1}'"
                echo "... $occRspLength bytes"
            fi
        fi

        if [ $verbose -ne 0 ]; then
            echo "--> $binfile is $occRspLength bytes long"
            echo "Raw Rsp Header: (32 bytes)"
            hexdump -C -n 32 ${binfile}
        fi
    fi

    ### Response Header
    let offset=0
    let rspStatus=0
    if [ "$interface" == "opal" ]; then
        let offset=0
        let end_of_rsp_data=$occRspLength
        let length=$end_of_rsp_data
    elif [ -z $bmc ] && [ -z "$inputfile" ]; then
        let expSeq=0x"${sequence}"
        let rspSeq=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
        if [ $rspSeq -eq $expSeq ]; then
            if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
                printf " Rsp Sequence: 0x%02X\n" $rspSeq;
            fi
        else
            echo -e -n "${red}"
            printf " Rsp Sequence: 0x%02X  MISMATCH - expected 0x%02X\n" $rspSeq $expSeq;
            echo -e -n "${normal}"
            let seqMismatch=1
        fi
        let offset=$offset+1
        if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
            hexdump -s $offset -n 1 -e '"      Command: 0x%02X\n"' ${binfile}
        fi
        let offset=$offset+1
        if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
            hexdump -s $offset -n 1 -e '"   RSP Status: 0x%02X\n"' ${binfile}
        fi
        let rspStatus=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`;
        let offset=$offset+1

        let length="0x`hexdump -s $offset -n 2 -e '2/1 "%02X"' ${binfile}`"
        let offset=$offset+2
        let end_of_rsp_data=$offset+$length
    elif [ -n "$inputfile" ]; then
        if [ $passThru -eq 0 ]; then
            # USED TO PARSE POLL RESPONSES FROM syslog file (must be formated as just hex with spaces between each byte)
            let rspSeq=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
            printf " Rsp Sequence: 0x%02X\n" $rspSeq;
            let offset=$offset+1
            hexdump -s $offset -n 1 -e '"      Command: 0x%02X\n"' ${binfile}
            let offset=$offset+1
            hexdump -s $offset -n 1 -e '"   RSP Status: 0x%02X\n"' ${binfile}
            let rspStatus=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`;
            let offset=$offset+1
            let length="0x`hexdump -s $offset -n 2 -e '2/1 "%02X"' ${binfile}`"
            printf "       Length: 0x%04X\n" $length
            let offset=$offset+2
        else
            let offset=0
            let end_of_rsp_data=$occRspLength
        fi
    elif [ $sendOccInstance -ne 0 ]; then
        let compCode=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`
        compCodeString="(Success)"
        if [ $compCode -ne 0 ]; then
            compCodeString="(Failure)"
        fi
        printf "AMI Comp Code: 0x%02X $compCodeString\n" $compCode
        let offset=$offset+1
        printf "AMI Rsp Length: %d bytes\n" $occRspLength
    else
        hexdump -s $offset -n 1 -e '"   RSP Status: 0x%02X\n"' ${binfile}
        let rspStatus=0x`hexdump -s $offset -n 1 -e '"%02X"' ${binfile}`;
        let offset=$offset+1
    fi

    if [ $skip_header -eq 0 ] || [ $verbose -ne 0 ]; then
        printf "  Data Length: 0x%04X\n" $length
    fi

    # Check for exception
    let key="$rspStatus & 0xF0"
    let elogId=0
    if [ $key -eq 224 ]; then
        printf "${red}OCC EXCEPTION STATUS FOUND: 0x%02X ${normal}\n" $rspStatus;
        echo "Exception Data:"
        #hexdump -s $offset -n $length -e '"         " 2/1 "%02X" " " 2/1 "%02X" "\n"' ${binfile}
        hexdump -C -v -s $offset -n $length ${binfile}
        echo ""
        let seqMismatch=0
    else
        if [ "$occ_cmd" == "00" ]; then # POLL COMMAND
            parse_rsp_poll
            if [ $elogId -ne 0 ] && [ $elogAddr -ne 0 ] ; then
                process_elog
            fi
        elif [ "$occ_cmd" == "40" ]; then # DEBUG PASSTHRU COMMAND
            parse_rsp_debugpt
        elif [ "$occ_cmd" == "53" ]; then # MFG COMMAND
            parse_rsp_mfg
        else
            # Dump response as hex data
            echo "Response Data:"
            let remaining_bytes=$end_of_rsp_data-$offset
            if [ $verbose -ne 0 ]; then
                # -v to display all repeated data (like remaining 00s)
                hexdump -C -v -s $offset -n $remaining_bytes ${binfile}
            else
                hexdump -C    -s $offset -n $remaining_bytes ${binfile}
            fi
        fi
    fi
} # end handle_occ_rsp()


function process_elog
{
    if [ "$interface" == "cronus" ]; then
    #if [ -z $bmc ] && [ -z "$inputfile" ]; then
        echo ""
        printf "${bold}==> Retrieving elog from POLL (id 0x%02X, addr 0x%08X, len 0x%04X)${normal}\n" $elogId $elogAddr $elogLen;
        if [ $verbose -ne 0 ]; then
            printf "${bold}==> getsram %08X %d -p${occ} -ch $channel $quiet  (read ELOG data from SRAM)${normal}\n" $elogAddr $elogLen
        fi
        sramAddr=`printf "%08X" $elogAddr`
        echo "getsram $sramAddr $elogLen -p${occ} -ch $channel $quiet -fb elog.bin"
        getsram $sramAddr $elogLen -p${occ} -ch $channel $quiet -fb elog.bin
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed reading Elog data from SRAM (rc=$rc)${normal}"
            exit  3;
        fi
        if [ $verbose -ne 0 ]; then
            echo "Raw Elog:"
            hexdump -C -s 0 elog.bin
        else
            echo ""
        fi
        echo ""

        let offset=4
        hexdump -s $offset -n 1  -e '" Return Code: 0x2A%02X\n"' elog.bin
        let offset=$offset+1
        let sev="0x`hexdump -s $offset -n 1 -e '"%02X"' elog.bin`"
        flags="Unknown"
        if [ $sev -eq 0 ]; then flags="Informational";
        elif [ $sev -eq 1 ]; then flags="Recoverable";
        elif [ $sev -eq 2 ]; then flags="Unrecoverable"; fi
        printf "    Severity: 0x%02X ($flags)\n" $sev
        let offset=$offset+1
        flags=""
        let actions="0x`hexdump -s $offset -n 1 -e '"%02X"' elog.bin`"
        let bitset="$actions & 0x80";
        if [ $bitset -ne 0 ]; then flags="ResetRqd"; fi
        let bitset="$actions & 0x40";
        if [ $bitset -ne 0 ]; then flags="$flags SafeModeRqd"; fi
        if [ -n "$flags" ]; then flags="($flags)"; fi
        printf "     Actions: 0x%02X $flags\n" $actions
        let offset=$offset+5
        hexdump -s $offset -n 1  -e '" MaxCallouts: 0x%02X\n"' elog.bin
        let offset=$offset+1
        echo "    Callouts: tt cccccccccccccccc pp rrrr (type, callout, priority, rsvd)"
        hexdump -v -s $offset -n 72 -e '"              " 1/1 "%02X" " " 8/1 "%02X" " " 1/1 "%02X" " " 2/1 "%02X" "\n"' elog.bin
        let offset=$offset+72
        if [ $verbose -ne 0 ] || [ $purge -ne 0 ]; then
            echo "Remaining Elog Data:"
            #    hexdump -C -s $offset -n 64 -e '"%06.6_ax:  " 4/1 "%02X" " " 4/1 "%02X" " " 4/1 "%02X" " " 4/1 "%02X" "\n"' elog.bin
            hexdump -C -s $offset elog.bin
            #    hexdump -C -s $offset -n 64 -x elog.bin
        else
            echo "    (add -v parm to display full elog data OR -p to dump then purge elog)"
        fi

        rm elog.bin

        if [ $purge -ne 0 ]; then
            printf "${bold}==> Sending CLEAR ELOG command (id 0x%02X)${normal}\n" $elogId;
            if [ -z $bmc ] && [ -z "$inputfile" ]; then
                # First, store the clear elog command in command buffer in SRAM
                let csum=0xCC+0x12+0x01+$elogId
                clearElogCmd=`printf "cc120001%02X%04X" $elogId $csum`
                if [ $verbose -ne 0 ]; then
                    echo -e "${bold}==> putsram $cmd_sram_addr $clearElogCmd -p${occ} -ch $channel $quiet  (write CLEAR_ELOG command to OCC SRAM)${normal}"
                fi
                putsram $cmd_sram_addr $clearElogCmd -p${occ} -ch $channel $quiet
                let rc=$?
                if [ $rc -ne 0 ]; then
                    echo -e "${red}ERROR: failed writing CLEAR_ELOG command to OCC SRAM (rc=$rc)${normal}"
                    exit 1;
                fi

                # Second, send a doorbell to OCC
                if [ $verbose -ne 0 ]; then
                    echo -e "${bold}==> putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet  (send doorbell to OCC)${normal}"
                fi
                putscom pu $doorbell_addr 0101000000000000 -p${occ} $quiet
                let rc=$?
                if [ $rc -ne 0 ]; then
                    echo -e "${red}ERROR: failed sendingn doorbell to OCC (rc=$rc)${normal}"
                fi

                # Third, collect response from response buffer in SRAa
                if [ $verbose -ne 0 ]; then
                    echo -e "${bold}==> getsram $rsp_sram_addr 16 -p${occ} -ch $channel $quiet  (read CLEAR_ELOG response from SRAM)${normal}"
                fi
                getsram $rsp_sram_addr 16 -p${occ} -ch $channel $quiet
                let rc=$?
                if [ $rc -ne 0 ]; then
                    echo -e "${red}ERROR: failed reading CLEAR_ELOG response from SRAM (rc=$rc)${normal}"
                    exit 2;
                fi
            else
                if [ $verbose -ne 0 ]; then
                    echo -e "${bold}==> ipmitool -H $bmc -I lanplus -U $bmcId -P $bmcPw raw 0x3a 0x0d 0x12 $elogId${normal}"
                fi
                ipmitool -H $bmc -I lanplus -U $bmcId -P $bmcPw raw 0x3a 0x0d 0x12 $elogId
                let rc=$?
                if [ $rc -ne 0 ]; then
                    echo -e "${red}ERROR: failed sending CLEAR_ELOG $elogId to OCC via IPMI/BMC (rc=$rc)${normal}"
                    exit 8
                fi
            fi
        else
            printf "${bold}==> Ignoring elog from POLL (id 0x%02X, addr 0x%08X, len 0x%04X)${normal}\n" $elogId $elogAddr $elogLen;
        fi
    else
        printf "\n${red}Note: Unable to read elog sram data via $interface, use cronus (OCC logid 0x%02X, addr 0x%08X, len 0x%04X)${normal}\n" $elogId $elogAddr $elogLen;
    fi
} # end process_elog()


function tmgt_info
{
    ### Dump HTMGT and OCC states and status
    echo "==> opal-prd --expert-mode htmgt-passthru 0x01"
    $sudo opal-prd --expert-mode htmgt-passthru 0x01 | sed 's/\s//g' > $temp_filename
    # get status of first cmd in piped cmdline
    let rc=${PIPESTATUS[0]}
    #echo "020003030000000000002ada00000000" > $temp_filename
    #echo "000301010100000000000000c3100300" >> $temp_filename
    #echo "01030000010000000000000003900200" >> $temp_filename
    #let rc=0
    if [ $verbose -ne 0 ]; then
        echo -n "Raw Data:"
        cat $temp_filename
        echo ""
    fi
    let inSafe=0
    let numOccs=0
    if [ $rc -eq 0 ]; then
        let lineno=0
        while read line; do
            if [ ${#line} -gt 2 ]; then
                let lineno=$lineno+1
                if [ ${lineno} -eq 1 ]; then
                    let numOccs=0x${line:0:2}
                    let master=0x${line:2:2}
                    let state=0x${line:4:2}
                    if [ $state -eq 4 ]; then
                        let in_safe=1
                    fi
                    let targState=0x${line:6:2}
                    let count=0x${line:8:2}
                    let pstype=0x${line:10:2}
                    # 1 byte reserved
                    let safe=0x${line:14:2}
                    safeRc=${line:20:4}
                    let safeInst=0x${line:24:8}
                    if [ $state -eq 1 ]; then
                        stateText="STANDBY"
                    elif [ $state -eq 2 ]; then
                        stateText="OBSERV "
                    elif [ $state -eq 3 ]; then
                        stateText="ACTIVE "
                    elif [ $state -eq 4 ]; then
                        stateText="SAFE   "
                    elif [ $state -eq 5 ]; then
                        stateText="CHARACT"
                    elif [ $state -eq $((0x85)) ]; then
                        stateText="RESET  "
                    elif [ $state -eq $((0x87)) ]; then
                        stateText="TRANSIT"
                    elif [ $state -eq $((0x88)) ]; then
                        stateText="LOADING"
                    elif [ $state -eq $((0x89)) ]; then
                        stateText=""
                    else
                        stateText="UNDEFIN"
                    fi
                    if [ $safe -ne 0 ]; then
                        let inSafe=1
                        echo "HTMGT State: $stateText($(printf "0x%02X" $state)), $numOccs OCC (master:OCC$master), resetCount:$count,  (SAFE MODE: rc=0x${safeRc}/OCC$safeInst)"
                    else
                        if [ $safeRc == "0000" ]; then
                            echo "HTMGT State: $stateText($(printf "0x%02X" $state)), $numOccs OCC (master:OCC$master), resetCount:$count"
                        else
                            echo "HTMGT State: $stateText($(printf "0x%02X" $state)), $numOccs OCC (master:OCC$master), resetCount:$count (last reset due to rc=0x${safeRc}/OCC$safeInst)"
                        fi
                    fi
                else
                    let inst=0x${line:0:2}
                    let state=0x${line:2:2}
                    let role=0x${line:4:2} #
                    let capab=0x${line:6:2} #
                    let occComm=0x${line:8:2}
                    # 3 bytes reserved
                    let failed=0x${line:16:2}
                    let needReset=0x${line:18:2}
                    let resetReason=0x${line:20:2} #
                    let wof_reset_count=0x${line:22:1}
                    let count=0x${line:23:1}
                    pollRsp=${line:24:8}
                    let pollRspExtStatus=0x${pollRsp:2:2}
                    type="Slave "
                    if [ $master -eq $inst ]; then
                        type="Master"
                    fi
                    if [ $state -eq 1 ]; then
                        stateText="STANDBY"
                    elif [ $state -eq 2 ]; then
                        stateText="OBSERV "
                    elif [ $state -eq 3 ]; then
                        stateText="ACTIVE "
                    elif [ $state -eq 4 ]; then
                        stateText="SAFE   "
                    elif [ $state -eq 5 ]; then
                        stateText="CHARACT"
                    elif [ $state -eq $((0x85)) ]; then
                        stateText="RESET  "
                    elif [ $state -eq $((0x87)) ]; then
                        stateText="TRANSIT"
                    elif [ $state -eq $((0x88)) ]; then
                        stateText="LOADING"
                    elif [ $state -eq $((0x89)) ]; then
                        stateText=""
                    else
                        stateText="UNDEFIN"
                    fi
                    flags=""
                    if [ $occComm -eq 0 ]; then
                        flags="${flags}NOCOMM "
                    elif [ $failed -ne 0 ]; then
                        flags="${flags}FAILED "
                    elif [ $needReset -ne 0 ]; then
                        flags="${flags}NEEDSRESET "
                    fi
                    if [ $pollRspExtStatus -eq 0 ]; then
                        echo "OCC${inst}: $type $stateText($(printf "0x%02X" $state)) resetCount:$count wofResets:$wof_reset_count $flags pollRsp:0x${pollRsp}..."
                    else
                        extflags="";
                        let bitset="$pollRspExtStatus & 0x10";
                        if [ $bitset -ne 0 ]; then extflags="$extflags QuickPowerDrop"; fi
                        let bitset="$pollRspExtStatus & 0x80";
                        if [ $bitset -ne 0 ]; then extflags="$extflags Throttle-ProcOverTemp"; fi
                        let bitset="$pollRspExtStatus & 0x40";
                        if [ $bitset -ne 0 ]; then extflags="$extflags Throttle-Power"; fi
                        let bitset="$pollRspExtStatus & 0x20";
                        if [ $bitset -ne 0 ]; then extflags="$extflags MemThrot-OverTemp"; fi
                        let bitset="$pollRspExtStatus & 0x08";
                        if [ $bitset -ne 0 ]; then extflags="$extflags Throttle-VddOverTemp"; fi
                        echo "OCC${inst}: $type $stateText($(printf "0x%02X" $state)) resetCount:$count wofResets:$wof_reset_count $flags pollRsp:0x${pollRsp}... ($extflags )"
                    fi
                fi
            fi
        done < $temp_filename
    else
        echo "ERROR: opal-prd occ passthru command failed with rc=$rc"
    fi
    if [ -e "$temp_filename" ]; then
        rm -rf $temp_filename
    fi

    if [ $rc -eq 0 ] && [ $inSafe -ne 0 ]; then
        let rc=4
    fi
} # end tmgt_info()



function wof_reset_reasons
{
    ### Dump WOF reset reasons and OCC instance ID
    echo "==> opal-prd --expert-mode htmgt-passthru 0x0A"
    $sudo opal-prd --expert-mode htmgt-passthru 0x0A | sed 's/\s//g' > /tmp/wofrr.bin
    # get status of first cmd in piped cmdline
    let rc=${PIPESTATUS[0]}
    if [ $rc -eq 0 ]; then
        while read line; do
            if [ ${#line} -gt 0 ]; then
                #First read the output data into one variable
                alldata=$alldata$line
            fi
        done < /tmp/wofrr.bin
    else
        echo "ERROR: opal-prd occ passthru command failed with rc=$rc"
    fi

    # Data length should be multiple of 10. Each OCC has a 2 digit ID followed
    # by the 8 digit WOF Reset reason vector
    if [ $((${#alldata}%10)) -ne 0 ]; then
        echo "ERROR: Data is unexpected length. Aborting..."
    else
        numOccs=$((${#alldata}/10))
        current_index=0
        for (( i=0; i<$numOccs; i++ ))
        do
            #Move to the next 10 digit block
            current_line=${alldata:${current_index}:10}
            #Extract OCC Instance
            let occId=0x${current_line:0:2}
            #Extract wof_disabled bit vector
            let wofRR=0x${current_line:2:8}
            printf "OCC%X WOF Reset Reasons: 0x%08X\n" $occId $wofRR
            #Increment index
            current_index=$current_index+10
        done
    fi
} # end wof_reset_reasons


function tmgt_flags
{
    ### Dump HTMGT Internal Flags
    echo "==> opal-prd --expert-mode htmgt-passthru 0x02"
    $sudo opal-prd --expert-mode htmgt-passthru 0x02
    let flagvalue=0x`$sudo opal-prd --expert-mode htmgt-passthru 0x02 | tr -d '\r\n' | sed 's/\s//g1'`
    flags="";
    let bitset="$flagvalue & 0x00800000";
    if [ $bitset -ne 0 ]; then flags="$flags HaltOnSrc"; fi
    let bitset="$flagvalue & 0x00000800";
    if [ $bitset -ne 0 ]; then flags="$flags DisableMemConfig"; fi
    let bitset="$flagvalue & 0x00000100";
    if [ $bitset -ne 0 ]; then flags="$flags HaltOnResetFail"; fi
    let bitset="$flagvalue & 0x00000080";
    if [ $bitset -ne 0 ]; then flags="$flags ExtResetDisable"; fi
    let bitset="$flagvalue & 0x00000040";
    if [ $bitset -ne 0 ]; then flags="$flags DisableMemThrot"; fi
    let bitset="$flagvalue & 0x00000020";
    if [ $bitset -ne 0 ]; then flags="$flags IgnoreOccState"; fi
    let bitset="$flagvalue & 0x00000010";
    if [ $bitset -ne 0 ]; then flags="$flags HoldOccsInReset"; fi
    let bitset="$flagvalue & 0x00000008";
    if [ $bitset -ne 0 ]; then flags="$flags LoadDisabled"; fi
    let bitset="$flagvalue & 0x00000004";
    if [ $bitset -ne 0 ]; then flags="$flags TerminateOnErr"; fi
    let bitset="$flagvalue & 0x00000002";
    if [ $bitset -ne 0 ]; then flags="$flags ResetDisabled"; fi
    let bitset="$flagvalue & 0x00000001";
    if [ $bitset -ne 0 ]; then flags="$flags ExternalOverride"; fi
    let bitset="$flagvalue & 0x007FF600";
    if [ $bitset -ne 0 ]; then flags="$flags UnknownBit"; fi
    printf "Flags: 0x%08X  $flags\n" $flagvalue

    if [ -n "$newFlags" ]; then
        newFlagValue=`printf "%08X" $newFlags`
        echo "Updating internalFlags to: $newFlagValue"
        ### Set HTMGT Internal Flags
        echo "==> opal-prd --expert-mode htmgt-passthru 0x02 0x${newFlagValue:0:2} 0x${newFlagValue:2:2} 0x${newFlagValue:4:2} 0x${newFlagValue:6:2}"
        $sudo opal-prd --expert-mode htmgt-passthru 0x02 0x${newFlagValue:0:2} 0x${newFlagValue:2:2} 0x${newFlagValue:4:2} 0x${newFlagValue:6:2}
    fi
}


function occ_ffdc
{
    echo ""
    let numOccs=1

    while [ $numOccs -gt 0 ]; do
        echo "`hostname` OCC$occ FFDC Data:  (`date`)"
        echo "==> opal-prd --expert-mode htmgt-passthru 0x03 $occ 0x42 0x00"
        $sudo opal-prd --expert-mode htmgt-passthru 0x03 $occ 0x42 0x00
        let rc=${PIPESTATUS[0]}
        echo ""
        let occ=$occ+1
        let numOccs=$numOccs-1
    done
} # end occ_ffdc()


function occ_trace
{
    echo ""
    let numOccs=1

    while [ $numOccs -gt 0 ]; do
        echo "`hostname` OCC$occ Trace:  (`date`)"
        occ_cmd="40"
        occ_cmd_data="03010045525200" # ERR traces
        send_occ_cmd
        handle_occ_rsp
        occ_cmd_data="030100494D5000" # IMP traces
        send_occ_cmd
        handle_occ_rsp
        occ_cmd_data="030100494E4600" # INF traces
        send_occ_cmd
        handle_occ_rsp
        occ_cmd_data="03010047503000" # GP0 traces
        send_occ_cmd
        handle_occ_rsp
         # Need to run: ppe2fsp infile outfile
        occ_cmd_data="03010047503100" # GP1 traces
        send_occ_cmd
        handle_occ_rsp
         # Need to run: ppe2fsp infile outfile
        let occ=$occ+1
        let numOccs=$numOccs-1
    done
} # end occ_trace()


function occ_trace_cronus
{
    echo ""
    let numOccs=1

    if [ -z "$string_file" ]; then
        if [ -e "./occStringFile" ]; then
            string_file="./occStringFile"
        elif [ -e "/tmp/occStringFile" ]; then
            string_file="/tmp/occStringFile"
        elif [ -e "/nfs/occStringFile" ]; then
            string_file="/nfs/occStringFile"
        else
            echo "WARNING: unable to find occStringFile"
        fi
    fi

    let min_sram_size=4
    if [ $toolkit -ne 0 ]; then
        let min_sram_size=8
    fi
    while [ $numOccs -gt 0 ]; do
        echo -e "${bold}Collecting OCC$occ Trace via cronus:  (`date`)${normal}"
        # Confirm eyecatcher is correct
        if [ $verbose -ne 0 ]; then
            echo "==> getsram fffb4003 $min_sram_size -ch $channel -p$occ -n$node -exp 42455252"
        fi
        getsram fffb4003 $min_sram_size -ch $channel -p$occ -n$node
        getsram fffb4003 $min_sram_size -ch $channel -p$occ -n$node -exp 42455252 # "BERR"
        let foundERR=$?
        if [ $foundERR -eq 0 ]; then
            # Remove old files
            rm -f ./occTrace*.bin ./occTrace.ppe
            echo -e "${bold}==> getsram fffb4000 8192 -p$occ -n$node -fb ./occTraceERR.bin -ch $channel ${normal}"
            getsram                     fffb4000 8192 -p$occ -n$node -fb ./occTraceERR.bin -ch $channel
            echo -e "${bold}==> getsram fffb6000 8192 -p$occ -n$node -fb ./occTraceINF.bin -ch $channel ${normal}"
            getsram                     fffb6000 8192 -p$occ -n$node -fb ./occTraceINF.bin -ch $channel
            echo -e "${bold}==> getsram fffb8000 8192 -p$occ -n$node -fb ./occTraceIMP.bin -ch $channel ${normal}"
            getsram                     fffb8000 8192 -p$occ -n$node -fb ./occTraceIMP.bin -ch $channel

            if [ -e "./ppe2fsp" ]; then
                ppe2fsp_cmd="./ppe2fsp"
            else
                echo -e "${red}Unable to find ppe2fsp to convert GPE traces to FSP trace format${normal}"
                echo "NOTE: Command is available in occ/obj/ppetools/ppe2fsp"
                ppe2fsp_cmd="";
            fi

            GPE0ADDR=`getsram fffb3c10 $min_sram_size -ch $channel | grep 00000000 | awk '{print $2}'`
            GPE0SIZEHEX=`getsram fffb3c14 $min_sram_size -ch $channel | grep 00000000 | awk '{print $2}'`
            #echo "gpe0 $GPE0ADDR $GPE0SIZEHEX $GPE0SIZE"
            #GPE0SIZE=`echo \$((16#$GPE0SIZEHEX))`
            let GPE0SIZE=0x${GPE0SIZEHEX}
            echo "gpe0 $GPE0ADDR $GPE0SIZEHEX $GPE0SIZE"
            let gpe_addr=0x$GPE0ADDR
            if [ $gpe_addr -ne 0 ]; then
                echo -e "${bold}==> getsram $GPE0ADDR $GPE0SIZE -ch $channel -p$occ -n$node -fb ./occTraceGPE0.ppe ${normal}"
                getsram                     $GPE0ADDR $GPE0SIZE -ch $channel -p$occ -n$node -fb ./occTraceGPE0.ppe

                if [ -n "$ppe2fsp_cmd" ]; then
                    echo -e "${bold}==> $ppe2fsp_cmd ./occTraceGPE0.ppe ./occTraceGPE0.bin ${normal}"
                    $ppe2fsp_cmd ./occTraceGPE0.ppe ./occTraceGPE0.bin
                    if [ $? -eq 0 ]; then
                        rm -f ./occTraceGPE0.ppe
                    else
                        echo -e "${red}ERROR: Unable to convert occTraceGPE0.ppe to FSP trace format${normal}"
                        rm -f ./occTraceGPE0.bin
                    fi
                else
                    echo -e "${red}ERROR: unable to find ppe2fsp to convert GPE traces to FSP trace format${normal}"
                fi
            fi

            GPE1ADDR=`getsram fffb3c18 $min_sram_size -ch $channel | grep 00000000 | awk '{print $2}'`
            GPE1SIZEHEX=`getsram fffb3c1c $min_sram_size -ch $channel | grep 00000000 | awk '{print $2}'`
            #GPE1SIZE=`echo \$((16#$GPE1SIZEHEX))`
            let GPE1SIZE=0x${GPE1SIZEHEX}
            echo "gpe1 $GPE1ADDR $GPE1SIZEHEX $GPE1SIZE"
            if [ $gpe_addr -ne 0 ]; then
                echo -e "${bold}==> getsram $GPE1ADDR $GPE1SIZE -ch $channel -p$occ -n$node -fb ./occTraceGPE1.ppe ${normal}"
                getsram                     $GPE1ADDR $GPE1SIZE -ch $channel -p$occ -n$node -fb ./occTraceGPE1.ppe

                if [ -n "$ppe2fsp_cmd" ]; then
                    echo -e "${bold}==> $ppe2fsp_cmd ./occTraceGPE1.ppe ./occTraceGPE1.bin ${normal}"
                    $ppe2fsp_cmd ./occTraceGPE1.ppe ./occTraceGPE1.bin
                    if [ $? -eq 0 ]; then
                        rm -f ./occTraceGPE1.ppe
                    else
                        echo -e "${red}ERROR: Unable to convert occTraceGPE1.ppe to FSP trace format${normal}"
                        rm -f ./occTraceGPE1.bin
                    fi
                fi
            fi

            if [ -e "./fsp-trace" ]; then
                fsptrace_cmd="./fsp-trace"
            else
                #echo -e "${red}Unable to find fsp-trace to parse FSP traces${normal}"
                fsptrace_cmd="fsp-trace";
            fi

            if [ -n "$string_file" ]; then
                if [ -n "$fsptrace_cmd" ]; then
                    echo -e "${bold}==> $fsptrace_cmd -s $string_file ./*.bin ${normal}"
                    $fsptrace_cmd -s $string_file ./*.bin
                fi
            else
                echo "To parse: fsp-trace -s OCC_STRING_FILENAME ./occTrace*.bin"
            fi
        else
            echo "ERROR: ERR eyecatcher was not found!  ABORTING TRACE COLLECTION"
        fi
        let occ=$occ+1
        let numOccs=$numOccs-1
    done
} # end occ_trace()


if [ $passThru -eq 1 ] && [ -z "$inputfile" ]; then
    # No input file specified, check clipboard for hex data to parse
    inputfile="/tmp/occtool.temp.txt"
    echo "Extracting copy buffer into ${inputfile}..."
    xselection PRIMARY > $inputfile
fi

if [ $passThru -eq 1 ] && [ -n "$inputfile" ]; then
    convertToBinary $inputfile $binfile
fi

#sendOccCmd 00 10
#exit

if [ -n "$action" ]; then
    if [ "$action" == "SensorDump" ]; then
        # -X 53 0600003d = get sensor details for GUID 0x003d"
        occ_cmd="53"
        occ_cmd_data=`printf "0600%04X" $sensor_guid`
        #echo "==> $occ_cmd $occ_cmd_data"
        send_occ_cmd
        handle_occ_rsp
    elif [ "$action" == "SensorList" ]; then
        printf "    Sensor Type: 0x%04X\n" $sensor_type
        printf "Sensor Location: 0x%04X\n" $sensor_loc
        if [ $only_non_zero_sensors -eq 1 ]; then
            printf "    (only displaying non-zero sensors)\n"
        fi

        # Collect the list of applicable sensors (and their sample value)
        let more_sensors=1
        let first_sensor=0
        let skip_header=1
        while [ $more_sensors -ne 0 ]; do
            # -X 53 0500000001LLLLTTTT = list first 50 OCC sensors (LLLL=Location,TTTT=Type)"
            occ_cmd="53"
            occ_cmd_data=`printf "0500%04X%02X%04X%04X" $first_sensor $only_non_zero_sensors $sensor_loc $sensor_type`
            send_occ_cmd
            handle_occ_rsp # will update more_sensors and last_sensor
            let first_sensor=$last_sensor+1
        done;

        # Display sensor details (min, max, etc for each one)
        if [ $guidListCount -gt 0 ]; then
            printf "\nSensor Details: (found $guidListCount sensors, details only for Status of 0x00)\n";
            let index=0
            let sensor_summary=1
            while [ $index -lt $guidListCount ]; do
                # -X 53 0600003d = get sensor details for GUID 0x003d"
                occ_cmd="53"
                occ_cmd_data=`printf "0600%04X" ${guidList[$index]}`
                send_occ_cmd
                handle_occ_rsp
                let index=$index+1
            done;
        fi
    elif [ "$action" == "OCCFFDC" ]; then
        occ_ffdc
    elif [ "$action" == "ExitSafe" ]; then
        if [ "$interface" == "opal" ]; then
            ### Dump HTMGT and OCC states and status
            tmgt_info
            if [ $in_safe -ne 0 ]; then
                ### Attempt to exit safe mode
                echo "==> opal-prd --expert-mode htmgt-passthru 0x05"
                $sudo opal-prd --expert-mode htmgt-passthru 0x05
                let rc=$?
                echo "return status: $rc"
            else
                echo "System is not currently in safe mode!"
            fi
        else
            echo -e "${red}ERROR: Command only supported with opal-prd${normal} (not $interface)"
        fi
    elif [ "$action" == "TMGTInfo" ]; then

        if [ "$interface" == "opal" ]; then
            tmgt_info
        else
            echo -e "${red}ERROR: Command only supported with opal-prd${normal} (not $interface)"
        fi
    elif [ "$action" == "WOFRR" ]; then

        if [ "$interface" == "opal" ]; then
            wof_reset_reasons
        else
            echo -e "${red}ERROR: Command only supported with opal-prd${normal} (not $interface)"
        fi
    elif [ "$action" == "TMGTFlags" ]; then

        if [ "$interface" == "opal" ]; then
            tmgt_flags
        else
            echo -e "${red}ERROR: Command only supported with opal-prd${normal} (not $interface)"
        fi
    elif [ "$action" == "trace" ]; then
        if [ "$interface" == "opal" ]; then
            occ_trace $occ
        elif [ "$interface" == "cronus" ]; then
            occ_trace_cronus
        fi
    elif [ "$action" == "CmdRspBuffer" ]; then
        let buffer_size=128
        echo "OCC Command Buffers from SRAM ($cmd_sram_addr):"
        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> getsram $cmd_sram_addr $buffer_size -pall -ch $channel $quiet  (read $cmd response from SRAM)${normal}"
        fi
        if [ -e "${binfile}" ]; then
            rm ${binfile}
        fi
        getsram $cmd_sram_addr $buffer_size -pall -ch $channel $quiet
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed reading response buffer from SRAM (rc=$rc)${normal}"
            exit 2;
        fi
        echo "OCC Response Buffers from SRAM ($rsp_sram_addr):"
        if [ $verbose -ne 0 ]; then
            echo -e "${bold}==> getsram $rsp_sram_addr $buffer_size -pall -ch $channel $quiet  (read $cmd response from SRAM)${normal}"
        fi
        if [ -e "${binfile}" ]; then
            rm ${binfile}
        fi
        getsram $rsp_sram_addr $buffer_size -pall -ch $channel $quiet
        let rc=$?
        if [ $rc -ne 0 ]; then
            echo -e "${red}ERROR: failed reading response buffer from SRAM (rc=$rc)${normal}"
            exit 2;
        fi
    else
        echo -e "${red}ERROR: internal action of $action is not implemented by occtoolp9 script${normal}";
    fi
else
    if [ $passThru -eq 1 ]; then
        occ_cmd="00"
        handle_occ_rsp
    elif [ -n "$occ_cmd" ]; then
        # Send user specified command
        send_occ_cmd
        handle_occ_rsp
    else
        usage
        exit 0
    fi
fi

#cleanup
if [ -e "${binfile}" ]; then
    rm ${binfile}
fi

if [ $seqMismatch -ne 0 ]; then
    echo ""
    echo -e "${red}Warning: sequence number mismatch!${normal}  (Response data is stale!)"
    exit 9
fi


OpenPOWER on IntegriCloud