mirror of https://github.com/acidanthera/audk.git
BaseTools: Add DevicePath support for PCD values
Use C code parse device path to output hex string, and Python run command when PCD Value need device path parse. https://bugzilla.tianocore.org/show_bug.cgi?id=541 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com> Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
f13f306b3b
commit
7dbc50bd24
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
|
||||
dir=$(dirname "$full_cmd")
|
||||
cmd=${full_cmd##*/}
|
||||
|
||||
if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
|
||||
then
|
||||
exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
|
||||
elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
|
||||
then
|
||||
if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
|
||||
then
|
||||
echo "BaseTools C Tool binary was not found ($cmd)"
|
||||
echo "You may need to run:"
|
||||
echo " make -C $EDK_TOOLS_PATH/Source/C"
|
||||
else
|
||||
exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
|
||||
fi
|
||||
elif [ -e "$dir/../../Source/C/bin/$cmd" ]
|
||||
then
|
||||
exec "$dir/../../Source/C/bin/$cmd" "$@"
|
||||
else
|
||||
echo "Unable to find the real '$cmd' to run"
|
||||
echo "This message was printed by"
|
||||
echo " $0"
|
||||
exit 127
|
||||
fi
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
# must ensure that files that are required by the cx_freeze frozen binaries are
|
||||
# present in the Bin\Win32 directory.
|
||||
#
|
||||
# Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2014 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials are licensed and made available under
|
||||
# the terms and conditions of the BSD License which accompanies this distribution.
|
||||
|
@ -59,6 +59,7 @@ UPT.exe
|
|||
VfrCompile.exe
|
||||
VolInfo.exe
|
||||
Pkcs7Sign.exe
|
||||
DevicePath.exe
|
||||
|
||||
[ExtraFiles.Win32]
|
||||
TestSigningPrivateKey.pem
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
|||
/** @file
|
||||
Common library assistance routines.
|
||||
|
||||
Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -17,10 +17,31 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|||
|
||||
#include <Common/UefiBaseTypes.h>
|
||||
#include <Common/BuildVersion.h>
|
||||
#include <assert.h>
|
||||
#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination
|
||||
|
||||
#define MAX_LONG_FILE_PATH 500
|
||||
|
||||
#define MAX_UINTN MAX_ADDRESS
|
||||
#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)
|
||||
#define MAX_UINT16 ((UINT16)0xFFFF)
|
||||
#define MAX_UINT8 ((UINT8)0xFF)
|
||||
#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))
|
||||
#define ASCII_RSIZE_MAX 1000000
|
||||
#ifndef RSIZE_MAX
|
||||
#define RSIZE_MAX 1000000
|
||||
#endif
|
||||
|
||||
#define IS_COMMA(a) ((a) == L',')
|
||||
#define IS_HYPHEN(a) ((a) == L'-')
|
||||
#define IS_DOT(a) ((a) == L'.')
|
||||
#define IS_LEFT_PARENTH(a) ((a) == L'(')
|
||||
#define IS_RIGHT_PARENTH(a) ((a) == L')')
|
||||
#define IS_SLASH(a) ((a) == L'/')
|
||||
#define IS_NULL(a) ((a) == L'\0')
|
||||
|
||||
#define ASSERT(x) assert(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -149,6 +170,285 @@ CHAR8 *
|
|||
LongFilePath (
|
||||
IN CHAR8 *FileName
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrLen (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
VOID *
|
||||
AllocateCopyPool (
|
||||
UINTN AllocationSize,
|
||||
CONST VOID *Buffer
|
||||
);
|
||||
|
||||
INTN
|
||||
StrnCmp (
|
||||
CONST CHAR16 *FirstString,
|
||||
CONST CHAR16 *SecondString,
|
||||
UINTN Length
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrToGuid (
|
||||
CONST CHAR16 *String,
|
||||
EFI_GUID *Guid
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrHexToBytes (
|
||||
CONST CHAR16 *String,
|
||||
UINTN Length,
|
||||
UINT8 *Buffer,
|
||||
UINTN MaxBufferSize
|
||||
);
|
||||
|
||||
UINTN
|
||||
InternalHexCharToUintn (
|
||||
CHAR16 Char
|
||||
);
|
||||
|
||||
VOID *
|
||||
InternalAllocateCopyPool (
|
||||
UINTN AllocationSize,
|
||||
CONST VOID *Buffer
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
InternalIsDecimalDigitCharacter (
|
||||
CHAR16 Char
|
||||
);
|
||||
|
||||
UINT32
|
||||
SwapBytes32 (
|
||||
UINT32 Value
|
||||
);
|
||||
|
||||
UINT16
|
||||
SwapBytes16 (
|
||||
UINT16 Value
|
||||
);
|
||||
|
||||
EFI_GUID *
|
||||
CopyGuid (
|
||||
EFI_GUID *DestinationGuid,
|
||||
CONST EFI_GUID *SourceGuid
|
||||
);
|
||||
|
||||
UINT64
|
||||
WriteUnaligned64 (
|
||||
UINT64 *Buffer,
|
||||
UINT64 Value
|
||||
);
|
||||
|
||||
UINT64
|
||||
ReadUnaligned64 (
|
||||
CONST UINT64 *Buffer
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrSize (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrHexToUintn (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrDecimalToUintn (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINT64
|
||||
StrHexToUint64 (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
UINT64
|
||||
StrDecimalToUint64 (
|
||||
CONST CHAR16 *String
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrHexToUint64S (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer,
|
||||
UINT64 *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrHexToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrDecimalToUint64S (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINT64 *Data
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrDecimalToUintnS (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer, OPTIONAL
|
||||
UINTN *Data
|
||||
);
|
||||
|
||||
VOID *
|
||||
ReallocatePool (
|
||||
UINTN OldSize,
|
||||
UINTN NewSize,
|
||||
VOID *OldBuffer OPTIONAL
|
||||
);
|
||||
|
||||
VOID *
|
||||
InternalReallocatePool (
|
||||
UINTN OldSize,
|
||||
UINTN NewSize,
|
||||
VOID *OldBuffer OPTIONAL
|
||||
);
|
||||
|
||||
VOID *
|
||||
InternalAllocateZeroPool (
|
||||
UINTN AllocationSize
|
||||
) ;
|
||||
|
||||
VOID *
|
||||
InternalAllocatePool (
|
||||
UINTN AllocationSize
|
||||
);
|
||||
|
||||
UINTN
|
||||
StrnLenS (
|
||||
CONST CHAR16 *String,
|
||||
UINTN MaxSize
|
||||
);
|
||||
|
||||
CHAR16
|
||||
InternalCharToUpper (
|
||||
CHAR16 Char
|
||||
);
|
||||
|
||||
INTN
|
||||
StrCmp (
|
||||
CONST CHAR16 *FirstString,
|
||||
CONST CHAR16 *SecondString
|
||||
);
|
||||
|
||||
UINT64
|
||||
SwapBytes64 (
|
||||
UINT64 Value
|
||||
);
|
||||
|
||||
UINT64
|
||||
InternalMathSwapBytes64 (
|
||||
UINT64 Operand
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrToIpv4Address (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer,
|
||||
EFI_IPv4_ADDRESS *Address,
|
||||
UINT8 *PrefixLength
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrToIpv6Address (
|
||||
CONST CHAR16 *String,
|
||||
CHAR16 **EndPointer,
|
||||
EFI_IPv6_ADDRESS *Address,
|
||||
UINT8 *PrefixLength
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
StrCpyS (
|
||||
CHAR16 *Destination,
|
||||
UINTN DestMax,
|
||||
CONST CHAR16 *Source
|
||||
);
|
||||
|
||||
RETURN_STATUS
|
||||
UnicodeStrToAsciiStrS (
|
||||
CONST CHAR16 *Source,
|
||||
CHAR8 *Destination,
|
||||
UINTN DestMax
|
||||
);
|
||||
VOID *
|
||||
AllocatePool (
|
||||
UINTN AllocationSize
|
||||
);
|
||||
|
||||
UINT16
|
||||
WriteUnaligned16 (
|
||||
UINT16 *Buffer,
|
||||
UINT16 Value
|
||||
);
|
||||
|
||||
UINT16
|
||||
ReadUnaligned16 (
|
||||
CONST UINT16 *Buffer
|
||||
);
|
||||
|
||||
VOID *
|
||||
AllocateZeroPool (
|
||||
UINTN AllocationSize
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
InternalIsHexaDecimalDigitCharacter (
|
||||
CHAR16 Char
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
InternalSafeStringIsOverlap (
|
||||
IN VOID *Base1,
|
||||
IN UINTN Size1,
|
||||
IN VOID *Base2,
|
||||
IN UINTN Size2
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
InternalSafeStringNoStrOverlap (
|
||||
IN CHAR16 *Str1,
|
||||
IN UINTN Size1,
|
||||
IN CHAR16 *Str2,
|
||||
IN UINTN Size2
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsHexStr (
|
||||
CHAR16 *Str
|
||||
);
|
||||
|
||||
UINTN
|
||||
Strtoi (
|
||||
CHAR16 *Str
|
||||
);
|
||||
|
||||
VOID
|
||||
Strtoi64 (
|
||||
CHAR16 *Str,
|
||||
UINT64 *Data
|
||||
);
|
||||
|
||||
VOID
|
||||
StrToAscii (
|
||||
CHAR16 *Str,
|
||||
CHAR8 **AsciiStr
|
||||
);
|
||||
|
||||
CHAR16 *
|
||||
SplitStr (
|
||||
CHAR16 **List,
|
||||
CHAR16 Separator
|
||||
);
|
||||
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
@ -166,8 +466,6 @@ Returns:
|
|||
}
|
||||
#endif
|
||||
|
||||
#define ASSERT(x) assert(x)
|
||||
|
||||
#ifdef __GNUC__
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
|
@ -0,0 +1,186 @@
|
|||
/** @file
|
||||
Definition for Device Path Tool.
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiDevicePathLib.h"
|
||||
|
||||
//
|
||||
// Utility Name
|
||||
//
|
||||
#define UTILITY_NAME "DevicePath"
|
||||
|
||||
//
|
||||
// Utility version information
|
||||
//
|
||||
#define UTILITY_MAJOR_VERSION 0
|
||||
#define UTILITY_MINOR_VERSION 1
|
||||
|
||||
EFI_GUID gEfiDebugPortDevicePathGuid = DEVICE_PATH_MESSAGING_DEBUGPORT;
|
||||
EFI_GUID gEfiPcAnsiGuid = EFI_PC_ANSI_GUID;
|
||||
EFI_GUID gEfiVT100Guid = EFI_VT_100_GUID;
|
||||
EFI_GUID gEfiVT100PlusGuid = EFI_VT_100_PLUS_GUID;
|
||||
EFI_GUID gEfiVTUTF8Guid = EFI_VT_UTF8_GUID;
|
||||
EFI_GUID gEfiUartDevicePathGuid = EFI_UART_DEVICE_PATH_GUID;
|
||||
EFI_GUID gEfiSasDevicePathGuid = EFI_SAS_DEVICE_PATH_GUID;
|
||||
EFI_GUID gEfiVirtualDiskGuid = EFI_VIRTUAL_DISK_GUID;
|
||||
EFI_GUID gEfiVirtualCdGuid = EFI_VIRTUAL_CD_GUID;
|
||||
EFI_GUID gEfiPersistentVirtualDiskGuid = EFI_PERSISTENT_VIRTUAL_DISK_GUID;
|
||||
EFI_GUID gEfiPersistentVirtualCdGuid = EFI_PERSISTENT_VIRTUAL_CD_GUID;
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
Version (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Displays the standard utility information to SDTOUT
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
fprintf (stdout, "%s Version %d.%d %s \n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
|
||||
}
|
||||
|
||||
STATIC
|
||||
VOID
|
||||
Usage (
|
||||
VOID
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Displays the utility usage syntax to STDOUT
|
||||
|
||||
Arguments:
|
||||
|
||||
None
|
||||
|
||||
Returns:
|
||||
|
||||
None
|
||||
|
||||
--*/
|
||||
{
|
||||
//
|
||||
// Summary usage
|
||||
//
|
||||
fprintf (stdout, "\nUsage: %s [options]\n\n", UTILITY_NAME);
|
||||
|
||||
//
|
||||
// Copyright declaration
|
||||
//
|
||||
fprintf (stdout, "Copyright (c) 2017, Intel Corporation. All rights reserved.\n\n");
|
||||
//
|
||||
// Details Option
|
||||
//
|
||||
fprintf (stdout, "Options:\n");
|
||||
fprintf (stdout, " DevicePathString Device Path string is specified, no space character.\n"
|
||||
" Example: \"PciRoot(0)/Pci(0,0)\"\n");
|
||||
|
||||
fprintf (stdout, " --version Show program's version number and exit.\n");
|
||||
fprintf (stdout, " -h, --help Show this help message and exit.\n");
|
||||
}
|
||||
|
||||
|
||||
void print_mem(void const *vp, size_t n)
|
||||
{
|
||||
unsigned char const *p = vp;
|
||||
for (size_t i=0; i<n; i++) {
|
||||
printf("0x%02x ", p[i]);
|
||||
}
|
||||
}
|
||||
|
||||
VOID
|
||||
Ascii2UnicodeString (
|
||||
CHAR8 *String,
|
||||
CHAR16 *UniString
|
||||
)
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
|
||||
Write ascii string as unicode string format to FILE
|
||||
|
||||
Arguments:
|
||||
|
||||
String - Pointer to string that is written to FILE.
|
||||
UniString - Pointer to unicode string
|
||||
|
||||
Returns:
|
||||
|
||||
NULL
|
||||
|
||||
--*/
|
||||
{
|
||||
while (*String != '\0') {
|
||||
*(UniString++) = (CHAR16) *(String++);
|
||||
}
|
||||
//
|
||||
// End the UniString with a NULL.
|
||||
//
|
||||
*UniString = '\0';
|
||||
}
|
||||
|
||||
int main(int argc, CHAR8 *argv[])
|
||||
{
|
||||
CHAR8 * Str;
|
||||
CHAR16* Str16;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
|
||||
if (argc == 1) {
|
||||
Error (NULL, 0, 1001, "Missing options", "No input options specified.");
|
||||
Usage ();
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if ((stricmp (argv[1], "-h") == 0) || (stricmp (argv[1], "--help") == 0)) {
|
||||
Version ();
|
||||
Usage ();
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (stricmp (argv[1], "--version") == 0) {
|
||||
Version ();
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
Str = argv[1];
|
||||
if (Str == NULL) {
|
||||
fprintf(stderr, "Invalid option value, Device Path can't be NULL");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
Str16 = (CHAR16 *)malloc(1024);
|
||||
if (Str16 == NULL) {
|
||||
fprintf(stderr, "Resource, memory cannot be allcoated");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
Ascii2UnicodeString(Str, Str16);
|
||||
DevicePath = UefiDevicePathLibConvertTextToDevicePath(Str16);
|
||||
while (!((DevicePath->Type == END_DEVICE_PATH_TYPE) && (DevicePath->SubType == END_ENTIRE_DEVICE_PATH_SUBTYPE)) )
|
||||
{
|
||||
print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
|
||||
DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)DevicePath + (DevicePath->Length[0] | DevicePath->Length[1] << 8));
|
||||
}
|
||||
print_mem(DevicePath, (DevicePath->Length[0] | DevicePath->Length[1] << 8));
|
||||
putchar('\n');
|
||||
return STATUS_SUCCESS;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,875 @@
|
|||
/** @file
|
||||
Device Path services. The thing to remember is device paths are built out of
|
||||
nodes. The device path is terminated by an end node that is length
|
||||
sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
|
||||
all over this file.
|
||||
|
||||
The only place where multi-instance device paths are supported is in
|
||||
environment varibles. Multi-instance device paths should never be placed
|
||||
on a Handle.
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#include "UefiDevicePathLib.h"
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
|
||||
//
|
||||
// Template for an end-of-device path node.
|
||||
//
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {
|
||||
END_DEVICE_PATH_TYPE,
|
||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||
{
|
||||
END_DEVICE_PATH_LENGTH,
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
Determine whether a given device path is valid.
|
||||
If DevicePath is NULL, then ASSERT().
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param MaxSize The maximum size of the device path data structure.
|
||||
|
||||
@retval TRUE DevicePath is valid.
|
||||
@retval FALSE The length of any node node in the DevicePath is less
|
||||
than sizeof (EFI_DEVICE_PATH_PROTOCOL).
|
||||
@retval FALSE If MaxSize is not zero, the size of the DevicePath
|
||||
exceeds MaxSize.
|
||||
@retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node
|
||||
count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDevicePathValid (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
UINTN MaxSize
|
||||
)
|
||||
{
|
||||
UINTN Count;
|
||||
UINTN Size;
|
||||
UINTN NodeLength;
|
||||
|
||||
ASSERT (DevicePath != NULL);
|
||||
|
||||
if (MaxSize == 0) {
|
||||
MaxSize = MAX_UINTN;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate the input size big enough to touch the first node.
|
||||
//
|
||||
if (MaxSize < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (Count = 0, Size = 0; !IsDevicePathEnd (DevicePath); DevicePath = NextDevicePathNode (DevicePath)) {
|
||||
NodeLength = DevicePathNodeLength (DevicePath);
|
||||
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (NodeLength > MAX_UINTN - Size) {
|
||||
return FALSE;
|
||||
}
|
||||
Size += NodeLength;
|
||||
|
||||
//
|
||||
// Validate next node before touch it.
|
||||
//
|
||||
if (Size > MaxSize - END_DEVICE_PATH_LENGTH ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Count++;
|
||||
if (Count >= MAX_DEVICE_PATH_NODE_COUNT) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
// Only return TRUE when the End Device Path node is valid.
|
||||
//
|
||||
return (BOOLEAN) (DevicePathNodeLength (DevicePath) == END_DEVICE_PATH_LENGTH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Returns the Type field of a device path node.
|
||||
|
||||
Returns the Type field of the device path node specified by Node.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@return The Type field of the device path node specified by Node.
|
||||
|
||||
**/
|
||||
UINT8
|
||||
DevicePathType (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the SubType field of a device path node.
|
||||
|
||||
Returns the SubType field of the device path node specified by Node.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@return The SubType field of the device path node specified by Node.
|
||||
|
||||
**/
|
||||
UINT8
|
||||
DevicePathSubType (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the 16-bit Length field of a device path node.
|
||||
|
||||
Returns the 16-bit Length field of the device path node specified by Node.
|
||||
Node is not required to be aligned on a 16-bit boundary, so it is recommended
|
||||
that a function such as ReadUnaligned16() be used to extract the contents of
|
||||
the Length field.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@return The 16-bit Length field of the device path node specified by Node.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
DevicePathNodeLength (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
Returns a pointer to the next node in a device path.
|
||||
|
||||
Returns a pointer to the device path node that follows the device path node
|
||||
specified by Node.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@return a pointer to the device path node that follows the device path node
|
||||
specified by Node.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
NextDevicePathNode (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if a device path node is an end node of a device path.
|
||||
This includes nodes that are the end of a device path instance and nodes that
|
||||
are the end of an entire device path.
|
||||
|
||||
Determines if the device path node specified by Node is an end node of a device path.
|
||||
This includes nodes that are the end of a device path instance and nodes that are the
|
||||
end of an entire device path. If Node represents an end node of a device path,
|
||||
then TRUE is returned. Otherwise, FALSE is returned.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@retval TRUE The device path node specified by Node is an end node of a
|
||||
device path.
|
||||
@retval FALSE The device path node specified by Node is not an end node of
|
||||
a device path.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDevicePathEndType (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if a device path node is an end node of an entire device path.
|
||||
|
||||
Determines if a device path node specified by Node is an end node of an entire
|
||||
device path. If Node represents the end of an entire device path, then TRUE is
|
||||
returned. Otherwise, FALSE is returned.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@retval TRUE The device path node specified by Node is the end of an entire
|
||||
device path.
|
||||
@retval FALSE The device path node specified by Node is not the end of an
|
||||
entire device path.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDevicePathEnd (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if a device path node is an end node of a device path instance.
|
||||
|
||||
Determines if a device path node specified by Node is an end node of a device
|
||||
path instance. If Node represents the end of a device path instance, then TRUE
|
||||
is returned. Otherwise, FALSE is returned.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
@retval TRUE The device path node specified by Node is the end of a device
|
||||
path instance.
|
||||
@retval FALSE The device path node specified by Node is not the end of a
|
||||
device path instance.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDevicePathEndInstance (
|
||||
CONST VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the length, in bytes, of a device path node.
|
||||
|
||||
Sets the length of the device path node specified by Node to the value specified
|
||||
by NodeLength. NodeLength is returned. Node is not required to be aligned on
|
||||
a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
|
||||
be used to set the contents of the Length field.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
If NodeLength >= SIZE_64KB, then ASSERT().
|
||||
If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
@param Length The length, in bytes, of the device path node.
|
||||
|
||||
@return Length
|
||||
|
||||
**/
|
||||
UINT16
|
||||
SetDevicePathNodeLength (
|
||||
VOID *Node,
|
||||
UINTN Length
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
ASSERT ((Length >= sizeof (EFI_DEVICE_PATH_PROTOCOL)) && (Length < SIZE_64KB));
|
||||
return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));
|
||||
}
|
||||
|
||||
/**
|
||||
Fills in all the fields of a device path node that is the end of an entire device path.
|
||||
|
||||
Fills in all the fields of a device path node specified by Node so Node represents
|
||||
the end of an entire device path. The Type field of Node is set to
|
||||
END_DEVICE_PATH_TYPE, the SubType field of Node is set to
|
||||
END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
|
||||
END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
|
||||
so it is recommended that a function such as WriteUnaligned16() be used to set
|
||||
the contents of the Length field.
|
||||
|
||||
If Node is NULL, then ASSERT().
|
||||
|
||||
@param Node A pointer to a device path node data structure.
|
||||
|
||||
**/
|
||||
VOID
|
||||
SetDevicePathEndNode (
|
||||
VOID *Node
|
||||
)
|
||||
{
|
||||
ASSERT (Node != NULL);
|
||||
memcpy (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the size of a device path in bytes.
|
||||
|
||||
This function returns the size, in bytes, of the device path data structure
|
||||
specified by DevicePath including the end of device path node.
|
||||
If DevicePath is NULL or invalid, then 0 is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval 0 If DevicePath is NULL or invalid.
|
||||
@retval Others The size of a device path in bytes.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
UefiDevicePathLibGetDevicePathSize (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *Start;
|
||||
|
||||
if (DevicePath == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!IsDevicePathValid (DevicePath, 0)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Search for the end of the device path structure
|
||||
//
|
||||
Start = DevicePath;
|
||||
while (!IsDevicePathEnd (DevicePath)) {
|
||||
DevicePath = NextDevicePathNode (DevicePath);
|
||||
}
|
||||
|
||||
//
|
||||
// Compute the size and add back in the size of the end device path structure
|
||||
//
|
||||
return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new copy of an existing device path.
|
||||
|
||||
This function allocates space for a new copy of the device path specified by DevicePath.
|
||||
If DevicePath is NULL, then NULL is returned. If the memory is successfully
|
||||
allocated, then the contents of DevicePath are copied to the newly allocated
|
||||
buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL DevicePath is NULL or invalid.
|
||||
@retval Others A pointer to the duplicated device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibDuplicateDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
UINTN Size;
|
||||
|
||||
//
|
||||
// Compute the size
|
||||
//
|
||||
Size = GetDevicePathSize (DevicePath);
|
||||
if (Size == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate space for duplicate device path
|
||||
//
|
||||
|
||||
return AllocateCopyPool (Size, DevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new device path by appending a second device path to a first device path.
|
||||
|
||||
This function creates a new device path by appending a copy of SecondDevicePath
|
||||
to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
|
||||
device node from SecondDevicePath is retained. The newly created device path is
|
||||
returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
|
||||
SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
|
||||
and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
|
||||
SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
|
||||
|
||||
If there is not enough memory for the newly allocated buffer, then NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param FirstDevicePath A pointer to a device path data structure.
|
||||
@param SecondDevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL If there is not enough memory for the newly allocated buffer.
|
||||
@retval NULL If FirstDevicePath or SecondDevicePath is invalid.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath
|
||||
)
|
||||
{
|
||||
UINTN Size;
|
||||
UINTN Size1;
|
||||
UINTN Size2;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath2;
|
||||
|
||||
//
|
||||
// If there's only 1 path, just duplicate it.
|
||||
//
|
||||
if (FirstDevicePath == NULL) {
|
||||
return DuplicateDevicePath ((SecondDevicePath != NULL) ? SecondDevicePath : &mUefiDevicePathLibEndDevicePath);
|
||||
}
|
||||
|
||||
if (SecondDevicePath == NULL) {
|
||||
return DuplicateDevicePath (FirstDevicePath);
|
||||
}
|
||||
|
||||
if (!IsDevicePathValid (FirstDevicePath, 0) || !IsDevicePathValid (SecondDevicePath, 0)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Allocate space for the combined device path. It only has one end node of
|
||||
// length EFI_DEVICE_PATH_PROTOCOL.
|
||||
//
|
||||
Size1 = GetDevicePathSize (FirstDevicePath);
|
||||
Size2 = GetDevicePathSize (SecondDevicePath);
|
||||
Size = Size1 + Size2 - END_DEVICE_PATH_LENGTH;
|
||||
|
||||
NewDevicePath = AllocatePool (Size);
|
||||
|
||||
if (NewDevicePath != NULL) {
|
||||
NewDevicePath = memcpy (NewDevicePath, FirstDevicePath, Size1);
|
||||
//
|
||||
// Over write FirstDevicePath EndNode and do the copy
|
||||
//
|
||||
DevicePath2 = (EFI_DEVICE_PATH_PROTOCOL *) ((CHAR8 *) NewDevicePath +
|
||||
(Size1 - END_DEVICE_PATH_LENGTH));
|
||||
memcpy (DevicePath2, SecondDevicePath, Size2);
|
||||
}
|
||||
|
||||
return NewDevicePath;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new path by appending the device node to the device path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device node
|
||||
specified by DevicePathNode to a copy of the device path specified by DevicePath
|
||||
in an allocated buffer. The end-of-device-path device node is moved after the
|
||||
end of the appended device node.
|
||||
If DevicePathNode is NULL then a copy of DevicePath is returned.
|
||||
If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
|
||||
path device node is returned.
|
||||
If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
|
||||
device node is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathNode A pointer to a single device path node.
|
||||
|
||||
@retval NULL If there is not enough memory for the new device path.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
A copy of DevicePathNode followed by an end-of-device-path node
|
||||
if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
A copy of an end-of-device-path node if both FirstDevicePath
|
||||
and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathNode (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NextNode;
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||
UINTN NodeLength;
|
||||
|
||||
if (DevicePathNode == NULL) {
|
||||
return DuplicateDevicePath ((DevicePath != NULL) ? DevicePath : &mUefiDevicePathLibEndDevicePath);
|
||||
}
|
||||
//
|
||||
// Build a Node that has a terminator on it
|
||||
//
|
||||
NodeLength = DevicePathNodeLength (DevicePathNode);
|
||||
|
||||
TempDevicePath = AllocatePool (NodeLength + END_DEVICE_PATH_LENGTH);
|
||||
if (TempDevicePath == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
TempDevicePath = memcpy (TempDevicePath, DevicePathNode, NodeLength);
|
||||
//
|
||||
// Add and end device path node to convert Node to device path
|
||||
//
|
||||
NextNode = NextDevicePathNode (TempDevicePath);
|
||||
SetDevicePathEndNode (NextNode);
|
||||
//
|
||||
// Append device paths
|
||||
//
|
||||
NewDevicePath = AppendDevicePath (DevicePath, TempDevicePath);
|
||||
|
||||
free (TempDevicePath);
|
||||
|
||||
return NewDevicePath;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new device path by appending the specified device path instance to the specified device
|
||||
path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device path
|
||||
instance specified by DevicePathInstance to a copy of the device path specified
|
||||
by DevicePath in a allocated buffer.
|
||||
The end-of-device-path device node is moved after the end of the appended device
|
||||
path instance and a new end-of-device-path-instance node is inserted between.
|
||||
If DevicePath is NULL, then a copy if DevicePathInstance is returned.
|
||||
If DevicePathInstance is NULL, then NULL is returned.
|
||||
If DevicePath or DevicePathInstance is invalid, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathInstance A pointer to a device path instance.
|
||||
|
||||
@return A pointer to the new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
|
||||
UINTN SrcSize;
|
||||
UINTN InstanceSize;
|
||||
|
||||
if (DevicePath == NULL) {
|
||||
return DuplicateDevicePath (DevicePathInstance);
|
||||
}
|
||||
|
||||
if (DevicePathInstance == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!IsDevicePathValid (DevicePath, 0) || !IsDevicePathValid (DevicePathInstance, 0)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SrcSize = GetDevicePathSize (DevicePath);
|
||||
InstanceSize = GetDevicePathSize (DevicePathInstance);
|
||||
|
||||
NewDevicePath = AllocatePool (SrcSize + InstanceSize);
|
||||
if (NewDevicePath != NULL) {
|
||||
|
||||
TempDevicePath = memcpy (NewDevicePath, DevicePath, SrcSize);;
|
||||
|
||||
while (!IsDevicePathEnd (TempDevicePath)) {
|
||||
TempDevicePath = NextDevicePathNode (TempDevicePath);
|
||||
}
|
||||
|
||||
TempDevicePath->SubType = END_INSTANCE_DEVICE_PATH_SUBTYPE;
|
||||
TempDevicePath = NextDevicePathNode (TempDevicePath);
|
||||
memcpy (TempDevicePath, DevicePathInstance, InstanceSize);
|
||||
}
|
||||
|
||||
return NewDevicePath;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a copy of the current device path instance and returns a pointer to the next device path
|
||||
instance.
|
||||
|
||||
This function creates a copy of the current device path instance. It also updates
|
||||
DevicePath to point to the next device path instance in the device path (or NULL
|
||||
if no more) and updates Size to hold the size of the device path instance copy.
|
||||
If DevicePath is NULL, then NULL is returned.
|
||||
If DevicePath points to a invalid device path, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
If Size is NULL, then ASSERT().
|
||||
|
||||
@param DevicePath On input, this holds the pointer to the current
|
||||
device path instance. On output, this holds
|
||||
the pointer to the next device path instance
|
||||
or NULL if there are no more device path
|
||||
instances in the device path pointer to a
|
||||
device path data structure.
|
||||
@param Size On output, this holds the size of the device
|
||||
path instance, in bytes or zero, if DevicePath
|
||||
is NULL.
|
||||
|
||||
@return A pointer to the current device path instance.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibGetNextDevicePathInstance (
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||
UINTN *Size
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevPath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *ReturnValue;
|
||||
UINT8 Temp;
|
||||
|
||||
ASSERT (Size != NULL);
|
||||
|
||||
if (DevicePath == NULL || *DevicePath == NULL) {
|
||||
*Size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!IsDevicePathValid (*DevicePath, 0)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Find the end of the device path instance
|
||||
//
|
||||
DevPath = *DevicePath;
|
||||
while (!IsDevicePathEndType (DevPath)) {
|
||||
DevPath = NextDevicePathNode (DevPath);
|
||||
}
|
||||
|
||||
//
|
||||
// Compute the size of the device path instance
|
||||
//
|
||||
*Size = ((UINTN) DevPath - (UINTN) (*DevicePath)) + sizeof (EFI_DEVICE_PATH_PROTOCOL);
|
||||
|
||||
//
|
||||
// Make a copy and return the device path instance
|
||||
//
|
||||
Temp = DevPath->SubType;
|
||||
DevPath->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
|
||||
ReturnValue = DuplicateDevicePath (*DevicePath);
|
||||
DevPath->SubType = Temp;
|
||||
|
||||
//
|
||||
// If DevPath is the end of an entire device path, then another instance
|
||||
// does not follow, so *DevicePath is set to NULL.
|
||||
//
|
||||
if (DevicePathSubType (DevPath) == END_ENTIRE_DEVICE_PATH_SUBTYPE) {
|
||||
*DevicePath = NULL;
|
||||
} else {
|
||||
*DevicePath = NextDevicePathNode (DevPath);
|
||||
}
|
||||
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a device node.
|
||||
|
||||
This function creates a new device node in a newly allocated buffer of size
|
||||
NodeLength and initializes the device path node header with NodeType and NodeSubType.
|
||||
The new device path node is returned.
|
||||
If NodeLength is smaller than a device path header, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param NodeType The device node type for the new device node.
|
||||
@param NodeSubType The device node sub-type for the new device node.
|
||||
@param NodeLength The length of the new device node.
|
||||
|
||||
@return The new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibCreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
|
||||
if (NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL)) {
|
||||
//
|
||||
// NodeLength is less than the size of the header.
|
||||
//
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DevicePath = AllocateZeroPool (NodeLength);
|
||||
if (DevicePath != NULL) {
|
||||
DevicePath->Type = NodeType;
|
||||
DevicePath->SubType = NodeSubType;
|
||||
SetDevicePathNodeLength (DevicePath, NodeLength);
|
||||
}
|
||||
|
||||
return DevicePath;
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if a device path is single or multi-instance.
|
||||
|
||||
This function returns TRUE if the device path specified by DevicePath is
|
||||
multi-instance.
|
||||
Otherwise, FALSE is returned.
|
||||
If DevicePath is NULL or invalid, then FALSE is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval TRUE DevicePath is multi-instance.
|
||||
@retval FALSE DevicePath is not multi-instance, or DevicePath
|
||||
is NULL or invalid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
UefiDevicePathLibIsDevicePathMultiInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *Node;
|
||||
|
||||
if (DevicePath == NULL) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!IsDevicePathValid (DevicePath, 0)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Node = DevicePath;
|
||||
while (!IsDevicePathEnd (Node)) {
|
||||
if (IsDevicePathEndInstance (Node)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Node = NextDevicePathNode (Node);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Retrieves the device path protocol from a handle.
|
||||
|
||||
This function returns the device path protocol from the handle specified by Handle.
|
||||
If Handle is NULL or Handle does not contain a device path protocol, then NULL
|
||||
is returned.
|
||||
|
||||
@param Handle The handle from which to retrieve the device
|
||||
path protocol.
|
||||
|
||||
@return The device path protocol from the handle specified by Handle.
|
||||
|
||||
**/
|
||||
/*
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
DevicePathFromHandle (
|
||||
EFI_HANDLE Handle
|
||||
)
|
||||
{
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = gBS->HandleProtocol (
|
||||
Handle,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
(VOID *) &DevicePath
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DevicePath = NULL;
|
||||
}
|
||||
return DevicePath;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
Allocates a device path for a file and appends it to an existing device path.
|
||||
|
||||
If Device is a valid device handle that contains a device path protocol, then a device path for
|
||||
the file specified by FileName is allocated and appended to the device path associated with the
|
||||
handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
|
||||
that does not support the device path protocol, then a device path containing a single device
|
||||
path node for the file specified by FileName is allocated and returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
If FileName is NULL, then ASSERT().
|
||||
If FileName is not aligned on a 16-bit boundary, then ASSERT().
|
||||
|
||||
@param Device A pointer to a device handle. This parameter
|
||||
is optional and may be NULL.
|
||||
@param FileName A pointer to a Null-terminated Unicode string.
|
||||
|
||||
@return The allocated device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
FileDevicePath (
|
||||
EFI_HANDLE Device, OPTIONAL
|
||||
CONST CHAR16 *FileName
|
||||
)
|
||||
{
|
||||
UINTN Size;
|
||||
FILEPATH_DEVICE_PATH *FilePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
|
||||
EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;
|
||||
|
||||
DevicePath = NULL;
|
||||
|
||||
Size = StrSize (FileName);
|
||||
FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
|
||||
if (FileDevicePath != NULL) {
|
||||
FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
|
||||
FilePath->Header.Type = MEDIA_DEVICE_PATH;
|
||||
FilePath->Header.SubType = MEDIA_FILEPATH_DP;
|
||||
memcpy (&FilePath->PathName, FileName, Size);
|
||||
SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
|
||||
SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
|
||||
|
||||
//if (Device != NULL) {
|
||||
// DevicePath = DevicePathFromHandle (Device);
|
||||
//}
|
||||
|
||||
DevicePath = AppendDevicePath (DevicePath, FileDevicePath);
|
||||
free (FileDevicePath);
|
||||
}
|
||||
|
||||
return DevicePath;
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
## @file
|
||||
# GNU/Linux makefile for 'DevicePath' module build.
|
||||
#
|
||||
# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
ARCH ?= IA32
|
||||
MAKEROOT ?= ..
|
||||
|
||||
APPNAME = DevicePath
|
||||
|
||||
OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o DevicePathUtilities.o
|
||||
|
||||
include $(MAKEROOT)/Makefiles/app.makefile
|
||||
|
||||
LIBS = -lCommon
|
||||
ifeq ($(CYGWIN), CYGWIN)
|
||||
LIBS += -L/lib/e2fsprogs -luuid
|
||||
endif
|
||||
|
||||
ifeq ($(LINUX), Linux)
|
||||
LIBS += -luuid
|
||||
endif
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
## @file
|
||||
# Windows makefile for 'DevicePath' module build.
|
||||
#
|
||||
# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
!INCLUDE ..\Makefiles\ms.common
|
||||
|
||||
APPNAME = DevicePath
|
||||
|
||||
LIBS = $(LIB_PATH)\Common.lib
|
||||
|
||||
OBJECTS = DevicePath.obj UefiDevicePathLib.obj DevicePathFromText.obj DevicePathUtilities.obj
|
||||
|
||||
#CFLAGS = $(CFLAGS) /nodefaultlib:libc.lib
|
||||
|
||||
!INCLUDE ..\Makefiles\ms.app
|
||||
|
|
@ -0,0 +1,298 @@
|
|||
/** @file
|
||||
Device Path services. The thing to remember is device paths are built out of
|
||||
nodes. The device path is terminated by an end node that is length
|
||||
sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
|
||||
all over this file.
|
||||
|
||||
The only place where multi-instance device paths are supported is in
|
||||
environment varibles. Multi-instance device paths should never be placed
|
||||
on a Handle.
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php.
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include "UefiDevicePathLib.h"
|
||||
|
||||
/**
|
||||
Returns the size of a device path in bytes.
|
||||
|
||||
This function returns the size, in bytes, of the device path data structure
|
||||
specified by DevicePath including the end of device path node.
|
||||
If DevicePath is NULL or invalid, then 0 is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval 0 If DevicePath is NULL or invalid.
|
||||
@retval Others The size of a device path in bytes.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
GetDevicePathSize (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibGetDevicePathSize (DevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new copy of an existing device path.
|
||||
|
||||
This function allocates space for a new copy of the device path specified by DevicePath.
|
||||
If DevicePath is NULL, then NULL is returned. If the memory is successfully
|
||||
allocated, then the contents of DevicePath are copied to the newly allocated
|
||||
buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL DevicePath is NULL or invalid.
|
||||
@retval Others A pointer to the duplicated device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
DuplicateDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibDuplicateDevicePath (DevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new device path by appending a second device path to a first device path.
|
||||
|
||||
This function creates a new device path by appending a copy of SecondDevicePath
|
||||
to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
|
||||
device node from SecondDevicePath is retained. The newly created device path is
|
||||
returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
|
||||
SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
|
||||
and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
|
||||
SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
|
||||
|
||||
If there is not enough memory for the newly allocated buffer, then NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param FirstDevicePath A pointer to a device path data structure.
|
||||
@param SecondDevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL If there is not enough memory for the newly allocated buffer.
|
||||
@retval NULL If FirstDevicePath or SecondDevicePath is invalid.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new path by appending the device node to the device path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device node
|
||||
specified by DevicePathNode to a copy of the device path specified by DevicePath
|
||||
in an allocated buffer. The end-of-device-path device node is moved after the
|
||||
end of the appended device node.
|
||||
If DevicePathNode is NULL then a copy of DevicePath is returned.
|
||||
If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
|
||||
path device node is returned.
|
||||
If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
|
||||
device node is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathNode A pointer to a single device path node.
|
||||
|
||||
@retval NULL If there is not enough memory for the new device path.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
A copy of DevicePathNode followed by an end-of-device-path node
|
||||
if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
A copy of an end-of-device-path node if both FirstDevicePath
|
||||
and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePathNode (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a new device path by appending the specified device path instance to the specified device
|
||||
path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device path
|
||||
instance specified by DevicePathInstance to a copy of the device path specified
|
||||
by DevicePath in a allocated buffer.
|
||||
The end-of-device-path device node is moved after the end of the appended device
|
||||
path instance and a new end-of-device-path-instance node is inserted between.
|
||||
If DevicePath is NULL, then a copy if DevicePathInstance is returned.
|
||||
If DevicePathInstance is NULL, then NULL is returned.
|
||||
If DevicePath or DevicePathInstance is invalid, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathInstance A pointer to a device path instance.
|
||||
|
||||
@return A pointer to the new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePathInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a copy of the current device path instance and returns a pointer to the next device path
|
||||
instance.
|
||||
|
||||
This function creates a copy of the current device path instance. It also updates
|
||||
DevicePath to point to the next device path instance in the device path (or NULL
|
||||
if no more) and updates Size to hold the size of the device path instance copy.
|
||||
If DevicePath is NULL, then NULL is returned.
|
||||
If DevicePath points to a invalid device path, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
If Size is NULL, then ASSERT().
|
||||
|
||||
@param DevicePath On input, this holds the pointer to the current
|
||||
device path instance. On output, this holds
|
||||
the pointer to the next device path instance
|
||||
or NULL if there are no more device path
|
||||
instances in the device path pointer to a
|
||||
device path data structure.
|
||||
@param Size On output, this holds the size of the device
|
||||
path instance, in bytes or zero, if DevicePath
|
||||
is NULL.
|
||||
|
||||
@return A pointer to the current device path instance.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
GetNextDevicePathInstance (
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||
UINTN *Size
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);
|
||||
}
|
||||
|
||||
/**
|
||||
Creates a device node.
|
||||
|
||||
This function creates a new device node in a newly allocated buffer of size
|
||||
NodeLength and initializes the device path node header with NodeType and NodeSubType.
|
||||
The new device path node is returned.
|
||||
If NodeLength is smaller than a device path header, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param NodeType The device node type for the new device node.
|
||||
@param NodeSubType The device node sub-type for the new device node.
|
||||
@param NodeLength The length of the new device node.
|
||||
|
||||
@return The new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
CreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);
|
||||
}
|
||||
|
||||
/**
|
||||
Determines if a device path is single or multi-instance.
|
||||
|
||||
This function returns TRUE if the device path specified by DevicePath is
|
||||
multi-instance.
|
||||
Otherwise, FALSE is returned.
|
||||
If DevicePath is NULL or invalid, then FALSE is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval TRUE DevicePath is multi-instance.
|
||||
@retval FALSE DevicePath is not multi-instance, or DevicePath
|
||||
is NULL or invalid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
IsDevicePathMultiInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert text to the binary representation of a device node.
|
||||
|
||||
@param TextDeviceNode TextDeviceNode points to the text representation of a device
|
||||
node. Conversion starts with the first character and continues
|
||||
until the first non-device node character.
|
||||
|
||||
@return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
|
||||
insufficient memory or text unsupported.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
ConvertTextToDeviceNode (
|
||||
CONST CHAR16 *TextDeviceNode
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);
|
||||
}
|
||||
|
||||
/**
|
||||
Convert text to the binary representation of a device path.
|
||||
|
||||
|
||||
@param TextDevicePath TextDevicePath points to the text representation of a device
|
||||
path. Conversion starts with the first character and continues
|
||||
until the first non-device node character.
|
||||
|
||||
@return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
|
||||
there was insufficient memory.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
ConvertTextToDevicePath (
|
||||
CONST CHAR16 *TextDevicePath
|
||||
)
|
||||
{
|
||||
return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);
|
||||
}
|
|
@ -0,0 +1,452 @@
|
|||
/** @file
|
||||
Definition for Device Path library.
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
#ifndef _UEFI_DEVICE_PATH_LIB_H_
|
||||
#define _UEFI_DEVICE_PATH_LIB_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#ifdef __GNUC__
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <direct.h>
|
||||
#endif
|
||||
#include <Common/UefiBaseTypes.h>
|
||||
#include <Protocol/DevicePath.h>
|
||||
#include <Protocol/DevicePathUtilities.h>
|
||||
#include "CommonLib.h"
|
||||
#include "EfiUtilityMsgs.h"
|
||||
|
||||
#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))
|
||||
#define MAX_DEVICE_PATH_NODE_COUNT 1024
|
||||
#define SIZE_64KB 0x00010000
|
||||
|
||||
//
|
||||
// Private Data structure
|
||||
//
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
(*DEVICE_PATH_FROM_TEXT) (
|
||||
IN CHAR16 *Str
|
||||
);
|
||||
|
||||
typedef struct {
|
||||
CHAR16 *Str;
|
||||
UINTN Count;
|
||||
UINTN Capacity;
|
||||
} POOL_PRINT;
|
||||
|
||||
|
||||
typedef struct {
|
||||
CHAR16 *DevicePathNodeText;
|
||||
DEVICE_PATH_FROM_TEXT Function;
|
||||
} DEVICE_PATH_FROM_TEXT_TABLE;
|
||||
|
||||
typedef struct {
|
||||
BOOLEAN ClassExist;
|
||||
UINT8 Class;
|
||||
BOOLEAN SubClassExist;
|
||||
UINT8 SubClass;
|
||||
} USB_CLASS_TEXT;
|
||||
|
||||
#define USB_CLASS_AUDIO 1
|
||||
#define USB_CLASS_CDCCONTROL 2
|
||||
#define USB_CLASS_HID 3
|
||||
#define USB_CLASS_IMAGE 6
|
||||
#define USB_CLASS_PRINTER 7
|
||||
#define USB_CLASS_MASS_STORAGE 8
|
||||
#define USB_CLASS_HUB 9
|
||||
#define USB_CLASS_CDCDATA 10
|
||||
#define USB_CLASS_SMART_CARD 11
|
||||
#define USB_CLASS_VIDEO 14
|
||||
#define USB_CLASS_DIAGNOSTIC 220
|
||||
#define USB_CLASS_WIRELESS 224
|
||||
|
||||
#define USB_CLASS_RESERVE 254
|
||||
#define USB_SUBCLASS_FW_UPDATE 1
|
||||
#define USB_SUBCLASS_IRDA_BRIDGE 2
|
||||
#define USB_SUBCLASS_TEST 3
|
||||
|
||||
#define RFC_1700_UDP_PROTOCOL 17
|
||||
#define RFC_1700_TCP_PROTOCOL 6
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
EFI_GUID Guid;
|
||||
UINT8 VendorDefinedData[1];
|
||||
} VENDOR_DEFINED_HARDWARE_DEVICE_PATH;
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
EFI_GUID Guid;
|
||||
UINT8 VendorDefinedData[1];
|
||||
} VENDOR_DEFINED_MESSAGING_DEVICE_PATH;
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
EFI_GUID Guid;
|
||||
UINT8 VendorDefinedData[1];
|
||||
} VENDOR_DEFINED_MEDIA_DEVICE_PATH;
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
UINT32 Hid;
|
||||
UINT32 Uid;
|
||||
UINT32 Cid;
|
||||
CHAR8 HidUidCidStr[3];
|
||||
} ACPI_EXTENDED_HID_DEVICE_PATH_WITH_STR;
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
UINT16 NetworkProtocol;
|
||||
UINT16 LoginOption;
|
||||
UINT64 Lun;
|
||||
UINT16 TargetPortalGroupTag;
|
||||
CHAR8 TargetName[1];
|
||||
} ISCSI_DEVICE_PATH_WITH_NAME;
|
||||
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_PROTOCOL Header;
|
||||
EFI_GUID Guid;
|
||||
UINT8 VendorDefinedData[1];
|
||||
} VENDOR_DEVICE_PATH_WITH_DATA;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
/**
|
||||
Returns the size of a device path in bytes.
|
||||
|
||||
This function returns the size, in bytes, of the device path data structure
|
||||
specified by DevicePath including the end of device path node.
|
||||
If DevicePath is NULL or invalid, then 0 is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval 0 If DevicePath is NULL or invalid.
|
||||
@retval Others The size of a device path in bytes.
|
||||
|
||||
**/
|
||||
UINTN
|
||||
UefiDevicePathLibGetDevicePathSize (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new copy of an existing device path.
|
||||
|
||||
This function allocates space for a new copy of the device path specified by DevicePath.
|
||||
If DevicePath is NULL, then NULL is returned. If the memory is successfully
|
||||
allocated, then the contents of DevicePath are copied to the newly allocated
|
||||
buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL DevicePath is NULL or invalid.
|
||||
@retval Others A pointer to the duplicated device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibDuplicateDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new device path by appending a second device path to a first device path.
|
||||
|
||||
This function creates a new device path by appending a copy of SecondDevicePath
|
||||
to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
|
||||
device node from SecondDevicePath is retained. The newly created device path is
|
||||
returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
|
||||
SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
|
||||
and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
|
||||
SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
|
||||
|
||||
If there is not enough memory for the newly allocated buffer, then NULL is returned.
|
||||
The memory for the new device path is allocated from EFI boot services memory.
|
||||
It is the responsibility of the caller to free the memory allocated.
|
||||
|
||||
@param FirstDevicePath A pointer to a device path data structure.
|
||||
@param SecondDevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval NULL If there is not enough memory for the newly allocated buffer.
|
||||
@retval NULL If FirstDevicePath or SecondDevicePath is invalid.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new path by appending the device node to the device path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device node
|
||||
specified by DevicePathNode to a copy of the device path specified by DevicePath
|
||||
in an allocated buffer. The end-of-device-path device node is moved after the
|
||||
end of the appended device node.
|
||||
If DevicePathNode is NULL then a copy of DevicePath is returned.
|
||||
If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
|
||||
path device node is returned.
|
||||
If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
|
||||
device node is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathNode A pointer to a single device path node.
|
||||
|
||||
@retval NULL If there is not enough memory for the new device path.
|
||||
@retval Others A pointer to the new device path if success.
|
||||
A copy of DevicePathNode followed by an end-of-device-path node
|
||||
if both FirstDevicePath and SecondDevicePath are NULL.
|
||||
A copy of an end-of-device-path node if both FirstDevicePath
|
||||
and SecondDevicePath are NULL.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathNode (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new device path by appending the specified device path instance to the specified device
|
||||
path.
|
||||
|
||||
This function creates a new device path by appending a copy of the device path
|
||||
instance specified by DevicePathInstance to a copy of the device path specified
|
||||
by DevicePath in a allocated buffer.
|
||||
The end-of-device-path device node is moved after the end of the appended device
|
||||
path instance and a new end-of-device-path-instance node is inserted between.
|
||||
If DevicePath is NULL, then a copy if DevicePathInstance is returned.
|
||||
If DevicePathInstance is NULL, then NULL is returned.
|
||||
If DevicePath or DevicePathInstance is invalid, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
@param DevicePathInstance A pointer to a device path instance.
|
||||
|
||||
@return A pointer to the new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a copy of the current device path instance and returns a pointer to the next device path
|
||||
instance.
|
||||
|
||||
This function creates a copy of the current device path instance. It also updates
|
||||
DevicePath to point to the next device path instance in the device path (or NULL
|
||||
if no more) and updates Size to hold the size of the device path instance copy.
|
||||
If DevicePath is NULL, then NULL is returned.
|
||||
If DevicePath points to a invalid device path, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
If Size is NULL, then ASSERT().
|
||||
|
||||
@param DevicePath On input, this holds the pointer to the current
|
||||
device path instance. On output, this holds
|
||||
the pointer to the next device path instance
|
||||
or NULL if there are no more device path
|
||||
instances in the device path pointer to a
|
||||
device path data structure.
|
||||
@param Size On output, this holds the size of the device
|
||||
path instance, in bytes or zero, if DevicePath
|
||||
is NULL.
|
||||
|
||||
@return A pointer to the current device path instance.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibGetNextDevicePathInstance (
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||
UINTN *Size
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a device node.
|
||||
|
||||
This function creates a new device node in a newly allocated buffer of size
|
||||
NodeLength and initializes the device path node header with NodeType and NodeSubType.
|
||||
The new device path node is returned.
|
||||
If NodeLength is smaller than a device path header, then NULL is returned.
|
||||
If there is not enough memory to allocate space for the new device path, then
|
||||
NULL is returned.
|
||||
The memory is allocated from EFI boot services memory. It is the responsibility
|
||||
of the caller to free the memory allocated.
|
||||
|
||||
@param NodeType The device node type for the new device node.
|
||||
@param NodeSubType The device node sub-type for the new device node.
|
||||
@param NodeLength The length of the new device node.
|
||||
|
||||
@return The new device path.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibCreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
);
|
||||
|
||||
/**
|
||||
Determines if a device path is single or multi-instance.
|
||||
|
||||
This function returns TRUE if the device path specified by DevicePath is
|
||||
multi-instance.
|
||||
Otherwise, FALSE is returned.
|
||||
If DevicePath is NULL or invalid, then FALSE is returned.
|
||||
|
||||
@param DevicePath A pointer to a device path data structure.
|
||||
|
||||
@retval TRUE DevicePath is multi-instance.
|
||||
@retval FALSE DevicePath is not multi-instance, or DevicePath
|
||||
is NULL or invalid.
|
||||
|
||||
**/
|
||||
BOOLEAN
|
||||
UefiDevicePathLibIsDevicePathMultiInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Convert text to the binary representation of a device node.
|
||||
|
||||
@param TextDeviceNode TextDeviceNode points to the text representation of a device
|
||||
node. Conversion starts with the first character and continues
|
||||
until the first non-device node character.
|
||||
|
||||
@return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
|
||||
insufficient memory or text unsupported.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibConvertTextToDeviceNode (
|
||||
CONST CHAR16 *TextDeviceNode
|
||||
);
|
||||
|
||||
/**
|
||||
Convert text to the binary representation of a device path.
|
||||
|
||||
|
||||
@param TextDevicePath TextDevicePath points to the text representation of a device
|
||||
path. Conversion starts with the first character and continues
|
||||
until the first non-device node character.
|
||||
|
||||
@return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
|
||||
there was insufficient memory.
|
||||
|
||||
**/
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibConvertTextToDevicePath (
|
||||
CONST CHAR16 *TextDevicePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
CreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
CreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsDevicePathMultiInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
GetNextDevicePathInstance (
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||
UINTN *Size
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePathInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePathNode (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL
|
||||
);
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
AppendDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
DuplicateDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
UINTN
|
||||
GetDevicePathSize (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
CHAR16 *
|
||||
ConvertDeviceNodeToText (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
|
||||
BOOLEAN DisplayOnly,
|
||||
BOOLEAN AllowShortcuts
|
||||
);
|
||||
|
||||
CHAR16 *
|
||||
ConvertDevicePathToText (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
BOOLEAN DisplayOnly,
|
||||
BOOLEAN AllowShortcuts
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
ConvertTextToDeviceNode (
|
||||
CONST CHAR16 *TextDeviceNode
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
ConvertTextToDevicePath (
|
||||
CONST CHAR16 *TextDevicePath
|
||||
);
|
||||
|
||||
#endif
|
|
@ -67,7 +67,8 @@ APPLICATIONS = \
|
|||
LzmaCompress \
|
||||
Split \
|
||||
TianoCompress \
|
||||
VolInfo
|
||||
VolInfo \
|
||||
DevicePath
|
||||
|
||||
SUBDIRS := $(LIBRARIES) $(APPLICATIONS)
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/** @file
|
||||
This file contains the Bluetooth definitions that are consumed by drivers.
|
||||
These definitions are from Bluetooth Core Specification Version 4.0 June, 2010
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _BLUETOOTH_H_
|
||||
#define _BLUETOOTH_H_
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
///
|
||||
/// BLUETOOTH_ADDRESS
|
||||
///
|
||||
typedef struct {
|
||||
///
|
||||
/// 48bit Bluetooth device address.
|
||||
///
|
||||
UINT8 Address[6];
|
||||
} BLUETOOTH_ADDRESS;
|
||||
|
||||
///
|
||||
/// BLUETOOTH_CLASS_OF_DEVICE. See Bluetooth specification for detail.
|
||||
///
|
||||
typedef struct {
|
||||
UINT8 FormatType:2;
|
||||
UINT8 MinorDeviceClass: 6;
|
||||
UINT16 MajorDeviceClass: 5;
|
||||
UINT16 MajorServiceClass:11;
|
||||
} BLUETOOTH_CLASS_OF_DEVICE;
|
||||
|
||||
///
|
||||
/// BLUETOOTH_LE_ADDRESS
|
||||
///
|
||||
typedef struct {
|
||||
///
|
||||
/// 48-bit Bluetooth device address
|
||||
///
|
||||
UINT8 Address[6];
|
||||
///
|
||||
/// 0x00 - Public Device Address
|
||||
/// 0x01 - Random Device Address
|
||||
///
|
||||
UINT8 Type;
|
||||
} BLUETOOTH_LE_ADDRESS;
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#define BLUETOOTH_HCI_COMMAND_LOCAL_READABLE_NAME_MAX_SIZE 248
|
||||
|
||||
#define BLUETOOTH_HCI_LINK_KEY_SIZE 16
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,294 @@
|
|||
/** @file
|
||||
EFI_DEVICE_PATH_UTILITIES_PROTOCOL as defined in UEFI 2.0.
|
||||
Use to create and manipulate device paths and device nodes.
|
||||
|
||||
Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
|
||||
This program and the accompanying materials
|
||||
are licensed and made available under the terms and conditions of the BSD License
|
||||
which accompanies this distribution. The full text of the license may be found at
|
||||
http://opensource.org/licenses/bsd-license.php
|
||||
|
||||
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef __DEVICE_PATH_UTILITIES_H__
|
||||
#define __DEVICE_PATH_UTILITIES_H__
|
||||
|
||||
///
|
||||
/// Device Path Utilities protocol
|
||||
///
|
||||
#define EFI_DEVICE_PATH_UTILITIES_GUID \
|
||||
{ \
|
||||
0x379be4e, 0xd706, 0x437d, {0xb0, 0x37, 0xed, 0xb8, 0x2f, 0xb7, 0x72, 0xa4 } \
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the size of the device path, in bytes.
|
||||
|
||||
@param DevicePath Points to the start of the EFI device path.
|
||||
|
||||
@return Size Size of the specified device path, in bytes, including the end-of-path tag.
|
||||
@retval 0 DevicePath is NULL
|
||||
|
||||
**/
|
||||
typedef
|
||||
UINTN
|
||||
( *EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
Create a duplicate of the specified path.
|
||||
|
||||
@param DevicePath Points to the source EFI device path.
|
||||
|
||||
@retval Pointer A pointer to the duplicate device path.
|
||||
@retval NULL insufficient memory or DevicePath is NULL
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
/**
|
||||
Create a new path by appending the second device path to the first.
|
||||
If Src1 is NULL and Src2 is non-NULL, then a duplicate of Src2 is returned.
|
||||
If Src1 is non-NULL and Src2 is NULL, then a duplicate of Src1 is returned.
|
||||
If Src1 and Src2 are both NULL, then a copy of an end-of-device-path is returned.
|
||||
|
||||
@param Src1 Points to the first device path.
|
||||
@param Src2 Points to the second device path.
|
||||
|
||||
@retval Pointer A pointer to the newly created device path.
|
||||
@retval NULL Memory could not be allocated
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_APPEND_PATH)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *Src1,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *Src2
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new path by appending the device node to the device path.
|
||||
If DeviceNode is NULL then a copy of DevicePath is returned.
|
||||
If DevicePath is NULL then a copy of DeviceNode, followed by an end-of-device path device node is returned.
|
||||
If both DeviceNode and DevicePath are NULL then a copy of an end-of-device-path device node is returned.
|
||||
|
||||
@param DevicePath Points to the device path.
|
||||
@param DeviceNode Points to the device node.
|
||||
|
||||
@retval Pointer A pointer to the allocated device node.
|
||||
@retval NULL There was insufficient memory.
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_APPEND_NODE)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a new path by appending the specified device path instance to the specified device path.
|
||||
|
||||
@param DevicePath Points to the device path. If NULL, then ignored.
|
||||
@param DevicePathInstance Points to the device path instance.
|
||||
|
||||
@retval Pointer A pointer to the newly created device path
|
||||
@retval NULL Memory could not be allocated or DevicePathInstance is NULL.
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a copy of the current device path instance and returns a pointer to the next device path
|
||||
instance.
|
||||
|
||||
@param DevicePathInstance On input, this holds the pointer to the current device path
|
||||
instance. On output, this holds the pointer to the next
|
||||
device path instance or NULL if there are no more device
|
||||
path instances in the device path.
|
||||
@param DevicePathInstanceSize On output, this holds the size of the device path instance,
|
||||
in bytes or zero, if DevicePathInstance is NULL.
|
||||
If NULL, then the instance size is not output.
|
||||
|
||||
@retval Pointer A pointer to the copy of the current device path instance.
|
||||
@retval NULL DevicePathInstace was NULL on entry or there was insufficient memory.
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE)(
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePathInstance,
|
||||
UINTN *DevicePathInstanceSize
|
||||
);
|
||||
|
||||
/**
|
||||
Creates a device node
|
||||
|
||||
@param NodeType NodeType is the device node type (EFI_DEVICE_PATH.Type) for
|
||||
the new device node.
|
||||
@param NodeSubType NodeSubType is the device node sub-type
|
||||
EFI_DEVICE_PATH.SubType) for the new device node.
|
||||
@param NodeLength NodeLength is the length of the device node
|
||||
(EFI_DEVICE_PATH.Length) for the new device node.
|
||||
|
||||
@retval Pointer A pointer to the newly created device node.
|
||||
@retval NULL NodeLength is less than
|
||||
the size of the header or there was insufficient memory.
|
||||
|
||||
**/
|
||||
typedef
|
||||
EFI_DEVICE_PATH_PROTOCOL*
|
||||
( *EFI_DEVICE_PATH_UTILS_CREATE_NODE)(
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
);
|
||||
|
||||
/**
|
||||
Returns whether a device path is multi-instance.
|
||||
|
||||
@param DevicePath Points to the device path. If NULL, then ignored.
|
||||
|
||||
@retval TRUE The device path has more than one instance
|
||||
@retval FALSE The device path is empty or contains only a single instance.
|
||||
|
||||
**/
|
||||
typedef
|
||||
BOOLEAN
|
||||
( *EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE)(
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
///
|
||||
/// This protocol is used to creates and manipulates device paths and device nodes.
|
||||
///
|
||||
typedef struct {
|
||||
EFI_DEVICE_PATH_UTILS_GET_DEVICE_PATH_SIZE GetDevicePathSize;
|
||||
EFI_DEVICE_PATH_UTILS_DUP_DEVICE_PATH DuplicateDevicePath;
|
||||
EFI_DEVICE_PATH_UTILS_APPEND_PATH AppendDevicePath;
|
||||
EFI_DEVICE_PATH_UTILS_APPEND_NODE AppendDeviceNode;
|
||||
EFI_DEVICE_PATH_UTILS_APPEND_INSTANCE AppendDevicePathInstance;
|
||||
EFI_DEVICE_PATH_UTILS_GET_NEXT_INSTANCE GetNextDevicePathInstance;
|
||||
EFI_DEVICE_PATH_UTILS_IS_MULTI_INSTANCE IsDevicePathMultiInstance;
|
||||
EFI_DEVICE_PATH_UTILS_CREATE_NODE CreateDeviceNode;
|
||||
} EFI_DEVICE_PATH_UTILITIES_PROTOCOL;
|
||||
|
||||
extern EFI_GUID gEfiDevicePathUtilitiesProtocolGuid;
|
||||
|
||||
VOID
|
||||
SetDevicePathEndNode (
|
||||
VOID *Node
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsDevicePathValid (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
UINTN MaxSize
|
||||
);
|
||||
|
||||
UINT8
|
||||
DevicePathType (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
UINT8
|
||||
DevicePathSubType (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
UINTN
|
||||
DevicePathNodeLength (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
NextDevicePathNode (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsDevicePathEndType (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
IsDevicePathEnd (
|
||||
CONST VOID *Node
|
||||
);
|
||||
BOOLEAN
|
||||
IsDevicePathEndInstance (
|
||||
CONST VOID *Node
|
||||
);
|
||||
|
||||
UINT16
|
||||
SetDevicePathNodeLength (
|
||||
VOID *Node,
|
||||
UINTN Length
|
||||
);
|
||||
|
||||
VOID
|
||||
SetDevicePathEndNode (
|
||||
VOID *Node
|
||||
);
|
||||
|
||||
UINTN
|
||||
UefiDevicePathLibGetDevicePathSize (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibDuplicateDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePath (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathNode (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibAppendDevicePathInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibGetNextDevicePathInstance (
|
||||
EFI_DEVICE_PATH_PROTOCOL **DevicePath,
|
||||
UINTN *Size
|
||||
);
|
||||
|
||||
EFI_DEVICE_PATH_PROTOCOL *
|
||||
UefiDevicePathLibCreateDeviceNode (
|
||||
UINT8 NodeType,
|
||||
UINT8 NodeSubType,
|
||||
UINT16 NodeLength
|
||||
);
|
||||
|
||||
BOOLEAN
|
||||
UefiDevicePathLibIsDevicePathMultiInstance (
|
||||
CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
||||
);
|
||||
|
||||
#endif
|
|
@ -1,7 +1,7 @@
|
|||
## @file
|
||||
# Windows makefile for C tools build.
|
||||
#
|
||||
# Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
|
@ -32,7 +32,8 @@ APPLICATIONS = \
|
|||
Split \
|
||||
TianoCompress \
|
||||
VolInfo \
|
||||
VfrCompile
|
||||
VfrCompile \
|
||||
DevicePath
|
||||
|
||||
all: libs apps install
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
|
|||
from Common.MultipleWorkspace import MultipleWorkspace as mws
|
||||
import uuid
|
||||
from CommonDataClass.Exceptions import BadExpression
|
||||
|
||||
import subprocess
|
||||
## Regular expression used to find out place holders in string template
|
||||
gPlaceholderPattern = re.compile("\$\{([^$()\s]+)\}", re.MULTILINE | re.UNICODE)
|
||||
|
||||
|
@ -1474,7 +1474,37 @@ def AnalyzePcdExpression(Setting):
|
|||
return FieldList
|
||||
|
||||
def ParseDevPathValue (Value):
|
||||
pass
|
||||
DevPathList = [ "Path","HardwarePath","Pci","PcCard","MemoryMapped","VenHw","Ctrl","BMC","AcpiPath","Acpi","PciRoot",
|
||||
"PcieRoot","Floppy","Keyboard","Serial","ParallelPort","AcpiEx","AcpiExp","AcpiAdr","Msg","Ata","Scsi",
|
||||
"Fibre","FibreEx","I1394","USB","I2O","Infiniband","VenMsg","VenPcAnsi","VenVt100","VenVt100Plus",
|
||||
"VenUtf8","UartFlowCtrl","SAS","SasEx","NVMe","UFS","SD","eMMC","DebugPort","MAC","IPv4","IPv6","Uart",
|
||||
"UsbClass","UsbAudio","UsbCDCControl","UsbHID","UsbImage","UsbPrinter","UsbMassStorage","UsbHub",
|
||||
"UsbCDCData","UsbSmartCard","UsbVideo","UsbDiagnostic","UsbWireless","UsbDeviceFirmwareUpdate",
|
||||
"UsbIrdaBridge","UsbTestAndMeasurement","UsbWwid","Unit","iSCSI","Vlan","Uri","Bluetooth","Wi-Fi",
|
||||
"MediaPath","HD","CDROM","VenMedia","Media","Fv","FvFile","Offset","RamDisk","VirtualDisk","VirtualCD",
|
||||
"PersistentVirtualDisk","PersistentVirtualCD","BbsPath","BBS","Sata" ]
|
||||
if '\\' in Value:
|
||||
Value.replace('\\', '/').replace(' ', '')
|
||||
for Item in Value.split('/'):
|
||||
Key = Item.strip().split('(')[0]
|
||||
if Key not in DevPathList:
|
||||
pass
|
||||
|
||||
Cmd = 'DevicePath ' + '"' + Value + '"'
|
||||
try:
|
||||
p = subprocess.Popen(Cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
out, err = p.communicate()
|
||||
except Exception, X:
|
||||
raise BadExpression("DevicePath: %s" % (str(X)) )
|
||||
finally:
|
||||
subprocess._cleanup()
|
||||
p.stdout.close()
|
||||
p.stderr.close()
|
||||
if err:
|
||||
raise BadExpression("DevicePath: %s" % str(err))
|
||||
Size = len(out.split())
|
||||
out = ','.join(out.split())
|
||||
return '{' + out + '}', Size
|
||||
|
||||
def ParseFieldValue (Value):
|
||||
if type(Value) == type(0):
|
||||
|
|
Loading…
Reference in New Issue