summaryrefslogtreecommitdiffstats
path: root/src/usr/isteps/nvdimm/nvdimm_update.C
blob: 1f42228ced080495be80fd993f8d77df4fc56b43 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/isteps/nvdimm/nvdimm_update.C $                       */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2018,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#include "nvdimm_update.H"
#include "nvdimm.H"
#include <isteps/nvdimm/nvdimm.H>
#include <isteps/nvdimm/nvdimmreasoncodes.H>

#include <initservice/istepdispatcherif.H> // sendProgressCode
#include <util/utilmclmgr.H> // secure LID manager
#include <errl/errlmanager.H>
#include <devicefw/userif.H>
#include <vpd/spdenums.H>
#include <sys/time.h>

// Unique tracing for nvdimm update process
const char NVDIMM_UPD[] = "NVDIMM_UPD";
trace_desc_t* g_trac_nvdimm_upd = NULL;
TRAC_INIT(&g_trac_nvdimm_upd, NVDIMM_UPD, 2*KILOBYTE);


// Easy macro replace for unit testing
//#define TRACUCOMP(args...)  TRACFCOMP(args)
#define TRACUCOMP(args...)

namespace NVDIMM
{
//////////////////////////////////////////////////////////////////////////////
// Helper Inline functions
//////////////////////////////////////////////////////////////////////////////
/**
 * @brief Inline function to collect NVDIMM traces and
 *        make sure error is logged at least as PREDICTIVE
 */
inline void commitPredictiveNvdimmError(errlHndl_t & io_err)
{
    io_err->collectTrace(NVDIMM_UPD, 512);
    io_err->collectTrace(NVDIMM_COMP_NAME, 256);  // for helper function traces
    if ( io_err->sev() < ERRORLOG::ERRL_SEV_PREDICTIVE )
    {
        io_err->setSev( ERRORLOG::ERRL_SEV_PREDICTIVE );
    }
    ERRORLOG::errlCommit(io_err, NVDIMM_COMP_ID);
}

////////////////////////////////////////////////////////////////////////////////
// Helper structs/enums for code update
//
// Refer to JEDEC BAEBI spec for details
// https://www.jedec.org/standards-documents/docs/jesd245a
////////////////////////////////////////////////////////////////////////////////
// Definition of FIRMWARE_OPS_STATUS -- offset 0x71
typedef union {
    uint8_t whole;
    struct
    {
        // [7:6] : reserved
        uint8_t reserved : 2;
        // [5] : the abort of the last fw operation failed
        uint8_t fw_ops_abort_error : 1;
        // [4] : the last fw operation was aborted by the host
        uint8_t fw_ops_abort_success : 1;
        // [3] : the last block has been received successfully by the NVDIMM
        //       and the host may proceed with sending the next block
        uint8_t fw_ops_block_received : 1;
        // [2] : the module is in FW update mode where firmware on the module
        //       can be changed.
        //       If cleared, firmware on the module cannot be changed
        uint8_t fw_ops_update_mode : 1;
        // [1] : the last firmware operation failed
        uint8_t fw_ops_error : 1;
        // [0] : the last firmware operation completed without any errors
        uint8_t fw_ops_success : 1;
    } PACKED;
} fw_ops_status_t;

// Definition of FIRMWARE_OPS_CMD -- offset 0x4A
typedef union {
    uint8_t whole;
    struct
    {
        // [6-7] : Reserved for future use
        uint8_t reserved : 2;
        // [5] : Start a Validate Firmware Image operation
        uint8_t start_validate_fw_image_op : 1;
        // [4] : Start a Validate Firmware Header operation
        uint8_t start_validate_fw_header_op : 1;
        // [3] : Start a Commit Firmware operation
        uint8_t start_commit_fw_op : 1;
        // [2] : Start a Generate Firmware Checksum operation
        uint8_t start_generate_fw_checksum_op : 1;
        // [1] : Start a Clear Firmware operation
        uint8_t start_clear_fw_op : 1;
        // [0] : Enable / Disable firmware update mode.
        // 0b0: fw update mode is disabled.
        // 0b1: fw update mode is enabled.
        uint8_t firmware_update_mode : 1;
    } PACKED;
} fw_ops_cmd_t;

// Definition of NVDIMM_CMD_STATUS0 -- offset 0x61
typedef union {
    uint8_t whole;
    struct
    {
        // [7] : Firmware operations currently in progress
        uint8_t firmware_ops_in_progress : 1;
        // [6] : Arm operation in progress
        uint8_t arm_in_progress : 1;
        // [5] : Abort operation in progress
        uint8_t abort_in_progress : 1;
        // [4] : Erase operation in progress
        uint8_t erase_in_progress : 1;
        // [3] : Restore operation in progress
        uint8_t restore_in_progress : 1;
        // [2] : Catastrophic Save operation in progress
        uint8_t catastrophic_save_in_progress : 1;
        // [1] : Factory Default in progress
        uint8_t factory_default_in_progress : 1;
        // [0] : Operation in progress
        uint8_t operation_in_progress : 1;
    } PACKED;
} nvdimm_cmd_status0_t;

// A code update block is composed of this many bytes
const uint8_t BYTES_PER_BLOCK = 32;


///////////////////////////////////////////////////////////////////////////////
// NVDIMM LID Image
///////////////////////////////////////////////////////////////////////////////
NvdimmLidImage::NvdimmLidImage(const void * i_lidImageAddr, size_t i_size) :
    iv_lidImage(i_lidImageAddr), iv_lidImageSize(i_size)
{
}

uint32_t NvdimmLidImage::getType()
{
    uint32_t o_type = INVALID_TYPE;

    if (iv_lidImageSize >= sizeof(nvdimm_image_header_t))
    {
        const nvdimm_image_header_t * pLid =
            reinterpret_cast<const nvdimm_image_header_t*>(iv_lidImage);
        o_type = (uint32_t)pLid->module_mnfg_id_code << 16;
        o_type |= (uint32_t)pLid->module_product_id;
    }
    return o_type;
}

uint16_t NvdimmLidImage::getVersion()
{
    uint16_t o_version = INVALID_VERSION;

    if (iv_lidImageSize >= sizeof(nvdimm_image_header_t))
    {
        const nvdimm_image_header_t * pLid =
            reinterpret_cast<const nvdimm_image_header_t*>(iv_lidImage);
        o_version = pLid->controller_firmware_revision;
    }
    return o_version;
}

const uint8_t * NvdimmLidImage::getHeaderAndSmartSignature(uint16_t & o_size)
{
    o_size = 0;
    if (iv_lidImageSize > sizeof(nvdimm_image_header_t))
    {
        const nvdimm_image_header_t * pLid =
            reinterpret_cast<const nvdimm_image_header_t*>(iv_lidImage);
        o_size = le16toh(pLid->SMART_digital_signature_size);
        o_size += sizeof(nvdimm_image_header_t);
    }
    return reinterpret_cast<const uint8_t*>(iv_lidImage);
}


const void * NvdimmLidImage::getFlashImage()
{
    void * o_image_ptr = nullptr;
    if (iv_lidImageSize > sizeof(nvdimm_image_header_t))
    {
        const nvdimm_image_header_t * pLid =
            reinterpret_cast<const nvdimm_image_header_t*>(iv_lidImage);

        // make sure we don't point outside of lid memory
        // nvdimm flash image starts after the header and digital signature
        if ((sizeof(nvdimm_image_header_t) +
             le16toh(pLid->SMART_digital_signature_size)) < iv_lidImageSize)
        {
            TRACUCOMP(g_trac_nvdimm_upd,
                "NvdimmLidImage::getFlashImage() -> starts at offset 0x%X "
                "(digital signature size: %d, header size: %d)",
                sizeof(nvdimm_image_header_t) +
                le16toh(pLid->SMART_digital_signature_size),
                le16toh(pLid->SMART_digital_signature_size),
                sizeof(nvdimm_image_header_t));

            o_image_ptr = reinterpret_cast<void*>(const_cast<uint8_t *>(
                              reinterpret_cast<const uint8_t*>(iv_lidImage) +
                              sizeof(nvdimm_image_header_t) +
                              le16toh(pLid->SMART_digital_signature_size)));
        }
    }
    return o_image_ptr;
}


size_t NvdimmLidImage::getFlashImageSize()
{
    uint32_t o_flash_size = 0;
    if (iv_lidImageSize > sizeof(nvdimm_image_header_t))
    {
        const nvdimm_image_header_t * pLid =
            reinterpret_cast<const nvdimm_image_header_t*>(iv_lidImage);
        // Note: firmware_image_size does NOT include the Digital Signature
        //       (does include the 32-byte header though)
        o_flash_size = le32toh(pLid->firmware_image_size);
        o_flash_size -= sizeof(nvdimm_image_header_t);

        // safety check so we don't access past lid's memory size
        if ((o_flash_size + sizeof(nvdimm_image_header_t) +
             le16toh(pLid->SMART_digital_signature_size)) > iv_lidImageSize)
        {
            TRACFCOMP(g_trac_nvdimm_upd,
                ERR_MRK"getFlashImageSize(): %ld flash size + %ld header + "
                "%ld digital signature is greater than %ld overall lid size",
                o_flash_size, sizeof(nvdimm_image_header_t),
                le16toh(pLid->SMART_digital_signature_size),
                iv_lidImageSize);
            // flash image size is outside of lid memory bounds so don't return
            // a valid flash size
            o_flash_size = 0;
        }
    }
    return o_flash_size;
}

///////////////////////////////////////////////////////////////////////////////
// NVDIMM Installed Image
///////////////////////////////////////////////////////////////////////////////
NvdimmInstalledImage::NvdimmInstalledImage(TARGETING::Target * i_nvDimm) :
    iv_dimm(i_nvDimm), iv_version(INVALID_VERSION),
    iv_manufacturer_id(INVALID_ID), iv_product_id(INVALID_ID),
    iv_timeout(INVALID_TIMEOUT),
    iv_max_blocks_per_region(INVALID_REGION_BLOCK_SIZE)
{
    // initialize to invalid values
}

errlHndl_t NvdimmInstalledImage::getType(uint32_t & o_type)
{
    errlHndl_t l_err = nullptr;
    do {
      size_t l_id_size = 0; // size of id
      if ( iv_manufacturer_id == INVALID_ID)
      {
          // grab values for the installed NVDIMM via SPD
          l_id_size = sizeof(iv_manufacturer_id);
          l_err = deviceRead(iv_dimm, &iv_manufacturer_id, l_id_size,
                           DEVICE_SPD_ADDRESS(SPD::RAW_MODULE_MANUFACTURER_ID));
          if (l_err)
          {
              TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"NvdimmInstalledImage::getType()"
                  " nvdimm[%X] failed to read manufacturer ID",
                  TARGETING::get_huid(iv_dimm));
              iv_manufacturer_id = INVALID_ID;
              break;
          }
      }

      if (iv_product_id == INVALID_ID)
      {
          // grab values for the installed NVDIMM via SPD
          l_id_size = sizeof(iv_product_id);
          l_err = deviceRead(iv_dimm, &iv_product_id, l_id_size,
                            DEVICE_SPD_ADDRESS(SPD::RAW_MODULE_PRODUCT_ID));
          if (l_err)
          {
              TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"NvdimmInstalledImage::getType()"
                  " nvdimm[%X] failed to read product ID",
                  TARGETING::get_huid(iv_dimm));
              iv_product_id = INVALID_ID;
              break;
          }
      }
    } while (0);

    // return the concatenated Type (this may include INVALID_IDs)
    o_type = ((uint32_t)iv_manufacturer_id << 16) | (uint32_t)iv_product_id;
    return l_err;
}

