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

// ----------------------------------------------
// Includes
// ----------------------------------------------
#include <string.h>
#include <sys/time.h>
#include <sys/msg.h>
#include <trace/interface.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <errl/errludtarget.H>
#include <errl/errludstring.H>
#include <secureboot/trustedbootif.H>
#include <secureboot/trustedboot_reasoncodes.H>
#include <secureboot/header.H>
#include <secureboot/containerheader.H>
#include <pnor/pnorif.H>
#include <config.h>
#include "../trustedboot.H"
#include "../trustedbootCmds.H"
#include "../trustedbootUtils.H"
#include "../../pnor/pnor_utils.H"
#include "trustedbootMsg.H"
#include "../tpmLogMgr.H"
#include <algorithm>

// ----------------------------------------------
// Trace definitions
// ----------------------------------------------

trace_desc_t* g_trac_trustedboot = nullptr;
TRAC_INIT( & g_trac_trustedboot, TRBOOT_COMP_NAME, KILOBYTE );

namespace TRUSTEDBOOT
{

// Const string to append to PCR extension messages
const char* const FW_KEY_HASH_EXT = " FW KEY HASH";

#ifdef CONFIG_TPMDD

/// Global object to store system trusted boot data
SystemData systemData;

#endif

void getTPMs(
          TARGETING::TargetHandleList& o_tpmList,
    const TPM_FILTER                   i_filter)
{
    TRACUCOMP(g_trac_trustedboot,ENTER_MRK "getTPMs(): i_filter=%d",
        i_filter);

    o_tpmList.clear();

    TARGETING::getAllChips(
        o_tpmList,
        TARGETING::TYPE_TPM,
        (i_filter == TPM_FILTER::ALL_IN_BLUEPRINT) ? false : true);

    if(i_filter == TPM_FILTER::ALL_FUNCTIONAL)
    {
        // From functional TPMs, remove any TPMs that are not actually
        // initialized.  This prevents Hostboot from using the backup TPM
        // in an MPIPL when it's considered "functional" but hasn't been
        // initialized  yet.
        o_tpmList.erase(
            std::remove_if(
                o_tpmList.begin(),
                o_tpmList.end(),
                [](TARGETING::Target* i_pTpm)
                {
                    return !i_pTpm->getAttr<
                               TARGETING::ATTR_HB_TPM_INIT_ATTEMPTED>();
                }),
            o_tpmList.end());
    }

    TRACUCOMP(g_trac_trustedboot,EXIT_MRK "getTPMs(): Found %d TPMs",
        o_tpmList.size());
}

_TpmLogMgr* getTpmLogMgr(
    const TpmTarget* const i_pTpm)
{
    assert(i_pTpm != nullptr,"getTpmLogMgr: BUG! i_pTpm was nullptr");
    assert(i_pTpm->getAttr<TARGETING::ATTR_TYPE>() == TARGETING::TYPE_TPM,
           "getTpmLogMgr: BUG! Expected target to be of TPM type, but "
           "it was of type 0x%08X",i_pTpm->getAttr<TARGETING::ATTR_TYPE>());
    return reinterpret_cast<_TpmLogMgr*>(
        i_pTpm->getAttr<TARGETING::ATTR_HB_TPM_LOG_MGR_PTR>());
}

void setTpmLogMgr(
          TpmTarget*  const i_pTpm,
    const _TpmLogMgr* const i_pTpmLogMgr)
{
    assert(i_pTpm != nullptr,"setTpmLogMgr: BUG! i_pTpm was nullptr");
    assert(i_pTpm->getAttr<TARGETING::ATTR_TYPE>() == TARGETING::TYPE_TPM,
           "setTpmLogMgr: BUG! Expected target to be of TPM type, but "
           "it was of type 0x%08X",i_pTpm->getAttr<TARGETING::ATTR_TYPE>());
    auto pLogMgrPtr =
        reinterpret_cast<TARGETING::ATTR_HB_TPM_LOG_MGR_PTR_type>(
            i_pTpmLogMgr);
    i_pTpm->setAttr<
        TARGETING::ATTR_HB_TPM_LOG_MGR_PTR>(pLogMgrPtr);
}

errlHndl_t pcrExtendSeparator(bool i_sendAsync)
{
    errlHndl_t err = NULL;
#ifdef CONFIG_TPMDD
    MessageMode mode = (i_sendAsync) ? MSG_MODE_ASYNC : MSG_MODE_SYNC;

    TRACUCOMP( g_trac_trustedboot,
               ENTER_MRK"pcrExtendSeparator()");

    Message* msg = Message::factory(MSG_TYPE_SEPARATOR,
                                    0,
                                    NULL,
                                    mode);
    assert(msg !=NULL, "BUG! Message is NULL");
    if (!i_sendAsync)
    {
        int rc = msg_sendrecv(systemData.msgQ, msg->iv_msg);
        if (0 == rc)
        {
            err = msg->iv_errl;
            msg->iv_errl = NULL;
        }
        // Sendrecv failure
        else
        {
            /*@
             * @errortype       ERRL_SEV_UNRECOVERABLE
             * @moduleid        MOD_TPM_SEPARATOR
             * @reasoncode      RC_SENDRECV_FAIL
             * @userdata1       rc from msq_sendrecv()
             * @devdesc         msg_sendrecv() failed
             * @custdesc        Firmware error during system boot
             */
            err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          MOD_TPM_SEPARATOR,
                                          RC_SENDRECV_FAIL,
                                          rc,
                                          0,
                                          true);
            err->collectTrace(SECURE_COMP_NAME);
            err->collectTrace(TRBOOT_COMP_NAME);
        }
        delete msg;
        msg = NULL;
    }
    else
    {
        int rc = msg_send(systemData.msgQ, msg->iv_msg);
        if (rc)
        {
            /*@
             * @errortype       ERRL_SEV_UNRECOVERABLE
             * @moduleid        MOD_TPM_SEPARATOR
             * @reasoncode      RC_SEND_FAIL
             * @userdata1       rc from msq_send()
             * @devdesc         msg_send() failed
             * @custdesc        Firmware error during system boot
             */
            err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          MOD_TPM_SEPARATOR,
                                          RC_SEND_FAIL,
                                          rc,
                                          0,
                                          true);
            err->collectTrace(SECURE_COMP_NAME);
            err->collectTrace(TRBOOT_COMP_NAME);
        }
    }

    TRACUCOMP( g_trac_trustedboot,
               EXIT_MRK"pcrExtendSeparator() - %s",
               ((NULL == err) ? "No Error" : "With Error") );

