summaryrefslogtreecommitdiffstats
path: root/src/usr/sbe/sbe_update.C
blob: ef222e04de6a95ae70079395abb9ed29079a9fbb (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
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/sbe/sbe_update.C $                                    */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2013,2019                        */
/* [+] Google Inc.                                                        */
/* [+] 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 <vector>
#include <trace/interface.H>
#include <vpd/mvpdenums.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errl/errludtarget.H>
#include <errl/errlreasoncodes.H>
#include <targeting/common/predicates/predicatectm.H>
#include <targeting/common/utilFilter.H>
#include <targeting/common/targetservice.H>
#include <targeting/common/target.H>
#include <targeting/targplatutil.H>
#include <targeting/attrrp.H>
#include <util/align.H>
#include <util/crc32.H>
#include <util/misc.H>
#include <util/utilxipimage.H>
#include <errno.h>
#include <pnor/pnorif.H>
#include <pnor/ecc.H>
#include <devicefw/driverif.H>
#include <sys/mm.h>
#include <sys/misc.h>
#include <sys/msg.h>
#include <hwas/common/deconfigGard.H>
#include <hwas/common/hwas.H>
#include <initservice/initserviceif.H>
#include <console/consoleif.H>
#include <config.h>
#include <sbe/sbeif.H>
#include <sbeio/sbeioif.H>
#include <sbe/sbereasoncodes.H>
#include <sbe/sbe_update.H>
#include <initservice/initsvcreasoncodes.H>
#include <sys/time.h>

#ifdef CONFIG_BMC_IPMI
#include <ipmi/ipmisensor.H>
#include <ipmi/ipmiwatchdog.H>
#endif
#include <initservice/istepdispatcherif.H>
#ifdef CONFIG_SECUREBOOT
#include <secureboot/containerheader.H>
#endif

//  fapi support
#include    <fapi2.H>
#include    <fapi2/plat_hwp_invoker.H>
#include    <fapi2/hwp_executor.H>
#include    <fapi2/hw_access.H>

//Procedures
#include <p9_xip_customize.H>
#include <p9_xip_section_append.H>
#include <p9_xip_image.h>

#include <p9_perv_scom_addresses.H>
#include <initservice/mboxRegs.H>
#include <bootloader/bootloaderif.H>
#include <secureboot/service.H>
#include <assert.h>
#include <securerom/sha512.H>

// ----------------------------------------------
// Trace definitions
// ----------------------------------------------
trace_desc_t* g_trac_sbe = NULL;
TRAC_INIT( & g_trac_sbe, SBE_COMP_NAME, 4*KILOBYTE );

// ------------------------
// Macros for unit testing
//#define TRACUCOMP(args...)  TRACFCOMP(args)
#define TRACUCOMP(args...)

// ----------------------------------------
// Global Variables for MBOX Ipl Query
static bool g_mbox_query_done   = false;
static bool g_mbox_query_result = false;
static bool g_istep_mode        = false;
static bool g_update_both_sides = false;

// ----------------------------------------
// Global Variables HW Keys Hash Transition
static bool    g_do_hw_keys_hash_transition = false;
static SHA512_t g_hw_keys_hash_transition_data = {0};

// ----------------------------------------
// Global Variables for VMM management
//   Note - this implies that we can not run any of this code multithread
static std::list<PNOR::SectionId> g_loadedSections;

using namespace ERRORLOG;
using namespace TARGETING;

namespace SBE
{
    /**
     * @brief Retrieve the PNOR information for a section and perform
     *        secure load if required
     * @parm[in] PNOR Section id
     * @parm[out] PNOR Section info
     * @return errlHndl_t = nullptr on success
     */
    errlHndl_t loadPnorSection( PNOR::SectionId i_section,
                                PNOR::SectionInfo_t& o_info);

    /**
     * @brief Perform secure unload of a PNOR section (if required),
     *        then flush it out of the VMM
     * @parm[in] PNOR Section id
     * @return errlHndl_t = nullptr on success
     */
    errlHndl_t unloadPnorSection( PNOR::SectionId i_section);


    errlHndl_t updateProcessorSbeSeeproms(
        const KEY_TRANSITION_PERM i_keyTransPerm)
    {
        errlHndl_t err = NULL;
        errlHndl_t err_cleanup = NULL;
        sbeTargetState_t sbeState;
        std::vector<sbeTargetState_t> sbeStates_vector;

        bool l_cleanupVmmSpace = false;
        bool l_restartNeeded   = false;

        TRACFCOMP( g_trac_sbe,
                   ENTER_MRK"updateProcessorSbeSeeproms()");

        do{

#ifdef CONFIG_NO_SBE_UPDATES
            TRACFCOMP( g_trac_sbe, INFO_MRK"updateProcessorSbeSeeproms() - "
                       "SBE updates not configured");
            break;
#endif

#ifdef CONFIG_SBE_UPDATE_SEQUENTIAL
            // Check if FSP-services are enabled and if we're running in simics
            if ( !INITSERVICE::spBaseServicesEnabled() &&
                 !Util::isSimicsRunning() )
            {
                assert (false, "resolveProcessorSbeSeeproms() - "
                        "SBE_UPDATE_SEQUENTIAL mode, but FSP-services are not "
                        "enabled - Invalid Configuration");
            }
            // else - continue on
#endif


            // Get Target Service, and the system target.
            TargetService& tS = targetService();
            TARGETING::Target* sys = NULL;
            (void) tS.getTopLevelTarget( sys );
            assert(sys, "updateProcessorSbeSeeproms() system target is NULL");

            /*****************************************************************/
            /* Skip Update if ATTR_SBE_UPDATE_DISABLE is set                 */
            /*****************************************************************/
            if ( sys->getAttr<ATTR_SBE_UPDATE_DISABLE>() ) // true => disable
            {
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update skipped due to "
                           "system attribute SBE_UPDATE_DISABLE being set");
                break;
            }

            /*****************************************************************/
            /* Skip Update if MNFG_FLAG_FSP_UPDATE_SBE_IMAGE is set          */
            /* AND there is a FSP present                                    */
            /*****************************************************************/
            ATTR_MNFG_FLAGS_type mnfg_flags = sys->getAttr<ATTR_MNFG_FLAGS>();
            if ( (mnfg_flags & MNFG_FLAG_FSP_UPDATE_SBE_IMAGE)
                 && INITSERVICE::spBaseServicesEnabled() // true => FSP present
               )
            {
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update skipped due to "
                           "FSP present and MNFG_FLAG_FSP_UPDATE_SBE_IMAGE "
                           "(0x%.16X) is set in MNFG Flags 0x%.16X",
                           MNFG_FLAG_FSP_UPDATE_SBE_IMAGE, mnfg_flags);
                break;
            }

            // For a future check, determine if in istep mode and FSP is present
            if ( sys->getAttr<ATTR_ISTEP_MODE>() && // true => istep mode
                 INITSERVICE::spBaseServicesEnabled() ) // true => FSP present
            {
                g_istep_mode = true;
            }

            if (mnfg_flags & MNFG_FLAG_UPDATE_BOTH_SIDES_OF_SBE)
            {
                TRACFCOMP(g_trac_sbe,
                            INFO_MRK"Update Both Sides of SBE Flag Indicated.");
                g_update_both_sides = true;
            }

            //Make sure procedure constants keep within expected range.
            assert((FIXED_SEEPROM_WORK_SPACE <= VMM_SBE_UPDATE_SIZE/2),
                   "updateProcessorSbeSeeproms() FIXED_SEEPROM_WORK_SPACE "
                   "too large");
            assert((MAX_RING_BUF_SIZE <= VMM_SBE_UPDATE_SIZE/4),
                   "updateProcessorSbeSeeproms() MAX_RING_BUF_SIZE too "
                   "large");

            // reset global variables for MBOX Ipl Query
            g_mbox_query_done   = false;
            g_mbox_query_result = false;

            // Create VMM space for p9_xip_customize() procedure
            err = createSbeImageVmmSpace();
            if (err)
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"updateProcessorSbeSeeproms(): "
                           "createSbeImageVmmSpace() Failed. ",
                           "rc=0x%.4X", err->reasonCode() );

                break;
            }
            else
            {
                // Make sure cleanup gets called
                l_cleanupVmmSpace = true;
            }

            /*****************************************************************/
            /*  Iterate over all the functional processors and do for each:  */
            /*  1) Check their SBE State  (PNOR, MVPD, SEEPROMs, etc),       */
            /*  2) Determine the Necessary Update                            */
            /*  3) Perform Update Action                                     */
            /*****************************************************************/
            TARGETING::TargetHandleList procList;
            TARGETING::getAllChips(procList,
                                   TARGETING::TYPE_PROC,
                                   true); // true: return functional targets

            if( ( 0 == procList.size() ) ||
                ( NULL == procList[0] ) )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateProcessorSbeSeeproms() - "
                           "No functional processors Found!" );
                break;
            }

            // Get the Master Proc Chip Target for comparisons later
            TARGETING::Target* masterProcChipTargetHandle = NULL;
            err = tS.queryMasterProcChipTargetHandle(
                                                masterProcChipTargetHandle);
            if (err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateProcessorSbeSeeproms() - "
                           "queryMasterProcChipTargetHandle returned error. "
                           "Commit here and continue.  Check below against "
                           "masterProcChipTargetHandle=NULL is ok, "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                 errlCommit( err, SBE_COMP_ID );
                 err = NULL;
            }

            // Check if a key transition is allowed/needed
            if(i_keyTransPerm == ALLOW_KEY_TRANSITION)
            {
                err = secureKeyTransition();
            }

            if (err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateProcessorSbeSeeproms() - failed secureKeyTransition");
                break;
            }
            // Print new hw keys' hash if a key transition is required.
            if(g_do_hw_keys_hash_transition)
            {
                TRACFBIN(g_trac_sbe, "updateProcessorSbeSeeproms(): Key transition new hw key hash",
                         g_hw_keys_hash_transition_data,
                         sizeof(g_hw_keys_hash_transition_data));

                if(INITSERVICE::spBaseServicesEnabled())
                {
                    // Sync all attributes to FSP before we quiesce all the
                    // SBEs.
                    err = TARGETING::AttrRP::syncAllAttributesToFsp();
                    if( err )
                    {
                        // Failed to sync all attributes to FSP; this is not
                        // necessarily fatal.  The key transition will continue,
                        // but this issue will be logged.
                        TRACFCOMP(g_trac_sbe, ERR_MRK
                            "updateProcessorSbeSeeproms: Error syncing "
                            "attributes to FSP, RC=0x%04X, PLID=0x%08X",
                            ERRL_GETRC_SAFE(err),
                            ERRL_GETPLID_SAFE(err));
                        errlCommit(err,SBE_COMP_ID );
                    }
                }
            }

            for(uint32_t i=0; i<procList.size(); i++)
            {
                /*********************************************/
                /*  Collect SBE Information for this Target  */
                /*********************************************/
                memset(&sbeState, 0, sizeof(sbeState));
                sbeState.target = procList[i];

                TRACUCOMP( g_trac_sbe, "updateProcessorSbeSeeproms(): "
                           "Main Loop: tgt=0x%X, i=%d",
                           TARGETING::get_huid(sbeState.target), i);

                // Check to see if current target is master processor
                if ( sbeState.target == masterProcChipTargetHandle)
                {
                    TRACUCOMP(g_trac_sbe,"sbeState.target=0x%X is MASTER. "
                              " (i=%d)",
                              TARGETING::get_huid(sbeState.target), i);
                    sbeState.target_is_master = true;
                }
                else
                {
                    sbeState.target_is_master = false;
                }

                //Can only update the SBE once the powerbus is up (secureboot)
                //Use the scom switch Xscom capability flag as a proxy for
                //powerbus access.  If we can't access via powerbus, then skip
                TARGETING::ScomSwitches scomSetting =
                      sbeState.target->getAttr<TARGETING::ATTR_SCOM_SWITCHES>();

                if(!(scomSetting.useXscom))
                {
                    //Xscom is not viable on this chip, thus powerbus isn't
                    //up to chip -- skip it
                    TRACFCOMP( g_trac_sbe,
                               INFO_MRK"updateProcessorSbeSeeproms(): "
                               "Power bus not established to chip 0x%X,"
                               " not performing update",
                               TARGETING::get_huid(sbeState.target));
                    continue;
                }

                err = getSbeInfoState(sbeState);

                if (err)
                {
                    TRACFCOMP( g_trac_sbe,
                               INFO_MRK"updateProcessorSbeSeeproms(): "
                               "getSbeInfoState() Failed "
                               "rc=0x%.4X, Target UID=0x%X",
                               err->reasonCode(),
                               TARGETING::get_huid(sbeState.target));

                    // Don't break - handle error at the end of the loop
                }


                /**********************************************/
                /*  Determine update actions for this target  */
                /**********************************************/
                // Skip if we got an error collecting SBE Info State
                if ( err == NULL )
                {
                    err = getTargetUpdateActions(sbeState);
                    if (err)
                    {
                        TRACFCOMP( g_trac_sbe,
                                   INFO_MRK"updateProcessorSbeSeeproms(): "
                                   "getTargetUpdateActions() Failed "
                                   "rc=0x%.4X, Target UID=0x%X",
                                   err->reasonCode(),
                                   TARGETING::get_huid(sbeState.target));

                        // Don't break - handle error at the end of the loop,
                    }

                }

                /**********************************************/
                /*  Perform Update Actions For This Target    */
                /**********************************************/
                // Force an update of SEEPROM 0 or SEEPROM 1 if SB keyword
                // flags is requesting an update for that particular seeprom
                if (((sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY) &&
                (sbeState.mvpdSbKeyword.flags & SEEPROM_0_FORCE_UPDATE_MASK)) ||
                    ((sbeState.seeprom_side_to_update == EEPROM::SBE_BACKUP) &&
                (sbeState.mvpdSbKeyword.flags & SEEPROM_1_FORCE_UPDATE_MASK)))
                {
                   // The DO_UPDATE flag alone might not be enough to
                   // force an update, setting UPDATE_SBE flag as well
                   // because I know that performUpdateActions checks that flag
                   sbeState.update_actions = static_cast<sbeUpdateActions_t>
                             (sbeState.update_actions | DO_UPDATE | UPDATE_SBE);
                }

                if ((err == NULL) && (sbeState.update_actions & DO_UPDATE))
                {
                    // If update is needed, check to see if it's in MPIPL
                    if(sys->getAttr<TARGETING::ATTR_IS_MPIPL_HB>() == true)
                    {
                        TRACFCOMP( g_trac_sbe,
                                       INFO_MRK"updateProcessorSbeSeeproms(): "
                                       "Skip SBE update during MPIPL "
                                       ", Target UID=0x%X",
                                       TARGETING::get_huid(sbeState.target));
                        /*@
                         * @errortype
                         * @moduleid          SBE_UPDATE_SEEPROMS
                         * @reasoncode        SBE_UPDATE_DURING_MPIPL
                         * @userdata1         Target huid id
                         * @userdata2[0:31]   Update actions
                         * @userdata2[32:63]  SEEPROM side to update
                         * @devdesc           SBE update is being skipped
                         *                    during MPIPL
                         * @custdesc          SBE is not being updated
                         */
                        err = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                  SBE_UPDATE_SEEPROMS,
                                  SBE_UPDATE_DURING_MPIPL,
                                  TARGETING::get_huid(sbeState.target),
                                  TWO_UINT32_TO_UINT64(
                                      TO_UINT32(sbeState.update_actions),
                                      TO_UINT32(sbeState.seeprom_side_to_update)
                                  )
                        );
                        err->collectTrace(SBE_COMP_NAME);
                    }
                    else
                    {
                        err = performUpdateActions(sbeState);
                        if (err)
                        {
                            TRACFCOMP( g_trac_sbe,
                                       INFO_MRK"updateProcessorSbeSeeproms(): "
                                       "performUpdateActions() Failed "
                                       "rc=0x%.4X, Target UID=0x%X",
                                       err->reasonCode(),
                                       TARGETING::get_huid(sbeState.target));

                            //Don't break - handle error at the end of the loop,
                        }
                        else
                        {
                            //Target updated without failure, so set IPL_RESTART
                            //flag, if necessary
                            if (sbeState.update_actions & IPL_RESTART)
                            {
                                l_restartNeeded = true;
                            }
                        }
                    }  // end else of if(sys->getAttr<TARGETING::ATTR_IS_MPIPL_HB>() == true)
                }  // end if ((err == NULL) && (sbeState.update_actions & DO_UPDATE))

                if ( err )
                {
                    // Something failed for this target.
                    // Save error information
                    sbeState.err_plid = err->plid();
                    sbeState.err_eid  = err->eid();
                    sbeState.err_rc   = err->reasonCode();
                    sbeState.err_sev  = err->sev();

                    // Commit the error here and move on to the next target,
                    // or if no targets left, will just continue the IPL
                    TRACFCOMP( g_trac_sbe,
                               INFO_MRK"updateProcessorSbeSeeproms(): "
                               "Committing Error Log rc=0x%.4X eid=0x%.8X "
                               "plid=0x%.8X sev=0x%.2X for Target UID=0x%X, "
                               "but continuing procedure",
                               sbeState.err_rc, sbeState.err_eid,
                               sbeState.err_plid, sbeState.err_sev,
                               TARGETING::get_huid(sbeState.target));
                    errlCommit( err, SBE_COMP_ID );
                }

                /**********************************************/
                /*   Reset the watchdog after each Action     */
                /**********************************************/
                INITSERVICE::sendProgressCode();

                // Push this sbeState onto the vector
                sbeStates_vector.push_back(sbeState);

            } //end of Target for loop collecting each target's SBE State

            /**************************************************************/
            /*  Perform System Operation                                  */
            /**************************************************************/

            // Restart IPL if SBE Update requires it or key transition occurred
            if (   (l_restartNeeded == true)
                || (g_do_hw_keys_hash_transition))
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"updateProcessorSbeSeeproms(): Restart "
                           "Needed (%d). Calling preReIplCheck()",
                           l_restartNeeded);

                err = preReIplCheck(sbeStates_vector);

                if ( err )
                {
                    // Something failed on the check.  Commit the error here
                    // and continue with the Re-IPL Request
                    TRACFCOMP( g_trac_sbe,
                               INFO_MRK"updateProcessorSbeSeeproms(): "
                               "Committing Error Log rc=0x%.4X from "
                               "preReIplCheck(), but doing Re-IPL",
                               err->reasonCode());
                    errlCommit( err, SBE_COMP_ID );
                }

                err = sbeDoReboot();
                if (err)
                {
                    TRACFCOMP( g_trac_sbe,ERR_MRK"sbeDoReboot failed");
                    break;
                }
            }
            else
            {
                /************************************************************/
                /* Deconfigure any Processors that have a Version different */
                /*   from the Master Processor's Version                    */
                /************************************************************/
                err = masterVersionCompare(sbeStates_vector);

                if ( err )
                {
                    // Something failed on the check
                    TRACFCOMP( g_trac_sbe,
                               INFO_MRK"updateProcessorSbeSeeproms(): Call to "
                               "masterVersionCompare() failed rc=0x%.4X",
                               err->reasonCode());
                }
            }

        }while(0);

        // Cleanup VMM Workspace
        if ( l_cleanupVmmSpace == true )
        {
            err_cleanup = cleanupSbeImageVmmSpace();
            if ( err_cleanup != NULL )
            {

                if ( err != NULL )
                {
                    // 2 error logs, so commit the cleanup log here
                    TRACFCOMP( g_trac_sbe,
                               ERR_MRK"updateProcessorSbeSeeproms(): Previous "
                               "error (rc=0x%X) before cleanupSbeImageVmmSpace"
                               "() failed.  Committing cleanup error (rc=0x%X) "
                               "and returning original error",
                               err->reasonCode(), err_cleanup->reasonCode()  );

                     errlCommit( err_cleanup, SBE_COMP_ID );
                }
                else
                {
                    // no previous error, so returning cleanup error
                    TRACFCOMP( g_trac_sbe,
                               ERR_MRK"updateProcessorSbeSeeproms(): "
                               "cleanupSbeImageVmmSpace() failed.",
                               "rc=0x%.4X", err_cleanup->reasonCode() );
                    err = err_cleanup;
                }
            }
        }

        if(err && g_do_hw_keys_hash_transition)
        {
            // In theory it's possible to end up here if Hostboot fails to send
            // the key transition started/succeeded message.  Hostboot will
            // treat that as a failure of the key transition process to call
            // attention to the unexpected sequence.
            errlHndl_t pError = updateKeyTransitionState(
                TARGETING::KEY_TRANSITION_STATE_KEY_TRANSITION_FAILED);
            if(pError)
            {
                TRACFCOMP(g_trac_sbe,
                    ERR_MRK"updateProcessorSbeSeeproms(): Failed in call to "
                    "updateKeyTransitionState with state of "
                    "KEY_TRANSITION_STATE_KEY_TRANSITION_FAILED. "
                    "Error log's EID=0x%08X, PLID=0x%08X, RC=0x%04X. ",
                    "Changing error log's PLID to 0x%08X.",
                    pError->eid(),pError->plid(),pError->reasonCode(),
                    err->plid());

                pError->plid(err->plid());
                err->collectTrace(SBE_COMP_NAME);
                err->collectTrace(SBEIO_COMP_NAME);
                errlCommit(pError,SBE_COMP_ID);
            }
        }

        TRACFCOMP( g_trac_sbe,
                   EXIT_MRK"updateProcessorSbeSeeproms()" );

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t findSBEInPnor(TARGETING::Target* i_target,
                             void*& o_imgPtr,
                             size_t& o_imgSize,
                             sbe_image_version_t* o_version)
    {
        errlHndl_t err = NULL;
        PNOR::SectionInfo_t pnorInfo;
        sbeToc_t* sbeToc = NULL;
        uint8_t ec = 0;
        PNOR::SectionId pnorSectionId = PNOR::INVALID_SECTION;

        void* hdr_Ptr  = NULL;
        o_imgPtr = NULL;
        o_imgSize = 0;

        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"findSBEInPnor()" );

        do{

            // Get the correct PNOR Section Id
            if ( i_target->getAttr<ATTR_TYPE>() == TYPE_PROC )
            {
                pnorSectionId = PNOR::SBE_IPL;
            }
            else
            {
                // Unsupported target type was passed in
                TRACFCOMP( g_trac_sbe, ERR_MRK"findSBEInPnor: Unsupported "
                           "target type was passed in: uid=0x%X, type=0x%X",
                           TARGETING::get_huid(i_target),
                           i_target->getAttr<ATTR_TYPE>());

                /*@
                 * @errortype
                 * @moduleid     SBE_FIND_IN_PNOR
                 * @reasoncode   SBE_INVALID_INPUT
                 * @userdata1    Target Unit Id
                 * @userdata2    Target Type
                 * @devdesc      Unsupported Target Type passed in
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_FIND_IN_PNOR,
                                    SBE_INVALID_INPUT,
                                    TARGETING::get_huid(i_target),
                                    i_target->getAttr<ATTR_TYPE>());
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }

            // Get SBE PNOR section info from PNOR RP
            err = loadPnorSection( pnorSectionId,
                                   pnorInfo );

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"findSBEInPnor: Error calling "
                           "loadPnorSection() rc=0x%.4X",
                           err->reasonCode() );
                break;
            }

            TRACUCOMP( g_trac_sbe,
                       INFO_MRK"findSBEInPnor: UID=0x%X, sectionId=0x%X. "
                       "pnor vaddr = 0x%.16X",
                       TARGETING::get_huid(i_target),
                       pnorSectionId, pnorInfo.vaddr);

            sbeToc = reinterpret_cast<sbeToc_t*>( pnorInfo.vaddr );

            if (sbeToc->eyeCatch != SBETOC_EYECATCH)
            {
                //The SBE partition does not have the proper eyecatcher
                TRACFCOMP( g_trac_sbe, ERR_MRK"findSBEInPnor: SBE partition "
                           "does not have the proper eyecatcher: was: 0x%X, "
                           "should be: 0x%X",
                           sbeToc->eyeCatch, SBETOC_EYECATCH );

                TRACFBIN( g_trac_sbe, "sbeToc", sbeToc, sizeof(sbeToc_t));

                /*@
                 * @errortype
                 * @moduleid     SBE_FIND_IN_PNOR
                 * @reasoncode   SBE_INVALID_EYECATCHER
                 * @userdata1    SBE TOC EYE-CATCHER
                 * @userdata2    Expected EYE-CATCHER
                 * @devdesc      Unsupported EYE-CATCHER found in TOC
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_FIND_IN_PNOR,
                                    SBE_INVALID_EYECATCHER,
                                    sbeToc->eyeCatch,
                                    SBETOC_EYECATCH);
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_SP_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }
            else
            {

                //Check the TOC Version
                if( SUPPORTED_TOC_VER != sbeToc->tocVersion)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"findSBEInPnor: Unsupported "
                               "SBE TOC Version in SBE Partition" );

                    TRACFBIN( g_trac_sbe, "sbeToc", sbeToc, sizeof(sbeToc_t));

                    /*@
                     * @errortype
                     * @moduleid          SBE_FIND_IN_PNOR
                     * @reasoncode        SBE_UNSUPPORTED_TOC
                     * @userdata1[0:31]   CHIP EC
                     * @userdata1[32:63]  Expected TOC Version
                     * @userdata2[0:31]   SBE TOC Version
                     * @userdata2[32:63]  SBE TOC EyeCatch
                     * @devdesc      SBE partition contains unsupported version
                     *               of Table of Contents
                     * @custdesc     A problem occurred while updating processor
                     *               boot code.
                     */
                    err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                        SBE_FIND_IN_PNOR,
                                        SBE_UNSUPPORTED_TOC,
                                        TWO_UINT32_TO_UINT64(ec,
                                                             SUPPORTED_TOC_VER),
                                        TWO_UINT32_TO_UINT64(sbeToc->tocVersion,
                                                             sbeToc->eyeCatch));
                    err->collectTrace(SBE_COMP_NAME);
                    err->addProcedureCallout( HWAS::EPUB_PRC_SP_CODE,
                                              HWAS::SRCI_PRIORITY_HIGH );

                    break;
                }

                //Walk the TOC and find our current EC
                ec = i_target->getAttr<TARGETING::ATTR_EC>();

                // If ec == 0 then this indicates simics is not correctly
                // writing EC to the FSI register we get the EC level from
                if(ec == 0)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"findSBEInPnor: invalid EC found, EC cannot be 0, check simics model" );

                    /*@
                     * @errortype
                     * @moduleid          SBE_FIND_IN_PNOR
                     * @reasoncode        SBE_UNSUPPORTED_EC
                     * @userdata1         Target Huid
                     * @userdata2         unused
                     * @devdesc           EC level says 0, which is invalid
                     * @custdesc          Chip level is invalid
                     */
                    err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                        SBE_FIND_IN_PNOR,
                                        SBE_UNSUPPORTED_EC,
                                        TARGETING::get_huid(i_target),
                                        0,
                                        ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
                    err->collectTrace(SBE_COMP_NAME);

                    break;
                }

                for(uint32_t i=0; i<MAX_SBE_ENTRIES; i++)
                {
                    if(static_cast<uint32_t>(ec) == sbeToc->entries[i].ec)
                    {

                        // EC found in TOC
                        uint64_t offset = pnorInfo.vaddr
                          + static_cast<uint64_t>(sbeToc->entries[i].offset);
                        hdr_Ptr = reinterpret_cast<void*>( offset );

                        o_imgSize = sbeToc->entries[i].size;

                        TRACUCOMP( g_trac_sbe, INFO_MRK"findSBEInPnor: Found "
                                   "EC Image: ec=0x%.2X offset=0x%.16X, i=%d "
                                   "size=0x%X",
                                   ec, offset, i, o_imgSize );
                        break;
                    }
                }
            }
            // IF we failed to find hdr_Ptr then no matching EC found
            if(NULL == hdr_Ptr)
            {
                //if we get here, it's an error
                TRACFCOMP( g_trac_sbe,ERR_MRK"findSBEInPnor:SBE Image not "
                           "located, ec=0x%.2X",ec );

                TRACFBIN( g_trac_sbe, "sbeToc", sbeToc, sizeof(sbeToc_t));

                /*@
                 * @errortype
                 * @moduleid     SBE_FIND_IN_PNOR
                 * @reasoncode   SBE_EC_NOT_FOUND
                 * @userdata1[0:31]   CHIP EC
                 * @userdata1[32:63]  PNOR Section ID
                 * @userdata2[0:31]   SBE TOC Version
                 * @userdata2[32:63]  SBE TOC EyeCatch
                 * @devdesc      SBE image for current chip EC was not found
                 *               in PNOR
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_FIND_IN_PNOR,
                                    SBE_EC_NOT_FOUND,
                                    TWO_UINT32_TO_UINT64(ec,
                                                         pnorSectionId),
                                    TWO_UINT32_TO_UINT64(sbeToc->tocVersion,
                                                         sbeToc->eyeCatch));
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_SP_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }

            //  The SBE Image for the corresponding EC was found, check if
            //  it includes a SBE Header
            if (pnorInfo.sha512perEC)
            {
                TRACFCOMP(g_trac_sbe,INFO_MRK"findSBEInPnor: sha512perEC "
                          "Found in %s", pnorInfo.name);
                // Advance PNOR pointer 4k to move it past header page to the
                // start of the non-customized SBE image
                o_imgPtr = reinterpret_cast<void*>
                                (reinterpret_cast<char*>(hdr_Ptr)+PAGE_SIZE);
                // Do not include header in size
                o_imgSize -= PAGE_SIZE;
            }

            if(NULL != o_version)
            {
                err = readPNORVersion(hdr_Ptr,
                                      *o_version);
                if(err)
                {
                    break;
                }
            }

        }while(0);


        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"findSBEInPnor(): o_imgPtr=%p, o_imgSize=0x%X",
                   o_imgPtr, o_imgSize );


        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t appendHbblToSbe(void*     i_section,
                               uint32_t  i_section_size,
                               void*     i_image,
                               uint32_t& io_image_size)
    {
        errlHndl_t err = NULL;
        P9XipItem l_xipItem;

        TRACFCOMP( g_trac_sbe,
                   ENTER_MRK"appendHbblToSbe(): i_section=%p, "
                            "i_section_size=0x%X, i_image=%p, "
                            "io_image_size=0x%X",
                            i_section, i_section_size,
                            i_image, io_image_size);

        do{
            // Call p9_xip_find to find HBBL image in SBE image
            const char* l_sectionId = ".hbbl";
            // Note - this is not a fapi2 function
            int xip_rc = p9_xip_find( i_image, l_sectionId, &l_xipItem );

            // Check the return code
            if( xip_rc == P9_XIP_ITEM_NOT_FOUND )
            {
                TRACUCOMP( g_trac_sbe, "appendHbblToSbe(): "
                           "p9_xip_find received expected return code, item "
                           "not found, rc=0x%X",
                           xip_rc );
            }
            else if( xip_rc == P9_XIP_DATA_NOT_PRESENT )
            {
                TRACFCOMP( g_trac_sbe, "appendHbblToSbe(): "
                           "p9_xip_find located %s, rc=0x%X",
                           xip_rc ? "TOC only" : "TOC and section data",
                           xip_rc );

                // Call p9_xip_delete_section to delete existing HBBL image
                // from SBE image
                void *l_imageBuf =malloc(io_image_size);
                xip_rc = p9_xip_delete_section(
                                 i_image,
                                 l_imageBuf,
                                 io_image_size,
                                 P9_XIP_SECTION_SBE_HBBL );
                free(l_imageBuf);

                // Check for error
                if( xip_rc )
                {
                    TRACFCOMP( g_trac_sbe, "appendHbblToSbe(): "
                               "p9_xip_delete_section failed, rc=0x%X",
                               xip_rc );
                    /*@
                     * @errortype
                     * @moduleid     SBE_APPEND_HBBL
                     * @reasoncode   ERROR_FROM_XIP_DELETE
                     * @userdata1    rc from p9_xip_delete
                     * @userdata2    <unused>
                     * @devdesc      Bad RC from p9_xip_delete
                     * @custdesc     A problem occurred while updating processor
                     *               boot code.
                     */
                    err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                        SBE_APPEND_HBBL,
                                        ERROR_FROM_XIP_DELETE,
                                        xip_rc,
                                        0,
                                        true /* SW error */);
                    err->collectTrace(SBE_COMP_NAME);

                    // exit loop
                    break;
                }
            }
            else
            {
                TRACFCOMP( g_trac_sbe, "appendHbblToSbe(): p9_xip_find "
                           "received unexpected return code, rc=0x%X",
                           xip_rc );
                /*@
                 * @errortype
                 * @moduleid     SBE_APPEND_HBBL
                 * @reasoncode   ERROR_FROM_XIP_FIND
                 * @userdata1    rc from p9_xip_find
                 * @userdata2    <unused>
                 * @devdesc      Bad RC from p9_xip_find
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_APPEND_HBBL,
                                    ERROR_FROM_XIP_FIND,
                                    xip_rc,
                                    0,
                                    true /* SW error */);
                err->collectTrace(SBE_COMP_NAME);
                err->collectTrace(FAPI_IMP_TRACE_NAME,256);
                err->collectTrace(FAPI_TRACE_NAME,384);

                // exit loop
                break;
            }

            // Invoke p9_xip_section_append to append HBBL image to SBE image
            FAPI_INVOKE_HWP( err,
                             p9_xip_section_append,
                             i_section,
                             i_section_size,
                             P9_XIP_SECTION_SBE_HBBL,
                             i_image,
                             io_image_size );

            // Check for error
            if(err)
            {
                TRACFCOMP( g_trac_sbe, "appendHbblToSbe(): "
                           "p9_xip_section_append failed, rc=0x%X",
                           err->reasonCode() );

                // exit loop
                break;
            }

        }while(0);

        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"appendHbblToSbe(): i_image=%p, "
                   "io_image_size=0x%X, RC=0x%X",
                   i_image, io_image_size, ERRL_GETRC_SAFE(err) );

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t ringOvd(void *io_imgPtr,
                       uint32_t & io_ovdImgSize)
    {
        errlHndl_t l_err = nullptr;
        PNOR::SectionInfo_t l_pnorRingOvd;

        do {

            l_err = PNOR::getSectionInfo(PNOR::RINGOVD, l_pnorRingOvd);
            if(l_err)
            {
                delete l_err;
                l_err = NULL;
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"ringOvd():Error trying to read RINGOVD "
                           "from PNOR. Could be blocked in secure mode. "
                           "It is optional, continuing");
                io_ovdImgSize = 0;
                break;
            }
            if(l_pnorRingOvd.size == 0)
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"ringOvd(): No RINGOVD section in PNOR");
                io_ovdImgSize = 0;
                break;
            }

            TRACDBIN( g_trac_sbe,
                      "ringOvd():100 bytes of RINGOVD section",
                      (void *)l_pnorRingOvd.vaddr,100);

            // If first 8 bytes are just FF's then we know there's no override
            if((*(static_cast<uint64_t *>((void *)l_pnorRingOvd.vaddr))) ==
                    0xFFFFFFFFFFFFFFFF)
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"ringOvd():No overrides in RINGOVD section "
                           "found");
                io_ovdImgSize = 0;
                break;
            }

            TRACFCOMP( g_trac_sbe,
                       INFO_MRK"ringOvd():Valid overrides, applying them");

            FAPI_INVOKE_HWP(l_err,p9_xip_section_append,
                            (void *)l_pnorRingOvd.vaddr,
                            RING_OVD_SIZE,
                            P9_XIP_SECTION_SBE_OVERRIDES,
                            io_imgPtr,
                            io_ovdImgSize);

            if ( l_err )
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"ringOvd(): FAPI_INVOKE_HWP("
                           "p9_xip_section_append) failed, PLID=0x%x",
                           l_err->plid());

                l_err->collectTrace(SBE_COMP_NAME, 256);

                io_ovdImgSize = 0;
                break;
            }

        }while(0);

        return l_err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t procCustomizeSbeImg(TARGETING::Target* i_target,
                                   void* i_hwImgPtr,
                                   void* i_sbeImgPtr,
                                   size_t i_maxImgSize,
                                   void* io_imgPtr,
                                   size_t& o_actImgSize)
    {
        errlHndl_t err = NULL;
        uint32_t tmpImgSize = static_cast<uint32_t>(i_maxImgSize);
        uint32_t coreMask = 0x00FFFFFF; // Bits(8:31) = EC00:EC23
        size_t maxCores = P9_MAX_EC_PER_PROC;
        uint32_t coreCount = 0;
        uint32_t procIOMask = 0;
        bool procedure_success = false;

        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"procCustomizeSbeImg(): uid=0x%X, i_sbeImgPtr= "
                            "%p, maxS=0x%X, io_imgPtr=%p",
                            TARGETING::get_huid(i_target), i_sbeImgPtr,
                            i_maxImgSize, io_imgPtr);

        do{

            // Before doing any customization, we need to ensure that the
            // ATTR_EC/EQ_GARD attributes are setup to reflect the
            // current state of our targets
            HWAS::setChipletGardsOnProc(i_target);

            // cast OUR type of target to a FAPI type of target.
            const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>
                l_fapiTarg(i_target);

            // The p9_xip_customize() procedure tries to include as much core
            // information as possible, but is limited by SBE Image size
            // constraints.
            // First, maximize core mask for the target
            // Then loop on the procedure call, where the loop is designed to
            // remove the number of cores passed into p9_xip_customize() until
            // an image can be created successfully.

            // Maximize Core mask for this target
            err = selectBestCores(i_target,
                                  maxCores,
                                  coreMask);
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"procCustomizeSbeImg() - "
                           "selectBestCores() failed rc=0x%X. "
                           "MaxCores=0x%.8X. HUID=0x%X. Aborting "
                           "Customization of SBE Image",
                           err->reasonCode(), maxCores,
                           TARGETING::get_huid(i_target));
                break;
            }

            // Get Target Service
            // System target check done earlier, so no assert check necessary
            TargetService& tS = targetService();
            TARGETING::Target* sys = NULL;
            (void) tS.getTopLevelTarget( sys );

            // setup loop parameters
            coreCount = __builtin_popcount(coreMask);
            uint32_t desired_min_cores = ((is_fused_mode()) ? 2 : 1) *
                sys->getAttr<ATTR_SBE_IMAGE_MINIMUM_VALID_ECS>();

            // Use desired minimum number of cores, but be less restrictive if
            // fewer cores are found to be present
            uint32_t min_cores = std::min(desired_min_cores, coreCount);
            if(min_cores < desired_min_cores)
            {
                // Identify that the desired minimum core count was not met
                TRACFCOMP( g_trac_sbe, INFO_MRK"procCustomizeSbeImg() - "
                           "Using fewer cores than desired minimum number of "
                           "cores. HUID=0x%X, coreCount=%d, coreMask=0x%.8X, "
                           "desired_min_cores=0x%X",
                           TARGETING::get_huid(i_target),
                           coreCount, coreMask, desired_min_cores);
            }

            while( coreCount >= min_cores )
            {
                // copy customized SBE image to destination
                memcpy ( io_imgPtr,
                         i_sbeImgPtr,
                         tmpImgSize);

                procIOMask = coreMask;

                uint32_t l_ringSectionBufSize = MAX_SEEPROM_IMAGE_SIZE;
                FAPI_INVOKE_HWP( err,
                                 p9_xip_customize,
                                 l_fapiTarg,
                                 i_hwImgPtr,
                                 io_imgPtr, //image in/out
                                 tmpImgSize,
                                 (void*)RING_SEC_VADDR,
                                 l_ringSectionBufSize,
                                 SYSPHASE_HB_SBE,
                                 MODEBUILD_IPL,
                                 (void*)RING_BUF1_VADDR,
                                 (uint32_t)MAX_RING_BUF_SIZE,
                                 (void*)RING_BUF2_VADDR,
                                 (uint32_t)MAX_RING_BUF_SIZE,
                                 (void*)RING_BUF3_VADDR,
                                 (uint32_t)MAX_RING_BUF_SIZE,
                                 procIOMask ); // Bits(8:31) = EC00:EC23

                // Check for no error and use of input cores
                if ( (NULL == err) && (procIOMask == coreMask))
                {
                    // Procedure was successful
                    procedure_success = true;

                    o_actImgSize = static_cast<size_t>(tmpImgSize);

                    TRACUCOMP( g_trac_sbe, "procCustomizeSbeImg(): "
                               "p9_xip_customize success=%d, procIOMask=0x%X "
                               "o_actImgSize=0x%X",
                               procedure_success, procIOMask, o_actImgSize);

                    // exit inner loop
                    break;
                }
                // Check if p9_xip_customize returned a different core mask
                else if ( procIOMask != coreMask )
                {
                    // A different core mask is returned from p9_xip_customize
                    // when the cores sent in couldn't fit, but possibly
                    // a different procIOMask would work

                    TRACFCOMP( g_trac_sbe,
                               ERR_MRK"procCustomizeSbeImg(): FAPI_INVOKE_HWP("
                               "p9_xip_customize) returned rc=0x%X, "
                               "XIPC_IMAGE_WOULD_OVERFLOW-Retry "
                               "MaxCores=0x%.8X. HUID=0x%X. coreMask=0x%.8X, "
                               "procIOMask=0x%.8X. coreCount=%d",
                               ERRL_GETRC_SAFE(err), maxCores,
                               TARGETING::get_huid(i_target),
                               coreMask, procIOMask, coreCount);

                    // Setup for next loop - update coreMask
                    err = selectBestCores(i_target,
                                          --coreCount,
                                          coreMask);

                    if ( err )
                    {
                        TRACFCOMP(g_trac_sbe,
                                  ERR_MRK"procCustomizeSbeImg() - "
                                  "selectBestCores() failed rc=0x%X. "
                                  "coreCount=0x%.8X. HUID=0x%X. Aborting "
                                  "Customization of SBE Image",
                                  err->reasonCode(), coreCount,
                                  TARGETING::get_huid(i_target));

                        // break from inner while loop
                        break;
                    }

                    TRACFCOMP( g_trac_sbe, "procCustomizeSbeImg(): for "
                               "next loop: coreMask=0x%.8X, coreCount=%d",
                               coreMask, coreCount);

                    // Check if loop will execute again
                    // Clean up some data if it will
                    if( coreCount >= min_cores )
                    {
                        // Reset size and clear image buffer
                        tmpImgSize = static_cast<uint32_t>(i_maxImgSize);
                        memset ( io_imgPtr,
                                 0,
                                 tmpImgSize);
                    }

                    // No break - keep looping
                }
                else
                {
                    // Unexpected return code - create err and fail
                    TRACFCOMP( g_trac_sbe,
                               ERR_MRK"procCustomizeSbeImg(): FAPI_INVOKE_HWP("
                               "p9_xip_customize) failed with rc=0x%X, "
                               "MaxCores=0x%X. HUID=0x%X. coreMask=0x%.8X, "
                               "procIOMask=0x%.8X. coreCount=%d. Create "
                               "err and break loop",
                               ERRL_GETRC_SAFE(err), maxCores,
                               TARGETING::get_huid(i_target),
                               coreMask, procIOMask, coreCount);

                    ERRORLOG::ErrlUserDetailsTarget(i_target,
                                                    "Proc Target")
                                                    .addToLog(err);
                    err->collectTrace(SBE_COMP_NAME, 256);

                    // break from inner while loop
                    break;
                }
            }  // end of inner while loop

            if(err)
            {
                // There was a previous error, so break here
                break;
            }

            if ( procedure_success == false )
            {
                // No err, but exit from while loop before successful
                TRACFCOMP( g_trac_sbe, ERR_MRK"procCustomizeSbeImg() - "
                           "Failure to successfully complete p9_xip_customize()"
                           ". HUID=0x%X, rc=0x%X, coreCount=%d, coreMask=0x%.8X"
                           " procIOMask=0x%.8X, maxCores=0x%X, min_cores=0x%X, "
                           "desired_min_cores=0x%X",
                           TARGETING::get_huid(i_target), ERRL_GETRC_SAFE(err),
                           coreCount, coreMask, procIOMask, maxCores,
                           min_cores, desired_min_cores);
                /*@
                 * @errortype
                 * @moduleid          SBE_CUSTOMIZE_IMG
                 * @reasoncode        SBE_P9_XIP_CUSTOMIZE_UNSUCCESSFUL
                 * @userdata1[0:31]   procIOMask in/out parameter
                 * @userdata1[32:63]  rc of procedure
                 * @userdata2[0:31]   coreMask of target
                 * @userdata2[32:63]  coreCount - updated on the loops
                 * @devdesc      Unsuccessful in creating Customized SBE Image
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_CUSTOMIZE_IMG,
                                    SBE_P9_XIP_CUSTOMIZE_UNSUCCESSFUL,
                                    TWO_UINT32_TO_UINT64(procIOMask,
                                                         ERRL_GETRC_SAFE(err)),
                                    TWO_UINT32_TO_UINT64(coreMask,
                                                         coreCount));

                ErrlUserDetailsTarget(i_target
                                      ).addToLog(err);
                err->collectTrace("FAPI", 256);
                err->collectTrace(SBE_COMP_NAME, 256);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
            }

        }while(0);

        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"procCustomizeSbeImg(): io_imgPtr=%p, "
                   "o_actImgSize=0x%X, RC=0x%X, procedure_success=%d",
                   io_imgPtr, o_actImgSize, ERRL_GETRC_SAFE(err),
                   procedure_success );

        return err;
    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t selectBestCores(TARGETING::Target* i_target,
                               size_t i_maxCores,
                               uint32_t& o_coreMask)
    {
        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"selectBestCores(i_maxCores=0x%.8X)",
                   i_maxCores);

        errlHndl_t err = NULL;
        const uint32_t chipUnitMask = 0x00800000; // Bits(8:31) = EC00:EC23
        uint32_t manGuardEcs = 0x00000000;
        uint32_t remainingEcs = 0x00000000;
        uint32_t coreCount = 0;
        uint32_t deconfigByEid = 0;

        o_coreMask = 0x00000000;

        do{

            // Special case: if i_maxCores == 0 don't loop through cores
            if (unlikely(i_maxCores == 0 ))
            {
                break;
            }

            // find all CORE chiplets of the proc
            TARGETING::TargetHandleList l_coreTargetList;
            TARGETING::getChildAffinityTargetsByState( l_coreTargetList,
                                                       i_target,
                                                       CLASS_UNIT,
                                                       TYPE_CORE,
                                                       UTIL_FILTER_PRESENT);

            //Sort through cores
            for( const auto & l_core_target: l_coreTargetList )
            {
                uint8_t chipUnit = l_core_target->
                    getAttr<TARGETING::ATTR_CHIP_UNIT>();

                if(l_core_target->
                    getAttr<TARGETING::ATTR_HWAS_STATE>().functional)
                {
                    o_coreMask |= (chipUnitMask >> chipUnit);
                    coreCount++;
                }
                else
                {
                    //If non-functional due to FCO or Manual gard,
                    //add it to list of cores to include if
                    //more are needed

                    deconfigByEid = l_core_target->
                                      getAttr<TARGETING::ATTR_HWAS_STATE>().
                                      deconfiguredByEid;
                    if(
                       // FCO
                       (deconfigByEid ==
                        HWAS::DeconfigGard::DECONFIGURED_BY_FIELD_CORE_OVERRIDE)
                       || // Manual GARD
                       (deconfigByEid ==
                        HWAS::DeconfigGard::DECONFIGURED_BY_MANUAL_GARD)
                       )
                    {
                        manGuardEcs |= (chipUnitMask >> chipUnit);
                    }
                    // Add it to the 'remaining' list in case
                    // more are needed
                    else
                    {
                        remainingEcs |= (chipUnitMask >> chipUnit);
                    }

                }
            }   // end core target loop

            if(coreCount == i_maxCores)
            {
                //We've found the exact amount, break out of function
                break;
            }

            else if(coreCount > i_maxCores)
            {
                //We have too many, so need to trim
                o_coreMask = trimBitMask(o_coreMask,
                                         i_maxCores);
                break;
            }

            else
            {
                // We need to add 'other' cores
                TRACUCOMP( g_trac_sbe,INFO_MRK"selectBestCores: non-functional "
                           "cores needed for bit mask: coreCount=%d, "
                           "i_maxCores=%d, o_coreMask=0x%.8X, "
                           "manGuardEcs=0x%.8X, remainingEcs=0x%.8X",
                           coreCount, i_maxCores, o_coreMask, manGuardEcs,
                           remainingEcs );
            }

            // Add more 'good' cores.
            manGuardEcs = trimBitMask(manGuardEcs,
                                      i_maxCores-coreCount);
            o_coreMask |= manGuardEcs;
            coreCount = __builtin_popcount(o_coreMask);
            TRACUCOMP( g_trac_sbe,INFO_MRK"selectBestCores: trimBitMask "
                       "manGuardEcs=0x%.8X", manGuardEcs);

            if(coreCount >= i_maxCores)
            {
                //We've found enough, break out of function
                break;
            }

            // If we still need more, add 'remaining' cores
            // Get Target Service
            // System target check done earlier, so no assert check necessary
            TargetService& tS = targetService();
            TARGETING::Target* sys = NULL;
            (void) tS.getTopLevelTarget( sys );

            uint32_t min_cores =
                sys->getAttr<ATTR_SBE_IMAGE_MINIMUM_VALID_ECS>();
            min_cores *= (is_fused_mode()) ? 2 : 1; // double minimum for fused
            if ( coreCount < min_cores )
            {
                remainingEcs = trimBitMask(remainingEcs,
                                           min_cores-coreCount);
                o_coreMask |= remainingEcs;
                TRACUCOMP( g_trac_sbe,INFO_MRK"selectBestCores: trimBitMask "
                           "remainingEcs=0x%.8X, min_cores=%d",
                           remainingEcs, min_cores);
            }

        }while(0);

        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"selectBestCores(o_coreMask=0x%.8X)",
                   o_coreMask);

        return err;
    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t getSetMVPDVersion(TARGETING::Target* i_target,
                                 opType_t i_op,
                                 mvpdSbKeyword_t& io_sb_keyword)
    {
        errlHndl_t err = NULL;
        size_t vpdSize = 0;

        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"getSetMVPDVersion(i_op=%d)", i_op );

        do{
            // Read SB Keyword which contains SBE version and dirty bit
            // information
            // Note: First read with NULL for o_buffer sets vpdSize to the
            // correct length
            err = deviceRead( i_target,
                              NULL,
                              vpdSize,
                              DEVICE_MVPD_ADDRESS( MVPD::CP00,
                                                   MVPD::SB ) );

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSetMVPDVersion() - MVPD "
                           "failure getting SB keywordw size HUID=0x%.8X",
                           TARGETING::get_huid(i_target));
                break;
            }

            if(vpdSize != MVPD_SB_RECORD_SIZE)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSetMVPDVersion() - MVPD SB "
                           "keyword wrong length HUID=0x%.8X, length=0x%.2X, "
                           "expected=0x%.2x",
                           TARGETING::get_huid(i_target), vpdSize,
                           MVPD_SB_RECORD_SIZE);
                /*@
                 * @errortype
                 * @moduleid     SBE_GETSET_MVPD_VERSION
                 * @reasoncode   SBE_MVPD_LEN_INVALID
                 * @userdata1    Discovered VPD Size
                 * @userdata2    Expected VPD Size
                 * @devdesc      SB Keyword in MVPD has invalid size
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_GETSET_MVPD_VERSION,
                                    SBE_MVPD_LEN_INVALID,
                                    TO_UINT64(vpdSize),
                                    TO_UINT64(MVPD_SB_RECORD_SIZE));
                ErrlUserDetailsTarget(i_target
                                      ).addToLog(err);
                err->collectTrace(SBE_COMP_NAME, 256);
                err->addProcedureCallout( HWAS::EPUB_PRC_SP_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_MED );

                break;
            }

            if(i_op == MVPDOP_READ)
            {
                err = deviceRead( i_target,
                                  reinterpret_cast<void*>( &io_sb_keyword ),
                                  vpdSize,
                                  DEVICE_MVPD_ADDRESS( MVPD::CP00,
                                                       MVPD::SB ) );
                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSetMVPDVersion() - MVPD "
                               "failure reading SB keyword data HUID=0x%.8X",
                               TARGETING::get_huid(i_target));
                    break;
                }
                TRACDBIN(g_trac_sbe, "MVPD:SB:r", &io_sb_keyword, vpdSize);

            }
            else //write
            {
                TRACDBIN(g_trac_sbe, "MVPD:SB:w", &io_sb_keyword, vpdSize);

                err = deviceWrite( i_target,
                                  reinterpret_cast<void*>( &io_sb_keyword ),
                                  vpdSize,
                                  DEVICE_MVPD_ADDRESS( MVPD::CP00,
                                                       MVPD::SB ) );
                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSetMVPDVersion() - MVPD "
                               "failure writing SB keyword data HUID=0x%.8X",
                               TARGETING::get_huid(i_target));
                    break;
                }
            }

        }while(0);

        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"getSetMVPDVersion()" );

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t readPNORVersion(void*& i_pnorImgHdrPtr,
                               sbe_image_version_t& o_version)
    {
        errlHndl_t err = NULL;
        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"readPNORVersion()" );

        do{
            // @todo RTC 34080 - support Secure Boot Header

            //For Non-secure systems, version is prefixed with
            //'VERSION\0' in ASCII in the 4k header.  The official
            //protocol is to scan for VERSION, then grab the value
            //that follows.

            char* tmpPtr = static_cast<char*>(i_pnorImgHdrPtr);


            //Last reasonable offset is (Version size +
            //size of eyecatcher) bytes from end of Page.
            char* endPtr = tmpPtr +(4*KILOBYTE) -
              sizeof(sbe_image_version_t&) -
              sizeof(NONSECURE_VER_EYECATCH);

            // Increment pointer sizeof(uint64_t) because eyecatcher
            // must be 8-byte aligned
            for(; tmpPtr<endPtr; tmpPtr+=sizeof(uint64_t))
            {
                if(*(reinterpret_cast<uint64_t*>(tmpPtr)) ==
                   NONSECURE_VER_EYECATCH)
                {
                    //increment 8 more bytes and break out
                    tmpPtr+=sizeof(uint64_t);
                    break;
                }
            }

            if(tmpPtr < endPtr)
            {
                memcpy(reinterpret_cast<void*>( &o_version ),
                       tmpPtr,
                       sizeof(o_version));
            }
            else
            {

                TRACFCOMP( g_trac_sbe, ERR_MRK"readPNORVersion() - VERSION not found in SBE image in PNOR");
                /*@
                 * @errortype
                 * @moduleid     SBE_READ_PNOR_VERSION
                 * @reasoncode   SBE_VERSION_NOT_FOUND
                 * @userdata1    Not Used
                 * @userdata2    Not Used
                 * @devdesc      Image Version not found in PNOR
                 *               SBE image.
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_READ_PNOR_VERSION,
                                    SBE_VERSION_NOT_FOUND,
                                    0, 0);
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_SP_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
            }

        }while(0);

        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"readPNORVersion()" );

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t getSbeBootSeeprom(TARGETING::Target* i_target,
                                 sbeSeepromSide_t& o_bootSide,
                                 const bool i_failoverToMaster)
    {
        TRACFCOMP( g_trac_sbe, ENTER_MRK"getSbeBootSeeprom()" );

        errlHndl_t err = NULL;
        uint64_t scomData = 0x0;
        TARGETING::Target* masterProcChipTargetHandle = NULL;

        o_bootSide = SBE_SEEPROM_INVALID;

        do{
            assert(i_target != nullptr,"Bug! Attempting to get the boot seeprom of a null target.");

            TARGETING::Target * l_target=i_target;

            // Get the Master Proc Chip Target for comparisons later
            TargetService& tS = targetService();
            err = tS.queryMasterProcChipTargetHandle(
                                                masterProcChipTargetHandle);

            if ( err )
            {
                break;
            }

            if( i_failoverToMaster &&
                (i_target != masterProcChipTargetHandle) &&
                !(i_target->getAttr<ATTR_SBE_IS_STARTED>()) )
            {
                l_target=masterProcChipTargetHandle;
                TRACFCOMP( g_trac_sbe, INFO_MRK"getSbeBootSeeprom() "
                           "using master proc to read SBE_VITAL_REG: "
                           "i_target=0x%.8x, target=0x%.8x ",
                           TARGETING::get_huid(i_target),
                           TARGETING::get_huid(l_target));

            }

            // Read PERV_SB_CS_SCOM 0x00050008
            size_t op_size = sizeof(scomData);
            err = deviceRead( l_target,
                              &scomData,
                              op_size,
                              DEVICE_SCOM_ADDRESS(PERV_SB_CS_SCOM) );
            if( err )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeBootSeeprom() -Error "
                           "reading SB CS SCOM (0x%.8X) from Target :"
                           "HUID=0x%.8X, RC=0x%X, PLID=0x%lX",
                           PERV_SB_CS_SCOM, // 0x00050008
                           TARGETING::get_huid(l_target),
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            if(scomData & SBE_BOOT_SELECT_MASK)
            {
                o_bootSide = SBE_SEEPROM1;
            }
            else
            {
                o_bootSide = SBE_SEEPROM0;
            }

        }while(0);

        TRACFCOMP( g_trac_sbe,
                   EXIT_MRK"getSbeBootSeeprom(): o_bootSide=0x%X (reg=0x%X, "
                   "tgt=0x%X, %s)",
                   o_bootSide, scomData, TARGETING::get_huid(i_target),
                   (i_target != masterProcChipTargetHandle) ? "slave" :
                   "master");

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t updateSbeBootSeeprom(TARGETING::Target* i_target)
    {
        TRACFCOMP( g_trac_sbe, ENTER_MRK"updateSbeBootSeeprom()" );

        errlHndl_t err = NULL;
        const uint32_t l_sbeBootSelectMask = SBE_BOOT_SELECT_MASK >> 32;

        size_t l_opSize = sizeof(uint32_t);

        do{
            // Read PERV_SB_CS_FSI 0x2808 for target proc
            uint32_t l_targetReg = 0;
            err = DeviceFW::deviceOp(
                         DeviceFW::READ,
                         i_target,
                         &l_targetReg,
                         l_opSize,
                         DEVICE_FSI_ADDRESS(PERV_SB_CS_FSI_BYTE) );
            if( err )
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"updateSbeBootSeeprom(): getCfamRegister, "
                           "PERV_SB_CS_FSI (0x%.4X), proc target = %.8X, "
                           "RC=0x%X, PLID=0x%lX",
                           PERV_SB_CS_FSI, // 0x2808
                           TARGETING::get_huid(i_target),
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

#ifdef CONFIG_SBE_UPDATE_SEQUENTIAL
            // Read version from MVPD for target proc
            mvpdSbKeyword_t l_mvpdSbKeyword;
            err =  getSetMVPDVersion(i_target,
                                     MVPDOP_READ,
                                     l_mvpdSbKeyword);

            if( err )
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"updateSbeBootSeeprom(): getSetMVPDVersion, "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // Determine Boot Side from flags in MVPD
            bool l_bootSide0 = (isIplFromReIplRequest())
                ? (REIPL_SEEPROM_0_VALUE ==
                    (l_mvpdSbKeyword.flags & REIPL_SEEPROM_MASK))
                : (SEEPROM_0_PERMANENT_VALUE ==
                    (l_mvpdSbKeyword.flags & PERMANENT_FLAG_MASK));

#else

            // The slave will use the same side setting as the master
            sbeSeepromSide_t l_bootside = SBE_SEEPROM_INVALID;
            TARGETING::Target * l_masterTarget = nullptr;
            targetService().masterProcChipTargetHandle(l_masterTarget);
            err = getSbeBootSeeprom( l_masterTarget, l_bootside );
            if( err )
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"updateSbeBootSeeprom(): call to getSbeBootSeeprom(master) failed : PLID=%.8X",
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            bool l_bootSide0 = (l_bootside == SBE_SEEPROM0);

            TRACFCOMP( g_trac_sbe,INFO_MRK"updateSbeBootSeeprom(): set SBE boot side %d for proc=%.8X",
                       !l_bootSide0,
                       TARGETING::get_huid(i_target) );

#endif

            if(l_bootSide0)
            {
                // Set Boot Side 0 by clearing bit for side 1
                l_targetReg &= ~l_sbeBootSelectMask;

                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"updateSbeBootSeeprom(): l_read_reg=0x%.8X "
                           "set SBE boot side 0 for proc=%.8llX",
                           l_targetReg,
                           TARGETING::get_huid(i_target) );
            }
            else
            {
                // Set Boot Side 1 by setting bit for side 1
                l_targetReg |= l_sbeBootSelectMask;

                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"updateSbeBootSeeprom(): l_read_reg=0x%.8X "
                           "set SBE boot side 1 for proc=%.8llX",
                           l_targetReg,
                           TARGETING::get_huid(i_target) );
            }

            // Write PERV_SB_CS_FSI 0x2808 back into target proc
            err = DeviceFW::deviceOp(
                         DeviceFW::WRITE,
                         i_target,
                         &l_targetReg,
                         l_opSize,
                         DEVICE_FSI_ADDRESS(PERV_SB_CS_FSI_BYTE) );
            if( err )
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"updateSbeBootSeeprom(): putCfamRegister, "
                           "PERV_SB_CS_FSI (0x%.4X), proc target = %.8X, "
                           "RC=0x%X, PLID=0x%lX",
                           PERV_SB_CS_FSI, // 0x2808
                           TARGETING::get_huid(i_target),
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

        }while(0);

        TRACFCOMP( g_trac_sbe, EXIT_MRK"updateSbeBootSeeprom()" );

        return err;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t loadPnorSection( PNOR::SectionId i_section,
                                PNOR::SectionInfo_t& o_info)
    {
        errlHndl_t l_errl = NULL;

        do
        {
#ifdef CONFIG_SECUREBOOT
            l_errl = loadSecureSection(i_section);
            if (l_errl)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK,"loadPnorSection() - Error from loadSecureSection(%d)", i_section);
                break;
            }
#endif

            // Get PNOR section info from PNOR RP
            l_errl = PNOR::getSectionInfo( i_section, o_info );
            if( l_errl )
            {
                //Don't leave the secure section loaded
#ifdef CONFIG_SECUREBOOT
                errlHndl_t l_tmperrl = unloadSecureSection(i_section);
                if( l_tmperrl )
                {
                    // Things have gotten very bad... just commit the error
                    errlCommit(l_tmperrl, SBE_COMP_ID);
                }
#endif

                //No need to commit error here, it gets handled later
                //just break out to escape this function
                break;
            }

            TRACUCOMP( g_trac_sbe,
                       INFO_MRK"loadPnorSection(%d) - addr = 0x%p ",
                       i_section, o_info.vaddr);

            // Remember that we loaded this section so that we can
            //  try to clean up later if something goes awry
            g_loadedSections.push_back(i_section);
        } while ( 0 );

        return  l_errl;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t unloadPnorSection( PNOR::SectionId i_section)
    {
        errlHndl_t l_errl = NULL;

        do
        {
#ifdef CONFIG_SECUREBOOT
            l_errl = unloadSecureSection(i_section);
            if (l_errl)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK,"unloadPnorSection() - Error from unloadSecureSection(%d)", i_section);
                break;
            }
#endif

            // kick any pages out of the VMM
            PNOR::flush( i_section );

            // remove this section from the list of loaded ones
            g_loadedSections.remove(i_section);
        } while ( 0 );

        return  l_errl;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t getSeepromVersions(sbeTargetState_t& io_sbeState)
    {
        errlHndl_t l_err = nullptr;
        bool l_sbeSupportedSeepromReadOp = true;
        bool l_errFoundDuringChipOp = false;

        //Make sure that io_sbeState had valid information
        assert(io_sbeState.target != NULL, "target member variable not set on io_sbeState");
        do
        {
            //Get Current (boot) Side
            sbeSeepromSide_t tmp_cur_side = SBE_SEEPROM_INVALID;
            l_err = getSbeBootSeeprom(io_sbeState.target, tmp_cur_side);
            if(l_err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                          "determining which seeprom we booted on. Exiting function");
                break;
            }
            bool l_sideZeroActive = (tmp_cur_side == SBE_SEEPROM0);
            /*******************************************/
            /*  Get SEEPROM 0 SBE Version Information  */
            /*******************************************/

            // If the current seeprom is side 0 then attempt read via chipOp
            // TODO RTC:186269 Remove forced I2C path when simics issue is resolved
            if (l_sideZeroActive &&
                !Util::isSimicsRunning())
            {
                l_err = getSeepromSideVersionViaChipOp(io_sbeState.target,
                                            io_sbeState.seeprom_0_ver,
                                            l_sbeSupportedSeepromReadOp);

                if(l_err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                            "getting SBE Information from SEEPROM 0 (Primary) via ChipOp "
                            "RC=0x%X, PLID=0x%lX, will attempt I2C read instead",
                            ERRL_GETRC_SAFE(l_err),
                            ERRL_GETPLID_SAFE(l_err));
                    //Commit error as informational and attempt reading via i2c
                    l_errFoundDuringChipOp = true;
                    l_err->setSev(ERRORLOG::ERRL_SEV_INFORMATIONAL);
                    l_err->collectTrace(SBE_COMP_NAME, 256);
                    l_err->collectTrace(SBEIO_COMP_NAME, 256);
                    errlCommit( l_err, SBE_COMP_ID );
                }
                else if(!l_sbeSupportedSeepromReadOp)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                    "getting SBE Information from SEEPROM 0 (Primary) via ChipOp. The "
                    "SBE firmware level does not support readSeeprom Op, will attempt I2C read instead");
                }
                else
                {
                    TRACDBIN(g_trac_sbe, "getSeepromVersions found via ChipOp -spA",
                            &(io_sbeState.seeprom_0_ver),
                            sizeof(sbeSeepromVersionInfo_t));
                }
            }

            //If side 0 is not active or there was an error trying to read
            //the primary via chipOp, then try reading via I2C
            // TODO RTC:186269 Remove forced I2C path when simics issue is resolved
            if(!l_sideZeroActive || !l_sbeSupportedSeepromReadOp ||
                l_errFoundDuringChipOp || Util::isSimicsRunning())
            {

                l_err = getSeepromSideVersionViaI2c(io_sbeState.target,
                                            EEPROM::SBE_PRIMARY,
                                            io_sbeState.seeprom_0_ver,
                                            io_sbeState.seeprom_0_ver_ECC_fail);

                if(l_err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                            "getting SBE Information from SEEPROM 0 (Primary) via I2C, "
                            "RC=0x%X, PLID=0x%lX",
                            ERRL_GETRC_SAFE(l_err),
                            ERRL_GETPLID_SAFE(l_err));
                    break;
                }

                TRACDBIN(g_trac_sbe, "getSeepromVersions found via I2C -spA",
                        &(io_sbeState.seeprom_0_ver),
                        sizeof(sbeSeepromVersionInfo_t));
            }


            /*******************************************/
            /*  Get SEEPROM 1 SBE Version Information  */
            /*******************************************/

            //If side 1 is active, then attempt read via chipOp
            //Note that there is no reason to attempt chipOp on backup if it failed
            //on the primary.
            // TODO RTC:186269 Remove forced I2C path when simics issue is resolved
            if (!l_sideZeroActive && l_sbeSupportedSeepromReadOp &&
                !l_errFoundDuringChipOp && !Util::isSimicsRunning() )
            {
                l_err = getSeepromSideVersionViaChipOp(io_sbeState.target,
                                                    io_sbeState.seeprom_1_ver,
                                                    l_sbeSupportedSeepromReadOp);

                if(l_err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                            "getting SBE Information from SEEPROM 1 (Backup) via Chipop, "
                            "RC=0x%X, PLID=0x%lX, will attempt I2C read instead",
                            ERRL_GETRC_SAFE(l_err),
                            ERRL_GETPLID_SAFE(l_err));
                    //Commit error as informational and attempt reading via i2c
                    l_errFoundDuringChipOp = true;
                    l_err->setSev(ERRORLOG::ERRL_SEV_INFORMATIONAL);
                    l_err->collectTrace(SBE_COMP_NAME, 256);
                    l_err->collectTrace(SBEIO_COMP_NAME, 256);
                    errlCommit( l_err, SBE_COMP_ID );
                }
                else if(!l_sbeSupportedSeepromReadOp)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                                "getting SBE Information from SEEPROM 1 (Backup) via ChipOp. The "
                                "SBE firmware level does not support readSeeprom Op, will attempt I2C read instead");
                }
                else
                {
                    TRACDBIN(g_trac_sbe, "getSeepromVersions found via Chipop -spB",
                            &(io_sbeState.seeprom_1_ver),
                            sizeof(sbeSeepromVersionInfo_t));
                }
            }

            //If side 1 is not active, or there was an error trying to read
            //the primary via chipOp, then try reading via I2C
            // TODO RTC:186269 Remove forced I2C path when simics issue is resolved
            if(l_sideZeroActive || !l_sbeSupportedSeepromReadOp ||
                l_errFoundDuringChipOp || Util::isSimicsRunning() )
            {
                l_err = getSeepromSideVersionViaI2c(io_sbeState.target,
                                            EEPROM::SBE_BACKUP,
                                            io_sbeState.seeprom_1_ver,
                                            io_sbeState.seeprom_1_ver_ECC_fail);

                if(l_err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromVersions() - Error "
                            "getting SBE Information from SEEPROM 1 (Backup) via I2C, "
                            "RC=0x%X, PLID=0x%lX",
                            ERRL_GETRC_SAFE(l_err),
                            ERRL_GETPLID_SAFE(l_err));
                    break;
                }

                TRACDBIN(g_trac_sbe, "getSeepromVersions-spB found via I2C",
                        &(io_sbeState.seeprom_1_ver),
                        sizeof(sbeSeepromVersionInfo_t));
            }
        }while(0);

        return l_err;
    }

    /////////////////////////////////////////////////////////////////////
    errlHndl_t getSbeInfoState(sbeTargetState_t& io_sbeState)
    {

        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"getSbeInfoState(): HUID=0x%.8X",
                   TARGETING::get_huid(io_sbeState.target));


        errlHndl_t err = nullptr;
        void *sbeHbblImgPtr = nullptr;

        // Clear build information
        io_sbeState.new_imageBuild.buildDate = 0;
        io_sbeState.new_imageBuild.buildTime = 0;
        memset(io_sbeState.new_imageBuild.buildTag,
               '\0',
               sizeof(io_sbeState.new_imageBuild.buildTag) );

        do{

            /***********************************************/
            /*  Determine which SEEPROM System Booted On   */
            /***********************************************/
            //Get Current (boot) Side
            sbeSeepromSide_t tmp_cur_side = SBE_SEEPROM_INVALID;
            err = getSbeBootSeeprom(io_sbeState.target, tmp_cur_side);
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error returned from getSbeBootSeeprom(), "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            io_sbeState.cur_seeprom_side = tmp_cur_side;
            if (io_sbeState.cur_seeprom_side == SBE_SEEPROM0)
            {
                io_sbeState.alt_seeprom_side = SBE_SEEPROM1;
            }
            else if ( io_sbeState.cur_seeprom_side == SBE_SEEPROM1)
            {
                io_sbeState.alt_seeprom_side = SBE_SEEPROM0;
            }
            else
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - Error: "
                           "Unexpected cur_seeprom_side value = 0x%X, ",
                           io_sbeState.cur_seeprom_side);

                 /*@
                  * @errortype
                  * @moduleid     SBE_GET_TARGET_INFO_STATE
                  * @reasoncode   SBE_INVALID_SEEPROM_SIDE
                  * @userdata1    Temporary Current Side
                  * @userdata2    SBE State Current Side
                  * @devdesc      Invalid Boot SEEPROM Side Found
                  */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_GET_TARGET_INFO_STATE,
                                    SBE_INVALID_SEEPROM_SIDE,
                                    tmp_cur_side,
                                    io_sbeState.cur_seeprom_side);
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );

                break;
            }

            TRACUCOMP( g_trac_sbe,"getSbeInfoState() - cur=0x%X, alt=0x%X",
                       io_sbeState.cur_seeprom_side,
                       io_sbeState.alt_seeprom_side);

            /************************************************************/
            /*  Set Target Properties (target_is_master previously set) */
            /************************************************************/
            io_sbeState.ec = io_sbeState.target->getAttr<TARGETING::ATTR_EC>();

            /*******************************************/
            /*  Get SBE SEEPROM Version Information    */
            /*******************************************/
            err = getSeepromVersions(io_sbeState);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                "Error getting SBE Version from SEEPROMs, "
                "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                           break;
            }

            /*******************************************/
            /*  Get PNOR SBE Version Information       */
            /*******************************************/
            void* sbePnorPtr = NULL;
            size_t sbePnorImageSize = 0;
            sbe_image_version_t tmp_pnorVersion;

            err = findSBEInPnor(io_sbeState.target,
                                sbePnorPtr,
                                sbePnorImageSize,
                                &tmp_pnorVersion);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error getting SBE Version from PNOR, "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }
            else
            {
                TRACFCOMP( g_trac_sbe, "getSbeInfoState() - "
                           "sbePnorPtr=%p, sbePnorImageSize=0x%08X (%d)",
                           sbePnorPtr, sbePnorImageSize, sbePnorImageSize);

                // Pull build information from XIP header and trace it
                Util::pullTraceBuildInfo(sbePnorPtr,
                                         io_sbeState.new_imageBuild,
                                         g_trac_sbe);
            }

            // copy tmp_pnorVersion to the main structure
            memcpy ( &io_sbeState.pnorVersion,
                     &tmp_pnorVersion,
                     sizeof(tmp_pnorVersion));


            /*******************************************/
            /*  Get PNOR HBBL Information              */
            /*******************************************/

            // Get HBBL PNOR section info from PNOR RP
            PNOR::SectionInfo_t pnorInfo;
            err = loadPnorSection( PNOR::HB_BOOTLOADER, pnorInfo );
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState: Error calling "
                           "loadPnorSection() rc=0x%.4X",
                           err->reasonCode() );
                break;
            }

            // Create a working copy of HBBL since it may need to be modified
            // and it's not legal to update code partitions
            uint8_t pHbbl[MAX_HBBL_SIZE]={0};
            memcpy(pHbbl,
                   reinterpret_cast<const void*>(pnorInfo.vaddr),
                   sizeof(pHbbl));
            const void* hbblPnorPtr = reinterpret_cast<const void*>(pHbbl);

            // Use max hbbl size and not the PNOR size. The PNOR size can grow
            // to add a secure header, but the code size limit is still 20K.
            TRACFCOMP( g_trac_sbe, "getSbeInfoState() - "
                       "hbblPnorPtr=%p, hbblMaxSize=0x%08X (%d)",
                       hbblPnorPtr, MAX_HBBL_SIZE, MAX_HBBL_SIZE);

            /*******************************************/
            /*  Update the HW Key Hash in the HBBL     */
            /*******************************************/
            // Create an 'all-zero' hash for comparison now and then use it
            // to save hash being put into image for comparison later
            SHA512_t tmp_hash = {0};

            if ( !g_do_hw_keys_hash_transition )
            {
                // Use the HW Key Hash that the system used to boot
                SHA512_t sys_hash = {0};
                SECUREBOOT::getHwKeyHash(sys_hash);

                // Look for 'all-zero' system hash
                if ( memcmp(sys_hash, tmp_hash, sizeof(SHA512_t)) == 0 )
                {
                    // System hash is all zeros, so use HW Key Hash in HBBL
                    // section from PNOR
                    TRACFCOMP( g_trac_sbe, "getSbeInfoState() - Using HW Key "
                               "Hash from HBBL section of PNOR: 0x%8X",
                               sha512_to_u32(
                                   reinterpret_cast<uint8_t*>(
                                       reinterpret_cast<uint64_t>(hbblPnorPtr) +
                                       HBBL_HW_KEY_HASH_LOCATION)));

                    // Save hash for comparison later
                    memcpy (tmp_hash,
                            reinterpret_cast<uint8_t*>(
                                       reinterpret_cast<uint64_t>(hbblPnorPtr) +
                                       HBBL_HW_KEY_HASH_LOCATION),
                            sizeof(SHA512_t));
                }
                else
                {
                    // Use non-zero system hash
                    TRACFCOMP( g_trac_sbe, "getSbeInfoState() - Using System "
                               "HW Key Hash: 0x%.8X",
                               sha512_to_u32(sys_hash));

                    memcpy (reinterpret_cast<void*>(
                                reinterpret_cast<uint64_t>(hbblPnorPtr) +
                                HBBL_HW_KEY_HASH_LOCATION),
                            sys_hash,
                            sizeof(SHA512_t));

                    // Save hash for comparison later
                    memcpy (tmp_hash,
                            sys_hash,
                            sizeof(SHA512_t));
                }
            }
            else
            {
                // Use the Secureboot Transition HW Key Hash found earlier
                TRACFCOMP( g_trac_sbe, "getSbeInfoState() - Using Secureboot "
                           "Transition HW Key Hash: 0x%.8X",
                           sha512_to_u32(g_hw_keys_hash_transition_data));

                memcpy (reinterpret_cast<void*>(
                            reinterpret_cast<uint64_t>(hbblPnorPtr) +
                            HBBL_HW_KEY_HASH_LOCATION),
                        g_hw_keys_hash_transition_data,
                        sizeof(SHA512_t));

                // Save hash for comparison later
                memcpy (tmp_hash,
                        g_hw_keys_hash_transition_data,
                        sizeof(SHA512_t));
            }

            /*******************************************/
            /*  Append HBBL Image from PNOR to SBE     */
            /*  Image from PNOR                        */
            /*******************************************/
            uint32_t sbeHbblImgSize =
                static_cast<uint32_t>(sbePnorImageSize + MAX_HBBL_SIZE);

            // copy SBE image from PNOR to memory
            sbeHbblImgPtr = (void*)SBE_HBBL_IMG_VADDR;
            memcpy ( sbeHbblImgPtr,
                     sbePnorPtr,
                     sbePnorImageSize);

            err = appendHbblToSbe(const_cast<void*>(hbblPnorPtr), // HBBL Image to append
                                  MAX_HBBL_SIZE, // Size of HBBL Image
                                  sbeHbblImgPtr,     // SBE, HBBL Image
                                  sbeHbblImgSize);   // Available/used

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error from procAppendHbblToSbe(), "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // We are now done with the SBE and HBBL images in PNOR, unload
            //  them now to save memory for the other images we have to load
            err = unloadPnorSection(PNOR::SBE_IPL);
            if (err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - Error from unloadPnorSection(PNOR::SBE_IPL)");
                break;
            }

            err = unloadPnorSection(PNOR::HB_BOOTLOADER);
            if (err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK,"getSbeInfoState() - Error from unloadPnorSection(PNOR::HB_BOOTLOADER)");
                break;
            }


            /*******************************************/
            /*  Append RINGOVD Image from PNOR to SBE  */
            /*******************************************/
            // Check if we have a valid ring override section and
            // append it in if so
            uint32_t l_ovdImgSize =
              static_cast<uint32_t>(sbeHbblImgSize+RING_OVD_SIZE);
            err = ringOvd(sbeHbblImgPtr,l_ovdImgSize);
            if(err)
            {
                TRACFCOMP( g_trac_sbe,
                           ERR_MRK"procCustomizeSbeImg(): "
                           "Error in call to ringOvd!");
                break;
            }

            //If it's larger than the original size then we added some overrides
            if(l_ovdImgSize > sbeHbblImgSize)
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"procCustomizeSbeImg(): We added some "
                           "ring overrides, initial image size:%u "
                           "new image size:%u",
                           sbeHbblImgSize, l_ovdImgSize);

                // Set new size for use below
                sbeHbblImgSize = l_ovdImgSize;
            }

            // Pass in the larger of our custom size or MAX_SEEPROM_IMAGE_SIZE
            // -- p9_xip_customize is expecting at least MAX_SEEPROM_IMAGE_SIZE
            sbeHbblImgSize = std::max(sbeHbblImgSize, MAX_SEEPROM_IMAGE_SIZE);

            /*******************************************/
            /*  Customize SBE/HBBL Image and           */
            /*  Calculate CRC of the image             */
            /*******************************************/
            size_t sbeImgSize = 0;


            // get a pointer to the hcode for the .overlays
            PNOR::SectionInfo_t l_hcodePnorInfo;
            err = loadPnorSection(PNOR::HCODE,l_hcodePnorInfo);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"ge() - "
                        "Error from loadPnorSection(HCODE), "
                        "RC=0x%X, PLID=0x%lX",
                        ERRL_GETRC_SAFE(err),
                        ERRL_GETPLID_SAFE(err));
                break;
            }
            char* l_hCodeAddr = reinterpret_cast<char*>(l_hcodePnorInfo.vaddr);


            void * pCustomizedBfr = reinterpret_cast<void*>(SBE_IMG_VADDR);

            err = procCustomizeSbeImg(io_sbeState.target,
                                      l_hCodeAddr,    // HCODE in memory
                                      sbeHbblImgPtr,  //SBE, HBBL in memory
                                      sbeHbblImgSize,
                                      pCustomizedBfr,  //destination
                                      sbeImgSize);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error from procCustomizeSbeImg(), "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // We are now done with the HCODE image in PNOR, unload
            //  it now to save memory.
            err = unloadPnorSection(PNOR::HCODE);
            if (err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - Error from unloadPnorSection(PNOR::HCODE)");
                break;
            }

            // Verify that HW Key Hash is included in customized image
            SHA512_t hash = {0};
            err = getHwKeyHashFromSbeImage(io_sbeState.target,  // ignored
                                           EEPROM::SBE_PRIMARY, // ignored
                                           SBE_SEEPROM_INVALID, // ignored
                                           hash,
                                           pCustomizedBfr);

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error from getHwKeyHashFromSbeImage(), "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // Verify that the HW Key Hash is the same hash used earlier
            if ( memcmp(hash, tmp_hash, sizeof(SHA512_t)) != 0 )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - Error: "
                           "HW Key Hash in customized image 0x%.8X doesn't "
                           "match expected hash 0x%.8X for proc=0x%X",
                           sha512_to_u32(hash),
                           sha512_to_u32(tmp_hash),
                           TARGETING::get_huid(io_sbeState.target));

                /*@
                 * @errortype
                 * @moduleid         SBE_GET_TARGET_INFO_STATE
                 * @reasoncode       SBE_MISMATCHED_HW_KEY_HASH
                 * @userdata1        Target HUID
                 * @userdata2[0:31]  HW Key Hash found in Customized SBE Image
                 * @userdata2[32:63] Expected HW Key Hash
                 * @devdesc          Unexpected HW Key Hash found in SBE Image
                 * @custdesc         A problem occurred while updating processor
                 *                   boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_GET_TARGET_INFO_STATE,
                                    SBE_MISMATCHED_HW_KEY_HASH,
                                    TARGETING::get_huid(io_sbeState.target),
                                    TWO_UINT32_TO_UINT64(
                                      sha512_to_u32(hash),
                                      sha512_to_u32(tmp_hash)));

                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );

                break;
            }


            // save off the hbbl id and remove it from the image
            void * pSearchBfr = pCustomizedBfr;
            uint32_t searchSize = sbePnorImageSize;
            void * pHbblIdStringBfr;

            err = locateHbblIdStringBfr( pSearchBfr,
                                         searchSize,
                                         pHbblIdStringBfr );
            if(err)
            {
                //If string search failure, commit the error and move
                //   to the next proc
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error searhing for HBBL ID string, "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // save off the hbbl ID string and clear the source
            uint8_t tempHbblStringIdBfr[128];
            memcpy( &tempHbblStringIdBfr[0],
                    pHbblIdStringBfr,
                    sizeof(tempHbblStringIdBfr) );

            memset( pHbblIdStringBfr,
                    0,
                    sizeof(tempHbblStringIdBfr) );

            // Calculate Data CRC
            io_sbeState.customizedImage_size = sbeImgSize;
            io_sbeState.customizedImage_crc =
                            Util::crc32_calc(pCustomizedBfr,
                                             sbeImgSize) ;

            TRACFCOMP( g_trac_sbe, "getSbeInfoState() - procCustomizeSbeImg(): "
                       "maxSize=0x%X, actSize=0x%X, crc=0x%X",
                       MAX_SEEPROM_IMAGE_SIZE, sbeImgSize,
                       io_sbeState.customizedImage_crc);

            // restore the hbbl ID string
            memcpy( pHbblIdStringBfr,
                    &tempHbblStringIdBfr[0],
                    sizeof(tempHbblStringIdBfr) );

            /*******************************************/
            /*  Get MVPD SBE Version Information       */
            /*******************************************/
            err =  getSetMVPDVersion(io_sbeState.target,
                                     MVPDOP_READ,
                                     io_sbeState.mvpdSbKeyword);
            if(err)
            {
                //If MVPD is bad, commit the error and move to the next proc
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSbeInfoState() - "
                           "Error reading version from MVPD, "
                           "RC=0x%X, PLID=0x%lX",
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }


            // Determine Permanent Side from flag in MVPD
            if(SEEPROM_0_PERMANENT_VALUE ==
               (io_sbeState.mvpdSbKeyword.flags & PERMANENT_FLAG_MASK))
            {
                io_sbeState.permanent_seeprom_side = SBE_SEEPROM0;
            }
            else // Side 1 must be permanent
            {
                io_sbeState.permanent_seeprom_side = SBE_SEEPROM1;
            }

        }while(0);

        if(err && (io_sbeState.new_imageBuild.buildDate != 0) &&
           (io_sbeState.new_imageBuild.buildTime != 0))
        {
            err->addFFDC(ERRL_COMP_ID,
                         &(io_sbeState.new_imageBuild),
                         sizeof(io_sbeState.new_imageBuild),
                         0,                   // Version
                         ERRL_UDT_BUILD,      // parser for XIP image build info
                         false );             // merge
        }

        return err;

    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t getSeepromSideVersionViaI2c(TARGETING::Target* i_target,
                                     EEPROM::EEPROM_ROLE i_seepromSide,
                                     sbeSeepromVersionInfo_t& o_info,
                                     bool& o_seeprom_ver_ECC_fail)
    {
        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"getSeepromSideVersionViaI2c(): HUID=0x%.8X, side:%d",
                   TARGETING::get_huid(i_target), i_seepromSide);

        errlHndl_t err = NULL;
        PNOR::ECC::eccStatus eccStatus = PNOR::ECC::CLEAN;
        o_seeprom_ver_ECC_fail = false;

        // Set these variables to the read out the max struct size
        // Supported version 1 is a subset of supported version 2
        size_t sbeInfoSize = sizeof(sbeSeepromVersionInfo_t);
        size_t sbeInfoSize_ECC = (sbeInfoSize*9)/8;
        uint8_t * tmp_data_ECC = static_cast<uint8_t*>(
                                        malloc(sbeInfoSize_ECC));

        do{

            /***********************************************/
            /*  Read SBE Version SBE Version Information   */
            /***********************************************/
            // Clear Buffer
            memset( tmp_data_ECC, 0, sbeInfoSize_ECC );

            //Read SBE Versions
            err = deviceRead( i_target,
                              tmp_data_ECC,
                              sbeInfoSize_ECC,
                              DEVICE_EEPROM_ADDRESS(
                                            i_seepromSide,
                                            SBE_VERSION_SEEPROM_ADDRESS,
                                            EEPROM::HARDWARE));

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromSideVersionViaI2c() - "
                           "Error reading SBE Version from Seeprom 0x%X, "
                           "HUID=0x%.8X, RC=0x%X, PLID=0x%lX",
                           i_seepromSide, TARGETING::get_huid(i_target),
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            TRACDBIN(g_trac_sbe,
                     "getSeepromSideVersionViaI2c() - tmp_data_ECC",
                     tmp_data_ECC,
                     sbeInfoSize_ECC);


            // Clear destination
            memset( &o_info, 0, sizeof(o_info) );


            // Initially only look at the first 8-Bytes which should include
            // the struct version value
            // Remove ECC
            eccStatus = removeECC(tmp_data_ECC,
                                  reinterpret_cast<uint8_t*>(&o_info),
                                  8,
                                  SBE_VERSION_SEEPROM_ADDRESS,
                                  SBE_SEEPROM_SIZE);

            TRACUCOMP( g_trac_sbe, "getSeepromSideVersionViaI2c(): First 8-Bytes: "
                       "eccStatus=%d, version=0x%X, data_crc=0x%X",
                       eccStatus, o_info.struct_version, o_info.data_crc);


            if ( STRUCT_VERSION_CHECK(o_info.struct_version) )
            {
                // Supported Versions - set size variable to remove ECC
                sbeInfoSize = SBE_SEEPROM_STRUCT_SIZES[o_info.struct_version];
                sbeInfoSize_ECC = (sbeInfoSize*9)/8;

            }
            else
            {
                // Unsupported versions - ignoring any ECC errors
                TRACFCOMP( g_trac_sbe, "getSeepromSideVersionViaI2c(): Unsupported "
                           "Struct Version=0x%X, ignoring any eccStatus=%d",
                           o_info.struct_version, eccStatus);

                break;
            }

            // Remove ECC for full SBE Version struct
            eccStatus = PNOR::ECC::CLEAN;
            eccStatus = removeECC(tmp_data_ECC,
                                  reinterpret_cast<uint8_t*>(&o_info),
                                  sbeInfoSize,
                                  SBE_VERSION_SEEPROM_ADDRESS,
                                  SBE_SEEPROM_SIZE);

            TRACFCOMP( g_trac_sbe, "getSeepromSideVersionViaI2c(): eccStatus=%d, "
                       "sizeof o_info/sI=%d, sI_ECC=%d, origin golden=%i",
                       eccStatus, sbeInfoSize, sbeInfoSize_ECC, o_info.origin);

            // Handle Uncorrectable ECC - no error log:
            // clear data and set o_seeprom_ver_ECC_fail=true
            if ( eccStatus == PNOR::ECC::UNCORRECTABLE )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getSeepromSideVersionViaI2c() - ECC "
                           "ERROR: Handled. eccStatus=%d, side=%d, sizeof "
                           "o_info/sI=%d, sI_ECC=%d",
                           eccStatus, i_seepromSide, sbeInfoSize,
                           sbeInfoSize_ECC);

                memset( &o_info, 0, sizeof(o_info));
                o_seeprom_ver_ECC_fail = true;

                TRACUCOMP( g_trac_sbe, "getSeepromSideVersionViaI2c(): clearing out "
                "version data (o_info) for side %d and returning "
                "o_seeprom_ver_ECC_fail as true (%d)",
                i_seepromSide, o_seeprom_ver_ECC_fail);
            }

            TRACDBIN(g_trac_sbe,
                     "getSeepromSideVersionViaI2c: data (no ECC)",
                     &o_info,
                     sizeof(o_info));

        }while(0);

        // Free allocated memory
        free(tmp_data_ECC);


        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"getSeepromSideVersionViaI2c: o_seeprom_ver_ECC_fail=%d",
                   o_seeprom_ver_ECC_fail );

        return err;
    }

