acrn-hypervisor/misc/config_tools/board_inspector/acpiparser/tpm2.py
Kunhui-Li 4bf53e4b83 config_tools: category based on different log levels
category based on different log levels:
1) If the board inspector show CRITICAL error messages, it means that the
board inspector tool exit instantly and generate no file.
2) If the board inspector show ERROR messages, it means that the board
inspector will generate the board XML file successfully, but several conditions
may result in ACRN build or boot failure cannot continue execution due to the error.
3) If the board inspector show WARNING messages, this means that the board inspector
generate the board XML file successfully, but this board XML file is lack of
some feature which could still boot ACRN but loss some features.
4) If the board inspector show INFO messages, this means that board inspector
printed out some normal information.
5) If the board inspector show DEBUG messages, this means that it is used to
debug board inspector workflow.

v1->v2
1. Keep the assertions or exceptions under the acpiparser, inspectorlib
and smbiosparser directory.
2. Exit after all check_deps() completes instead of any unsatisfied dep
is identified.
3. As Amy's advice, Replace the message "{board_xml} saved successfully" with
the message "SUCCESS: Board configuration file <file name> generated successfully
and saved to <path>."

To do:
Print all messages using the colored font.

Tracked-On: #6689
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Kunhui-Li <kunhuix.li@intel.com>
2022-02-17 14:49:25 +08:00

52 lines
1.9 KiB
Python

# Copyright (C) 2021 Intel Corporation. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
import ctypes
import logging
import inspectorlib.cdata as cdata
from acpiparser._utils import TableHeader
def tpm2_optional_data(data_len):
start_method_data_len = 0
has_log_area = False
if data_len <= 12:
start_method_data_len = data_len
elif data_len == 24:
start_method_data_len = 12
has_log_area = True
else:
start_method_data_len = 12
logging.debug(f"TPM2 data length: {data_len + 52} is greater than 64 bytes but less than 76 bytes.")
logging.debug(f"The TPM2 data is still processed but the 65 to {data_len + 52} bytes are discard.")
return start_method_data_len, has_log_area
def tpm2_factory(start_method_data_len, has_log_area):
class TPM2(cdata.Struct):
_pack_ = 1
_fields_ = [
('header', TableHeader),
('platform_class', ctypes.c_uint16),
('reserved', ctypes.c_uint16),
('address_of_control_area', ctypes.c_uint64),
('start_method', ctypes.c_uint32),
('start_method_specific_parameters', ctypes.c_ubyte * start_method_data_len),
] + ([
('log_area_minimum_length', ctypes.c_uint32),
('log_area_start_address', ctypes.c_uint64),
] if has_log_area else [])
return TPM2
def TPM2(val):
"""Create class based on decode of a TPM2 table from filename."""
if isinstance(val, str):
base_length = 52
data = open(val, mode='rb').read()
start_method_data_len, has_log_area = tpm2_optional_data(len(data) - base_length)
return tpm2_factory(start_method_data_len, has_log_area).from_buffer_copy(data)
elif isinstance(val, bytearray):
return tpm2_factory(12, True).from_buffer(val) if len(val) > 64 else tpm2_factory(12, False).from_buffer(val)