#endif
    return err;
}

errlHndl_t pcrExtend(TPM_Pcr i_pcr,
                     EventTypes i_eventType,
                     const uint8_t* i_digest,
                     size_t  i_digestSize,
                     const uint8_t* i_logMsg,
                     const size_t i_logMsgSize,
                     bool i_sendAsync,
                     const TpmTarget* i_pTpm,
                     const bool i_mirrorToLog)
{
    errlHndl_t err = NULL;
#ifdef CONFIG_TPMDD
    MessageMode mode = MSG_MODE_ASYNC;

    TRACDCOMP( g_trac_trustedboot, ENTER_MRK"pcrExtend()" );
    TRACUCOMP( g_trac_trustedboot,
               ENTER_MRK"pcrExtend() pcr=%d",
               i_pcr);
    if(i_logMsg)
    {
        TRACUBIN(g_trac_trustedboot, "TPM log msg", i_logMsg, i_logMsgSize);
    }

    TRACUBIN(g_trac_trustedboot, "pcrExtend() digest:", i_digest, i_digestSize);

    // msgData will be freed when message is freed
    PcrExtendMsgData* msgData = new PcrExtendMsgData;
    memset(msgData, 0, sizeof(PcrExtendMsgData));
    msgData->mPcrIndex = i_pcr;
    msgData->mAlgId = TPM_ALG_SHA256;
    msgData->mEventType = i_eventType;
    msgData->mDigestSize = (i_digestSize < sizeof(msgData->mDigest) ?
                            i_digestSize : sizeof(msgData->mDigest));
    msgData->mSingleTpm = i_pTpm;
    msgData->mMirrorToLog = i_mirrorToLog;


    // copy over the incoming digest and truncate to what we need
    memcpy(msgData->mDigest, i_digest, msgData->mDigestSize);

    // Truncate logMsg if required
    if (i_logMsg)
    {
        memcpy(msgData->mLogMsg, i_logMsg,
            (i_logMsgSize < sizeof(msgData->mLogMsg) ?
                i_logMsgSize : sizeof(msgData->mLogMsg)));
    }
    msgData->mLogMsgSize = i_logMsgSize;

    if (!i_sendAsync)
    {
        mode = MSG_MODE_SYNC;
    }

    Message* msg = Message::factory(MSG_TYPE_PCREXTEND,
                                    sizeof(PcrExtendMsgData),
                                    reinterpret_cast<uint8_t*>(msgData),
                                    mode);
    // Message owns msgData now
    msgData = NULL;

    if (!i_sendAsync)
    {
        int rc = msg_sendrecv(systemData.msgQ, msg->iv_msg);
        if (0 == rc)
        {
            err = msg->iv_errl;
            msg->iv_errl = NULL;
        }
        // Sendrecv failure
        else
        {
            /*@
             * @errortype       ERRL_SEV_UNRECOVERABLE
             * @moduleid        MOD_TPM_PCREXTEND
             * @reasoncode      RC_SENDRECV_FAIL
             * @userdata1       rc from msq_sendrecv()
             * @devdesc         msg_sendrecv() failed
             * @custdesc        Firmware error during system boot
             */
            err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          MOD_TPM_PCREXTEND,
                                          RC_SENDRECV_FAIL,
                                          rc,
                                          0,
                                          true);
            err->collectTrace(SECURE_COMP_NAME);
            err->collectTrace(TRBOOT_COMP_NAME);
        }
        delete msg;
        msg = NULL;
    }
    else
    {
        int rc = msg_send(systemData.msgQ, msg->iv_msg);
        if (rc)
        {
            /*@
             * @errortype       ERRL_SEV_UNRECOVERABLE
             * @moduleid        MOD_TPM_PCREXTEND
             * @reasoncode      RC_SEND_FAIL
             * @userdata1       rc from msq_send()
             * @devdesc         msg_send() failed
             * @custdesc        Firmware error during system boot
             */
            err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                          MOD_TPM_PCREXTEND,
                                          RC_SEND_FAIL,
                                          rc,
                                          0,
                                          true);
            err->collectTrace(SECURE_COMP_NAME);
            err->collectTrace(TRBOOT_COMP_NAME);
        }
    }

    TRACUCOMP( g_trac_trustedboot,
               EXIT_MRK"pcrExtend() - %s",
               ((NULL == err) ? "No Error" : "With Error") );