errlHndl_t NvdimmInstalledImage::getVersion(uint16_t & o_version,
                                            const bool i_force_recollect)
{
    errlHndl_t l_err = nullptr;

    do {
      if ((iv_version == INVALID_VERSION) || i_force_recollect)
      {
          // Return version in little-endian format
          uint8_t l_rev1 = 0xFF;
          uint8_t l_rev0 = 0xFF;

          l_err = nvdimmReadReg(iv_dimm, SLOT1_FWREV0, l_rev0 );
          if (l_err)
          {
              TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"NvdimmInstalledImage::"
                  "getVersion() nvdimm[%X] failed to read SLOT1_FWREV0",
                  TARGETING::get_huid(iv_dimm));
              iv_version = INVALID_VERSION;
              break;
          }
          iv_version = (uint16_t)l_rev0 << 8;
          l_err = nvdimmReadReg(iv_dimm, SLOT1_FWREV1, l_rev1 );
          if (l_err)
          {
              TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"NvdimmInstalledImage::"
                  "getVersion() nvdimm[%X] failed to read SLOT1_FWREV1",
                  TARGETING::get_huid(iv_dimm));
              iv_version = INVALID_VERSION;
              break;
          }
          iv_version |= (uint16_t)l_rev1;
      }
    } while (0);
    o_version = iv_version;
    return l_err;
}