errlHndl_t getSeepromSideVersionViaChipOp(TARGETING::Target* i_target,
                                          sbeSeepromVersionInfo_t& o_info,
                                          bool& o_opSupported)
    {
        errlHndl_t l_err = nullptr;

        // Set these variables to the read out the max struct size
        // Supported version 1 is a subset of supported version 2
        size_t sbeInfoSize = sizeof(sbeSeepromVersionInfo_t);

        //Set up the buffer which the SBE will copy the version info to
        //Add 127 bytes to the buffer length so we can guarantee a 128 byte aligned addr
        //Note that the SBE_SEEPROM_VERSION_READ_SIZE is 2 * 128 Bytes to be cacheline aligned
        uint8_t * l_seepromReadBuffer = static_cast<uint8_t*>(
                                               malloc(SBE_SEEPROM_VERSION_READ_SIZE + 127 ));

        uint64_t l_seepromReadBufferAligned = ALIGN_X(reinterpret_cast<uint64_t>(l_seepromReadBuffer),
                                                      128);

        do{

            /***********************************************/
            /*  Read SBE Version SBE Version Information   */
            /***********************************************/
            // Clear Buffer
            memset( reinterpret_cast<uint8_t*>(l_seepromReadBufferAligned),
                    0,
                    SBE_SEEPROM_VERSION_READ_SIZE );

            // Clear destination
            memset( &o_info, 0, sizeof(o_info) );

            l_err = SBEIO::sendPsuReadSeeprom(i_target,
                               END_OF_SEEPROM_MINUS_READ_SIZE,
                               SBE_SEEPROM_VERSION_READ_SIZE,
                               mm_virt_to_phys(reinterpret_cast<void*>(l_seepromReadBufferAligned)),
                               o_opSupported);

            if(!l_err && o_opSupported)
            {

                TRACDBIN(g_trac_sbe,
                        "getSeepromSideVersionViaChipOp() - l_seepromReadBufferAligned",
                        reinterpret_cast<uint8_t*>(l_seepromReadBufferAligned),
                        SBE_SEEPROM_VERSION_READ_SIZE);

                // Initially only look at the first 8-Bytes which should include
                // the struct version value
                memcpy ( &o_info, reinterpret_cast<void*>(l_seepromReadBufferAligned), 8);

                if ( STRUCT_VERSION_CHECK(o_info.struct_version) )
                {
                    // Supported Versions - set size variable
                    sbeInfoSize = SBE_SEEPROM_STRUCT_SIZES[o_info.struct_version];
                }
                else
                {
                    // Unsupported versions
                    TRACFCOMP( g_trac_sbe, "getSeepromSideVersion(): Unsupported "
                            "Struct Version=0x%X",
                            o_info.struct_version);

                    break;
                }

                //Copy the sbeInfo data into the struct that was passed into the function
                memcpy ( &o_info, reinterpret_cast<void*>(l_seepromReadBufferAligned), sbeInfoSize);

                TRACDBIN(g_trac_sbe,
                        "getSeepromSideVersionViaChipOp: data (no ECC)",
                        &o_info,
                        sizeof(o_info));
            }
            else
            {
                TRACFCOMP( g_trac_sbe,
                        "Error reading seeprom via chipOp, either the Op isnt supported by SBE or"
                        " something else went wrong, not going to attempt to parse results");
            }

        }while(0);

        //Free up the buffer before returning no matter what
        free(l_seepromReadBuffer);
        l_seepromReadBuffer = nullptr;

        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"getSeepromSideVersionViaChipOp" );
        return l_err;
    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t updateSeepromSide(sbeTargetState_t& io_sbeState)
    {
        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"updateSeepromSide(): HUID=0x%.8X, side=%d",
                   TARGETING::get_huid(io_sbeState.target),
                   io_sbeState.seeprom_side_to_update);

