forked from tianocore/edk2-basetools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseTools: Python VfrCompiler implementation
This python VfrCompiler tool is the python implementation of the edk2 VfrCompiler tool which C implementation locates at https://github.com/tianocore/edk2/tree/master/BaseTools/Source/C/VfrCompile. This python implementation not only covers the same usage as the C version VfrCompiler, but also extends several new features. Edk2 Basetools issue link: tianocore#68 Cc: Rebecca Cran <[email protected]> Cc: Liming Gao <[email protected]> Cc: Bob Feng <[email protected]> Signed-off-by: Yuting Yang <[email protected]> Signed-off-by: Yuwei Chen <[email protected]>
- Loading branch information
1 parent
8d9b898
commit 275d952
Showing
14 changed files
with
38,501 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
from edk2basetools.VfrCompiler.IfrCtypes import * | ||
|
||
# Enumeration of EFI_STATUS. | ||
RETURN_SUCCESS = EFI_SUCCESS = 0 | ||
EFI_BUFFER_TOO_SMALL = 0x8000000000000000 | (5) | ||
EFI_ABORTED = 0x8000000000000000 | (21) | ||
EFI_OUT_OF_RESOURCES = 0x8000000000000000 | (9) | ||
EFI_INVALID_PARAMETER = 0x8000000000000000 | (2) | ||
EFI_NOT_FOUND = 0x8000000000000000 | (14) | ||
RETURN_INVALID_PARAMETER = 0x8000000000000000 | (2) | ||
RETURN_UNSUPPORTED = 0x8000000000000000 | (3) | ||
|
||
|
||
def EFI_ERROR(A): | ||
if A < 0: | ||
return True | ||
else: | ||
return False | ||
|
||
|
||
# Converts a string to an EFI_GUID. | ||
def StringToGuid(AsciiGuidBuffer: str, GuidBuffer: EFI_GUID): | ||
Data4 = [0] * 8 | ||
if AsciiGuidBuffer == None or GuidBuffer == None: | ||
return EFI_INVALID_PARAMETER | ||
Index = 0 | ||
while Index < 36: | ||
if Index == 8 or Index == 13 or Index == 18 or Index == 23: | ||
if AsciiGuidBuffer[Index] != "-": | ||
break | ||
else: | ||
if ( | ||
(AsciiGuidBuffer[Index] >= "0" and AsciiGuidBuffer[Index] <= "9") | ||
or (AsciiGuidBuffer[Index] >= "a" and AsciiGuidBuffer[Index] <= "f") | ||
or (AsciiGuidBuffer[Index] >= "A" and AsciiGuidBuffer[Index] <= "F") | ||
): | ||
Index += 1 | ||
continue | ||
else: | ||
break | ||
Index += 1 | ||
continue | ||
|
||
if Index < 36: | ||
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid option value") | ||
return EFI_ABORTED | ||
Index = 11 | ||
try: | ||
Data1 = int(AsciiGuidBuffer[0:8], 16) | ||
Data2 = int(AsciiGuidBuffer[9:13], 16) | ||
Data3 = int(AsciiGuidBuffer[14:18], 16) | ||
Data4[0] = int(AsciiGuidBuffer[19:21], 16) | ||
Data4[1] = int(AsciiGuidBuffer[21:23], 16) | ||
Data4[2] = int(AsciiGuidBuffer[24:26], 16) | ||
Data4[3] = int(AsciiGuidBuffer[26:28], 16) | ||
Data4[4] = int(AsciiGuidBuffer[28:30], 16) | ||
Data4[5] = int(AsciiGuidBuffer[30:32], 16) | ||
Data4[6] = int(AsciiGuidBuffer[32:34], 16) | ||
Data4[7] = int(AsciiGuidBuffer[34:36], 16) | ||
except: | ||
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid Data value!") | ||
Index = 0 | ||
|
||
# Verify the correct number of items were scanned. | ||
if Index != 11: | ||
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid option value") | ||
return EFI_ABORTED | ||
|
||
# Copy the data into our GUID. | ||
GuidBuffer.Data1 = Data1 | ||
GuidBuffer.Data2 = Data2 | ||
GuidBuffer.Data3 = Data3 | ||
GuidBuffer.Data4[0] = Data4[0] | ||
GuidBuffer.Data4[1] = Data4[1] | ||
GuidBuffer.Data4[2] = Data4[2] | ||
GuidBuffer.Data4[3] = Data4[3] | ||
GuidBuffer.Data4[4] = Data4[4] | ||
GuidBuffer.Data4[5] = Data4[5] | ||
GuidBuffer.Data4[6] = Data4[6] | ||
GuidBuffer.Data4[7] = Data4[7] | ||
Status = EFI_SUCCESS | ||
|
||
return Status, GuidBuffer |
Oops, something went wrong.