#endif
    return err;
}

errlHndl_t extendPnorSectionHash(
    const SECUREBOOT::ContainerHeader& i_conHdr,
    const void* const                  i_vaddr,
    const PNOR::SectionId              i_sec)
{
    errlHndl_t pError = nullptr;

#ifdef CONFIG_TPMDD

    do {

    PNOR::SectionInfo_t sectionInfo;
    pError = PNOR::getSectionInfo(i_sec,sectionInfo);
    if(pError)
    {
        TRACFCOMP(g_trac_trustedboot, ERR_MRK " Failed in call to "
            "getSectionInfo() with section ID = %d.",
            i_sec);
        break;
    }

    TRACDCOMP(g_trac_trustedboot, ENTER_MRK " extendPnorSectionHash for "
        "section: %s",sectionInfo.name);

    const size_t protectedSize = i_conHdr.payloadTextSize();

    // Generate pcr extension message
    char swKeyMsg[strlen(sectionInfo.name) + strlen(FW_KEY_HASH_EXT) + 1];
    memset(swKeyMsg, 0, sizeof(swKeyMsg));
    strcat(swKeyMsg,sectionInfo.name);
    strcat(swKeyMsg,FW_KEY_HASH_EXT);

    TPM_Pcr pnorHashPcr = PCR_0;
    EventTypes swKeyHashEventType = TRUSTEDBOOT::EV_PLATFORM_CONFIG_FLAGS;
    EventTypes pnorHashEventType = TRUSTEDBOOT::EV_POST_CODE;
    // PAYLOAD is the only section that needs its hash extended to PCR_4
    if (i_sec == PNOR::PAYLOAD)
    {
        pnorHashPcr = PCR_4;
        swKeyHashEventType = TRUSTEDBOOT::EV_COMPACT_HASH;
        pnorHashEventType = TRUSTEDBOOT::EV_COMPACT_HASH;
    }
    else if(PNOR::isCoreRootOfTrustSection(i_sec))
    {
        pnorHashEventType = TRUSTEDBOOT::EV_S_CRTM_CONTENTS;
    }
    // Extend swKeyHash to the next PCR after the hash extension PCR.
    const TPM_Pcr swKeyHashPcr = static_cast<TPM_Pcr>(pnorHashPcr + 1);

    if (SECUREBOOT::enabled())
    {
        // If secureboot is enabled, use protected hash in header
        pError = TRUSTEDBOOT::pcrExtend(pnorHashPcr,
              pnorHashEventType,
              reinterpret_cast<const uint8_t*>(i_conHdr.payloadTextHash()),
              sizeof(SHA512_t),
              reinterpret_cast<const uint8_t*>(sectionInfo.name),
              strlen(sectionInfo.name) + 1);
        if (pError)
        {
            TRACFCOMP(g_trac_trustedboot, ERR_MRK " Failed in call to "
                "pcrExtend() (extend payload text hash) for section %s.",
                sectionInfo.name);
            break;
        }

        // Extend SW public key hash
        pError = TRUSTEDBOOT::pcrExtend(swKeyHashPcr,
                    swKeyHashEventType,
                    reinterpret_cast<const uint8_t*>(i_conHdr.swKeyHash()),
                    sizeof(SHA512_t),
                    reinterpret_cast<const uint8_t*>(swKeyMsg),
                    strlen(swKeyMsg) + 1);
        if (pError)
        {
            TRACFCOMP(g_trac_trustedboot, ERR_MRK " Failed in call to "
                "pcrExtend() (extend SW public key hash) for section %s.",
                sectionInfo.name);
            break;
        }
    }
    else
    {
        // If secureboot is not enabled, measure protected section
        SHA512_t hash = {0};
        SECUREBOOT::hashBlob(i_vaddr, protectedSize, hash);
        pError = TRUSTEDBOOT::pcrExtend(pnorHashPcr,
                pnorHashEventType,
                hash,
                sizeof(SHA512_t),
                reinterpret_cast<const uint8_t*>(sectionInfo.name),
                strlen(sectionInfo.name) + 1);
        if (pError)
        {
            TRACFCOMP(g_trac_trustedboot, ERR_MRK " Failed in call to "
                "pcrExtend() (extend payload text) for section %s.",
                sectionInfo.name);
            break;
        }
    }

    } while(0);

    TRACDCOMP(g_trac_trustedboot, EXIT_MRK " extendPnorSectionHash");

#endif

    return pError;
}

errlHndl_t extendBaseImage()
{
    errlHndl_t pError = nullptr;

#ifdef CONFIG_TPMDD

    TRACDCOMP(g_trac_trustedboot, ENTER_MRK " extendBaseImage()");

    do {

    // Query the HBB header and code address
    const void* pHbbHeader = nullptr;

    (void)SECUREBOOT::baseHeader().getHeader(
        pHbbHeader);

    // Fatal code bug if either address is nullptr
    if(pHbbHeader == nullptr)
    {
        assert(false,"BUG! In extendBaseImage(), cached header address is "
            "nullptr");
    }

    TRACDBIN(g_trac_trustedboot,"Base Header",pHbbHeader,
        TRUSTEDBOOT::DEFAULT_BIN_TRACE_SIZE);

    // Build a container header object from the raw header
    SECUREBOOT::ContainerHeader hbbContainerHeader;
    pError = hbbContainerHeader.setHeader(pHbbHeader);
    if (pError)
    {
        TRACFCOMP(g_trac_trustedboot, ERR_MRK"extendBaseImage() setheader failed");
        break;
    }

    // TPM extension of PNOR sections operates differently when SecureMode is
    // enabled/disabled.  Provide all possible info and let TPM code handle
    // the logic
    PNOR::SectionInfo_t l_info;
    pError = getSectionInfo(PNOR::HB_BASE_CODE, l_info);
    if(pError)
    {
        TRACFCOMP(g_trac_trustedboot, ERR_MRK "Failed in call to "
            "getSectionInfo for HBB section");
        break;
    }

    if(l_info.vaddr == 0)
    {
        assert(false,"BUG! In extendBaseImage(), HBB virtual address was 0");
    }

    const void* pHbbVa = reinterpret_cast<const void*>(l_info.vaddr);

    TRACDBIN(g_trac_trustedboot,"PNOR Base Code",pHbbVa,
             TRUSTEDBOOT::DEFAULT_BIN_TRACE_SIZE);

    // Extend the HBB measurement to the TPM
    pError = extendPnorSectionHash(
        hbbContainerHeader,
        pHbbVa,
        PNOR::HB_BASE_CODE);

    if(pError)
    {
        TRACFCOMP(g_trac_trustedboot, ERR_MRK "Failed in call to "
            "extendPnorSectionHash() for HBB section.");
        break;
    }

    } while(0);

    TRACDCOMP(g_trac_trustedboot, EXIT_MRK " extendBaseImage()");

#endif

    return pError;
}

