Saturday, August 8, 2015

import EfiPy

Description

EfiPy uses python ctypes, which has been ported to UEFI Python package, can be downloaded from EfiPy download site.

EfiPy is almost mapped to EDKII MdePkg/Include.

#
# import EfiPy package
#
import EfiPy

With above python code, import EfiPy, and running it in UEFI shell environment, it has following benefit.

1. Basic data type inherited from ctypes (UINTN, UINT32, ...)
2. EFI_SYSTEM_TABLE, EFI_BOOT_SERVICES and EFI_RUNTIME_SERVICES data structure
3. ISA (Instruction Set Architecture) related structure
4. gRT, gST and gBS objects
5. gImageHandle and pImageHandle
6. EFI basic data structure

There are many macro #define in EDKII source code, it is transferred to constant value/function in EfiPy

source code - Table and Services

#
# UEFI basic tables gST, gRT, gBS
#

gRT = EFI_RUNTIME_SERVICES.from_address (_EfiPy.EfiPygRtAddr)
gST = EFI_SYSTEM_TABLE.from_address     (_EfiPy.EfiPygStAddr)
gBS = EFI_BOOT_SERVICES.from_address    (_EfiPy.EfiPygBsAddr)

source code - Handles

#
# EDK basic image handle
#

gImageHandle = EFI_HANDLE.from_address( _EfiPy.gImageHandle)
pImageHandle = EFI_HANDLE.from_address( _EfiPy.pImageHandle)

source code - basic data structure samples

UINT64  = c_uint64
INT64   = c_int64
UINT32  = c_uint32

source code - EfiPy constant value/function

#
# ENCODE_ERROR function
#
def ENCODE_ERROR (StatusCode):

  return StatusCode | MAX_BIT  # MAX_BIT is exported from _EfiPy

#
# Return value
#
RETURN_INVALID_PARAMETER     = ENCODE_ERROR (2)

No comments:

Post a Comment