Skip to content

Commit

Permalink
WIP: Add util subcmd to get efi variables from spi
Browse files Browse the repository at this point in the history
Signed-off-by: Nathaniel Mitchell <[email protected]>
  • Loading branch information
npmitche committed Mar 26, 2024
1 parent 0e8192c commit ea8a73d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion chipsec/hal/uefi.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,13 @@ def dump_EFI_variables_from_SPI(self) -> bytes:
return self.read_EFI_variables_from_SPI(0, 0x800000)

def read_EFI_variables_from_SPI(self, BIOS_region_base: int, BIOS_region_size: int) -> bytes:
rom = self.cs.spi.read_spi(BIOS_region_base, BIOS_region_size)
from chipsec.hal.spi import SPI
spi = SPI(self.cs)
rom = spi.read_spi(BIOS_region_base, BIOS_region_size)
efi_var_store = find_EFI_variable_store(rom, self._FWType)
if efi_var_store:
efi_vars = uefi_platform.EFI_VAR_DICT[self._FWType]['func_getefivariables']
breakpoint()
return efi_vars
return efi_var_store

Expand Down
23 changes: 23 additions & 0 deletions chipsec/utilcmd/uefi_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class UEFICommand(BaseCommand):
def requirements(self) -> toLoad:
if 'decode' in self.argv:
return toLoad.Nil
if 'var-spi-list' in self.argv:
return toLoad.All
return toLoad.Driver

def parse_arguments(self) -> None:
Expand Down Expand Up @@ -104,6 +106,10 @@ def parse_arguments(self) -> None:
parser_var_list = subparsers.add_parser('var-list')
parser_var_list.set_defaults(func=self.var_list)

# var-list command args
parser_var_list = subparsers.add_parser('var-spi-list')
parser_var_list.set_defaults(func=self.var_spi_list)

# var-find command args
parser_var_find = subparsers.add_parser('var-find')
parser_var_find.add_argument('name_guid', type=str, help='name or guid of variable to find')
Expand Down Expand Up @@ -225,6 +231,23 @@ def var_list(self):
self.logger.set_log_file(_orig_logname)
self.logger.log("[CHIPSEC] Variables are in efi_variables.lst log and efi_variables.dir directory")

def var_spi_list(self):
self.logger.log("[CHIPSEC] Enumerating all EFI variables via OS specific EFI Variable API..")
efi_vars = self._uefi.dump_EFI_variables_from_SPI()
if efi_vars is None:
self.logger.log("[CHIPSEC] Could not enumerate EFI Variables (Legacy OS?). Exit..")
return
self.logger.log("[CHIPSEC] Decoding EFI Variables..")
_orig_logname = self.logger.LOG_FILE_NAME
logname = "efi_variables_spi"
self.logger.set_log_file(f'{logname}.lst', False)
nvram_pth = f'{logname}.dir'
if not os.path.exists(nvram_pth):
os.makedirs(nvram_pth)
decode_EFI_variables(efi_vars, nvram_pth)
self.logger.set_log_file(_orig_logname)
self.logger.log(f"[CHIPSEC] Variables are in {logname}.lst log and {logname}.dir directory")

def var_find(self):
_vars = self._uefi.list_EFI_variables()
if _vars is None:
Expand Down

0 comments on commit ea8a73d

Please sign in to comment.