5/13/2016

Python package in UEFI shell environment

Intrdocution
It is short description for Python package file structure.

Assume following folder structure in boot device

FSx: Efi
     ├── Apps
     │   ├── CorepySample
     │   └── EfiPy2Sample
     ├── BOOT
     │   └── BOOTX64.EFI
     ├── lib
     ├── StdLib
     │   ├── etc
     │   └── lib
     │       └── python36.8
     │           ├── corepy
     │           ├── ctypes
     │           ├── EfiPy2
     │           │   ├── Lib
     │           │   ├── MdePkg
     │           │   │   ├── Base.py
     │           │   │   ├── Guid
     │           │   │   ├── IndustryStandard
     │           │   │   ├── Library
     │           │   │   ├── Pi
     │           │   │   ├── Ppi
     │           │   │   ├── Protocol
     │           │   │   ├── Register
     │           │   │   │   ├── Amd
     │           │   │   │   └── Intel
     │           │   │   │       ├── Microcode.py
     │           │   │   │       └── Msr
     │           │   │   └── Uefi
     │           │   └── ShellPkg
     │           │       ├── Guid
     │           │       └── Protocol
     │           └ ... <<Python linraries>>
     └── Tools
         └── Python.efi

Python.efi is at FSx:\EFI\Tools and key folders are...
1. EfiPy2 self-defined modules are at FSx:\Efi\StdLib\lib\python36.8\EfiPy2\Lib
2. Executable python tool is at FSx:\EFI\Tools.

Any python scripts which using EfiPy2 packages in FS0:\EFI\Apps need to have import statement.

import EfiPy2
or
import EfiPy2 as EfiPy

Example
This script file "Startup.nsh" run "CpuIdBasic.py", automatically, while system boot into shell.
(Assume python and its related packages are installed in fs0)

Python.efi fs0:\Efi\Apps\EfiPy2Sample\CpuIdBasic.py

5/07/2016

dump SMBIOS data with EfiPy

Sample code:
https://github.com/EfiPy/EfiPy2/blob/main/Efi/Apps/EfiPy2Sample/EfiPy2Smbios.py

Description:
This sample uses EFI_SMBIOS_PROTOCOL, defined from EfiPy2.MdePkg.Protocol.Smbios.

By using EFI_SMBIOS_PROTOCOL protocol member function GetNext(), it has the same algorithm as EDK II driver/application. infinite while loop until return error in GetNext().


In this sample, it uses getattr() member function to get SMBIOS type class defined in EfiPy2.MdePkg.IndustryStandard.SmBios.

This sample also leverages the power of Python/ctypes (sample in the function SmbiosDumpStruct2() and SmbiosDumpStruct3()).
In this function, it does not need to know SMBIOS structure definition, it uses Python getattr() to get SMBIOS structure member name and its value.