#ifdef CONFIG_CONSOLE
        CONSOLE::displayf(SBE_COMP_NAME,
                          "System Performing SBE Update for PROC %d, side %d",
                        io_sbeState.target->getAttr<TARGETING::ATTR_POSITION>(),
                        io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY ? SBE_SEEPROM0 : SBE_SEEPROM1);
#endif

        errlHndl_t err = NULL;
        int64_t rc = 0;

        int64_t rc_readBack_ECC_memcmp = 0;
        PNOR::ECC::eccStatus eccStatus = PNOR::ECC::CLEAN;

        // This struct is always 8-byte aligned
        size_t sbeInfoSize = sizeof(sbeSeepromVersionInfo_t);
        size_t sbeInfoSize_ECC = (sbeInfoSize*9)/8;


        // Buffers for reading/writing SBE Version Information
        uint8_t * sbeInfo_data = static_cast<uint8_t*>(
                                                malloc(sbeInfoSize));

        uint8_t * sbeInfo_data_ECC = static_cast<uint8_t*>(
                                                malloc(sbeInfoSize_ECC));

        uint8_t * sbeInfo_data_readBack = static_cast<uint8_t*>(
                                                malloc(sbeInfoSize));

        uint8_t * sbeInfo_data_ECC_readBack = static_cast<uint8_t*>(
                                                malloc(sbeInfoSize_ECC));

        do{


            /*************************************************************/
            /*  Write Invalid SBE Version Information                    */
            /*  -- This is done to prevent confusion if there is a fail  */
            /*     when updating the Version or Image after this         */
            /*************************************************************/

            // Create Invalid Version struct (which is always 8-byte aligned)
            uint8_t* sbeInfoEnd = sbeInfo_data + sbeInfoSize;
            for (uint64_t* p = reinterpret_cast<uint64_t*>(sbeInfo_data);
                 p < reinterpret_cast<uint64_t*>(sbeInfoEnd);
                 p++)
            {
                *p = SBE_SEEPROM_STRUCT_INVALID;
            }

            // Inject ECC to Data
            memset( sbeInfo_data_ECC, 0, sbeInfoSize_ECC);
            injectECC(sbeInfo_data,
                      sbeInfoSize,
                      SBE_VERSION_SEEPROM_ADDRESS,
                      SBE_SEEPROM_SIZE,
                      sbeInfo_data_ECC);

            TRACDBIN( g_trac_sbe, "updateSeepromSide: Invalid Info",
                      sbeInfo_data, sbeInfoSize);
            TRACDBIN( g_trac_sbe, "updateSeepromSide: Invalid Info ECC",
                      sbeInfo_data_ECC, sbeInfoSize_ECC);

            err = deviceWrite( io_sbeState.target,
                               sbeInfo_data_ECC,
                               sbeInfoSize_ECC,
                               DEVICE_EEPROM_ADDRESS(
                                             io_sbeState.seeprom_side_to_update,
                                             SBE_VERSION_SEEPROM_ADDRESS,
                                             EEPROM::HARDWARE));
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                           "Writing SBE Version Info: HUID=0x%.8X, side=%d, "
                           "RC=0x%X, PLID=0x%lX",
                           TARGETING::get_huid(io_sbeState.target),
                           io_sbeState.seeprom_side_to_update,
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // In an effort to avoid an infinite loop of updates, if there
            // was an ECC error when reading this SBE Version Information
            // while collecting data, read back this data to ensure there
            // isn't a permanent ECC error on the SEEPROM
            if ( io_sbeState.new_readBack_check == true )
            {
                // Read Back Version Information
                err = deviceRead( io_sbeState.target,
                                  sbeInfo_data_ECC_readBack,
                                  sbeInfoSize_ECC,
                                  DEVICE_EEPROM_ADDRESS(
                                             io_sbeState.seeprom_side_to_update,
                                             SBE_VERSION_SEEPROM_ADDRESS,
                                             EEPROM::HARDWARE));

                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                               "Reading Back SBE Version Info: HUID=0x%.8X, "
                               "side=%d, RC=0x%X, PLID=0x%lX",
                               TARGETING::get_huid(io_sbeState.target),
                               io_sbeState.seeprom_side_to_update,
                               ERRL_GETRC_SAFE(err),
                               ERRL_GETPLID_SAFE(err));
                    break;
                }

                // Compare ECC data
                rc_readBack_ECC_memcmp = memcmp( sbeInfo_data_ECC,
                                                 sbeInfo_data_ECC_readBack,
                                                 sbeInfoSize_ECC);

                // Remove ECC
                eccStatus = removeECC( sbeInfo_data_ECC_readBack,
                                       sbeInfo_data_readBack,
                                       sbeInfoSize,
                                       SBE_VERSION_SEEPROM_ADDRESS,
                                       SBE_SEEPROM_SIZE);

                TRACUCOMP( g_trac_sbe, "updateSeepromSide(): eccStatus=%d, "
                           "sizeof sI=%d, sI_ECC=%d, rc_ECC=%d",
                           eccStatus, sbeInfoSize, sbeInfoSize_ECC,
                           rc_readBack_ECC_memcmp);

                // Fail if uncorrectable ECC or any data miscompare
                if (  ( eccStatus == PNOR::ECC::UNCORRECTABLE ) ||
                      ( rc_readBack_ECC_memcmp != 0 )
                   )
                {

                    // There is an ECC issue with this SEEPROM

                    TRACFCOMP( g_trac_sbe,ERR_MRK"updateSeepromSide() - ECC "
                               "ERROR or Data Miscompare On SBE Version Read "
                               "Back: eccStatus=%d, rc_ECC=%d,  "
                               "sI=%d, sI_ECC=%d, HUID=0x%.8X, side=%d",
                               eccStatus, rc_readBack_ECC_memcmp,
                               sbeInfoSize, sbeInfoSize_ECC,
                               TARGETING::get_huid(io_sbeState.target),
                               io_sbeState.seeprom_side_to_update);

                    TRACFBIN( g_trac_sbe, "updateSeepromSide: readback_wECC",
                              sbeInfo_data_ECC_readBack, sbeInfoSize_ECC);

                    /*@
                     * @errortype
                     * @moduleid     SBE_GET_SEEPROM_INFO
                     * @reasoncode   SBE_ECC_FAIL
                     * @userdata1[0:15]     ECC Status
                     * @userdata1[16:31]    SEEPROM Side
                     * @userdata1[32:47]    RC on Data Compare with ECC
                     * @userdata1[48:63]    <unused>
                     * @userdata2[0:31]     Size - No Ecc
                     * @userdata2[32:63]    Size - ECC
                     * @devdesc      ECC or Data Miscompare Fail Reading Back
                     *               SBE Version Information
                     * @custdesc     ECC or Data Miscompare Fail Reading Back
                     *               Self Boot Engine (SBE) Version Information
                     */
                    err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                        SBE_UPDATE_SEEPROMS,
                                        SBE_ECC_FAIL,
                                        FOUR_UINT16_TO_UINT64(
                                             eccStatus,
                                             io_sbeState.seeprom_side_to_update,
                                             rc_readBack_ECC_memcmp,
                                             0x0),
                                        TWO_UINT32_TO_UINT64(sbeInfoSize,
                                                             sbeInfoSize_ECC));

                    err->collectTrace(SBE_COMP_NAME);

                    err->addPartCallout(
                                         io_sbeState.target,
                                         HWAS::SBE_SEEPROM_PART_TYPE,
                                         HWAS::SRCI_PRIORITY_HIGH,
                                         HWAS::NO_DECONFIG,
                                         HWAS::GARD_NULL );


                    ErrlUserDetailsTarget(io_sbeState.target).addToLog(err);

                    break;
                }

            }

            /*******************************************/
            /*  Update SBE with Customized Image       */
            /*******************************************/
            // The Customized Image For This Target Still Resides In
            // The SBE Update VMM Space: SBE_IMG_VADDR = VMM_VADDR_SBE_UPDATE

            // Inject ECC
            // clear out back half of page block to use as temp space
            // for ECC injected SBE Image.
            rc = mm_remove_pages(RELEASE,
                                 reinterpret_cast<void*>(SBE_ECC_IMG_VADDR),
                                 SBE_ECC_IMG_MAX_SIZE);
            if( rc )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                           "from mm_remove_pages : rc=%d,  HUID=0x%.8X, "
                           "ECC_VADDR=0x%.16X, eccSize=0x%.8X.",
                           rc, TARGETING::get_huid(io_sbeState.target),
                           SBE_ECC_IMG_VADDR,
                           SBE_ECC_IMG_MAX_SIZE );
                /*@
                 * @errortype
                 * @moduleid     SBE_UPDATE_SEEPROMS
                 * @reasoncode   SBE_REMOVE_PAGES_FOR_EC
                 * @userdata1    Requested Address
                 * @userdata2    rc from mm_remove_pages
                 * @devdesc      updateProcessorSbeSeeproms> mm_remove_pages
                 *               RELEASE failed
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_UPDATE_SEEPROMS,
                                    SBE_REMOVE_PAGES_FOR_EC,
                                    TO_UINT64(SBE_ECC_IMG_VADDR),
                                    TO_UINT64(rc));
                //Target isn't directly related to fail, but could be useful
                // to see how far we got before failing.
                ErrlUserDetailsTarget(io_sbeState.target
                                      ).addToLog(err);
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }


            //align size, calculate ECC size
            size_t sbeImgSize = ALIGN_8(io_sbeState.customizedImage_size);
            size_t sbeEccImgSize = setECCSize(sbeImgSize);

            // Check if assert below will fail and values should be traced
            if(sbeEccImgSize > SBE_ECC_IMG_MAX_SIZE)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide(): assert "
                           "values eccSize=0x%.8X <= ECC_MAX_SIZE=0x%.8X",
                           sbeEccImgSize,
                           SBE_ECC_IMG_MAX_SIZE );
            }

            assert(sbeEccImgSize <= SBE_ECC_IMG_MAX_SIZE,
                   "updateSeepromSide() SBE Image with ECC too large");

            TRACUCOMP( g_trac_sbe, INFO_MRK"updateSeepromSide(): "
                       "SBE_VADDR=0x%.16X, ECC_VADDR=0x%.16X, size=0x%.8X, "
                       "eccSize=0x%.8X, UPDATE_END=0x%.16X, UPDATE_SIZE=0x%.8X",
                       SBE_IMG_VADDR,
                       SBE_ECC_IMG_VADDR,
                       sbeImgSize,
                       sbeEccImgSize,
                       VMM_VADDR_SBE_UPDATE_END,
                       VMM_SBE_UPDATE_SIZE );

            injectECC(reinterpret_cast<uint8_t*>(SBE_IMG_VADDR),
                      sbeImgSize,
                      SBE_IMAGE_SEEPROM_ADDRESS,
                      SBE_SEEPROM_SIZE,
                      reinterpret_cast<uint8_t*>(SBE_ECC_IMG_VADDR));

            TRACDBIN(g_trac_sbe,"updateSeepromSide()-start of IMG - no ECC",
                     reinterpret_cast<void*>(SBE_IMG_VADDR), 0x80);
            TRACDBIN(g_trac_sbe,"updateSeepromSide()-start of IMG - ECC",
                     reinterpret_cast<void*>(SBE_ECC_IMG_VADDR), 0x80);


            //Quiesce the SBE before writing current SBE
            if ( ( ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY )
                   &&
                   ( io_sbeState.cur_seeprom_side == SBE_SEEPROM0 ) )
                 ||
                 ( ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_BACKUP )
                   &&
                   ( io_sbeState.cur_seeprom_side == SBE_SEEPROM1 ) ) )
            {
                err = SBEIO::sendPsuQuiesceSbe(io_sbeState.target);

                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                               "quiescing SBE.  RC=0x%X, PLID=0x%lX",
                               ERRL_GETRC_SAFE(err), ERRL_GETPLID_SAFE(err));
                    break;
                }
            }

            //Write new data to seeprom
            TRACFCOMP( g_trac_sbe, INFO_MRK"updateSeepromSide(): Write New "
                       "SBE Image for Target 0x%X to Seeprom %d",
                       TARGETING::get_huid(io_sbeState.target),
                       io_sbeState.seeprom_side_to_update );

            //Write image to indicated side
            err = deviceWrite(io_sbeState.target,
                              reinterpret_cast<void*>(SBE_ECC_IMG_VADDR),
                              sbeEccImgSize,
                              DEVICE_EEPROM_ADDRESS(
                                            io_sbeState.seeprom_side_to_update,
                                            SBE_IMAGE_SEEPROM_ADDRESS,
                                            EEPROM::HARDWARE));

            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                           "writing new SBE image to size=%d. HUID=0x%.8X."
                           "SBE_VADDR=0x%.16X, ECC_VADDR=0x%.16X, size=0x%.8X, "
                           "eccSize=0x%.8X, EEPROM offset=0x%X, "
                           "RC=0x%X, PLID=0x%lX",
                           io_sbeState.seeprom_side_to_update,
                           TARGETING::get_huid(io_sbeState.target),
                           SBE_IMG_VADDR, SBE_ECC_IMG_VADDR, sbeImgSize,
                           sbeEccImgSize, SBE_IMAGE_SEEPROM_ADDRESS,
                           ERRL_GETRC_SAFE(err), ERRL_GETPLID_SAFE(err));
                break;
            }

            /*******************************************/
            /*  Update SBE Version Information         */
            /*******************************************/

            // The new version has already been created
            memcpy(sbeInfo_data, &io_sbeState.new_seeprom_ver, sbeInfoSize);

            // Inject ECC to Data
            memset( sbeInfo_data_ECC, 0, sbeInfoSize_ECC);
            injectECC(sbeInfo_data,
                      sbeInfoSize,
                      SBE_VERSION_SEEPROM_ADDRESS,
                      SBE_SEEPROM_SIZE,
                      sbeInfo_data_ECC);

            TRACDBIN( g_trac_sbe, "updateSeepromSide: Info",
                      sbeInfo_data, sbeInfoSize);
            TRACDBIN( g_trac_sbe, "updateSeepromSide: Info ECC",
                      sbeInfo_data_ECC, sbeInfoSize_ECC);

            err = deviceWrite( io_sbeState.target,
                               sbeInfo_data_ECC,
                               sbeInfoSize_ECC,
                               DEVICE_EEPROM_ADDRESS(
                                             io_sbeState.seeprom_side_to_update,
                                             SBE_VERSION_SEEPROM_ADDRESS,
                                             EEPROM::HARDWARE));
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"updateSeepromSide() - Error "
                           "Writing SBE Version Info: HUID=0x%.8X, side=%d, "
                           "RC=0x%X, PLID=0x%lX",
                           TARGETING::get_huid(io_sbeState.target),
                           io_sbeState.seeprom_side_to_update,
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));
                break;
            }

            // Successful update if we get here, so update internal code
            // structure with the new version information
            memcpy( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY
                    ? &io_sbeState.seeprom_0_ver : &io_sbeState.seeprom_1_ver,
                    &io_sbeState.new_seeprom_ver,
                    sbeInfoSize );

            // Also update with new Build date, time, and tag for MVPD
            memcpy( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY
                    ? &io_sbeState.mvpdSbKeyword.seeprom_0_build
                    : &io_sbeState.mvpdSbKeyword.seeprom_1_build,
                    &io_sbeState.new_imageBuild,
                    sizeof(Util::imageBuild_t) );
        }while(0);

        // Free allocated memory
        free( sbeInfo_data );
        free( sbeInfo_data_ECC);
        free( sbeInfo_data_readBack );
        free( sbeInfo_data_ECC_readBack );