errlHndl_t NvdimmInstalledImage::updateImage(NvdimmLidImage * i_lidImage)
{
    errlHndl_t l_err = nullptr;
    // need to always disable this after it gets enabled
    bool l_fw_update_mode_enabled = false;
    do {
        INITSERVICE::sendProgressCode();
        ////////////////////////////////////////////////////////////////////////
        // Start of firmware update logic, section 9.7 in JESD245B
        ////////////////////////////////////////////////////////////////////////
        // 1. Validate module manufacturer ID and module product identifier
        //    Done before this was called, it is what selected i_lidImage

        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 2");
        // 2. Verify 'Operation In Progress' bit in the NVDIMM_CMD_STATUS0
        //    register is cleared (ie. NV controller is NOT busy)
        nvdimm_cmd_status0_t l_status;
        l_err = nvdimmReadReg(iv_dimm, NVDIMM_CMD_STATUS0, l_status.whole);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Read of NVDIMM_CMD_STATUS0 register on 0x%.8X NVDIMM failed",
                TARGETING::get_huid(iv_dimm), l_status.whole);
            break;
        }
        if (l_status.operation_in_progress)
        {
            TRACFCOMP(g_trac_nvdimm_upd,ERR_MRK"updateImage: "
                "NV controller is busy (0x%08X) for NVDIMM 0x%.8X",
                l_status.whole, TARGETING::get_huid(iv_dimm));
            /*
             *@errortype
             *@moduleid         UPDATE_IMAGE
             *@reasoncode       NVDIMM_OPERATION_IN_PROGRESS
             *@userdata1        NVDIMM Target Huid
             *@userdata2        NVDIMM_CMD_STATUS0
             *@devdesc          NV controller is busy so no update can run
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry(
                                   ERRORLOG::ERRL_SEV_PREDICTIVE,
                                   UPDATE_IMAGE,
                                   NVDIMM_OPERATION_IN_PROGRESS,
                                   TARGETING::get_huid(iv_dimm),
                                   l_status.whole,
                                   ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
            l_err->collectTrace( NVDIMM_COMP_NAME, 256 );
            l_err->addPartCallout( iv_dimm,
                                   HWAS::NV_CONTROLLER_PART_TYPE,
                                   HWAS::SRCI_PRIORITY_HIGH );
            l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                        HWAS::SRCI_PRIORITY_LOW );
            break;
        }

        // 3. Make sure we start from a cleared state
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 3");
        l_err = clearFwOpsStatus();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Unable to clear firmware ops status for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 4. Enable firmware update mode
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 4");
        l_err = changeFwUpdateMode(FW_UPDATE_MODE_ENABLED);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Unable to enable firmware update mode for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        // Set this flag so we will disable the update mode on error
        l_fw_update_mode_enabled = true;

        // 5. Clear the Firmware Operation status
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 5");
        l_err = clearFwOpsStatus();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Unable to clear firmware ops status for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 6. Clear the firmware data block to ensure there is no residual data.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 6");
        l_err = clearFwDataBlock();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Step 6. clearFwDataBlock() failed for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 7. Send the first part (header + SMART signature) of
        //    the Firmware Image Data

        // 7a. Write the TYPED_BLOCK_DATA register with 0x1 (Firmware Image Data)
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7a");
        l_err = nvdimmWriteReg(iv_dimm, TYPED_BLOCK_DATA, 0x01);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Write of 0x01 to TYPED_BLOCK_DATA failed for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 7b. Write the BLOCK_ID, REGION_ID0 and REGION_ID1 registers with value 0.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7b");
        l_err = nvdimmWriteReg(iv_dimm, BLOCK_ID, 0x00);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Write of 0x00 to BLOCK_ID failed for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        l_err = nvdimmWriteReg(iv_dimm, REGION_ID0, 0x00);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Write of 0x00 to REGION_ID0 failed for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        l_err = nvdimmWriteReg(iv_dimm, REGION_ID1, 0x00);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Write of 0x00 to REGION_ID1 failed for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 7c. Send the header (first 32 bytes of the image) +
        //     SMART digital signature to multiple blocks of
        //     TYPED_BLOCK_DATA_BYTE0 - TYPED_BLOCK_DATA_BYTE31.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7c");
        uint16_t header_plus_signature_size = 0;
        const uint8_t * pHeaderAndDigitalSignature =
            i_lidImage->getHeaderAndSmartSignature(header_plus_signature_size);
        l_err = byteRegionBlockTransfer( pHeaderAndDigitalSignature,
                                         header_plus_signature_size, false );
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: Unable to send "
                "header and digital signature update for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 7d. Validate the transfer by checksum

        // 7d.i. Host calculate checksum using the crc16 algo in JESD245B
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7d.i.");
        uint16_t hostCksm = crc16(pHeaderAndDigitalSignature,
                                  header_plus_signature_size);

        // 7d.ii. Set bit 1 (Clear the FIRMWARE_OPS_STATUS register) in
        //        the NVDIMM_MGT_CMD1 register.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7d.ii.");
        l_err = clearFwOpsStatus();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "Unable to clear Firmware Operations Status for NVDIMM %.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 7d.iii - 7d.vii
        // Write the FIRMWARE_OPS_CMD register with value 0x04
        // to start a Generate Firmware Checksum operation.
        // Compare the module generated value with the host value.
        // Abort the workflow if they do not match.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 7d.iii.");
        uint16_t nvCksm;
        l_err = calcAndGetCksm(nvCksm);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage: calcAndGetCksm() "
                "failed for 0x%.8X nvdimm", TARGETING::get_huid(iv_dimm));
            break;
        }
        if (hostCksm != nvCksm)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImage: "
                "NVDIMM 0x%.8X: data checksums mismatch (calc host: 0x%X "
                "and nv: 0x%X) for first part (header + SMART signature)",
                TARGETING::get_huid(iv_dimm), hostCksm, nvCksm);
            /*
             *@errortype
             *@moduleid         UPDATE_IMAGE
             *@reasoncode       NVDIMM_CHECKSUM_ERROR
             *@userdata1        NVDIMM Target Huid
             *@userdata2[0:15]  Host checksum calculated
             *@userdata2[16:31] NV checksum returned
             *@userdata2[32:47] size of data for checksum
             *@devdesc          Checksum failure when transferring region
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry(
                                   ERRORLOG::ERRL_SEV_PREDICTIVE,
                                   UPDATE_IMAGE_DATA,
                                   NVDIMM_CHECKSUM_ERROR,
                                   TARGETING::get_huid(iv_dimm),
                                   FOUR_UINT16_TO_UINT64(
                                      hostCksm, nvCksm,
                                      header_plus_signature_size,
                                      0x0000),
                                   ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
            l_err->collectTrace( NVDIMM_COMP_NAME, 256 );

            // maybe some data was altered on the NV controller
            l_err->addPartCallout( iv_dimm,
                                   HWAS::NV_CONTROLLER_PART_TYPE,
                                   HWAS::SRCI_PRIORITY_HIGH );
            // possible code issue
            l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                        HWAS::SRCI_PRIORITY_LOW );
            break;
        }

        // 8. Command the module to validate that the firmware image is valid
        //    for the module based on the header.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 8");
        l_err = validateFwHeader();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage: firmware header "
                "for 0x%.8X nvdimm cannot be validated",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        else
        {
            TRACFCOMP(g_trac_nvdimm_upd, "updateImage: NVDIMM 0x%.8X "
                "updated with valid header + SMART signature",
                TARGETING::get_huid(iv_dimm));
        }

        // 9. Commit the first firmware data region
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 9");
        l_err = commitFwRegion();
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage: commitFwRegion() "
                "of first data region failed for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 10. Send and commit the remaining firmware data in
        //     REGION_BLOCK_SIZE regions
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10");
        l_err = updateImageData(i_lidImage);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage:  "
                "updateImageData() failed sending full image for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // 11. Validate the firmware data
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 11");
        l_err = validateFwImage();
        if ( l_err )
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage:  "
                "validateFwImage() failed for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        else
        {
            TRACFCOMP(g_trac_nvdimm_upd, "updateImage: NVDIMM 0x%.8X "
                "updated with valid image data", TARGETING::get_huid(iv_dimm));
        }

        // 12. Disable firmware update mode
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 12");
        l_fw_update_mode_enabled = false;  // don't retry the disable on error
        l_err = changeFwUpdateMode(FW_UPDATE_MODE_DISABLED);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage:  "
                "Unable to disable FW update mode for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // There are two slots for firmware.
        // Slot 0 is read-only hence this procedure only updates slot 1.
        // At the end of the update, we should explicitly select slot 1,
        // by writing 0x1 to FW_SLOT_INFO, to make sure the module is
        // running on the latest code.
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: Switch to slot 1");
        l_err = nvdimmWriteReg(iv_dimm, FW_SLOT_INFO, 0x01);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage:  "
                "Unable to switch to slot 1 for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // Reset controller to activate new firmware
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: resetController");
        l_err = nvdimmResetController(iv_dimm);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage:  "
                "Unable to activate new firmware for 0x%.8X nvdimm",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // force a recollect of the version of code installed
        TRACUCOMP(g_trac_nvdimm_upd, "updateImage: verify new code version running");
        uint16_t new_version = INVALID_VERSION;
        l_err = getVersion(new_version, true);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage: "
                "Unable to verify NVDIMM 0x%.8X was successfully updated",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        else
        {
            TRACFCOMP(g_trac_nvdimm_upd, "updateImage: NVDIMM 0x%.8X of type "
                "0x%04X%04X now running new code level 0x%04X",
                TARGETING::get_huid(iv_dimm),
                le16toh(iv_manufacturer_id), le16toh(iv_product_id),
                le16toh(new_version));

        }

    } while (0);

    // If update operation is aborted, we need to disable update mode
    if (l_fw_update_mode_enabled)
    {
        TRACFCOMP(g_trac_nvdimm_upd, "updateImage: update was aborted, so disable FW_UPDATE_MODE");
        errlHndl_t l_err2 = changeFwUpdateMode(FW_UPDATE_MODE_DISABLED);
        if (l_err2)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "updateImage: "
                "Attempt to disable Firmware Update Mode of 0x%.8X failed,"
                " RC=0x%X", TARGETING::get_huid(iv_dimm),
                ERRL_GETRC_SAFE(l_err2));

            // Should always have an error here, so link the two errors together
            // Just a safety-check so we don't dereference a nullptr
            if (l_err)
            {
                l_err2->plid(l_err->plid());
                l_err2->collectTrace(NVDIMM_COMP_NAME, 256);
                l_err2->collectTrace(NVDIMM_UPD, 256);
                errlCommit(l_err2, NVDIMM_COMP_ID);
            }
            else
            {
                // this path shouldn't get run
                l_err = l_err2;
            }
        }
    }

    return l_err;
}


// HELPER FUNCTIONS FOR UPDATE
errlHndl_t NvdimmInstalledImage::updateImageData(NvdimmLidImage * i_lidImage)
{
    errlHndl_t l_err = nullptr;
    do
    {
        uint8_t blocks_per_region;
        l_err = getBlocksPerRegion(blocks_per_region);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                "getBlocksPerRegion() failed on NVDIMM 0x%.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // calculate the region size which equals block size * blocks per region
        uint16_t region_size = BYTES_PER_BLOCK * blocks_per_region;
        const uint8_t * fw_img_data =
            reinterpret_cast<const uint8_t*>(i_lidImage->getFlashImage());
        size_t fw_img_data_len = i_lidImage->getFlashImageSize();

        // Get the number of regions required for the amount of data.
        // This sets the upper bound for the REGION_ID
        uint16_t fw_img_total_regions = fw_img_data_len/region_size;
        if (fw_img_data_len % region_size > 0)
        {
            // account for a partial region
            fw_img_total_regions++;
        }
        if (fw_img_total_regions == 0)
        {
            /*
             *@errortype
             *@moduleid         UPDATE_IMAGE_DATA
             *@reasoncode       NVDIMM_ZERO_TOTAL_REGIONS
             *@userdata1        NVDIMM Target Huid
             *@userdata2[0:15]  Firmware image size
             *@userdata2[16:31] region_size
             *@devdesc          Firmware image size is not large enough
             *                  (needs to be at least region_size)
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry(
                                   ERRORLOG::ERRL_SEV_PREDICTIVE,
                                   UPDATE_IMAGE_DATA,
                                   NVDIMM_ZERO_TOTAL_REGIONS,
                                   TARGETING::get_huid(iv_dimm),
                                   TWO_UINT16_ONE_UINT32_TO_UINT64(
                                      fw_img_data_len,
                                      region_size,
                                      0x00000000),
                                   ERRORLOG::ErrlEntry::ADD_SW_CALLOUT );
            l_err->collectTrace( NVDIMM_COMP_NAME, 256 );
            break;
        }

        // 10.a Write the BLOCK_ID, REGION_ID0 and REGION_ID1 registers
        //      with the appropriate value starting at 0
        TRACUCOMP(g_trac_nvdimm_upd,
            "updateImage: Sending %d total regions of size %d bytes (total size: 0x%08X)",
            fw_img_total_regions, region_size, fw_img_data_len);
        l_err = nvdimmWriteReg(iv_dimm, REGION_ID0, 0x00);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                "Write of 0x00 to REGION_ID0 failed on NVDIMM 0x%.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }
        l_err = nvdimmWriteReg(iv_dimm, REGION_ID1, 0x00);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                "Write of 0x00 to REGION_ID1 failed on NVDIMM 0x%.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        uint16_t region = 0;
        while (region < fw_img_total_regions)
        {
            if (region % 100 == 0)
            {
                TRACFCOMP(g_trac_nvdimm_upd,
                    "updateImage: progress code for sending region %d",
                    region);
                INITSERVICE::sendProgressCode();
            }
            TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.a - region 0x%04X",
                region);
            // For each region, start with BLOCK_ID of 0. BLOCK_ID
            // is controlled in byteRegionBlockTransfer().
            l_err = nvdimmWriteReg(iv_dimm, BLOCK_ID, 0x00);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Write of 0x00 to BLOCK_ID failed on NVDIMM 0x%.8X",
                    TARGETING::get_huid(iv_dimm));
                break;
            }

            // Update REGION_ID0(lsb) and REGION_ID1(msb)
            uint8_t l_data = region & 0x00FF;
            l_err = nvdimmWriteReg(iv_dimm, REGION_ID0, l_data);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Write of 0x%02X to REGION_ID0 failed on NVDIMM 0x%.8X",
                    l_data, TARGETING::get_huid(iv_dimm));
                break;
            }
            l_data = (((region & 0xFF00) >> 8) & 0x00FF);
            l_err = nvdimmWriteReg(iv_dimm, REGION_ID1, l_data);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d write of 0x%02X to REGION_ID1 failed on NVDIMM "
                    "0x%.8X", region, l_data, TARGETING::get_huid(iv_dimm));
                break;
            }

            // 10.b Clear the firmware data block to ensure there is no
            //      residual data.
            TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.b");
            l_err = clearFwDataBlock();
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d: clearFwDataBlock() failed on NVDIMM 0x%.8X",
                    region, TARGETING::get_huid(iv_dimm));
                break;
            }

            // 10.c Send the data over to nvdimm region by region.
            // Check if the remaining data is in the multiple of the region size
            // If not, have the function to calculate the actual amount of data
            // to send over to the nvdimm
            const uint8_t * pImageData = &(fw_img_data[(region*region_size)]);
            uint16_t data_len = region_size;
            if ((fw_img_data_len-(region*region_size)) < region_size)
            {
                // send a final partial region
                data_len = fw_img_data_len-(region*region_size);
                TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.c - send partial region (%d length)", data_len);
                l_err = byteRegionBlockTransfer(pImageData, data_len, false);
            }
            else
            {
                // send a full region worth of data
                TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.c - send full region (%d length)", data_len);
                l_err = byteRegionBlockTransfer(pImageData, data_len, true);
            }
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d: byteRegionBlockTransfer() failed on NVDIMM 0x%.8X",
                    region, TARGETING::get_huid(iv_dimm));
                break;
            }

            // 10.d-e After transferring each region, validate the transfer by checksum
            TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.d-e");
            uint16_t hostCksm = crc16(pImageData, data_len);
            l_err = clearFwOpsStatus();
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d: clearFwOpsStatus() failed on NVDIMM 0x%.8X",
                    region, TARGETING::get_huid(iv_dimm));
                break;
            }
            uint16_t nvCksm;
            l_err = calcAndGetCksm(nvCksm);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d: calcAndGetCksm() failed on NVDIMM 0x%.8X",
                    region, TARGETING::get_huid(iv_dimm));
                break;
            }
            if (hostCksm != nvCksm)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d of NVDIMM 0x%.8X: data checksums mismatch "
                    "(calc host: 0x%X and nv: 0x%X)",
                    region, TARGETING::get_huid(iv_dimm), hostCksm, nvCksm);

                /*
                 *@errortype
                 *@moduleid         UPDATE_IMAGE_DATA
                 *@reasoncode       NVDIMM_CHECKSUM_ERROR
                 *@userdata1        NVDIMM Target Huid
                 *@userdata2[0:15]  Host checksum calculated
                 *@userdata2[16:31] NV checksum returned
                 *@userdata2[32:47] size of data for checksum
                 *@userdata2[48:63] region
                 *@devdesc          Checksum failure when transferring region
                 *@custdesc         NVDIMM not updated
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                       ERRORLOG::ERRL_SEV_PREDICTIVE,
                                       UPDATE_IMAGE_DATA,
                                       NVDIMM_CHECKSUM_ERROR,
                                       TARGETING::get_huid(iv_dimm),
                                       FOUR_UINT16_TO_UINT64(
                                          hostCksm, nvCksm,
                                          region, data_len),
                                       ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                l_err->collectTrace( NVDIMM_COMP_NAME, 256 );
                l_err->addPartCallout( iv_dimm,
                                       HWAS::NV_CONTROLLER_PART_TYPE,
                                       HWAS::SRCI_PRIORITY_HIGH );
                l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                            HWAS::SRCI_PRIORITY_LOW );

                break;
            }

            // 10.f Commit the firmware data region transferred
            TRACUCOMP(g_trac_nvdimm_upd, "updateImage: step 10.f");
            l_err = commitFwRegion();
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"updateImageData: "
                    "Region %d: commitFwRegion() failed on NVDIMM 0x%.8X",
                    region, TARGETING::get_huid(iv_dimm));
                break;
            }
            region++;
        } // End of FW image data transfer
    } while (0);

    return l_err;
}

errlHndl_t NvdimmInstalledImage::changeFwUpdateMode(fw_update_mode i_mode)
{
    errlHndl_t l_err = nullptr;

    l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, i_mode);
    if (!l_err)
    {
        // Wait for ops to complete
        l_err = waitFwOpsComplete();
        if (!l_err)
        {
            // if ops completed successfully, check the status
            // to make sure that FW update mode has been enabled/disabled
            fw_ops_status_t opStatus;
            l_err = nvdimmReadReg(iv_dimm, FIRMWARE_OPS_STATUS, opStatus.whole);
            if (!l_err)
            {
                // Create an error if the mode was NOT set correctly
                if (!(((i_mode == FW_UPDATE_MODE_ENABLED) &&
                       (opStatus.fw_ops_update_mode == 1)) ||
                      ((i_mode == FW_UPDATE_MODE_DISABLED) &&
                       (opStatus.fw_ops_update_mode == 0))) )
                {
                    /*
                     *@errortype
                     *@moduleid         CHANGE_FW_UPDATE_MODE
                     *@reasoncode       NVDIMM_UPDATE_MODE_UNCHANGED
                     *@userdata1        NVDIMM Target Huid
                     *@userdata2[0:7]   Mode setting
                     *@userdata2[8:15]  FIRMWARE_OPS_STATUS byte
                     *@devdesc          Firmware Update Mode not updated
                     *@custdesc         NVDIMM not updated
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_PREDICTIVE,
                                           CHANGE_FW_UPDATE_MODE,
                                           NVDIMM_UPDATE_MODE_UNCHANGED,
                                           TARGETING::get_huid(iv_dimm),
                                           FOUR_UINT8_TO_UINT32(
                                              i_mode, opStatus.whole,
                                              0x00, 0x00),
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                    l_err->collectTrace( NVDIMM_COMP_NAME, 256 );
                    l_err->addPartCallout( iv_dimm,
                                           HWAS::NV_CONTROLLER_PART_TYPE,
                                           HWAS::SRCI_PRIORITY_HIGH );
                    l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                                HWAS::SRCI_PRIORITY_LOW );
                }
            }
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::waitFwOpsBlockReceived()
{
    errlHndl_t l_err = nullptr;

    // retry for a total of 100ms
    uint32_t timeout_ms_val = 100;

    bool blockReceived = false;
    fw_ops_status_t opStatus;
    while (1)
    {
        l_err = nvdimmReadReg(iv_dimm, FIRMWARE_OPS_STATUS,
                              opStatus.whole);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"waitFwOpsBlockReceived: "
                "FIRMWARE_OPS_STATUS read failed on NVDIMM 0x%.8X "
                "(timeout: 0x%04X ms of 100 ms)",
                TARGETING::get_huid(iv_dimm), timeout_ms_val);
            break;
        }
        if (!opStatus.fw_ops_block_received)
        {
            // wait 1 millisecond between checking status
            if (timeout_ms_val > 0)
            {
                timeout_ms_val -= 1;
                nanosleep(0, NS_PER_MSEC);
            }
            else
            {
                // timeout hit
                break;
            }
        }
        else
        {
            // block received
            blockReceived = true;
            break;
        }
    }

    if (!blockReceived && !l_err)
    {
        /*
         *@errortype
         *@moduleid         WAIT_FW_OPS_BLOCK_RECEIVED
         *@reasoncode       NVDIMM_BLOCK_NOT_RECEIVED
         *@userdata1        NVDIMM Target Huid
         *@userdata2[0:15]  Last FIRMWARE_OPS_STATUS read
         *@userdata2[16:31] Timeout (msecs)
         *@devdesc          Firmware Operation timed out waiting for
         *                  data block transfer confirmation
         *@custdesc         NVDIMM not updated
         */
        l_err = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_PREDICTIVE,
                               WAIT_FW_OPS_BLOCK_RECEIVED,
                               NVDIMM_FW_OPS_IN_PROGRESS_TIMEOUT,
                               TARGETING::get_huid(iv_dimm),
                               TWO_UINT16_ONE_UINT32_TO_UINT64
                               (
                                  TWO_UINT8_TO_UINT16( 0x00,
                                                  opStatus.whole),
                                  100,
                                  timeout_ms_val
                               ),
                               ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
        l_err->collectTrace(NVDIMM_COMP_NAME, 512 );
        l_err->addPartCallout( iv_dimm,
                               HWAS::NV_CONTROLLER_PART_TYPE,
                               HWAS::SRCI_PRIORITY_HIGH );
        l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                    HWAS::SRCI_PRIORITY_LOW );
    }

    return l_err;
}


