public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Alexander Graf" <graf@amazon.com>
To: <devel@edk2.groups.io>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Dandan Bi <dandan.bi@intel.com>,
	Zhichao Gao <zhichao.gao@intel.com>,
	Liming Gao <gaoliming@byosoft.com.cn>
Subject: [PATCH 09/12] Scripts: Add bootlog decyphering script
Date: Fri, 27 May 2022 04:43:14 +0200	[thread overview]
Message-ID: <20220527024317.13476-10-graf@amazon.com> (raw)
In-Reply-To: <20220527024317.13476-1-graf@amazon.com>

The bootlog itself is a binary data structure that is not immediately human
readable. This commit adds a python script to generate a human readable form
of it with Linux dmesg like time stamp information.

The script can take multiple log sources and collate them into a single
output, making it easier to correlate messages.

Signed-off-by: Alexander Graf <graf@amazon.com>
---
 BaseTools/Scripts/ShowDebugLog.py | 88 +++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100755 BaseTools/Scripts/ShowDebugLog.py

diff --git a/BaseTools/Scripts/ShowDebugLog.py b/BaseTools/Scripts/ShowDebugLog.py
new file mode 100755
index 0000000000..f99b4b02f7
--- /dev/null
+++ b/BaseTools/Scripts/ShowDebugLog.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python3
+## @file
+#  Dump Bootlog files
+#
+#  Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.<BR>
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+
+from __future__ import print_function
+
+VersionNumber = '0.1'
+__copyright__ = "Copyright (c) 2022, Amazon Development Center Germany GmbH. All rights reserved.."
+
+import argparse
+import os
+import sys
+import struct
+
+class DebugLog:
+    """Parses a Bootlog blob and provides a string representation
+    """
+
+    def __init__(self, log):
+        self.entries = []
+        off = 0
+
+        signature, self.producer, extraheadertype, extraheadersize, msgextraheadersize, lastbyte, self.tickspersecond = struct.unpack_from('<4s4sHBBLQ', log)
+        if signature != b'BTLH':
+            raise Exception("File has incorrect signature. Expected b'BTLH'. Found %s." % signature)
+        if len(log) < lastbyte:
+            raise Exception("File smaller than total log contents (%d < %d). It was probably truncated." % (len(log), lastbyte))
+        off = 4 + 4 + 2 + 1 + 1 + 4 + 8 + extraheadersize
+
+        while off < lastbyte:
+            off = off + msgextraheadersize
+            time, = struct.unpack_from('<Q', log, off)
+            off = off + 8
+            msg = log[off:log.find(b'\0', off)]
+            off = off + len(msg) + 1
+            if self.tickspersecond != 0:
+                time = time / float(self.tickspersecond)
+            self.entries.append({ "time": time,
+                                  "msg": msg.decode("utf-8")})
+
+    def __str__(self):
+        if self.tickspersecond != 0:
+           fmt = "[%14.6f] %s"
+        else:
+           fmt = "[%14s] %s"
+        r = ""
+        newline = True
+        for entry in self.entries:
+          if newline:
+              r = r + fmt % (entry["time"], entry["msg"])
+          else:
+              r = r + "%s" % (entry["msg"])
+
+          try:
+              if entry["msg"][-1] == '\n':
+                  newline = True
+              else:
+                  newline = False
+          except:
+              pass
+
+        return r
+
+class DumpDebugLogApp:
+    """Dumps Configuration Table based Debug Logs."""
+
+    def __init__(self):
+        self.parse_options()
+
+        for source in self.args.source:
+            log = open(source, mode='rb').read()
+            print(DebugLog(log))
+
+    def parse_options(self):
+        parser = argparse.ArgumentParser(description=__copyright__)
+        parser.add_argument('--version', action='version',
+                            version='%(prog)s ' + VersionNumber)
+        parser.add_argument('source', nargs='+',
+                            help='[Debug Log Configuration Table]')
+        self.args = parser.parse_args()
+
+if __name__ == "__main__":
+    DumpDebugLogApp()
-- 
2.28.0.394.ge197136389




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879




  parent reply	other threads:[~2022-05-27  2:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-27  2:43 [PATCH 00/12] Introduce Bootlog DEBUG() output Alexander Graf
2022-05-27  2:43 ` [PATCH 01/12] MdePkg: Add DebugBootlog header Alexander Graf
2022-05-27  2:43 ` [PATCH 02/12] MdePkg: Add Null BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 03/12] MdePkg: Add Fallback timer support for BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 04/12] MdePkg: Add X86 " Alexander Graf
2022-05-27  2:43 ` [PATCH 05/12] MdePkg: Add ARM " Alexander Graf
2022-05-27  2:43 ` [PATCH 06/12] MdePkg: Add Pei phase BaseDebugBootlog Alexander Graf
2022-05-27  2:43 ` [PATCH 07/12] MdePkg: Add Dxe " Alexander Graf
2022-05-27  2:43 ` [PATCH 08/12] MdePkg: Add BaseDebugLibBootlog Alexander Graf
2022-05-27  2:43 ` Alexander Graf [this message]
2022-05-27  2:43 ` [PATCH 10/12] BaseDebugLibSerialPort: Include BaseDebugBootlog in all dscs Alexander Graf
2022-05-27  2:43 ` [PATCH 11/12] BaseDebugLibSerialPort: Emit messages to boot log Alexander Graf
2022-05-27  2:43 ` [PATCH 12/12] OvmfPkg/PlatformDebugLibIoPort: Add Bootlog support Alexander Graf
2022-06-01  9:33 ` [edk2-devel] [PATCH 00/12] Introduce Bootlog DEBUG() output Gerd Hoffmann
2022-06-01 16:58   ` Benjamin Doron
2022-06-02  8:35     ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220527024317.13476-10-graf@amazon.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox