* Add firmware data retrieval
* Apply suggestions from code review
* Remove FW info native versions from linux/win helpers and added results to info module
---------
Signed-off-by: Dan Scott <dan.scott@intel.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Nathaniel Mitchell <nathaniel.p.mitchell@intel.com>
Commit 99f9052438 ("Remove filehelper") removed `from_file` and
`to_file` from `OsHelper` but it remained in `BaseHelper`. Remove these
parameters too.
While at it, remove the similar parameters from the mock helper used in
tests.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
the test invalid pch mock helper returned fake pch id, but valid plat id,
if plat id matched xml file defined reqs_pch=true, will cause exception,
the mocked plat id corresponding xml is reqs_pch=true.
Signed-off-by: Jason Zhou <jun2.zhou@intel.com>
In tests, `read_phys_mem` could return strings instead of bytes, which
prevents detecting issues with `chipsec_util.py gdt` and
`chipsec_util.py idt`.
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
Currently `test_tpm_eventlog_firmware_blob` generates a TPM event with
16 bytes (`struct.pack("QQ",...)`) to check the decoding of
`EFIFirmwareBlob`. But the code expects a "native unsigned long", as
documented in `chipsec/hal/tpm_eventlog.py`:
class EFIFirmwareBlob(TcgPcrEvent):
# Although [4] 9.2.5 mentions UNIT64 for the length, [1] 7.7 uses
# a UINTN. Use a native unsigned long to cover the most general case.
_event_fmt = "@QL"
On Windows, the size of `unsigned long` is 32 bits, and the test fails:
File "d:\a\chipsec\chipsec\chipsec\hal\tpm_eventlog.py", line 115, in __init__
base, length = struct.unpack(self._event_fmt, self.event)
struct.error: unpack requires a buffer of 12 bytes
Use `"QL"` in the test in order to fix this test on Windows.
When running "python setup.py test" on Windows, the following failure is
reported:
======================================================================
ERROR: test_platform_invalid (tests.software.test_cs.TestPlatformChipsecCs)
----------------------------------------------------------------------
Traceback (most recent call last):
File "d:\a\chipsec\chipsec\tests\software\cs.py", line 46, in tearDown
os.remove(self.log_file)
PermissionError: [WinError 32] The process cannot access the file
because it is being used by another process:
'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmpg5_6bcaz'
This is because when `_cs.init()` (in `tests/software/cs.py`) throws an
exception, the temporary log file is not closed. Then the function
`TestChipsecUtil.tearDown` attempts to remove the temporary file with
`os.remove(self.log_file)` and it fails, as it is still used by the
logger.
Fix this by putting `_cs.init()` inside a `try`/`finally` construction
which always calls `logger.logger().close()` when an exception happens.
While at it, use `with open(...) as log` instead of `log.open()` +
`log.close()`, which is a more usual way of reading files in Python.
Updated mock_helper to use BaseHelper
Updated util harness to correctly override helper with testhelper
Signed-off-by: BrentHoltsclaw <brent.holtsclaw@intel.com>
* Updated util_cmds starting within d to use argparse
* Add get_thread_count to unittest mock_helper to fix unit_test error
Signed-off-by: BrentHoltsclaw <brent.holtsclaw@intel.com>
* More operation in chipsec_util reg command
Added write, read_field, write_field, get_control, set_control
operations
* reg read util command updated
Returned back "chipsec_util reg read" syntax and added tests.
* Commented out test_reg_get_control
Need to implement get_MMIO_BAR_base_address or read_pci_reg for SPIBAR
in mock_helper.py