Skip to content

Commit

Permalink
Merge 1cf69a5 into 8d9b898
Browse files Browse the repository at this point in the history
  • Loading branch information
yytshirley authored Sep 27, 2023
2 parents 8d9b898 + 1cf69a5 commit e1cfac4
Show file tree
Hide file tree
Showing 395 changed files with 113,709 additions and 0 deletions.
100 changes: 100 additions & 0 deletions edk2basetools/VfrCompiler/IfrCommon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
## @file
# This file is used to define common funtions.
#
# Copyright (c) 2022-, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

import Common.EdkLogger as EdkLogger
from VfrCompiler.IfrCtypes import EFI_GUID
from Common.BuildToolError import PARAMETER_INVALID

Check warning on line 10 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L8-L10

Added lines #L8 - L10 were not covered by tests

# 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)

Check warning on line 20 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L13-L20

Added lines #L13 - L20 were not covered by tests

ASCII_GUID_BUFFER_INDEX_1 = 8
ASCII_GUID_BUFFER_INDEX_2 = 13
ASCII_GUID_BUFFER_INDEX_3 = 18
ASCII_GUID_BUFFER_INDEX_4 = 23
ASCII_GUID_BUFFER_MAX_INDEX = 36
GUID_BUFFER_VALUE_LEN = 11

Check warning on line 27 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L22-L27

Added lines #L22 - L27 were not covered by tests


def EFI_ERROR(A):
return A < 0

Check warning on line 31 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L30-L31

Added lines #L30 - L31 were not covered by tests


# Converts a string to an EFI_GUID.
def StringToGuid(AsciiGuidBuffer: str, GuidBuffer: EFI_GUID):
Data4 = [0] * 8
if AsciiGuidBuffer is None or GuidBuffer is None:
return EFI_INVALID_PARAMETER
Index = 0
while Index < ASCII_GUID_BUFFER_MAX_INDEX:
if (

Check warning on line 41 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L35-L41

Added lines #L35 - L41 were not covered by tests
Index == ASCII_GUID_BUFFER_INDEX_1
or Index == ASCII_GUID_BUFFER_INDEX_2
or Index == ASCII_GUID_BUFFER_INDEX_3
or Index == ASCII_GUID_BUFFER_INDEX_4
):
if AsciiGuidBuffer[Index] != "-":
break
elif (

Check warning on line 49 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L47-L49

Added lines #L47 - L49 were not covered by tests
(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

Check warning on line 55 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L54-L55

Added lines #L54 - L55 were not covered by tests
else:
break
Index += 1
continue

Check warning on line 59 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L57-L59

Added lines #L57 - L59 were not covered by tests

if Index < ASCII_GUID_BUFFER_MAX_INDEX:
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid option value")
return EFI_ABORTED
Index = GUID_BUFFER_VALUE_LEN
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 Exception:
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid Data value!")
Index = 0

Check warning on line 79 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L61-L79

Added lines #L61 - L79 were not covered by tests

# Verify the correct number of items were scanned.
if Index != GUID_BUFFER_VALUE_LEN:
EdkLogger.error("VfrCompiler", PARAMETER_INVALID, "Invalid option value")
return EFI_ABORTED

Check warning on line 84 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L82-L84

Added lines #L82 - L84 were not covered by tests

# 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

Check warning on line 98 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L87-L98

Added lines #L87 - L98 were not covered by tests

return Status, GuidBuffer

Check warning on line 100 in edk2basetools/VfrCompiler/IfrCommon.py

View check run for this annotation

Codecov / codecov/patch

edk2basetools/VfrCompiler/IfrCommon.py#L100

Added line #L100 was not covered by tests
Loading

0 comments on commit e1cfac4

Please sign in to comment.