#ifdef CONFIG_SBE_UPDATE_SIMULTANEOUS
        // If no error, recursively call this function for the other SEEPROM
        if ( ( err == NULL ) &&
             ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY ) )
        {
            io_sbeState.seeprom_side_to_update = EEPROM::SBE_BACKUP;
            TRACFCOMP( g_trac_sbe,
                       "updateSeepromSide(): Recursively calling itself: "
                       "HUID=0x%.8X, side=%d",
                       TARGETING::get_huid(io_sbeState.target),
                       io_sbeState.seeprom_side_to_update);

            err = updateSeepromSide(io_sbeState);
        }
#endif

#ifdef CONFIG_SBE_UPDATE_SEQUENTIAL

        // If no error and a key transition in progress, recursively call this
        // function for the other SEEPROM
        if ( ( err == nullptr ) &&
             ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY ) &&
             ( g_do_hw_keys_hash_transition) )
        {
            io_sbeState.seeprom_side_to_update = EEPROM::SBE_BACKUP;
            TRACFCOMP( g_trac_sbe,
                       "updateSeepromSide(): Recursively calling itself: "
                       "HUID=0x%.8X, side=%d",
                       TARGETING::get_huid(io_sbeState.target),
                       io_sbeState.seeprom_side_to_update);

            err = updateSeepromSide(io_sbeState);
        }
