[edk2-devel] [PATCH 09/12] Scripts: Add bootlog decyphering script
Alexander Graf via groups.io
graf=amazon.com at groups.io
Fri May 27 02:43:14 UTC 2022
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 at 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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#90071): https://edk2.groups.io/g/devel/message/90071
Mute This Topic: https://groups.io/mt/91368911/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list