void initBackupTpm()
{
#ifdef CONFIG_TPMDD
    errlHndl_t l_errl = nullptr;
    Message* l_msg = Message::factory(MSG_TYPE_INIT_BACKUP_TPM,
                                      0,
                                      nullptr,
                                      MSG_MODE_SYNC);
    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc == 0)
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }
    else
    {
        TRACFCOMP(g_trac_trustedboot, "Error occurred while sending message to"
                 " the TPM daemon. RC = %d", l_rc);
        /*@
         * @errortype      ERRL_SEV_UNRECOVERABLE
         * @reasoncode     RC_SENDRECV_FAIL
         * @moduleid       MOD_INIT_BACKUP_TPM
         * @userdata1      rc from msq_sendrecv()
         * @devdesc        msg_sendrecv() failed
         * @custdesc       Trusted Boot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_INIT_BACKUP_TPM,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         0,
                                         true);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    delete l_msg;
    l_msg = nullptr;

    if(l_errl)
    {
        TARGETING::Target* l_backupTpm = nullptr;
        getBackupTpm(l_backupTpm);
        if(l_backupTpm)
        {
            tpmMarkFailed(l_backupTpm, l_errl);
        }
    }
#endif
}

errlHndl_t testCmpPrimaryAndBackupTpm()
{
    errlHndl_t l_err = nullptr;
#ifdef CONFIG_TPMDD
    TARGETING::Target* l_primaryTpm = nullptr;
    TARGETING::Target* l_backupTpm = nullptr;
    bool l_errorOccurred = false;
    BackupTpmTestFailures l_rc = TPM_TEST_NO_ERROR;

    do {

    getPrimaryTpm(l_primaryTpm);
    if(!l_primaryTpm)
    {
        TRACFCOMP(g_trac_trustedboot,
                           "testCmpPrimaryAndBackupTpm: primary TPM not found;"
                           "skipping test");
        break;
    }
    getBackupTpm(l_backupTpm);
    if(!l_backupTpm)
    {
        TRACFCOMP(g_trac_trustedboot,
                            "testCmpPrimaryAndBackupTpm: backup TPM not found;"
                            "skipping test");
        break;
    }

    auto l_primaryHwasState = l_primaryTpm->getAttr<
                                                  TARGETING::ATTR_HWAS_STATE>();
    if(!(l_primaryHwasState.present && l_primaryHwasState.functional))
    {
        TRACFCOMP(g_trac_trustedboot, "testCmpPrimaryAndBackupTpm: primary TPM"
                                      "is not present or not functional;"
                                      "skipping the test.");
        break;
    }

    auto l_backupHwasState = l_backupTpm->getAttr<TARGETING::ATTR_HWAS_STATE>();
    if(!(l_backupHwasState.present && l_backupHwasState.functional))
    {
        TRACFCOMP(g_trac_trustedboot, "testCmpPrimaryAndBackupTpm: backup TPM"
                                      "is not present or not functional;"
                                      "skipping the test.");
        break;
    }

    auto * const pTpmLogMgr = getTpmLogMgr(l_primaryTpm);
    auto * const bTpmLogMgr = getTpmLogMgr(l_backupTpm);

    if(!pTpmLogMgr || !bTpmLogMgr)
    {
        TRACFCOMP(g_trac_trustedboot,
                  "testCmpPrimaryAndBackupTpm: TPM log manager(s)"
                  " is(are) uninitialized");
        l_errorOccurred = true;
        l_rc = TPM_TEST_LOGS_NOT_INITIALIZED;
        break;
    }

    if(TpmLogMgr_getLogSize(bTpmLogMgr) == TpmLogMgr_getLogSize(pTpmLogMgr))
    {
        TRACFCOMP(g_trac_trustedboot,
                     "testCmpPrimaryAndBackupTpm: the sizes of TPM logs match");
    }
    else
    {
        TRACFCOMP(g_trac_trustedboot,
                  "testCmpPrimaryAndBackupTpm: log size mismatch."
                  " Primary log size: %d; backup log size: %d.",
                  TpmLogMgr_getLogSize(pTpmLogMgr),
                  TpmLogMgr_getLogSize(bTpmLogMgr));
        l_errorOccurred = true;
        l_rc = TPM_TEST_LOG_SIZE_MISMATCH;
        break;
    }

    int l_count = 0;
    TCG_PCR_EVENT2 l_pEventLog = {0};
    TCG_PCR_EVENT2 l_bEventLog = {0};
    // Skip the first entry which is the header
    const uint8_t* l_pEventHdl = TpmLogMgr_getFirstEvent(pTpmLogMgr);
    const uint8_t* l_bEventHdl = TpmLogMgr_getFirstEvent(bTpmLogMgr);

    // Match the logs
    while(l_pEventHdl != nullptr && l_bEventHdl != nullptr)
    {
        // Other (than the header) events need to be processed
        l_pEventHdl = TpmLogMgr_getNextEvent(pTpmLogMgr, l_pEventHdl,
                                            &l_pEventLog, &l_errorOccurred);
        if(l_errorOccurred)
        {
            TRACFCOMP(g_trac_trustedboot,
                "testCmpPrimaryAndBackupTpm: Unmarshaling error occurred.");
            l_rc = TPM_TEST_UNMARSHAL_ERROR;
            break;
        }

        l_bEventHdl = TpmLogMgr_getNextEvent(bTpmLogMgr, l_bEventHdl,
                                            &l_bEventLog, &l_errorOccurred);
        if(l_errorOccurred)
        {
            TRACFCOMP(g_trac_trustedboot,
                "testCmpPrimaryAndBackupTpm: Unmarshaling error occurred.");
            l_rc = TPM_TEST_UNMARSHAL_ERROR;
            break;
        }

        if(memcmp(&l_pEventLog, &l_bEventLog, sizeof(TCG_PCR_EVENT2)))
        {
            TRACFCOMP(g_trac_trustedboot,
                      "testCmpPrimaryAndBackupTpm: log #%d does not match",
                      l_count);
            TRACFBIN(g_trac_trustedboot,
                     "testCmpPrimaryAndBackupTpm: primary TPM's log:",
                     &l_pEventLog, sizeof(TCG_PCR_EVENT2));
            TRACFBIN(g_trac_trustedboot,
                     "testCmpPrimaryAndBackupTpm: backup TPM's log:",
                     &l_bEventLog, sizeof(TCG_PCR_EVENT2));
            l_errorOccurred = true;
            l_rc = TPM_TEST_LOG_MISMATCH;
            break;
        }
        else
        {
            TRACFCOMP(g_trac_trustedboot,
                      "testCmpPrimaryAndBackupTpm: log #%d matches",
                      l_count);
        }

        l_count++;
    } //while

    if(l_err || l_errorOccurred)
    {
        break;
    }

    TPM_Pcr l_pcrRegs[8] = {PCR_0, PCR_1, PCR_2, PCR_3,
                            PCR_4, PCR_5, PCR_6, PCR_7};
    TPM_Alg_Id l_algIds[2] = {TPM_ALG_SHA1, TPM_ALG_SHA256};

    size_t l_sizeToAllocate = std::max(getDigestSize(TPM_ALG_SHA1),
                                       getDigestSize(TPM_ALG_SHA256));

    uint8_t* l_pDigest = new uint8_t[l_sizeToAllocate]();
    uint8_t* l_bDigest = new uint8_t[l_sizeToAllocate]();
    size_t l_digestSize = 0;

    // Match the contents of the PCR regs
    for(const auto l_algId : l_algIds)
    {
        l_digestSize = getDigestSize(l_algId);

        for(const auto l_pcrReg : l_pcrRegs)
        {
            l_err = tpmCmdPcrRead(l_primaryTpm,
                                  l_pcrReg,
                                  l_algId,
                                  l_pDigest,
                                  l_digestSize);
            if(l_err)
            {
                TRACFCOMP(g_trac_trustedboot,
                          "testCmpPrimaryAndBackupTpm: failed to read PCR %d"
                          " of primary TPM; algId = 0x%.04x",
                          l_pcrReg,
                          l_algId);
                break;
            }

            l_err = tpmCmdPcrRead(l_backupTpm,
                                  l_pcrReg,
                                  l_algId,
                                  l_bDigest,
                                  l_digestSize);
            if(l_err)
            {
                TRACFCOMP(g_trac_trustedboot,
                          "testCmpPrimaryAndBackupTpm: failed to read PCR %d"
                          " of backup TPM; algId = 0x%.04x",
                          l_pcrReg,
                          l_algId);
                break;
            }

            if(memcmp(l_pDigest, l_bDigest, l_digestSize))
            {
                TRACFCOMP(g_trac_trustedboot,
                          "testCmpPrimaryAndBackupTpm: digests of PCR %d"
                          " algId 0x%.04x do not match!",
                          l_pcrReg,
                          l_algId);
                TRACFBIN(g_trac_trustedboot,
                         "testCmpPrimaryAndBackupTpm: contents of primary TPM's"
                         " PCR:",
                         l_pDigest, l_digestSize);
                TRACFBIN(g_trac_trustedboot,
                         "testCmpPrimaryAndBackupTpm: contents of backup TPM's"
                         " PCR:",
                         l_bDigest, l_digestSize);
                l_rc = TPM_TEST_DIGEST_MISMATCH;
                l_errorOccurred = true;
                break;
            }
            else
            {
                TRACFCOMP(g_trac_trustedboot,
                          "testCmpPrimaryAndBackupTpm: digests of PCR %d, algId"
                          " 0x%.04x match",
                          l_pcrReg,
                          l_algId);
            }
        } // pcrReg

        if(l_err || l_errorOccurred)
        {
            break;
        }
    } // algId

    delete l_pDigest;
    delete l_bDigest;
    l_pDigest = l_bDigest = nullptr;

    } while(0);

    if(!l_err && l_errorOccurred)
    {
        /*@
         * @errortype
         * @reasoncode     RC_BACKUP_TPM_TEST_FAIL
         * @severity       ERRL_SEV_UNRECOVERABLE
         * @moduleid       MOD_TEST_CMP_PRIMARY_AND_BACKUP_TPM
         * @userdata1      return code
         * @userdata2      0
         * @devdesc        TPM testcase error. See the return code for details.
         * @custdesc       Trusted Boot failure.
         */
        l_err = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                      MOD_TEST_CMP_PRIMARY_AND_BACKUP_TPM,
                                      RC_BACKUP_TPM_TEST_FAIL,
                                      l_rc,
                                      0,
                                      true /*Add HB SW Callout*/);

        l_err->collectTrace(SECURE_COMP_NAME);
        l_err->collectTrace(TRBOOT_COMP_NAME);
    }