#endif

#ifdef CONFIG_SBE_UPDATE_INDEPENDENT
        //If MFG flag is set to indicate update both side of SBE
        //Update both sides of SBE - even in indepent mode
        if (g_update_both_sides)
        {
            // If no error, recursively call this function for the other SEEPROM
            if ( ( err == NULL ) &&
                 ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY ) )
            {
                io_sbeState.seeprom_side_to_update = EEPROM::SBE_BACKUP;
                TRACFCOMP( g_trac_sbe, "UPDATE_BOTH_SIDES_OF_SBE MNFG Flag indicated, will update both sides" );
                TRACFCOMP( g_trac_sbe,
                           "updateSeepromSide(): Recursively calling itself: "
                           "HUID=0x%.8X, side=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           io_sbeState.seeprom_side_to_update);
                 err = updateSeepromSide(io_sbeState);
            }
        }
#endif

        return err;
    }



/////////////////////////////////////////////////////////////////////
    errlHndl_t getTargetUpdateActions(sbeTargetState_t& io_sbeState)
    {
        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"getTargetUpdateActions(): HUID=0x%.8X",
                   TARGETING::get_huid(io_sbeState.target));

        errlHndl_t err = NULL;

        bool seeprom_0_isDirty =    false;
        bool seeprom_1_isDirty =    false;
#ifndef CONFIG_SBE_UPDATE_CONSECUTIVE
        bool current_side_isDirty = false;
        bool alt_side_isDirty     = false;
#endif

        bool pnor_check_dirty     = false;
        bool crc_check_dirty      = false;
        bool isSimics_check       = false;

        TARGETING::Target * l_sys = nullptr;

        // Set system_situation - bits defined in sbe_update.H
        uint8_t system_situation = 0x00;

        do{

            /**************************************************************/
            /*  Compare SEEPROM 0 with PNOR and Customized Image CRC --   */
            /*  -- dirty or clean?                                        */
            /**************************************************************/
            // Check PNOR and SEEPROM 0 Version
            if ( 0 != memcmp(&(io_sbeState.pnorVersion),
                             &(io_sbeState.seeprom_0_ver.image_version),
                             SBE_IMAGE_VERSION_SIZE) )
            {
                pnor_check_dirty = true;
            }

            // Check CRC and SEEPROM 0 CRC
            if ( io_sbeState.customizedImage_crc !=
                 io_sbeState.seeprom_0_ver.data_crc )
            {
                crc_check_dirty = true;
            }

            // Check if in simics
            if ( ( io_sbeState.seeprom_0_ver.struct_version ==
                   STRUCT_VERSION_SIMICS )
                 && ( Util::isSimicsRunning() )
               )
            {
                isSimics_check = true;
            }

            if ( ( pnor_check_dirty ||
                   crc_check_dirty )
                 && !isSimics_check )
            {
                seeprom_0_isDirty = true;
#ifdef CONFIG_SBE_UPDATE_CONSECUTIVE
                system_situation |= SITUATION_SIDE_0_DIRTY;
#endif
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: Seeprom0 "
                           "dirty: pnor=%d, crc=%d (custom=0x%X/s0=0x%X), "
                           "isSimics=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           pnor_check_dirty, crc_check_dirty,
                           io_sbeState.customizedImage_crc,
                           io_sbeState.seeprom_0_ver.data_crc,
                           isSimics_check);
            }
            else
            {
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: Seeprom0 "
                           "flagged as clean: pnor=%d, crc=%d "
                           "(custom=0x%X/s0=0x%X), isSimics=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           pnor_check_dirty, crc_check_dirty,
                           io_sbeState.customizedImage_crc,
                           io_sbeState.seeprom_0_ver.data_crc,
                           isSimics_check);
            }

            /**************************************************************/
            /*  Compare SEEPROM 1 with PNOR and Customized Image CRC --   */
            /*  -- dirty or clean?                                        */
            /**************************************************************/
            // reset dirty variables
            pnor_check_dirty     = false;
            crc_check_dirty      = false;
            isSimics_check       = false;

            // Check PNOR and SEEPROM 1 Version
            if ( 0 != memcmp(&(io_sbeState.pnorVersion),
                             &(io_sbeState.seeprom_1_ver.image_version),
                             SBE_IMAGE_VERSION_SIZE) )
            {
                pnor_check_dirty = true;
            }

            // Check CRC and SEEPROM 1 CRC
            if ( io_sbeState.customizedImage_crc !=
                 io_sbeState.seeprom_1_ver.data_crc )
            {
                crc_check_dirty = true;
            }

            // Check if in simics
            if ( ( io_sbeState.seeprom_1_ver.struct_version ==
                   STRUCT_VERSION_SIMICS )
                 && ( Util::isSimicsRunning() )
               )
            {
                isSimics_check = true;
            }

            if ( (pnor_check_dirty ||
                  crc_check_dirty )
                 && !isSimics_check )
            {
                seeprom_1_isDirty = true;
#ifdef CONFIG_SBE_UPDATE_CONSECUTIVE
                system_situation |= SITUATION_SIDE_1_DIRTY;
#endif
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: Seeprom1 "
                           "dirty: pnor=%d, crc=%d (custom=0x%X/s1=0x%X), "
                           "isSimics=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           pnor_check_dirty, crc_check_dirty,
                           io_sbeState.customizedImage_crc,
                           io_sbeState.seeprom_1_ver.data_crc,
                           isSimics_check);
            }
            else
            {
                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: Seeprom1 "
                           "flagged as clean: pnor=%d, crc=%d "
                           "(custom=0x%X/s1=0x%X), isSimics=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           pnor_check_dirty, crc_check_dirty,
                           io_sbeState.customizedImage_crc,
                           io_sbeState.seeprom_1_ver.data_crc,
                           isSimics_check);
            }


            // Extra information for unit testing
            if ( seeprom_0_isDirty || seeprom_1_isDirty )
            {
                TRACFBIN( g_trac_sbe,
                          "PNOR Version",
                          &(io_sbeState.pnorVersion),
                          16 ) ;

                TRACFBIN( g_trac_sbe,
                          "Seeprom0: Image Version",
                          &(io_sbeState.seeprom_0_ver.image_version),
                          16 ) ;

                TRACFBIN( g_trac_sbe,
                          "Seeprom1: Image Version",
                          &(io_sbeState.seeprom_1_ver.image_version),
                          16 ) ;

                TRACFBIN( g_trac_sbe,
                          "MVPD SB",
                          &(io_sbeState.mvpdSbKeyword),
                          sizeof(mvpdSbKeyword_t));
            }


            /**************************************************************/
            /*  Determine what side to update                             */
            /**************************************************************/
#ifndef CONFIG_SBE_UPDATE_CONSECUTIVE
            // Set cur and alt isDirty values
            if( io_sbeState.cur_seeprom_side == SBE_SEEPROM0 )
            {
                current_side_isDirty = seeprom_0_isDirty;
                alt_side_isDirty     = seeprom_1_isDirty;
            }
            else
            {
                current_side_isDirty = seeprom_1_isDirty;
                alt_side_isDirty     = seeprom_0_isDirty;
            }

            // Bit 0: current_side is permanent (0) or temp (1)
            // -- defaulted to 0 (cur=perm) above
            if ( io_sbeState.cur_seeprom_side !=
                 io_sbeState.permanent_seeprom_side )
            {
               system_situation |= SITUATION_CUR_IS_TEMP;
            }

            // Bit 1:  current_side clean (0) or dirty (1)
            // -- defaulted to 0 (clean) above
            if ( current_side_isDirty )
            {
                system_situation |= SITUATION_CUR_IS_DIRTY;
            }

            // Bit 2:  alt_side is clean (0) or dirty (1)
            if ( alt_side_isDirty )
            {
                system_situation |= SITUATION_ALT_IS_DIRTY;
            }
#else
            if (io_sbeState.cur_seeprom_side == SBE_SEEPROM1)
            {
                system_situation |= SITUATION_BOOT_SIDE_1;
            }
#endif

            // Call function to update actions
            err = decisionTreeForUpdates(io_sbeState, system_situation);

            if ( err ) { break; }

            TRACUCOMP( g_trac_sbe, "getTargetUpdateActions() - system_situation"
                       "= 0x%.2X, actions=0x%.8X, Update EEPROM=0x%X",
                       system_situation,
                       io_sbeState.update_actions,
                       io_sbeState.seeprom_side_to_update);

            /**************************************************************/
            /*  Setup new SBE Image Version Info, if necessary            */
            /**************************************************************/
            if ( ( io_sbeState.update_actions & UPDATE_SBE ) ||
                 ( io_sbeState.update_actions & UPDATE_NEST_FREQ ) )
            {
                memset(&(io_sbeState.new_seeprom_ver),
                       0x0,
                       sizeof(sbeSeepromVersionInfo_t));
                // the above memset also has the side effect of setting the
                // origin field to WORKING_SIDE which is the default

                io_sbeState.new_seeprom_ver.struct_version =
                                            STRUCT_VERSION_LATEST;

                memcpy( &(io_sbeState.new_seeprom_ver.image_version),
                        &(io_sbeState.pnorVersion),
                        SBE_IMAGE_VERSION_SIZE);

                memcpy( &(io_sbeState.new_seeprom_ver.data_crc),
                        &(io_sbeState.customizedImage_crc),
                        sizeof(io_sbeState.new_seeprom_ver.data_crc));

                TARGETING::targetService().getTopLevelTarget( l_sys );
                io_sbeState.new_seeprom_ver.nest_freq_mhz =
                         l_sys->getAttr<TARGETING::ATTR_FREQ_PB_MHZ>();

                // If there was an ECC fail on either SEEPROM, do a read-back
                // Check when writing this information to the SEEPROM
                io_sbeState.new_readBack_check = (
                                io_sbeState.seeprom_0_ver_ECC_fail ||
                                io_sbeState.seeprom_1_ver_ECC_fail);

                TRACFBIN( g_trac_sbe,
                          "getTargetUpdateActions() - New SBE Version Info",
                          &(io_sbeState.new_seeprom_ver),
                          sizeof(sbeSeepromVersionInfo_t));
            }

            /**************************************************************/
            /*  Update MVPD Struct to write back, if necessary            */
            /**************************************************************/
            if ( io_sbeState.update_actions & UPDATE_MVPD )
            {
                // Note: mvpdSbKeyword.flags updated in decisionTreeForUpdates()

                if ( io_sbeState.seeprom_side_to_update == EEPROM::SBE_PRIMARY )
                {
                    memcpy(&(io_sbeState.mvpdSbKeyword.seeprom_0_data_crc),
                           &(io_sbeState.customizedImage_crc),
                          sizeof(io_sbeState.mvpdSbKeyword.seeprom_0_data_crc));

                    memcpy(&(io_sbeState.mvpdSbKeyword.seeprom_0_short_version),
                           &(io_sbeState.pnorVersion),
                           SBE_MVPD_SHORT_IMAGE_VERSION_SIZE);
                }
                else // EEPROM::SBE_Backup
                {
                    memcpy(&(io_sbeState.mvpdSbKeyword.seeprom_1_data_crc),
                           &(io_sbeState.customizedImage_crc),
                          sizeof(io_sbeState.mvpdSbKeyword.seeprom_1_data_crc));

                    memcpy(&(io_sbeState.mvpdSbKeyword.seeprom_1_short_version),
                           &(io_sbeState.pnorVersion),
                           SBE_MVPD_SHORT_IMAGE_VERSION_SIZE);
                }
            }


        }while(0);

        return err;


    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t decisionTreeForUpdates(sbeTargetState_t& io_sbeState,
                                uint8_t i_system_situation)
    {
        errlHndl_t err = NULL;

        uint32_t l_actions           = CLEAR_ACTIONS;
        io_sbeState.update_actions   = CLEAR_ACTIONS;
        io_sbeState.seeprom_side_to_update = EEPROM::LAST_CHIP_TYPE;

        do{

            // To be safe, we're only look at the bits defined in sbe_update.H
            i_system_situation &= SITUATION_ALL_BITS_MASK;

#ifdef CONFIG_SBE_UPDATE_INDEPENDENT
            //Check if MFG flag set to indicate both sides should be updated
            if (g_update_both_sides)
            {
                decisionTreeForUpdatesSimultaneous(l_actions,
                                                   io_sbeState,
                                                   i_system_situation);
            }
            else
            {
                // The 2 SBE SEEPROMs are independent of each other
                // Determine if PNOR is 1- or 2-sided and if the current
                // Seeprom is pointing at PNOR's GOLDEN side
                PNOR::SideId tmp_side = PNOR::WORKING;
                PNOR::SideInfo_t pnor_side_info;
                err = PNOR::getSideInfo (tmp_side, pnor_side_info);
                if ( err )
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK
                               "SBE Update() - Error returned from "
                               "PNOR::getSideInfo() rc=0x%.4X, Target UID=0x%X",
                               err->reasonCode(),
                               TARGETING::get_huid(io_sbeState.target));
                    break;
                }

                TRACUCOMP( g_trac_sbe,INFO_MRK"SBE Update tgt=0x%X: PNOR Info: "
                           "side-%c, sideId=0x%X, isGolden=%d, hasOtherSide=%d",
                           TARGETING::get_huid(io_sbeState.target),
                           pnor_side_info.side, pnor_side_info.id,
                           pnor_side_info.isGolden,
                           pnor_side_info.hasOtherSide);

                if ( pnor_side_info.isGolden == true )
                {
                    // Nothing to do (covered in istep 6 function)
                    l_actions = CLEAR_ACTIONS;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                            "Booting READ_ONLY SEEPROM pointing at PNOR's "
                            "GOLDEN side. No updates for cur side=%d. Continue "
                            "IPL. (sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                            TARGETING::get_huid(io_sbeState.target),
                            io_sbeState.cur_seeprom_side,
                            i_system_situation, l_actions,
                            io_sbeState.mvpdSbKeyword.flags);
                }
                else if (  ( pnor_side_info.hasOtherSide == false ) &&
                         ( io_sbeState.cur_seeprom_side == READ_ONLY_SEEPROM ) )
                {
                    // Even though current seeprom is not pointing at PNOR's
                    // GOLDEN side, treat like READ_ONLY if booting from
                    // READ_ONLY seeprom and PNOR does not have another side
                    // - No Update (ie, Palmetto configuration)
                    l_actions = CLEAR_ACTIONS;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "Treating cur like READ_ONLY SBE SEEPROM. "
                               "No updates for cur side=%d. Continue IPL. "
                               "(sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                               TARGETING::get_huid(io_sbeState.target),
                               io_sbeState.cur_seeprom_side,
                               i_system_situation, l_actions,
                               io_sbeState.mvpdSbKeyword.flags);
                }
                else // proceed to update this side
                {
                    // proceed to update this side
                    TRACUCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "NOT Booting READ_ONLY SEEPROM. Check for update"
                               " on cur side=%d ",
                               TARGETING::get_huid(io_sbeState.target),
                               io_sbeState.cur_seeprom_side);

                    // Check for clean vs. dirty only on cur side
                    if ( i_system_situation & SITUATION_CUR_IS_DIRTY )
                    {
                        //  Update cur side and re-ipl
                        l_actions |= IPL_RESTART;
                        l_actions |= DO_UPDATE;
                        l_actions |= UPDATE_SBE;
                        //even though flags byte not updated
                        l_actions |= UPDATE_MVPD;

                        // Set Update side to cur
                        io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.cur_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                     ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur side (%d) dirty. Update cur. Re-IPL. "
                                   "(sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions,
                                   io_sbeState.mvpdSbKeyword.flags);
                    }
                    else
                    {
                        // Cur side clean - No Updates - Continue IPL
                        l_actions = CLEAR_ACTIONS;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur side (%d) clean-no updates. "
                                   "Continue IPL. (sit=0x%.2X, act=0x%.8X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions);
                    }
                }
            }
#elif CONFIG_SBE_UPDATE_SIMULTANEOUS
            decisionTreeForUpdatesSimultaneous(l_actions,
                                               io_sbeState,
                                               i_system_situation);

#elif CONFIG_SBE_UPDATE_SEQUENTIAL

            // On a secure boot key transition, force both sides to update
            if (g_do_hw_keys_hash_transition)
            {
                decisionTreeForUpdatesSimultaneous(l_actions,
                                                   io_sbeState,
                                                   i_system_situation);
            }
            else
            {
                // Updating the SEEPROMs 1-at-a-time
                switch ( i_system_situation )
                {

                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_TEMP  |
                           SITUATION_CUR_IS_DIRTY |
                           SITUATION_ALT_IS_DIRTY  ) :

                        // 0xE0: cur=temp, cur=dirty, alt=dirty
                        // Treat like 0xC0
                        // not sure why we booted off of temp

                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_TEMP  |
                           SITUATION_CUR_IS_DIRTY |
                           SITUATION_ALT_IS_CLEAN  ) :


                        // 0xC0: cur=temp, cur=dirty, alt=clean
                        // Bad path: we shouldn't be booting to dirty side
                        // Update Alt and re-IPL to it
                        // Update MVPD flag: make cur=perm (because we know it
                        //  works a bit)

                        l_actions |= IPL_RESTART;
                        l_actions |= DO_UPDATE;
                        l_actions |= UPDATE_MVPD;
                        l_actions |= UPDATE_SBE;

                        // Set Update side to alt
                        io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.alt_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                    ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP ;

                        // Update MVPD PERMANENT flag: make cur=perm
                        ( io_sbeState.cur_seeprom_side == SBE_SEEPROM0 ) ?
                             // clear bit 0
                             io_sbeState.mvpdSbKeyword.flags &=
                                 ~PERMANENT_FLAG_MASK
                             : //set bit 0
                             io_sbeState.mvpdSbKeyword.flags |=
                                 PERMANENT_FLAG_MASK;

                        // Update MVPD RE-IPL SEEPROM flag: re-IPL on ALT:
                        ( io_sbeState.alt_seeprom_side == SBE_SEEPROM0 ) ?
                             // clear bit 1
                             io_sbeState.mvpdSbKeyword.flags &=
                                 ~REIPL_SEEPROM_MASK
                             : //set bit 1
                             io_sbeState.mvpdSbKeyword.flags |=
                                 REIPL_SEEPROM_MASK;


                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur=temp/dirty(%d). Update alt. Re-IPL. "
                                   "Update MVPD flag "
                                   "(sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions,
                                   io_sbeState.mvpdSbKeyword.flags);


                        break;

                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_TEMP  |
                           SITUATION_CUR_IS_CLEAN |
                           SITUATION_ALT_IS_DIRTY  ) :

                        // 0xA0: cur=temp, cur=clean, alt=dirty
                        // Common 2nd step of Code Update path
                        // Update Alt and Continue IPL
                        // Update MVPD flag: make cur=perm

                        l_actions |= DO_UPDATE;
                        l_actions |= UPDATE_MVPD;
                        l_actions |= UPDATE_SBE;

                        // Set Update side to alt
                        io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.alt_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                    ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP ;


                        // MVPD flag Update
                        // Update MVPD flag make cur=perm
                        ( io_sbeState.cur_seeprom_side == SBE_SEEPROM0 ) ?
                             // clear bit 0
                             io_sbeState.mvpdSbKeyword.flags &=
                                 ~PERMANENT_FLAG_MASK
                             : // set bit 0
                             io_sbeState.mvpdSbKeyword.flags |=
                                 PERMANENT_FLAG_MASK;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur=temp/clean(%d), alt=dirty. "
                                   "Update alt. Continue IPL. Update MVPD flag."
                                   "(sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions,
                                   io_sbeState.mvpdSbKeyword.flags);

                        break;


                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_TEMP  |
                           SITUATION_CUR_IS_CLEAN |
                           SITUATION_ALT_IS_CLEAN  ) :

                        // 0x80: cur=temp, cur=clean, alt=clean
                        // Both sides are clean,
                        // Not sure why cur=temp, but do nothing

                        l_actions = CLEAR_ACTIONS;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "Both sides clean-no updates. cur was temp "
                                   "(%d). Continue IPL. (sit=0x%.2X, "
                                   "act=0x%.8X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions);

                        break;


                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_PERM  |
                           SITUATION_CUR_IS_DIRTY |
                           SITUATION_ALT_IS_DIRTY  ) :

                        // 0x60: cur=perm, cur=dirty, alt=dirty
                        // Common situation: likely first step of code update
                        // Update alt and re-ipl
                        l_actions |= IPL_RESTART;
                        l_actions |= DO_UPDATE;
                        l_actions |= UPDATE_MVPD;
                        l_actions |= UPDATE_SBE;

                        // Set Update side to alt
                        io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.alt_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                    ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP ;

                        // Update MVPD RE-IPL SEEPROM flag: re-IPL on ALT:
                        ( io_sbeState.alt_seeprom_side == SBE_SEEPROM0 ) ?
                             // clear bit 1
                             io_sbeState.mvpdSbKeyword.flags &=
                                 ~REIPL_SEEPROM_MASK
                             : // set bit 1
                             io_sbeState.mvpdSbKeyword.flags |=
                                 REIPL_SEEPROM_MASK;

                        // If istep mode, re-IPL bit won't be checked, so also
                        // change perm flag to boot off of alt on next IPL
                        if ( g_istep_mode )
                        {
                            // Update MVPD PERMANENT flag: make alt=perm
                            (io_sbeState.alt_seeprom_side == SBE_SEEPROM0 ) ?
                             // clear bit 0
                             io_sbeState.mvpdSbKeyword.flags &=
                                 ~PERMANENT_FLAG_MASK
                             : //set bit 0
                             io_sbeState.mvpdSbKeyword.flags |=
                                 PERMANENT_FLAG_MASK;

                            TRACFCOMP(g_trac_sbe,INFO_MRK"SBE Update tgt=0x%X: "
                                      "istep mode: update alt to perm, (sit="
                                      "0x%.2X)",
                                      TARGETING::get_huid(io_sbeState.target),
                                      i_system_situation);
                        }

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur=perm/dirty(%d), alt=dirty. Update alt. "
                                   "re-IPL. (sit=0x%.2X, act=0x%.8X, "
                                   "flags=0x%.2X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions,
                                   io_sbeState.mvpdSbKeyword.flags);

                        break;


                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_PERM  |
                           SITUATION_CUR_IS_DIRTY |
                           SITUATION_ALT_IS_CLEAN  ) :

                        // 0x40: cur=perm, cur=dirty, alt=clean
                        // Ask FSP if we just re-IPLed due to our request.
                        // If Yes: Working PERM side is out-of-sync, so callout
                        //         SBE code, but continue IPL on dirty image
                        // If Not: Update alt and re-IPL

                        if ( isIplFromReIplRequest() )
                        {
                            l_actions = CLEAR_ACTIONS;
                            TRACFCOMP(g_trac_sbe, INFO_MRK"SBE Update "
                                      "tgt=0x%X: cur=perm/dirty(%d), "
                                      "alt=clean. On our Re-"
                                      "IPL. Call-out SBE code but Continue "
                                      "IPL. (sit=0x%.2X, act=0x%.8X)",
                                      TARGETING::get_huid(io_sbeState.target),
                                      io_sbeState.cur_seeprom_side,
                                      i_system_situation, l_actions);

                            /*@
                             * @errortype
                             * @moduleid     SBE_DECISION_TREE
                             * @reasoncode   SBE_PERM_SIDE_DIRTY_BAD_PATH
                             * @userdata1    System Situation
                             * @userdata2    Update Actions
                             * @devdesc      Bad Path in decisionUpdateTree:
                             *               cur=PERM/DIRTY
                             * @custdesc     A problem occurred while updating
                             *               processor boot code.
                             */
                            err = new ErrlEntry(ERRL_SEV_RECOVERED,
                                                SBE_DECISION_TREE,
                                                SBE_PERM_SIDE_DIRTY_BAD_PATH,
                                                TO_UINT64(i_system_situation),
                                                TO_UINT64(l_actions));
                            // Target isn't directly related to fail, but could
                            // be useful to see how far we got before failing.
                            ErrlUserDetailsTarget(io_sbeState.target
                                                  ).addToLog(err);
                            err->collectTrace(SBE_COMP_NAME);
                            err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                                      HWAS::SRCI_PRIORITY_HIGH);
                            break;

                        }
                        else
                        {
                            // Update alt and re-ipl
                            l_actions |= IPL_RESTART;
                            l_actions |= DO_UPDATE;
                            l_actions |= UPDATE_MVPD;
                            l_actions |= UPDATE_SBE;

                            // Set Update side to alt
                            io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.alt_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                    ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP ;

                            // Update MVPD RE-IPL SEEPROM flag: re-IPL on ALT:
                            ( io_sbeState.alt_seeprom_side == SBE_SEEPROM0 ) ?
                              // clear bit 1
                              io_sbeState.mvpdSbKeyword.flags &=
                                  ~REIPL_SEEPROM_MASK
                              : // set bit 1
                              io_sbeState.mvpdSbKeyword.flags |=
                                  REIPL_SEEPROM_MASK;

                            TRACFCOMP(g_trac_sbe,INFO_MRK"SBE Update tgt=0x%X: "
                                      "cur=perm/dirty(%d), alt=clean. Not our "
                                      "Re-IPL. Update alt and MVPD. re-IPL. "
                                      "(sit=0x%.2X, act=0x%.8X, flags=0x%.2X)",
                                      TARGETING::get_huid(io_sbeState.target),
                                      io_sbeState.cur_seeprom_side,
                                      i_system_situation, l_actions,
                                      io_sbeState.mvpdSbKeyword.flags);

                            break;
                        }

                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_PERM  |
                           SITUATION_CUR_IS_CLEAN |
                           SITUATION_ALT_IS_DIRTY  ) :

                        // 0x20: cur=perm, cur=clean, alt=dirty
                        // Not sure why alt is dirty, but update alt and
                        // continue IPL

                        l_actions |= DO_UPDATE;
                        l_actions |= UPDATE_SBE;

                        // Set Update side to alt
                        io_sbeState.seeprom_side_to_update =
                                    ( io_sbeState.alt_seeprom_side ==
                                                  SBE_SEEPROM0 )
                                    ? EEPROM::SBE_PRIMARY : EEPROM::SBE_BACKUP ;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "cur=perm/clean(%d), alt=dirty. "
                                   "Update alt. Continue IPL. "
                                   "(sit=0x%.2X, act=0x%.8X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions);

                        break;


                ////////////////////////////////////////////////////////////////
                    case ( SITUATION_CUR_IS_PERM  |
                           SITUATION_CUR_IS_CLEAN |
                           SITUATION_ALT_IS_CLEAN  ) :

                        // 0x0: cur=perm, cur=clean, alt=clean
                        // Both sides are clean - no updates
                        // Continue IPL
                        l_actions = CLEAR_ACTIONS;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "Both sides clean-no updates. cur was "
                                   "perm(%d). Continue IPL. (sit=0x%.2X, "
                                   "act=0x%.8X)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   io_sbeState.cur_seeprom_side,
                                   i_system_situation, l_actions);

                        break;

                ////////////////////////////////////////////////////////////////
                    default:

                        l_actions = UNSUPPORTED_SITUATION;

                        TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                                   "Unsupported Scenario.  Just Continue IPL. "
                                   "(sit=0x%.2X, act=0x%.8X, cur=%d)",
                                   TARGETING::get_huid(io_sbeState.target),
                                   i_system_situation, l_actions,
                                   io_sbeState.cur_seeprom_side);

                        break;
                }
                ////////////////////////////////////////////////////////////////
                //  End of i_system_situation switch statement
                ////////////////////////////////////////////////////////////////

            }