errlHndl_t NvdimmInstalledImage::waitFwOpsComplete()
{
    errlHndl_t l_err = nullptr;

    uint16_t timeout_val = INVALID_TIMEOUT;
    l_err = getFwOpsTimeout(timeout_val);
    uint32_t timeout_ms_val = timeout_val * 1000;
    if (!l_err)
    {
        TRACUCOMP(g_trac_nvdimm_upd, "waitFwOpsComplete: timeout_val %d seconds", timeout_val);
        bool opsComplete = false;
        nvdimm_cmd_status0_t cmdStatus;
        while (1)
        {
            l_err = nvdimmReadReg(iv_dimm, NVDIMM_CMD_STATUS0, cmdStatus.whole);
            if (l_err)
            {
                break;
            }
            if (cmdStatus.firmware_ops_in_progress)
            {
                // wait 1 millisecond between checking status
                if (timeout_ms_val > 0)
                {
                    timeout_ms_val -= 1;
                    nanosleep(0, NS_PER_MSEC);
                }
                else
                {
                    // timeout hit
                    break;
                }
            }
            else
            {
                // ops completed
                opsComplete = true;
                break;
            }
        }

        if (!opsComplete && !l_err)
        {
            /*
             *@errortype
             *@moduleid         WAIT_FW_OPS_COMPLETE
             *@reasoncode       NVDIMM_FW_OPS_IN_PROGRESS_TIMEOUT
             *@userdata1        NVDIMM Target Huid
             *@userdata2[0:15]  Last NVDIMM_CMD_STATUS0 read
             *@userdata2[16:31] Timeout (seconds)
             *@devdesc          Firmware Operation timed out
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry(
                                   ERRORLOG::ERRL_SEV_PREDICTIVE,
                                   WAIT_FW_OPS_COMPLETE,
                                   NVDIMM_FW_OPS_IN_PROGRESS_TIMEOUT,
                                   TARGETING::get_huid(iv_dimm),
                                   TWO_UINT16_ONE_UINT32_TO_UINT64
                                   (
                                      TWO_UINT8_TO_UINT16( 0x00,
                                                      cmdStatus.whole),
                                      iv_timeout,
                                      timeout_ms_val
                                   ),
                                   ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
            l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
            l_err->addPartCallout( iv_dimm,
                                   HWAS::NV_CONTROLLER_PART_TYPE,
                                   HWAS::SRCI_PRIORITY_HIGH );
            l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                        HWAS::SRCI_PRIORITY_LOW );
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::getFwOpsTimeout(uint16_t & o_timeout)
{
    errlHndl_t l_err = nullptr;

    do {
        // Grab the timeout value once and reuse
        if (iv_timeout == INVALID_TIMEOUT)
        {
            uint8_t lsb;
            uint8_t msb;
            l_err = nvdimmReadReg(iv_dimm, FIRMWARE_OPS_TIMEOUT0, lsb);
            if (l_err)
            {
                break;
            }
            l_err = nvdimmReadReg(iv_dimm, FIRMWARE_OPS_TIMEOUT1, msb);
            if (l_err)
            {
                break;
            }

            // Look for whether this is in milliseconds or seconds
            if (msb < 0x80)
            {
                // convert time value for milliseconds to seconds
                iv_timeout = ((msb << 8) | lsb)/1000;
            }
            else
            {
                // timeout value is in seconds (remove the indicator bit)
                iv_timeout = (((msb - 0x80) << 8) | lsb);
            }
            TRACUCOMP(g_trac_nvdimm_upd,"getFwOpsTimeout: msb:0x%02X lsb:0x%02X -> 0x%04X",
                msb, lsb, iv_timeout);
        }
        o_timeout = iv_timeout;
    } while (0);

    return l_err;
}

errlHndl_t NvdimmInstalledImage::clearFwOpsStatus()
{
    errlHndl_t l_err = nullptr;
    // NVDIMM_MGT_CMD1:
    // Bit 1 set, the module shall clear all the bits except Bit 2 in
    // the FIRMWARE_OPS_STATUS register
    uint8_t l_data = 0x02;
    l_err = nvdimmWriteReg(iv_dimm, NVDIMM_MGT_CMD1, l_data);
    if (l_err)
    {
        TRACFCOMP(g_trac_nvdimm_upd,ERR_MRK"clearFwOpsStatus: "
            "NVDIMM 0x%.8X clear FIRMWARE_OPS_STATUS register failed",
            TARGETING::get_huid(iv_dimm));
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::isFwOpsSuccess(bool & o_success)
{
    errlHndl_t l_err = nullptr;
    o_success = false;

    fw_ops_status_t l_data;
    l_err = nvdimmReadReg(iv_dimm, FIRMWARE_OPS_STATUS, l_data.whole);
    if (l_err)
    {
        TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"isFwOpsSuccess: "
            "NVDIMM 0x%.8X read FIRMWARE_OPS_STATUS register failed (0x%02X)",
            TARGETING::get_huid(iv_dimm), l_data.whole);
    }
    else
    {
        if (l_data.fw_ops_success)
        {
            o_success = true;
        }
        else
        {
            // add this trace so we know what was returned from FIRMWARE_OP_STATUS read
            TRACFCOMP(g_trac_nvdimm_upd, "isFwOpsSuccess() returning false (0x%02X)",
                l_data.whole);
            o_success = false;
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::getBlocksPerRegion
                                    (uint8_t & io_blocks_per_region)
{
    errlHndl_t l_err = nullptr;

    io_blocks_per_region = iv_max_blocks_per_region;
    if (iv_max_blocks_per_region == INVALID_REGION_BLOCK_SIZE)
    {
        l_err = nvdimmReadReg(iv_dimm, REGION_BLOCK_SIZE, io_blocks_per_region);
        if (!l_err)
        {
            // If no error, update the class variable
            // as this gets called multiple times
            iv_max_blocks_per_region = io_blocks_per_region;
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::byteRegionBlockTransfer(const uint8_t * i_data,
                                                const uint16_t i_data_size,
                                                bool i_use_region_block_size)
{
    errlHndl_t l_err = nullptr;
    uint8_t blocks_per_region = 0x00;
    uint8_t max_blocks_per_region = 0x00;

    do {
        l_err = getBlocksPerRegion(max_blocks_per_region);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"byteRegionBlockTransfer: "
                "getBlocksPerRegion() failed on NVDIMM 0x%.8X",
                TARGETING::get_huid(iv_dimm));
            break;
        }

        // If the data passed in does not equal the region block size,
        // calculate the number of blocks required for the given data
        if (!i_use_region_block_size)
        {
            blocks_per_region = i_data_size/BYTES_PER_BLOCK;
            if (i_data_size % BYTES_PER_BLOCK)
            {
                // Add another block if data can't be evenly broken into
                // BYTES_PER_BLOCK blocks
                blocks_per_region++;
            }
            if (blocks_per_region > max_blocks_per_region)
            {
                /*
                 *@errortype
                 *@moduleid         BYTE_REGION_BLOCK_TRANSFER
                 *@reasoncode       NVDIMM_DATA_SIZE_TOO_LARGE
                 *@userdata1        NVDIMM Target Huid
                 *@userdata2[0:15]  Data size trying to transfer
                 *@userdata2[16:31] Maximum data size allowed
                 *@userdata2[32:47] Calculated blocks_per_region
                 *@userdata2[48-63] Maximum blocks_per_region allowed
                 *@devdesc          Data size too big to transfer in one command
                 *@custdesc         NVDIMM not updated
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                         ERRORLOG::ERRL_SEV_PREDICTIVE,
                                         BYTE_REGION_BLOCK_TRANSFER,
                                         NVDIMM_DATA_SIZE_TOO_LARGE,
                                         TARGETING::get_huid(iv_dimm),
                                         FOUR_UINT16_TO_UINT64(
                                          i_data_size,
                                          max_blocks_per_region*BYTES_PER_BLOCK,
                                          blocks_per_region,
                                          max_blocks_per_region),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT );
                break;
            }
        }
        else
        {
            blocks_per_region = max_blocks_per_region;
        }

        TRACUCOMP(g_trac_nvdimm_upd,"byteRegionBlockTransfer: blocks_per_region = 0x%02X", blocks_per_region);

        if (i_data_size > (BYTES_PER_BLOCK*blocks_per_region))
        {
            /*
             *@errortype
             *@moduleid         BYTE_REGION_BLOCK_TRANSFER
             *@reasoncode       NVDIMM_DATA_SIZE_INVALID
             *@userdata1        NVDIMM Target Huid
             *@userdata2[0:15]  Data size trying to transfer
             *@userdata2[16:31] Calculated maximum data size transfer
             *@userdata2[32:47] Blocks per region
             *@userdata2[48-63] Bytes transferred per block
             *@devdesc          Data size too big to transfer
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry(
                                     ERRORLOG::ERRL_SEV_PREDICTIVE,
                                     BYTE_REGION_BLOCK_TRANSFER,
                                     NVDIMM_DATA_SIZE_INVALID,
                                     TARGETING::get_huid(iv_dimm),
                                     FOUR_UINT16_TO_UINT64(
                                        i_data_size,
                                        BYTES_PER_BLOCK*blocks_per_region,
                                        blocks_per_region,
                                        BYTES_PER_BLOCK),
                                     ERRORLOG::ErrlEntry::ADD_SW_CALLOUT );
            break;
        }

        uint8_t blockNum = 0;
        uint8_t block[BYTES_PER_BLOCK]; // used for partial transfer
        uint8_t * pCurrentBlockData = nullptr;
        while (blockNum < blocks_per_region && (!l_err))
        {
            TRACUCOMP(g_trac_nvdimm_upd,"byteRegionBlockTransfer: block = 0x%02X", blockNum);
            l_err = nvdimmWriteReg(iv_dimm, BLOCK_ID, blockNum);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"byteRegionBlockTransfer: "
                    "Write 0x%02X to BLOCK_ID failed on NVDIMM 0x%.8X",
                    blockNum, TARGETING::get_huid(iv_dimm));
                break;
            }

            // Data must be transferred in multiple of BYTES_PER_BLOCK bytes.
            // If block_data is not BYTES_PER_BLOCK bytes, pad the end with 0s
            if ((i_data_size - BYTES_PER_BLOCK * blockNum) < BYTES_PER_BLOCK)
            {
                // clear entire block of bytes
                memset(block, 0x00, BYTES_PER_BLOCK);

                // add the last partial block of data bytes
                if (i_data_size > (blockNum * BYTES_PER_BLOCK))
                {
                    memcpy(block, &i_data[blockNum * BYTES_PER_BLOCK],
                        (i_data_size - (blockNum * BYTES_PER_BLOCK)));
                }
                pCurrentBlockData = block;
            }
            else
            {
                pCurrentBlockData = const_cast<uint8_t *>(&i_data[blockNum * BYTES_PER_BLOCK]);
            }

            // write out the 32-byte (BYTES_PER_BLOCK) data block
            TRACUCOMP(g_trac_nvdimm_upd,"byteRegionBlockTransfer: write out 32byte block 0x%02X", blockNum);
            l_err = nvdimmOpenPage(iv_dimm, PAGE(TYPED_BLOCK_DATA_BYTE0));
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"byteRegionBlockTransfer: "
                    "Unable to open page for BLOCK %d transfer of NVDIMM "
                    "0x%.8X", blockNum, TARGETING::get_huid(iv_dimm));
            }

            size_t l_numBytes = BYTES_PER_BLOCK;
            uint8_t l_reg_addr = ADDRESS(TYPED_BLOCK_DATA_BYTE0);
            l_err = DeviceFW::deviceOp( DeviceFW::WRITE,
                                        iv_dimm,
                                        pCurrentBlockData,
                                        l_numBytes,
                                        DEVICE_NVDIMM_RAW_ADDRESS(l_reg_addr) );
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"byteRegionBlockTransfer: "
                    "Block %d write to 0x%02X failed on NVDIMM 0x%.8X",
                    blockNum, l_reg_addr, TARGETING::get_huid(iv_dimm));
                break;
            }
            // increment to next block
            pCurrentBlockData += BYTES_PER_BLOCK;

            // After a block has been transferred, verify that the 32-byte block
            // was received by polling FIRMWARE_OPS_STATUS offset for
            // FIRMWARE_BLOCK_RECEIVED.
            TRACUCOMP(g_trac_nvdimm_upd, ">> waitFwOpsBlockReceived");
            l_err = waitFwOpsBlockReceived();
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK"byteRegionBlockTransfer: "
                    "Block %d read of FIRMWARE_OPS_STATUS failed on NVDIMM "
                    " 0x%.8X", blockNum, TARGETING::get_huid(iv_dimm));
                break;
            }

            // block of data successfully sent to NV controller
            TRACUCOMP(g_trac_nvdimm_upd,"byteRegionBlockTransfer: block 0x%02X successfully sent to NV controller", blockNum);
            blockNum++;
        }

    } while (0);

    return l_err;
} // end byteRegionBlockTransfer()

errlHndl_t NvdimmInstalledImage::calcAndGetCksm(uint16_t & o_nvCksm)
{
    errlHndl_t l_err = nullptr;

    // Command the module to calculate the checksum
    fw_ops_cmd_t opsCmd;
    opsCmd.whole = 0x00;
    opsCmd.start_generate_fw_checksum_op = 1;
    l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, opsCmd.whole);
    if (!l_err)
    {
        l_err = waitFwOpsComplete();
        if (!l_err)
        {
            bool opSuccessful = false;
            l_err = isFwOpsSuccess(opSuccessful);
            if (!l_err && opSuccessful)
            {
                uint8_t lsb, msb;
                l_err = nvdimmReadReg(iv_dimm, FW_REGION_CRC0, lsb);
                if (!l_err)
                {
                    l_err = nvdimmReadReg(iv_dimm, FW_REGION_CRC1, msb);
                    if (!l_err)
                    {
                        o_nvCksm = (msb << 8) | lsb;
                    }
                }
            }
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::validateFwHeader()
{
    errlHndl_t l_err = nullptr;

    l_err = clearFwOpsStatus();
    if (!l_err)
    {
        fw_ops_cmd_t opsCmd;
        opsCmd.whole = 0x00;
        opsCmd.start_validate_fw_header_op = 1;

        l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, opsCmd.whole);
        if (!l_err)
        {
            l_err = waitFwOpsComplete();
            if (!l_err)
            {
                bool opsSuccessful = false;
                l_err = isFwOpsSuccess(opsSuccessful);
                if (!l_err && !opsSuccessful)
                {
                    /*
                     *@errortype
                     *@moduleid         VALIDATE_FW_HEADER
                     *@reasoncode       NVDIMM_FW_OPS_NOT_SUCCESSFUL
                     *@userdata1        NVDIMM Target Huid
                     *@userdata2        Operation command being verified
                     *@devdesc          Firmware Operation not successful
                     *@custdesc         NVDIMM not updated
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_PREDICTIVE,
                                           VALIDATE_FW_HEADER,
                                           NVDIMM_FW_OPS_NOT_SUCCESSFUL,
                                           TARGETING::get_huid(iv_dimm),
                                           opsCmd.whole,
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                    l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
                    l_err->addPartCallout( iv_dimm,
                                           HWAS::NV_CONTROLLER_PART_TYPE,
                                           HWAS::SRCI_PRIORITY_HIGH );
                    l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                                HWAS::SRCI_PRIORITY_LOW );
                }
            }
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::commitFwRegion()
{
    errlHndl_t l_err = nullptr;

    l_err = clearFwOpsStatus();
    if (!l_err)
    {
        fw_ops_cmd_t opsCmd;
        opsCmd.whole = 0x00;
        opsCmd.start_commit_fw_op = 1;
        l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, opsCmd.whole);
        if (!l_err)
        {
            l_err = waitFwOpsComplete();
            if (!l_err)
            {
                bool opsSuccessful = false;
                l_err = isFwOpsSuccess(opsSuccessful);
                if (!l_err && !opsSuccessful)
                {
                    /*
                     *@errortype
                     *@moduleid         COMMIT_FW_REGION
                     *@reasoncode       NVDIMM_FW_OPS_NOT_SUCCESSFUL
                     *@userdata1        NVDIMM Target Huid
                     *@userdata2        Operation command being verified
                     *@devdesc          Firmware Operation not successful
                     *@custdesc         NVDIMM not updated
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_PREDICTIVE,
                                           COMMIT_FW_REGION,
                                           NVDIMM_FW_OPS_NOT_SUCCESSFUL,
                                           TARGETING::get_huid(iv_dimm),
                                           opsCmd.whole,
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                    l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
                    l_err->addPartCallout( iv_dimm,
                                           HWAS::NV_CONTROLLER_PART_TYPE,
                                           HWAS::SRCI_PRIORITY_HIGH );
                    l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                                HWAS::SRCI_PRIORITY_LOW );
                }
            }
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::clearFwDataBlock()
{
    errlHndl_t l_err = nullptr;

    // clearFwOps
    fw_ops_cmd_t opsCmd;
    opsCmd.whole = 0x00;
    opsCmd.start_clear_fw_op = 1;
    TRACUCOMP(g_trac_nvdimm_upd, "clearFwDataBlock: clearFwOps cmd 0x%02X", opsCmd.whole);
    l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, opsCmd.whole);
    if (!l_err)
    {
        TRACUCOMP(g_trac_nvdimm_upd, "clearFwDataBlock: start waitFwOpsComplete");
        l_err = waitFwOpsComplete();
        if (!l_err)
        {
            bool ops_success = false;
            TRACUCOMP(g_trac_nvdimm_upd, "clearFwDataBlock: done waiting now check FwOpsStatus for success");
            l_err = isFwOpsSuccess(ops_success);
            if (!l_err && !ops_success)
            {
                /*
                 *@errortype
                 *@moduleid         CLEAR_FW_DATA_BLOCK
                 *@reasoncode       NVDIMM_FW_OPS_NOT_SUCCESSFUL
                 *@userdata1        NVDIMM Target Huid
                 *@userdata2        Operation command being verified
                 *@devdesc          Firmware Operation not successful
                 *@custdesc         NVDIMM not updated
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                       ERRORLOG::ERRL_SEV_PREDICTIVE,
                                       CLEAR_FW_DATA_BLOCK,
                                       NVDIMM_FW_OPS_NOT_SUCCESSFUL,
                                       TARGETING::get_huid(iv_dimm),
                                       opsCmd.whole,
                                       ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
                l_err->addPartCallout( iv_dimm,
                                       HWAS::NV_CONTROLLER_PART_TYPE,
                                       HWAS::SRCI_PRIORITY_HIGH );
                l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                            HWAS::SRCI_PRIORITY_LOW );
            }
        }
    }
    return l_err;
}

errlHndl_t NvdimmInstalledImage::validateFwImage()
{
    errlHndl_t l_err = nullptr;

    l_err = clearFwOpsStatus();
    if (!l_err)
    {
        fw_ops_cmd_t opsCmd;
        opsCmd.whole = 0x00;
        opsCmd.start_validate_fw_image_op = 1;
        l_err = nvdimmWriteReg(iv_dimm, FIRMWARE_OPS_CMD, opsCmd.whole);
        if (!l_err)
        {
            l_err = waitFwOpsComplete();
            if (!l_err)
            {
                bool opsSuccessful = false;
                l_err = isFwOpsSuccess(opsSuccessful);
                // create an error if operation not successful
                if (!l_err && !opsSuccessful)
                {
                    /*
                     *@errortype
                     *@moduleid         VALIDATE_FW_IMAGE
                     *@reasoncode       NVDIMM_FW_OPS_NOT_SUCCESSFUL
                     *@userdata1        NVDIMM Target Huid
                     *@userdata2        Operation command being verified
                     *@devdesc          Firmware Operation not successful
                     *@custdesc         NVDIMM not updated
                     */
                    l_err = new ERRORLOG::ErrlEntry(
                                           ERRORLOG::ERRL_SEV_PREDICTIVE,
                                           VALIDATE_FW_IMAGE,
                                           NVDIMM_FW_OPS_NOT_SUCCESSFUL,
                                           TARGETING::get_huid(iv_dimm),
                                           opsCmd.whole,
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                    l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
                    l_err->addPartCallout( iv_dimm,
                                           HWAS::NV_CONTROLLER_PART_TYPE,
                                           HWAS::SRCI_PRIORITY_HIGH );
                    l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                                HWAS::SRCI_PRIORITY_LOW );

                }
            }
        }
    }
    return l_err;
}

