Files
chipsec-chipsec/source/tool/chipsec/hal/ucode.py
T
CHIPSEC 0654edca19 Version 1.2.0
Revision 1.2.0
--------------

This version includes the following new or updated modules:

#. Merged common.secureboot.keys module into common.secureboot.variables
module
#. Updated tools.secureboot.te module to be able to test PE/TE issue on
Linux or UEFI shell
#. Updated tools.smm.smm_ptr module

This version includes the following updates:

#. Added the *controls* abstraction. Modules are encouraged to use
``get_control`` and ``set_control`` when interacting with platform
registers. This permits greater flexibility in case the register that
controls a given feature or configuration changes between platform
generations. The controls are defined in the platform XML file. At this
time, only a small number of controls are defined. We plan to move
existing modules over to this new mechanism.
#. Added XML Schema for the XML configuration files
#. Support for reading, writing, and listing UEFI variables from the
UEFI Shell environment has been added.
#. Added support for decompression while SPI flash parsing via
``decode`` or ``uefi decode`` commands in Linux
#. Added basic ACPI table parsing to HAL (RSDP, RSDT/XSDT, APIC, DMAR)
#. Added UEFI tables searching and parsing to HAL (EFI system table,
runtime services table, boot services table, DXE services table, EFI
configuration table)
#. Added DIMM Serial Presence Detect (SPD) ROM dumping and parsing to
HAL
#. Added ``uefi s3bootscript`` command parsing the S3 boot script to
chipsec_util.py
#. Added virtual-to-physical address translation function to
Linux/EFI/Windows helpers
#. Added support of server platforms (Haswell server and Ivy Town) to
chipset.py

This version has the following known issues:

#. Decompression of images in SPI flash parsing is not available in UEFI
shell.
#. When calling alloc_phys_mem, the argument to set maximum physical
address (max_pa) for allocation is ignored on linux. A message will be
printed in dmesg if the allocation is above the max_pa that is passed
in, but the call will return anyway.
#. UEFI Shell environment does not support ``cpuid`` or
``get_thread_count``. There are functions that simply warn that they are
not supported.
#. Size of PCIEXBAR (MMCFG) is calculated incorrectly
2015-06-09 16:48:26 -07:00

138 lines
5.4 KiB
Python

#!/usr/local/bin/python
#CHIPSEC: Platform Security Assessment Framework
#Copyright (c) 2010-2015, Intel Corporation
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#as published by the Free Software Foundation; Version 2.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
#Contact information:
#chipsec@intel.com
#
# -------------------------------------------------------------------------------
#
# CHIPSEC: Platform Hardware Security Assessment Framework
# (c) 2010-2012 Intel Corporation
#
# -------------------------------------------------------------------------------
"""
Microcode update specific functionality (for each CPU thread)
usage:
>>> ucode_update_id( 0 )
>>> load_ucode_update( 0, ucode_buf )
>>> update_ucode_all_cpus( 'ucode.pdb' )
>>> dump_ucode_update_header( 'ucode.pdb' )
"""
__version__ = '1.0'
import struct
import sys
from chipsec.logger import *
from chipsec.hal.physmem import *
from chipsec.hal.msr import *
from chipsec.file import *
IA32_MSR_BIOS_UPDT_TRIG = 0x79
IA32_MSR_BIOS_SIGN_ID = 0x8B
IA32_MSR_BIOS_SIGN_ID_STATUS = 0x1
from collections import namedtuple
class UcodeUpdateHeader( namedtuple('UcodeUpdateHeader', 'header_version update_revision date processor_signature checksum loader_revision processor_flags data_size total_size reserved1 reserved2 reserved3') ):
__slots__ = ()
def __str__(self):
return """
Microcode Update Header
--------------------------------
Header Version : 0x%08X
Update Revision : 0x%08X
Date : 0x%08X
Processor Signature : 0x%08X
Checksum : 0x%08X
Loader Revision : 0x%08X
Processor Flags : 0x%08X
Update Data Size : 0x%08X
Total Size : 0x%08X
Reserved1 : 0x%08X
Reserved2 : 0x%08X
Reserved3 : 0x%08X
""" % ( self.header_version, self.update_revision, self.date, self.processor_signature, self.checksum, self.loader_revision, self.processor_flags, self.data_size, self.total_size, self.reserved1, self.reserved2, self.reserved3 )
UCODE_HEADER_SIZE = 0x30
def dump_ucode_update_header( pdb_ucode_buffer ):
ucode_header = UcodeUpdateHeader( *struct.unpack_from( '12I', pdb_ucode_buffer ) )
print ucode_header
return ucode_header
def read_ucode_file( ucode_filename ):
ucode_buf = read_file( ucode_filename )
if (ucode_filename.endswith('.pdb')):
if logger().VERBOSE:
logger().log( "[ucode] PDB file '%.256s' has ucode update header (size = 0x%X)" % (ucode_filename, UCODE_HEADER_SIZE) )
dump_ucode_update_header( ucode_buf )
return ucode_buf[UCODE_HEADER_SIZE:]
else:
return ucode_buf
class Ucode:
def __init__( self, cs ):
self.helper = cs.helper
self.cs = cs
# @TODO remove later/replace with msr.get_cpu_thread_count()
def get_cpu_thread_count( self ):
(core_thread_count, dummy) = self.helper.read_msr( 0, Cfg.IA32_MSR_CORE_THREAD_COUNT )
return (core_thread_count & Cfg.IA32_MSR_CORE_THREAD_COUNT_THREADCOUNT_MASK)
def ucode_update_id(self, cpu_thread_id):
#self.helper.write_msr( cpu_thread_id, IA32_MSR_BIOS_SIGN_ID, 0, 0 )
#self.helper.cpuid( cpu_thread_id, 0 )
(bios_sign_id_lo, bios_sign_id_hi) = self.helper.read_msr( cpu_thread_id, IA32_MSR_BIOS_SIGN_ID )
ucode_update_id = bios_sign_id_hi
if (bios_sign_id_lo & IA32_MSR_BIOS_SIGN_ID_STATUS):
if logger().VERBOSE: logger().log( "[ucode] CPU%d: last Microcode update failed (current microcode id = 0x%08X)" % (cpu_thread_id, ucode_update_id) )
else:
if logger().VERBOSE: logger().log( "[ucode] CPU%d: Microcode update ID = 0x%08X" % (cpu_thread_id, ucode_update_id) )
return ucode_update_id
def update_ucode_all_cpus(self, ucode_file ):
if not ( os.path.exists(ucode_file) and os.path.isfile(ucode_file) ):
logger().error( "Ucode file not found: '%.256s'" % ucode_file )
return False
ucode_buf = read_ucode_file( ucode_file )
if (ucode_buf is not None) and (len(ucode_buf) > 0):
for tid in range(self.get_cpu_thread_count()):
self.load_ucode_update( tid, ucode_buf )
return True
def update_ucode(self, cpu_thread_id, ucode_file ):
if not ( os.path.exists(ucode_file) and os.path.isfile(ucode_file) ):
logger().error( "Ucode file not found: '%.256s'" % ucode_file )
return False
_ucode_buf = read_ucode_file( ucode_file )
return self.load_ucode_update( cpu_thread_id, _ucode_buf )
def load_ucode_update(self, cpu_thread_id, ucode_buf ):
if logger().HAL: logger().log( "[ucode] loading microcode update on CPU%d" % cpu_thread_id )
self.helper.load_ucode_update( cpu_thread_id, ucode_buf )
return self.ucode_update_id( cpu_thread_id )