#elif CONFIG_SBE_UPDATE_CONSECUTIVE
            // Updating the SEEPROMs 1-at-a-time (OP systems)

            // Check system situation ignoring perm/temp bit
            switch ( i_system_situation )
            {

            //// 0x0E: side0=dirty, side1=dirty, boot=1 ///////////////////////
            // Uncommon situation:
                case ( SITUATION_SIDE_0_DIRTY  |
                       SITUATION_SIDE_1_DIRTY |
                       SITUATION_BOOT_SIDE_1  ) :
                    // fall through

            //// 0x0C: side0=dirty, side1=dirty, boot=0 ///////////////////////
            // Common situation: likely first step of code update
                case ( SITUATION_SIDE_0_DIRTY  |
                       SITUATION_SIDE_1_DIRTY |
                       SITUATION_BOOT_SIDE_0  ) :
                    // fall through

            //// 0x0A: side0=dirty, side1=clean, boot=1 ///////////////////////
            // Uncommon situation:
                case ( SITUATION_SIDE_0_DIRTY  |
                       SITUATION_SIDE_1_CLEAN |
                       SITUATION_BOOT_SIDE_1  ) :
                    // fall through

            //// 0x08: side0=dirty, side1=clean, boot=0 ///////////////////////
            // Uncommon situation:
                case ( SITUATION_SIDE_0_DIRTY  |
                       SITUATION_SIDE_1_CLEAN |
                       SITUATION_BOOT_SIDE_0  ) :

                    // Update side 0 and re-ipl

                    l_actions |= IPL_RESTART;
                    l_actions |= DO_UPDATE;
                    l_actions |= UPDATE_MVPD;
                    l_actions |= UPDATE_SBE;

                    // Set Update side to primary
                    io_sbeState.seeprom_side_to_update =  EEPROM::SBE_PRIMARY;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "side 0=dirty, side 1=%s. Boot side %d. "
                               "Update side 0 (primary). re-IPL. "
                               "(sit=0x%.2X, act=0x%.8X)",
                               TARGETING::get_huid(io_sbeState.target),
                               ( i_system_situation & SITUATION_SIDE_1_DIRTY)
                                   ? "dirty" : "clean",
                               io_sbeState.cur_seeprom_side,
                               i_system_situation, l_actions);

                    break;


            //// 0x06: side0=clean, side1=dirty, boot=1 ///////////////////////
            // Uncommon situation: booting from dirty side after other side
            //                     was updated
                case ( SITUATION_SIDE_0_CLEAN  |
                       SITUATION_SIDE_1_DIRTY |
                       SITUATION_BOOT_SIDE_1  ) :

                    // No update, log error and continue IPL

                    l_actions = CLEAR_ACTIONS;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "side 0=clean, side 1=dirty. Boot side 1. "
                               "Call-out SBE code. Continue IPL. "
                               "(sit=0x%.2X, act=0x%.8X)",
                               TARGETING::get_huid(io_sbeState.target),
                               i_system_situation, l_actions);

                    /*
                     * errortype
                     * moduleid     SBE_DECISION_TREE
                     * reasoncode   SBE_BOOT_SIDE_DIRTY_BAD_PATH
                     * userdata1    System Situation
                     * userdata2    Update Actions
                     * devdesc      Bad Path in decisionUpdateTree:
                     *               cur=DIRTY, alt=CLEAN
                     * custdesc     A problem occurred while updating
                     *               processor boot code.
                     */
                    err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                        SBE_DECISION_TREE,
                                        SBE_BOOT_SIDE_DIRTY_BAD_PATH,
                                        TO_UINT64(i_system_situation),
                                        TO_UINT64(l_actions));
                    // Target isn't directly related to fail, but could be
                    // useful to see how far we got before failing.
                    ErrlUserDetailsTarget(io_sbeState.target
                                          ).addToLog(err);
                    err->collectTrace(SBE_COMP_NAME);
                    err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                              HWAS::SRCI_PRIORITY_HIGH );

                    break;


            //// 0x04: side0=clean, side1=dirty, boot=0 ///////////////////////
            // Common situation: likely second step of code update
                case ( SITUATION_SIDE_0_CLEAN  |
                       SITUATION_SIDE_1_DIRTY |
                       SITUATION_BOOT_SIDE_0  ) :

                    // Update side 1 and continue IPL

                    l_actions |= DO_UPDATE;
                    l_actions |= UPDATE_MVPD;
                    l_actions |= UPDATE_SBE;

                    // Set Update side to backup
                    io_sbeState.seeprom_side_to_update = EEPROM::SBE_BACKUP;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "side 0=clean, side 1=dirty. Boot side 0. "
                               "Update side 1 (backup). Continue IPL. "
                               "(sit=0x%.2X, act=0x%.8X)",
                               TARGETING::get_huid(io_sbeState.target),
                               i_system_situation, l_actions);

                    break;


            //// 0x02: side0=clean, side1=clean, boot=1 ///////////////////////
            // Uncommon situation: booting from side 1 when both sides clean
                case ( SITUATION_SIDE_0_CLEAN  |
                       SITUATION_SIDE_1_CLEAN |
                       SITUATION_BOOT_SIDE_1  ) :
                    // fall through

            //// 0x00: side0=clean, side1=clean, boot=0 ///////////////////////
            // Common situation: normal boot
                case ( SITUATION_SIDE_0_CLEAN  |
                       SITUATION_SIDE_1_CLEAN |
                       SITUATION_BOOT_SIDE_0  ) :

                    // No update (both sides are clean) and continue IPL

                    l_actions = CLEAR_ACTIONS;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "Both sides clean-no updates. Boot side %d. "
                               "Continue IPL. (sit=0x%.2X, act=0x%.8X)",
                               TARGETING::get_huid(io_sbeState.target),
                               io_sbeState.cur_seeprom_side,
                               i_system_situation, l_actions);

                    break;

            ///////////////////////////////////////////////////////////////////
                default:

                    l_actions = UNSUPPORTED_SITUATION;

                    TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                               "Unsupported Scenario.  Just Continue IPL. "
                               "(sit=0x%.2X, act=0x%.8X, Boot side %d)",
                               TARGETING::get_huid(io_sbeState.target),
                               i_system_situation, l_actions,
                               io_sbeState.cur_seeprom_side);

                    break;
            }
            ///////////////////////////////////////////////////////////////////
            //  End of i_system_situation switch statement
            ///////////////////////////////////////////////////////////////////

#endif

            // Set actions
            io_sbeState.update_actions = static_cast<sbeUpdateActions_t>
                                                    (l_actions);

            TRACUCOMP( g_trac_sbe, "decisionTreeForUpdates() Tgt=0x%X: "
                       "i_system_situation=0x%.2X, actions=0x%.8X, "
                       "Update EEPROM=0x%X, flags=0x%X, cur=%d",
                       TARGETING::get_huid(io_sbeState.target),
                       i_system_situation,
                       io_sbeState.update_actions,
                       io_sbeState.seeprom_side_to_update,
                       io_sbeState.mvpdSbKeyword.flags,
                       io_sbeState.cur_seeprom_side);

        }while(0);

        return err;

    }

/////////////////////////////////////////////////////////////////////
    void decisionTreeForUpdatesSimultaneous(uint32_t& io_actions,
                                            sbeTargetState_t& io_sbeState,
                                            uint8_t& i_system_situation )
    {
        // Updates both SEEPROMs if either side is dirty
        if ( ( i_system_situation & SITUATION_CUR_IS_DIRTY ) ||
             ( i_system_situation & SITUATION_ALT_IS_DIRTY )  )
        {
                // At least one of the sides is dirty
                // Update both sides and re-IPL
                // Update MVPD flag: make cur=perm (because we know it
                //  works a bit)

                io_actions |= IPL_RESTART;
                io_actions |= DO_UPDATE;
                io_actions |= UPDATE_MVPD;
                io_actions |= UPDATE_SBE;

                // Set update side to Primary here, but both sides
                // will be updated
                io_sbeState.seeprom_side_to_update = EEPROM::SBE_PRIMARY;
                // Update MVPD PERMANENT flag: make cur=perm
                ( io_sbeState.cur_seeprom_side == SBE_SEEPROM0 ) ?
                     // clear bit 0
                     io_sbeState.mvpdSbKeyword.flags &= ~PERMANENT_FLAG_MASK
                     : //set bit 0
                     io_sbeState.mvpdSbKeyword.flags |= PERMANENT_FLAG_MASK;

                // Update MVPD RE-IPL SEEPROM flag: re-IPL on ALT:
                ( io_sbeState.alt_seeprom_side == SBE_SEEPROM0 ) ?
                     // clear bit 1
                     io_sbeState.mvpdSbKeyword.flags &= ~REIPL_SEEPROM_MASK
                     : //set bit 1
                     io_sbeState.mvpdSbKeyword.flags |= REIPL_SEEPROM_MASK;


                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                           "At least one side dirty. cur side=%d. Update "
                           "alt. Re-IPL. Update MVPD flag "
                           "(sit=0x%.2X, act=0x%.8X flags=0x%.2X)",
                           TARGETING::get_huid(io_sbeState.target),
                           io_sbeState.cur_seeprom_side,
                           i_system_situation, io_actions,
                           io_sbeState.mvpdSbKeyword.flags);
        }
        else
        {
                // Both sides are clean - no updates
                // Continue IPL
                io_actions = CLEAR_ACTIONS;

                TRACFCOMP( g_trac_sbe, INFO_MRK"SBE Update tgt=0x%X: "
                           "Both sides clean-no updates. cur side=%d. "
                           "Continue IPL. (sit=0x%.2X, act=0x%.8X)",
                           TARGETING::get_huid(io_sbeState.target),
                           io_sbeState.cur_seeprom_side,
                           i_system_situation, io_actions);
        }
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t performUpdateActions(sbeTargetState_t& io_sbeState)
    {
        TRACUCOMP( g_trac_sbe,
                   ENTER_MRK"performUpdateActions(): HUID=0x%.8X, "
                   "updateActions=0x%.8X",
                   TARGETING::get_huid(io_sbeState.target),
                   io_sbeState.update_actions);

        errlHndl_t err      = NULL;
        errlHndl_t err_info = NULL;
        uint32_t   l_actions = io_sbeState.update_actions;

        do{
            /**************************************************************/
            /*  Update SEEPROM, if necessary                              */
            /**************************************************************/
            if (l_actions & UPDATE_SBE)
            {
#ifdef CONFIG_SBE_UPDATE_SIMULTANEOUS
                io_sbeState.seeprom_side_to_update = EEPROM::SBE_PRIMARY;
#endif

#ifdef CONFIG_SBE_UPDATE_INDEPENDENT
                if (g_update_both_sides)
                {
                    TRACFCOMP( g_trac_sbe, "UPDATE_BOTH_SIDES_OF_SBE MNFG Flag indicated, will update both sides" );
                    io_sbeState.seeprom_side_to_update = EEPROM::SBE_PRIMARY;
                }
#endif

#ifdef CONFIG_SBE_UPDATE_SEQUENTIAL
                if (g_do_hw_keys_hash_transition)
                {
                    TRACFCOMP( g_trac_sbe, "UPDATE_BOTH_SIDES_OF_SBE Key transition, will update both sides" );
                    io_sbeState.seeprom_side_to_update = EEPROM::SBE_PRIMARY;
                }
#endif

                err = updateSeepromSide(io_sbeState);
                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"performUpdateActions() - "
                               "updateProcessorSbeSeeproms() failed. "
                               "HUID=0x%.8X.",
                               TARGETING::get_huid(io_sbeState.target));
                    break;
                }
                l_actions |= SBE_UPDATE_COMPLETE;
            }

            /**************************************************************/
            /*  Update MVPD, if necessary                                 */
            /**************************************************************/
            if (l_actions & UPDATE_MVPD)
            {
                err =  getSetMVPDVersion(io_sbeState.target,
                                         MVPDOP_WRITE,
                                         io_sbeState.mvpdSbKeyword);
                if(err)
                {
                    TRACFCOMP( g_trac_sbe, ERR_MRK"performUpdateActions() - "
                               "Error Updating MVPD with new SBE Image Info "
                               "HUID=0x%.8X, rc=0x%.4x. Skipping SBE Update. "
                               "(actions=0x%.8X)",
                               TARGETING::get_huid(io_sbeState.target),
                               err->reasonCode(), l_actions );
                    break;
                }
                l_actions |= MVPD_UPDATE_COMPLETE;
            }

            /**************************************************************/
            /*  Create Info Error Log of successful operation             */
            /**************************************************************/
#ifndef CONFIG_SBE_UPDATE_SIMULTANEOUS
            TRACFCOMP( g_trac_sbe,INFO_MRK"performUpdateActions(): Successful "
                       "SBE Update of HUID=0x%.8X SEEPROM %d",
                       TARGETING::get_huid(io_sbeState.target),
                       io_sbeState.seeprom_side_to_update);
#else
            TRACFCOMP( g_trac_sbe,INFO_MRK"performUpdateActions(): Successful "
                       "SBE Update of HUID=0x%.8X - Both SEEPROMs",
                       TARGETING::get_huid(io_sbeState.target));
#endif

            /*@
             * @errortype
             * @moduleid          SBE_PERFORM_UPDATE_ACTIONS
             * @reasoncode        SBE_INFO_LOG
             * @userdata1[0:31]   Update Actions Enum
             * @userdata1[32:63]  Customized Data CRC
             * @userdata2[0:31]   Original SEEPROM 0 CRC
             * @userdata2[32:63]  Original SEEPROM 1 CRC
             * @devdesc      Successful Update of SBE SEEPROM
             *               SBE Version Information
             * @custdesc     Successful Update of Self Boot Engine
             *               (SBE) SEEPROM SBE Version Information
             */
            err_info = new ErrlEntry(ERRL_SEV_INFORMATIONAL,
                                     SBE_PERFORM_UPDATE_ACTIONS,
                                     SBE_INFO_LOG,
                                     TWO_UINT32_TO_UINT64(
                                         l_actions,
                                         io_sbeState.customizedImage_crc),
                                     TWO_UINT32_TO_UINT64(
                                         io_sbeState.seeprom_0_ver.data_crc,
                                         io_sbeState.seeprom_1_ver.data_crc));


            // Add general data sections to capture MVPD SB Keyword and
            // the new SBE SEEPROM Version structure
            err_info->addFFDC( SBE_COMP_ID,
                               &(io_sbeState.mvpdSbKeyword),
                               sizeof(io_sbeState.mvpdSbKeyword),
                               0,                   // Version
                               ERRL_UDT_NOFORMAT,   // parser ignores data
                               false );             // merge

            err_info->addFFDC( SBE_COMP_ID,
                               &(io_sbeState.new_seeprom_ver),
                               sizeof(io_sbeState.new_seeprom_ver),
                               0,                   // Version
                               ERRL_UDT_NOFORMAT,   // parser ignores data
                               false );             // merge


            err_info->collectTrace(SBE_COMP_NAME, KILOBYTE);

            ErrlUserDetailsTarget(io_sbeState.target, "SBE Target Updated")
                                 .addToLog(err_info);

            errlCommit( err_info, SBE_COMP_ID );

            /**************************************************************/


        }while(0);

        io_sbeState.update_actions = static_cast<sbeUpdateActions_t>
                                                    (l_actions);
        TRACUCOMP( g_trac_sbe,
                   EXIT_MRK"performUpdateActions(): HUID=0x%.8X, "
                   "updateActions=0x%.8X",
                   TARGETING::get_huid(io_sbeState.target),
                   io_sbeState.update_actions);

        return err;

    }


/////////////////////////////////////////////////////////////////////
    uint32_t trimBitMask(uint32_t i_mask,
                         size_t i_maxBits)
    {
        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"trimBitMask(i_mask=0x%.8X, i_maxBits=0x%.8X)",
                   i_mask, i_maxBits);
        uint32_t retMask = i_mask;

        while(__builtin_popcount(retMask) >  static_cast<int32_t>(i_maxBits))
        {
            retMask ^= (0x80000000 >>
                        static_cast<uint32_t>(__builtin_clz(retMask)));
        }

        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"trimBitMask(): retMask=0x%.8X",
                   retMask);

        return retMask;
    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t createSbeImageVmmSpace(void)
    {

        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"createSbeImageVmmSpace");

        int64_t rc = 0;
        errlHndl_t err = NULL;

        do{

            //Make sure procedure constants keep within expected range.
            assert((FIXED_SEEPROM_WORK_SPACE <= VMM_SBE_UPDATE_SIZE/2),
                "createSbeImageVmmSpace() FIXED_SEEPROM_WORK_SPACE too large");
            assert((MAX_RING_BUF_SIZE <= VMM_SBE_UPDATE_SIZE/4),
                "createSbeImageVmmSpace() MAX_RING_BUF_SIZE too large");


            // Create a memory block to serve as XIP Customize scratch space
            // NOTE: using mm_alloc_block since this code is running before we
            // have mainstore and we must have contiguous blocks of memory for
            // the customize procedure to use.
            rc = mm_alloc_block( NULL,
                                 reinterpret_cast<void*>
                                 (VMM_VADDR_SBE_UPDATE),
                                 VMM_SBE_UPDATE_SIZE);

            if(rc == -EALREADY)
            {
                //-EALREADY inidciates the block is already mapped
                // so just ignore
                rc = 0;
            }

            if( rc )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"createSbeImageVmmSpace() - "
                           "Error from mm_alloc_block : rc=%d", rc );
                /*@
                 * @errortype
                 * @moduleid     SBE_CREATE_TEST_SPACE
                 * @reasoncode   SBE_ALLOC_BLOCK_FAIL
                 * @userdata1    Requested Address
                 * @userdata2    rc from mm_alloc_block
                 * @devdesc      updateProcessorSbeSeeproms> Error
                 *               from mm_alloc_block
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_CREATE_TEST_SPACE,
                                    SBE_ALLOC_BLOCK_FAIL,
                                    TO_UINT64(VMM_VADDR_SBE_UPDATE),
                                    TO_UINT64(rc));

                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );

                break;
            }

            rc = mm_set_permission(reinterpret_cast<void*>
                                   (VMM_VADDR_SBE_UPDATE),
                                   VMM_SBE_UPDATE_SIZE,
                                   WRITABLE | ALLOCATE_FROM_ZERO );
            if( rc )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"createSbeImageVmmSpace() - Error from mm_set_permission : rc=%d", rc );
                /*@
                 * @errortype
                 * @moduleid     SBE_CREATE_TEST_SPACE
                 * @reasoncode   SBE_SET_PERMISSION_FAIL
                 * @userdata1    Requested Address
                 * @userdata2    rc from mm_set_permission
                 * @devdesc      updateProcessorSbeSeeproms> Error from
                 *               mm_set_permission on creation
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_CREATE_TEST_SPACE,
                                    SBE_SET_PERMISSION_FAIL,
                                    TO_UINT64(VMM_VADDR_SBE_UPDATE),
                                    TO_UINT64(rc));
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }

        }while(0);

        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"createSbeImageVmmSpace() - rc =0x%X", rc);

        return err;

    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t cleanupSbeImageVmmSpace(void)
    {
        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"cleanupSbeImageVmmSpace");

        errlHndl_t err = NULL;
        int64_t rc = 0;

        do{

            //release all pages in page block
            rc = mm_remove_pages(RELEASE,
                                 reinterpret_cast<void*>
                                 (VMM_VADDR_SBE_UPDATE),
                                 VMM_SBE_UPDATE_SIZE);
            if( rc )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"cleanupSbeImageVmmSpace() - "
                           "Error from mm_remove_pages : rc=%d", rc );
                /*@
                 * @errortype
                 * @moduleid     SBE_CLEANUP_TEST_SPACE
                 * @reasoncode   SBE_REMOVE_PAGES_FAIL
                 * @userdata1    Requested Address
                 * @userdata2    rc from mm_remove_pages
                 * @devdesc      updateProcessorSbeSeeproms> mm_remove_pages
                 *               RELEASE failed
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_CLEANUP_TEST_SPACE,
                                    SBE_REMOVE_PAGES_FAIL,
                                    TO_UINT64(VMM_VADDR_SBE_UPDATE),
                                    TO_UINT64(rc));
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );

                break;
            }

            // Set permissions back to "no_access"
            rc = mm_set_permission(reinterpret_cast<void*>
                                   (VMM_VADDR_SBE_UPDATE),
                                   VMM_SBE_UPDATE_SIZE,
                                   NO_ACCESS | ALLOCATE_FROM_ZERO );
            if( rc )
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"cleanupSbeImageVmmSpace() - "
                           "Error from mm_set_permission : rc=%d", rc );
                /*@
                 * @errortype
                 * @moduleid     SBE_CLEANUP_TEST_SPACE
                 * @reasoncode   SBE_SET_PERMISSION_FAIL
                 * @userdata1    Requested Address
                 * @userdata2    rc from mm_set_permission
                 * @devdesc      updateProcessorSbeSeeproms> Error from
                 *               mm_set_permission on cleanup
                 * @custdesc     A problem occurred while updating processor
                 *               boot code.
                 */
                err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                    SBE_CLEANUP_TEST_SPACE,
                                    SBE_SET_PERMISSION_FAIL,
                                    TO_UINT64(VMM_VADDR_SBE_UPDATE),
                                    TO_UINT64(rc));
                err->collectTrace(SBE_COMP_NAME);
                err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                          HWAS::SRCI_PRIORITY_HIGH );
                break;
            }

            // Unload any PNOR sections that might've gotten left loaded
            //  (probably due to some error path)
            std::list<PNOR::SectionId> tmplist = g_loadedSections;
            for( const auto & section : tmplist )
            {
                TRACFCOMP(g_trac_sbe,"Leftover section %d",section);
                err = unloadPnorSection(section);
                if( err )
                {
                    break;
                }
            }
            if( err ) { break; }
            g_loadedSections.clear();

        }while(0);


        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"cleanupSbeImageVmmSpace() - rc =0x%X", rc);

        return err;

    }


/////////////////////////////////////////////////////////////////////
    bool isIplFromReIplRequest(void)
    {
        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"isIplFromReIplRequest");

        bool o_reIplRequest = false;
        errlHndl_t err = NULL;
        msg_t * msg = msg_allocate();

        do{

            /***********************************************/
            /*  Check if MBOX Query has already been made  */
            /***********************************************/
            if ( g_mbox_query_done == true )
            {
                o_reIplRequest = g_mbox_query_result;

                TRACUCOMP( g_trac_sbe, "isIplFromReIplRequest: query "
                           "previously done (%d). o_reIplRequest = %d",
                           g_mbox_query_done, o_reIplRequest);
                break;
            }

            /*********************************************/
            /*  Check if MBOX is enabled                 */
            /*********************************************/
            bool mbox_enabled = false;

            TARGETING::Target * sys = NULL;
            TARGETING::targetService().getTopLevelTarget( sys );
            TARGETING::SpFunctions spfuncs;
            if( sys &&
                sys->tryGetAttr<TARGETING::ATTR_SP_FUNCTIONS>(spfuncs) &&
                spfuncs.mailboxEnabled)
            {
                mbox_enabled = true;
            }

            /****************************************************/
            /*  MBOX IS NOT enabled: assume IPL not our request */
            /****************************************************/
            if ( mbox_enabled == false )
            {
                o_reIplRequest = false;
                TRACFCOMP(g_trac_sbe, INFO_MRK"isIplFromReIplRequest(): "
                          "MBOX not enabled, so assume not our IPL request. "
                          "o_reIplRequest=%d", o_reIplRequest);
                break;
            }


            /*********************************************/
            /*  MBOX enabled, send message               */
            /*********************************************/
            msg->type = MSG_IPL_DUE_TO_SBE_UPDATE;
            msg->data[0] = 0x0;
            msg->data[1] = 0x0;
            msg->extra_data = NULL;

            err = MBOX::sendrecv(MBOX::IPL_SERVICE_QUEUE, msg);

            if(err)
            {
                o_reIplRequest = false;
                TRACFCOMP(g_trac_sbe, ERR_MRK"isIplFromReIplRequest(): "
                          "Error sending MBOX msg. Commit error, and assume "
                          "IPL wasn't requested from us: o_reIplRequest=%d, "
                          "RC=0x%X, PLID=0x%lX",
                          o_reIplRequest,
                          ERRL_GETRC_SAFE(err),
                          ERRL_GETPLID_SAFE(err));

                errlCommit(err, SBE_COMP_ID);
                break;
            }

            // data word 0: if non-zero:  IPL is due to SBE Update Request
            // data word 1: if non-zero:  IPL is due to an error found by the
            //                            FSP
            if ( msg->data[1] == 0 ) // No error from FSP side
            {
                if( msg->data[0] != 0 )
                {
                    // IPL is due to SBE Update Request
                    o_reIplRequest = true;
                    TRACFCOMP(g_trac_sbe, INFO_MRK"isIplFromReIplRequest(): "
                              "MBOX returned that it was our IPL request: "
                              "o_reIplRequest=%d (d0=0x%X, d1=0x%X)",
                              o_reIplRequest, msg->data[0], msg->data[1]);
                }
                else
                {
                    // normal IPL
                    o_reIplRequest = false;
                    TRACFCOMP(g_trac_sbe, INFO_MRK"isIplFromReIplRequest(): "
                             "MBOX returned that it was a normal IPL: "
                             "o_reIplRequest=%d (d0=0x%X, d1=0x%X)",
                              o_reIplRequest, msg->data[0], msg->data[1]);

                }
            }
            else  /*  Non-Zero: error from FSP side. */
            {
                // handle error reported by FSP
                o_reIplRequest = false;
                TRACFCOMP(g_trac_sbe, INFO_MRK"isIplFromReIplRequest(): "
                          "MBOX returned error from FSP-side, so assume not our"
                          "IPL request: o_reIplRequest=%d (d0=0x%X, d1=0x%X)",
                          o_reIplRequest, msg->data[0], msg->data[1]);
            }


        }while(0);


        /********************************************************************/
        /*  If check hadn't been done before, set globals for next request  */
        /********************************************************************/
        if ( g_mbox_query_done == false )
        {
            g_mbox_query_done = true;
            g_mbox_query_result = o_reIplRequest;

            TRACUCOMP( g_trac_sbe, "isIplFromReIplRequest: save results: "
                       "q_done = %d, q_result = %d",
                       g_mbox_query_done, g_mbox_query_result);
        }


        // msg cleanup
        msg_free(msg);
        msg = NULL;

        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"isIplFromReIplRequest(): o_reIplRequest=%d",
                   o_reIplRequest);

        return o_reIplRequest;

    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t preReIplCheck(std::vector<sbeTargetState_t>& io_sbeStates_v)
    {

        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"preReIplCheck");

        errlHndl_t err = NULL;

        // MVPD PERMANENT and Re-IPL Seeprom flags
        uint8_t perm_and_reipl = 0x0;
        uint8_t flags_mask = (PERMANENT_FLAG_MASK | REIPL_SEEPROM_MASK);
        uint8_t flags_match_0 =    SEEPROM_0_PERMANENT_VALUE |
                                   REIPL_SEEPROM_0_VALUE;
        uint8_t flags_match_1 =    SEEPROM_1_PERMANENT_VALUE |
                                   REIPL_SEEPROM_1_VALUE;
        uint8_t flags_misMatch_A = SEEPROM_1_PERMANENT_VALUE |
                                   REIPL_SEEPROM_0_VALUE;
        uint8_t flags_misMatch_B = SEEPROM_0_PERMANENT_VALUE |
                                   REIPL_SEEPROM_1_VALUE;

        do{


            /*****************************************************************/
            /*  Iterate over all the processors and check/update each for:   */
            /*  1) MVPD SB Keyword has correct flag set for the              */
            /*     re-IPL SEEPROM                                            */
            /*****************************************************************/
            for ( uint8_t i=0; i < io_sbeStates_v.size(); i++ )
            {
                /*************************************************************/
                /* If not already updated, make sure MVPD SB Keyword has     */
                /*     correct flag set for re-IPL SEEPROM                   */
                /*************************************************************/
                if (!(io_sbeStates_v[i].update_actions & MVPD_UPDATE_COMPLETE))
                {
                    // This target has not already had its MVPD updated
                    // Check that perm and re-IPL boot flag match

                    perm_and_reipl = io_sbeStates_v[i].mvpdSbKeyword.flags &
                                     flags_mask;


                    if ( ( perm_and_reipl == flags_match_0 ) ||
                         ( perm_and_reipl == flags_match_1 )   )
                    {
                        TRACUCOMP(g_trac_sbe,"preReIplCheck(): no MVPD update "
                                  "required for tgt=0x%X (u_a=0x%X, flag=0x%X)",
                                  TARGETING::get_huid(io_sbeStates_v[i].target),
                                  io_sbeStates_v[i].update_actions,
                                  io_sbeStates_v[i].mvpdSbKeyword.flags);
                        continue;

                    }
                    else if ( ( perm_and_reipl == flags_misMatch_A ) ||
                              ( perm_and_reipl == flags_misMatch_B )   )

                    {
                        if ( perm_and_reipl == flags_misMatch_A )
                        {
                            // Perm is SEEPROM 1, so set both to 1
                            io_sbeStates_v[i].mvpdSbKeyword.flags |=
                                                            flags_match_1;
                        }
                        else
                        {
                            // Perm is SEEPROM 0, so set both to 0
                            io_sbeStates_v[i].mvpdSbKeyword.flags &=
                                                           ~flags_mask;
                        }


                        TRACFCOMP(g_trac_sbe,"preReIplCheck(): MVPD update "
                                  "Required for tgt=0x%X (u_a=0x%X, flag=0x%X)",
                                  TARGETING::get_huid(io_sbeStates_v[i].target),
                                  io_sbeStates_v[i].update_actions,
                                  io_sbeStates_v[i].mvpdSbKeyword.flags);

                        err = getSetMVPDVersion(
                                    io_sbeStates_v[i].target,
                                    MVPDOP_WRITE,
                                    io_sbeStates_v[i].mvpdSbKeyword);
                        if(err)
                        {
                            TRACFCOMP(g_trac_sbe,ERR_MRK"preReIplCheck() "
                                "Error Updating MVPD with new flag Info: "
                                "HUID=0x%.8X, rc=0x%.4X. Committing log "
                                "here and continuing.",
                                TARGETING::get_huid(io_sbeStates_v[i].target),
                                err->reasonCode());
                             errlCommit( err, SBE_COMP_ID );
                        }

                        // update actions field
                        uint32_t tmp_actions = io_sbeStates_v[i].update_actions
                                                | MVPD_UPDATE_COMPLETE;

                        io_sbeStates_v[i].update_actions =
                                          static_cast<sbeUpdateActions_t>
                                                          (tmp_actions);

                        continue;

                    }
                }
            } // end of for loop

        }while(0);


        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"preReIplCheck()");

        return err;

    }


