summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/Errl.pm
blob: 46d510b5a4c734b476e597d66dd210b6ab9d1c6d (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
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
# 
# $Source: src/build/debug/Hostboot/Errl.pm $
# 
# IBM CONFIDENTIAL
# 
# COPYRIGHT International Business Machines Corp. 2011,2012
# 
# p1
# 
# Object Code Only (OCO) source materials
# Licensed Internal Code Source Materials
# IBM HostBoot Licensed Internal Code
# 
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.
# 
# Origin: 30
# 
# IBM_PROLOG_END_TAG 

use strict;
use File::Temp;

package Hostboot::Errl;
use Exporter;
our @EXPORT_OK = ('main');


sub getTempFileName
{
    my $fh = File::Temp->new( TEMPLATE => 'tempXXXXX',
                              DIR => '/tmp',
                              SUFFIX => '.bin', );
    return $fh->filename;
}



sub main
{
    my $moduleName = shift;
    # print "Module name: $moduleName\n";

    my $listArg = " -l "; #  default action is to list
    my $displayArg = "";  #  for -d <error log id>
    my $traceArg = "";    #  for the name of the hbot string file

    my %hashh = %{(shift)};
    my $temp;
    foreach $temp (keys(%hashh))
    {
        # print "$temp=" . $hashh{$temp} . "\n";

        if ( $temp eq "display" )
        {
            $displayArg = " -d ".$hashh{$temp};

            # display <id> overrides default behavior to list them all
            $listArg = "";
        }
        elsif( $temp eq "trace" )
        {
            $traceArg = " -t ".$hashh{$temp};
        }
        elsif( length($temp) eq 0  )
        {
           ; # apparently $temp can be empty
        }
        else
        {
            ::userDisplay "Unknown parameter $temp\n";
            die;
        }
    }

    my ($symAddr, $symSize) = ::findSymbolAddress("ERRORLOG::g_ErrlStorage");
    if (not defined $symAddr)
    {
        ::userDisplay "Couldn't find symbol ERRORLOG::g_ErrlStorage\n";
        die;
    }
    $symAddr = ::read64($symAddr); # Dereference g_ErrlStorage pointer.

    # Size of buffer resides at offset zero of buffer for length of 4
    my $errlSize;
    $errlSize = ::read32( $symAddr );

    # read entire buffer
    my $errlBuffer;
    $errlBuffer = ::readData( $symAddr, $errlSize );

    # write buffer to a temporary file
    my $tempFile = getTempFileName();
    open( ERRLDATA, "> $tempFile" ) or die "Can not write temporary file $tempFile\n";
    binmode ERRLDATA;
    print ERRLDATA $errlBuffer;
    close( ERRLDATA );

    my $imagePath;
    $imagePath = ::getImgPath();
    if (not defined $imagePath)
    {
        ::userDisplay "Can not find img path to errlparser binary.\n";
        die;
    }

    my $errlParser;
    $errlParser = $imagePath."/errlparser";
    if( not  -x  $errlParser )
    {
        ::userDisplay "Can not find errlparser binary in img directory.\n";
        die;
    }

    if( length( $traceArg ) eq 0 )
    {
        # string file not given; supply a default if possible
        my $defaultStringFile = $imagePath."/hbotStringFile";
        if( -f  $defaultStringFile )
        {
            $traceArg = " -t ".$defaultStringFile;
        }
    }


    my $cmdLine;
    $cmdLine = "$errlParser $tempFile $displayArg $traceArg $listArg";
    # ::userDisplay "$cmdLine\n";
    open ERRLPARSER, "$cmdLine |";
    while (my $line = <ERRLPARSER>)
    {
        ::userDisplay $line;
    }

    # delete temporary file
    unlink( $tempFile );


    return 0;
}

sub helpInfo
{
    my %info = (
        name => "Errl",
        intro => ["List or display the error log entries."],
        options => {
                    "display=<id>|all" => ["<id> - Display a specific error log by id.",
                                           "all - Display all error logs in the repository."],
                   },
        notes => ["The default behavior is to list all the committed error logs unless",
                  "requested to display a specific error log or all error logs."]
    );
}

OpenPOWER on IntegriCloud