uint16_t NvdimmInstalledImage::crc16(const uint8_t * i_data, int i_data_size)
{
    // From JEDEC JESD245B.01 document
    // https://www.jedec.org/standards-documents/docs/jesd245a
    int i, crc;
    crc = 0;
    while (--i_data_size >= 0)
    {
        crc = crc ^ (int)*i_data++ << 8;
        for (i = 0; i < 8; ++i)
        {
           if (crc & 0x8000)
           {
               crc = crc << 1 ^ 0x1021;
           }
           else
           {
               crc = crc << 1;
           }
        }
    }
    return (crc & 0xFFFF);
}

///////////////////////////////////////////////////////////////////////////////
// NVDIMMS Update Functions
///////////////////////////////////////////////////////////////////////////////
NvdimmsUpdate::NvdimmsUpdate(TARGETING::TargetHandleList i_nvdimmList)
{
    iv_nvdimmList = i_nvdimmList;
}

bool NvdimmsUpdate::runUpdateUsingLid(NvdimmLidImage * i_lidImage,
                                std::vector<NvdimmInstalledImage *> &i_list)
{
    bool o_no_error_found = true;

    errlHndl_t l_err = nullptr;
    for (auto pInstalledImage : i_list)
    {
        INITSERVICE::sendProgressCode();
        bool updateNeeded = false;
        l_err = isUpdateNeeded(updateNeeded, i_lidImage, pInstalledImage);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "NvdimmsUpdate::runUpdateUsingLid()"
                " Unable to determine if nvdimm[%X] needs NV controller update."
                " RC=0x%X, PLID=0x%.8X",
                TARGETING::get_huid(pInstalledImage->getNvdimmTarget()),
                ERRL_GETRC_SAFE(l_err), ERRL_GETPLID_SAFE(l_err));
            commitPredictiveNvdimmError(l_err);
            o_no_error_found = false;
            continue;
        }
        else if (updateNeeded)
        {
            // shared trace variables
            const TARGETING::Target * l_nvdimm = pInstalledImage->getNvdimmTarget();
            uint64_t l_nvdimm_huid = TARGETING::get_huid(l_nvdimm);

            uint32_t l_installed_type = INVALID_TYPE;
            l_err = pInstalledImage->getType(l_installed_type);
            if (l_err)
            {
                // Continue updating other dimms
                TRACFCOMP(g_trac_nvdimm_upd,
                    ERR_MRK"NvdimmsUpdate::runUpdateUsingLid() - "
                    "Unable to get nvdimm[0x%.8X] installed image type. "
                    "RC=0x%X, PLID=0x%.8X", l_nvdimm_huid,
                    ERRL_GETRC_SAFE(l_err), ERRL_GETPLID_SAFE(l_err));
                commitPredictiveNvdimmError(l_err);
                l_err = nullptr;
            }

            uint16_t l_oldVersion = INVALID_VERSION;
            l_err = pInstalledImage->getVersion(l_oldVersion);
            if (l_err)
            {
                // This shouldn't happen as getVersion should return a
                // cached version
                TRACFCOMP(g_trac_nvdimm_upd,
                    ERR_MRK"NvdimmsUpdate::runUpdateUsingLid() - "
                    "Failed to find current NVDIMM level of %.8X. "
                    "RC=0x%X, PLID=0x%.8X", l_nvdimm_huid,
                    ERRL_GETRC_SAFE(l_err), ERRL_GETPLID_SAFE(l_err));
                commitPredictiveNvdimmError(l_err);
                l_err = nullptr;
                o_no_error_found = false;
                continue;
            }

            // perform update for this DIMM with the current LID image
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdateUsingLid() - "
                "now update nvdimm[0x%.8X]", l_nvdimm_huid);

            TRACFCOMP(g_trac_nvdimm_upd,"Updating with flash size: 0x%08X",
                i_lidImage->getFlashImageSize());

            /*
             *@errortype        INFORMATIONAL
             *@reasoncode       NVDIMM_START_UPDATE
             *@moduleid         NVDIMM_RUN_UPDATE_USING_LID
             *@userdata1        NVDIMM Target Huid
             *@userdata2[0:15]  Old level (current)
             *@userdata2[16:31] Update image level (new)
             *@userdata2[32:63] Installed type (manufacturer and product)
             *@devdesc          Start of the NVDIMM update of this controller
             *@custdesc         NVDIMM update started
             */
            l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                       NVDIMM_RUN_UPDATE_USING_LID,
                                       NVDIMM_START_UPDATE,
                                       l_nvdimm_huid,
                                       TWO_UINT16_ONE_UINT32_TO_UINT64(
                                       l_oldVersion, i_lidImage->getVersion(),
                                       l_installed_type),
                                       ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
            l_err->collectTrace(NVDIMM_UPD, 256);
            ERRORLOG::errlCommit(l_err, NVDIMM_COMP_ID);
            l_err = nullptr;

            l_err = pInstalledImage->updateImage(i_lidImage);
            if (l_err)
            {
                // If update fails, the NV controller will run on its factory
                // installed version in slot 0.
                // We will call out the failed NVDIMM for replacement, but try
                // to keep running with as much function as possible.
                TRACFCOMP(g_trac_nvdimm_upd,
                    ERR_MRK"NvdimmsUpdate::runUpdateUsingLid() - "
                    "NVDIMM 0x%.8X NV controller update failed. "
                    "RC=0x%X, PLID=0x%.8X", l_nvdimm_huid,
                    ERRL_GETRC_SAFE(l_err), ERRL_GETPLID_SAFE(l_err));
                commitPredictiveNvdimmError(l_err);
                l_err = nullptr;
                o_no_error_found = false;
            }
            else
            {
                // successfully updated this NVDIMM

                // Note: call for version should just return a saved value
                uint16_t curVersion = INVALID_VERSION;
                l_err = pInstalledImage->getVersion(curVersion);
                if (l_err)
                {
                    TRACFCOMP(g_trac_nvdimm_upd,
                        ERR_MRK"NvdimmsUpdate::runUpdateUsingLid() - "
                        "Failed to find current NVDIMM level of %.8X after "
                        "successful update. RC=0x%X, PLID=0x%.8X",
                        l_nvdimm_huid,
                        ERRL_GETRC_SAFE(l_err), ERRL_GETPLID_SAFE(l_err));
                    commitPredictiveNvdimmError(l_err);
                    l_err = nullptr;
                }

                /*
                 *@errortype        INFORMATIONAL
                 *@reasoncode       NVDIMM_UPDATE_COMPLETE
                 *@moduleid         NVDIMM_RUN_UPDATE_USING_LID
                 *@userdata1        NVDIMM Target Huid
                 *@userdata2[0:15]  Previous level
                 *@userdata2[16:31] Current updated level
                 *@userdata2[32:63] Installed type (manufacturer and product)
                 *@devdesc          Successful update of NVDIMM code
                 *@custdesc         NVDIMM was successfully updated
                 */
                l_err = new ERRORLOG::ErrlEntry(
                                       ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                       NVDIMM_RUN_UPDATE_USING_LID,
                                       NVDIMM_UPDATE_COMPLETE,
                                       l_nvdimm_huid,
                                       TWO_UINT16_ONE_UINT32_TO_UINT64(
                                       l_oldVersion, curVersion,
                                       l_installed_type),
                                       ERRORLOG::ErrlEntry::ADD_SW_CALLOUT );
                l_err->collectTrace(NVDIMM_UPD, 512);
                ERRORLOG::errlCommit(l_err, NVDIMM_COMP_ID);
            }
        } // end of updateNeeded
    }
    return o_no_error_found;
}

