Refine the sample about how to convert the device path to string.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>



git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14077 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10 2013-01-22 09:51:19 +00:00
parent 80a047f04a
commit 947a5a9ae8
3 changed files with 15 additions and 42 deletions

View File

@ -2,7 +2,7 @@
This is an example of how a driver might export data to the HII protocol to be
later utilized by the Setup Protocol
Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2004 - 2013, 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
@ -1766,44 +1766,6 @@ DriverCallback (
return Status;
}
/**
Transfer the binary device path to string.
@param DevicePath The device path info.
@retval Device path string info.
**/
CHAR16 *
GenerateDevicePathString (
EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
CHAR16 *String;
CHAR16 *TmpBuf;
UINTN Index;
UINT8 *Buffer;
UINTN DevicePathSize;
//
// Compute the size of the device path in bytes
//
DevicePathSize = GetDevicePathSize (DevicePath);
String = AllocateZeroPool ((DevicePathSize * 2 + 1) * sizeof (CHAR16));
if (String == NULL) {
return NULL;
}
TmpBuf = String;
for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) {
TmpBuf += UnicodeValueToString (TmpBuf, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2);
}
return String;
}
/**
Main entry for this driver.
@ -1835,12 +1797,14 @@ DriverSampleInit (
MY_EFI_VARSTORE_DATA *VarStoreConfig;
EFI_INPUT_KEY HotKey;
EFI_FORM_BROWSER_EXTENSION_PROTOCOL *FormBrowserEx;
EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *pToText;
//
// Initialize the local variables.
//
ConfigRequestHdr = NULL;
NewString = NULL;
pToText = NULL;
//
// Initialize screen dimensions for SendForm().
@ -1957,11 +1921,18 @@ DriverSampleInit (
}
PrivateData->HiiHandle[1] = HiiHandle[1];
Status = gBS->LocateProtocol (
&gEfiDevicePathToTextProtocolGuid,
NULL,
(VOID **) &pToText
);
ASSERT_EFI_ERROR (Status);
//
// Update the device path string.
//
NewString = GenerateDevicePathString((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0);
NewString = pToText->ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)&mHiiVendorDevicePath0, FALSE, FALSE);
if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_DEVICE_PATH), NewString, NULL) == 0) {
DriverSampleUnload (ImageHandle);
return EFI_OUT_OF_RESOURCES;

View File

@ -1,6 +1,6 @@
/** @file
Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2007 - 2013, 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,6 +32,7 @@ Revision History
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiString.h>
#include <Protocol/FormBrowserEx.h>
#include <Protocol/DevicePathToText.h>
#include <Guid/MdeModuleHii.h>
#include <Library/DebugLib.h>

View File

@ -2,7 +2,7 @@
# This is a sample driver which show how HII protocol, VFR and UNI files are used to
# create a driver which can be dipslayed and configured by a UEFI HII Form Browser.
#
# Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2007 - 2013, 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
@ -70,6 +70,7 @@
gEfiHiiDatabaseProtocolGuid ## CONSUMES
gEfiSimpleTextInputExProtocolGuid ## CONSUMES
gEfiFormBrowserExProtocolGuid ## CONSUMES
gEfiDevicePathToTextProtocolGuid ## CONSUMES
[Depex]
gEfiSimpleTextOutProtocolGuid AND gEfiHiiDatabaseProtocolGuid AND gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid