/*The source code is from EFI Dev Kit(EDk).*/
/*It will make a string. and its layout as below:*/
Word(2bytes)
|
Length
|
Description
|
0
|
5 Words(10 Bytes)
|
“GUID=”
|
5
|
16 Words(32 Bytes)
|
EFI_GUID
|
21
|
6 Words(12 Bytes)
|
“&NAME=”
|
27
|
00 + “??”=2Words x L1(L1 x 4 = 4L1 Bytes)
|
00??, 00??, 00??.....
|
27 + 2L1
|
6 Words(12 Bytes)
|
“&PATH=”
|
33 + 2L1
|
Word(2 bytes) x L2 = 2L2bytes
|
Device Path Size
|
(33 + 2L1 + L2)Last Word
|
1 Words(2 Bytes)
|
00
|
CHAR16 *
ConstructConfigHdr (
IN EFI_GUID *Guid,
IN CHAR16 *Name,
IN EFI_HANDLE DriverHandle
)
/*++
Routine Description:
Construct
Arguments:
Guid - Routing information: GUID.
Name - Routing information: NAME.
DriverHandle - Driver handle which contains the routing information: PATH.
Returns:
NULL - Fails.
Other - Pointer to configHdr string.
--*/
{
EFI_STATUS Status;
CHAR16 *ConfigHdr;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
CHAR16 *String;
CHAR16 *UpperString;
UINTN Index;
UINT8 *Buffer;
UINTN DevicePathLength;
UINTN NameLength;
//
// Get the device path from handle installed EFI HII Config Access protocol
//
Status = BS->HandleProtocol (
DriverHandle,
&gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath
);
if (EFI_ERROR (Status)) {
return NULL;
}
DevicePathLength = DevicePathSize (DevicePath);
NameLength = StrLen (Name);
ConfigHdr = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathLength * 2 + 1) * sizeof (CHAR16));
if (ConfigHdr == NULL) {
return NULL;
}
String = ConfigHdr;
StrCpy (String, L"GUID=");
String += StrLen (L"GUID=");
//
// Append Guid converted to
//
UpperString = String;
for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) {
String += SPrint (String, 0, L"%02x", *Buffer++);
}
*String = 0;
StrLwr (UpperString);
//
// Append L"&NAME="
//
StrCpy (String, L"&NAME=");
String += StrLen (L"&NAME=");
UpperString = String;
for (Index = 0; Index < NameLength ; Index++) {
String += SPrint (String, 0, L"00%x", Name[Index]);
}
*String = 0;
StrLwr (UpperString);
//
// Append L"&PATH="
//
StrCpy (String, L"&PATH=");
String += StrLen (L"&PATH=");
UpperString = String;
for (Index = 0, Buffer = (UINT8 *) DevicePath; Index < DevicePathLength; Index++) {
String += SPrint (String, 0, L"%02x", *Buffer++);
}
*String = 0;
StrLwr (UpperString);
return ConfigHdr;
}
沒有留言:
張貼留言