diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-08-18 12:11:37 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2008-08-18 12:11:37 +0000 |
commit | b911d09f5525e5bb27d5c9dffcfd6120e095ac84 (patch) | |
tree | 657ff1575c56b81d968d90f29238313fae127816 /MdePkg/Library/IfrSupportLib | |
parent | d1a44d08c1b221669e88f27801b3e4ae26d7fd96 (diff) | |
download | edk2-platforms-b911d09f5525e5bb27d5c9dffcfd6120e095ac84.tar.xz |
Code Clean up for IfrSupportLib, HiiLib, PeiExtractGuidedSectionLib and DxeExtractGuidedSectionLib,
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5687 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/IfrSupportLib')
-rw-r--r-- | MdePkg/Library/IfrSupportLib/IfrSupportLib.inf | 14 | ||||
-rw-r--r-- | MdePkg/Library/IfrSupportLib/UefiIfrCommon.c | 51 | ||||
-rw-r--r-- | MdePkg/Library/IfrSupportLib/UefiIfrForm.c | 118 | ||||
-rw-r--r-- | MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h | 7 |
4 files changed, 90 insertions, 100 deletions
diff --git a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf b/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf index 32e1027ae3..6c1b86f12b 100644 --- a/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf +++ b/MdePkg/Library/IfrSupportLib/IfrSupportLib.inf @@ -2,7 +2,7 @@ #Utility functions which helps in opcode creation, HII configuration string manipulations,
#pop up window creations, setup browser persistence data set and get.
#
-# Copyright (c) 2007, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.
#
# All rights reserved. This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -21,7 +21,7 @@ FILE_GUID = bf38668e-e231-4baa-99e4-8c0e4c35dca6
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
- LIBRARY_CLASS = IfrSupportLib
+ LIBRARY_CLASS = IfrSupportLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
@@ -46,20 +46,10 @@ DevicePathLib
BaseLib
UefiBootServicesTableLib
- UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
- PcdLib
-
-[Guids]
- gEfiGlobalVariableGuid # ALWAYS_CONSUMED
[Protocols]
gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_CONSUMED
- gEfiHiiDatabaseProtocolGuid
- gEfiHiiStringProtocolGuid
gEfiHiiConfigRoutingProtocolGuid
gEfiFormBrowser2ProtocolGuid
-
-[Pcd]
- gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultPlatformLang
diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrCommon.c b/MdePkg/Library/IfrSupportLib/UefiIfrCommon.c deleted file mode 100644 index 18c594f45d..0000000000 --- a/MdePkg/Library/IfrSupportLib/UefiIfrCommon.c +++ /dev/null @@ -1,51 +0,0 @@ -/** @file -Utility functions which helps in opcode creation, HII configuration string manipulations, -pop up window creations, setup browser persistence data set and get. - -Copyright (c) 2007 - 2008, 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 -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 "UefiIfrLibraryInternal.h" - -EFI_HII_DATABASE_PROTOCOL *gIfrLibHiiDatabase; -EFI_HII_STRING_PROTOCOL *gIfrLibHiiString; - - -/** - IfrSupportLib's constructor. It locates the required protocol: - gEfiHiiDatabaseProtocolGuid and gEfiHiiStringProtocolGuid. - - @param ImageHandle The firmware allocated handle for the EFI image. - - @param SystemTable A pointer to the EFI System Table. - - @retval EFI_SUCCESS This function always completes successfully. - -**/ -EFI_STATUS -EFIAPI -IfrSupportLibConstructor ( - IN EFI_HANDLE ImageHandle, - IN EFI_SYSTEM_TABLE *SystemTable - ) -{ - EFI_STATUS Status; - - Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &gIfrLibHiiDatabase); - ASSERT_EFI_ERROR (Status); - - Status = gBS->LocateProtocol (&gEfiHiiStringProtocolGuid, NULL, (VOID **) &gIfrLibHiiString); - ASSERT_EFI_ERROR (Status); - - return EFI_SUCCESS; -} - - diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c b/MdePkg/Library/IfrSupportLib/UefiIfrForm.c index 504b88d468..3ae15f4161 100644 --- a/MdePkg/Library/IfrSupportLib/UefiIfrForm.c +++ b/MdePkg/Library/IfrSupportLib/UefiIfrForm.c @@ -15,6 +15,40 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "UefiIfrLibraryInternal.h" +STATIC CONST EFI_FORM_BROWSER2_PROTOCOL *mFormBrowser2 = NULL; +STATIC CONST EFI_HII_CONFIG_ROUTING_PROTOCOL *mHiiConfigRouting = NULL; + +/**
+ This function locate FormBrowser2 protocols for later usage.
+ + @return Status the status to locate protocol.
+**/
+EFI_STATUS
+LocateFormBrowser2Protocols (
+ VOID
+ )
+{ + EFI_STATUS Status; + // + // Locate protocols for later usage + // + if (mFormBrowser2 == NULL) { + Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &mFormBrowser2); + if (EFI_ERROR (Status)) { + return Status; + } + } + + if (mHiiConfigRouting == NULL) { + Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &mHiiConfigRouting); + if (EFI_ERROR (Status)) { + return Status; + } + } + + return EFI_SUCCESS; +} + // // Fake <ConfigHdr> // @@ -32,6 +66,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT16 mFakeConfigHdr[] = L"GUID=00000000000 @retval EFI_SUCCESS Displayed dialog and received user interaction @retval EFI_INVALID_PARAMETER One of the parameters was invalid. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. **/ EFI_STATUS @@ -86,13 +121,19 @@ IfrLibCreatePopUp2 ( CurrentAttribute = ConOut->Mode->Attribute; LineBuffer = AllocateZeroPool (DimensionsWidth * sizeof (CHAR16)); - ASSERT (LineBuffer != NULL); + if (LineBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } // // Determine the largest string in the dialog box // Notice we are starting with 1 since String is the first string // StringArray = AllocateZeroPool (NumberOfLines * sizeof (CHAR16 *)); + if (StringArray == NULL) { + FreePool (LineBuffer); + return EFI_OUT_OF_RESOURCES; + } LargestString = StrLen (String); StringArray[0] = String; @@ -100,6 +141,8 @@ IfrLibCreatePopUp2 ( StackString = VA_ARG (Marker, CHAR16 *); if (StackString == NULL) { + FreePool (LineBuffer); + FreePool (StringArray); return EFI_INVALID_PARAMETER; } @@ -211,7 +254,11 @@ IfrLibCreatePopUp2 ( ConOut->SetAttribute (ConOut, CurrentAttribute); ConOut->EnableCursor (ConOut, TRUE); - return Status;} + FreePool (LineBuffer); + FreePool (StringArray); + + return Status; +} /** @@ -307,6 +354,7 @@ ToLower ( @param BufferSize Size of the buffer in bytes. @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. **/ EFI_STATUS @@ -322,6 +370,9 @@ BufferToHexString ( UINTN StrBufferLen; NewBuffer = AllocateCopyPool (BufferSize, Buffer); + if (NewBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } SwapBuffer (NewBuffer, BufferSize); StrBufferLen = BufferSize * sizeof (CHAR16) + 1; @@ -670,6 +721,7 @@ FindBlockName ( @retval EFI_SUCCESS Routine success. @retval EFI_BUFFER_TOO_SMALL The intput buffer is too small. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. **/ EFI_STATUS @@ -688,18 +740,11 @@ GetBrowserData ( UINTN HeaderLen; UINTN BufferLen; CHAR16 *Progress; - EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; // // Locate protocols for use // - Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting); + Status = LocateFormBrowser2Protocols (); if (EFI_ERROR (Status)) { return Status; } @@ -709,16 +754,22 @@ GetBrowserData ( // ConfigHdr = mFakeConfigHdr; HeaderLen = StrLen (ConfigHdr); - + + // + // First try allocate 0x4000 buffer for the formet storage data. + // BufferLen = 0x4000; ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); + if (ConfigResp == NULL) { + BufferLen = 0; + } StringPtr = ConfigResp + HeaderLen; *StringPtr = L'&'; StringPtr++; - Status = FormBrowser2->BrowserCallback ( - FormBrowser2, + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, &BufferLen, StringPtr, TRUE, @@ -726,15 +777,21 @@ GetBrowserData ( VariableName ); if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (ConfigResp); + if (ConfigResp != NULL) { + FreePool (ConfigResp); + } + ConfigResp = AllocateZeroPool (BufferLen + HeaderLen); + if (ConfigResp == NULL) { + return EFI_OUT_OF_RESOURCES; + } StringPtr = ConfigResp + HeaderLen; *StringPtr = L'&'; StringPtr++; - Status = FormBrowser2->BrowserCallback ( - FormBrowser2, + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, &BufferLen, StringPtr, TRUE, @@ -751,8 +808,8 @@ GetBrowserData ( // // Convert <ConfigResp> to buffer data // - Status = HiiConfigRouting->ConfigToBlock ( - HiiConfigRouting, + Status = mHiiConfigRouting->ConfigToBlock ( + mHiiConfigRouting, ConfigResp, Buffer, BufferSize, @@ -780,6 +837,7 @@ GetBrowserData ( &OFFSET=<Number>&WIDTH=<Number>* @retval EFI_SUCCESS Routine success. + @retval EFI_OUT_OF_RESOURCES There is no enough available memory space. @retval Other Updating Browser uncommitted data failed. **/ @@ -800,8 +858,6 @@ SetBrowserData ( UINTN HeaderLen; UINTN BufferLen; CHAR16 *Progress; - EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; - EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; CHAR16 BlockName[33]; CHAR16 *ConfigRequest; CHAR16 *Request; @@ -809,12 +865,7 @@ SetBrowserData ( // // Locate protocols for use // - Status = gBS->LocateProtocol (&gEfiFormBrowser2ProtocolGuid, NULL, (VOID **) &FormBrowser2); - if (EFI_ERROR (Status)) { - return Status; - } - - Status = gBS->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid, NULL, (VOID **) &HiiConfigRouting); + Status = LocateFormBrowser2Protocols (); if (EFI_ERROR (Status)) { return Status; } @@ -846,6 +897,9 @@ SetBrowserData ( BufferLen = HeaderLen * sizeof (CHAR16) + StrSize (Request); ConfigRequest = AllocateZeroPool (BufferLen); + if (ConfigRequest == NULL) { + return EFI_OUT_OF_RESOURCES; + } CopyMem (ConfigRequest, ConfigHdr, HeaderLen * sizeof (CHAR16)); StringPtr = ConfigRequest + HeaderLen; @@ -854,8 +908,8 @@ SetBrowserData ( // // Convert buffer to <ConfigResp> // - Status = HiiConfigRouting->BlockToConfig ( - HiiConfigRouting, + Status = mHiiConfigRouting->BlockToConfig ( + mHiiConfigRouting, ConfigRequest, Buffer, BufferSize, @@ -863,7 +917,7 @@ SetBrowserData ( &Progress ); if (EFI_ERROR (Status)) { - FreePool (ConfigResp); + FreePool (ConfigRequest); return Status; } @@ -875,14 +929,14 @@ SetBrowserData ( // // Change uncommitted data in Browser // - Status = FormBrowser2->BrowserCallback ( - FormBrowser2, + Status = mFormBrowser2->BrowserCallback ( + mFormBrowser2, &BufferSize, StringPtr, FALSE, NULL, NULL ); - FreePool (ConfigResp); + FreePool (ConfigRequest); return Status; } diff --git a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h b/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h index 34a0cf1260..1cdb36c78d 100644 --- a/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h +++ b/MdePkg/Library/IfrSupportLib/UefiIfrLibraryInternal.h @@ -2,7 +2,7 @@ Utility functions which helps in opcode creation, HII configuration string manipulations, pop up window creations, setup browser persistence data set and get. -Copyright (c) 2007, Intel Corporation +Copyright (c) 2007 - 2008, 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 @@ -20,19 +20,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include <PiDxe.h> -#include <Guid/GlobalVariable.h> #include <Protocol/DevicePath.h> #include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> -#include <Library/UefiRuntimeServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Library/BaseLib.h> #include <Library/DevicePathLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/IfrSupportLib.h> -#include <Library/HiiLib.h> -#include <Library/PcdLib.h> + #endif |