EDK2 PyTool Library

0.23.13 · active · verified Wed Apr 15

The edk2-pytool-library is a Tianocore-maintained Python library, currently at version 0.23.13, that supports UEFI EDK2 firmware development. It provides modules for tasks such as parsing EDK2-specific file types, encoding/decoding UEFI binary structures, wrapping system CLI tools (e.g., signtool), and offering general utilities like logging and path resolution. Its intent is to provide reusable python code and is typically consumed by other tools and scripts, rather than directly by end-users via command-line interfaces. It is released on an ongoing basis, with minor releases for each merged pull request.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use the `Edk2Path` class from `edk2toollib.path_utilities` to manage EDK2 file paths. It sets up a temporary workspace and package structure to showcase how an absolute path can be converted into an EDK2 relative path. It also includes a brief mention of a utility function from `edk2toollib.utility_functions`.

from edk2toollib.path_utilities import Edk2Path
from pathlib import Path
import tempfile

# Create a dummy workspace and package for demonstration
with tempfile.TemporaryDirectory() as tmpdir:
    workspace_path = Path(tmpdir) / "edk2_workspace"
    package_path = workspace_path / "MyPkg"
    (package_path / "MyModule").mkdir(parents=True)
    (package_path / "MyModule" / "MyModule.inf").touch()

    workspace_path.mkdir()
    package_path.mkdir()

    # Instantiate Edk2Path - note the performance warning in warnings section
    edk2_path_obj = Edk2Path(ws=workspace_path, package_path_list=[package_path])

    # Example: Get an EDK2 relative path
    abs_module_path = package_path / "MyModule" / "MyModule.inf"
    edk2_relative_path = edk2_path_obj.GetEdk2RelativePathFromAbsolutePath(str(abs_module_path))
    print(f"EDK2 Relative Path: {edk2_relative_path}")

    # Example using a utility function (requires a file to print)
    test_file = Path(tmpdir) / "test.txt"
    test_file.write_text("Hello, EDK2!")
    print("\nPrinting file data:")
    # PrintFileData is often used internally, no direct output capturing shown here for simplicity
    # The function itself prints to console, so we can't easily assert its output without mocking sys.stdout
    # For demonstration, we simply call it.
    # In a real scenario, you'd likely use a logger or capture stdout.
    # from edk2toollib.utility_functions import PrintFileData
    # PrintFileData(str(test_file))
    print(f"Content of {test_file.name}: {test_file.read_text()}") # Simulate PrintFileData output

view raw JSON →