1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
|
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/usr/errl/parser/genErrlParsers.pl $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2013,2017
# [+] Google Inc.
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
# Purpose: Generates files needed to parse SRC and User Detail Data from
# Hostboot error logs. The files are delivered to the FSP and built there
#
# It scans the hostboot source code for the doxygen like error log tags and
# generates a C file for each component containing a function called by the FSP
# errl tool to parse the error log SRC, for example:
# - hbfwSrcParse1.C (For parsing errlogs generated by comp-id 0x01)
# - hbfwSrcParse2.C
# - hbfwSrcParse3.C
# It generates a file that contains IDs needed by the Hostboot User Detail Data
# parsers
# - hbfwUdIds.H
# It generates a makefile that builds the Hostboot SRC/UserDetailData parsers
# - makefile
use strict;
use Time::localtime;
#------------------------------------------------------------------------------
# Process Arguments
#------------------------------------------------------------------------------
my $DEBUG = 0;
my $base = ".";
my $outputDir = ".";
while( $ARGV = shift )
{
if( $ARGV =~ m/-b/ )
{
$base = shift;
}
elsif( $ARGV =~ m/-o/i )
{
$outputDir = shift;
}
elsif( $ARGV =~ m/-d/i )
{
$DEBUG = 1;
}
else
{
usage();
}
}
#------------------------------------------------------------------------------
# Global variables
#------------------------------------------------------------------------------
my $compIdFile = $base."/src/include/usr/hbotcompid.H";
my $compPath = $base."/src/usr";
my $compIncPath = $base."/src/include/usr";
my $compBlPath = $base."/src/bootloader";
my $compBlIncPath = $base."/src/include/bootloader";
my $genFilesPath = $base."/obj/genfiles";
my $hbfwTermRcFile = $genFilesPath."/hbfw_term_rc.H";
my $srcFileName = $genFilesPath."/srcListing";
my $errlTypes = $compIncPath."/errl/hberrltypes.H";
#------------------------------------------------------------------------------
# Call subroutines to populate the following arrays:
# - @reasonCodeFiles (The list of files to parse through for reason codes)
# - @filesToParse (The list of files to parse through for SRC tags)
# - @pluginDirsToParse (the list of plugin directories containing User Detail
# Data parsers)
#------------------------------------------------------------------------------
my @reasonCodeFiles;
my @filesToParse;
my @pluginDirsToParse;
getReasonCodeFiles($compIncPath);
getReasonCodeFiles($compBlIncPath);
getFilesToParse($compPath);
getFilesToParse($compIncPath);
getFilesToParse($genFilesPath);
getFilesToParse($compBlPath);
getFilesToParse($compBlIncPath);
getPluginDirsToParse($compPath);
#Add kernel/lib files for TI SRC descriptions
getReasonCodeFiles($base."/src/include/kernel");
getFilesToParse($base."/src/kernel");
getFilesToParse($base."/src/lib");
if ($DEBUG)
{
print("---> ReasonCode files to process\n");
foreach my $file(@reasonCodeFiles)
{
print("RC File: $file\n");
}
}
if ($DEBUG)
{
print("---> Files to parse for error log tags\n");
foreach my $file(@filesToParse)
{
print("File to Parse: $file\n");
}
}
if ($DEBUG)
{
print("---> Directories to parse for user detail data\n");
foreach my $dir(@pluginDirsToParse)
{
print("Plugin Directory to Parse: $dir\n");
}
}
#------------------------------------------------------------------------------
# Process the compIdFile, recording all of the component ID values
#------------------------------------------------------------------------------
my %compIdToValueHash;
my %compIdToHexValueHash;
open(COMP_ID_FILE, $compIdFile) or die("Cannot open: $compIdFile: $!");
while (my $line = <COMP_ID_FILE>)
{
# An example of the component ID line is:
# const compId_t DEVFW_COMP_ID = 0x0200;
if ($line =~ /^const compId_t (\w+) = 0x([\dA-Fa-f]+)00/)
{
my $compId = $1;
my $compValue = $2;
# Strip off any leading zeroes from the component value
$compValue =~ s/^0//g;
$compIdToValueHash{$compId} = $compValue;
# Need the integer value for compId sorting purposes
$compIdToHexValueHash{$compId} = hex $compValue;
}
}
close(COMP_ID_FILE);
if ($DEBUG)
{
print("---> Component ID values\n");
foreach my $key (keys %compIdToValueHash)
{
print ("CompId: $key = $compIdToValueHash{$key},\n");
}
}
#------------------------------------------------------------------------------
# Process the reasonCodeFiles, recording all of the module ids, reason codes
# and user detail data sections in hashes: The module ids and reason codes
# can be duplicated across components and so the namespace is also stored.
# Example hashes:
#
# %modIdToValueHash = (
# 'PNOR' => { 'MOD_PNORDD_ERASEFLASH' => '1A',
# 'MOD_PNORDD_READFLASH' => '12'},
# 'IBSCOM' => { 'IBSCOM_GET_TARG_VIRT_ADDR' => '03',
# 'IBSCOM_SANITY_CHECK' => '02'}
# );
#
# %rcToValueHash = (
# 'PNOR' => { 'RC_UNSUPPORTED_OPERATION' => '0607',
# 'RC_STARTUP_FAIL' => '0605'},
# 'IBSCOM' => { 'IBSCOM_INVALID_CONFIG' => '1C03',
# 'IBSCOM_INVALID_OP_TYPE' => '1C02'}
# );
#
# %udIdToValueHash = (
# 'HWPF_UDT_HWP_RCVALUE' => '0x01',
# 'ERRL_UDT_CALLOUT' => '0x07'
# );
#------------------------------------------------------------------------------
my %modIdToValueHash;
my %rcToValueHash;
my %udIdToValueHash;
open(TERM_RC_FILE, ">", "$hbfwTermRcFile") or die("Cannot open: $hbfwTermRcFile: $!");
# print header of file
print TERM_RC_FILE "#ifndef __HBFW_TERM_RC_H\n";
print TERM_RC_FILE "#define __HBFW_TERM_RC_H\n\n";
print TERM_RC_FILE "namespace HBFW\n{\n\n";
# print body of file
sub print_term_rc
{
my ($namespace, $enumName, @taggedLines) = @_;
# spaces in front to ensure correct headerfile format
print TERM_RC_FILE "namespace $namespace\n";
print TERM_RC_FILE "{\n";
print TERM_RC_FILE " $enumName\n";
print TERM_RC_FILE " {\n";
foreach my $line (@taggedLines)
{
print TERM_RC_FILE " $line\n";
}
print TERM_RC_FILE " };\n";
print TERM_RC_FILE "};\n\n";
}
foreach my $file (@reasonCodeFiles)
{
open(RC_FILE, $file) or die("Cannot open: $file: $!");
my $namespace = "NO_NS";
my $processing = 0;
my $processingModIds = 1;
my $processingRcs = 2;
my $processingUds = 3;
my $compId = "";
my $term_rc_tag = 0;
my $printEnum = 0;
my $enumName = "";
my @taggedLines;
while (my $line = <RC_FILE>)
{
if ($line =~ /^\s*namespace\s+(\w+)/)
{
if ($namespace ne "NO_NS")
{
print ("$0: Multiple namespaces in '$file'\n");
exit(1);
}
$namespace = $1;
next;
}
elsif ($line =~ /enum.+ModuleId/i)
{
$processing = $processingModIds;
next;
}
elsif ($line =~ /enum.+ReasonCode/i)
{
# avoids comment lines '@enum *ReasonCode'
if ($line !~ /\s*\@/ )
{
# requiring namespaces in reason code header files
if ($namespace eq "NO_NS")
{
print ("No namespace in '$file'\n");
exit(1);
}
# strip leading whitespace and trailing characters
$enumName = $line;
$enumName =~ s!^\s+!!;
chomp($enumName);
}
$processing = $processingRcs;
next;
}
elsif ($line =~ /enum.+UserDetail/i)
{
$processing = $processingUds;
next;
}
elsif ($line =~ /}/)
{
$processing = 0;
if ($printEnum)
{
print_term_rc($namespace, $enumName, @taggedLines);
$printEnum = 0;
}
next;
}
if ($processing == $processingModIds)
{
# Example: "MOD_PNORRP_WAITFORMESSAGE = 0x01"
if ($line =~ /(\w+)\s+=\s+0x([\dA-Fa-f]+)/)
{
$modIdToValueHash{$namespace}->{$1} = $2;
}
}
elsif ($processing == $processingRcs)
{
if ($line =~ /termination_rc/i)
{
$term_rc_tag = 1;
next;
}
if ($compId ne "")
{
# Reason code line does not contain Component ID
# Example: "RC_TARGET_NOT_DECONFIGURABLE = 0x01,"
if ($line =~ /(\w+)\s+=\s+0x([\dA-Fa-f]+)/)
{
if (! exists $compIdToValueHash{$compId})
{
print ("$0: Could not find CompID '$compId'\n");
exit(1);
}
$rcToValueHash{$namespace}->{$1} =
$compIdToValueHash{$compId} . $2;
# if comment tag "termination_rc" is above enum
# in reasoncode.H files
if($term_rc_tag)
{
my $line = $1." = 0x".
$rcToValueHash{$namespace}->{$1}.",";
push @taggedLines, $line;
$printEnum = 1;
$term_rc_tag = 0;
}
}
}
else
{
# Reason code line contains Component ID
# Example: "RC_INVALID_MESSAGE_TYPE = PNOR_COMP_ID | 0x01"
if ($line =~ /(\w+)\s+=\s+(\w+)\s+\|\s+0x([\dA-Fa-f]+)/)
{
if (! exists $compIdToValueHash{$2})
{
print ("$0: Could not find CompID '$2'\n");
exit(1);
}
$rcToValueHash{$namespace}->{$1} =
$compIdToValueHash{$2} . $3;
# if comment tag "termination_rc" is above enum
# in reasoncode.H files
if($term_rc_tag)
{
my $line = $1." = 0x".
$rcToValueHash{$namespace}->{$1}.",";
push @taggedLines, $line;
$printEnum = 1;
$term_rc_tag = 0;
}
}
}
}
elsif ($processing == $processingUds)
{
# Example: "HWPF_UDT_HWP_RCVALUE = 0x01,"
if ($line =~ /(\w+)\s+=\s+(0x[\dA-Fa-f]+)/)
{
my $udId = $1;
my $udValue = $2;
if (exists($udIdToValueHash{$udId}))
{
print ("$0: duplicate user data section in '$file'\n");
print ("$0: section is '$udId'\n");
exit(1);
}
$udIdToValueHash{$udId} = $udValue;
}
}
}
close(RC_FILE);
}
# print footer of file
print TERM_RC_FILE "};\n#endif\n";
close(TERM_RC_FILE);
if ($DEBUG)
{
print("---> ModuleId values\n");
foreach my $namespaceKey (keys %modIdToValueHash)
{
foreach my $modIdKey (keys %{$modIdToValueHash{$namespaceKey}})
{
print ("$namespaceKey:$modIdKey:$modIdToValueHash{$namespaceKey}->{$modIdKey}\n");
}
}
print("---> ReasonCode values\n");
foreach my $namespaceKey (keys %rcToValueHash)
{
foreach my $rcKey (keys %{$rcToValueHash{$namespaceKey}})
{
print ("$namespaceKey:$rcKey:$rcToValueHash{$namespaceKey}->{$rcKey}\n");
}
}
print("---> User Detail Data Section values\n");
foreach my $udKey (keys %udIdToValueHash)
{
print ("$udKey:$udIdToValueHash{$udKey}\n");
}
}
#------------------------------------------------------------------------------
# Generate the FSP hbfwUdIds.H file that contains the set of Hostboot component
# IDs and user detail data IDs. This is used by the user data parsers
#------------------------------------------------------------------------------
my $outputFileName = $outputDir . "/hbfwUdIds.H";
open(OFILE, ">", $outputFileName) or die("Cannot open: $outputFileName: $!");
print OFILE "// Automatically generated by Hostboot's $0\n";
print OFILE "// Do not modify this file in the FSP tree, it is provided by\n";
print OFILE "// Hostboot and will be overwritten\n";
print OFILE "//\n\n";
print OFILE "\#ifndef HBFWUDIDS_H\n";
print OFILE "\#define HBFWUDIDS_H\n\n";
print OFILE "// Hostboot component IDs\n";
print OFILE "namespace hbfw\n";
print OFILE "{\n";
print OFILE " enum\n";
print OFILE " {\n";
foreach my $key (keys %compIdToValueHash)
{
print OFILE " $key = 0x$compIdToValueHash{$key}00,\n";
}
print OFILE " };\n";
print OFILE "}\n\n";
print OFILE "// Hostboot User Detail Data IDs\n";
print OFILE "enum\n";
print OFILE "{\n";
foreach my $udKey (keys %udIdToValueHash)
{
print OFILE " $udKey = $udIdToValueHash{$udKey},\n";
}
print OFILE "};\n\n";
print OFILE "#endif\n";
close(OFILE);
#------------------------------------------------------------------------------
# Process the code files, looking for error log tags, save the parsing for each
# in a hash indexed by the component value
#------------------------------------------------------------------------------
my %compValueToParseHash;
my %rcModValuesUsed;
my %srcList;
my %displayDataEntries;
foreach my $file (@filesToParse)
{
open(PARSE_FILE, $file) or die("Cannot open: $file: $!");
my @namespaces;
push(@namespaces, "NO_NS");
#-------------------------------------------------------------------------
# Example Tag:
# /*@
# * @errortype
# * @reasoncode I2C_INVALID_OP_TYPE
# * @severity ERRL_SEV_UNRECOVERABLE
# * @moduleid I2C_PERFORM_OP
# * @userdata1 i_opType
# * @userdata2 addr
# * @devdesc Invalid Operation type.
# * @custdec Firmware Error
# */
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
while (my $line = <PARSE_FILE>)
{
if ($line =~ /namespace\s+(\w+)/)
{
# Found a namespace, record it to be used when searching for
# moduleid and reasoncode values
push(@namespaces, $1);
next;
}
if ($line =~ /\/\*\@/)
{
# Found the start of an error log tag
my $modId = "";
my $modIdValue = "";
my $rc = "";
my $rcValue = "";
my @userData;
my @userDataTextOnly;
my $desc = "";
my $cdesc = "";
# Read the entire error log tag into an array
my @tag;
while ($line = <PARSE_FILE>)
{
if ($line =~ /\*\//)
{
# Found the end of an error log tag
last;
}
push(@tag, $line);
}
# Process the error log tag
my $numLines = scalar (@tag);
for (my $lineNum = 0; $lineNum < $numLines; $lineNum++)
{
$line = $tag[$lineNum];
if ($line =~ /\@moduleid\s+(\S+)/i)
{
# Found a moduleid, find out the value
$modId = $1;
if ($modId =~ /(\w+)::(\w+)/)
{
# The namespace was provided
if ((exists $modIdToValueHash{$1}) &&
(exists ${modIdToValueHash{$1}->{$2}}))
{
$modIdValue = ${modIdToValueHash{$1}->{$2}};
}
}
else
{
# The namespace was not provided, look through all
# namespaces mentioned in the file
foreach my $namespace(@namespaces)
{
if ((exists $modIdToValueHash{$namespace}) &&
(exists ${modIdToValueHash{$namespace}->{$modId}}))
{
$modIdValue = ${modIdToValueHash{$namespace}->{$modId}};
last;
}
}
}
if ($modIdValue eq "")
{
print ("$0: Error finding moduleid value for '$file:$line'\n");
exit(1);
}
}
elsif ($line =~ /\@reasoncode\s+(\S+)/i)
{
# Found a reasoncode, figure out the value
$rc = $1;
if ($rc =~ /(\w+)::(\w+)/)
{
# The namespace was provided
if ((exists $rcToValueHash{$1}) &&
(exists ${rcToValueHash{$1}->{$2}}))
{
$rcValue = ${rcToValueHash{$1}->{$2}};
}
}
else
{
# The namespace was not provided, look through all
# namespaces mentioned in the file
foreach my $namespace(@namespaces)
{
if ((exists $rcToValueHash{$namespace}) &&
(exists ${rcToValueHash{$namespace}->{$rc}}))
{
$rcValue = ${rcToValueHash{$namespace}->{$rc}};
last;
}
}
}
if ($rcValue eq "")
{
print ("$0: Error finding reasoncode value for '$file:$line'\n");
exit(1);
}
}
elsif ($line =~ /\@(userdata\S+)\s+(\S+.*)/i)
{
# Found user data, strip out any double-quotes and trailing
# whitespace
my $udDesc = $1;
my $udText = $2;
$udText =~ s/\"//g;
$udText =~ s/\s+$//;
# Look for follow-on lines
for ($lineNum++; $lineNum < $numLines; $lineNum++)
{
$line = $tag[$lineNum];
if ($line =~ /\@/)
{
# Found the next element, rewind
$lineNum--;
last;
}
# Continuation of user data, strip out any double-quotes
# and leading / trailing whitespace
$line =~ s/^.+\*\s+//;
$line =~ s/\"//g;
$line =~ s/\s+$//;
if ($line ne "")
{
$udText = $udText . " " . $line;
}
}
my $udString = "\"$udDesc\", \"$udText\"";
push(@userData, $udString);
push(@userDataTextOnly, $udText);
}
elsif ($line =~ /\@devdesc\s+(\S+.*)/i)
{
# Found a description, strip out any double-quotes and
# trailing whitespace
$desc = $1;
$desc =~ s/\"//g;
$desc =~ s/\s+$//;
# Look for follow-on lines
for ($lineNum++; $lineNum < $numLines; $lineNum++)
{
$line = $tag[$lineNum];
if ($line =~ /\@/)
{
# Found the next element, rewind
$lineNum--;
last;
}
# Continuation of description, strip out any double-
# quotes and leading / trailing whitespace
$line =~ s/^.+\*\s+//;
$line =~ s/\"//g;
$line =~ s/\s+$//;
if ($line ne "")
{
$desc = $desc . " " . $line;
}
}
}
elsif ($line =~ /\@custdesc\s+(\S+.*)/i)
{
# Found a customer description. Strip out any
# double-quotes and trailing whitespace
$cdesc = $1;
$cdesc =~ s/\"//g;
$cdesc =~ s/\s+$//;
# Look for follow-on lines
for ($lineNum++; $lineNum < $numLines; $lineNum++)
{
$line = $tag[$lineNum];
if ($line =~ /\@/)
{
# Found the next element, rewind
$lineNum--;
last;
}
# Continuation of description, strip out any
# double-quotes and leading / trailing
# whitespace
$line =~ s/^.+\*\s+//;
$line =~ s/\"//g;
$line =~ s/\s+$//;
if ($line ne "")
{
$cdesc = $cdesc . " " . $line;
}
}
}
}
# Check that the required fields were found
if ($modId eq "")
{
print ("$0: moduleid missing from error log tag in '$file'\n");
print ("$0: reasoncode is '$rc'\n");
exit(1);
}
if ($rc eq "")
{
print ("$0: reasoncode missing from error log tag in '$file'\n");
print ("$0: moduleid is '$modId'\n");
exit(1);
}
if ($desc eq "")
{
print ("$0: description missing from error log tag in '$file'\n");
print ("$0: moduleid is '$modId', reasoncode is '$rc'\n");
exit(1);
}
# if no customer desc is provided, then use $desc
if ($cdesc eq "")
{
$cdesc =
"During processor/memory subsystem initialization,"
. " an error was encountered: $desc";
}
# SRC list - Don't add testcase SRCs
if(not $file =~ /\/test\//)
{
my $srcText = sprintf("%04X", hex($rcValue));
# eliminate dups
if($srcList{$srcText} eq "")
{
$srcList{$srcText} .= $cdesc;
}
}
# Create the combined returncode/moduleid value that the parser looks for and
# ensure that it is not a duplicate of one already found
my $rcModValue = $rcValue . $modIdValue;
if (exists($rcModValuesUsed{$rcModValue}))
{
print ("$0: duplicate moduleid/reasoncode error log tag in '$file'\n");
print ("$0: moduleid is '$modId', reasoncode is '$rc'\n");
exit(1);
}
$rcModValuesUsed{$rcModValue} = 1;
# Create the parser code for this error
my $parserCode = " case 0x$rcModValue:\n"
. " i_parser.PrintString(\"devdesc\", \"$desc\");\n"
. " i_parser.PrintString(\"moduleid\", \"$modId\");\n"
. " i_parser.PrintString(\"reasoncode\", \"$rc\");\n";
foreach my $udString(@userData)
{
$parserCode .= " i_parser.PrintString($udString);\n";
}
$parserCode .= " break;\n\n";
# Create the data entry code for this error
my $dataEntryCode = " {\n"
. " 0x$modIdValue, // Module Id\n"
. " 0x$rcValue, // ReasonCode\n"
. " \"$desc\",\n"
. " \"$modId\",\n"
. " \"$rc\",\n"
. " \"$userDataTextOnly[0]\",\n"
. " \"$userDataTextOnly[1]\"\n"
. " },\n\n";
# The component value is the first two characters of the 4 character rc
my $compValue = $rcValue;
$compValue =~ s/..$//;
# Add the parser code to compValueToParseHash
$compValueToParseHash{$compValue} .= $parserCode;
# Add the data entry code to displayDataEntries
$displayDataEntries{$modIdValue}{$rcValue} = $dataEntryCode;
}
}
close(PARSE_FILE);
}
#------------------------------------------------------------------
# Load the sybsystem values for the System Reference Codes (SRCs)
#------------------------------------------------------------------
my %subsysList;
my $in_enum = 0;
open(SUBSYSTEM_TYPES_FILE, $errlTypes) or die("Cannot open: $errlTypes: $!");
while (my $line = <SUBSYSTEM_TYPES_FILE> and $in_enum lt 2)
{
if($in_enum eq 0)
{
if($line =~ /^enum epubSubSystem_t/)
{
$in_enum = 1;
}
}
else
{
if(not $line =~/\@PUB_IGNORE/)
{
if($line =~ /^\s*EPUB_(\w+) += +0x([\dA-Fa-f]+),/)
{
my $epub_desc = $1;
my $epub_val = $2;
$subsysList{$epub_val} .= $epub_desc;
}
elsif($line =~ /.*^\}\;/)
{
$in_enum = 2;
}
}
}
}
close(SUBSYSTEM_TYPES_FILE);
# ------------------------------------------------------------------
# Generate a list of all possible SRCs and their descriptions
# ------------------------------------------------------------------
open(OFILE, ">", $srcFileName) or die ("Cannot open: $srcFileName: $!");
foreach my $sub (sort keys %subsysList)
{
foreach my $rcVal (sort keys %srcList)
{
my $src = "BC$sub$rcVal";
print OFILE "//////////////////////////////////////////////////////\n";
print OFILE "/****************************************************/\n";
print OFILE "#define Refcode_$src 0x$src\n";
print OFILE "/****************************************************/\n";
print OFILE "\n/***** $src RCDL text starts here.\n";
print OFILE "\$OWNER = J.Patel\n";
print OFILE "\$LOCATION = Austin\n";
print OFILE "\$COMPONENT = FSP\n";
print OFILE "\$MODULE = NA\n";
print OFILE "\$TYPE = AUTO\n\n";
print OFILE "\@SubsystemOrProduct = FSP_SRC\n\n";
my $txt = "\$DESCRIPTION = $srcList{$rcVal}";
if(not $txt =~/.*\.$/)
{
$txt = $txt.".";
}
my @atxt = split(/ +/,$txt);
my $word = shift(@atxt);
my $line_sz = length($word);
print OFILE "$word";
while (my $word = shift(@atxt))
{
if (lc $word eq "fsp")
{
$word = "service processor";
}
elsif (lc $word eq "fsp.")
{
$word = "service processor.";
}
my $wordlen = length($word);
$line_sz = $line_sz + $wordlen + 1;
if($line_sz > 76 )
{
$line_sz = $wordlen;
print OFILE "\n$word";
}
else
{
print OFILE " $word";
}
}
print OFILE "\n\$ENDDESCRIPTION\n\n";
print OFILE "\$RepairAction = The FRU callouts are calculated at the ".
"time of the failure.\n";
print OFILE "See the error log for the actual replacement strategy.\n";
print OFILE "\$ENDRepairAction\n\n";
print OFILE "\@REPORTING_LEVEL = Call_Home\n\n\n";
print OFILE " |------ Callout List ------|\n";
print OFILE " \$FRU = \$NOFRU\n\n";
print OFILE "***** $src RCDL text ends here. */\n\n\n";
}
}
close(OFILE);
#------------------------------------------------------------------------------
# For each component value, print a file containing the parse code
#------------------------------------------------------------------------------
my $timestamp = ctime();
my $imageId = getImageId();
foreach my $compValue (keys %compValueToParseHash)
{
my $outputFileName = $outputDir . "/hbfwSrcParse$compValue.C";
open(OFILE, ">", $outputFileName) or die("Cannot open: $outputFileName: $!");
print OFILE "/*\n";
print OFILE " * Automatically generated by Hostboot's $0\n";
print OFILE " * Do not modify this file in the FSP tree, it is provided by\n";
print OFILE " * Hostboot and will be overwritten\n";
print OFILE " *\n";
print OFILE " * TimeStamp: $timestamp\n";
print OFILE " * Image Id: $imageId\n";
print OFILE " *\n";
print OFILE " */\n\n";
print OFILE "#include <errlplugins.H>\n";
print OFILE "#include <errlusrparser.H>\n";
print OFILE "#include <srcisrc.H>\n\n";
print OFILE "static bool SrcDataParse(ErrlUsrParser & i_parser,\n";
print OFILE " const SrciSrc & i_src)\n";
print OFILE "{\n";
print OFILE " uint32_t l_error = (i_src.reasonCode() << 8) + i_src.moduleId();\n";
print OFILE " bool l_success = true;\n\n";
print OFILE " switch(l_error)\n";
print OFILE " {\n";
print OFILE $compValueToParseHash{$compValue};
print OFILE " default:\n";
print OFILE " l_success = false;\n";
print OFILE " break;\n";
print OFILE " };\n";
print OFILE " return l_success;\n";
print OFILE "}\n\n";
print OFILE "static errl::SrcPlugin g_SrcPlugin(0x$compValue";
print OFILE "00, SrcDataParse, ERRL_CID_HOSTBOOT);\n";
close(OFILE);
}
#------------------------------------------------------------------------------
# Figure out the user detail data files to compile for each component
#------------------------------------------------------------------------------
my %compValToUdFilesHash;
foreach my $dir(@pluginDirsToParse)
{
my $ofiles = "";
my $compId = "";
my $compVal = 0;
# Open the directory and read all entries (files) skipping any beginning
# with "."
my @dirEntries;
opendir(DH, $dir) or die("Cannot open $dir directory");
@dirEntries = grep { !/^\./ } readdir(DH);
closedir(DH);
# The plugin directory must contain a <COMP_ID>_Parse.C file which contains
# the user detail data parser for that component
foreach my $file(@dirEntries)
{
if ($file =~ /^(.+).C$/)
{
# Found a C file add it to the files to compile list
$ofiles .= "$1\.o ";
if ($file =~ /^(.+COMP_ID)_Parse.C$/)
{
# Found the main Parse.C file for a component
$compId = $1;
}
}
}
if ($compId eq "")
{
print ("$0: Could not find CompID Parser file in $dir\n");
exit(1);
}
# Find the component ID value
if (! exists $compIdToValueHash{"$compId"})
{
print ("$0: Could not find CompID $compId while processing $dir\n");
exit(1);
}
$compVal = $compIdToValueHash{$compId};
$compValToUdFilesHash{$compVal} = $ofiles;
}
#------------------------------------------------------------------------------
# Generate the FSP makefile that builds the Hostboot error log parsers
#------------------------------------------------------------------------------
$outputFileName = $outputDir . "/makefile";
open(OFILE, ">", $outputFileName) or die("Cannot open: $outputFileName: $!");
print OFILE "\# Automatically generated by Hostboot's $0\n";
print OFILE "\# Do not modify this file in the FSP tree, it is provided by\n";
print OFILE "\# Hostboot and will be overwritten\n";
print OFILE "\#\n";
print OFILE "CFLAGS += -DPARSER\n\n";
print OFILE "EXPLIBS =\n\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "\# Call PRD makefile for prdf plugins\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE ".if ( \$(CONTEXT) != \"x86.nfp\" )\n";
print OFILE "EXPLIB_SUBDIRS += prdf\n";
print OFILE "EXPSHLIB_SUBDIRS += prdf\n";
print OFILE ".else\n";
print OFILE "EXPLIB_SUBDIRS += prdf\n";
print OFILE ".endif\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "\# SRC Parsers\n";
print OFILE "\#-------------------------------------------------------------\n";
foreach my $compValue (keys %compValueToParseHash)
{
print OFILE ".if ( \$(CONTEXT) != \"x86.nfp\" )\n";
print OFILE "\tlibB-$compValue" . "00.so_OFILES = hbfwSrcParse$compValue.o\n";
print OFILE "\tlibB-$compValue" . "00.so_EXTRA_LIBS = libbase.so\n\n";
print OFILE ".else\n";
print OFILE "\tlibB-$compValue" . "00.a_OFILES = hbfwSrcParse$compValue.o\n";
print OFILE ".endif\n";
}
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "\# User Detail Data Parsers\n";
print OFILE "\#-------------------------------------------------------------\n";
foreach my $compValue (keys %compValToUdFilesHash)
{
print OFILE ".if ( \$(CONTEXT) != \"x86.nfp\" )\n";
print OFILE "libB-$compValue" . "00.so_OFILES += $compValToUdFilesHash{$compValue}\n";
print OFILE ".else\n";
print OFILE "libB-$compValue" . "00.a_OFILES += $compValToUdFilesHash{$compValue}\n";
print OFILE ".endif\n";
}
print OFILE ".if ( \$(CONTEXT) != \"x86.nfp\" )\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "\# Shared library for each component\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "SHARED_LIBRARIES = ";
foreach my $compValue (keys %compValueToParseHash)
{
print OFILE "libB-$compValue" . "00.so ";
}
print OFILE "\n.else\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "\# x86 mode generate an archive file for each component\n";
print OFILE "\#-------------------------------------------------------------\n";
print OFILE "LIBRARIES = ";
foreach my $compValue (keys %compValueToParseHash)
{
print OFILE "libB-$compValue" . "00.a ";
}
print OFILE "\nEXPLIBS = ";
foreach my $compValue (keys %compValueToParseHash)
{
print OFILE "libB-$compValue" . "00.a ";
}
print OFILE "\n.endif\n";
print OFILE "\n\n.include<\${RULES_MK}>\n";
close(OFILE);
#------------------------------------------------------------------------------
# Generate the errldisplaydata.C file that contains the set of Hostboot
# component IDs and detailed error data.
# Note: This file is placed one directory up from the other generated files
# because this is actually part of hostboot.
#------------------------------------------------------------------------------
$outputFileName = $outputDir . "/../errldisplaydata.C";
open(OFILE, ">", $outputFileName . ".tmp") or
die("Cannot open: $outputFileName.tmp: $!");
#------------------------------------------------------------------------------
# Helper function for sort method, convert hex string to decimal and compare
#------------------------------------------------------------------------------
sub hexToDecCmp
{
hex($a) <=> hex($b);
}
print OFILE "/*\n";
print OFILE " * Automatically generated by Hostboot's $0\n";
print OFILE " * Do not modify this file in the hostboot tree, it is automatically\n";
print OFILE " * generated every build.\n";
print OFILE " *\n";
print OFILE " * Image Id: $imageId\n";
print OFILE " *\n";
print OFILE " */\n\n";
print OFILE "#include <errldisplay/errldisplay.H>\n";
print OFILE "#include <stdlib.h>\n\n";
print OFILE "namespace ERRORLOGDISPLAY\n{\n\n";
print OFILE "// Error Info Table\n";
print OFILE "ErrLogDisplay::errLogInfo ErrLogDisplay::errorInfo [] = {\n";
foreach my $modID (sort hexToDecCmp keys(%displayDataEntries))
{
foreach my $rc (sort hexToDecCmp keys(%{$displayDataEntries{$modID}}))
{
print OFILE $displayDataEntries{$modID}{$rc};
}
}
#------------------------------------------------------------------------------
# Helper function for sort method, sorts by ascending values
#------------------------------------------------------------------------------
sub hashValueAsc
{
$compIdToHexValueHash{$a} <=> $compIdToHexValueHash{$b};
}
print OFILE "};\n";
print OFILE "uint16_t ErrLogDisplay::errorInfoTableSize = sizeof(errorInfo) / sizeof(errorInfo[0]);\n\n";
print OFILE "\n\n// Component Id Table\n";
print OFILE "#include <hbotcompid.H>\n";
print OFILE "ErrLogDisplay::compTableInfo ErrLogDisplay::compTable [] = {\n";
foreach my $key (sort hashValueAsc (keys(%compIdToHexValueHash)))
{
$key = substr($key,0,length($key)-3);
print OFILE " {" . $key . "_ID, " . $key . "_NAME},\n";
}
print OFILE "};\n";
print OFILE "uint16_t ErrLogDisplay::compTableSize = sizeof(compTable) / sizeof(compTable[0]);\n\n";
print OFILE "} // End Namespace\n";
close(OFILE);
use File::Compare;
use File::Copy;
if (compare($outputFileName . ".tmp", $outputFileName) != 0) {
move($outputFileName . ".tmp", $outputFileName) or
die("Cannot move $outputFileName.tmp to $outputFileName: $!");
}
else
{
unlink $outputFileName . ".tmp";
}
#------------------------------------------------------------------------------
# Subroutine that prints the usage
#------------------------------------------------------------------------------
sub usage
{
print "Usage: $0 <-b base> <-d> <-o output dir>\"\n";
print "\n";
print "-b: Base directory containing Hostboot src directory (default is pwd)\n";
print "-o: Output directory where files are created (default is pwd)\n";
print "-d Enable Debug messages.\n";
print "\n\n";
exit 1;
}
#------------------------------------------------------------------------------
# Subroutine that updates @reasonCodeFiles
#------------------------------------------------------------------------------
sub getReasonCodeFiles
{
# Open the input directory and read all entries (files/directories)
# Skipping any beginning with "."
my $inputDir = @_[0];
my @dirEntries;
opendir(DH, $inputDir) or die("Cannot open $inputDir directory");
@dirEntries = grep { !/^\./ } readdir(DH);
closedir(DH);
foreach my $dirEntry (@dirEntries)
{
my $dirEntryPath = "$inputDir/$dirEntry";
if (-d $dirEntryPath)
{
# Exclude PRD directory
if ( !($dirEntryPath =~ /prdf/) )
{
# Recursively call this function
getReasonCodeFiles($dirEntryPath);
}
}
elsif(($dirEntry =~ /reasoncodes/i) ||
($dirEntry =~ /service_codes/i) ||
($dirEntry =~ /examplerc/i))
{
# Found reason-codes file
push(@reasonCodeFiles, $dirEntryPath);
}
}
}
#------------------------------------------------------------------------------
# Subroutine that updates @filesToParse
#------------------------------------------------------------------------------
sub getFilesToParse
{
# Open the input directory and read all entries (files/directories)
# Skipping any beginning with "."
my $inputDir = @_[0];
my @dirEntries;
opendir(DH, $inputDir) or die("Cannot open $inputDir directory");
@dirEntries = grep { !/^\./ } readdir(DH);
closedir(DH);
foreach my $dirEntry (@dirEntries)
{
my $dirEntryPath = "$inputDir/$dirEntry";
if (-d $dirEntryPath)
{
# Exclude PRD directory
if ( !($dirEntryPath =~ /prdf/) )
{
# Recursively call this function
getFilesToParse($dirEntryPath);
}
}
elsif($dirEntry =~ /\.[H|C]$/)
{
# Found file to parse
push(@filesToParse, $dirEntryPath);
}
}
}
#------------------------------------------------------------------------------
# Subroutine that updates @pluginDirsToParse
#------------------------------------------------------------------------------
sub getPluginDirsToParse
{
# Open the input directory and read all entries (files/directories)
# Skipping any beginning with "."
my $inputDir = @_[0];
my @dirEntries;
opendir(DH, $inputDir) or die("Cannot open $inputDir directory");
@dirEntries = grep { !/^\./ } readdir(DH);
closedir(DH);
foreach my $dirEntry (@dirEntries)
{
my $dirEntryPath = "$inputDir/$dirEntry";
if (-d $dirEntryPath)
{
if ($dirEntryPath =~ /plugins/)
{
push(@pluginDirsToParse, $dirEntryPath);
}
else
{
# Exclude PRD directory
if ( !($dirEntryPath =~ /prdf/) )
{
# Recursively call this function
getPluginDirsToParse($dirEntryPath);
}
}
}
}
}
#------------------------------------------------------------------------------
# Subroutine that gets the Image ID
#------------------------------------------------------------------------------
sub getImageId
{
my $imageId = `git describe --dirty || echo Unknown-Image \`git rev-parse --short HEAD\``;
chomp $imageId;
if (($imageId =~ m/Unknown-Image/) || # Couldn't find git describe tag.
($imageId =~ m/dirty/) || # Find 'dirty' commit.
($imageId =~ m/^.{15}-[1-9]+/)) # Found commits after a tag.
{
$imageId = $imageId."/".$ENV{"USER"};
}
return $imageId;
}
|