From 947a5a9ae84cba2e20536ead860c5de6e73ebc6a Mon Sep 17 00:00:00 2001 From: ydong10 Date: Tue, 22 Jan 2013 09:51:19 +0000 Subject: [PATCH] Refine the sample about how to convert the device path to string. Signed-off-by: Eric Dong Reviewed-by: Liming Gao git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14077 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/DriverSampleDxe/DriverSample.c | 51 ++++--------------- .../Universal/DriverSampleDxe/DriverSample.h | 3 +- .../DriverSampleDxe/DriverSampleDxe.inf | 3 +- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 854a5a7291..7c47b5fd39 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -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.
+Copyright (c) 2004 - 2013, Intel Corporation. All rights reserved.
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; diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h index 07ace64852..cd546bf388 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
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 #include #include +#include #include #include diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf index bcc157442e..36511e66d0 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf @@ -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.
+# Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
# # 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