/////////////////////////////////////////////////////////////////////
    errlHndl_t masterVersionCompare(
                     std::vector<sbeTargetState_t>& io_sbeStates_v)
    {
        TRACDCOMP( g_trac_sbe,
                   ENTER_MRK"masterVersionCompare");

        errlHndl_t err = NULL;

        uint8_t mP = UINT8_MAX;
        sbe_image_version_t mP_version;
        sbe_image_version_t * ver_ptr;
        TARGETING::ATTR_MODEL_type l_model;

        do{

            // If running in simics, don't do these checks
            if ( Util::isSimicsRunning() )
            {
                break;
            }

            /*****************************************************************/
            /*  Iterate over all the processors to find Master Processor     */
            /*****************************************************************/
            for ( uint8_t i=0; i < io_sbeStates_v.size(); i++ )
            {
                if ( io_sbeStates_v[i].target_is_master == true )
                {
                    mP = i;
                    l_model = io_sbeStates_v[i].target
                                           ->getAttr<TARGETING::ATTR_MODEL>();

                    // Compare against 'current' Master side in case there is
                    // an issue with the other side
                    if (io_sbeStates_v[i].cur_seeprom_side ==
                                          SBE_SEEPROM0)
                    {
                        ver_ptr =
                            &(io_sbeStates_v[i].seeprom_0_ver.image_version);
                    }
                    else // SBE_SEEPROM1
                    {
                        ver_ptr =
                            &(io_sbeStates_v[i].seeprom_1_ver.image_version);
                    }

                    memcpy(&(mP_version),
                           ver_ptr,
                           SBE_IMAGE_VERSION_SIZE);
                    break;
                }
            }

            // Handle very unlikely case of not finding Master Processor
            assert( (mP != UINT8_MAX),
                    "masterVersionCompare(): master processor not found");

            /*****************************************************************/
            /*  Make sure that there aren't any errors associated with       */
            /*  updating the non-master targets; otherwise you can't trust   */
            /*  their  version                                               */
            /*  -- AND --                                                    */
            /*  Compare 'current' Version on all processors to see if they   */
            /*  match the 'current' version on the Master Processor          */
            /*                                                               */
            /*  NOTE: Comparison based on PNOR SBE Image and --NOT--         */
            /*        based on CRC (which is partly target specific)         */
            /*                                                               */
            /*  Also, there are special checks for the Master Processor      */
            /*****************************************************************/

            // @todo RTC 107721 - Need to handle Habanero 'Golden' SEEPROM side

            for ( uint8_t i=0; i < io_sbeStates_v.size(); i++ )
            {

                // Special Master Processor checks
                if ( i == mP )
                {
// Skip Master Processor check of Both SEEPROMs being identical
#ifndef CONFIG_SBE_UPDATE_INDEPENDENT

                    // Compare Versions of Both SEEPROMs to PNOR Version
                    // Create a Predictive Error if there's an issue
                    if ((0 != memcmp(
                              &(io_sbeStates_v[i].pnorVersion),
                              &(io_sbeStates_v[i].seeprom_0_ver.image_version),
                              SBE_IMAGE_VERSION_SIZE) )
                        ||
                        (0 != memcmp(
                              &(io_sbeStates_v[i].pnorVersion),
                              &(io_sbeStates_v[i].seeprom_1_ver.image_version),
                              SBE_IMAGE_VERSION_SIZE) )
                            )
                    {
                        TRACFCOMP( g_trac_sbe,ERR_MRK"masterVersionCompare() - "
                                   "SBE Version Miscompare Between Master "
                                   "Target SEEPROMs (HUID=0x%.8X, current "
                                   "side=%d)",
                                   TARGETING::get_huid(
                                                  io_sbeStates_v[mP].target),
                                   io_sbeStates_v[mP].cur_seeprom_side);

                        // Trace first 8 bytes of each section
                        // Full Version added to error log below
                        TRACFBIN( g_trac_sbe,
                                  "PNOR Version",
                                  &(io_sbeStates_v[i].pnorVersion),
                                  8 ) ;

                        TRACFBIN(
                             g_trac_sbe,
                             "Seeprom0: Master Image Version",
                             &(io_sbeStates_v[mP].seeprom_0_ver.image_version),
                             8 ) ;

                        TRACFBIN(
                             g_trac_sbe,
                             "Seeprom1: Master Image Version",
                             &(io_sbeStates_v[mP].seeprom_1_ver.image_version),
                             8 ) ;

                        /*@
                         * @errortype
                         * @moduleid     SBE_MASTER_VERSION_COMPARE
                         * @reasoncode   SBE_MASTER_VERSION_DOWNLEVEL
                         * @userdata1    Master Target HUID
                         * @userdata2    Master Target Loop Index
                         * @devdesc      SBE Image Version Miscompare with
                         *               Master Target
                         * @custdesc     Self Boot Engine (SBE) Image Version
                         *               Miscompare with Master Target
                         */
                        err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                            SBE_MASTER_VERSION_COMPARE,
                                            SBE_MASTER_VERSION_DOWNLEVEL,
                                            TARGETING::get_huid(
                                                  io_sbeStates_v[mP].target),
                                            mP);

                        err->collectTrace(SBE_COMP_NAME);

                        err->addProcedureCallout(HWAS::EPUB_PRC_LVL_SUPP,
                                                 HWAS::SRCI_PRIORITY_HIGH);

                        err->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                                HWAS::SRCI_PRIORITY_MED);

                        err->addProcedureCallout(HWAS::EPUB_PRC_SP_CODE,
                                                 HWAS::SRCI_PRIORITY_LOW);

                        ErrlUserDetailsTarget(io_sbeStates_v[mP].target,
                                              "Master Target").addToLog(err);

                        // Add general data sections to capture the
                        // different versions
                        err->addFFDC( SBE_COMP_ID,
                                      &(io_sbeStates_v[i].pnorVersion),
                                      SBE_IMAGE_VERSION_SIZE,
                                      0,                 // Version
                                      ERRL_UDT_NOFORMAT, // parser ignores data
                                      false );           // merge

                        err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[mP].seeprom_0_ver.image_version),
                                      SBE_IMAGE_VERSION_SIZE,
                                      0,                 // Version
                                      ERRL_UDT_NOFORMAT, // parser ignores data
                                      false );           // merge

                        err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[mP].seeprom_1_ver.image_version),
                                      SBE_IMAGE_VERSION_SIZE,
                                      0,                 // Version
                                      ERRL_UDT_NOFORMAT, // parser ignores data
                                      false );           // merge

                        errlCommit( err, SBE_COMP_ID );

                    } // end of check
#endif
                    // Continue to avoid remaining non-Master Processor checks
                    continue;
                }
                else
                {
                    // Not Master, so get 'current' version
                    if (io_sbeStates_v[i].cur_seeprom_side ==
                                          SBE_SEEPROM0)
                    {
                        ver_ptr =
                            &(io_sbeStates_v[i].seeprom_0_ver.image_version);
                    }
                    else // SBE_SEEPROM1
                    {
                        ver_ptr =
                            &(io_sbeStates_v[i].seeprom_1_ver.image_version);
                    }

                }


                // See if there was an issue updating this target
                if ( io_sbeStates_v[i].err_plid != 0 )
                {
                    TRACFCOMP( g_trac_sbe,ERR_MRK"masterVersionCompare() - "
                               "Error Associated with Updating Target "
                               "HUID=0x%.8X: plid=0x%.8X, eid=0x%.8X, "
                               "rc=0x%.4X, sev=0x%.2X. "
                               "Can't trust its SBE Version",
                               TARGETING::get_huid(io_sbeStates_v[i].target),
                               io_sbeStates_v[i].err_plid,
                               io_sbeStates_v[i].err_eid,
                               io_sbeStates_v[i].err_rc,
                               io_sbeStates_v[i].err_sev);

                    /*@
                     * @errortype
                     * @moduleid     SBE_MASTER_VERSION_COMPARE
                     * @reasoncode   SBE_ERROR_ON_UPDATE
                     * @userdata1[0:31]     Target HUID
                     * @userdata1[32:63]    Original Error PLID
                     * @userdata2[0:31]     Original Error EID
                     * @userdata2[32:63]    Original Error Reason Code
                     * @devdesc      Error Associated with Updating this Target
                     */
                    err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                        SBE_MASTER_VERSION_COMPARE,
                                        SBE_ERROR_ON_UPDATE,
                                        TWO_UINT32_TO_UINT64(
                                          TARGETING::get_huid(
                                                     io_sbeStates_v[i].target),
                                          io_sbeStates_v[i].err_plid),
                                        TWO_UINT32_TO_UINT64(
                                          io_sbeStates_v[i].err_eid,
                                          io_sbeStates_v[i].err_rc));

                    // Link the 2 logs
                    err->plid(io_sbeStates_v[i].err_plid);

                }

                // Compare 'current' version of target to 'current' version
                // of Master target in case Master version is down-level
                // This check will fail compat mode mixing of parts.
                // Allow it to pass if that is the case
                // TODO RTC:197737 improve mixed mode, instead of skipping
                else if ( (0 != memcmp( &(mP_version),
                                       ver_ptr,
                                       SBE_IMAGE_VERSION_SIZE)) &&
                         ! HWAS::mixedECsAllowed(l_model, io_sbeStates_v[mP].ec,
                                               io_sbeStates_v[i].ec)
                           )
                {
                    TRACFCOMP( g_trac_sbe,ERR_MRK"masterVersionCompare() - "
                               "SBE Version Miscompare Between Master Target "
                               "HUID=0x%.8X (side=%d) and Target HUID=0x%.8X "
                               "(side=%d)",
                               TARGETING::get_huid(
                                          io_sbeStates_v[mP].target),
                               io_sbeStates_v[mP].cur_seeprom_side,
                               TARGETING::get_huid(io_sbeStates_v[i].target),
                               io_sbeStates_v[i].cur_seeprom_side);

                    // Trace first 8 bytes of each section
                    // Full Version added to error log below
                    TRACFBIN( g_trac_sbe,
                              "PNOR Version",
                              &(io_sbeStates_v[i].pnorVersion),
                              8 ) ;

                    TRACFBIN( g_trac_sbe,
                              "Seeprom0: Master Image Version",
                              &(io_sbeStates_v[mP].seeprom_0_ver.image_version),
                              8 ) ;

                    TRACFBIN( g_trac_sbe,
                              "Seeprom1: Master Image Version",
                              &(io_sbeStates_v[mP].seeprom_1_ver.image_version),
                              8 ) ;

                    TRACFBIN( g_trac_sbe,
                              "Seeprom0: Failing Image Version",
                              &(io_sbeStates_v[i].seeprom_0_ver.image_version),
                              8  ) ;

                    TRACFBIN( g_trac_sbe,
                              "Seeprom1: Failing Image Version",
                              &(io_sbeStates_v[i].seeprom_1_ver.image_version),
                              8 ) ;


                    /*@
                     * @errortype
                     * @moduleid     SBE_MASTER_VERSION_COMPARE
                     * @reasoncode   SBE_MISCOMPARE_WITH_MASTER_VERSION
                     * @userdata1    Master Target HUID
                     * @userdata2    Comparison Target HUID
                     * @devdesc      SBE Version Miscompare with Master Target
                     * @custdesc     Self Boot Engine (SBE) Version Miscompare
                     *               with Master Target
                     */
                    err = new ErrlEntry(ERRL_SEV_PREDICTIVE,
                                        SBE_MASTER_VERSION_COMPARE,
                                        SBE_MISCOMPARE_WITH_MASTER_VERSION,
                                        TARGETING::get_huid(
                                                   io_sbeStates_v[mP].target),
                                        TARGETING::get_huid(
                                                   io_sbeStates_v[i].target));

                    // Add general data sections to capture the
                    // different versions
                    err->addFFDC( SBE_COMP_ID,
                                  &(io_sbeStates_v[i].pnorVersion),
                                  SBE_IMAGE_VERSION_SIZE,
                                  0,                 // Version
                                  ERRL_UDT_NOFORMAT, // parser ignores data
                                  false );           // merge

                    err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[mP].seeprom_0_ver.image_version),
                                  SBE_IMAGE_VERSION_SIZE,
                                  0,                 // Version
                                  ERRL_UDT_NOFORMAT, // parser ignores data
                                  false );           // merge

                    err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[mP].seeprom_1_ver.image_version),
                              SBE_IMAGE_VERSION_SIZE,
                                  0,                 // Version
                                  ERRL_UDT_NOFORMAT, // parser ignores data
                                  false );           // merge

                   err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[i].seeprom_0_ver.image_version),
                                  SBE_IMAGE_VERSION_SIZE,
                                  0,                 // Version
                                  ERRL_UDT_NOFORMAT, // parser ignores data
                                  false );           // merge

                    err->addFFDC( SBE_COMP_ID,
                             &(io_sbeStates_v[i].seeprom_1_ver.image_version),
                              SBE_IMAGE_VERSION_SIZE,
                                  0,                 // Version
                                  ERRL_UDT_NOFORMAT, // parser ignores data
                                  false );           // merge

                }

                // No issues
                else
                {
                    TRACUCOMP( g_trac_sbe, "masterVersionCompare: Successful "
                               "Version check", i, mP);
                }


                if ( err )
                {
                    // Add FFDC and Commit the error log created here
                    err->collectTrace(SBE_COMP_NAME);

                    err->addProcedureCallout(HWAS::EPUB_PRC_LVL_SUPP,
                                             HWAS::SRCI_PRIORITY_HIGH);

                    err->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
                                             HWAS::SRCI_PRIORITY_MED);

                    err->addProcedureCallout(HWAS::EPUB_PRC_SP_CODE,
                                             HWAS::SRCI_PRIORITY_LOW);

                    ErrlUserDetailsTarget(io_sbeStates_v[mP].target,
                                          "Master Target").addToLog(err);

                    ErrlUserDetailsTarget(io_sbeStates_v[i].target,
                                          "Failing Target").addToLog(err);

                    errlCommit( err, SBE_COMP_ID );

                }
            }

        }while(0);


        TRACDCOMP( g_trac_sbe,
                   EXIT_MRK"masterVersionCompare");

        return err;

    }


/////////////////////////////////////////////////////////////////////
    size_t setECCSize(size_t i_srcSz,
                      const uint64_t i_offset,
                      const uint64_t i_boundary)
    {
        // Assert that source size is a multiple of 8
        assert((i_srcSz % 8) == 0);

        // Calculate size with ECC. but without padding
        size_t l_eccSz = (i_srcSz * 9) / 8;

        // Determine padding at each boundary
        size_t l_padSz = i_boundary % 9;

        // Calculate number of boundary crossings
        // Only use portion of offset beyond last boundary it crosses
        // Exactly reaching a boundary is not counted as a crossing
        uint64_t l_boundaryCrossings =
            (l_eccSz + (i_offset % i_boundary) - 1) / (i_boundary - l_padSz);

        // Calculate total padding
        size_t l_totalPadding = l_boundaryCrossings * l_padSz;

        return (l_eccSz + l_totalPadding);
    }


/////////////////////////////////////////////////////////////////////
    void injectECC(const uint8_t* i_src,
                   size_t i_srcSz,
                   const uint64_t i_offset,
                   const uint64_t i_boundary,
                   uint8_t* o_dst)
    {
        // Initialize local size variables for inject loop
        size_t l_completeSz = 0;
        size_t l_completeEccSz = 0;
        size_t l_padSz = i_boundary % 9;
        size_t l_injectSz =
            ((i_boundary - l_padSz - (i_offset % i_boundary)) * 8) / 9;
        if(l_injectSz > i_srcSz)
        {
            l_injectSz = i_srcSz;
        }

        // Loop through injection of ECC
        while(l_completeSz < i_srcSz)
        {
            // Assert that injection size is a multiple of 8
            assert((l_injectSz % 8) == 0);

            // Inject ECC
            PNOR::ECC::injectECC(i_src + l_completeSz,
                                 l_injectSz,
                                 o_dst + l_completeEccSz);

            // Adjust local size variables
            l_completeSz += l_injectSz;
            l_completeEccSz += ((l_injectSz * 9) / 8);

            // Determine next size for ECC injection
            if((i_srcSz - l_completeSz) >= (((i_boundary - l_padSz) * 8) / 9))
            {
                // Set up size to go to next device boundary
                l_injectSz = ((i_boundary - l_padSz) * 8) / 9;
            }
            else
            {
                // Set up size to finish ECC injection
                l_injectSz = i_srcSz - l_completeSz;
            }

            // Determine if ECC injection is not finished
            if(l_injectSz > 0)
            {
                // Pad to device boundary if some ECC injection is left
                memset(o_dst + l_completeEccSz,
                       '\0',
                       l_padSz);
                l_completeEccSz += l_padSz;
            }
        } // while (l_completeSz < i_srcSz)
    }


/////////////////////////////////////////////////////////////////////
    PNOR::ECC::eccStatus removeECC(uint8_t* io_src,
                                   uint8_t* o_dst,
                                   size_t i_dstSz,
                                   const uint64_t i_offset,
                                   const uint64_t i_boundary)
    {
        PNOR::ECC::eccStatus l_status = PNOR::ECC::CLEAN;

        // Initialize local size variables for remove loop
        size_t l_completeSz = 0;
        size_t l_completeEccSz = 0;
        size_t l_padSz = i_boundary % 9;
        size_t l_removeSz =
            ((i_boundary - l_padSz - (i_offset % i_boundary)) * 8) / 9;
        if(l_removeSz > i_dstSz)
        {
            l_removeSz = i_dstSz;
        }

        // Loop through removal of ECC
        while(l_completeSz < i_dstSz)
        {
            // Assert that removal size is a multiple of 8
            assert((l_removeSz % 8) == 0);

            // remove ECC
            l_status = PNOR::ECC::removeECC(io_src + l_completeEccSz,
                                            o_dst + l_completeSz,
                                            l_removeSz);
            if (l_status == PNOR::ECC::UNCORRECTABLE)
            {
                break;
            }

            // Adjust local size variables
            l_completeSz += l_removeSz;
            l_completeEccSz += ((l_removeSz * 9) / 8);

            // Determine next size for ECC removal
            if((i_dstSz - l_completeSz) >= (((i_boundary - l_padSz) * 8) / 9))
            {
                // Set up size to go to next device boundary
                l_removeSz = ((i_boundary - l_padSz) * 8) / 9;
            }
            else
            {
                // Set up size to finish ECC removal
                l_removeSz = i_dstSz - l_completeSz;
            }

            // Determine if ECC removal is not finished
            if(l_removeSz > 0)
            {
                // Skip pad at device boundary if some ECC removal is left
                l_completeEccSz += l_padSz;
            }
        } // while (l_completeSz < i_dstSz)

        return l_status;
    }

/////////////////////////////////////////////////////////////////////
    errlHndl_t getBootMcSyncMode( uint8_t& o_mcSyncMode )
    {
        errlHndl_t l_err = nullptr;

        INITSERVICE::SPLESS::MboxScratch5_t l_scratch5;

        TRACFCOMP( g_trac_sbe, ENTER_MRK"Enter getBootMcSyncMode()");
        do
        {
            TARGETING::Target * l_sys = nullptr;
            (void) TARGETING::targetService().getTopLevelTarget( l_sys );
            assert( l_sys, "getBootMcSyncMode() system target is NULL");

            TARGETING::ATTR_MASTER_MBOX_SCRATCH_type l_scratchRegs;
            assert(l_sys->tryGetAttr
                      <TARGETING::ATTR_MASTER_MBOX_SCRATCH>(l_scratchRegs),
                   "getBootMcSyncMode() failed to get MASTER_MBOX_SCRATCH");
            l_scratch5.data32 = l_scratchRegs[INITSERVICE::SPLESS::SCRATCH_5];

            TRACFCOMP(g_trac_sbe,
                      "The MC Sync Bit is %d",
                      l_scratch5.mcSyncMode );

            o_mcSyncMode = l_scratch5.mcSyncMode;

        } while( 0 );
        TRACUCOMP(g_trac_sbe,EXIT_MRK "Exit getBootMcSyncMode()");

        return l_err;
    }

/////////////////////////////////////////////////////////////////////
errlHndl_t sbeDoReboot( void )
{
    errlHndl_t err = NULL;
    TRACFCOMP( g_trac_sbe, ENTER_MRK"sbeDoReboot");

    do{

        if(g_do_hw_keys_hash_transition)
        {
            err = updateKeyTransitionState(
                      TARGETING::KEY_TRANSITION_STATE_KEY_TRANSITION_SUCCEEDED);
            if(err)
            {
                TRACFCOMP(g_trac_sbe,
                    ERR_MRK"sbeDoReboot(): Failed in call to "
                    "updateKeyTransitionState with state of "
                    "KEY_TRANSITION_STATE_KEY_TRANSITION_SUCCEEDED");
                break;
            }
        }

#ifdef CONFIG_BMC_IPMI
        uint16_t count = SENSOR::DEFAULT_REBOOT_COUNT;
        SENSOR::RebootCountSensor l_sensor;

        // Set reboot count to default value
        TRACFCOMP( g_trac_sbe,
                   INFO_MRK"sbeDoReboot: "
                   "Writing Reboot Sensor Count=%d", count);

        err = l_sensor.setRebootCount( count );
        if ( err )
        {
            TRACFCOMP( g_trac_sbe,
                       ERR_MRK"sbeDoReboot: "
                       "FAIL Writing Reboot Sensor Count to %d. "
                       "Committing Error Log rc=0x%.4X eid=0x%.8X "
                       "plid=0x%.8X, but continuing shutdown",
                       count,
                       err->reasonCode(),
                       err->eid(),
                       err->plid());
            err->collectTrace(SBE_COMP_NAME);
            errlCommit( err, SBE_COMP_ID );

            // No Break - Still send chassis power cycle
        }

#else //non-IPMI

        if(   INITSERVICE::spBaseServicesEnabled()
           && !g_do_hw_keys_hash_transition)
        {
            // Sync all attributes to the FSP before doing the Shutdown
            err = TARGETING::AttrRP::syncAllAttributesToFsp();
            if( err )
            {
                // Something failed on the sync.  Commit the error here
                // and continue with the Re-IPL Request
                TRACFCOMP(g_trac_sbe, ERR_MRK
                    "sbeDoReboot: Error syncing attributes to FSP.  "
                    "RC=0x%04X, PLID=0x%08X",
                    ERRL_GETRC_SAFE(err),
                    ERRL_GETPLID_SAFE(err));
                errlCommit( err, SBE_COMP_ID );
            }
            else
            {
                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"sbeDoReboot() - Sync "
                           "Attributes to FSP" );
            }
        }

#endif

#ifdef CONFIG_CONSOLE
        if(g_do_hw_keys_hash_transition)
        {
            CONSOLE::displayf(SBE_COMP_NAME, "Performing Secure Boot key transition\n");
            CONSOLE::displayf(SBE_COMP_NAME, "System will power off after completion\n");
            CONSOLE::flush();
        }
        else
        {
            CONSOLE::displayf(SBE_COMP_NAME, "System Rebooting To "
                              "Complete SBE Update Process");
            CONSOLE::flush();
        }
#endif

#ifdef CONFIG_BMC_IPMI
        if(g_do_hw_keys_hash_transition)
        {
            // Initiate a graceful power off
            TRACFCOMP(g_trac_sbe,
                INFO_MRK"sbeDoReboot(): Performing Secure Boot key transition. "
                "Requesting power off");
            INITSERVICE::requestPowerOff();
        }
        else
        {
            // Initiate a graceful power cycle
            TRACFCOMP( g_trac_sbe,"sbeDoReboot: "
                       "requesting power cycle");
            INITSERVICE::requestReboot();
        }
#else //non-IPMI
        if(g_do_hw_keys_hash_transition)
        {
            TRACFCOMP(g_trac_sbe,
                INFO_MRK"sbeDoReboot(): Performing Secure Boot key transition. "
                "Calling INITSERVICE::doShutdown() with "
                "SHUTDOWN_KEY_TRANSITION = 0x%08X",
                INITSERVICE::SHUTDOWN_KEY_TRANSITION );
            INITSERVICE::doShutdown(INITSERVICE::
                                    SHUTDOWN_KEY_TRANSITION);
        }
        else
        {
            TRACFCOMP( g_trac_sbe,
                       INFO_MRK"sbeDoReboot(): Calling "
                       "INITSERVICE::doShutdown() with "
                       "SBE_UPDATE_REQUEST_REIPL = 0x%08X",
                       SBE_UPDATE_REQUEST_REIPL );
            // shutdown/TI hostboot
            INITSERVICE::doShutdown(SBE_UPDATE_REQUEST_REIPL);
        }
#endif

    }while(0);

    TRACFCOMP( g_trac_sbe, EXIT_MRK"sbeDoReboot");

    return err;
}

