-
Notifications
You must be signed in to change notification settings - Fork 97
/
bpm_update.C
4108 lines (3605 loc) · 146 KB
/
bpm_update.C
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
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/isteps/nvdimm/bpm_update.C $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 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.H"
#include "bpm_update.H"
#include "nvdimm_update.H"
#include <isteps/nvdimm/nvdimm.H>
#include <errl/hberrltypes.H>
#include <errl/errlmanager.H>
#include <endian.h>
#include <sys/time.h>
#include <hbotcompid.H>
#include <trace/interface.H>
#include <initservice/istepdispatcherif.H>
#include <isteps/nvdimm/bpmreasoncodes.H>
#include <hwas/common/hwasCallout.H>
#include <targeting/common/targetservice.H>
#include <attributeenums.H>
namespace NVDIMM
{
namespace BPM
{
trace_desc_t* g_trac_bpm = nullptr;
TRAC_INIT(&g_trac_bpm, BPM_COMP_NAME, 4*KILOBYTE);
// For debug traces
#define TRACUCOMP(args...)
//#define TRACUCOMP(args...) TRACFCOMP(args)
#define TRACUBIN(args...)
//#define TRACUBIN(args...) TRACUBIN(args)
// These constants are kept out of the header file since they aren't relevant
// outside of this file.
const uint16_t BPM_ADDRESS_ZERO = 0;
const uint16_t BPM_CONFIG_START_ADDRESS = 0x1800;
// There are two potential start addresses for the firmware section.
// They are:
const uint16_t MAIN_PROGRAM_ADDRESS = 0x8000;
const uint16_t MAIN_PROGRAM_ADDRESS_ALT = 0xA000;
// In order to disable write protection on the BPM to perform updates a sequence
// of characters must be written. The hex represenation of those characters are
// defined by this constant. The sequence is SMOD
const uint8_t BPM_PASSWORD[] = {0x53, 0x4D, 0x4F, 0x44};
const size_t BPM_PASSWORD_LENGTH = 4;
// These are the segment codes used to dump out a particular config data segment
// on the BPM.
const uint16_t DEFAULT_REG_PAGE = 0x905E;
const uint16_t SEGMENT_A_CODE = 0x9A5E;
const uint16_t SEGMENT_B_CODE = 0x9B5E;
const uint16_t SEGMENT_C_CODE = 0x9C5E;
const uint16_t SEGMENT_D_CODE = 0x9D5E;
// Starting addresses relative to address 0x1800.
// Segments appear in reverse order on BPM.
// Each segment is SEGMENT_SIZE long.
const size_t SEGMENT_D_START_ADDR = 0x000;
const size_t SEGMENT_C_START_ADDR = 0x080;
const size_t SEGMENT_B_START_ADDR = 0x100;
const size_t SEGMENT_A_START_ADDR = 0x180;
const std::map<uint16_t, size_t> segmentMap
{
{SEGMENT_A_CODE, SEGMENT_A_START_ADDR},
{SEGMENT_B_CODE, SEGMENT_B_START_ADDR},
{SEGMENT_C_CODE, SEGMENT_C_START_ADDR},
{SEGMENT_D_CODE, SEGMENT_D_START_ADDR},
};
const uint8_t MAX_RETRY = 3;
/**
* @brief A helper function used in assert statements to verify the correct
* BSP commands were passed into the correct function arguments.
*
* @param[in] i_command The command that will verified to be a BSP command.
*
* @return bool true if i_command is a BSP command.
* false if it's not a BSP command.
*/
bool isBspCommand(const uint8_t i_command)
{
bool result = ((i_command == BPM_PASSTHROUGH) || (i_command == BPM_LOCAL))
? true : false;
return result;
}
/**
* @brief A helper function used in assert statements to verify the correct
* BCL commands were passed into the correct function arguments.
*
* @param[in] i_command The command that will verified to be a BCL command.
*
* @return bool true if i_command is a BCL command.
* false if it's not a BCL command.
*/
bool isBclCommand(const uint8_t i_command)
{
bool result = false;
switch(i_command)
{
case BCL_ENTER_BSL_MODE:
case BCL_IS_BSL_MODE:
case BCL_WRITE_REG:
case BCL_START_UPDATE:
case BCL_END_UPDATE:
case BCL_IS_UPDATE_IN_PROGRESS:
{
result = true;
break;
}
default:
{
result = false;
break;
}
}
return result;
}
/**
* @brief A helper function used in assert statements to verify the correct
* BSL commands were passed into the correct function arguments.
*
* @param[in] i_command The command that will verified to be a BSL command.
*
* @return bool true if i_command is a BSL command.
* false if it's not a BSL command.
*/
bool isBslCommand(const uint8_t i_command)
{
bool result = false;
switch(i_command)
{
case BSL_RX_DATA_BLOCK:
case BSL_RX_PASSWORD:
case BSL_ERASE_SEGMENT:
case BSL_TOGGLE_INFO:
case BSL_ERASE_BLOCK:
case BSL_MASS_ERASE:
case BSL_CRC_CHECK:
case BSL_LOAD_PC:
case BSL_TX_DATA_BLOCK:
case BSL_TX_BSL_VERSION:
case BSL_TX_BUFFER_SIZE:
case BSL_RX_DATA_BLOCK_FAST:
case BSL_RESET_DEVICE:
case BSL_VERIFY_BLOCK:
{
result = true;
break;
}
default:
{
result = false;
break;
}
}
return result;
}
/**
* @brief Helper function to pull out the BPM address offset in the given
* payload.
*
* @param[in] i_payload The payload from which to extract the address
* offset.
*/
uint16_t getPayloadAddressBE(payload_t i_payload)
{
// Get the payload address and convert back to big endian.
uint16_t payloadAddress = (i_payload[PAYLOAD_ADDRESS_START_INDEX])
| (i_payload[PAYLOAD_ADDRESS_START_INDEX + 1] << 8);
return payloadAddress;
}
/**
* @brief Helper function to extract the Segement ID from the segment code.
*
* @param[in] i_segmentCode The Segment code to pull the segment ID from
*
* @return uint8_t The Segment ID (A, B, C, D) as a hex value.
* For example 0xA, 0xB, etc.
*/
uint8_t getSegmentIdentifier(uint16_t i_segmentCode)
{
uint8_t segmentId = (i_segmentCode >> 8) & 0xF;
return segmentId;
}
/**
* @brief Helper function to sleep for longer durations in 5 second increments.
*
* @param[in] i_sleepInSeconds How many seconds to sleep.
*/
void longSleep(uint8_t const i_sleepInSeconds)
{
int iterations = i_sleepInSeconds / 5;
do
{
// Send progress code.
INITSERVICE::sendProgressCode();
// Sleep for 5 seconds
nanosleep(5, 0);
--iterations;
} while (iterations > 0);
}
void runBpmUpdates(bpmList_t * const i_16gb_BPMs,
bpmList_t * const i_32gb_BPMs,
BpmFirmwareLidImage * const i_16gb_fwImage,
BpmFirmwareLidImage * const i_32gb_fwImage,
BpmConfigLidImage * const i_16gb_configImage,
BpmConfigLidImage * const i_32gb_configImage)
{
assert( (i_16gb_BPMs == nullptr)
|| i_16gb_BPMs->empty()
|| ((i_16gb_fwImage != nullptr) && (i_16gb_configImage != nullptr)),
"BPM::runBpmUpdates(): Update images for 16gb BPMs was nullptr and "
"there are 16gb BPMs in the system to may require updates.");
assert( (i_32gb_BPMs == nullptr)
|| i_32gb_BPMs->empty()
|| ((i_32gb_fwImage != nullptr) && (i_32gb_configImage != nullptr)),
"BPM::runBpmUpdates(): Update images for 32gb BPMs was nullptr and "
"there are 32gb BPMs in the system to may require updates.");
errlHndl_t errl = nullptr;
do {
if ( (i_16gb_BPMs != nullptr)
&& (i_16gb_fwImage != nullptr)
&& (i_16gb_configImage != nullptr))
{
TRACFCOMP(g_trac_bpm,
"Check/update %d BPMs on 16GB_TYPE NVDIMMs",
i_16gb_BPMs->size());
for(auto& bpm : *i_16gb_BPMs)
{
errl = bpm.runUpdate(*i_16gb_fwImage, *i_16gb_configImage);
if (errl != nullptr)
{
uint32_t nvdimmHuid = TARGETING::get_huid(bpm.getNvdimm());
if (bpm.attemptAnotherUpdate())
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"An error occurred during a 16GB_TYPE BPM "
"update for NVDIMM 0x%.8X. "
"Try again.",
nvdimmHuid);
delete errl;
errl = bpm.runUpdate(*i_16gb_fwImage,
*i_16gb_configImage);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"Another error occurred while attempting "
"to update the same 16GB_TYPE BPM for "
"NVDIMM 0x%.8X. Commit and move onto the "
"next BPM",
nvdimmHuid);
}
else
{
continue;
}
}
else
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"An error occurred during a 16GB_TYPE BPM "
"update for NVDIMM 0x%.8X. "
"Commit and move onto the next BPM",
nvdimmHuid);
}
ERRORLOG::errlCommit(errl, BPM_COMP_ID);
}
}
}
if ( (i_32gb_BPMs != nullptr)
&& (i_32gb_fwImage != nullptr)
&& (i_32gb_configImage != nullptr))
{
TRACFCOMP(g_trac_bpm,
"Check/update %d BPMs on 32GB_TYPE NVDIMMs",
i_32gb_BPMs->size());
for(auto& bpm : *i_32gb_BPMs)
{
errl = bpm.runUpdate(*i_32gb_fwImage, *i_32gb_configImage);
if (errl != nullptr)
{
uint32_t nvdimmHuid = TARGETING::get_huid(bpm.getNvdimm());
if (bpm.attemptAnotherUpdate())
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"An error occurred during a 32GB_TYPE BPM "
"update for NVDIMM 0x%.8X. "
"Try again.",
nvdimmHuid);
delete errl;
errl = bpm.runUpdate(*i_32gb_fwImage,
*i_32gb_configImage);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"Another error occurred while attempting "
"to update the same 32GB_TYPE BPM for "
"NVDIMM 0x%.8X. Commit and move onto the "
"next BPM",
nvdimmHuid);
}
else
{
continue;
}
}
else
{
TRACFCOMP(g_trac_bpm, ERR_MRK
"An error occurred during a 32GB_TYPE BPM "
"update for NVDIMM 0x%.8X. "
"Commit and move onto the next BPM",
nvdimmHuid);
}
ERRORLOG::errlCommit(errl, BPM_COMP_ID);
}
}
}
} while(0);
}
// =============================================================================
// BpmFirmwareLidImage Class Functions
// =============================================================================
BpmFirmwareLidImage::BpmFirmwareLidImage(void * const i_lidImageAddr,
size_t i_size)
: iv_lidImage(i_lidImageAddr), iv_lidImageSize(i_size)
{
assert(i_lidImageAddr != nullptr,
"BPM::BpmFirmwareLidImage(): Provided LID image must not be nullptr");
}
uint16_t BpmFirmwareLidImage::getVersion() const
{
uint16_t version = INVALID_VERSION;
if (iv_lidImageSize >= sizeof(firmware_image_header_t))
{
const firmware_image_header_t * header =
reinterpret_cast<const firmware_image_header_t*>(iv_lidImage);
version = TWO_UINT8_TO_UINT16(header->iv_versionMajor,
header->iv_versionMinor);
}
return version;
}
uint16_t BpmFirmwareLidImage::getNumberOfBlocks() const
{
uint16_t numberOfBlocks = 0;
if (iv_lidImageSize >= sizeof(firmware_image_header_t))
{
const firmware_image_header_t * header =
reinterpret_cast<const firmware_image_header_t*>(iv_lidImage);
numberOfBlocks = header->iv_numberOfBlocks;
}
return numberOfBlocks;
}
void const * BpmFirmwareLidImage::getFirstBlock() const
{
void * block = nullptr;
if (getNumberOfBlocks() > 0)
{
block = reinterpret_cast<uint8_t* const>(iv_lidImage)
+ sizeof(firmware_image_header_t);
}
return block;
}
// =============================================================================
// BpmConfigLidImage Class Functions
// =============================================================================
BpmConfigLidImage::BpmConfigLidImage(void * const i_lidImageAddr,
size_t i_size)
: iv_lidImage(i_lidImageAddr), iv_lidImageSize(i_size)
{
assert(i_lidImageAddr != nullptr,
"BPM::BpmConfigLidImage(): Provided LID image must not be nullptr");
}
uint16_t BpmConfigLidImage::getVersion() const
{
uint16_t version = INVALID_VERSION;
if (iv_lidImageSize >= sizeof(config_image_header_t))
{
const config_image_header_t * header =
reinterpret_cast<const config_image_header_t*>(iv_lidImage);
version = TWO_UINT8_TO_UINT16(header->iv_versionMajor,
header->iv_versionMinor);
}
return version;
}
uint16_t BpmConfigLidImage::getNumberOfFragments() const
{
uint16_t numberOfFragments = 0;
if (iv_lidImageSize >= sizeof(config_image_header_t))
{
const config_image_header_t * header =
reinterpret_cast<const config_image_header_t*>(iv_lidImage);
numberOfFragments = header->iv_numberOfFragments;
}
return numberOfFragments;
}
void const * BpmConfigLidImage::getFirstFragment() const
{
void * fragment = nullptr;
if (getNumberOfFragments() > 0)
{
fragment = reinterpret_cast<uint8_t* const>(iv_lidImage)
+ sizeof(config_image_header_t);
}
return fragment;
}
// =============================================================================
// Bpm Class Functions
// =============================================================================
Bpm::Bpm(const TARGETING::TargetHandle_t i_nvdimm)
: iv_nvdimm(i_nvdimm),
iv_bslVersion(0),
iv_firmwareStartAddress(0),
iv_attemptAnotherUpdate(false),
iv_segmentDMerged(false),
iv_segmentBMerged(false),
iv_updateAttempted(false)
{
assert((i_nvdimm != nullptr) && (isNVDIMM(i_nvdimm)),
"BPM::Bpm(): An nvdimm target must be given.");
memset(&iv_segmentD, 0, SEGMENT_SIZE);
memset(&iv_segmentB, 0, SEGMENT_SIZE);
}
bool Bpm::attemptAnotherUpdate()
{
return iv_attemptAnotherUpdate;
}
bool Bpm::hasAttemptedUpdate()
{
return iv_updateAttempted;
}
void Bpm::setAttemptAnotherUpdate()
{
if (iv_updateAttempted)
{
// Since iv_updateAttempted is true that means that this function was
// called on a subsequent update attempt, meaning we should no longer
// attempt updates if the current attempt fails.
iv_attemptAnotherUpdate = false;
}
else
{
// Since iv_updateAttempted is false that means that this function was
// called on the first update attempt because by default
// iv_updateAttempted is false and is only set to true as the last part
// of the update procedure.
iv_attemptAnotherUpdate = true;
}
}
const TARGETING::TargetHandle_t Bpm::getNvdimm()
{
return iv_nvdimm;
}
errlHndl_t Bpm::readBslVersion()
{
TRACFCOMP(g_trac_bpm, ENTER_MRK"Bpm::readBslVersion()");
errlHndl_t errl = nullptr;
do {
// Enter Update mode
errl = enterUpdateMode();
if (errl != nullptr)
{
break;
}
// Verify in Update mode
errl = inUpdateMode();
if (errl != nullptr)
{
break;
}
// Enter Bootstrap Loader (BSL) mode
errl = enterBootstrapLoaderMode();
if (errl != nullptr)
{
break;
}
// Unlock the device. This is a BSL command so we must already be in
// BSL mode to execute it.
errl = unlockDevice();
if (errl != nullptr)
{
break;
}
// Command to get the version is a BSL command, so it has to be sent as
// a payload.
payload_t payload;
errl = setupPayload(payload, BSL_TX_BSL_VERSION, BPM_ADDRESS_ZERO);
if (errl != nullptr)
{
break;
}
// Issue the BSL command
errl = issueCommand(BPM_PASSTHROUGH,
payload,
WRITE,
NO_DELAY_EXTERNAL_RESPONSE);
if (errl != nullptr)
{
break;
}
// Get the result from the BPM.
errl = getResponse(&iv_bslVersion, sizeof(uint8_t));
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::readBslVersion(): "
"Failed to determine BSL Version.");
break;
}
TRACFCOMP(g_trac_bpm, "Bpm::readBslVersion(): BSL Version is 0x%X",
iv_bslVersion);
} while(0);
// Reset the device. This will exit BSL mode.
errlHndl_t exitErrl = resetDevice();
if (exitErrl != nullptr)
{
handleMultipleErrors(errl, exitErrl);
}
// Exit update mode
exitErrl = exitUpdateMode();
if (exitErrl != nullptr)
{
handleMultipleErrors(errl, exitErrl);
}
return errl;
}
errlHndl_t Bpm::getFwVersion(uint16_t & o_fwVersion) const
{
TRACFCOMP(g_trac_bpm, ENTER_MRK"Bpm::getFwVersion()");
errlHndl_t errl = nullptr;
do {
uint8_t bpmMajor = 0, bpmMinor = 0;
errl = nvdimmReadReg(iv_nvdimm,
ES_FWREV1,
bpmMajor);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::getFwVersion(): "
"Failed to read BPM major version byte");
errl->collectTrace(BPM_COMP_NAME);
break;
}
errl = nvdimmReadReg(iv_nvdimm,
ES_FWREV0,
bpmMinor);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::getFwVersion(): "
"Failed to read BPM minor version byte");
errl->collectTrace(BPM_COMP_NAME);
break;
}
o_fwVersion = TWO_UINT8_TO_UINT16(bpmMajor, bpmMinor);
} while(0);
return errl;
}
errlHndl_t Bpm::issueCommand(const uint8_t i_bspCommand,
const uint8_t i_command,
const uint8_t i_opType,
const int i_msDelay)
{
assert(isBspCommand(i_bspCommand),
"i_bspCommand must be a valid BSP command");
assert(isBclCommand(i_command),
"i_command must be a valid BCL command");
// i_opType gets set in the BPM_CMD_STATUS register where it is only given
// two bits. So any value above 3 is not valid.
assert(i_opType <= 3, "i_opType can only range between 0 and 3");
errlHndl_t errl = nullptr;
// i_command must be sent in BPM_REG_PAYLOAD_START, but it doesn't need to
// be formatted into a typical payload since the command isn't a BSL
// command. So, just create a payload_t, push_back the command, and let the
// issueCommand function that takes a payload_t parameter handle the rest.
payload_t payloadCommand;
payloadCommand.push_back(i_command);
errl = issueCommand(i_bspCommand, payloadCommand, i_opType, i_msDelay);
return errl;
}
errlHndl_t Bpm::issueCommand(const uint8_t i_command,
payload_t i_payload,
const uint8_t i_opType,
const int i_msDelay)
{
assert(isBspCommand(i_command),
"i_bspCommand must be a valid BSP command");
// i_opType gets set in the BPM_CMD_STATUS register where it is only given
// two bits. So any value above 3 is not valid.
assert(i_opType <= 3, "i_opType can only range between 0 and 3");
errlHndl_t errl = nullptr;
do {
// Check the full payload size to make sure it's not too large. Add the
// size of the SYNC_BYTE that was dropped during payload creation to
// verify that the full payload sent by the NVDIMM won't exceed the max
// size the BPM is able to receive.
if ((i_payload.size() + SYNC_BYTE_SIZE) > MAX_PAYLOAD_SIZE)
{
uint8_t payloadSize = i_payload.size() + SYNC_BYTE_SIZE;
uint8_t payloadHeaderDataSize =
i_payload[PAYLOAD_HEADER_DATA_LENGTH_INDEX];
TRACFCOMP(g_trac_bpm, ERR_MRK"Bpm::issueCommand(): "
"payload size %d exceeds max payload size of %d",
payloadSize, MAX_PAYLOAD_SIZE);
/*@
* @errortype
* @severity ERRORLOG::ERRL_SEV_PREDICTIVE
* @moduleid BPM_RC::BPM_ISSUE_COMMAND
* @reasoncode BPM_RC::BPM_INVALID_PAYLOAD_SIZE
* @userdata1[00:31] Full Payload Size, including SYNC_BYTE
* @userdata1[32:63] MAX_PAYLOAD_SIZE
* @userdata2[00:31] Payload Header + Data size
* @userdata2[32:63] NVDIMM Target HUID associated with this BPM
* @devdesc The maximum payload size to be sent to the BPM
* was exceeded.
* @custdesc A problem occurred during IPL of the system.
*/
errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_PREDICTIVE,
BPM_RC::BPM_ISSUE_COMMAND,
BPM_RC::BPM_INVALID_PAYLOAD_SIZE,
TWO_UINT16_TO_UINT32(payloadSize,
MAX_PAYLOAD_SIZE),
TWO_UINT32_TO_UINT64(
payloadHeaderDataSize,
TARGETING::get_huid(iv_nvdimm))
);
errl->addProcedureCallout(HWAS::EPUB_PRC_HB_CODE,
HWAS::SRCI_PRIORITY_HIGH);
errl->collectTrace(BPM_COMP_NAME);
nvdimmAddPage4Regs(iv_nvdimm,errl);
nvdimmAddVendorLog(iv_nvdimm, errl);
break;
}
// Load the payload
int i = 0;
for (const auto& byte : i_payload)
{
errl = nvdimmWriteReg(iv_nvdimm,
(BPM_REG_PAYLOAD_START + (i * sizeof(uint8_t))),
byte);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::issueCommand(): "
"Failed to write payload to BPM_REG_PAYLOAD_START");
errl->collectTrace(BPM_COMP_NAME);
break;
}
++i;
}
if (errl != nullptr)
{
break;
}
// Clear the error status register
errl = nvdimmWriteReg(iv_nvdimm,
BPM_REG_ERR_STATUS,
0x00);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::issueCommand(): "
"Failed to clear error status register");
errl->collectTrace(BPM_COMP_NAME);
break;
}
// Set the payload length. This is the actual length of the payload
// excluding the size of the SYNC_BYTE that was dropped during payload
// creation which is already missing from size().
uint8_t data = i_payload.size();
errl = nvdimmWriteReg(iv_nvdimm,
BPM_PAYLOAD_LENGTH,
data);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::issueCommand(): "
"Failed to set payload length");
errl->collectTrace(BPM_COMP_NAME);
break;
}
// Setup the command status register
command_status_register_t commandStatus;
commandStatus.bits.Bsp_Cmd_In_Progress = 1;
commandStatus.bits.Operator_Type = i_opType;
errl = nvdimmWriteReg(iv_nvdimm,
BPM_CMD_STATUS,
commandStatus.value);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::issueCommand(): "
"Failed to setup the command status register");
errl->collectTrace(BPM_COMP_NAME);
break;
}
// Setup command type. The basically executes the command
errl = nvdimmWriteReg(iv_nvdimm,
BPM_REG_CMD,
i_command);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, "Bpm::issueCommand(): "
"Failed to set the command type. "
"The command was not issued to the BPM");
errl->collectTrace(BPM_COMP_NAME);
break;
}
errl = waitForCommandStatusBitReset(commandStatus);
if (errl != nullptr)
{
break;
}
// If a delay was given then wait for the delay and check the response.
// Otherwise, do not wait and do not check the response. For a list of
// commands and delays, see bpm_update.H for more info.
if (i_msDelay > 0)
{
// Wait the given time in ms. Default 1ms for most commands.
nanosleep(0, i_msDelay * NS_PER_MSEC);
// Check the response from the BPM. A non-zero response value
// indicates failure. So, assume a failure and check for success.
uint8_t data = 0xFF;
errl = getResponse(&data, sizeof(uint8_t));
if (errl != nullptr)
{
break;
}
// If the data read from the response is a non-zero value then the
// issued command failed.
if (data != 0)
{
/*@
* @errortype
* @severity ERRORLOG::ERRL_SEV_PREDICTIVE
* @moduleid BPM_RC::BPM_ISSUE_COMMAND
* @reasoncode BPM_RC::BPM_BAD_RESPONSE
* @userdata1 The command that failed to execute.
* See bpm_update.H for list of commands.
* @userdata2 NVDIMM Target HUID associated with this BPM
* @devdesc The command sent to the BPM failed.
* @custdesc A problem occurred during IPL of the system.
*/
errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_PREDICTIVE,
BPM_RC::BPM_ISSUE_COMMAND,
BPM_RC::BPM_BAD_RESPONSE,
i_payload[PAYLOAD_COMMAND_INDEX],
TARGETING::get_huid(iv_nvdimm));
errl->addPartCallout(iv_nvdimm,
HWAS::BPM_PART_TYPE,
HWAS::SRCI_PRIORITY_HIGH);
errl->collectTrace(BPM_COMP_NAME);
nvdimmAddPage4Regs(iv_nvdimm,errl);
nvdimmAddVendorLog(iv_nvdimm, errl);
break;
}
}
} while(0);
return errl;
}
errlHndl_t Bpm::runUpdate(BpmFirmwareLidImage i_fwImage,
BpmConfigLidImage i_configImage)
{
TRACFCOMP(g_trac_bpm, ENTER_MRK"Bpm::runUpdate(): "
"Running BPM Update for NVDIMM 0x%.8X",
TARGETING::get_huid(iv_nvdimm));
errlHndl_t errl = nullptr;
// Assume an update is necessary for the BPM and determine if it isn't.
bool shouldPerformUpdate = true;
// Get the sys target to check for attribute overrides.
TARGETING::Target* sys = nullptr;
TARGETING::targetService().getTopLevelTarget(sys);
auto updateOverride =
sys->getAttr<TARGETING::ATTR_BPM_UPDATE_OVERRIDE>();
uint16_t firmwareOverrideFlag = (updateOverride & 0xFF00);
uint16_t configOverrideFlag = (updateOverride & 0x00FF);
do {
// First check if there is a BPM connected
errl = verifyGoodBpmState();
if (errl != nullptr)
{
// Either there isn't a BPM connected to this NVDIMM or it's not
// functional. Don't bother with updates.
shouldPerformUpdate = false;
iv_attemptAnotherUpdate = false;
break;
}
// Check the version on the BPM against the version in the image.
uint16_t bpmFwVersion = INVALID_VERSION;
errl = getFwVersion(bpmFwVersion);
if (errl != nullptr)
{
TRACFCOMP(g_trac_bpm, ERR_MRK"Bpm::runUpdate(): "
"Could not determine firmware version on BPM "
"Skipping update.");
break;
}
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"Firmware version on the BPM 0x%.4X, "
"Firmware version of image 0x%.4X.",
bpmFwVersion, i_fwImage.getVersion());
if (i_fwImage.getVersion() == bpmFwVersion)
{
shouldPerformUpdate = false;
if (updateOverride == TARGETING::BPM_UPDATE_BEHAVIOR_DEFAULT_ALL)
{
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"Firmware version on the BPM matches the version in "
"the image. Skipping update.");
break;
}
}
if (updateOverride == TARGETING::BPM_UPDATE_BEHAVIOR_SKIP_ALL)
{
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"ATTR_BPM_UPDATE_OVERRIDE set to SKIP_ALL. "
"Skipping update.");
break;
}
// Depending on the BSL version a CRC check may be necessary
errl = readBslVersion();
if (errl != nullptr)
{
break;
}
// If the BSL version read from the BPM isn't a supported version then
// don't perform the updates as the update flow may have changed between
// BSL versions.
if (iv_bslVersion != BSL_VERSION_1_4)
{
TRACFCOMP(g_trac_bpm, "Bpm::runUpdate(): "
"Unsupported BSL Version 0x%.2X detected on BPM. "
"Cancelling Update.");
break;
}
if ((shouldPerformUpdate
|| (firmwareOverrideFlag == TARGETING::BPM_UPDATE_BEHAVIOR_FORCE_FW))
&& !(firmwareOverrideFlag == TARGETING::BPM_UPDATE_BEHAVIOR_SKIP_FW))
{
if (firmwareOverrideFlag == TARGETING::BPM_UPDATE_BEHAVIOR_FORCE_FW)
{
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"ATTR_BPM_UPDATE_OVERRIDE set to force firmware "
"portion of BPM updates. Running Firmware Update...");
}
errl = runFirmwareUpdates(i_fwImage);
if (errl != nullptr)
{
break;
}
}
else
{
if (firmwareOverrideFlag == TARGETING::BPM_UPDATE_BEHAVIOR_SKIP_FW)
{
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"ATTR_BPM_UPDATE_OVERRIDE set to skip firmware "
"portion of BPM updates. Skipping Firmware Update...");
}
else
{
TRACFCOMP(g_trac_bpm, INFO_MRK"Bpm::runUpdate(): "
"Firmware Data on BPM already up-to-date. "
"Skipping Firmware Update...");
}
}