8/05/2024

EFI variable library - II

 Introduction

The EfiPyVariables module includes an iterable class named EfiPyVariables(). This class uses EfiPy2.gRT.GetNextVariableName() to enumerate each EFI variable and its GUID.

EfiPyVariables

This class has these object initialization parameters, Name, Guid and CaseSensitive. Then user script can use for loop to enumerate UEFI variables name and GUID by these parameters as filter condition.

Name:

    If this parameter is not None and it is substring of variable name, then the variable name/GUID will return to user script.

    If this parameter is None then UEFI variable name will not be in filter condition.

Guid:

    If this parameter is not None then each enumerating result will compare UEFI variable GUID to this parameter. And only comparing result TRUE will return to user script.

    If this parameter is None then UEFI variable GUID will not be in filter condition.

Above two parameters are logic AND combination when they are not None.

CaseSensitive:

    This parameter indicates whether the comparison of UEFI variable names is case-sensitive. Default is none case-sensitive.


The modules and its sample code is here (module) and here (sample code).

Example

from EfiPy2.MdePkg.Guid.GlobalVariable import gEfiGlobalVariableGuid

#

# Enumerate every UEFI variables

#

with Variables() as Vars:

  for n, g in Vars:

    print (n, g)

#

# Enumerate any UEFI variables which name include sub-string 'BOOT'

# It is none case-sensitve.

#

with Variables('BOOT') as Vars:

  for n, g in Vars:

    print (n, g)

#

# Enumerate any UEFI variables which name include sub-string 'BOOT' 

# and its GUID is equal to gEfiGlobalVariableGuid

# This is case-insensitive example

with Variables('BOOT', gEfiGlobalVariableGuid) as Vars:

  for n, g in Vars:

    print (n, g)

#

# Enumerate any UEFI variables which name include sub-string 'BOOT' 

# and its GUID is equal to gEfiGlobalVariableGuid

# This is case-sensitive example

with Variables('BOOT', gEfiGlobalVariableGuid, CaseSensitive = True) as Vars:

  for n, g in Vars:

    print (n, g)


No comments:

Post a Comment