/////////////////////////////////////////////////////////////////////
errlHndl_t getHwKeyHashFromSbeImage(
                           TARGETING::Target* const i_target,
                           const EEPROM::EEPROM_ROLE i_seeprom,
                           const sbeSeepromSide_t i_bootSide,
                           SHA512_t o_hash,
                           const void * i_image_ptr) // defaults to nullptr
{
    errlHndl_t err = nullptr;

    // if i_image_ptr == nullptr, then read from SBE Seeprom;
    //   if i_seepom matches i_bootSide then read from SEEPROM via ChipOp
    //   else read from SEEPROM via I2C
    // if i_image_ptr != nullptr, then read from memory at i_image_ptr
    // TODO RTC:186269 Remove check forcing down I2C path when simics issue
    // is resolved
    bool l_useChipOp = (((i_bootSide == SBE_SEEPROM0) &&
                         (i_seeprom == EEPROM::SBE_PRIMARY)) ||
                        ((i_bootSide == SBE_SEEPROM1) &&
                        (i_seeprom == EEPROM::SBE_BACKUP)))
                        && !Util::isSimicsRunning();

    // reading via ChipOp should be supported, but this parameter is still used
    // for the call
    bool l_chipOpSupported = false;

    TRACFCOMP( g_trac_sbe, ENTER_MRK"getHwKeyHashFromSbeImage: "
               "i_target=0x%X, i_seeprom=%d, i_image_ptr=%p: "
               "reading from %s",
               get_huid(i_target), i_seeprom, i_image_ptr,
               (i_image_ptr) ? "memory" :
                  (l_useChipOp) ? "seeprom via ChipOp" :
                                  "seeprom via I2C");

    // Check Input Parameters
    if ( i_image_ptr == nullptr )
    {
        // Only check i_target and i_seeprom if i_image_ptr == nullptr;
        // otherwise they're ignored as i_image_ptr is used
        assert(i_target != nullptr,"getHwKeyHashFromSbeImage i_target can't be NULL");
        assert(i_target->getAttr<TARGETING::ATTR_TYPE>() == TARGETING::TYPE_PROC, "getHwKeyHashFromSbeImage i_target must be TYPE_PROC");
        assert(((i_seeprom == EEPROM::SBE_PRIMARY) || (i_seeprom == EEPROM::SBE_BACKUP)), "getHwKeyHashFromSbeImage i_seeprom=%d is invalid", i_seeprom);
    }


    // Code Assumptions
    static_assert((sizeof(P9XipHeader) % 8) == 0, "getHwKeyHashFromSbeImage(): sizeof(P9XipHeader) is not 8-byte-aligned");
    static_assert((sizeof(P9XipHeader().iv_magic) % 8) == 0, "getHwKeyHashFromSbeImage(): sizeof(P9XipHeader().iv_magic) is not 8-byte-aligned");
    static_assert((sizeof(SHA512_t) % 8) == 0, "getHwKeyHashFromSbeImage(): sizeof(SHA512_t) is not 8-byte-aligned");

    // Local variables used to capture ECC FFDC
    PNOR::ECC::eccStatus eccStatus = PNOR::ECC::CLEAN;
    size_t seeprom_offset = 0;
    size_t remove_ECC_size = 0;
    size_t size = 0;
    size_t expected_size = 0;

    // Create buffers for read operations and removing ECC
    const size_t max_buffer_size = PNOR::ECC::sizeWithEcc(
         (std::max(sizeof(P9XipHeader), sizeof(SHA512_t))));
    uint8_t tmp_data[max_buffer_size] = {0};
    uint8_t tmp_data_ECC[max_buffer_size] = {0};


    // For reading via ChipOp we need the buffer on a 128 byte boundary, so get
    // the right size for that boundary and then add 127 bytes to the buffer
    // length so we can guarantee a 128 byte aligned addr
    const size_t max_buffer_size_chipOp =
                   ALIGN_X(max_buffer_size,
                           CHIPOP_READ_SEEPROM_SIZE_ALIGNMENT_BYTES);
    uint8_t * l_chipOpBuffer = static_cast<uint8_t*>(
                                      malloc(max_buffer_size_chipOp + 127 ));

    uint64_t l_chipOpBufferAligned =
                 ALIGN_X(reinterpret_cast<uint64_t>(l_chipOpBuffer),
                         128);
    // Clear Buffer
    memset( reinterpret_cast<uint8_t*>(l_chipOpBufferAligned),
            0,
            max_buffer_size);
    do{
        // Get P9XipHeader, which is at the start of the SBE Image
        seeprom_offset = 0;

        if ( ( i_image_ptr == nullptr ) &&
             ( l_useChipOp == false ) )
        {
            // Read Seeprom via I2C
            // Calculate amount of data to read from SEEPROM
            size = PNOR::ECC::sizeWithEcc(sizeof(P9XipHeader));
            expected_size = size;

            //Read SBE Versions
            err = deviceRead( i_target,
                              tmp_data_ECC,
                              size,
                              DEVICE_EEPROM_ADDRESS(i_seeprom,
                                                    seeprom_offset,
                                                    EEPROM::HARDWARE));
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getHwKeyHashFromSbeImage() "
                           "Error getting SBE Data from Tgt=0x%X SEEPROM "
                           "(0x%X), RC=0x%X, PLID=0x%X",
                           get_huid(i_target),
                           EEPROM::SBE_BACKUP,
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));

                err->collectTrace(SBE_COMP_NAME);

                break;
            }
            assert(size==expected_size, "getHwKeyHashFromSbeImage: size 0x%X returned form reading P9XipHeader does not equal expected_size=0x%X", size, expected_size);

            remove_ECC_size = sizeof(P9XipHeader);
            eccStatus = removeECC( tmp_data_ECC,
                                   tmp_data,
                                   remove_ECC_size,
                                   seeprom_offset,
                                   SBE_SEEPROM_SIZE);

            if ( eccStatus == PNOR::ECC::UNCORRECTABLE )
            {
                TRACFCOMP( g_trac_sbe, "getHwKeyHashFromSbeImage(): "
                           "Uncorrectable eccStatus from reading P9XipHeader: "
                           "%d",
                           eccStatus);

                // Break here - error log will be created after do-while loop
                break;
            }

            TRACDBIN( g_trac_sbe,
                      "getHwKeyHashFromSbeImage: P9XipHeader with ECC",
                      tmp_data_ECC,
                      PNOR::ECC::sizeWithEcc(sizeof(P9XipHeader().iv_magic) ) );

        }
        else if ( ( i_image_ptr == nullptr ) &&
                  ( l_useChipOp == true ) )
        {
            // Read Seeprom via ChipOp
            err = SBEIO::sendPsuReadSeeprom(
                           i_target,
                           seeprom_offset,
                           ALIGN_X(sizeof(P9XipHeader),
                                   CHIPOP_READ_SEEPROM_SIZE_ALIGNMENT_BYTES),
                           mm_virt_to_phys(reinterpret_cast
                                           <void*>(l_chipOpBufferAligned)),
                           l_chipOpSupported);

            if(err || !l_chipOpSupported)
            {
              TRACFCOMP( g_trac_sbe,
                          "getHwKeyHashFromSbeImage: Error reading P9XipHeader "
                          "from seeprom via chipOp: either the Op is not "
                          "supported by SBE (%d) or something else went wrong "
                          "(err_rc=0x%X, err_plid=0x%X)",
                          l_chipOpSupported, ERRL_GETRC_SAFE(err),
                          ERRL_GETPLID_SAFE(err));
               break;
            }
            // Copy P9XipHeader to local membuf
            memcpy (tmp_data,
                    reinterpret_cast<void*>(l_chipOpBufferAligned),
                    sizeof(P9XipHeader));

        }
        else
        {
            // Copy P9XipHeader to local membuf
            memcpy (tmp_data, i_image_ptr, sizeof(P9XipHeader));
        }

        TRACDBIN( g_trac_sbe,
                  "getHwKeyHashFromSbeImage: P9XipHeader no ECC",
                  tmp_data,
                  sizeof(P9XipHeader().iv_magic) ) ;


        // After getting P9XipHeader, call p9_xip_find to find HBBL image
        // in SBE Image
        P9XipSection l_xipSection = {0};

        // Call p9_xip_find to find HBBL image in SBE image
        auto l_sectionId = P9_XIP_SECTION_SBE_HBBL;

        int xip_rc = p9_xip_get_section( tmp_data, l_sectionId, &l_xipSection );

        TRACUCOMP( g_trac_sbe, "getHwKeyHashFromSbeImage: xip_rc=%d: "
                   "Section iv_offset=0x%X, iv_size=0x%X, iv_alignment=0x%X",
                   xip_rc, l_xipSection.iv_offset, l_xipSection.iv_size,
                   l_xipSection.iv_alignment);

        // Check the return code
        if( ( xip_rc != 0 ) ||
            ( l_xipSection.iv_offset == 0 ) ||
            ( l_xipSection.iv_size == 0 ) )
        {
            TRACFCOMP( g_trac_sbe, "getHwKeyHashFromSbeImage: Error from "
                       "p9_xip_get_section: xip_rc=%d: Section iv_offset=0x%X, "
                       "iv_size=0x%X, iv_alignment=0x%X",
                       xip_rc, l_xipSection.iv_offset, l_xipSection.iv_size,
                       l_xipSection.iv_alignment);

            /*@
             * @errortype
             * @moduleid         SBE_GET_HW_KEY_HASH
             * @reasoncode       ERROR_FROM_XIP_FIND
             * @userdata1[0:31]  Target HUID
             * @userdata1[32:63] Seeprom Side
             * @userdata2[0:15]  Offset of HBBL Section in Seeprom Image
             * @userdata2[16:31] Size of HBBL Section in Seeprom Image
             * @userdata2[32:63] Return Code from p9_xip_get_section
             * @devdesc          Error Associated with Target's SBE Seeprom
             * @custdesc         A problem occurred with processor seeprom
             */
            err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                                SBE_GET_HW_KEY_HASH,
                                ERROR_FROM_XIP_FIND,
                                TWO_UINT32_TO_UINT64(
                                  TARGETING::get_huid(i_target),
                                  i_seeprom),
                                TWO_UINT16_ONE_UINT32_TO_UINT64(
                                  l_xipSection.iv_offset,
                                  l_xipSection.iv_size,
                                  xip_rc));

            err->addPartCallout(i_target,
                                HWAS::SBE_SEEPROM_PART_TYPE,
                                HWAS::SRCI_PRIORITY_HIGH,
                                HWAS::NO_DECONFIG,
                                HWAS::GARD_NULL );

            ErrlUserDetailsTarget(i_target,"Target").addToLog(err);

            err->collectTrace(SBE_COMP_NAME);

            break;
        }


        // Calculate Seeprom offset
        // -- Raw Image Offset -- HW Key Hash is at end of HBBL section
        seeprom_offset = l_xipSection.iv_offset + HBBL_HW_KEY_HASH_LOCATION;
        if ( ( i_image_ptr == nullptr ) &&
             ( l_useChipOp == false ) )
        {
            // Math to convert Image offset to Seeprom(with ECC) Offset
            // when reading Seeprom via I2C
            seeprom_offset = setECCSize(seeprom_offset);
        }

        TRACUCOMP( g_trac_sbe, "getHwKeyHashFromSbeImage: seeprom_offset "
                   "= 0x%X, size = 0x%X",
                   seeprom_offset, l_xipSection.iv_size);

        if ( ( i_image_ptr == nullptr ) &&
            ( l_useChipOp == false ) )
        {
            // Read HW Key Hash from SBE Image via I2C

            // Clear buffers and set size to SHA512_t+ECC
            memset( tmp_data_ECC, 0, max_buffer_size );
            memset( tmp_data, 0, max_buffer_size );
            size = PNOR::ECC::sizeWithEcc(sizeof(SHA512_t));
            expected_size = size;

            //Read SBE Seeprom
            err = deviceRead( i_target,
                              tmp_data_ECC,
                              size,
                              DEVICE_EEPROM_ADDRESS(
                                                i_seeprom,
                                                seeprom_offset,
                                                EEPROM::HARDWARE));
            if(err)
            {
                TRACFCOMP( g_trac_sbe, ERR_MRK"getHwKeyHashFromSbeImage() "
                           "Error getting HKH from SEEPROM (0x%X), "
                           "RC=0x%X, PLID=0x%X",
                           EEPROM::SBE_BACKUP,
                           ERRL_GETRC_SAFE(err),
                           ERRL_GETPLID_SAFE(err));

                err->collectTrace(SBE_COMP_NAME);

                break;
            }
            assert(size==expected_size, "getHwKeyHashFromSbeImage: size 0x%X returned form reading HW Key Hash does not equal expected_size=0x%X", size, expected_size);

            remove_ECC_size = sizeof(SHA512_t);
            eccStatus = removeECC( tmp_data_ECC,
                                   tmp_data,
                                   remove_ECC_size,
                                   seeprom_offset,
                                   SBE_SEEPROM_SIZE);

            if ( eccStatus == PNOR::ECC::UNCORRECTABLE )
            {
                TRACFCOMP( g_trac_sbe, "getHwKeyHashFromSbeImage(): "
                           "Uncorrectable eccStatus from reading HW Key Hash: %d",
                           eccStatus);

                // Break here - error log will be created after do-while loop
                break;
            }

            TRACDBIN( g_trac_sbe,
                      "getHwKeyHashFromSbeImage: ECC",
                      tmp_data_ECC,
                      expected_size ) ;

            TRACDBIN( g_trac_sbe,
                      "getHwKeyHashFromSbeImage: no ECC",
                      tmp_data,
                      sizeof(SHA512_t) ) ;

            // If we made it here, HW Key Hash was found successfully
            TRACUCOMP( g_trac_sbe, INFO_MRK"getHwKeyHashFromSbeImage(): hash "
                       "found successfully from SBE Seeprom- setting o_hash");
            memcpy(o_hash, tmp_data, sizeof(SHA512_t));
        }
        else if ( ( i_image_ptr == nullptr ) &&
                  ( l_useChipOp == true ) )
        {

            // Read Seeprom via ChipOp
            err = SBEIO::sendPsuReadSeeprom(
                           i_target,
                           seeprom_offset,
                           ALIGN_X(sizeof(SHA512_t),
                                   CHIPOP_READ_SEEPROM_SIZE_ALIGNMENT_BYTES),
                           mm_virt_to_phys(reinterpret_cast
                                           <void*>(l_chipOpBufferAligned)),
                           l_chipOpSupported);

            if(err || !l_chipOpSupported)
            {
               TRACFCOMP( g_trac_sbe,
                          "getHwKeyHashFromSbeImage: Error reading Hash from "
                          "seeprom via chipOp: either the Op is not supported "
                          "by SBE (%d) or something else went wrong: (err_rc="
                          "0x%X, err_plid=0x%X): offset=0x%X",
                          l_chipOpSupported, ERRL_GETRC_SAFE(err),
                          ERRL_GETPLID_SAFE(err), seeprom_offset);
               break;
            }
            // Copy P9XipHeader to local membuf
            memcpy (o_hash,
                    reinterpret_cast<void*>(l_chipOpBufferAligned),
                    sizeof(SHA512_t));

        }
        else
        {
            // Copy HW Key Hash from system memory
            memcpy(o_hash,
                   reinterpret_cast<uint8_t*>(const_cast<void*>(i_image_ptr))
                     + seeprom_offset,
                   sizeof(SHA512_t));
        }

    }while(0);

    // Create error log here for ECC fails
    if ( (eccStatus == PNOR::ECC::UNCORRECTABLE)
         && ( err == nullptr ) )
    {
        // Trace above; create error log here

        /*@
         * @errortype
         * @moduleid         SBE_GET_HW_KEY_HASH
         * @reasoncode       SBE_ECC_FAIL
         * @userdata1[0:31]  Target HUID
         * @userdata1[32:63] Seeprom Side
         * @userdata2[0:15]  ECC Status
         * @userdata2[16:31] No-ECC Data Size
         * @userdata2[32:63] Offset into Seeprom Data Came From
         * @devdesc          Error Associated with Updating this Target
         * @custdesc         A problem occurred with processor seeprom
         */
        err = new ErrlEntry(ERRL_SEV_UNRECOVERABLE,
                            SBE_GET_HW_KEY_HASH,
                            SBE_ECC_FAIL,
                            TWO_UINT32_TO_UINT64(
                              TARGETING::get_huid(i_target),
                              i_seeprom),
                            TWO_UINT16_ONE_UINT32_TO_UINT64(
                              eccStatus,
                              remove_ECC_size,
                              seeprom_offset));

        err->addPartCallout(i_target,
                            HWAS::SBE_SEEPROM_PART_TYPE,
                            HWAS::SRCI_PRIORITY_HIGH,
                            HWAS::NO_DECONFIG,
                            HWAS::GARD_NULL );

        ErrlUserDetailsTarget(i_target,"Target").addToLog(err);

        err->collectTrace(SBE_COMP_NAME);
    }

    //Free up the buffer before returning no matter what
    if (l_chipOpBuffer)
    {
        free(l_chipOpBuffer);
        l_chipOpBuffer = nullptr;
    }

    TRACFCOMP( g_trac_sbe, EXIT_MRK"getHwKeyHashFromSbeImage: "
               "err rc=0x%X, plid=0x%X, o_hash=0x%.8X",
               ERRL_GETRC_SAFE(err), ERRL_GETPLID_SAFE(err),
               sha512_to_u32(o_hash));

    return err;
}

errlHndl_t secureKeyTransition()
{
    errlHndl_t l_errl = nullptr;

#ifdef CONFIG_SECUREBOOT
    do {
    bool l_loaded = false;
    PNOR::SectionInfo_t l_secInfo;

    // Get SBKT PNOR section info from PNOR RP
    l_errl = getSectionInfo(PNOR::SBKT, l_secInfo);
    // SBKT section is optional so just delete error and no-op
    if (l_errl)
    {
        TRACFCOMP( g_trac_sbe, ERR_MRK"secureKeyTransition() - getSectionInfo() optional PNOR::SBKT DNE");
        delete l_errl;
        l_errl = nullptr;
        break;
    }

    // if it has a secure header, we do need to load and verify the container
    if(l_secInfo.secure)
    {
        // Verify and Load SBKT section and nested container.
        l_errl = loadSecureSection(PNOR::SBKT);
        if (l_errl)
        {
            TRACFCOMP( g_trac_sbe, ERR_MRK"secureKeyTransition() - Error from loadSecureSection(PNOR::SBKT)");
            break;
        }
        l_loaded = true;

        // Get new verified HW key hash
        const void* l_pVaddr = reinterpret_cast<void*>(l_secInfo.vaddr);
        SECUREBOOT::ContainerHeader l_nestedConHdr;
        l_errl = l_nestedConHdr.setHeader(l_pVaddr);
        if(l_errl)
        {
            TRACFCOMP( g_trac_sbe, ERR_MRK"secureKeyTransition() - setheader failed");
            break;
        }
        // Get pointer to first element of hwKeyHash from header.
        const uint8_t* l_hwKeyHash = l_nestedConHdr.hwKeyHash()[0];
        // Update global variable with hw keys hash to transition to.
        memcpy(g_hw_keys_hash_transition_data, l_hwKeyHash,
               sizeof(g_hw_keys_hash_transition_data));
        // Indicate a key transition is required
        g_do_hw_keys_hash_transition = true;

        l_errl = updateKeyTransitionState(
                     TARGETING::KEY_TRANSITION_STATE_KEY_TRANSITION_STARTED);
        if(l_errl)
        {
            TRACFCOMP(g_trac_sbe,ERR_MRK "secureKeyTransition(): Failed in "
                "call to updateKeyTransitionState() with state of "
                "KEY_TRANSITION_STATE_KEY_TRANSITION_STARTED");
            break;
        }

        bool l_hw_lab_override_flag = l_nestedConHdr.sb_flags()->hw_lab_override;
        TRACFCOMP(g_trac_sbe, "Overriding the Lab Security Backdoor Bit due to"
                  " key transition; new Security Backdoor Enabled bit is %d",
                  l_nestedConHdr.sb_flags()->hw_lab_override);
        l_errl = SECUREBOOT::setSbeSecurityMode(!l_hw_lab_override_flag);
        if(l_errl)
        {
            TRACFCOMP(g_trac_sbe, ERR_MRK"secureKeyTransition() - could not"
                      " set SBE security mode.");
            break;
        }
    }
    if(l_loaded)
    {
        l_errl = unloadSecureSection(PNOR::SBKT);
        if (l_errl)
        {
            TRACFCOMP( g_trac_sbe, ERR_MRK"secureKeyTransition() - Error from unloadSecureSection(PNOR::SBKT)");
            break;
        }
    }
    } while(0);
#endif

    return l_errl;
}

/////////////////////////////////////////////////////////////////////

errlHndl_t locateHbblIdStringBfr( void * i_pSourceBfr,
                                  uint32_t i_SourceBfrLen,
                                  void * & o_pHbblIdStringBfr )
{
    errlHndl_t l_errl = NULL;
    o_pHbblIdStringBfr = NULL;


    // packing of ID string is defined in bl_start.S
    //   - 16 byte aligned : note, after customize, this may only be
    //                              8 byte aligned
    //   - 128 bytes long
    //   - resides in .data at end of binary

    //  start near end of bfr, minimum of 128 bytes from overflow,
    //    aligned on 16 byte boundary
    uint64_t sourceBfrAddr = reinterpret_cast<uint64_t>(i_pSourceBfr);
    uint64_t bfrOverflowAddr = sourceBfrAddr + i_SourceBfrLen;
    uint64_t startSearchAddr = ALIGN_DOWN_8(bfrOverflowAddr - 128);

    uint64_t * pBfrUnderflow = reinterpret_cast<uint64_t *>(sourceBfrAddr);
    uint64_t * pStartSearch = reinterpret_cast<uint64_t *>(startSearchAddr);

    // 'HBBL ID '
#define SBE_HBBL_ID_MARKER0  0x4842424c20494420ull
    // 'STRING ='
#define SBE_HBBL_ID_MARKER1  0x535452494e47203dull

    TRACFCOMP( g_trac_sbe,
               INFO_MRK"locateHbblIdStringBfr() : start search "
               "pBfr=0x%X, BfrLen=0x%X, pSearchStart=0x%X",
               sourceBfrAddr, i_SourceBfrLen, pStartSearch );

    do
    {
        for // search for the string, starting from the end of the bfr
          ( uint64_t * pCurTestPosn = pStartSearch;
            pCurTestPosn >= pBfrUnderflow;
            pCurTestPosn-=(8/8) )  // backup 8 bytes, 8-byte ptr math
        {
            if // current position is hbbl id marker
              ( ((*(pCurTestPosn)) == SBE_HBBL_ID_MARKER0) &&
                ((*(pCurTestPosn+1)) == SBE_HBBL_ID_MARKER1) )
            {
                // found the string eye catcher, all done
                //  note : step over 16 byte hdr using 8-byte ptr math
                o_pHbblIdStringBfr = pCurTestPosn + (16/8);

                TRACFCOMP( g_trac_sbe,
                           INFO_MRK"locateHbblIdStringBfr() : string found "
                           "pString=0x%X",
                           o_pHbblIdStringBfr );

                TRACFBIN( g_trac_sbe,
                          INFO_MRK"locateHbblIdStringBfr() : "
                                  "Eye Catcher + string Bfr = ",
                          pCurTestPosn,
                          (16+128) );

                break;
            }
        } // end reverse bfr search

    } while(0);

    return l_errl;
}

errlHndl_t updateKeyTransitionState(
    const TARGETING::KEY_TRANSITION_STATE i_keyTransitionState)
{
    errlHndl_t pError = nullptr;

    do {

    TRACFCOMP(g_trac_sbe,
        INFO_MRK "updateKeyTransitionState: new key transition state of "
        "0x%08X",
        i_keyTransitionState);

    TARGETING::UTIL::getCurrentNodeTarget()->setAttr<
        TARGETING::ATTR_KEY_TRANSITION_STATE>(i_keyTransitionState);

    if(INITSERVICE::spBaseServicesEnabled())
    {
        auto * pMsg = msg_allocate();
        pMsg->type = SBE::MSG_KEY_TRANSITION_EVENT_OCCURRED;
        pMsg->data[0] = i_keyTransitionState;
        pMsg->data[1] = 0;
        pMsg->extra_data = nullptr;

        pError = MBOX::sendrecv(MBOX::IPL_SERVICE_QUEUE,pMsg);
        if (pError)
        {
            TRACFCOMP(g_trac_sbe,
                ERR_MRK "updateKeyTransitionState: "
                "Failed in call to MBOX::sendrecv attempting to send a "
                "MSG_KEY_TRANSITION_EVENT_OCCURRED event with key transition "
                "state of 0x%08X",
                i_keyTransitionState);
        }

        // Error or not, always have to free the memory
        msg_free(pMsg);
        pMsg=nullptr;
    }

    } while(0);

    return pError;
}


errlHndl_t querySbeSeepromVersions()
{
    errlHndl_t l_errl = nullptr;
    sbeTargetState_t l_sbeState;
    TARGETING::TargetHandleList l_procList;
    do {
        // Query all of the functional processor targets
        TARGETING::getAllChips(l_procList,
                            TARGETING::TYPE_PROC,
                            true); // true: return functional targets
        assert( l_procList.size(), "querySbeSeepromVersions: no functional procs found!")

        if(!Util::isSimicsRunning())
        {
            for(const auto & l_procTarget : l_procList)
            {
                memset(&l_sbeState, 0, sizeof(l_sbeState));
                l_sbeState.target = l_procTarget;
                // populate the SBE SEEPROM version info
                l_errl = getSeepromVersions(l_sbeState);

                if(l_errl)
                {
                    break;
                }

                // If the image_versions do not match then we must set the attribute to reflect that
                if(memcmp(&l_sbeState.seeprom_0_ver.image_version,
                        &l_sbeState.seeprom_1_ver.image_version,
                        SBE_IMAGE_VERSION_SIZE) != 0)
                {
                    // ATTR_HB_SBE_SEEPROM_VERSION_MISMATCH is defaulted to be 0, so
                    // we need to set the attribute to 1 if we find that the SEEPROM
                    // sides do not have matching versions.
                    l_procTarget->setAttr<ATTR_HB_SBE_SEEPROM_VERSION_MISMATCH>(1);
                }
            }

            if(l_errl)
            {
                TRACFCOMP(g_trac_sbe,
                          ERR_MRK "querySbeSeepromVersions: "
                          "Error occured looking up seeprom versions. Returning early from function.");
                break;
            }
        }
        else
        {
            // If we are running simics it is safe to assume both sides of the seeprom are the same.
            // We don't actually perform SEEPROM updates in simics do to time restrictions so the
            // concept of updating the SBE SEEPROMs in simics is a little spoofed out so we need
            // to do some fudging here. ATTR_HB_SBE_SEEPROM_VERSION_MATCH is defaulted to 1 so there
            // is no need to set it.
        }

    } while(0);
    return l_errl;
}


} //end SBE Namespace

OpenPOWER on IntegriCloud