Saturday, October 21, 2023

EfiPy2 working environment

Introduction

EfiPy2 is python 3 library, is original designed for UEFI shell application. Static data strcuture in EfiPy2 are also suitable being used in OS environmrnt if user can read low layer data, for example PCIe configuration space and complex registers in CPU.

While import EfiPy2 in OS environment, the global data gBS, gST, gRT and gImage are set as fake value to them. That is only static data structure can be apply to Python application and EFI protocol are disabled.

In Windows/Linux system, user can import EfiPy2 without ModuleNotFoundError exception. Thus user Python application can import data structure in EfiPy2.MdePkg.Indusctry and EfiPy2.MdePkg.Register properly. With suitable modifying corepy package, it can also work on EDK2 and Linux system, too.


The conclusion for current stats...

EfiPy2 is full support in UEFI environment.

In Linux system, Python application can import EfiPy2 and corepy. And application can launch corepy code

    % PYTHONPATH=$EfiPy2Path python3

In Windows system, Python application can import EfiPy2

    X:\>set PYTHONPATH=%EfiPy2Path%

    X:\>python


There are two samples for above condition

1. CpuIdBasic.py

    This application leverage corepy excuting cpuid instruction to fetch CPUID data in both UEFI and Linux system.

2. MsrBasic.py

    It can be launched in both Linux and UEFI

    This applicaiton uses rdmsr/wrmsr instructions from corepy, these instrucitons are ring 0 privilege.
    UEFI is a ring 0 environment, too. MsrBasic.py fully achieve msr read/write purpose.
    In Linux, Python run in ring 3 privilege, only related assmbly code is printed in this design while MsrBasic.py is launched.


No comments:

Post a Comment