in tools/manifest_tools/manifest_parser.py [0:0]
def process_pcd (root, xml_file):
"""
Process PCD XML and generate list of element and attribute values.
:param root: XML to utilize
:param xml_file: Filename of XML
:return List of PCD values, manifest version, boolean for whether manifest is for an empty PCD
"""
xml = {}
result = xml_extract_attrib (root, XML_SKU_ATTRIB, True, xml_file)
xml.update ({"platform_id":result})
result = xml_extract_attrib (root, XML_VERSION_ATTRIB, False, xml_file)
xml.update ({"version":int (result, 16)})
result = xml_extract_attrib (root, XML_EMPTY_ATTRIB, True, xml_file, False)
if result and result.lower () == "true":
return xml, manifest_types.VERSION_2, True
rot = xml_find_single_tag (root, XML_ROT_TAG, xml_file)
xml["rot"] = {}
result = xml_extract_attrib (rot, XML_TYPE_ATTRIB, True, xml_file)
if result == PCD_ROT_TYPE_PA_ROT:
result = 0
elif result == PCD_ROT_TYPE_AC_ROT:
result = 1
else:
raise ValueError ("Unknown RoT type: {0}".format (result))
xml["rot"].update ({"type":result})
result = xml_extract_attrib (rot, XML_MCTP_CTRL_TIMEOUT_ATTRIB, False, xml_file)
xml["rot"].update ({"mctp_ctrl_timeout":int (result)})
result = xml_extract_attrib (rot, XML_MCTP_BRIDGE_GET_TABLE_WAIT_ATTRIB, False, xml_file)
xml["rot"].update ({"mctp_bridge_get_table_wait":int (result)})
ports = xml_find_single_tag (rot, XML_PORTS_TAG, xml_file, False)
if ports is not None:
xml["rot"]["ports"] = {}
for port in ports.findall (XML_PORT_TAG):
port_id = xml_extract_attrib (port, XML_ID_ATTRIB, False, xml_file)
xml["rot"]["ports"][port_id] = {}
result = xml_extract_single_value (port, {"spi_freq": XML_SPIFREQ_TAG,
"flash_mode": XML_FLASHMODE_TAG, "reset_ctrl": XML_RESETCTRL_TAG,
"policy": XML_POLICY_TAG, "pulse_interval": XML_PULSEINTERVAL_TAG,
"runtime_verification": XML_RUNTIMEVERIFICATION_TAG,
"watchdog_monitoring": XML_WATCHDOGMONITORING_TAG,
"host_reset_action": XML_HOSTRESETACTION_TAG}, xml_file)
if result["flash_mode"] == PCD_FLASH_MODE_DUAL:
result["flash_mode"] = 0
elif result["flash_mode"] == PCD_FLASH_MODE_SINGLE:
result["flash_mode"] = 1
elif result["flash_mode"] == PCD_FLASH_MODE_DUAL_FILTERED_BYPASS:
result["flash_mode"] = 2
elif result["flash_mode"] == PCD_FLASH_MODE_SINGLE_FILTERED_BYPASS:
result["flash_mode"] = 3
else:
raise ValueError ("Unknown port {0} flash mode: {1}".format (port_id,
result["flash_mode"]))
if result["reset_ctrl"] == PCD_RESET_CTRL_NOTIFY:
result["reset_ctrl"] = 0
elif result["reset_ctrl"] == PCD_RESET_CTRL_RESET:
result["reset_ctrl"] = 1
elif result["reset_ctrl"] == PCD_RESET_CTRL_PULSE:
result["reset_ctrl"] = 2
else:
raise ValueError ("Unknown port {0} reset control: {1}".format (port_id,
result["reset_ctrl"]))
if result["policy"] == PCD_POLICY_PASSIVE:
result["policy"] = 0
elif result["policy"] == PCD_POLICY_ACTIVE:
result["policy"] = 1
else:
raise ValueError ("Unknown port {0} policy: {1}".format (port_id, result["policy"]))
if result["runtime_verification"] == PCD_DISABLED:
result["runtime_verification"] = 0
elif result["runtime_verification"] == PCD_ENABLED:
result["runtime_verification"] = 1
else:
raise ValueError ("Unknown port {0} runtime verification setting: {1}".format (
port_id, result["runtime_verification"]))
if result["watchdog_monitoring"] == PCD_DISABLED:
result["watchdog_monitoring"] = 0
elif result["watchdog_monitoring"] == PCD_ENABLED:
result["watchdog_monitoring"] = 1
else:
raise ValueError ("Unknown port {0} watchdog monitoring setting: {1}".format (
port_id, result["watchdog_monitoring"]))
if result["host_reset_action"] == PCD_HOST_RESET_ACTION_NONE:
result["host_reset_action"] = 0
elif result["host_reset_action"] == PCD_HOST_RESET_ACTION_RESET_FLASH:
result["host_reset_action"] = 1
else:
raise ValueError ("Unknown port {0} host reset action: {1}".format (port_id,
result["host_reset_action"]))
xml["rot"]["ports"].update ({port_id:result})
interface = xml_find_single_tag (rot, XML_INTERFACE_TAG, xml_file)
xml["rot"]["interface"] = {}
interface_type = xml_extract_attrib (interface, XML_TYPE_ATTRIB, True, xml_file)
if interface_type == PCD_INTERFACE_TYPE_I2C:
interface_type = 0
else:
raise ValueError ("Unknown RoT interface type: {0}".format (interface_type))
xml["rot"]["interface"].update ({"type":interface_type})
result = xml_extract_single_value (interface, {"address": XML_ADDRESS_TAG,
"rot_eid": XML_ROT_EID_TAG, "bridge_eid": XML_BRIDGE_EID_TAG,
"bridge_address": XML_BRIDGE_ADDRESS_TAG}, xml_file)
result["address"] = int (result["address"], 16)
result["rot_eid"] = int (result["rot_eid"], 16)
result["bridge_eid"] = int (result["bridge_eid"], 16)
result["bridge_address"] = int (result["bridge_address"], 16)
xml["rot"]["interface"].update (result)
power_controller = xml_find_single_tag (root, XML_POWER_CONTROLLER_TAG, xml_file, False)
if power_controller is not None:
xml["power_controller"] = {}
interface = xml_find_single_tag (power_controller, XML_INTERFACE_TAG, xml_file)
xml["power_controller"]["interface"] = {}
interface_type = xml_extract_attrib (interface, XML_TYPE_ATTRIB, True, xml_file)
if interface_type == PCD_INTERFACE_TYPE_I2C:
interface_type = 0
else:
print ("Unknown PowerController interface type: {0}".format (interface_type))
xml["power_controller"]["interface"].update ({"type":interface_type})
result = xml_extract_single_value (interface, {"bus": XML_BUS_TAG,
"eid": XML_EID_TAG, "address": XML_ADDRESS_TAG, "i2c_mode": XML_I2CMODE_TAG}, xml_file)
result["eid"] = int (result["eid"], 16)
result["address"] = int (result["address"], 16)
if result["i2c_mode"] is None:
raise ValueError ("PowerController missing I2C mode")
if result["i2c_mode"] == PCD_INTERFACE_I2C_MODE_MM:
result["i2c_mode"] = 0
elif result["i2c_mode"] == PCD_INTERFACE_I2C_MODE_MS:
result["i2c_mode"] = 1
else:
raise ValueError ("Unknown PowerController interface I2C mode: {0}".format (
result["i2c_mode"]))
xml["power_controller"]["interface"].update (result)
muxes = xml_find_single_tag (interface, XML_MUXES_TAG, xml_file, False)
if muxes is not None:
xml["power_controller"]["interface"]["muxes"] = {}
for mux in muxes.findall (XML_MUX_TAG):
level = xml_extract_attrib (mux, XML_LEVEL_ATTRIB, False, xml_file)
result = xml_extract_single_value (mux, {"address": XML_ADDRESS_TAG,
"channel": XML_CHANNEL_TAG}, xml_file)
result["address"] = int (result["address"], 16)
xml["power_controller"]["interface"]["muxes"].update ({level:result})
components = xml_find_single_tag (root, XML_COMPONENTS_TAG, xml_file, False)
if components is not None:
xml["components"]= []
for component in components.findall (XML_COMPONENT_TAG):
curr_component = {}
result = xml_extract_attrib (component, XML_TYPE_ATTRIB, True, xml_file)
curr_component.update ({"type":result})
result = xml_extract_attrib (component, XML_ATTESTATION_SUCCESS_RETRY_ATTRIB,
False, xml_file)
curr_component.update ({"attestation_success_retry":int (result)})
result = xml_extract_attrib (component, XML_ATTESTATION_FAIL_RETRY_ATTRIB, False,
xml_file)
curr_component.update ({"attestation_fail_retry":int (result)})
result = xml_extract_attrib (component,
XML_ATTESTATION_RSP_NOT_READY_MAX_DURATION_ATTRIB, False, xml_file)
curr_component.update ({"attestation_rsp_not_ready_max_duration":int (result)})
result = xml_extract_attrib (component, XML_ATTESTATION_RSP_NOT_READY_MAX_RETRY_ATTRIB,
False, xml_file)
curr_component.update ({"attestation_rsp_not_ready_max_retry":int (result)})
cnxn_type = xml_extract_attrib (component, XML_CONNECTION_ATTRIB, True, xml_file)
if cnxn_type == PCD_COMPONENT_CONNECTION_DIRECT:
curr_component.update ({"connection":PCD_COMPONENT_CONNECTION_DIRECT})
interface = xml_find_single_tag (component, XML_INTERFACE_TAG, xml_file)
curr_component["interface"] = {}
interface_type = xml_extract_attrib (interface, XML_TYPE_ATTRIB, True, xml_file)
if interface_type == PCD_INTERFACE_TYPE_I2C:
interface_type = 0
else:
raise ValueError ("Unknown component {0} interface type: {1}".format (
curr_component["type"], interface_type))
curr_component["interface"].update ({"type":interface_type})
result = xml_extract_single_value (interface, {"bus": XML_BUS_TAG,
"eid": XML_EID_TAG, "address": XML_ADDRESS_TAG, "i2c_mode": XML_I2CMODE_TAG},
xml_file)
result["eid"] = int (result["eid"], 16)
result["address"] = int (result["address"], 16)
if result["i2c_mode"] is None:
raise ValueError ("Component {0} missing I2C mode".format (
curr_component["type"]))
if result["i2c_mode"] == PCD_INTERFACE_I2C_MODE_MM:
result["i2c_mode"] = 0
elif result["i2c_mode"] == PCD_INTERFACE_I2C_MODE_MS:
result["i2c_mode"] = 1
else:
print ("Unknown component {0} interface I2C mode: {1}".format (
curr_component["type"], result["i2c_mode"]))
curr_component["interface"].update (result)
muxes = xml_find_single_tag (interface, XML_MUXES_TAG, xml_file, False)
if muxes is not None:
curr_component["interface"]["muxes"] = {}
for mux in muxes.findall (XML_MUX_TAG):
level = xml_extract_attrib (mux, XML_LEVEL_ATTRIB, False, xml_file)
result = xml_extract_single_value (mux, {"address": XML_ADDRESS_TAG,
"channel": XML_CHANNEL_TAG}, xml_file)
result["address"] = int (result["address"], 16)
curr_component["interface"]["muxes"].update ({level:result})
elif cnxn_type == PCD_COMPONENT_CONNECTION_MCTP_BRIDGE:
curr_component.update ({"connection":PCD_COMPONENT_CONNECTION_MCTP_BRIDGE})
count = xml_extract_attrib (component, XML_COUNT_ATTRIB, False, xml_file)
curr_component.update ({"count": int (count)})
result = xml_extract_attrib (component, XML_DISCOVERY_FAIL_RETRY_ATTRIB, False,
xml_file)
curr_component.update ({"discovery_fail_retry":int (result)})
result = xml_extract_attrib (component, XML_MCTP_BRIDGE_ADDITIONAL_TIMEOUT_ATTRIB,
False, xml_file)
curr_component.update ({"mctp_bridge_additional_timeout":int (result)})
result = xml_extract_single_value (component, {"eid": XML_EID_TAG,
"deviceid": XML_DEVICE_ID_TAG, "vendorid": XML_VENDOR_ID_TAG,
"subdeviceid": XML_SUB_DEVICE_ID_TAG, "subvendorid": XML_SUB_VENDOR_ID_TAG},
xml_file)
result["eid"] = int (result["eid"], 16)
result["deviceid"] = int (result["deviceid"], 16)
result["vendorid"] = int (result["vendorid"], 16)
result["subdeviceid"] = int (result["subdeviceid"], 16)
result["subvendorid"] = int (result["subvendorid"], 16)
curr_component.update (result)
else:
raise ValueError ("Unknown component {0} connection type: {1}".format (
curr_component["type"], cnxn_type))
result = xml_extract_single_value (component, {"policy": XML_POLICY_TAG}, xml_file)
if result["policy"] == PCD_POLICY_PASSIVE:
result["policy"] = 0
elif result["policy"] == PCD_POLICY_ACTIVE:
result["policy"] = 1
else:
raise ValueError ("Unknown component {0} policy: {1}".format (
curr_component["type"], result["policy"]))
curr_component.update (result)
powerctrl = xml_find_single_tag (component, XML_PWRCTRL_TAG, xml_file)
curr_component["powerctrl"] = {}
result = xml_extract_single_value (powerctrl, {"register": XML_REGISTER_TAG,
"mask": XML_MASK_TAG}, xml_file)
result["register"] = int (result["register"], 16)
result["mask"] = int (result["mask"], 16)
curr_component["powerctrl"].update (result)
xml["components"].append (curr_component)
return xml, manifest_types.VERSION_2, False