-
Notifications
You must be signed in to change notification settings - Fork 97
/
xmltohb.pl
executable file
·7373 lines (6217 loc) · 270 KB
/
xmltohb.pl
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
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/targeting/common/xmltohb/xmltohb.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2012,2017
# [+] 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
#
# Purpose:
# Author: Nick Bofferding
# Last Updated: 09/09/2011
#
# Version: 1.0
#
# Change Log **********************************************************
#
# End Change Log ******************************************************
use strict;
################################################################################
# Use of the following packages
################################################################################
use Carp;
use Getopt::Long;
use Pod::Usage;
use XML::Simple;
use Text::Wrap;
use Data::Dumper;
use POSIX;
use Env;
use XML::LibXML;
# Provides object deep copy capability to support virtual
# attribute removal
use Storable 'dclone';
################################################################################
# Set PREFERRED_PARSER to XML::Parser. Otherwise it uses XML::SAX which contains
# bugs that result in XML parse errors that can be fixed by adjusting white-
# space (i.e. parse errors that do not make sense).
################################################################################
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
################################################################################
# Process command line parameters, issue help text if needed
################################################################################
sub main{ }
my $cfgSrcOutputDir = ".";
my $cfgImgOutputDir = ".";
my $cfgHbXmlFile = "./hb.xml";
my $cfgVmmConstsFile = "../../../include/usr/vmmconst.h";
my $cfgFapiAttributesXmlFile = "";
my $cfgImgOutputFile = "./targeting.bin";
my $cfgHelp = 0;
my $cfgMan = 0;
my $cfgVerbose = 0;
my $cfgShortEnums = 0;
my $cfgBigEndian = 1;
my $cfgIncludeFspAttributes = 0;
my $CfgSMAttrFile = "";
my $cfgAddVersionPage = 0;
my $cfgBiosXmlFile = undef;
my $cfgBiosSchemaFile = undef;
my $cfgBiosOutputFile = undef;
GetOptions("hb-xml-file:s" => \$cfgHbXmlFile,
"src-output-dir:s" => \$cfgSrcOutputDir,
"img-output-dir:s" => \$cfgImgOutputDir,
"fapi-attributes-xml-file:s" => \$cfgFapiAttributesXmlFile,
"img-output-file:s" => \$cfgImgOutputFile,
"vmm-consts-file:s" => \$cfgVmmConstsFile,
"short-enums!" => \$cfgShortEnums,
"big-endian!" => \$cfgBigEndian,
"smattr-output-file:s" => \$CfgSMAttrFile,
"include-fsp-attributes!" => \$cfgIncludeFspAttributes,
"version-page!" => \$cfgAddVersionPage,
"bios-xml-file:s" => \$cfgBiosXmlFile,
"bios-schema-file:s" => \$cfgBiosSchemaFile,
"bios-output-file:s" => \$cfgBiosOutputFile,
"help" => \$cfgHelp,
"man" => \$cfgMan,
"verbose" => \$cfgVerbose ) || pod2usage(-verbose => 0);
pod2usage(-verbose => 1) if $cfgHelp;
pod2usage(-verbose => 2) if $cfgMan;
# Remove extraneous '/' from end of path names; use temporary version of $/ for
# the chomp
{
local $/ = '/';
chomp($cfgSrcOutputDir);
$cfgSrcOutputDir .= "/";
chomp($cfgImgOutputDir);
$cfgImgOutputDir .= "/";
}
if($cfgVerbose)
{
print STDOUT "Host boot intemediate XML model = $cfgHbXmlFile\n";
print STDOUT "Fapi attributes XML file = $cfgFapiAttributesXmlFile\n";
print STDOUT "Source output dir = $cfgSrcOutputDir\n";
print STDOUT "Image output dir = $cfgImgOutputDir\n";
print STDOUT "VMM constants file = $cfgVmmConstsFile\n";
print STDOUT "Short enums = $cfgShortEnums\n";
print STDOUT "Big endian = $cfgBigEndian\n";
print STDOUT "include-fsp-attributes = $cfgIncludeFspAttributes\n",
print STDOUT "version-page = $cfgAddVersionPage\n",
print STDOUT "bios-schema-file = $cfgBiosSchemaFile\n";
print STDOUT "bios-xml-file = $cfgBiosXmlFile\n";
print STDOUT "bios-output-file = $cfgBiosOutputFile\n";
}
################################################################################
# Initialize some globals
################################################################################
use constant INVALID_HUID=>0xffffffff;
use constant PEER_HUID_NOT_PRESENT=>0xfffffffe;
# When computing associations between targets, always store the association list
# pointers in this exact order within each target object. It also must be the
# case that the ASSOCIATION_TYPE enum in the target service header must declare
# the corresponding enum values in this order as well
use constant PARENT_BY_CONTAINMENT => "ParentByContainment";
use constant CHILD_BY_CONTAINMENT => "ChildByContainment";
use constant PARENT_BY_AFFINITY => "ParentByAffinity";
use constant CHILD_BY_AFFINITY => "ChildByAffinity";
use constant PERVASIVE_CHILD => "PervasiveChild";
use constant PARENT_PERVASIVE => "ParentPervasive";
my @associationTypes = ( PARENT_BY_CONTAINMENT,
CHILD_BY_CONTAINMENT, PARENT_BY_AFFINITY, CHILD_BY_AFFINITY,
PERVASIVE_CHILD, PARENT_PERVASIVE );
# Constants for attribute names (minus ATTR_ prefix)
use constant ATTR_PARENT_PERVASIVE => "PARENT_PERVASIVE";
use constant ATTR_PHYS_PATH => "PHYS_PATH";
use constant ATTR_AFFINITY_PATH => "AFFINITY_PATH";
use constant ATTR_UNKNOWN => "UnknownAttributeName";
use constant ATTR_POSITION => "POSITION";
use constant ATTR_CHIP_UNIT => "CHIP_UNIT";
use constant ATTR_CLASS => "CLASS";
use constant ATTR_TYPE => "TYPE";
use constant ATTR_MODEL => "MODEL";
# Data manipulation constants
use constant BITS_PER_BYTE => 8;
use constant LOW_BYTE_MASK => 0xFF;
use constant BYTE_RIGHT_BIT_INDEX => BITS_PER_BYTE - 1;
use constant BYTES_PER_ABSTRACT_POINTER => 8;
# This is the maximum total sum of (compute nodes + control nodes) possible for
# any known system using this attribute compiler. It is used to reserve
# space in each system target's CHILD + CHILD_BY_AFFINITY association lists
# so that FSP can link a system target to multiple nodes
use constant MAX_COMPUTE_AND_CONTROL_NODE_SUM => 5;
my $xml = new XML::Simple (KeyAttr=>[]);
use Digest::MD5 qw(md5_hex);
# Until full machine parseable workbook parsing splits out all the input files,
# use the intermediate representation containing the full host boot model.
# Aborts application if file name not found.
# NOTE: the attribute list initially contains both real and virtual attributes
my $allAttributes = $xml->XMLin($cfgHbXmlFile,
forcearray => ['enumerationType','enumerator','attribute','hwpfToHbAttrMap',
'compileAttribute']);
my $fapiAttributes = {};
if ($cfgFapiAttributesXmlFile ne "")
{
$fapiAttributes = $xml->XMLin($cfgFapiAttributesXmlFile,
forcearray => ['attribute']);
}
# save attributes defined as Target_t type
my %Target_t = ();
# Perform some sanity validation of the model (so we don't have to later)
# Subject virtual attributes to same sanity checks
validateAttributes($allAttributes);
validateTargetInstances($allAttributes);
validateTargetTypes($allAttributes);
validateTargetTypesExtension($allAttributes);
# Clone the attributes and strip out any references to virtual
# attributes, then continue forward using the result as the typical
# working attribute set. The original set containing virtual attributes
# will be used for very specific tasks, like computing associations
my $attributes = dclone $allAttributes;
my %virtualAttrIds = ();
for my $attr (reverse 0..((scalar @{$attributes->{attribute}})-1) )
{
if(exists $attributes->{attribute}[$attr]->{virtual})
{
# Found a virtual attribute; note it and remove
$virtualAttrIds{$attributes->{attribute}[$attr]->{id}} = 1;
splice @{$attributes->{attribute}}, $attr, 1;
}
}
foreach my $targetType (@{$attributes->{targetType}})
{
if(exists $targetType->{attribute})
{
for my $attr (reverse 0..((scalar
@{$targetType->{attribute}})-1))
{
my $currentAttr = $targetType->{attribute}[$attr];
if( exists $currentAttr->{id}
&& exists $virtualAttrIds{$currentAttr->{id}} )
{
# A targetType refers to the virtual attribute
# so remove it
splice @{$targetType->{attribute}}, $attr, 1;
}
}
}
}
if($cfgIncludeFspAttributes)
{
handleTgtPtrAttributesFsp(\$attributes, \%Target_t);
}
else
{
handleTgtPtrAttributesHb(\$attributes, \%Target_t);
}
# Output R/W attributes
my $rwAttrOutputDir = "";
if (!($cfgSrcOutputDir =~ "none"))
{
$rwAttrOutputDir = $cfgSrcOutputDir;
}
open(my $rwAttrFile, ">$rwAttrOutputDir"."PersistRwAttrList.csv")
or croak("R/W data file 'PersistRwAttrList.csv' could not be opened.");
print $rwAttrFile "# PersistRwAttrList.csv\n"
. "# This file is generated by perl script xmltohb.pl\n"
. "# It lists all non-volatile read/write attributes that persist in PNOR\n"
. "# and can be manipulated at will.\n";
foreach my $attrs (@{$attributes->{attribute}})
{
if (exists $attrs->{readable} &&
exists $attrs->{writeable} &&
exists $attrs->{persistency} &&
$attrs->{persistency} eq "non-volatile")
{
print $rwAttrFile "$attrs->{id}\n";
}
}
close $rwAttrFile;
# Open the output files and write them
if( !($cfgSrcOutputDir =~ "none") )
{
open(ATTR_TARG_MAP_FILE,">$cfgSrcOutputDir"."targAttrOverrideData.H")
or croak("Target Attribute data file: \"$cfgSrcOutputDir"
. "getTargAttrData.C\" could not be opened.");
my $targAttrFile = *ATTR_TARG_MAP_FILE;
writeTargAttrMap($attributes, $targAttrFile);
close $targAttrFile;
open(TRAIT_FILE,">$cfgSrcOutputDir"."attributetraits.H")
or croak ("Trait file: \"$cfgSrcOutputDir"
. "attributetraits.H\" could not be opened.");
my $traitFile = *TRAIT_FILE;
writeTraitFileHeader($attributes,$traitFile);
writeTraitFileTraits($attributes,$traitFile);
writeTraitFileFooter($traitFile);
close $traitFile;
open(ATTR_FILE,">$cfgSrcOutputDir"."attributeenums.H")
or croak ("Attribute enum file: \"$cfgSrcOutputDir"
. "attributeenums.H\" could not be opened.");
my $enumFile = *ATTR_FILE;
writeEnumFileHeader($enumFile);
writeEnumFileAttrIdEnum($attributes,$enumFile);
writeEnumFileAttrEnums($attributes,$enumFile);
writeEnumFileFooter($enumFile);
close $enumFile;
open(STRING_HEADER_FILE,">$cfgSrcOutputDir"."attributestrings.H")
or croak ("Attribute string header file: \"$cfgSrcOutputDir"
. "attributestrings.H\" could not be opened.");
my $stringHeaderFile = *STRING_HEADER_FILE;
writeStringHeaderFileHeader($stringHeaderFile);
writeStringHeaderFileStrings($attributes,$stringHeaderFile);
writeStringHeaderFileFooter($stringHeaderFile);
close $stringHeaderFile;
open(STRING_IMPLEMENTATION_FILE,">$cfgSrcOutputDir"."attributestrings.C")
or croak ("Attribute string source file: \"$cfgSrcOutputDir"
. "attributestrings.C\" could not be opened.");
my $stringImplementationFile = *STRING_IMPLEMENTATION_FILE;
writeStringImplementationFileHeader($stringImplementationFile);
writeStringImplementationFileStrings($attributes,$stringImplementationFile);
writeStringImplementationFileFooter($stringImplementationFile);
writeTestEntityPath($attributes);
close $stringImplementationFile;
open(STRUCTS_HEADER_FILE,">$cfgSrcOutputDir"."attributestructs.H")
or croak ("Attribute struct file: \"$cfgSrcOutputDir"
. "attributestructs.H\" could not be opened.");
my $structFile = *STRUCTS_HEADER_FILE;
writeStructFileHeader($structFile);
writeStructFileStructs($attributes,$structFile);
writeStructFileFooter($structFile);
close $structFile;
open(PNOR_HEADER_DEF_FILE,">$cfgSrcOutputDir"."pnortargeting.H")
or croak ("Targeting header definition header file: \"$cfgSrcOutputDir"
. "pnortargeting.H\" could not be opened.");
my $pnorHeaderDefFile = *PNOR_HEADER_DEF_FILE;
writeHeaderFormatHeaderFile($pnorHeaderDefFile);
close $pnorHeaderDefFile;
open(FAPI2_PLAT_ATTR_MACROS_FILE,">$cfgSrcOutputDir"."fapi2platattrmacros.H")
or croak ("FAPI2 platform attribute macro header file: \"$cfgSrcOutputDir"
. "fapi2platattrmacros.H\" could not be opened.");
my $fapi2PlatAttrMacrosHeaderFile = *FAPI2_PLAT_ATTR_MACROS_FILE;
writeFapi2PlatAttrMacrosHeaderFileHeader ($fapi2PlatAttrMacrosHeaderFile);
writeFapi2PlatAttrMacrosHeaderFileContent($attributes,$fapiAttributes,
$fapi2PlatAttrMacrosHeaderFile);
writeFapi2PlatAttrMacrosHeaderFileFooter ($fapi2PlatAttrMacrosHeaderFile);
close $fapi2PlatAttrMacrosHeaderFile;
open(ATTR_ATTRERRL_C_FILE,">$cfgSrcOutputDir"."errludattribute.C")
or croak ("Attribute errlog C file: \"$cfgSrcOutputDir"
. "errludattribute.C\" could not be opened.");
my $attrErrlCFile = *ATTR_ATTRERRL_C_FILE;
writeAttrErrlCFile($attributes,$attrErrlCFile);
close $attrErrlCFile;
mkdir("$cfgSrcOutputDir/errl");
open(ATTR_ATTRERRL_H_FILE,">$cfgSrcOutputDir"."errl/errludattribute.H")
or croak ("Attribute errlog H file: \"$cfgSrcOutputDir"
. "errl/errludattribute.H\" could not be opened.");
my $attrErrlHFile = *ATTR_ATTRERRL_H_FILE;
writeAttrErrlHFile($attributes,$attrErrlHFile);
close $attrErrlHFile;
open(ATTR_TARGETERRL_C_FILE,">$cfgSrcOutputDir"."errludtarget.C")
or croak ("Target errlog C file: \"$cfgSrcOutputDir"
. "errludtarget.C\" could not be opened.");
my $targetErrlCFile = *ATTR_TARGETERRL_C_FILE;
writeTargetErrlCFile($attributes,$targetErrlCFile);
close $targetErrlCFile;
open(ATTR_TARGETERRL_H_FILE,">$cfgSrcOutputDir"."errl/errludtarget.H")
or croak ("Target errlog H file: \"$cfgSrcOutputDir"
. "errl/errludtarget.H\" could not be opened.");
my $targetErrlHFile = *ATTR_TARGETERRL_H_FILE;
writeTargetErrlHFile($attributes,$targetErrlHFile);
close $targetErrlHFile;
open(ATTR_INFO_CSV_FILE,">$cfgSrcOutputDir"."targAttrInfo.csv")
or croak ("Attribute info csv file: \"$cfgSrcOutputDir"
. "targAttrInfo.csv\" could not be opened.");
my $attrInfoCsvFile = *ATTR_INFO_CSV_FILE;
writeAttrInfoCsvFile($attributes,$attrInfoCsvFile);
close $attrInfoCsvFile;
open(MAP_ATTR_METADATA_H_FILE,">$cfgSrcOutputDir"."mapattrmetadata.H")
or croak ("Attribute metadata map file Header: \"$cfgSrcOutputDir"
. "mapattrmetadata.H\" could not be opened.");
my $attrMetadataMapHFile = *MAP_ATTR_METADATA_H_FILE;
writeAttrMetadataMapHFile($attrMetadataMapHFile);
close $attrMetadataMapHFile;
open(MAP_ATTR_METADATA_C_FILE,">$cfgSrcOutputDir"."mapattrmetadata.C")
or croak ("Attribute metadata map C file: \"$cfgSrcOutputDir"
. "mapattrmetadata.C\" could not be opened.");
my $attrMetadataMapCFile = *MAP_ATTR_METADATA_C_FILE;
writeAttrMetadataMapCFileHeader($attrMetadataMapCFile);
writeAttrMetadataMapCFile($attributes,$attrMetadataMapCFile);
writeAttrMetadataMapCFileFooter($attrMetadataMapCFile);
close $attrMetadataMapCFile;
open(MAP_ATTR_SIZE_H_FILE,">$cfgSrcOutputDir"."mapsystemattrsize.H")
or croak ("Attribute size map file Header: \"$cfgSrcOutputDir"
. "mapsystemattrsize.H\" could not be opened.");
my $attrSizeMapHFile = *MAP_ATTR_SIZE_H_FILE;
writeAttrSizeMapHFile($attrSizeMapHFile);
close $attrSizeMapHFile;
open(MAP_ATTR_SIZE_C_FILE,">$cfgSrcOutputDir"."mapsystemattrsize.C")
or croak ("Attribute size map file: \"$cfgSrcOutputDir"
. "mapsystemattrsize.C\" could not be opened.");
my $attrSizeMapCFile = *MAP_ATTR_SIZE_C_FILE;
writeAttrSizeMapCFileHeader($attrSizeMapCFile);
writeAttrSizeMapCFile($attributes,$attrSizeMapCFile);
writeAttrSizeMapCFileFooter($attrSizeMapCFile);
close $attrSizeMapCFile;
}
use constant ATTRID => 0;
use constant HUID => 1;
use constant DATA => 2;
use constant SECTION => 3;
use constant TARGET => 4;
use constant ATTRNAME => 5;
my @attrDataforSM = ();
#Flag which indicates if the script needs to add the 4096 bytes of version
#checksum as first page in the binary file generated.
my $addRO_Section_VerPage = 0;
if( !($cfgImgOutputDir =~ "none") )
{
#Version page will be added only if the script is called in with the flag
#--version-page
if ($cfgAddVersionPage)
{
$addRO_Section_VerPage = 1;
}
# Different portions of the targeting data split up.
my $combinedData;
my $protectedData;
my $unprotectedData;
#Pass the $addRO_Section_VerPage into the sub rotuine
generateTargetingImage($cfgVmmConstsFile,$attributes,\%Target_t,
$addRO_Section_VerPage,$allAttributes,
\$combinedData,
\$protectedData,
\$unprotectedData);
# Generate combined targeting file
open(PNOR_TARGETING_FILE,">$cfgImgOutputDir".$cfgImgOutputFile)
or croak ("Targeting image file: \"$cfgImgOutputDir"
. "$cfgImgOutputFile\" could not be opened.");
binmode(PNOR_TARGETING_FILE);
print PNOR_TARGETING_FILE "$combinedData";
close(PNOR_TARGETING_FILE);
# Generate protected payload file
open(PNOR_TARGETING_FILE,">$cfgImgOutputDir"."$cfgImgOutputFile.protected")
or fatal ("Targeting image file: \"$cfgImgOutputDir"
. "$cfgImgOutputFile.protected\" could not be opened.");
binmode(PNOR_TARGETING_FILE);
print PNOR_TARGETING_FILE "$protectedData";
close(PNOR_TARGETING_FILE);
# Generate unprotected payload file
open(PNOR_TARGETING_FILE,
">$cfgImgOutputDir"."$cfgImgOutputFile.unprotected")
or fatal ("Targeting image file: \"$cfgImgOutputDir"
. "$cfgImgOutputFile.unprotected\" could not be opened.");
binmode(PNOR_TARGETING_FILE);
print PNOR_TARGETING_FILE "$unprotectedData";
close(PNOR_TARGETING_FILE);
if ($CfgSMAttrFile ne "")
{
generateXMLforSM();
}
}
exit(0);
sub VALIDATION_FUNCTIONS { }
################################################################################
# Validates sub-elements of an element against criteria
################################################################################
sub validateSubElements {
my($name,$mustBeHash,$element,$criteria) = @_;
if($mustBeHash && (ref($element) ne "HASH"))
{
print "name=$name, mustBeHash=$mustBeHash, element=$element, criteria=$criteria \n";
croak("$name must be in the form of a hash.");
}
# print keys %{$element} . "\n";
for my $subElementName (sort(keys %{$element}))
{
if(!exists $criteria->{$subElementName})
{
croak("$name element cannot have child element of type "
. "\"$subElementName\".");
}
}
for my $subElementName (sort(keys %{$criteria}))
{
if( ($criteria->{$subElementName}{required} == 1)
&& (!exists $element->{$subElementName}))
{
croak("$name element missing required child element "
. "\"$subElementName\".");
}
if(exists $element->{$subElementName}
&& ($criteria->{$subElementName}{isscalar} == 1)
&& (ref ($element->{$subElementName}) eq "HASH"))
{
croak("$name element child element \"$subElementName\" should be "
. "scalar, but is a hash.");
}
}
}
################################################################################
# Validates attribute element for correctness
################################################################################
sub validateAttributes {
my($attributes) = @_;
my %elements = ( );
$elements{"id"} = { required => 1, isscalar => 1};
$elements{"description"} = { required => 1, isscalar => 1};
$elements{"persistency"} = { required => 1, isscalar => 1};
$elements{"fspOnly"} = { required => 0, isscalar => 0};
$elements{"hbOnly"} = { required => 0, isscalar => 0};
$elements{"readable"} = { required => 0, isscalar => 0};
$elements{"simpleType"} = { required => 0, isscalar => 0};
$elements{"complexType"} = { required => 0, isscalar => 0};
$elements{"nativeType"} = { required => 0, isscalar => 0};
$elements{"writeable"} = { required => 0, isscalar => 0};
$elements{"hasStringConversion"}
= { required => 0, isscalar => 0};
$elements{"hwpfToHbAttrMap"}
= { required => 0, isscalar => 0};
$elements{"display-name"} = { required => 0, isscalar => 1};
$elements{"virtual"} = { required => 0, isscalar => 0};
$elements{"tempAttribute"} = { required => 0, isscalar => 0};
$elements{"serverwizReadonly"} = { required => 0, isscalar => 0};
$elements{"serverwizShow"} = { required => 0, isscalar => 1};
$elements{"global"} = { required => 0, isscalar => 0};
foreach my $attribute (@{$attributes->{attribute}})
{
validateSubElements("attribute",1,$attribute,\%elements);
}
}
################################################################################
# Validates field element for correctness
################################################################################
sub validateFieldElement {
my($field) = @_;
my %elements = ( );
$elements{"type"} = { required => 1, isscalar => 1};
$elements{"name"} = { required => 1, isscalar => 1};
$elements{"description"} = { required => 1, isscalar => 1};
$elements{"default"} = { required => 1, isscalar => 1};
$elements{"bits"} = { required => 0, isscalar => 1};
validateSubElements("field",1,$field,\%elements);
}
################################################################################
# Validates target type extension elements for correctness
################################################################################
sub validateTargetTypesExtension {
my($attributes) = @_;
my %elements = ( );
$elements{"id"} = { required => 1, isscalar => 1};
$elements{"attribute"} = { required => 1, isscalar => 1};
foreach my $targetTypeExtension (@{$attributes->{targetTypeExtension}})
{
validateSubElements("targetTypeExtension",1,
$targetTypeExtension,\%elements);
}
}
################################################################################
# Validates target type elements for correctness
################################################################################
sub validateTargetTypes {
my($attributes) = @_;
my %elements = ( );
$elements{"id"} = { required => 1, isscalar => 1};
$elements{"parent"} = { required => 0, isscalar => 1};
$elements{"attribute"} = { required => 0, isscalar => 0};
$elements{"fspOnly"} = { required => 0, isscalar => 0};
$elements{"compileAttribute"} = { required => 0, isscalar => 0};
$elements{"parent_type"} = { required => 0, isscalar => 0};
foreach my $targetType (@{$attributes->{targetType}})
{
validateSubElements("targetType",1,$targetType,\%elements);
}
}
################################################################################
# Validates target instance elements for correctness
################################################################################
sub validateTargetInstances{
my($attributes) = @_;
my %elements = ( );
$elements{"id"} = { required => 1, isscalar => 1};
$elements{"type"} = { required => 1, isscalar => 1};
$elements{"attribute"} = { required => 0, isscalar => 0};
$elements{"compileAttribute"} = { required => 0, isscalar => 0};
foreach my $targetInstance (@{$attributes->{targetInstance}})
{
validateSubElements("targetInstance",1,$targetInstance,\%elements);
}
}
################################################################################
# Convert Target_t PHYS_PATH into Peer target's HUID - FSP Specific
################################################################################
sub handleTgtPtrAttributesFsp
{
my($attributes) = @_;
# replace PEER_TARGET attribute<PHYS_PATH> value with PEER's HUID
foreach my $targetInstance (@{${$attributes}->{targetInstance}})
{
foreach my $attr (@{$targetInstance->{attribute}})
{
if (exists $attr->{default})
{
if( ($attr->{default} ne "NULL")
&& ($attr->{id} eq "PEER_TARGET") )
{
my $peerHUID = INVALID_HUID;
$peerHUID = getPeerHuid($targetInstance);
if($peerHUID == INVALID_HUID)
{
croak("HUID for Peer Target not found for "
. "Peer Target [$attr->{default}]\n");
}
elsif($peerHUID == PEER_HUID_NOT_PRESENT)
{
# Might require this for debug, so keeping it.
#print STDOUT "****PEER HUID Attribut not present for "
# . "Peer Target [$attr->{default}]... Skip\n";
$attr->{default} = "NULL";
}
else
{
$attr->{default} =
sprintf("0x%X",(hex($peerHUID) << 32));
}
}
}
}
}
}
################################################################################
# Convert PHYS_PATH into index for Target_t attribute's value
################################################################################
sub handleTgtPtrAttributesHb{
my($attributes, $Target_t) = @_;
my $aId = 0;
${$Target_t}{'NULL'} = $aId;
foreach my $attribute (@{${$attributes}->{attribute}})
{
$aId++;
if(exists $attribute->{simpleType} &&
exists $attribute->{simpleType}->{'Target_t'})
{
${$Target_t}{"$attribute->{id}"} = $aId;
}
}
my %TargetList = ();
my $index = 1;
# Mapping instance's PHYS_PATH to index (1-base)
foreach my $targetInstance (@{${$attributes}->{targetInstance}})
{
foreach my $attr (@{$targetInstance->{attribute}})
{
if ($attr->{id} eq "PHYS_PATH")
{
$TargetList{$attr->{default}} = $index++;
last;
}
}
}
# replace Target_t attribute's value with instance's index
foreach my $targetInstance (@{${$attributes}->{targetInstance}})
{
foreach my $attr (@{$targetInstance->{attribute}})
{
# An instance has a Target_t attribute
if(exists ${$Target_t}{$attr->{id}})
{
if (exists $TargetList{$attr->{default}})
{
$attr->{default} = $TargetList{$attr->{default}};
}
else
{
print STDOUT ("$attr->{id} attribute has an unknown value "
. "$attr->{default}\n"
. "It must be NULL or a valid PHYS_PATH\n");
$attr->{default} = "NULL";
}
}
}
}
}
sub getPeerHuid
{
my($targetInstance) = @_;
my $peerHUID = PEER_HUID_NOT_PRESENT;
if(exists $targetInstance->{compileAttribute})
{
foreach my $compileAttribute (@{$targetInstance->{compileAttribute}})
{
if($compileAttribute->{id} eq "PEER_HUID")
{
$peerHUID = $compileAttribute->{default};
last;
}
}
}
return $peerHUID;
}
sub SOURCE_FILE_GENERATION_FUNCTIONS { }
# FAPI2 ATTRIBUTE SUPPORT
################################################################################
# Writes the FAPI2 plat attribute macros header file header
################################################################################
sub writeFapi2PlatAttrMacrosHeaderFileHeader {
my($outFile) = @_;
print $outFile <<VERBATIM;
#ifndef FAPI2_FAPIPLATATTRMACROS_H
#define FAPI2_FAPIPLATATTRMACROS_H
/**
* \@file fapi2platattrmacros.H
*
* \@brief FAPI2 -> HB attribute mappings. This file is autogenerated and
* should not be altered.
*/
//******************************************************************************
// Includes
//******************************************************************************
// STD
#include <stdint.h>
//******************************************************************************
// Macros
//******************************************************************************
namespace fapiToTargeting
{
namespace fapi2
{
enum {
VERBATIM
}
################################################################################
# Writes the FAPI2 plat attribute macros
################################################################################
sub writeFapi2PlatAttrMacrosHeaderFileContent {
my($attributes,$fapiAttributes,$outFile) = @_;
my $macroSection = "";
my $attrSection = "";
my $typeSection = "";
foreach my $attribute (@{$attributes->{attribute}})
{
foreach my $hwpfToHbAttrMap (@{$attribute->{hwpfToHbAttrMap}})
{
if( !exists $hwpfToHbAttrMap->{id}
|| !exists $hwpfToHbAttrMap->{macro})
{
croak("id,macro fields required\n");
}
my $fapiReadable = 0;
my $fapiWriteable = 0;
my $instantiated = 0;
if ($cfgFapiAttributesXmlFile eq "")
{
#No FAPI attributes xml file specified
if(exists $attribute->{readable})
{
$macroSection .= ' #define ' . $hwpfToHbAttrMap->{id} .
"_GETMACRO(ID,PTARGET,VAL) \\\n" .
" FAPI2_PLAT_ATTR_SVC_GETMACRO_" .
$hwpfToHbAttrMap->{macro} . "(ID,PTARGET,VAL)\n";
$instantiated = 1;
}
if(exists $attribute->{writeable})
{
$macroSection .= ' #ifndef ' . $hwpfToHbAttrMap->{id} .
"_SETMACRO\n";
$macroSection .= ' #define ' . $hwpfToHbAttrMap->{id} .
"_SETMACRO(ID,PTARGET,VAL) \\\n" .
" FAPI2_PLAT_ATTR_SVC_SETMACRO_" .
$hwpfToHbAttrMap->{macro} . "(ID,PTARGET,VAL)\n";
$macroSection .= " #endif\n";
$instantiated = 1;
}
}
else
{
#FAPI attribute xml file specified - validate against FAPI attrs
foreach my $fapiAttr (@{$fapiAttributes->{attribute}})
{
if( (exists $fapiAttr->{id})
&& ($fapiAttr->{id} eq $hwpfToHbAttrMap->{id}) )
{
# Check that non-platInit attributes are in the
# volatile-zeroed section and have a direct mapping
if (! exists $fapiAttr->{platInit})
{
if ($hwpfToHbAttrMap->{macro} ne "DIRECT")
{
croak("FAPI non-platInit attr " .
"'$hwpfToHbAttrMap->{id}' is " .
"'$hwpfToHbAttrMap->{macro}', " .
"it must be DIRECT");
}
if ( (exists $fapiAttr->{persistent}))
{
if ($attribute->{persistency} ne "non-volatile")
{
croak("FAPI non-platInit attr " .
"'$hwpfToHbAttrMap->{id}' is " .
"'$attribute->{persistency}', " .
"it must be non-volatile");
}
}
else
{
# Check that platInit attributes
# have a non-volatile persistency
if($attribute->{persistency} ne
"volatile-zeroed")
{
croak("FAPI non-platInit attr " .
"'$hwpfToHbAttrMap->{id}' is " .
"'$attribute->{persistency}', " .
"it must be volatile-zeroed");
}
}
}
# All FAPI attributes are readable
$fapiReadable = 1;
if(exists $fapiAttr->{writeable})
{
$fapiWriteable = 1;
}
if(exists $attribute->{simpleType}->{enumeration})
{
die "Do not use enumerations for FAPI types! ".
$attribute->{id}."\n";
}
else
{
$typeSection .= " static_assert(sizeof(TARGETING::ATTR_". $attribute->{id}."_type) ==
sizeof(fapi2::". $fapiAttr->{id}."_Type), \"Size of attribute ATTR_". $attribute->{id}."_type is not equal to the size of ".
$fapiAttr->{id}."_Type , types dont match \" );\n";
}
last;
}
}
if($fapiReadable)
{
if(exists $attribute->{readable})
{
$macroSection .= ' #define ' . $hwpfToHbAttrMap->{id} .
"_GETMACRO(ID,PTARGET,VAL) \\\n" .
" FAPI2_PLAT_ATTR_SVC_GETMACRO_" .
$hwpfToHbAttrMap->{macro} . "(ID,PTARGET,VAL)\n";
$instantiated = 1;
}
else
{
croak("FAPI attribute $hwpfToHbAttrMap->{id} requires " .
"platform supply readable attribute.");
}
}
if($fapiWriteable)
{
if(exists $attribute->{writeable})
{
$macroSection .= ' #define ' . $hwpfToHbAttrMap->{id} .
"_SETMACRO(ID,PTARGET,VAL) \\\n" .
" FAPI2_PLAT_ATTR_SVC_SETMACRO_" .
$hwpfToHbAttrMap->{macro} . "(ID,PTARGET,VAL)\n";
$instantiated = 1;
}
else
{
croak("FAPI attribute $hwpfToHbAttrMap->{id} requires "
. "platform supply writeable attribute.");
}
}
}
if($instantiated)
{
$attrSection .=
$hwpfToHbAttrMap->{id} . " = " .
" TARGETING::ATTR_" .
$attribute->{id} . ",\n";
}
}
}
print $outFile $attrSection;
print $outFile "};\n\n";
print $outFile "} // End namespace platAttrSvc\n\n";
print $outFile "} // End namespace fapi2\n\n";
print $outFile $typeSection;
print $outFile "\n\n";
print $outFile $macroSection;
print $outFile "\n";
}
################################################################################
# Writes the plat attribute macros header file footer
################################################################################
sub writeFapi2PlatAttrMacrosHeaderFileFooter {
my($outFile) = @_;
print $outFile <<VERBATIM;
#endif // FAPI_FAPIPLATATTRMACROS_H
VERBATIM
}