#endif
    return l_err;
}

errlHndl_t flushTpmQueue()
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    TRACFCOMP(g_trac_trustedboot, ENTER_MRK"flushTpmQueue()");

    Message* l_msg = Message::factory(MSG_TYPE_FLUSH,
                                      0,
                                      nullptr,
                                      MSG_MODE_SYNC);

    assert(l_msg != nullptr, "TPM flush message is nullptr");

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
       /*@
        * @errortype       ERRL_SEV_UNRECOVERABLE
        * @moduleid        MOD_FLUSH_TPM_QUEUE
        * @reasoncode      RC_SENDRECV_FAIL
        * @userdata1       rc from msq_sendrecv()
        * @devdesc         msg_sendrecv() failed trying to send flush message to
        *                  TPM daemon
        * @custdesc        Trusted boot failure
        */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_FLUSH_TPM_QUEUE,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         0,
                                         true);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    delete l_msg;
    l_msg = nullptr;

    TRACFCOMP(g_trac_trustedboot, EXIT_MRK"flushTpmQueue()");
#endif
    return l_errl;
}

errlHndl_t createAttestationKeys(TpmTarget* i_target)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    TpmTargetData* l_data = new TpmTargetData{i_target};

    l_msg = Message::factory(MSG_TYPE_CREATE_ATT_KEYS,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg != nullptr, "createAttestationKeys: l_msg is nullptr");
    l_data = nullptr; //l_msg now owns l_data

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype   ERRL_SEV_UNRECOVERABLE
         * @moduleid    MOD_CREATE_ATT_KEYS
         * @reasoncode  RC_SENDRECV_FAIL
         * @userdata1   rc from msg_sendrecv
         * @userdata2   TPM HUID
         * @devdesc     msg_sendrecv failed for createAttestationKeys
         * @custdesc    trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_CREATE_ATT_KEYS,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }

#endif
    return l_errl;
}

errlHndl_t readAKCertificate(TpmTarget* i_target, TPM2B_MAX_NV_BUFFER* o_data)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    ReadAKCertData* l_data = new ReadAKCertData {i_target, o_data};

    l_msg = Message::factory(MSG_TYPE_READ_AK_CERT,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg != nullptr, "readAKCertificate: l_msg is nullptr");
    l_data = nullptr; // l_msg now owns l_data

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype   ERRL_SEV_UNRECOVERABLE
         * @moduleid    MOD_READ_AK_CERT
         * @reasoncode  RC_SENDRECV_FAIL
         * @userdata1   rc from msg_sendrecv
         * @userdata2   TPM HUID
         * @devdesc     msg_sendrecv failed for readAKCertificate
         * @custdesc    trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_READ_AK_CERT,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }

#endif
    return l_errl;
}

errlHndl_t generateQuote(TpmTarget* i_target,
                         const MasterTpmNonce_t* const i_masterNonce,
                         QuoteDataOut* o_data)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    GenQuoteData* l_data = new GenQuoteData{i_target, i_masterNonce, o_data};

    l_msg = Message::factory(MSG_TYPE_GEN_QUOTE,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg != nullptr, "generateQuote: l_msg is nullptr");
    l_data = nullptr; //l_msg now owns l_data

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype   ERRL_SEV_UNRECOVERABLE
         * @moduleid    MOD_GEN_QUOTE
         * @reasoncode  RC_SENDRECV_FAIL
         * @userdata1   rc from msg_sendrecv
         * @userdata2   TPM HUID
         * @devdesc     msg_sendrecv failed for generateQuote
         * @custdesc    trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_GEN_QUOTE,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }

#endif
    return l_errl;
}

errlHndl_t flushContext(TpmTarget* i_target)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    TpmTargetData* l_data = new TpmTargetData{i_target};

    l_msg = Message::factory(MSG_TYPE_FLUSH_CONTEXT,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg != nullptr, "flushContext: l_msg is nullptr");
    l_data = nullptr;

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype   ERRL_SEV_UNRECOVERABLE
         * @moduleid    MOD_FLUSH_CONTEXT
         * @reasoncode  RC_SENDRECV_FAIL
         * @userdata1   rc from msg_sendrecv
         * @userdata2   TPM HUID
         * @devdesc     msg_sendrecv failed for TPM2_FlushContext
         * @custdesc    trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_FLUSH_CONTEXT,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }

#endif
    return l_errl;
}

errlHndl_t pcrRead(TpmTarget* i_target,
                   const TPM_Pcr i_pcr,
                   const TPM_Alg_Id i_algId,
                   const size_t i_digestSize,
                   uint8_t* const o_digest)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    PcrReadData* l_data = new PcrReadData{i_target,
                                          i_pcr,
                                          i_algId,
                                          o_digest,
                                          i_digestSize};

    l_msg = Message::factory(MSG_TYPE_PCR_READ,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg != nullptr, "pcrRead: l_msg is nullptr");
    l_data = nullptr; //l_msg now owns l_data

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype   ERRL_SEV_UNRECOVERABLE
         * @moduleid    MOD_PCR_READ
         * @reasoncode  RC_SENDRECV_FAIL
         * @userdata1   rc from msg_sendrecv
         * @userdata2   TPM HUID
         * @devdesc     msg_sendrecv failed for pcrRead
         * @custdesc    trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_PCR_READ,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }

#endif
    return l_errl;
}

errlHndl_t expandTpmLog(TpmTarget* i_target)
{
    errlHndl_t l_errl = nullptr;
#ifdef CONFIG_TPMDD
    Message* l_msg = nullptr;

    TpmTargetData* l_data = new TpmTargetData(i_target);

    l_msg = Message::factory(MSG_TYPE_EXPAND_TPM_LOG,
                             sizeof(*l_data),
                             reinterpret_cast<uint8_t*>(l_data),
                             MSG_MODE_SYNC);
    assert(l_msg, "expandTpmLog: l_msg is nullptr");
    l_data = nullptr; // l_msg now owns l_data

    int l_rc = msg_sendrecv(systemData.msgQ, l_msg->iv_msg);
    if(l_rc)
    {
        /*@
         * @errortype ERRL_SEV_UNRECOVERABLE
         * @moduleid MOD_EXPAND_TPM_LOG
         * @reasoncode RC_SENDRECV_FAIL
         * @userdata1 rc from msg_sendrecv
         * @userdata2 TPM HUID
         * @devdesc msg_sendrecv failed for expandTpmLog
         * @custdesc trustedboot failure
         */
        l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
                                         MOD_EXPAND_TPM_LOG,
                                         RC_SENDRECV_FAIL,
                                         l_rc,
                                         TARGETING::get_huid(i_target),
                                         ERRORLOG::ErrlEntry::ADD_SW_CALLOUT);
        l_errl->collectTrace(SECURE_COMP_NAME);
        l_errl->collectTrace(TRBOOT_COMP_NAME);
    }
    else
    {
        l_errl = l_msg->iv_errl;
        l_msg->iv_errl = nullptr;
    }

    if(l_msg)
    {
        delete l_msg;
        l_msg = nullptr;
    }
#endif
    return l_errl;
}

} // end TRUSTEDBOOT
OpenPOWER on IntegriCloud