bool NvdimmsUpdate::runUpdate(void)
{
    bool o_no_error_found = true;  // true if no error was found during update

    errlHndl_t l_err = nullptr;

    uint32_t l_installed_type = INVALID_TYPE; // current LID type installed

    // List of each installed NVDIMM type
    std::vector<NvdimmInstalledImage*> v_NVDIMM_16GB_list;
    std::vector<NvdimmInstalledImage*> v_NVDIMM_32GB_list;

    // Build up installed NVDIMM image lists
    for (auto l_nvdimm : iv_nvdimmList)
    {
        NvdimmInstalledImage * l_installed_image =
            new NvdimmInstalledImage(l_nvdimm);
        l_err = l_installed_image->getType(l_installed_type);
        if (l_err)
        {
            // Continue updating other dimms
            TRACFCOMP(g_trac_nvdimm_upd, ERR_MRK "NvdimmsUpdate::runUpdate() - "
                "Unable to get nvdimm[0x%.8X] installed image type. "
                "RC=0x%X, PLID=0x%.8X",
                get_huid(l_nvdimm), ERRL_GETRC_SAFE(l_err),
                ERRL_GETPLID_SAFE(l_err));
            commitPredictiveNvdimmError(l_err);
            o_no_error_found = false;

            // Delete the unused NvdimmInstalledImage pointer
            delete l_installed_image;

            continue;
        }

        if (l_installed_type == SMART_NVDIMM_16GB_TYPE)
        {
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdate() - "
                "0x%.8X NVDIMM is SMART_NVDIMM_16GB_TYPE",
                get_huid(l_nvdimm));
            v_NVDIMM_16GB_list.push_back(l_installed_image);
        }
        else if (l_installed_type == SMART_NVDIMM_32GB_TYPE)
        {
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdate() - "
                "0x%.8X NVDIMM is SMART_NVDIMM_32GB_TYPE",
                get_huid(l_nvdimm));
            v_NVDIMM_32GB_list.push_back(l_installed_image);
        }
        else
        {
            // unknown/unsupported Type
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdate() - unknown "
                "nvdimm[%X] installed type 0x%04X, skipping update",
                TARGETING::get_huid(l_nvdimm), l_installed_type);
            /*
             *@errortype
             *@reasoncode       NVDIMM_UNSUPPORTED_NVDIMM_TYPE
             *@moduleid         NVDIMM_RUN_UPDATE
             *@userdata1[0:31]  Unsupported Type
             *@userdata1[32:63] NVDIMM Target Huid
             *@userdata2[0:31]  Supported nvdimm type
             *@userdata2[32:63] Other supported nvdimm type
             *@devdesc          Unable to update an unsupported NVDIMM type
             *@custdesc         NVDIMM not updated
             */
            l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_INFORMATIONAL,
                                           NVDIMM_RUN_UPDATE,
                                           NVDIMM_UNSUPPORTED_NVDIMM_TYPE,
                                           TWO_UINT32_TO_UINT64(
                                              l_installed_type,
                                              TARGETING::get_huid(l_nvdimm)),
                                           TWO_UINT32_TO_UINT64(
                                              SMART_NVDIMM_16GB_TYPE,
                                              SMART_NVDIMM_32GB_TYPE),
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
            l_err->collectTrace(NVDIMM_COMP_NAME, 256 );
            l_err->collectTrace(NVDIMM_UPD, 256);
            l_err->addPartCallout( l_nvdimm,
                                   HWAS::NV_CONTROLLER_PART_TYPE,
                                   HWAS::SRCI_PRIORITY_HIGH );
            l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                        HWAS::SRCI_PRIORITY_LOW );
            ERRORLOG::errlCommit(l_err, NVDIMM_COMP_ID);

            // Delete the unused NvdimmInstalledImage object
            delete l_installed_image;

            continue;
        }
    }

    do {
        // First check that updatable NVDIMMs exist on the system
        if ((v_NVDIMM_16GB_list.size() == 0) &&
            (v_NVDIMM_32GB_list.size() == 0))
        {
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdate() - "
                "No updatable NVDIMMs present on the system");
            break;
        }

        if (INITSERVICE::spBaseServicesEnabled())
        {
            // Load the NVDIMM flash binary via the MCL in load-only mode
            MCL::MasterContainerLidMgr mclManager(true);
            MCL::CompInfo info;
            l_err = mclManager.processSingleComponent(MCL::g_NvdimmCompId,info);
            if(l_err)
            {
                TRACFCOMP(g_trac_nvdimm, ERR_MRK "NvdimmsUpdate::runUpdate() - "
                    "unable to obtain NVDIMM lid images - ");
                commitPredictiveNvdimmError(l_err);
                o_no_error_found = false;
                break;
            }

            for(const auto& lid : info.lidIds)
            {
                TRACFCOMP(g_trac_nvdimm,"LID ID=0x%08X, size=%d, vAddr=%p",
                    lid.id, lid.size, lid.vAddr);

                if (lid.id == NVDIMM_16GB_LIDID)
                {
                    if (v_NVDIMM_16GB_list.size() > 0)
                    {
                        // Grab the 16GB lid
                        TRACFCOMP(g_trac_nvdimm,
                            "Check/update %d 16GB_TYPE NVDIMMs",
                            v_NVDIMM_16GB_list.size());
                        NvdimmLidImage lidImage(lid.vAddr, lid.size);
                        o_no_error_found &= runUpdateUsingLid(&lidImage,
                                                            v_NVDIMM_16GB_list);
                    }
                }
                else if (lid.id == NVDIMM_32GB_LIDID)
                {
                    if (v_NVDIMM_32GB_list.size() > 0)
                    {
                        // Grab the 32GB lid
                        TRACFCOMP(g_trac_nvdimm,
                            "Check/update %d 32GB_TYPE NVDIMMs",
                            v_NVDIMM_32GB_list.size());
                        NvdimmLidImage lidImage(lid.vAddr, lid.size);
                        o_no_error_found &= runUpdateUsingLid(&lidImage,
                                                            v_NVDIMM_32GB_list);
                    }
                }
                else if ((  lid.id == NVDIMM_32GB_BPM_FW_LIDID)
                        || (lid.id == NVDIMM_32GB_BPM_CONFIG_LIDID))
                {
                    TRACFCOMP(g_trac_nvdimm,
                              "Check/Update %d 32GB_TYPE NVDIMMs' BPM",
                              v_NVDIMM_32GB_list.size());
                    //@TODO RTC 212448 Add calls into bpm_update.C code.
                }
                else if ((  lid.id == NVDIMM_16GB_BPM_FW_LIDID)
                        || (lid.id == NVDIMM_16GB_BPM_CONFIG_LIDID))
                {
                    TRACFCOMP(g_trac_nvdimm,
                              "Check/Update %d 16GB_TYPE NVDIMMs' BPM",
                              v_NVDIMM_16GB_list.size());
                    //@TODO RTC 212448 Add calls into bpm_update.C code.
                }
                else if (lid.id != NVDIMM_SIGNATURE_LIDID)
                {
                    TRACFCOMP(g_trac_nvdimm, "NvdimmsUpdate::runUpdate() - "
                        "Unknown NVDIMM LID: ID=0x%08X, size=%d",
                        lid.id, lid.size);
                    TRACFBIN(g_trac_nvdimm, "Unknown LID", lid.vAddr, 64);
                }
            }

            // @TODO RTC 212448 Add call to perform BPM updates
            // Destructor automatically unloads the NVDIMM flash binary
        }
        else
        {
            TRACFCOMP(g_trac_nvdimm_upd, "NvdimmsUpdate::runUpdate() -  "
                "spBaseServices not running, therefore NVDIMM LID images "
                "cannot be accessed");
            // potential openpower support in future, so don't throw an error
            break;
        }
    } while (0); // end of flash update section

    // Clean up the pointers used in v_NVDIMM_16GB_list and v_NVDIMM_32GB_list
    for (const auto& pInstalledImage : v_NVDIMM_16GB_list)
    {
        delete pInstalledImage;
    }
    for (const auto& pInstalledImage : v_NVDIMM_32GB_list)
    {
        delete pInstalledImage;
    }

    return o_no_error_found;
}

