8/22/2015

EfiPy DevicePath

Sample code name

DevicePath.py

Description

In EfiPy2, it uses DevicePath and DevicePathToText to build DevicePathEfiPy.
For the detail, user can reference the source code in Efi\StdLib\lib\python36.8\EfiPy2\MdePkg\Protocol\DevicePathEfiPy.py

DevicePathEfiPy inherit from DevicePath and replace member function __str__ ()to convert device path protocol to readable string.

And this mechanism makes string format available.
  DevicePath = (EfiPy2.cast (TmpDevPath, EfiPy.POINTER(EFI_DEVICE_PATH_PROTOCOL)))[0]

  print ("%s" % DevicePath)

This is LocateHandle sample from EfiPy.gBS.LocateHandle()

  import EfiPy2 as EfiPy

  Status = EfiPy.gBS.LocateHandle(
             EfiPy.ByProtocol,
             EfiPy.byref(gEfiSimpleFileSystemProtocolGuid),
             None,
             EfiPy.byref(BufferSize),
             HandleArray
             )

Above results are put at array of handle.
It can be used by Python for loop to retrieve each handle.

  for Handle in HandleArray:
  
    TmpDevPath = EfiPy.PVOID ()
  
    Status = EfiPy.gBS.HandleProtocol (
                         Handle,
                         EfiPy.byref (gEfiDevicePathProtocolGuid),
                         EfiPy.byref (TmpDevPath)
                         )
    if EfiPy.EFI_ERROR (Status):
      continue
  
    DevicePath = (EfiPy.cast (TmpDevPath, EfiPy.POINTER(EFI_DEVICE_PATH_PROTOCOL)))[0]
  
    print ("%s" % DevicePath)

Screenshot


No comments:

Post a Comment