summaryrefslogtreecommitdiffstats
path: root/src/usr/util/runtime/rt_cmds.C
blob: bf0c5174959a91b43c37ac8e5d6fff4e5472eb5d (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/util/runtime/rt_cmds.C $                              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] 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                                                     */

#include <runtime/interface.h>
#include <stdio.h>
#include <trace/interface.H>
#include <string.h>
#include "../utilbase.H"
#include <targeting/common/target.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/predicates/predicateattrval.H>
#include <targeting/common/iterators/rangefilter.H>
#include <targeting/common/utilFilter.H>
#include <pnor/pnorif.H>
#include <devicefw/userif.H>
#include <devicefw/driverif.H>
#include <util/util_reasoncodes.H>
#include <errl/errlmanager.H>
#include <errl/errlreasoncodes.H>
#include <vector>
#include <isteps/pm/pm_common_ext.H>
#include <p9_hcd_memmap_base.H>  // for reload_pm_complex
#include <p9_stop_data_struct.H> // for reload_pm_complex
#include <scom/runtime/rt_scomif.H> // sendScomOpToFsp,
                                    // sendMultiScomReadToFsp,
                                    // switchToFspScomAccess
#ifdef CONFIG_NVDIMM
#include <isteps/nvdimm/nvdimm.H>  // notify NVDIMM protection change
#endif

extern char hbi_ImageId;

// need this here so compile works, linker will later find this
namespace RTPM
{
    int load_pm_complex( uint64_t i_chip,
                         uint64_t i_homer_addr,
                         uint64_t i_occ_common_addr,
                         uint32_t i_mode );
}

namespace Util
{

/**
 * @brief Poor-man's version of strtoul, see man page
 */
uint64_t strtou64(const char *nptr, char **endptr, int base)
{
    uint64_t l_data = 0;
    size_t i = 0;
    while( nptr[i] != '\0' )
    {
        uint64_t l_nib = 0;
        switch(nptr[i])
        {
            // handle leading '0x' or 'x'
            case('x'): case('X'):
                l_data = 0;
                break;
            case('0'): l_nib = 0; break;
            case('1'): l_nib = 1; break;
            case('2'): l_nib = 2; break;
            case('3'): l_nib = 3; break;
            case('4'): l_nib = 4; break;
            case('5'): l_nib = 5; break;
            case('6'): l_nib = 6; break;
            case('7'): l_nib = 7; break;
            case('8'): l_nib = 8; break;
            case('9'): l_nib = 9; break;
            case('A'): case('a'): l_nib = 0xA; break;
            case('B'): case('b'): l_nib = 0xB; break;
            case('C'): case('c'): l_nib = 0xC; break;
            case('D'): case('d'): l_nib = 0xD; break;
            case('E'): case('e'): l_nib = 0xE; break;
            case('F'): case('f'): l_nib = 0xF; break;
            default:
                UTIL_FT( "strtou64> nptr=%s, nptr[%d]=%c", nptr, i, nptr[i] );
                return 0xDEADBEEF;
        }
        l_data <<= 4;
        l_data |= l_nib;
        i++;
    }
    return l_data;
}


/**
 * @brief Fetch a target by HUID
 * @param[in] i_huid  HUID to translate
 * @return  Target Pointer, NULL if no match found
 */
TARGETING::Target* getTargetFromHUID( uint32_t i_huid )
{
    TARGETING::PredicateAttrVal<TARGETING::ATTR_HUID> l_huidMatches(i_huid);
    TARGETING::TargetRangeFilter l_targetsWithHuid(
        TARGETING::targetService().begin(),
        TARGETING::targetService().end(),
        &l_huidMatches);
    if(l_targetsWithHuid)
    {
        return *l_targetsWithHuid;
    }
    else
    {
        UTIL_FT( "bad huid - %.8X!", i_huid );
        return NULL;
    }
}


/**
 * @brief Read the value of an attribute by name
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_huid  HUID associated with Target to get attribute from
 * @param[in] i_attrId  Hash of attribute to read
 * @param[in] i_size  Size of attribute data in bytes
 */
void cmd_getattr( char*& o_output,
                  uint32_t i_huid,
                  uint32_t i_attrId,
                  uint32_t i_size )
{
    UTIL_FT( "cmd_getattr> huid=%.8X, attr=%.8X, size=%d",
             i_huid, i_attrId, i_size );

    TARGETING::Target* l_targ{};

    if(0xFFFFFFFF == i_huid)
    {
        TARGETING::targetService().getTopLevelTarget(l_targ);
    }
    else
    {
        l_targ = getTargetFromHUID(i_huid);
    }

    if( l_targ == NULL )
    {
        o_output = new char[100];
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    uint8_t l_data[i_size];
    bool l_try = l_targ->_tryGetAttr( (TARGETING::ATTRIBUTE_ID)i_attrId,
                                      i_size, l_data );
    if( !l_try )
    {
        o_output = new char[100];
        sprintf( o_output, "Error reading %.8X", i_attrId );
        return;
    }

    // "Targ[12345678] Attr[12345678] = 0x12345678...\n"
    o_output = new char[50 + i_size*2];
    if( i_size == 1 )
    {
        uint8_t* l_data8 = (uint8_t*)(l_data);
        sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.2X\n",
                 i_huid, i_attrId, *l_data8 );
    }
    else if( i_size == 2 )
    {
        uint16_t* l_data16 = (uint16_t*)(l_data);
        sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.4X\n",
                 i_huid, i_attrId, *l_data16 );
    }
    else if( i_size == 4 )
    {
        uint32_t* l_data32 = (uint32_t*)(l_data);
        sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.8X\n",
                 i_huid, i_attrId, *l_data32 );
    }
    else if( i_size == 8 )
    {
        uint64_t* l_data64 = (uint64_t*)(l_data);
        sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x%.8X%.8X\n",
                 i_huid, i_attrId, (uint32_t)(*l_data64>>32),
                 (uint32_t)*l_data64 );
    }
    else // give up on pretty-printing and just dump the hex
    {
        sprintf( o_output, "Targ[%.8X] Attr[%.8X] = 0x", i_huid, i_attrId );
        size_t l_len1 = strlen(o_output);
        for( size_t i=0; i<i_size; i++ )
        {
            sprintf( &(o_output[l_len1+i]), "%.2X", l_data[i] );
        }
        o_output[l_len1+i_size*2] = '-';
        o_output[l_len1+i_size*2+1] = '\n';
        o_output[l_len1+i_size*2+2] = '\0';
    }
}