errlHndl_t NvdimmsUpdate::isUpdateNeeded(bool & o_update_needed,
                                   NvdimmLidImage * i_lid_image,
                                   NvdimmInstalledImage * i_cur_image)
{
    o_update_needed = false;  // initialize to false

    errlHndl_t l_err = nullptr;
    uint32_t lidType = INVALID_TYPE;
    uint32_t curType = INVALID_TYPE;

    do {
        const TARGETING::Target * l_dimm = i_cur_image->getNvdimmTarget();

        // check Types match (same manufacturer and product)
        lidType = i_lid_image->getType();
        l_err = i_cur_image->getType(curType);
        if (l_err)
        {
            TRACFCOMP(g_trac_nvdimm_upd,
                "isUpdateNeeded(): failed to find type of NVDIMM[%X]",
                TARGETING::get_huid(l_dimm));
            break;
        }

        if ((lidType == curType) && (lidType != INVALID_TYPE))
        {
            // check that versions do NOT match
            uint16_t curVersion = INVALID_VERSION;
            uint16_t lidVersion = i_lid_image->getVersion();
            l_err = i_cur_image->getVersion(curVersion);
            if (l_err)
            {
                TRACFCOMP(g_trac_nvdimm_upd,
                    "isUpdateNeeded(): failed to find version of NVDIMM[%X]",
                    TARGETING::get_huid(l_dimm));
                break;
            }

            // Put a check here for non-updateable SMART NVDIMMs.
            // Anything before 0x0030 should bypass the update, as update
            // would fail due to a bug in the backlevel firmware on the
            // nvdimm card (exception: 0x0000 = slot blank so allow update)
            if ((curVersion != 0x0000) && (le16toh(curVersion) < 0x0030))
            {
                TRACFCOMP(g_trac_nvdimm_upd,
                    "isUpdateNeeded(): non-updatable SMART NVDIMM 0x%.8X "
                    "(0x%04X)",
                    TARGETING::get_huid(l_dimm), le16toh(curVersion));
                /*
                 *@errortype
                 *@reasoncode       NVDIMM_UPDATE_NOT_SUPPORTED
                 *@moduleid         NVDIMM_IS_UPDATE_NEEDED
                 *@userdata1[0:31]  NVDIMM version level
                 *@userdata1[32:63] NVDIMM Target Huid
                 *@userdata2        NVDIMM type (manufacturer and product)
                 *@devdesc          Unable to update an NVDIMM at this code level
                 *@custdesc         NVDIMM not updated
                 */
                l_err = new ERRORLOG::ErrlEntry( ERRORLOG::ERRL_SEV_PREDICTIVE,
                                           NVDIMM_IS_UPDATE_NEEDED,
                                           NVDIMM_UPDATE_NOT_SUPPORTED,
                                           TWO_UINT32_TO_UINT64(
                                               curVersion,
                                               TARGETING::get_huid(l_dimm)),
                                           curType,
                                           ERRORLOG::ErrlEntry::NO_SW_CALLOUT );
                l_err->collectTrace( NVDIMM_UPD, 256 );
                l_err->addPartCallout( l_dimm,
                                       HWAS::NV_CONTROLLER_PART_TYPE,
                                       HWAS::SRCI_PRIORITY_HIGH );
                l_err->addProcedureCallout( HWAS::EPUB_PRC_HB_CODE,
                                            HWAS::SRCI_PRIORITY_LOW );
                break;
            }

            if (curVersion != lidVersion)
            {
                // verify we are updating with a good version
                if (lidVersion != INVALID_VERSION)
                {
                    // Found mismatched version and a valid lid update version
                    // so an update can proceed
                    o_update_needed = true;

                    TRACFCOMP(g_trac_nvdimm_upd,
                        "NVDIMM[%X] code level - current: 0x%04X, new: 0x%04X",
                        TARGETING::get_huid(l_dimm),
                        le16toh(curVersion), le16toh(lidVersion));
                }
                else
                {
                    TRACFCOMP(g_trac_nvdimm_upd, "NVDIMM[%X] has invalid version",
                        TARGETING::get_huid(l_dimm));
                }
            }
            else
            {
                TRACFCOMP(g_trac_nvdimm_upd,
                    "Keeping current NVDIMM[%X] level: 0x%04X",
                    TARGETING::get_huid(l_dimm), le16toh(curVersion));
            }
        }
    } while (0);

    return l_err;
}

////////////////////////////////////////////////////////////////////////////////
// External function to update the NVDIMMs
////////////////////////////////////////////////////////////////////////////////
bool nvdimm_update(TARGETING::TargetHandleList &i_nvdimmList)
{
    NvdimmsUpdate l_nvdimmsUpdate(i_nvdimmList);
    return l_nvdimmsUpdate.runUpdate();
}

}; // end namespace NVDIMM
OpenPOWER on IntegriCloud