summaryrefslogtreecommitdiffstats
path: root/src/build/debug/Hostboot/BlTrace.pm
blob: 1a3ee0ec27f4b70358afa5defb684bbf323ff020 (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
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/build/debug/Hostboot/BlTrace.pm $
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2016,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

use strict;

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

my %traceText = (
    "10" => "Main started",
    "11" => "Main getHBBSection returned",
    "12" => "Main handleMMIO to working location returned",
    "13" => "Main removeECC returned",
    "14" => "Main verify started",
    "15" => "Main verify succeeded",
    "16" => "Main copy HBB to running location done",
    "17" => "Main verify skip verification - no eyecatch ",
    # @TODO RTC:167740 TI on failed magic # check once signing is widespread
    "18" => "Main verify skip verification - no magic number ",
    "19" => "Main verify skip verification - SAB unset ",
    "20" => "HandleMMIO started",
    "21" => "HandleMMIO started using BYTESIZE",
    "24" => "HandleMMIO started using WORDSIZE",
    "28" => "HandleMMIO started using DBLWORDSIZE",
    "30" => "PNOR Access getHBBSection started",
    "31" => "PNOR Access findTOC handleMMIO to copy TOC ONE returned",
    "32" => "PNOR Access findTOC readTOC for TOC ONE returned",
    "33" => "PNOR Access findTOC handleMMIO to copy TOC TWO returned",
    "34" => "PNOR Access findTOC readTOC for TOC TWO returned",
    "35" => "PNOR Access getHBBSection findTOC returned",
    "41" => "PNOR Access readTOC zeroSection returned",
    "42" => "PNOR Access readTOC checkForNullBuffer returned",
    "43" => "PNOR Access readTOC performHdrChecksum returned",
    "44" => "PNOR Access readTOC checkHeader returned",
    "45" => "PNOR Access readTOC parseEntries returned",
    "D0" => "Main removeECC returned corrected ECC rc",
    "E0" => "Utils checkHeader magic invalid",
    "E1" => "Utils checkHeader version invalid",
    "E2" => "Utils checkHeader entry size invalid",
    "E3" => "Utils checkHeader entry count invalid",
    "E4" => "Utils checkHeader block size invalid",
    "E5" => "Utils checkHeader block count invalid",
    "E6" => "Utils checkHeader header size invalid",
    "E7" => "Utils parseEntries invalid section",
    "E8" => "Utils SectionIdToString PNOR section id out of range",
    "E9" => "Utils cmpSecurebootMagicNumber requested address to compare is a nullptr",
    "F0" => "Main getHBBSection returned",
    "F1" => "Main removeECC returned error",
    "F2" => "PNOR Access readTOC checkForNullBuffer null buffer",
    "F3" => "PNOR Access readTOC performHdrChecksum checksum error",
    "F4" => "PNOR Access readTOC checkHeader header error",
    "F5" => "PNOR Access readTOC parseEntries entry error",
    "F6" => "PNOR Access findTOC readTOC errors",
    "F7" => "Utils parseEntries checksum error",
    "F8" => "Utils parseEntries size extends beyond Flash",
    "F9" => "PNOR Access getHBBSection findTOC error",
    "FA" => "PNOR Access getHBBSection findTOC no HBB section",
    "FB" => "main verifyBaseImage failed",
);

sub formatTrace
{
    my $trace = shift;
    my $traceDataRaw = "";
    my $traceDataText = "";

    for (my $i = 0; $i < length($trace); $i++)
    {
        my $traceHexStr = sprintf("%02X", ord(substr($trace, $i, 1)));
        $traceDataRaw .= $traceHexStr;

        if ($i % 16 == 15)
        {
            $traceDataRaw .= "\n";
        }
        elsif ($i % 4 == 3)
        {
            $traceDataRaw .= "   ";
        }
        else
        {
            $traceDataRaw .= " ";
        }

        if (exists $traceText{$traceHexStr})
        {
            if ($traceText{$traceHexStr} ne "")
            {
                $traceDataText .= "$traceHexStr  $traceText{$traceHexStr}\n";
            }
            else
            {
                $traceDataText .= "$traceHexStr  NO TRACE TEXT FOUND - check BlTrace.pm\n";
            }
        }
        else
        {
            $traceDataText .= "$traceHexStr  UNKNOWN HEX FOUND - check BlTrace.pm\n";
        }
    }

    return $traceDataRaw."\n\n".$traceDataText;
}

sub main
{
    ::setBootloader();

    my $dataAddr = 0x0000000008208000;

    my $indexAddr = $dataAddr + 64;
    ::sendIPCMsg("read-data", "$indexAddr,1"); # Trace index is 1 byte
    my ($type1, $index) = ::recvIPCMsg();
    $index =~ s/\0+//g; #strip off nulls
    my $indexStr = sprintf("0x%02X", ord($index));

    ::userDisplay "\n------------Bootloader Trace------------";
    ::userDisplay "\nNext Entry Index: ";
    ::userDisplay $indexStr;

    my $traceAddr = $dataAddr;
    my $traceAddrStr = sprintf("0x%08X", $traceAddr);
    ::sendIPCMsg("read-data", "$traceAddr,64"); # Trace buffer is 64 bytes
    my ($type2, $trace) = ::recvIPCMsg();
    $trace =~ s/\0+//g; #strip off nulls
    my $traceData = formatTrace($trace);

    ::userDisplay "\n\nTrace Buffer Address: ";
    ::userDisplay $traceAddrStr;
    ::userDisplay "\n\nTrace Data:\n";
    ::userDisplay $traceData;
    ::userDisplay "\n--------------------------------------------\n";

    ::clearBootloader();
}

sub helpInfo
{
    my %info = (
        name => "BlTrace",
        intro => ["Displays the Bootloader trace buffer."],
    );
}
OpenPOWER on IntegriCloud