/**
 * @brief Read or write data out/into SPD, MVPD or PVPD
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_rtCmd  write or read data flag
 * @param[in] i_huid  HUID associated with Target to read/write to/from
 * @param[in] i_keyword keyword to be used for SPD, MVPD or PVPD
 * @param[in] i_record  record to be used for MVPD or PVPD
 * @param[in] i_data The data supplied for a write or returned from a read
 */
void cmd_readwritevpd(char*& o_output, DeviceFW::OperationType i_rtCmd,
                      uint32_t i_huid, uint64_t i_keyword,
                      uint64_t i_record = 0, uint64_t i_data = 0)
{
    UTIL_FT( "cmd_readwritevpd> rtcmd=%s, huid=%.8X, "
             "keyword=%lx, record=%lx, data=%lx",
             (i_rtCmd == DeviceFW::OperationType::READ ? "read" : "write"),
              i_huid, i_keyword, i_record, i_data);

    o_output = new char[100];   // info for user to consume
    char o_readWriteCmd[20];    // repeat the command the user requested
    bool l_isSpd(false);        // are we doing SPD command
    size_t l_size(0);           // size of the date from/to device read/write
    errlHndl_t l_errhdl(nullptr); // handle to capture errors

    do
    {
        // get the target, if it exists from user supplied HUID
        TARGETING::Target* l_target = getTargetFromHUID(i_huid);
        if (nullptr == l_target)
        {
           sprintf( o_output, "HUID %.8X not found", i_huid );
           break;
        }

       // get the TYPE of the HUID (we are looking for DIMM, PROC and NODE)
       TARGETING::AttributeTraits<TARGETING::ATTR_TYPE>::Type l_targetType;
       if (!l_target->tryGetAttr<TARGETING::ATTR_TYPE>(l_targetType))
       {
           sprintf( o_output, "No TARGETING::ATTR_TYPE associated "
                              "with HUID %.8X", i_huid );
           break;
       }

       // vector to hold data that will be returned/sent to device read/write
       std::vector<uint64_t> l_dataVec;

       if (DeviceFW::OperationType::READ == i_rtCmd)   // reading data from vpd
       {
          if (TARGETING::TYPE_DIMM == l_targetType)  // SPD
          {
              sprintf( o_readWriteCmd, "read SPD");
              l_isSpd = true;

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                    DEVICE_SPD_ADDRESS(i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // read in the data
              l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
                                    DEVICE_SPD_ADDRESS(i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else if (TARGETING::TYPE_PROC == l_targetType)  // MVPD
          {
              sprintf( o_readWriteCmd, "read MVPD");

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                    DEVICE_MVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // read in the data
              l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
                                    DEVICE_MVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else if (TARGETING::TYPE_NODE == l_targetType)  // PVPD
          {
              sprintf( o_readWriteCmd, "read PVPD");

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                    DEVICE_PVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // read in the data
              l_errhdl = deviceRead(l_target, &l_dataVec.front(), l_size,
                                    DEVICE_PVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else
          {
              sprintf( o_output, "cmd_readvpd> VPD %.8X is currently not"
                        " supported for HUID %.8x", l_targetType, i_huid);
              break;
          }
       }
       else   // writing data to vpd
       {
          if (TARGETING::TYPE_DIMM == l_targetType)  // SPD
          {
              sprintf( o_readWriteCmd, "write SPD");
              l_isSpd = true;

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                    DEVICE_SPD_ADDRESS(i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // populate buffer with user data, repeat user data
              // if necessary to fill buffer
              for (size_t i = 0; i < l_dataVec.size(); ++i)
              {
                 l_dataVec[i] = i_data;
              }

              // write the data to the VPD
              l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
                                     DEVICE_SPD_ADDRESS(i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else if (TARGETING::TYPE_PROC == l_targetType)  // MVPD
          {
              sprintf( o_readWriteCmd, "write MVPD");

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                    DEVICE_MVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // populate buffer with user data, repeat user data
              // if necessary to fill buffer
              for (size_t i = 0; i < l_dataVec.size(); ++i)
              {
                 l_dataVec[i] = i_data;
              }

              l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
                                    DEVICE_MVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else if (TARGETING::TYPE_NODE == l_targetType)  // PVPD
          {
              sprintf( o_readWriteCmd, "write PVPD");

              // first get size of data with NULL call
              l_errhdl = deviceRead(l_target, NULL, l_size,
                                     DEVICE_PVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }

              // resize buffer to hold data, +1 to get "trailing bytes"
              l_dataVec.resize(l_size/sizeof(uint64_t) + 1);

              // populate buffer with user data, repeat user data
              // if necessary to fill buffer
              for (size_t i = 0; i < l_dataVec.size(); ++i)
              {
                 l_dataVec[i] = i_data;
              }

              l_errhdl = deviceWrite(l_target, &l_dataVec.front(), l_size,
                                     DEVICE_PVPD_ADDRESS(i_record, i_keyword));
              if (l_errhdl)
              {
                  break;
              }
          }
          else
          {
              sprintf( o_output, "cmd_writevpd> VPD %.8X is currently not"
                        " supported for HUID %.8x", l_targetType, i_huid);
              break;
          }
       }

       // resize o_output to hold the extra data from the device read/writes
       delete o_output;
       size_t l_newOutputSize = 100 +
                 (l_dataVec.size() * sizeof(uint64_t) * 2) + l_dataVec.size();
       o_output = new char[l_newOutputSize];

       if (l_isSpd)
       {
           // write out results for SPD
           sprintf( o_output, "%s - HUID=%.8X Keyword=%.8X %.8X, Data=",
                    &o_readWriteCmd,
                    i_huid,
                    (uint32_t)(i_keyword>>32), (uint32_t)i_keyword);
       }
       else
       {
           // write out results for MVPD or PVPD
           sprintf( o_output, "%s - HUID=%.8X Record=%.8X %.8X, "
                              "Keyword=%.8X %.8X, Data=",
                    &o_readWriteCmd,
                    i_huid,
                    (uint32_t)(i_record>>32), (uint32_t)i_record,
                    (uint32_t)(i_keyword>>32), (uint32_t)i_keyword);
       }

       // write out the data from the device read/write
       // first get the data that is a multiple of 8
       size_t l_len(strlen(o_output));
       uint64_t l_tempValue(0);

       size_t i(0);
       for (; i < l_dataVec.size() -1; ++i )
       {
           if( i % 4 == 0 )
           {
               sprintf(&o_output[l_len],"\n");
               l_len = strlen(o_output);
           }

           l_tempValue = l_dataVec[i];
           sprintf(&o_output[l_len],"%.8X ",(uint32_t)(l_tempValue>>32));
           l_len = strlen(o_output);

           sprintf(&o_output[l_len],"%.8X",(uint32_t)(l_tempValue));
           l_len = strlen(o_output);
       }

       // write out the rest of the date that is not a multiple of 8
       uint8_t* l_lastBytes = (uint8_t*)(&(l_dataVec[i]));
       size_t l_numLastBytes = l_size % sizeof(uint64_t);

       if (l_numLastBytes)
       {
           sprintf(&o_output[l_len],"\n");
           l_len = strlen(o_output);

           for (size_t i = 0; i < l_numLastBytes; ++i)
           {
              sprintf(&o_output[l_len],"%.2X", l_lastBytes[i]);
              l_len = strlen(o_output);

              if (i == 4)
              {
                 sprintf(&o_output[l_len]," ");
                 l_len = strlen(o_output);
              }
           }
       }
   } while(0);

   if (l_errhdl)
   {
      sprintf( o_output, "cmd_readwritevpd> FAIL - %s: RC=%.4X",
               &o_readWriteCmd,
               ERRL_GETRC_SAFE(l_errhdl) );
   }
}


/**
 * @brief Read data out of pnor
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_section  PNOR section id
 * @param[in] i_bytes  Number of bytes to read
 */
void cmd_readpnor( char*& o_output,
                   uint32_t i_section,
                   uint32_t i_bytes )
{
    UTIL_FT( "cmd_readpnor> section=%d, bytes=%d", i_section, i_bytes );

    PNOR::SectionInfo_t l_pnor;
    errlHndl_t l_errhdl = PNOR::getSectionInfo( (PNOR::SectionId)i_section,
                                                l_pnor );
    if( l_errhdl )
    {
        UTIL_FT( "cmd_readpnor> Error from getSectionInfo()" );
        o_output = new char[100];
        sprintf( o_output, "Error from getSectionInfo()" );
        delete l_errhdl;
        l_errhdl = nullptr;
        return;
    }

    o_output = new char[50 + i_bytes*2];
    sprintf( o_output, "PNOR[%d] : name=%s, size=0x%X = 0x",
             i_section, l_pnor.name, l_pnor.size );
    uint8_t* l_ptr = (uint8_t*)l_pnor.vaddr;
    size_t l_len1 = strlen(o_output);
    for( size_t i=0; i<i_bytes; i++ )
    {
        sprintf( &(o_output[l_len1+2*i]), "%.2X", l_ptr[i] );
    }
    o_output[l_len1+i_bytes*2] = '-';
    o_output[l_len1+i_bytes*2+1] = '\n';
    o_output[l_len1+i_bytes*2+2] = '\0';

    UTIL_FT( "PNOR[%d] : name=%s, size=0x%X = 0x",
             i_section, l_pnor.name, l_pnor.size );
    TRACFBIN( Util::g_util_trace, "PNOR", l_ptr, i_bytes );
}


/**
 * @brief Read a scom register
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_huid  Target to read scom from
 * @param[in] i_addr  Scom address
 */
void cmd_getscom( char*& o_output,
                  uint32_t i_huid,
                  uint64_t i_addr )
{
    UTIL_FT( "cmd_getscom> huid=%.8X, addr=%X%.8X",
             i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr );
    o_output = new char[100];

    TARGETING::Target* l_targ = getTargetFromHUID(i_huid);
    if( l_targ == NULL )
    {
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    uint64_t l_data = 0;
    size_t l_size = sizeof(uint64_t);
    errlHndl_t l_errhdl = deviceRead(l_targ,
                                     &l_data,
                                     l_size,
                                     DEVICE_SCOM_ADDRESS(i_addr));
    if( l_errhdl )
    {
        sprintf( o_output, "cmd_getscom> FAIL: RC=%.4X",
                 ERRL_GETRC_SAFE(l_errhdl) );
        return;
    }
    else
    {
        sprintf( o_output, "HUID=%.8X Addr=%X%.8X, Data=%.8X %.8X",
                 i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr,
                 (uint32_t)(l_data>>32), (uint32_t)l_data );
        return;
    }
}


/**
 * @brief Write a scom register
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_huid  Target to read scom from
 * @param[in] i_addr  Scom address
 * @param[in] i_data  Scom data to write
 */
void cmd_putscom( char*& o_output,
                  uint32_t i_huid,
                  uint64_t i_addr,
                  uint64_t i_data )
{
    UTIL_FT( "cmd_putscom> huid=%.8X, addr=%X%.8X, data=%.8X %.8X",
             i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr,
             (uint32_t)(i_data>>32), (uint32_t)i_data );
    o_output = new char[100];

    TARGETING::Target* l_targ = getTargetFromHUID(i_huid);
    if( l_targ == NULL )
    {
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    size_t l_size = sizeof(uint64_t);
    errlHndl_t l_errhdl = deviceWrite( l_targ,
                                       &i_data,
                                       l_size,
                                       DEVICE_SCOM_ADDRESS(i_addr));
    if( l_errhdl )
    {
        sprintf( o_output, "cmd_putscom> FAIL: RC=%.4X",
                 ERRL_GETRC_SAFE(l_errhdl) );
        return;
    }
    else
    {
        sprintf( o_output, "HUID=%.8X Addr=%X%.8X",
                 i_huid, (uint32_t)(i_addr>>32), (uint32_t)i_addr );
        return;
    }
}


/**
 * @brief Create and commit an error log
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_word1  Userdata 1 & 2
 * @param[in] i_word2  Userdata 3 & 4
 * @param[in] i_callout  HUID of target to callout (zero if none)
 * @param[in] i_ffdcLength  Additional ffdc data bytes to add to the error log
 * @param[in] i_deconfig  Indication if callout target should be deconfigured
 * @param[in] i_gard  Indication of type of failure for callout
 */
void cmd_errorlog( char*& o_output,
                   uint64_t i_word1,
                   uint64_t i_word2,
                   uint32_t i_callout,
                   uint32_t i_ffdcLength,
                   HWAS::DeconfigEnum i_deconfig,
                   HWAS::GARD_ErrorType i_gard )
{
    UTIL_FT( "cmd_errorlog> word1=%.8X%.8X, word2=%.8X%.8X, i_callout=%.8X ffdcLength=%ld, deconfig=%.2X, gard=%.2X",
             (uint32_t)(i_word1>>32), (uint32_t)i_word1,
             (uint32_t)(i_word2>>32), (uint32_t)i_word2, i_callout,
             i_ffdcLength, i_deconfig, i_gard );
    o_output = new char[100];

    errlHndl_t l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_PREDICTIVE,
                                                Util::UTIL_RT_CMDS,
                                                Util::UTIL_ERC_NONE,
                                                i_word1,
                                                i_word2,
                                                false );
    TARGETING::Target* l_targ = getTargetFromHUID(i_callout);
    if( l_targ != NULL )
    {
        l_err->addHwCallout( l_targ,
                             HWAS::SRCI_PRIORITY_HIGH,
                             i_deconfig,
                             i_gard );
    }

    if (i_ffdcLength > 0)
    {
        uint8_t l_count = 0;
        uint16_t l_packet_size = 256; // break i_ffdcLength into packets
        uint8_t data[l_packet_size];

        do {
            if (i_ffdcLength > l_packet_size)
            {
                i_ffdcLength -= l_packet_size;
            }
            else
            {
                l_packet_size = i_ffdcLength;
                i_ffdcLength = 0;
            }
            memset(data, l_count, l_packet_size);

            l_err->addFFDC(UTIL_COMP_ID,
                         &data,
                         l_packet_size,
                         0,         // Version
                         ERRORLOG::ERRL_UDT_NOFORMAT,   // parser ignores data
                         false );   // merge
            l_count++;
        } while (i_ffdcLength > 0);

        // Change the default eSEL type if i_word1 is equal to 1
        if (i_word1 == 1)
        {
            // mark error as callhome information eSEL 'dd' type
            // Mimics error passed down by the OCC
            l_err->setSev(ERRORLOG::ERRL_SEV_INFORMATIONAL);
            l_err->setEselCallhomeInfoEvent(true);
        }
    }

    l_err->collectTrace("UTIL", 1024);

    uint32_t l_plid = l_err->plid();
    errlCommit(l_err, UTIL_COMP_ID);
    sprintf( o_output, "Committed plid 0x%.8X", l_plid );
}


/**
 * @brief Process an SBE Message with a pass-through request
 * @param[out] o_output  Output display buffer, memory allocated here
 * @param[in] i_chipId   Processor chip ID
 */
void cmd_sbemsg( char*& o_output,
                 uint32_t i_chipId)
{
    UTIL_FT( "cmd_sbemsg> chipId=%.8X",
             i_chipId);
    o_output = new char[100];

    int rc = 0;

    do
    {
        // Get the runtime interface object
        runtimeInterfaces_t *l_rt_intf = getRuntimeInterfaces();
        if(nullptr == l_rt_intf)
        {
            rc = -2;
            sprintf( o_output, "Not able to get run time interface object");
            return;
        }

        rc = l_rt_intf->sbe_message_passing(i_chipId);
        if(0 != rc)
        {
            sprintf( o_output, "Unexpected return from RT SBE message passing. "
                     "Return code: 0x%.8X for chipID: 0x%.8X", rc, i_chipId);
            return;
        }
    }while (0);

    sprintf( o_output, "SBE message passing command for chipID 0x%.8X returned "
                       "rc 0x%.8X", i_chipId, rc );
}

int cmd_reload_pm_complex( char*& o_output, uint64_t stopAt )
{
    // NOTE: this is running in a 32K hbrt -exec stack instead of
    //       the normal 64K hbrt stack
    o_output = new char[100*8];
    char l_tmpstr[100];
    int rc = 0;

    sprintf(o_output, "cmd_reload_pm_complex >>\n");
    UTIL_FT("cmd_reload_pm_complex >>");
    uint64_t l_chip;
    uint64_t l_occ_common_addr;
    uint64_t l_homerPhysAddr;
    uint32_t l_mode = HBRT_PM_RELOAD;

    stopImageSection::SprRestoreArea_t * coreThreadRestoreBEFORE =
        (stopImageSection::SprRestoreArea_t *) new stopImageSection::SprRestoreArea_t[MAX_CORES_PER_CHIP][MAX_THREADS_PER_CORE];
    uint64_t coreThreadRestoreSize = sizeof(stopImageSection::SprRestoreArea_t)*MAX_CORES_PER_CHIP*MAX_THREADS_PER_CORE;

    TARGETING::Target* l_sys = nullptr;
    TARGETING::targetService().getTopLevelTarget(l_sys);
    assert(l_sys != nullptr);
    l_occ_common_addr = l_sys->getAttr<TARGETING::ATTR_OCC_COMMON_AREA_PHYS_ADDR>();

    TARGETING::TargetHandleList l_procChips;
    TARGETING::getAllChips(l_procChips, TARGETING::TYPE_PROC, true);

    // auto run through processor chips using attribute settings
    for (const auto & l_procChip: l_procChips)
    {
        // This attr was set during istep15 HCODE build
        l_homerPhysAddr = l_procChip->
                getAttr<TARGETING::ATTR_HOMER_PHYS_ADDR>();
        l_chip = l_procChip->getAttr<TARGETING::ATTR_POSITION>();

        // GET BEFORE SNAPSHOT OF MEMORY
        // Use this function as the virtual address gets reset to 0
        void* l_homerVAddr = HBPM::convertHomerPhysToVirt(l_procChip,
                                                    l_homerPhysAddr);
        if(nullptr == l_homerVAddr)
        {
            UTIL_FT(ERR_MRK"cmd_reload_pm_complex: "
                       "convertHomerPhysToVirt failed! "
                       "HOMER_Phys=0x%0lX", l_homerPhysAddr );
            break;
        }


        UTIL_FT("Get BEFORE snapshot of memory");
        stopImageSection::HomerSection_t *l_virt_addr =
              reinterpret_cast<stopImageSection::HomerSection_t*>(l_homerVAddr);

        if (l_virt_addr == nullptr)
        {
            sprintf(o_output, "ATTR_HOMER_VIRT_ADDR for %d chip returned 0\n",
                    l_chip);
            break;
        }

        UTIL_FT("%d: memcpy(%p, %p, %ld)", l_chip, coreThreadRestoreBEFORE,
            l_virt_addr->iv_coreThreadRestore, coreThreadRestoreSize);
        sprintf( l_tmpstr, "%d: memcpy(%p, %p, %ld)\n", l_chip,
            coreThreadRestoreBEFORE, l_virt_addr->iv_coreThreadRestore,
            coreThreadRestoreSize );
        strcat( o_output, l_tmpstr );
        if (stopAt == 1)
        {
            break;
        }
        memcpy( coreThreadRestoreBEFORE,
                l_virt_addr->iv_coreThreadRestore,
                coreThreadRestoreSize);

        // RUN LOAD_PM_COMPLEX
        UTIL_FT("Calling reload_pm_complex(%d, 0x%16llX, 0x%16llX, %s)",
                l_chip, l_homerPhysAddr, l_occ_common_addr,
                (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD");
        sprintf( l_tmpstr,
                "Calling reload_pm_complex(%d, 0x%16llX, 0x%16llX, %s)\n",
                l_chip, l_homerPhysAddr, l_occ_common_addr,
                (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD");
        strcat( o_output, l_tmpstr );
        if (stopAt == 2)
        {
            break;
        }
        rc = RTPM::load_pm_complex( l_chip, l_homerPhysAddr,
                                    l_occ_common_addr, l_mode );
        if (rc)
        {
            sprintf( l_tmpstr,
             "FAILURE: reload_pm_complex(%x, 0x%llx, 0x%llx, %x) returned %d\n",
             l_chip, l_homerPhysAddr, l_occ_common_addr, l_mode, rc );
            strcat( o_output, l_tmpstr );
            break;
        }

        // GET AFTER SNAPSHOT OF MEMORY
        UTIL_FT("Get AFTER snapshot of memory");
        if (stopAt == 3)
        {
            break;
        }

        // NOW COMPARE THE TWO SNAPSHOTS
        uint8_t lastMatch = memcmp(coreThreadRestoreBEFORE,
                                   l_virt_addr->iv_coreThreadRestore,
                                   coreThreadRestoreSize);
        // Both sections should be equal as
        // hostboot should NOT touch this section of memory
        if (lastMatch == 0)
        {
            // Verify non-zero exists
            stopImageSection::SprRestoreArea_t zeroedSprArea;
            memset(&zeroedSprArea, 0x00, sizeof(zeroedSprArea));
            bool foundNonZero = false;

            for (int x = 0; x < MAX_CORES_PER_CHIP; x++)
            {
                for (int y = 0; y < MAX_THREADS_PER_CORE; y++)
                {
                    // Check for non-zero threadArea
                    if ( 0 != memcmp(&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_threadArea),
                                &zeroedSprArea.iv_threadArea,
                                sizeof(zeroedSprArea.iv_threadArea)))
                    {
                        UTIL_FT("Found non-zero value in row %d, column %d threadArea", x, y);
                        UTIL_FBIN("Thread Area",
                            &(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_threadArea),
                            sizeof(zeroedSprArea.iv_threadArea));
                        foundNonZero = true;
                    }
                    // Check for non-zero coreArea
                    if ( 0 != memcmp(&(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_coreArea),
                                &zeroedSprArea.iv_coreArea,
                                sizeof(zeroedSprArea.iv_coreArea)))
                    {
                        UTIL_FT("Found non-zero value in row %d, column %d coreArea", x, y);
                        UTIL_FBIN("Core Area",
                            &(((stopImageSection::SprRestoreArea_t*)((char*)coreThreadRestoreBEFORE + (sizeof(zeroedSprArea)*x + sizeof(zeroedSprArea)*y)))->iv_coreArea),
                            sizeof(zeroedSprArea.iv_coreArea));
                        foundNonZero = true;
                    }
                }
            }
            if (foundNonZero)
            {
                UTIL_FT("SUCCESS: reload_pm_complex in %s mode: CHIP %d worked", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
                sprintf( l_tmpstr, "SUCCESS: reload_pm_complex in %s mode: CHIP %d worked\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
                strcat( o_output, l_tmpstr );
            }
            else
            {
                UTIL_FT("CONDITIONAL SUCCESS: reload_pm_complex in %s mode: CHIP %d worked with zeroed area", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
                sprintf( l_tmpstr, "CONDITIONAL SUCCESS: reload_pm_complex in %s mode: CHIP %d worked with zeroed area\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip);
                strcat( o_output, l_tmpstr );
            }
        }
        else
        {
            UTIL_FT("FAILURE: reload_pm_complex in %s mode: CHIP %d, first mismatch at %d", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip, lastMatch);
            sprintf( l_tmpstr, "FAILURE: reload_pm_complex in %s mode: CHIP %d, first mismatch at %d\n", (HBPM::PM_LOAD == l_mode) ? "LOAD" : "RELOAD", l_chip, lastMatch);
            strcat( o_output, l_tmpstr );

            UTIL_FBIN("BEFORE coreThreadRestore", &coreThreadRestoreBEFORE, coreThreadRestoreSize);
            UTIL_FBIN("AFTER  coreThreadRestore", l_virt_addr->iv_coreThreadRestore, coreThreadRestoreSize);
        }
    }
    delete coreThreadRestoreBEFORE;

    sprintf(l_tmpstr, "<< cmd_reload_pm_complex\n");
    strcat(o_output, l_tmpstr);
    UTIL_FT("<< cmd_reload_pm_complex");

    return rc;
}


/**
 * @brief Read version of HBRT
 * @param[out] o_output  Output display buffer, memory allocated here
 */
void cmd_readHBRTversion( char*& o_output )
{
    UTIL_FT( "cmd_readHBRTversion");

    const char * const l_title = "Hostboot Build ID: ";
    o_output = new char[strlen(l_title) + strlen(&hbi_ImageId) + 1];
    // Set beginning of output string
    strcpy(o_output, l_title);
    // Concatenate the Hostboot Image ID
    strcat(o_output, &hbi_ImageId);

    UTIL_FT( "%s", o_output);
}


/**
 * @brief Execute function to prepare targeting data for an HBRT update
 * @param[out] o_output  Output display buffer, memory allocated here
 */
void cmd_hbrt_update(char*& o_output)
{
    UTIL_FT( "cmd_hbrt_update>");
    o_output = new char[100];

    int rc = 0;

    do
    {
        // Get the runtime interface object
        runtimeInterfaces_t *l_rt_intf = getRuntimeInterfaces();
        if(nullptr == l_rt_intf)
        {
            rc = -2;
            sprintf( o_output, "Not able to get run time interface object");
            return;
        }

        rc = l_rt_intf->prepare_hbrt_update();
        if(0 != rc)
        {
            sprintf( o_output, "Unexpected return from RT prepare HBRT update. "
                     "Return code: 0x%.8X", rc);
            return;
        }
    }while (0);

    sprintf( o_output, "Prepare HBRT update command returned rc 0x%.8X", rc );
}


/**
 * @brief Mark a target as requiring access to its SCOMs through the FSP
 * @param[out] o_output     Output display buffer, memory allocated here
 * @param[in]  i_huid       HUID associated with Target to switch access on
 */
void cmd_switchToFspScomAccess( char*& o_output, uint32_t i_huid)
{
    UTIL_FT( "cmd_switchToFspScomAccess> huid=%.8X", i_huid );

    TARGETING::Target* l_targ{};

    if(0xFFFFFFFF == i_huid)
    {
        TARGETING::targetService().getTopLevelTarget(l_targ);
    }
    else
    {
        l_targ = getTargetFromHUID(i_huid);
    }

    o_output = new char[100];
    if( l_targ == NULL )
    {
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    FSISCOM::switchToFspScomAccess(l_targ);

    sprintf( o_output, "switchToFspScomAccess executed");
}


/**
 * @brief Send a scom operation (read/write) to the FSP
 * @param[out] o_output     Output display buffer, memory allocated here
 * @param[in]  i_op         Operation: r or w
 * @param[in]  i_huid       HUID associated with Target to get the SCOM from
 * @param[in]  i_scomAddr   Address of SCOM to read or write
 * @param[in]  io_scomValue Buffer for read SCOM value, or value to write
 */
void cmd_sendScomOpToFSP( char*&   o_output,
                          char     i_op,
                          uint32_t i_huid,
                          uint64_t i_scomAddr,
                          uint64_t *io_scomValue )
{
    UTIL_FT( "cmd_getScomFromFSP> op=%c, huid=%.8X, addr=%.8X, size=%d",
             i_op, i_huid, i_scomAddr, *io_scomValue );

    TARGETING::Target* l_targ{};

    if(0xFFFFFFFF == i_huid)
    {
        TARGETING::targetService().getTopLevelTarget(l_targ);
    }
    else
    {
        l_targ = getTargetFromHUID(i_huid);
    }

    o_output = new char[100];
    if( l_targ == NULL )
    {
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    DeviceFW::OperationType l_op;
    switch (i_op) {
        case 'r':
        case 'R':
            l_op = DeviceFW::READ;
            break;
        case 'w':
        case 'W':
            l_op = DeviceFW::WRITE;
            break;
        default:
            sprintf( o_output, "Operation must be r or w: %c", i_op );
            return;
    }

    errlHndl_t l_err = nullptr;
    l_err = FSISCOM::sendScomOpToFsp(l_op, l_targ, i_scomAddr,
                                     (void *)io_scomValue);
    if (l_err)
    {
            sprintf( o_output, "Error on call to sendScomOpToFsp, rc=%.4X",
                     ERRL_GETRC_SAFE(l_err) );
            return;
    }

    sprintf( o_output, "op=%c, huid=%.16llX, scomAddr=%.16llX, scomValue=%.16llX",
             i_op, i_huid, i_scomAddr, *io_scomValue);
}


/**
 * @brief Send a multi scom read to the FSP
 * @param[out] o_output     Output display buffer, memory allocated here
 * @param[in]  i_huid       HUID associated with Target to get the SCOMs from
 * @param[in]  i_scomAddr   Addresses of SCOMs to read
 * @param[in]  o_scomValue  Values of read SCOMs
 */
void cmd_sendMultiScomReadToFSP( char*                 &o_output,
                                 uint32_t               i_huid,
                                 std::vector<uint64_t> &i_scomAddr,
                                 std::vector<uint64_t> &o_scomValue )
{
    UTIL_FT( "cmd_sendMultiScomReadToFSP> huid=%.8X, num_SCOMs=%d,"
             " num_outSCOMs=%d",
             i_huid, i_scomAddr.size(), o_scomValue.size() );

    TARGETING::Target* l_targ{};

    if(0xFFFFFFFF == i_huid)
    {
        TARGETING::targetService().getTopLevelTarget(l_targ);
    }
    else
    {
        l_targ = getTargetFromHUID(i_huid);
    }

    o_output = new char[500];
    if( l_targ == NULL )
    {
        sprintf( o_output, "HUID %.8X not found", i_huid );
        return;
    }

    errlHndl_t l_err = nullptr;
    l_err = FSISCOM::sendMultiScomReadToFsp( l_targ, i_scomAddr, o_scomValue);
    if (l_err)
    {
            sprintf( o_output, "Error on call to sendMultiScomReadToFsp,"
                               " rc=%.4X", ERRL_GETRC_SAFE(l_err) );
            return;
    }

    sprintf( o_output, "num_outSCOMs=%d", o_scomValue.size());
    for (auto scom: o_scomValue)
    {
        char tmp_str[100];

        sprintf( tmp_str, ", %.8llX", scom);
        strcat( o_output, tmp_str);
    }
}

#ifdef CONFIG_NVDIMM
void cmd_nvdimm_protection_msg( char* &o_output, uint32_t i_huid,
                               uint32_t protection )
{
    errlHndl_t l_err = nullptr;
    o_output = new char[500];

    TARGETING::Target* l_targ{};
    l_targ = getTargetFromHUID(i_huid);

    // protection should match enum from nvdimm_protection_t
    // No match will just return, no error generated
    l_err = notifyNvdimmProtectionChange( l_targ,
                                (NVDIMM::nvdimm_protection_t)protection);
    if (l_err)
    {
        sprintf( o_output, "Error on call to notifyNvdimmProtectionChange"
                "(0x%.8X, %d), rc=0x%.8X, plid=0x%.8X",
                i_huid, protection, ERRL_GETRC_SAFE(l_err), l_err->plid() );
        errlCommit(l_err, UTIL_COMP_ID);
    }
}

/**
 * @brief Check the ES (energy source) health status of all NVDIMMs in the
 *         system. If check fails, see HBRT traces for further details.
 * @param[out] o_output  Output display buffer, memory allocated here.
 *                       Will inform caller if ES health check passes or fails.
 */
void cmd_nvDimmEsCheckHealthStatus( char* &o_output)
{
    o_output = new char[500];
    if (NVDIMM::nvDimmEsCheckHealthStatusOnSystem())
    {
        sprintf( o_output, "cmd_nvDimmEsCheckHealthStatus: "
                           "ES (energy source) health status check passed.");

    }
    else
    {
        sprintf( o_output, "cmd_nvDimmEsCheckHealthStatus: "
                           "ES (energy source) health status check failed. "
                           "Inspect HBRT traces for further details.");

    }

    return;
}  // end cmd_nvDimmEsCheckHealthStatus

/**
 * @brief Check the NVM (non-volatile memory) health status of all NVDIMMs in
 *         the system. If check fails, see HBRT traces for further details.
 * @param[out] o_output  Output display buffer, memory allocated here.
 *                       Will inform caller if NVM health check passes or fails.
 */

void cmd_nvdDmmNvmCheckHealthStatus( char* &o_output)
{
    o_output = new char[500];
    if (NVDIMM::nvDimmNvmCheckHealthStatusOnSystem())
    {
        sprintf( o_output, "cmd_nvdDmmNvmCheckHealthStatus: "
                       "NVM (non-volatile memory) health status check passed.");

    }
    else
    {
        sprintf( o_output, "cmd_nvdDmmNvmCheckHealthStatus: "
                       "NVM (non-volatile memory) health status check failed. "
                       "Inspect HBRT traces for further details.");

    }

    return;
}  // end cmd_nvdDmmNvmCheckHealthStatus


#endif

/**
 * @brief  Execute an arbitrary command inside Hostboot Runtime
 * @param[in]   Number of arguments (standard C args)
 * @param[in]   Array of argument values (standard C args)
 * @param[out]  Response message (NULL terminated), memory allocated
 *              by hbrt, if o_outString is NULL then no response will
 *              be sent
 * @return 0 on success, else error code
 */
int hbrtCommand( int argc,
                 const char** argv,
                 char** o_outString )
{
    int rc = 0;
    UTIL_FT("Executing run_command : argc=%d, o_outString=%p",
                argc, o_outString);

    if( !argc )
    {
        UTIL_FT("run_command : Number of arguments = 0");
        return rc;
    }

    if( argv == NULL )
    {
        UTIL_FT("run_command : Argument array is empty");
        return rc;
    }

    for( int aa=0; aa<argc; aa++ )
    {
        UTIL_FT("run_command : %d='%s'",aa,argv[aa]);
    }

    // If no output is specified, trace it instead
    bool l_traceOut = false;
    char* l_outPtr = NULL; //local value to use if needed
    char** l_output = o_outString;
    if( o_outString == NULL )
    {
        l_output = &l_outPtr;
        l_traceOut = true;
    }

    // Test path
    if( (argc == 2) && !strcmp( argv[0], "testRunCommand" ) )
    {
        *l_output = new char[strlen(argv[1])+1+5];//arg0+arg1+\0
        sprintf( *l_output, "TEST:%s", argv[1] );
    }
    else if( !strcmp( argv[0], "readvpd" ))
    {
        // readvpd <huid> <keyword> [<record>]
        if (argc == 3)
        {
            cmd_readwritevpd( *l_output,
                         DeviceFW::OperationType::READ,
                         strtou64( argv[1], NULL, 16 ),   // huid
                         strtou64( argv[2], NULL, 16 ));  // keyword

        }
        else if (argc == 4)
        {
            cmd_readwritevpd( *l_output,
                         DeviceFW::OperationType::READ,
                         strtou64( argv[1], NULL, 16 ),   // huid
                         strtou64( argv[2], NULL, 16 ),   // keyword
                         strtou64( argv[3], NULL, 16 ));  // record
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: readvpd <huid> <keyword> [<record>]\n" );
        }
    }
    else if( !strcmp( argv[0], "writevpd" ) )
    {
        // writevpd <vpd> <huid> <keyword> [<record>] <data>
        if( argc == 4 )
        {
            cmd_readwritevpd( *l_output,
                         DeviceFW::OperationType::WRITE,
                         strtou64( argv[1], NULL, 16 ),   // huid
                         strtou64( argv[2], NULL, 16 ),   // keyword
                         0,                               // record
                         strtou64( argv[3], NULL, 16 ));   // data
        }
        else if (argc == 5)
        {
            cmd_readwritevpd( *l_output,
                         DeviceFW::OperationType::WRITE,
                         strtou64( argv[1], NULL, 16 ),   // huid
                         strtou64( argv[2], NULL, 16 ),   // keyword
                         strtou64( argv[3], NULL, 16 ),   // record
                         strtou64( argv[4], NULL, 16 ));  // data
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: writevpd <huid> <keyword> [<record>] <data>\n" );
        }
    }
    else if( !strcmp( argv[0], "getattr" ) )
    {
        // getattr <huid> <attribute id> <size>
        if( argc == 4 )
        {
            cmd_getattr( *l_output,
                         strtou64( argv[1], NULL, 16 ),
                         strtou64( argv[2], NULL, 16 ),
                         strtou64( argv[3], NULL, 16 ) );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: getattr <huid> <attribute id> <size>\n" );
        }
    }
    else if( !strcmp( argv[0], "readpnor" ) )
    {
        // readpnor <pnor section> <bytes to read>
        if( argc == 3 )
        {
            cmd_readpnor( *l_output,
                          strtou64( argv[1], NULL, 16 ),
                          strtou64( argv[2], NULL, 16 ) );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: getpnor <pnor section> <bytes to read>\n" );
        }
    }
    else if( !strcmp( argv[0], "getscom" ) )
    {
        // getscom <huid> <address>
        if( argc == 3 )
        {
            cmd_getscom( *l_output,
                         strtou64( argv[1], NULL, 16 ),
                         strtou64( argv[2], NULL, 16 ) );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output, "ERROR: getscom <huid> <address>\n" );
        }
    }
    else if( !strcmp( argv[0], "putscom" ) )
    {
        // putscom <huid> <address> <data>
        if( argc == 4 )
        {
            cmd_putscom( *l_output,
                         strtou64( argv[1], NULL, 16 ),
                         strtou64( argv[2], NULL, 16 ),
                         strtou64( argv[3], NULL, 16 ) );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output, "ERROR: putscom <huid> <address> <data>\n" );
        }
    }
    else if( !strcmp( argv[0], "errorlog" ) )
    {
        // errorlog <word1> <word2> <huid to callout> <size> <deconfig> <gard>
        if( (argc == 3) || (argc == 4) || (argc == 5) || (argc == 6) ||
            (argc == 7) )
        {
            uint32_t l_huid = 0;
            uint32_t l_ffdcLength = 0;
            HWAS::DeconfigEnum l_deconfig = HWAS::NO_DECONFIG;
            HWAS::GARD_ErrorType l_gard = HWAS::GARD_NULL;
            if( argc >= 4 )
            {
                l_huid = strtou64( argv[3], NULL, 16 );
            }
            if (argc >= 5)
            {
                l_ffdcLength = strtou64( argv[4], NULL, 16 );
            }
            if( argc >= 6 )
            {
                l_deconfig = static_cast<HWAS::DeconfigEnum>(
                                 strtou64( argv[5], NULL, 16 ));
            }
            if( argc >= 7 )
            {
                l_gard = static_cast<HWAS::GARD_ErrorType>(
                             strtou64( argv[6], NULL, 16 ));
            }
            cmd_errorlog( *l_output,
                          strtou64( argv[1], NULL, 16 ),
                          strtou64( argv[2], NULL, 16 ),
                          l_huid,
                          l_ffdcLength,
                          l_deconfig,
                          l_gard );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output, "ERROR: errorlog <word1> <word2>\n" );
        }
    }
    else if( !strcmp( argv[0], "sbemsg" ) )
    {
        // sbemsg <chipid>
        if( argc == 2 )
        {
            cmd_sbemsg( *l_output,
                         strtou64( argv[1], NULL, 16 ) );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output, "ERROR: sbemsg <chipid>\n" );
        }
    }
    else if( !strcmp( argv[0], "reload_pm_complex" ) )
    {
        uint64_t breakPoint = 0;
        if (argc == 2)
        {
            breakPoint = strtou64( argv[1], NULL, 16 );
        }
        rc = cmd_reload_pm_complex(*l_output, breakPoint);
    }
    else if( !strcmp( argv[0], "readHBRTversion" ) )
    {
        // readHBRTversion
        if( argc == 1 )
        {
            cmd_readHBRTversion( *l_output );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: readHBRTversion\n" );
        }
    }
    else if( !strcmp( argv[0], "hbrt_update" ) )
    {
        // hbrt_update
        if( argc == 1 )
        {
            cmd_hbrt_update( *l_output );
        }
        else
        {
            *l_output = new char[100];
            sprintf( *l_output,
                     "ERROR: hbrt_update\n" );
        }
    }
    else if( !strcmp( argv[0], "switchToFspScomAccess" ) )
    {
        if (argc == 2)
        {
            cmd_switchToFspScomAccess( *l_output,
                                       strtou64(argv[1], NULL, 16)); // huid
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output,
                    "ERROR: switchToFspScomAccess <huid>");
        }
    }
    else if( !strcmp( argv[0], "scomOpToFsp" ) )
    {
        if ((argc == 4) || (argc == 5))
        {
            uint64_t l_scomValue = 0;

            if (argc == 5)
                l_scomValue = strtou64( argv[4], NULL, 16 );  // value

            cmd_sendScomOpToFSP( *l_output,
                                 argv[1][0],                  // op
                                 strtou64(argv[2], NULL, 16), // huid
                                 strtou64(argv[3], NULL, 16), // addr
                                 &l_scomValue );
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output,
                    "ERROR: scomOpToFsp <op> <huid> <scomAddr> [<scomValue>]");
        }
    }
    else if( !strcmp( argv[0], "multiScomReadToFsp" ) )
    {
        if (argc >= 3)
        {
            std::vector<uint64_t> l_scomAddrs, l_scomValues;

            for (int i = 2;i < argc;++i)
                l_scomAddrs.push_back(strtou64( argv[i], NULL, 16 ));
            l_scomValues.reserve(argc - 2);

            cmd_sendMultiScomReadToFSP( *l_output,
                                        strtou64(argv[1], NULL, 16), // huid
                                        l_scomAddrs,
                                        l_scomValues );
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output,
                    "ERROR: multiScomReadToFsp <huid> <scomAddrs>");
        }
    }
#ifdef CONFIG_NVDIMM
     else if( !strcmp( argv[0], "nvdimm_protection" ) )
    {
        if (argc >= 3)
        {
          uint32_t huid = strtou64(argv[1], NULL, 16);
          uint32_t protection = strtou64( argv[2], NULL, 16);
          cmd_nvdimm_protection_msg( *l_output, huid, protection );
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output, "ERROR: nvdimm_protection <huid> <0 or 1>");
        }
    }
    else if( !strcmp( argv[0], "nvdimm_es_check_status" ) )
    {
        if (argc == 1)
        {
            cmd_nvDimmEsCheckHealthStatus( *l_output );
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output, "Usage: nvdimm_es_check_status");
        }
    }
    else if( !strcmp( argv[0], "nvdimm_nvm_check_status" ) )
    {
        if (argc == 1)
        {
            cmd_nvdDmmNvmCheckHealthStatus( *l_output );
        }
        else
        {
            *l_output = new char[100];
            sprintf(*l_output, "Usage: nvdimm_nvm_check_status");
        }
    }

#endif
    else
    {
        *l_output = new char[50+100*12];
        char l_tmpstr[100];
        sprintf( *l_output, "HBRT Commands:\n" );
        sprintf( l_tmpstr, "testRunCommand <args...>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "getattr <huid> <attribute id> <size>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "readpnor <pnor section> <bytes to read>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "getscom <huid> <address>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "putscom <huid> <address> <data>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "errorlog <word1> <word2> [<huid to callout>] [size] [deconfig] [gard]\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "sbemsg <chipid>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "readvpd <huid> <keyword> [record]\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "writevpd <huid> <keyword> [<record>] <data>\n" );
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "reload_pm_complex [<breakPoint>]\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "readHBRTversion\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "hbrt_update\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "switchToFspScomAccess <huid>\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "scomOpToFsp <op> <huid> <scomAddr> [<scomValue>]\n"
                           "            <op> == r|w\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "multiScomReadToFsp <huid> <scomAddrs>\n");
        strcat( *l_output, l_tmpstr );
#ifdef CONFIG_NVDIMM
        sprintf( l_tmpstr, "nvdimm_protection <huid> <0 or 1>\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "nvdimm_es_check_status\n");
        strcat( *l_output, l_tmpstr );
        sprintf( l_tmpstr, "nvdimm_nvm_check_status\n");
        strcat( *l_output, l_tmpstr );

#endif

    }

    if( l_traceOut && (*l_output != NULL) )
    {
        UTIL_FT("Output::%s",*l_output);
        delete *l_output;
    }

    return rc;
}

};

struct registerCmds
{
    registerCmds()
    {
        getRuntimeInterfaces()->run_command = &Util::hbrtCommand;
    }
};

registerCmds g_registerCmds;



OpenPOWER on IntegriCloud