Sunday, May 15, 2016

SMBIOS - 2

In https://sourceforge.net/u/efipy/svn/HEAD/tree/Trunk/smbios.py r14, it adds 2 functions.

1.
Smbios.py accepts command line input parameter, which is requested SMBIOS type in numeric list.
example "Python.efi smbios.py 1 3 5", output SMBIOS information, type 1, 3, 5.

Python receives command line input parameter by Python list sys.argv.
sys.argv[0] is the program name.

2.
In StructDump() function, it output SMBIOS string if it parse SMBIOS raw data and get SMBIOS_TABLE_STRING data type.

Pseudo code of checking SMBIOS data type
#
# EfiPy/MdePkg/IndustryStandard/SmBios.py
#
class SMBIOS_TABLE_STRING (UINT8):
  pass


#
# SMBIOS sample code
#
if issubclass (field[1], Isb.SMBIOS_TABLE_STRING):
elif issubclass (field[1], EfiPy._SimpleCData):
elif isinstance (_o, EfiPy.GUID):
elif isinstance (_o, EfiPy.Structure):
elif isinstance (_o, EfiPy.Array):

Thursday, May 12, 2016

Python package in UEFI shell environment

It is simple description for how to build self-defined Python package.

Assume following folder structure in boot device

FS0:--+--EFI--+--Boot
      |       |
      |       +--StdLib--lib--python.27
      |       |
      |       +--Tools
      |
      +--Tools-+-Python.efi

      |        |
      |        +-CpuIds.py
      |
      +--ToolsPkg-+-__init__.py

                  |
                  +-CpuId.py

Python.efi is at FS0:\EFI\Tools
Self-defined package is FS0:\ToolsPkg and executable python tool is at FS0:\Tools.
Any python program in FS0:\Tools will import Python module in FS0:\ToolsPkg.

First, We have to set EFI shell environment, named "PYTHONPATH".
Second, Create __init__.py in FS0:\ToolsPkg, each sub-folder has to have __init__.py, too.
Third, make sure EFI shell environment "path" including FS0:\Tools

For example, This script file "Startup.nsh" run "CpuIds.py", automatically, while system boot into shell.

fs0:
set PYTHONPATH fs0:\ToolsPkg
Python.efi fs0:\Tools\CpuIds.py


Explanation: 
fs0:\ToolsPkg folder includes __init__.py and CpuId.py, which is used by CpuIds.py in FS0:\Tools

#
# CpuIds.py
#
import CpuId.py

Friday, May 6, 2016

dump SMBIOS data with EfiPy

Sample code:
https://sourceforge.net/u/efipy/svn/HEAD/tree/Trunk/smbios.py

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

It requires EfiPy_r0.1.1(20289) due to
1. This version fixed error for SMBIOS Industry standard in EfiPy.MdePkg.IndustryStandard.SmBios
2. This version also changed data structure SMBIOS_TABLE_STRING to class.

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() function to get SMBIOS type class defined in EfiPy.MdePkg.IndustryStandard.SmBios.

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