From cb7d01c0c9fd199742d0fed6aa69dab0c79c3338 Mon Sep 17 00:00:00 2001 From: rsun3 Date: Tue, 14 Apr 2009 10:47:19 +0000 Subject: HII Library Class interface refine. The "HiiLib" prefix for all HII Library API function names changed to "Hii". Remove: HiiLibPreparePackageList(), replaced by HiiAddPackages() HiiLibNewString(), replaced by HiiSetString() HiiLibGetStringFromHandle(), replaced by HiiGetString() HiiLibGetStringFromToken(), replaced by HiiGetPackageString() HiiLibExtractGuidFromHiiHandle() HiiLibDevicePathToHiiHandle() HiiLibGetSupportedSecondaryLanguages() HiiLibGetSupportedLanguageNumber() HiiLibExportPackageLists() HiiLibListPackageLists() Interface change: HiiAddPackages() HiiSetString() HiiGetString() HiiGetHiiHandles() git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8083 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Application/PlatOverMngr/PlatOverMngr.c | 105 +-- MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c | 16 +- MdeModulePkg/Include/Library/HiiLib.h | 496 +++++--------- MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c | 178 ++--- MdeModulePkg/Library/UefiHiiLib/HiiLib.c | 735 ++++++--------------- MdeModulePkg/Library/UefiHiiLib/HiiString.c | 535 +++++++-------- MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h | 24 +- .../Console/GraphicsConsoleDxe/GraphicsConsole.c | 14 +- .../Universal/DriverSampleDxe/DriverSample.c | 89 ++- .../Universal/DriverSampleDxe/DriverSample.h | 5 +- .../Universal/DriverSampleDxe/DriverSampleDxe.inf | 1 + .../Universal/Network/IScsiDxe/IScsiConfig.c | 28 +- MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c | 8 +- MdeModulePkg/Universal/SetupBrowserDxe/Setup.c | 50 +- MdeModulePkg/Universal/SetupBrowserDxe/Setup.h | 1 + .../Universal/SetupBrowserDxe/SetupBrowserDxe.inf | 3 +- MdeModulePkg/Universal/SetupBrowserDxe/Ui.c | 98 ++- 17 files changed, 928 insertions(+), 1458 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c b/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c index 64a26c6..018917f 100644 --- a/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c +++ b/MdeModulePkg/Application/PlatOverMngr/PlatOverMngr.c @@ -409,17 +409,19 @@ UpdateDeviceSelectPage ( // then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement // NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH); - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), &NewString); + NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH), NULL); ASSERT (NewString != NULL); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) { + ASSERT (FALSE); + } FreePool (NewString); NewStringToken = STRING_TOKEN (STR_FIRST_REFRESH_HELP); - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), &NewString); + NewString = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_REFRESH_HELP), NULL); ASSERT (NewString != NULL); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, NewString, NULL) == 0) { + ASSERT (FALSE); + } FreePool (NewString); // @@ -504,13 +506,8 @@ UpdateDeviceSelectPage ( } StrCat (NewString, ControllerName); - NewStringToken = mControllerToken[Index]; - if (NewStringToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - } - ASSERT_EFI_ERROR (Status); + NewStringToken = HiiSetString (Private->RegisteredHandle, mControllerToken[Index], NewString, NULL); + ASSERT (NewStringToken != 0); FreePool (NewString); // // Save the device path string toke for next access use @@ -799,7 +796,7 @@ UpdateBindingDriverSelectPage ( // // give a default name // - HiiLibGetStringFromHandle (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), &DriverName); + DriverName = HiiGetString (Private->RegisteredHandle, STRING_TOKEN (STR_DRIVER_DEFAULT_NAME), NULL); ASSERT (DriverName != NULL); FreeDriverName = TRUE; // the DriverName string need to free pool } @@ -821,14 +818,9 @@ UpdateBindingDriverSelectPage ( mLastSavedDriverImageNum++; } StrCat (NewString, DriverName); - NewStringToken = mDriverImageToken[Index]; - if (NewStringToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, NewString); - } + NewStringToken = HiiSetString (Private->RegisteredHandle, mDriverImageToken[Index], NewString, NULL); + ASSERT (NewStringToken != 0); mDriverImageToken[Index] = NewStringToken; - ASSERT_EFI_ERROR (Status); FreePool (NewString); if (FreeDriverName) { FreePool (DriverName); @@ -842,14 +834,9 @@ UpdateBindingDriverSelectPage ( NewString = AllocateZeroPool (StrSize (DriverName)); ASSERT (NewString != NULL); StrCat (NewString, DriverName); - NewStringHelpToken = mDriverImageFilePathToken[Index]; - if (NewStringHelpToken == 0) { - Status = HiiLibNewString (Private->RegisteredHandle, &NewStringHelpToken, NewString); - } else { - Status = HiiLibSetString (Private->RegisteredHandle, NewStringHelpToken, NewString); - } + NewStringHelpToken = HiiSetString (Private->RegisteredHandle, mDriverImageFilePathToken[Index], NewString, NULL); + ASSERT (NewStringHelpToken != 0); mDriverImageFilePathToken[Index] = NewStringHelpToken; - ASSERT_EFI_ERROR (Status); FreePool (NewString); FreePool (DriverName); @@ -1304,8 +1291,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"First, Select the controller by device path", NULL) == 0) { + ASSERT (FALSE); + } } if (((KeyValue >= KEY_VALUE_DEVICE_OFFSET) && (KeyValue < KEY_VALUE_DEVICE_MAX)) || (KeyValue == KEY_VALUE_ORDER_GOTO_PREVIOUS)) { @@ -1317,8 +1305,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Second, Select drivers for the previous selected controller", NULL) == 0) { + ASSERT (FALSE); + } } if (KeyValue == KEY_VALUE_DRIVER_GOTO_ORDER) { @@ -1327,8 +1316,9 @@ PlatOverMngrCallback ( // Update page title string // NewStringToken = STRING_TOKEN (STR_TITLE); - Status = HiiLibSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them"); - ASSERT_EFI_ERROR (Status); + if (HiiSetString (Private->RegisteredHandle, NewStringToken, L"Finally, Set the priority order for the drivers and save them", NULL) == 0) { + ASSERT (FALSE); + } } if (KeyValue == KEY_VALUE_ORDER_SAVE_AND_EXIT) { @@ -1383,23 +1373,9 @@ PlatOverMngrInit ( ) { EFI_STATUS Status; - EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; // - // There should only be one HII protocol - // - Status = gBS->LocateProtocol ( - &gEfiHiiDatabaseProtocolGuid, - NULL, - (VOID **) &HiiDatabase - ); - if (EFI_ERROR (Status)) { - return Status; - } - - // // There should only be one Form Configuration protocol // Status = gBS->LocateProtocol ( @@ -1439,23 +1415,15 @@ PlatOverMngrInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList ( - 2, - &mPlatformOverridesManagerGuid, - VfrBin, - PlatOverMngrStrings - ); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - mCallbackInfo->DriverHandle, - &mCallbackInfo->RegisteredHandle - ); - FreePool (PackageList); - - if (EFI_ERROR (Status)) { + mCallbackInfo->RegisteredHandle = HiiAddPackages ( + &mPlatformOverridesManagerGuid, + mCallbackInfo->DriverHandle, + VfrBin, + PlatOverMngrStrings, + NULL + ); + if (mCallbackInfo->RegisteredHandle == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Finish; } @@ -1494,11 +1462,8 @@ PlatOverMngrInit ( NULL ); - HiiDatabase->RemovePackageList (HiiDatabase, mCallbackInfo->RegisteredHandle); - - if (EFI_ERROR (Status)) { - goto Finish; - } + HiiRemovePackages (mCallbackInfo->RegisteredHandle); + Status = EFI_SUCCESS; Finish: if (mCallbackInfo->DriverHandle != NULL) { diff --git a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c index 7a8ee00..32ea3cf 100644 --- a/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c +++ b/MdeModulePkg/Bus/Usb/UsbKbDxe/KeyBoard.c @@ -318,7 +318,6 @@ InstallDefaultKeyboardLayout ( EFI_STATUS Status; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; EFI_HII_HANDLE HiiHandle; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Locate Hii database protocol @@ -335,13 +334,14 @@ InstallDefaultKeyboardLayout ( // // Install Keyboard Layout package to HII database // - PackageList = HiiLibPreparePackageList (1, &mUsbKeyboardLayoutPackageGuid, &mUsbKeyboardLayoutBin); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList (HiiDatabase, PackageList, UsbKeyboardDevice->ControllerHandle, &HiiHandle); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; + HiiHandle = HiiAddPackages ( + &mUsbKeyboardLayoutPackageGuid, + UsbKeyboardDevice->ControllerHandle, + &mUsbKeyboardLayoutBin, + NULL + ); + if (HiiHandle == NULL) { + return EFI_OUT_OF_RESOURCES; } // diff --git a/MdeModulePkg/Include/Library/HiiLib.h b/MdeModulePkg/Include/Library/HiiLib.h index 37b59bf..730f450 100644 --- a/MdeModulePkg/Include/Library/HiiLib.h +++ b/MdeModulePkg/Include/Library/HiiLib.h @@ -17,281 +17,207 @@ /** - Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. - - If GuidId is NULL, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param NumberOfPackages Number of packages. - @param GuidId Package GUID. - @param ... Variable argument list for packages to be assembled. - - @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -EFIAPI -HiiLibPreparePackageList ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - ... - ) -; - -/** - This function allocates pool for an EFI_HII_PACKAGE_LIST structure - with additional space that is big enough to host all packages described by the variable - argument list of package pointers. The allocated structure is initialized using NumberOfPackages, - GuidId, and the variable length argument list of package pointers. - - Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The - Handle to the newly registered Package List is returned throught HiiHandle. + Registers a list of packages in the HII Database and returns the HII Handle + associated with that registration. If an HII Handle has already been registered + with the same PackageListGuid, then NULL is returned. If there are not enough + resources to perform the registration, then NULL is returned. If an empty list + of packages is passed in, then NULL is returned. If the size of the list of + package is 0, then NULL is returned. - If HiiHandle is NULL, then ASSERT. + The variable arguments are pointers which point to package header that defined + by UEFI VFR compiler and StringGather tool. - @param NumberOfPackages The number of HII packages to register. - @param GuidId Package List GUID ID. - @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. - This DriverHandle uniquely defines the device that the added packages are associated with. - @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package - List later. If the functions failed to add the package to the default HII database, this value will - be set to NULL. - @param ... The variable argument list describing all HII Package. + #pragma pack (push, 1) + typedef struct { + UINT32 BinaryLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + } EDKII_AUTOGEN_PACKAGES_HEADER; + #pragma pack (pop) + + @param[in] PackageListGuid The GUID of the package list. + @param[in] DeviceHandle If not NULL, the Device Handle on which + an instance of DEVICE_PATH_PROTOCOL is installed. + This Device Handle uniquely defines the device that + the added packages are associated with. + @param[in] ... The variable argument list that contains pointers + to packages terminated by a NULL. - @return EFI_SUCCESS If the packages are successfully added to the default HII database. - @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. + @retval NULL A HII Handle has already been registered in the HII Database with + the same PackageListGuid. + @retval NULL The HII Handle could not be created. + @retval NULL An empty list of packages was passed in. + @retval NULL All packages are empty. + @retval Other The HII Handle associated with the newly registered package list. **/ -EFI_STATUS +EFI_HII_HANDLE EFIAPI -HiiLibAddPackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN EFI_HANDLE DriverHandle, OPTIONAL - OUT EFI_HII_HANDLE *HiiHandle, +HiiAddPackages ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_HANDLE DeviceHandle OPTIONAL, ... ) ; /** - Removes a package list from the default HII database. + Removes a package list from the HII database. If HiiHandle is NULL, then ASSERT. - If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. + If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT. - @param HiiHandle The handle that was previously registered to the data base that is requested for removal. - List later. + @param[in] HiiHandle The handle that was previously registered in the HII database **/ VOID EFIAPI -HiiLibRemovePackages ( +HiiRemovePackages ( IN EFI_HII_HANDLE HiiHandle ) ; /** - This function adds the string into String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If StringId is NULL, the ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId On return, contains the new strings id, which is - unique within PackageList. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibNewString ( - IN EFI_HII_HANDLE PackageList, - OUT EFI_STRING_ID *StringId, - IN CONST EFI_STRING String - ) -; - -/** - This function update the specified string in String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId Ths String Id to be updated. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibSetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST EFI_STRING String - ) -; - -/** - This function try to retrieve string from String package of current language. - If fails, it try to retrieve string from String package of first language it support. - - If StringSize is NULL, then ASSERT. - If String is NULL and *StringSize is not 0, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList The package list in the HII database to search for - the specified string. - @param StringId The string's id, which is unique within - PackageList. - @param String Points to the new null-terminated string. - @param StringSize On entry, points to the size of the buffer pointed - to by String, in bytes. On return, points to the - length of the string, in bytes. - - @retval EFI_SUCCESS The string was returned successfully. - @retval EFI_NOT_FOUND The string specified by StringId is not available. - @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small - to hold the string. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - OUT EFI_STRING String, - IN OUT UINTN *StringSize - ) -; - -/** - Get string specified by StringId form the HiiHandle. The caller - is responsible to free the *String. - - If String is NULL, then ASSERT. - If HiiHandle could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param HiiHandle The HII handle of package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_NOT_FOUND String is not found. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. - -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromHandle ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -; - -/** - Get the string given the StringId and String package Producer's Guid. The caller - is responsible to free the *String. - - If PackageList with the matching ProducerGuid is not found, then ASSERT. - If PackageList with the matching ProducerGuid is found but no String is - specified by StringId is found, then ASSERT. + This function create a new string in String Package or updates an existing + string in a String Package. If StringId is 0, then a new string is added to + a String Package. If StringId is not zero, then a string in String Package is + updated. If SupportedLanguages is NULL, then the string is added or updated + for all the languages that the String Package supports. If SupportedLanguages + is not NULL, then the string is added or updated for the set of languages + specified by SupportedLanguages. + + If HiiHandle is NULL, then ASSERT(). + If String is NULL, then ASSERT(). - @param ProducerGuid The Guid of String package list. - @param StringId The String ID. - @param String The output string. + @param[in] HiiHandle A handle that was previously registered in the + HII Database. + @param[in] StringId If zero, then a new string is created in the + String Package associated with HiiHandle. If + non-zero, then the string specified by StringId + is updated in the String Package associated + with HiiHandle. + @param[in] String A pointer to the Null-terminated Unicode string + to add or update in the String Package associated + with HiiHandle. + @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of + language codes. If this parameter is NULL, then + String is added or updated in the String Package + associated with HiiHandle for all the languages + that the String Package supports. If this + parameter is not NULL, then then String is added + or updated in the String Package associated with + HiiHandle for the set oflanguages specified by + SupportedLanguages. The format of + SupportedLanguages must follow the language + format assumed the HII Database. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + @retval 0 The string could not be added or updated in the String Package. + @retval Other The EFI_STRING_ID of the newly added or updated string. **/ -EFI_STATUS +EFI_STRING_ID EFIAPI -HiiLibGetStringFromToken ( - IN EFI_GUID *ProducerGuid, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String +HiiSetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, OPTIONAL + IN CONST EFI_STRING String, + IN CONST CHAR8 *SupportedLanguages OPTIONAL ) ; /** - Determines the handles that are currently active in the database. - It's the caller's responsibility to free handle buffer. - - If HandleBufferLength is NULL, then ASSERT. - If HiiHandleBuffer is NULL, then ASSERT. + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. - @param HandleBufferLength On input, a pointer to the length of the handle - buffer. On output, the length of the handle buffer - that is required for the handles found. - @param HiiHandleBuffer Pointer to an array of Hii Handles returned. + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. - @retval EFI_SUCCESS Get an array of Hii Handles successfully. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetHiiHandles ( - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HiiHandleBuffer +HiiGetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) ; /** - Extract Hii package list GUID for given HII handle. - - If HiiHandle could not be found in the default HII database, then ASSERT. - If Guid is NULL, then ASSERT. + Retrieves a string from a string package names by GUID in a specific language. + If the language is not specified, then a string from a string package in the + current platform language is retrieved. If the string can not be retrieved + using the specified language or the current platform language, then the string + is retrieved from the string package in the first language the string package + supports. The returned string is allocated using AllocatePool(). The caller + is responsible for freeing the allocated buffer using FreePool(). + + If PackageListGuid is NULL, then ASSERT(). + If StringId is 0, then ASSERT. - @param Handle Hii handle - @param Guid Package list GUID + @param[in] PackageListGuid The GUID of a package list that was previously + registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the + string package associated with PackageListGuid. + @param[in] Language The language of the string to retrieve. If this + parameter is NULL, then the current platform + language is used. The format of Language must + follow the language format assumed the HII Database. - @retval EFI_SUCCESS Successfully extract GUID from Hii database. + @retval NULL The package list specified by PackageListGuid is not present in the + HII Database. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibExtractGuidFromHiiHandle ( - IN EFI_HII_HANDLE Handle, - OUT EFI_GUID *Guid +HiiGetPackageString ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) ; /** - Find HII Handle in the default HII database associated with given Device Path. - - If DevicePath is NULL, then ASSERT. + Retrieves the array of all the HII Handles or the HII handle of a specific + package list in the HII Database. + This array is terminated with a NULL HII Handle. + This function allocates the returned array using AllocatePool(). + The caller is responsible for freeing the array with FreePool(). - @param DevicePath Device Path associated with the HII package list - handle. + @param[in] PackageListGuid An optional parameter that is used to request + an HII Handle that is associatd with a specific + Package List GUID. If this parameter is NULL + then all the HII Handles in the HII Database + are returned. If this parameter is not NULL + then at most 1 HII Handle is returned. - @retval Handle HII package list Handle associated with the Device - Path. - @retval NULL Hii Package list handle is not found. + @retval NULL No HII handles were found in the HII database + @retval NULL The array of HII Handles could not be retrieved + @retval Other A pointer to the NULL terminated array of HII Handles **/ -EFI_HII_HANDLE +EFI_HII_HANDLE * EFIAPI -HiiLibDevicePathToHiiHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath +HiiGetHiiHandles ( + IN CONST EFI_GUID *PackageListGuid OPTIONAL ) ; - /** Get next language from language code list (with separator ';'). @@ -313,139 +239,31 @@ HiiLibGetNextLanguage ( ; /** - This function returns the list of supported languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - - @param HiiHandle The HII package list handle. - - @retval !NULL The supported languages. - @retval NULL If Supported Languages can not be retrived. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedLanguages ( - IN EFI_HII_HANDLE HiiHandle - ) -; - -/** - This function returns the list of supported 2nd languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - @param FirstLanguage Pointer to language name buffer. + Retrieves a pointer to the a Null-terminated ASCII string containing the list + of languages that an HII handle in the HII Database supports. The returned + string is allocated using AllocatePool(). The caller is responsible for freeing + the returned string using FreePool(). The format of the returned string follows + the language format assumed the HII Database. - @return The supported languages. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedSecondaryLanguages ( - IN EFI_HII_HANDLE HiiHandle, - IN CONST CHAR8 *FirstLanguage - ) -; - - -/** - This function returns the number of supported languages on HiiHandle. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. + If HiiHandle is NULL, then ASSERT(). - @param HiiHandle The HII package list handle. + @param[in] HiiHandle A handle that was previously registered in the HII Database. - @return The number of supported languages. + @retval NULL HiiHandle is not registered in the HII database + @retval NULL There are not enough resources available to retrieve the suported + languages. + @retval NULL The list of suported languages could not be retrieved. + @retval Other A pointer to the Null-terminated ASCII string of supported languages. **/ -UINT16 +CHAR8 * EFIAPI -HiiLibGetSupportedLanguageNumber ( +HiiGetSupportedLanguages ( IN EFI_HII_HANDLE HiiHandle ) ; /** - Exports the contents of one or all package lists in the HII database into a buffer. - - If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, - then ASSERT. - If PackageListHeader is NULL, then ASSERT. - If PackageListSize is NULL, then ASSERT. - - @param Handle The HII Handle. - @param PackageListHeader A pointer to a buffer that will contain the results of - the export function. - @param PackageListSize On output, the length of the buffer that is required for the exported data. - - @retval EFI_SUCCESS Package exported. - - @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. - -**/ -EFI_STATUS -EFIAPI -HiiLibExportPackageLists ( - IN EFI_HII_HANDLE Handle, - OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, - OUT UINTN *PackageListSize - ) -; - -/** - - This function returns a list of the package handles of the - specified type that are currently active in the HII database. The - pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package - handles to be listed. - - If HandleBufferLength is NULL, then ASSERT. - If HandleBuffer is NULL, the ASSERT. - If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is - NULL, then ASSERT. - If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not - NULL, then ASSERT. - - - @param PackageType Specifies the package type of the packages - to list or EFI_HII_PACKAGE_TYPE_ALL for - all packages to be listed. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID which must match - the Guid field of - EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it - must be NULL. - - @param HandleBufferLength On output, the length of the handle buffer - that is required for the handles found. - - @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. - The caller is responcible to free this pointer allocated. - - @retval EFI_SUCCESS The matching handles are outputed successfully. - HandleBufferLength is updated with the actual length. - @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. - @retval EFI_NOT_FOUND No matching handle could not be found in database. -**/ -EFI_STATUS -EFIAPI -HiiLibListPackageLists ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **Handle - ) -; - -/** Convert language code from RFC3066 to ISO639-2. LanguageRfc3066 contain a single RFC 3066 code such as diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c index 2117329..45e178c 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLanguage.c @@ -58,155 +58,81 @@ HiiLibGetNextLanguage ( /** - This function returns the list of supported languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. + Retrieves a pointer to the a Null-terminated ASCII string containing the list + of languages that an HII handle in the HII Database supports. The returned + string is allocated using AllocatePool(). The caller is responsible for freeing + the returned string using FreePool(). The format of the returned string follows + the language format assumed the HII Database. + + If HiiHandle is NULL, then ASSERT(). - @param HiiHandle The HII package list handle. + @param[in] HiiHandle A handle that was previously registered in the HII Database. - @retval !NULL The supported languages. - @retval NULL If Supported Languages can not be retrived. + @retval NULL HiiHandle is not registered in the HII database + @retval NULL There are not enough resources available to retrieve the suported + languages. + @retval NULL The list of suported languages could not be retrieved. + @retval Other A pointer to the Null-terminated ASCII string of supported languages. **/ CHAR8 * EFIAPI -HiiLibGetSupportedLanguages ( +HiiGetSupportedLanguages ( IN EFI_HII_HANDLE HiiHandle ) { EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; + UINTN LanguageSize; + CHAR8 TempSupportedLanguages; + CHAR8 *SupportedLanguages; + + ASSERT (HiiHandle != NULL); - ASSERT (IsHiiHandleRegistered (HiiHandle)); // - // Collect current supported Languages for given HII handle - // First try allocate 4K buffer to store the current supported languages. + // Retrieve the size required for the supported languages buffer. // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetLanguages (gHiiString, HiiHandle, LanguageString, &BufferSize); - } - - if (EFI_ERROR (Status)) { - LanguageString = NULL; - } - - return LanguageString; -} - - -/** - This function returns the number of supported languages on HiiHandle. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - - @return The number of supported languages. - -**/ -UINT16 -EFIAPI -HiiLibGetSupportedLanguageNumber ( - IN EFI_HII_HANDLE HiiHandle - ) -{ - CHAR8 *Languages; - CHAR8 *LanguageString; - UINT16 LangNumber; - CHAR8 *Lang; - - Languages = HiiLibGetSupportedLanguages (HiiHandle); - if (Languages == NULL) { - return 0; - } - - LangNumber = 0; - Lang = AllocatePool (AsciiStrSize (Languages)); - if (Lang != NULL) { - LanguageString = Languages; - while (*LanguageString != 0) { - HiiLibGetNextLanguage (&LanguageString, Lang); - LangNumber++; - } + LanguageSize = 0; + Status = gHiiString->GetLanguages (gHiiString, HiiHandle, &TempSupportedLanguages, &LanguageSize); - FreePool (Lang); - } - FreePool (Languages); - - return LangNumber; -} - -/** - This function returns the list of supported 2nd languages, in the format specified - in UEFI specification Appendix M. - - If HiiHandle is not a valid Handle in the default HII database, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param HiiHandle The HII package list handle. - @param FirstLanguage Pointer to language name buffer. - - @return The supported languages. - -**/ -CHAR8 * -EFIAPI -HiiLibGetSupportedSecondaryLanguages ( - IN EFI_HII_HANDLE HiiHandle, - IN CONST CHAR8 *FirstLanguage - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - CHAR8 *LanguageString; - - ASSERT (HiiHandle != NULL); - ASSERT (IsHiiHandleRegistered (HiiHandle)); // - // Collect current supported 2nd Languages for given HII handle - // First try allocate 4K buffer to store the current supported 2nd languages. + // If GetLanguages() returns EFI_SUCCESS for a zero size, + // then there are no supported languages registered for HiiHandle. If GetLanguages() + // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present + // in the HII Database // - BufferSize = 0x1000; - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { + if (Status != EFI_BUFFER_TOO_SMALL) { + // + // Return NULL if the size can not be retrieved, or if HiiHandle is not in the HII Database + // return NULL; } - Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (LanguageString); - LanguageString = AllocateZeroPool (BufferSize); - if (LanguageString == NULL) { - return NULL; - } - - Status = gHiiString->GetSecondaryLanguages (gHiiString, HiiHandle, FirstLanguage, LanguageString, &BufferSize); + // + // Allocate the supported languages buffer. + // + SupportedLanguages = AllocateZeroPool (LanguageSize); + if (SupportedLanguages == NULL) { + // + // Return NULL if allocation fails. + // + return NULL; } + // + // Retrieve the supported languages string + // + Status = gHiiString->GetLanguages (gHiiString, HiiHandle, SupportedLanguages, &LanguageSize); if (EFI_ERROR (Status)) { - LanguageString = NULL; + // + // Free the buffer and return NULL if the supported languages can not be retrieved. + // + FreePool (SupportedLanguages); + return NULL; } - return LanguageString; + // + // Return the Null-terminated ASCII string of supported languages + // + return SupportedLanguages; } - - diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index 384bab4..e337b23 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -19,16 +19,26 @@ // GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR16 mConfigHdrTemplate[] = L"GUID=00000000000000000000000000000000&NAME=0000&PATH=00"; +EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; + // -// Form Browser2 Protocol +// Template used to mark the end of a list of packages // -EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; +GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_HII_PACKAGE_HEADER mEndOfPakageList = { + sizeof (EFI_HII_PACKAGE_HEADER), + EFI_HII_PACKAGE_END +}; /** - This funciton build the package list based on the package number, - the GUID of the package list and the list of pointer which point to - package header that defined by UEFI VFR compiler and StringGather - tool. + Registers a list of packages in the HII Database and returns the HII Handle + associated with that registration. If an HII Handle has already been registered + with the same PackageListGuid, then NULL is returned. If there are not enough + resources to perform the registration, then NULL is returned. If an empty list + of packages is passed in, then NULL is returned. If the size of the list of + package is 0, then NULL is returned. + + The variable arguments are pointers which point to package header that defined + by UEFI VFR compiler and StringGather tool. #pragma pack (push, 1) typedef struct { @@ -36,267 +46,269 @@ EFI_FORM_BROWSER2_PROTOCOL *mUefiFormBrowser2 = NULL; EFI_HII_PACKAGE_HEADER PackageHeader; } EDKII_AUTOGEN_PACKAGES_HEADER; #pragma pack (pop) - - If there is not enough resource for the new package list, - the function will ASSERT. - - @param NumberOfPackages The number of packages be - @param GuidId The GUID for the package list to be generated. - @param Marker The variable argument list. Each entry represent a specific package header that is - generated by VFR compiler and StrGather tool. The first 4 bytes is a UINT32 value - that indicate the overall length of the package. - - @return The pointer to the package list header. + + @param[in] PackageListGuid The GUID of the package list. + @param[in] DeviceHandle If not NULL, the Device Handle on which + an instance of DEVICE_PATH_PROTOCOL is installed. + This Device Handle uniquely defines the device that + the added packages are associated with. + @param[in] ... The variable argument list that contains pointers + to packages terminated by a NULL. + + @retval NULL A HII Handle has already been registered in the HII Database with + the same PackageListGuid. + @retval NULL The HII Handle could not be created. + @retval NULL An empty list of packages was passed in. + @retval NULL All packages are empty. + @retval Other The HII Handle associated with the newly registered package list. **/ -EFI_HII_PACKAGE_LIST_HEADER * -InternalHiiLibPreparePackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN VA_LIST Marker +EFI_HII_HANDLE +EFIAPI +HiiAddPackages ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_HANDLE DeviceHandle OPTIONAL, + ... ) { - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - UINT8 *PackageListData; - UINT32 PackageListLength; - UINT32 PackageLength; - EFI_HII_PACKAGE_HEADER PackageHeader; - UINT8 *PackageArray; - UINTN Index; - VA_LIST MarkerBackup; - - PackageListLength = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + EFI_STATUS Status; + EFI_HII_HANDLE *HiiHandleBuffer; + VA_LIST Args; + UINT32 *Package; + EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; + EFI_HII_HANDLE HiiHandle; + UINT32 Length; + UINT8 *Data; - MarkerBackup = Marker; + ASSERT (PackageListGuid != NULL); // - // Count the length of the final package list. + // Check to see if an HII Handle has already been registered with the same + // PackageListGuid // - for (Index = 0; Index < NumberOfPackages; Index++) { - CopyMem (&PackageLength, VA_ARG (Marker, VOID *), sizeof (UINT32)); - // - // Do not count the BinaryLength field. - // - PackageListLength += (PackageLength - sizeof (UINT32)); + HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); + if (HiiHandleBuffer != NULL) { + FreePool (HiiHandleBuffer); + return NULL; } // - // Include the length of EFI_HII_PACKAGE_END + // Calculate the length of all the packages in the variable argument list // - PackageListLength += sizeof (EFI_HII_PACKAGE_HEADER); - PackageListHeader = AllocateZeroPool (PackageListLength); - ASSERT (PackageListHeader != NULL); - - CopyGuid (&PackageListHeader->PackageListGuid, GuidId); - PackageListHeader->PackageLength = PackageListLength; - - PackageListData = ((UINT8 *) PackageListHeader) + sizeof (EFI_HII_PACKAGE_LIST_HEADER); + for (Length = 0, VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) { + Length += (ReadUnaligned32 (Package) - sizeof (UINT32)); + } + VA_END (Args); - Marker = MarkerBackup; // - // Prepare the final package list. + // If there are no packages in the variable argument list or all the packages + // are empty, then return a NULL HII Handle // - for (Index = 0; Index < NumberOfPackages; Index++) { - PackageArray = (UINT8 *) VA_ARG (Marker, VOID *); - // - // CopyMem is used for UINT32 to cover the unaligned address access. - // - CopyMem (&PackageLength, PackageArray, sizeof (UINT32)); - PackageLength -= sizeof (UINT32); - PackageArray += sizeof (UINT32); - CopyMem (PackageListData, PackageArray, PackageLength); - PackageListData += PackageLength; + if (Length == 0) { + return NULL; } // - // Append EFI_HII_PACKAGE_END + // Add the length of the Package List Header and the terminating Package Header // - PackageHeader.Type = EFI_HII_PACKAGE_END; - PackageHeader.Length = sizeof (EFI_HII_PACKAGE_HEADER); - CopyMem (PackageListData, &PackageHeader, PackageHeader.Length); - - return PackageListHeader; -} - -/** - Assemble EFI_HII_PACKAGE_LIST according to the passed in packages. - - If GuidId is NULL, then ASSERT. - If not enough resource to complete the operation, then ASSERT. - - @param NumberOfPackages Number of packages. - @param GuidId Package GUID. - @param ... Variable argument list for packages to be assembled. + Length += sizeof (EFI_HII_PACKAGE_LIST_HEADER) + sizeof (EFI_HII_PACKAGE_HEADER); - @return Pointer of EFI_HII_PACKAGE_LIST_HEADER. - -**/ -EFI_HII_PACKAGE_LIST_HEADER * -EFIAPI -HiiLibPreparePackageList ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - ... - ) -{ - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - VA_LIST Marker; - - ASSERT (GuidId != NULL); - - VA_START (Marker, GuidId); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Marker); - VA_END (Marker); - - return PackageListHeader; -} - - -/** - This function allocates pool for an EFI_HII_PACKAGE_LIST structure - with additional space that is big enough to host all packages described by the variable - argument list of package pointers. The allocated structure is initialized using NumberOfPackages, - GuidId, and the variable length argument list of package pointers. - - Then, EFI_HII_PACKAGE_LIST will be register to the default System HII Database. The - Handle to the newly registered Package List is returned through HiiHandle. - - If HiiHandle is NULL, then ASSERT. + // + // Allocate the storage for the entire Package List + // + PackageListHeader = AllocateZeroPool (Length); - @param NumberOfPackages The number of HII packages to register. - @param GuidId Package List GUID ID. - @param DriverHandle Optional. If not NULL, the DriverHandle on which an instance of DEVICE_PATH_PROTOCOL is installed. - This DriverHandle uniquely defines the device that the added packages are associated with. - @param HiiHandle On output, the HiiHandle is update with the handle which can be used to retrieve the Package - List later. If the functions failed to add the package to the default HII database, this value will - be set to NULL. - @param ... The variable argument list describing all HII Package. + // + // If the Packahge List can not be allocated, then return a NULL HII Handle + // + if (PackageListHeader == NULL) { + return NULL; + } - @return EFI_SUCCESS If the packages are successfully added to the default HII database. - @return EFI_OUT_OF_RESOURCE Not enough resource to complete the operation. + // + // Fill in the GUID and Length of the Package List Header + // + CopyGuid (&PackageListHeader->PackageListGuid, PackageListGuid); + PackageListHeader->PackageLength = Length; -**/ -EFI_STATUS -EFIAPI -HiiLibAddPackages ( - IN UINTN NumberOfPackages, - IN CONST EFI_GUID *GuidId, - IN EFI_HANDLE DriverHandle, OPTIONAL - OUT EFI_HII_HANDLE *HiiHandle, - ... - ) -{ - VA_LIST Args; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; - EFI_STATUS Status; + // + // Initialize a pointer to the beginning if the Package List data + // + Data = (UINT8 *)(PackageListHeader + 1); - ASSERT (HiiHandle != NULL); + // + // Copy the data from each package in the variable argument list + // + for (VA_START (Args, DeviceHandle); (Package = VA_ARG (Args, UINT32 *)) != NULL; ) { + Length = ReadUnaligned32 (Package) - sizeof (UINT32); + CopyMem (Data, Package + 1, Length); + Data += Length; + } + VA_END (Args); - VA_START (Args, HiiHandle); - PackageListHeader = InternalHiiLibPreparePackages (NumberOfPackages, GuidId, Args); + // + // Append a package of type EFI_HII_PACKAGE_END to mark the end of the package list + // + CopyMem (Data, &mEndOfPakageList, sizeof (mEndOfPakageList)); - Status = gHiiDatabase->NewPackageList (gHiiDatabase, PackageListHeader, DriverHandle, HiiHandle); - if (HiiHandle != NULL) { - if (EFI_ERROR (Status)) { - *HiiHandle = NULL; - } + // + // Register the package list with the HII Database + // + Status = gHiiDatabase->NewPackageList ( + gHiiDatabase, + PackageListHeader, + DeviceHandle, + &HiiHandle + ); + if (EFI_ERROR (Status)) { + HiiHandle = NULL; } + // + // Free the allocated package list + // FreePool (PackageListHeader); - VA_END (Args); - - return Status; + + // + // Return the new HII Handle + // + return HiiHandle; } /** - Removes a package list from the default HII database. + Removes a package list from the HII database. If HiiHandle is NULL, then ASSERT. - If HiiHandle is not a valid EFI_HII_HANDLE in the default HII database, then ASSERT. + If HiiHandle is not a valid EFI_HII_HANDLE in the HII database, then ASSERT. - @param HiiHandle The handle that was previously registered to the data base that is requested for removal. - List later. + @param[in] HiiHandle The handle that was previously registered in the HII database **/ VOID EFIAPI -HiiLibRemovePackages ( +HiiRemovePackages ( IN EFI_HII_HANDLE HiiHandle ) { EFI_STATUS Status; - ASSERT (IsHiiHandleRegistered (HiiHandle)); + ASSERT (HiiHandle != NULL); Status = gHiiDatabase->RemovePackageList (gHiiDatabase, HiiHandle); ASSERT_EFI_ERROR (Status); } /** - Determines the handles that are currently active in the database. - It's the caller's responsibility to free handle buffer. - - If HandleBufferLength is NULL, then ASSERT. - If HiiHandleBuffer is NULL, then ASSERT. - - @param HandleBufferLength On input, a pointer to the length of the handle - buffer. On output, the length of the handle buffer - that is required for the handles found. - @param HiiHandleBuffer Pointer to an array of Hii Handles returned. - - @retval EFI_SUCCESS Get an array of Hii Handles successfully. + Retrieves the array of all the HII Handles or the HII handle of a specific + package list in the HII Database. + This array is terminated with a NULL HII Handle. + This function allocates the returned array using AllocatePool(). + The caller is responsible for freeing the array with FreePool(). + + @param[in] PackageListGuid An optional parameter that is used to request + an HII Handle that is associatd with a specific + Package List GUID. If this parameter is NULL + then all the HII Handles in the HII Database + are returned. If this parameter is not NULL + then at most 1 HII Handle is returned. + + @retval NULL No HII handles were found in the HII database + @retval NULL The array of HII Handles could not be retrieved + @retval Other A pointer to the NULL terminated array of HII Handles **/ -EFI_STATUS +EFI_HII_HANDLE * EFIAPI -HiiLibGetHiiHandles ( - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HiiHandleBuffer +HiiGetHiiHandles ( + IN CONST EFI_GUID *PackageListGuid OPTIONAL ) { - EFI_STATUS Status; + EFI_STATUS Status; + UINTN HandleBufferLength; + EFI_HII_HANDLE TempHiiHandleBuffer; + EFI_HII_HANDLE *HiiHandleBuffer; + EFI_GUID Guid; + UINTN Index; + + // + // Retrieve the size required for the buffer of all HII handles. + // + HandleBufferLength = 0; + Status = gHiiDatabase->ListPackageLists ( + gHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &HandleBufferLength, + &TempHiiHandleBuffer + ); - ASSERT (HandleBufferLength != NULL); - ASSERT (HiiHandleBuffer != NULL); + // + // If ListPackageLists() returns EFI_SUCCESS for a zero size, + // then there are no HII handles in the HII database. If ListPackageLists() + // returns an error other than EFI_BUFFER_TOO_SMALL, then there are no HII + // handles in the HII database. + // + if (Status != EFI_BUFFER_TOO_SMALL) { + // + // Return NULL if the size can not be retrieved, or if there are no HII + // handles in the HII Database + // + return NULL; + } - *HandleBufferLength = 0; - *HiiHandleBuffer = NULL; + // + // Allocate the array of HII handles to hold all the HII Handles and a NULL terminator + // + HiiHandleBuffer = AllocateZeroPool (HandleBufferLength + sizeof (EFI_HII_HANDLE)); + if (HiiHandleBuffer == NULL) { + // + // Return NULL if allocation fails. + // + return NULL; + } // - // Try to find the actual buffer size for HiiHandle Buffer. + // Retrieve the array of HII Handles in the HII Database // Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - HandleBufferLength, - *HiiHandleBuffer - ); - - if (Status == EFI_BUFFER_TOO_SMALL) { - *HiiHandleBuffer = AllocateZeroPool (*HandleBufferLength); - ASSERT (*HiiHandleBuffer != NULL); - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - HandleBufferLength, - *HiiHandleBuffer - ); - - if (EFI_ERROR (Status)) { - FreePool (*HiiHandleBuffer); - *HiiHandleBuffer = NULL; - } + gHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &HandleBufferLength, + HiiHandleBuffer + ); + if (EFI_ERROR (Status)) { + // + // Free the buffer and return NULL if the HII handles can not be retrieved. + // + FreePool (HiiHandleBuffer); + return NULL; } - return Status; + if (PackageListGuid == NULL) { + // + // Return the NULL terminated array of HII handles in the HII Database + // + return HiiHandleBuffer; + } else { + for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) { + Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); + ASSERT_EFI_ERROR (Status); + if (CompareGuid (&Guid, PackageListGuid)) { + HiiHandleBuffer[0] = HiiHandleBuffer[Index]; + HiiHandleBuffer[1] = NULL; + return HiiHandleBuffer; + } + } + FreePool (HiiHandleBuffer); + return NULL; + } } /** Extract Hii package list GUID for given HII handle. - If HiiHandle could not be found in the default HII database, then ASSERT. + If HiiHandle could not be found in the HII database, then ASSERT. If Guid is NULL, then ASSERT. @param Handle Hii handle @@ -307,7 +319,7 @@ HiiLibGetHiiHandles ( **/ EFI_STATUS EFIAPI -HiiLibExtractGuidFromHiiHandle ( +InternalHiiExtractGuidFromHiiHandle ( IN EFI_HII_HANDLE Handle, OUT EFI_GUID *Guid ) @@ -317,7 +329,7 @@ HiiLibExtractGuidFromHiiHandle ( EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; ASSERT (Guid != NULL); - ASSERT (IsHiiHandleRegistered (Handle)); + ASSERT (Handle != NULL); // // Get HII PackageList @@ -350,326 +362,6 @@ HiiLibExtractGuidFromHiiHandle ( } /** - Find HII Handle in the default HII database associated with given Device Path. - - If DevicePath is NULL, then ASSERT. - - @param DevicePath Device Path associated with the HII package list - handle. - - @retval Handle HII package list Handle associated with the Device - Path. - @retval NULL Hii Package list handle is not found. - -**/ -EFI_HII_HANDLE -EFIAPI -HiiLibDevicePathToHiiHandle ( - IN EFI_DEVICE_PATH_PROTOCOL *DevicePath - ) -{ - EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; - UINTN BufferSize; - UINTN HandleCount; - UINTN Index; - EFI_HANDLE *Handles; - EFI_HANDLE Handle; - UINTN Size; - EFI_HANDLE DriverHandle; - EFI_HII_HANDLE *HiiHandles; - EFI_HII_HANDLE HiiHandle; - - ASSERT (DevicePath != NULL); - - // - // Locate Device Path Protocol handle buffer - // - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiDevicePathProtocolGuid, - NULL, - &HandleCount, - &Handles - ); - if (EFI_ERROR (Status)) { - return NULL; - } - - // - // Search Driver Handle by Device Path - // - DriverHandle = NULL; - BufferSize = GetDevicePathSize (DevicePath); - for(Index = 0; Index < HandleCount; Index++) { - Handle = Handles[Index]; - gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &TmpDevicePath); - - // - // Check whether DevicePath match - // - Size = GetDevicePathSize (TmpDevicePath); - if ((Size == BufferSize) && CompareMem (DevicePath, TmpDevicePath, Size) == 0) { - DriverHandle = Handle; - break; - } - } - FreePool (Handles); - - if (DriverHandle == NULL) { - return NULL; - } - - // - // Retrieve all Hii Handles from HII database - // - BufferSize = 0x1000; - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (HiiHandles); - HiiHandles = AllocatePool (BufferSize); - ASSERT (HiiHandles != NULL); - - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - EFI_HII_PACKAGE_TYPE_ALL, - NULL, - &BufferSize, - HiiHandles - ); - } - - if (EFI_ERROR (Status)) { - FreePool (HiiHandles); - return NULL; - } - - // - // Search Hii Handle by Driver Handle - // - HiiHandle = NULL; - HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); - for (Index = 0; Index < HandleCount; Index++) { - Status = gHiiDatabase->GetPackageListHandle ( - gHiiDatabase, - HiiHandles[Index], - &Handle - ); - if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { - HiiHandle = HiiHandles[Index]; - break; - } - } - - FreePool (HiiHandles); - return HiiHandle; -} - -/** - Exports the contents of one or all package lists in the HII database into a buffer. - - If Handle is not NULL and not a valid EFI_HII_HANDLE registered in the database, - then ASSERT. - If PackageListHeader is NULL, then ASSERT. - If PackageListSize is NULL, then ASSERT. - - @param Handle The HII Handle. - @param PackageListHeader A pointer to a buffer that will contain the results of - the export function. - @param PackageListSize On output, the length of the buffer that is required for the exported data. - - @retval EFI_SUCCESS Package exported. - - @retval EFI_OUT_OF_RESOURCES Not enought memory to complete the operations. - -**/ -EFI_STATUS -EFIAPI -HiiLibExportPackageLists ( - IN EFI_HII_HANDLE Handle, - OUT EFI_HII_PACKAGE_LIST_HEADER **PackageListHeader, - OUT UINTN *PackageListSize - ) -{ - EFI_STATUS Status; - UINTN Size; - EFI_HII_PACKAGE_LIST_HEADER *PackageListHdr; - - ASSERT (PackageListSize != NULL); - ASSERT (PackageListHeader != NULL); - - if (Handle != NULL) { - ASSERT (IsHiiHandleRegistered (Handle)); - } - - Size = 0; - PackageListHdr = NULL; - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - Handle, - &Size, - PackageListHdr - ); - ASSERT_EFI_ERROR (Status != EFI_BUFFER_TOO_SMALL); - - if (Status == EFI_BUFFER_TOO_SMALL) { - PackageListHdr = AllocateZeroPool (Size); - - if (PackageListHeader == NULL) { - return EFI_OUT_OF_RESOURCES; - } else { - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - Handle, - &Size, - PackageListHdr - ); - } - } - - if (!EFI_ERROR (Status)) { - *PackageListHeader = PackageListHdr; - *PackageListSize = Size; - } else { - FreePool (PackageListHdr); - } - - return Status; -} - -/** - - This function returns a list of the package handles of the - specified type that are currently active in the HII database. The - pseudo-type EFI_HII_PACKAGE_TYPE_ALL will cause all package - handles to be listed. - - If HandleBufferLength is NULL, then ASSERT. - If HandleBuffer is NULL, the ASSERT. - If PackageType is EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is - NULL, then ASSERT. - If PackageType is not EFI_HII_PACKAGE_TYPE_GUID and PackageGuid is not - NULL, then ASSERT. - - - @param PackageType Specifies the package type of the packages - to list or EFI_HII_PACKAGE_TYPE_ALL for - all packages to be listed. - - @param PackageGuid If PackageType is - EFI_HII_PACKAGE_TYPE_GUID, then this is - the pointer to the GUID which must match - the Guid field of - EFI_HII_PACKAGE_GUID_HEADER. Otherwise, it - must be NULL. - - @param HandleBufferLength On output, the length of the handle buffer - that is required for the handles found. - - @param HandleBuffer On output, an array of EFI_HII_HANDLE instances returned. - The caller is responcible to free this pointer allocated. - - @retval EFI_SUCCESS The matching handles are outputed successfully. - HandleBufferLength is updated with the actual length. - @retval EFI_OUT_OF_RESOURCES Not enough resource to complete the operation. - @retval EFI_NOT_FOUND No matching handle could not be found in database. -**/ -EFI_STATUS -EFIAPI -HiiLibListPackageLists ( - IN UINT8 PackageType, - IN CONST EFI_GUID *PackageGuid, - IN OUT UINTN *HandleBufferLength, - OUT EFI_HII_HANDLE **HandleBuffer - ) -{ - EFI_STATUS Status; - - ASSERT (HandleBufferLength != NULL); - ASSERT (HandleBuffer != NULL); - - *HandleBufferLength = 0; - *HandleBuffer = NULL; - - if (PackageType == EFI_HII_PACKAGE_TYPE_GUID) { - ASSERT (PackageGuid != NULL); - } else { - ASSERT (PackageGuid == NULL); - } - - Status = gHiiDatabase->ListPackageLists ( - gHiiDatabase, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { - // - // No packages is registered to UEFI HII Database, just return. - // - // - return Status; - } - - *HandleBuffer = AllocateZeroPool (*HandleBufferLength); - - if (*HandleBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - return gHiiDatabase->ListPackageLists ( - gHiiDatabase, - PackageType, - PackageGuid, - HandleBufferLength, - *HandleBuffer - ); - -} -/** - This function check if the Hii Handle is a valid handle registered - in the HII database. - - @param HiiHandle The HII Handle. - - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. -**/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ) -{ - EFI_STATUS Status; - UINTN BufferSize; - EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - - ASSERT (HiiHandle != NULL); - - HiiPackageList = NULL; - BufferSize = 0; - - Status = gHiiDatabase->ExportPackageLists ( - gHiiDatabase, - HiiHandle, - &BufferSize, - HiiPackageList - ); - - return (BOOLEAN) (Status == EFI_BUFFER_TOO_SMALL); -} - - -/** Converts all hex dtring characters in range ['A'..'F'] to ['a'..'f'] for hex digits that appear between a '=' and a '&' in a config string. @@ -2916,3 +2608,4 @@ HiiIfrLibExtractDefault( return EFI_SUCCESS; } + diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiString.c b/MdeModulePkg/Library/UefiHiiLib/HiiString.c index 7d8ca5e..2c317e5 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiString.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiString.c @@ -163,339 +163,340 @@ zulzu\ /** - This function adds the string into String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If StringId is NULL, the ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId On return, contains the new strings id, which is - unique within PackageList. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. + This function create a new string in String Package or updates an existing + string in a String Package. If StringId is 0, then a new string is added to + a String Package. If StringId is not zero, then a string in String Package is + updated. If SupportedLanguages is NULL, then the string is added or updated + for all the languages that the String Package supports. If SupportedLanguages + is not NULL, then the string is added or updated for the set of languages + specified by SupportedLanguages. + + If HiiHandle is NULL, then ASSERT(). + If String is NULL, then ASSERT(). + + @param[in] HiiHandle A handle that was previously registered in the + HII Database. + @param[in] StringId If zero, then a new string is created in the + String Package associated with HiiHandle. If + non-zero, then the string specified by StringId + is updated in the String Package associated + with HiiHandle. + @param[in] String A pointer to the Null-terminated Unicode string + to add or update in the String Package associated + with HiiHandle. + @param[in] SupportedLanguages A pointer to a Null-terminated ASCII string of + language codes. If this parameter is NULL, then + String is added or updated in the String Package + associated with HiiHandle for all the languages + that the String Package supports. If this + parameter is not NULL, then then String is added + or updated in the String Package associated with + HiiHandle for the set oflanguages specified by + SupportedLanguages. The format of + SupportedLanguages must follow the language + format assumed the HII Database. + + @retval 0 The string could not be added or updated in the String Package. + @retval Other The EFI_STRING_ID of the newly added or updated string. **/ -EFI_STATUS +EFI_STRING_ID EFIAPI -HiiLibNewString ( - IN EFI_HII_HANDLE PackageList, - OUT EFI_STRING_ID *StringId, - IN CONST EFI_STRING String +HiiSetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, OPTIONAL + IN CONST EFI_STRING String, + IN CONST CHAR8 *SupportedLanguages OPTIONAL ) { - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 *Lang; + EFI_STATUS Status; + CHAR8 *AllocatedLanguages; + CHAR8 *Supported; + CHAR8 *Language; + EFI_STRING_ID NewStringId; + ASSERT (HiiHandle != NULL); ASSERT (String != NULL); - ASSERT (StringId != NULL); - Status = EFI_SUCCESS; + if (SupportedLanguages == NULL) { + // + // Retrieve the languages that the package specified by HiiHandle supports + // + AllocatedLanguages = HiiGetSupportedLanguages (HiiHandle); + } else { + // + // Allocate a copy of the SupportLanguages string that passed in + // + AllocatedLanguages = AllocateCopyPool (AsciiStrLen (SupportedLanguages), SupportedLanguages); + } - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); // - // Allocate working buffer to contain substring of Languages. + // If there are not enough resources for the supported languages string, then return a StringId of 0 // - Lang = AllocatePool (AsciiStrSize (Languages)); - ASSERT (Lang != NULL); + if (AllocatedLanguages == NULL) { + return (EFI_STRING_ID)(0); + } - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); + NewStringId = 0; + Status = EFI_INVALID_PARAMETER; + // + // Loop through each language that the string supports + // + for (Supported = AllocatedLanguages; *Supported != '\0'; ) { + // + // Cache a pointer to the beginning of the current language in the list of languages + // + Language = Supported; // - // For each language supported by the package, - // a string token is created. + // Search for the next language seperator and replace it with a Null-terminator // - Status = gHiiString->NewString ( - gHiiString, - PackageList, - StringId, - Lang, - NULL, - String, - NULL - ); - if (EFI_ERROR (Status)) { - break; + for (; *Supported != 0 && *Supported != ';'; Supported++); + if (*Supported != 0) { + *(Supported++) = '\0'; } - } - - FreePool (Lang); - FreePool (Languages); - - return Status; - -} - -/** - This function update the specified string in String Package of each language - supported by the package list. - - If String is NULL, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList Handle of the package list where this string will - be added. - @param StringId Ths String Id to be updated. - @param String Points to the new null-terminated string. - - @retval EFI_SUCCESS The new string was added successfully. - @retval EFI_OUT_OF_RESOURCES Could not add the string due to lack of resources. - -**/ -EFI_STATUS -EFIAPI -HiiLibSetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - IN CONST EFI_STRING String - ) -{ - EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *LangStrings; - CHAR8 *Lang; - - ASSERT (IsHiiHandleRegistered (PackageList)); - - Status = EFI_SUCCESS; - - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); - - // - // Allocate working buffer to contain substring of Languages. - // - Lang = AllocatePool (AsciiStrSize (Languages)); - ASSERT (Lang != NULL); - - LangStrings = Languages; - while (*LangStrings != 0) { - HiiLibGetNextLanguage (&LangStrings, Lang); + // + // If StringId is 0, then call NewString(). Otherwise, call SetString() + // + if (StringId == (EFI_STRING_ID)(0)) { + Status = gHiiString->NewString (gHiiString, HiiHandle, &NewStringId, Language, NULL, String, NULL); + } else { + Status = gHiiString->SetString (gHiiString, HiiHandle, StringId, Language, String, NULL); + } // - // For each language supported by the package, - // the string is updated. + // If there was an error, then break out of the loop and return a StringId of 0 // - Status = gHiiString->SetString ( - gHiiString, - PackageList, - StringId, - Lang, - String, - NULL - ); if (EFI_ERROR (Status)) { break; } } - FreePool (Lang); - FreePool (Languages); - - return Status; + // + // Free the buffer of supported languages + // + FreePool (AllocatedLanguages); + + if (EFI_ERROR (Status)) { + return (EFI_STRING_ID)(0); + } else if (StringId == (EFI_STRING_ID)(0)) { + return NewStringId; + } else { + return StringId; + } } /** - Get the string given the StringId and String package Producer's Guid. The caller - is responsible to free the *String. - - If PackageList with the matching ProducerGuid is not found, then ASSERT. - If PackageList with the matching ProducerGuid is found but no String is - specified by StringId is found, then ASSERT. - - @param ProducerGuid The Guid of String package list. - @param StringId The String ID. - @param String The output string. - - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + Retrieves a string from a string package names by GUID in a specific language. + If the language is not specified, then a string from a string package in the + current platform language is retrieved. If the string can not be retrieved + using the specified language or the current platform language, then the string + is retrieved from the string package in the first language the string package + supports. The returned string is allocated using AllocatePool(). The caller + is responsible for freeing the allocated buffer using FreePool(). + + If PackageListGuid is NULL, then ASSERT(). + If StringId is 0, then ASSERT. + + @param[in] PackageListGuid The GUID of a package list that was previously + registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the + string package associated with PackageListGuid. + @param[in] Language The language of the string to retrieve. If this + parameter is NULL, then the current platform + language is used. The format of Language must + follow the language format assumed the HII Database. + + @retval NULL The package list specified by PackageListGuid is not present in the + HII Database. + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetStringFromToken ( - IN EFI_GUID *ProducerGuid, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String +HiiGetPackageString ( + IN CONST EFI_GUID *PackageListGuid, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) { - EFI_STATUS Status; - UINTN Index; - UINTN HandleBufferLen; - EFI_HII_HANDLE *HiiHandleBuffer; - EFI_GUID Guid; + EFI_HANDLE *HiiHandleBuffer; + EFI_HANDLE HiiHandle; - Status = HiiLibGetHiiHandles (&HandleBufferLen, &HiiHandleBuffer); - if (HiiHandleBuffer == NULL) { - return EFI_NOT_FOUND; - } - for (Index = 0; Index < (HandleBufferLen / sizeof (EFI_HII_HANDLE)); Index++) { - Status = HiiLibExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); - if (EFI_ERROR(Status)) { - return Status; - } - if (CompareGuid (&Guid, ProducerGuid)) { - break; - } - } + ASSERT (PackageListGuid != NULL); - if (Index >= (HandleBufferLen / sizeof (EFI_HII_HANDLE))) { - // - // If PackageList with the matching ProducerGuid is not found, then ASSERT. - // - ASSERT (FALSE); - Status = EFI_NOT_FOUND; - goto Out; + HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); + if (HiiHandleBuffer == NULL) { + return NULL; } - Status = HiiLibGetStringFromHandle (HiiHandleBuffer[Index], StringId, String); - -Out: + HiiHandle = HiiHandleBuffer[0]; FreePool (HiiHandleBuffer); - return Status; + return HiiGetString (HiiHandle, StringId, Language); } /** - This function try to retrieve string from String package of current language. - If fails, it try to retrieve string from String package of first language it support. - - If StringSize is NULL, then ASSERT. - If String is NULL and *StringSize is not 0, then ASSERT. - If PackageList could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param PackageList The package list in the HII database to search for - the specified string. - @param StringId The string's id, which is unique within - PackageList. - @param String Points to the new null-terminated string. - @param StringSize On entry, points to the size of the buffer pointed - to by String, in bytes. On return, points to the - length of the string, in bytes. - - @retval EFI_SUCCESS The string was returned successfully. - @retval EFI_NOT_FOUND The string specified by StringId is not available. - @retval EFI_BUFFER_TOO_SMALL The buffer specified by StringLength is too small - to hold the string. + Retrieves a string from a string package in a specific language. If the language + is not specified, then a string from a string package in the current platform + language is retrieved. If the string can not be retrieved using the specified + language or the current platform language, then the string is retrieved from + the string package in the first language the string package supports. The + returned string is allocated using AllocatePool(). The caller is responsible + for freeing the allocated buffer using FreePool(). + + If HiiHandle is NULL, then ASSERT(). + If StringId is 0, then ASSET. + + @param[in] HiiHandle A handle that was previously registered in the HII Database. + @param[in] StringId The identifier of the string to retrieved from the string + package associated with HiiHandle. + @param[in] Language The language of the string to retrieve. If this parameter + is NULL, then the current platform language is used. The + format of Language must follow the language format assumed + the HII Database. + + @retval NULL The string specified by StringId is not present in the string package. + @retval Other The string was returned. **/ -EFI_STATUS +EFI_STRING EFIAPI -HiiLibGetString ( - IN EFI_HII_HANDLE PackageList, - IN EFI_STRING_ID StringId, - OUT EFI_STRING String, - IN OUT UINTN *StringSize +HiiGetString ( + IN EFI_HII_HANDLE HiiHandle, + IN EFI_STRING_ID StringId, + IN CONST CHAR8 *Language OPTIONAL ) { EFI_STATUS Status; - CHAR8 *Languages; - CHAR8 *CurrentLang; + UINTN StringSize; + CHAR16 TempString; + EFI_STRING String; + CHAR8 *SupportedLanguages; + CHAR8 *PlatformLanguage; CHAR8 *BestLanguage; - ASSERT (StringSize != NULL); - ASSERT (!(*StringSize != 0 && String == NULL)); - ASSERT (IsHiiHandleRegistered (PackageList)); + ASSERT (HiiHandle != NULL); + ASSERT (StringId != 0); - Languages = HiiLibGetSupportedLanguages (PackageList); - ASSERT (Languages != NULL); + // + // Initialize all allocated buffers to NULL + // + SupportedLanguages = NULL; + PlatformLanguage = NULL; + BestLanguage = NULL; + String = NULL; - CurrentLang = GetEfiGlobalVariable (L"PlatformLang"); - - Status = EFI_NOT_FOUND; - BestLanguage = GetBestLanguage ( - Languages, - FALSE, - (CurrentLang != NULL) ? CurrentLang : "", - (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang), - Languages, - NULL - ); - if (BestLanguage != NULL ) { - Status = gHiiString->GetString ( - gHiiString, - BestLanguage, - PackageList, - StringId, - String, - StringSize, - NULL - ); - FreePool (BestLanguage); - } - if (CurrentLang != NULL) { - FreePool (CurrentLang); + // + // Get the languages that the package specified by HiiHandle supports + // + SupportedLanguages = HiiGetSupportedLanguages (HiiHandle); + if (SupportedLanguages == NULL) { + goto Error; } - FreePool (Languages); - - return Status; -} + // + // Get the current platform language setting + // + PlatformLanguage = GetEfiGlobalVariable (L"PlatformLang"); -/** - Get string specified by StringId form the HiiHandle. The caller - is responsible to free the *String. - - If String is NULL, then ASSERT. - If HiiHandle could not be found in the default HII database, then ASSERT. - If StringId is not found in PackageList, then ASSERT. - - @param HiiHandle The HII handle of package list. - @param StringId The String ID. - @param String The output string. + // + // If Languag is NULL, then set it to an empty string, so it will be + // skipped by GetBestLanguage() + // + if (Language == NULL) { + Language = ""; + } - @retval EFI_NOT_FOUND String is not found. - @retval EFI_SUCCESS Operation is successful. - @retval EFI_OUT_OF_RESOURCES There is not enought memory in the system. + // + // Get the best matching language from SupportedLanguages + // + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, // RFC 4646 mode + Language, // Highest priority + PlatformLanguage != NULL ? PlatformLanguage : "", // Next highest priority + SupportedLanguages, // Lowest priority + NULL + ); + if (BestLanguage == NULL) { + goto Error; + } -**/ -EFI_STATUS -EFIAPI -HiiLibGetStringFromHandle ( - IN EFI_HII_HANDLE HiiHandle, - IN EFI_STRING_ID StringId, - OUT EFI_STRING *String - ) -{ - EFI_STATUS Status; - UINTN StringSize; + // + // Retrieve the size of the string in the string package for the BestLanguage + // + StringSize = 0; + Status = gHiiString->GetString ( + gHiiString, + BestLanguage, + HiiHandle, + StringId, + &TempString, + &StringSize, + NULL + ); + // + // If GetString() returns EFI_SUCCESS for a zero size, + // then there are no supported languages registered for HiiHandle. If GetString() + // returns an error other than EFI_BUFFER_TOO_SMALL, then HiiHandle is not present + // in the HII Database + // + if (Status != EFI_BUFFER_TOO_SMALL) { + goto Error; + } - ASSERT (String != NULL); + // + // Allocate a buffer for the return string + // + String = AllocateZeroPool (StringSize); + if (String == NULL) { + goto Error; + } - StringSize = HII_LIB_DEFAULT_STRING_SIZE; - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; + // + // Retrieve the string from the string package + // + Status = gHiiString->GetString ( + gHiiString, + BestLanguage, + HiiHandle, + StringId, + String, + &StringSize, + NULL + ); + if (EFI_ERROR (Status)) { + // + // Free the buffer and return NULL if the supported languages can not be retrieved. + // + FreePool (String); + String = NULL; } - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (*String); - *String = AllocateZeroPool (StringSize); - if (*String == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Status = HiiLibGetString (HiiHandle, StringId, *String, &StringSize); +Error: + // + // Free allocated buffers + // + if (SupportedLanguages != NULL) { + FreePool (SupportedLanguages); + } + if (PlatformLanguage != NULL) { + FreePool (PlatformLanguage); + } + if (BestLanguage != NULL) { + FreePool (BestLanguage); } - return Status; + // + // Return the Null-terminated Unicode string + // + return String; } - - /** Convert language code from RFC3066 to ISO639-2. diff --git a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h index e144635..c3fd834 100644 --- a/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h +++ b/MdeModulePkg/Library/UefiHiiLib/InternalHiiLib.h @@ -48,17 +48,23 @@ extern CONST EFI_HII_DATABASE_PROTOCOL *mHiiDatabaseProt; extern CONST EFI_HII_STRING_PROTOCOL *mHiiStringProt; /** - This function check if the Hii Handle is a valid handle registered - in the HII database. + Extract Hii package list GUID for given HII handle. - @param HiiHandle The HII Handle. + If HiiHandle could not be found in the HII database, then ASSERT. + If Guid is NULL, then ASSERT. + + @param Handle Hii handle + @param Guid Package list GUID + + @retval EFI_SUCCESS Successfully extract GUID from Hii database. - @retval TRUE If it is a valid HII handle. - @retval FALSE If it is a invalid HII handle. **/ -BOOLEAN -IsHiiHandleRegistered ( - EFI_HII_HANDLE HiiHandle - ); +EFI_STATUS +EFIAPI +InternalHiiExtractGuidFromHiiHandle ( + IN EFI_HII_HANDLE Handle, + OUT EFI_GUID *Guid + ) +; #endif diff --git a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c index 4de8009..3d2e3f3 100644 --- a/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c +++ b/MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsole.c @@ -1857,7 +1857,6 @@ RegisterFontPackage ( EFI_STATUS Status; EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimplifiedFont; UINT32 PackageLength; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; UINT8 *Package; UINT8 *Location; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; @@ -1873,7 +1872,7 @@ RegisterFontPackage ( ASSERT_EFI_ERROR (Status); // - // Add 4 bytes to the header for entire length for HiiLibPreparePackageList use only. + // Add 4 bytes to the header for entire length for HiiAddPackages use only. // // +--------------------------------+ <-- Package // | | @@ -1905,10 +1904,13 @@ RegisterFontPackage ( // // Add this simplified font package to a package list then install it. // - PackageList = HiiLibPreparePackageList (1, &mFontPackageListGuid, Package); - Status = HiiDatabase->NewPackageList (HiiDatabase, PackageList, NULL, &mHiiHandle); - ASSERT_EFI_ERROR (Status); - FreePool (PackageList); + mHiiHandle = HiiAddPackages ( + &mFontPackageListGuid, + NULL, + Package, + NULL + ); + ASSERT (mHiiHandle != NULL); FreePool (Package); } diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 409c8e4..573374f 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -170,21 +170,21 @@ ValidatePassword ( // // Get user input password // - BufferSize = 21 * sizeof (CHAR16); - Password = AllocateZeroPool (BufferSize); - ASSERT (Password != NULL); - - Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize); - if (EFI_ERROR (Status)) { + Password = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL); + if (Password == NULL) { + return EFI_NOT_READY; + } + if (StrLen (Password) > 20) { FreePool (Password); - return Status; + return EFI_NOT_READY; } // // Validate old password // - EncodedPassword = AllocateCopyPool (21 * sizeof (CHAR16), Password); + EncodedPassword = AllocateZeroPool (21 * sizeof (CHAR16)); ASSERT (EncodedPassword != NULL); + StrnCpy (EncodedPassword, Password, 21); EncodePassword (EncodedPassword, 20 * sizeof (CHAR16)); if (CompareMem (EncodedPassword, PrivateData->Configuration.WhatIsThePassword2, 20 * sizeof (CHAR16)) != 0) { // @@ -219,6 +219,7 @@ SetPassword ( { EFI_STATUS Status; CHAR16 *Password; + CHAR16 *TempPassword; UINTN PasswordSize; DRIVER_SAMPLE_CONFIGURATION *Configuration; UINTN BufferSize; @@ -242,13 +243,19 @@ SetPassword ( // Get user input password // Password = &PrivateData->Configuration.WhatIsThePassword2[0]; - PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); - + PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); ZeroMem (Password, PasswordSize); - Status = HiiLibGetString (PrivateData->HiiHandle[0], StringId, Password, &BufferSize); - if (EFI_ERROR (Status)) { - return Status; + + TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL); + if (TempPassword == NULL) { + return EFI_NOT_READY; + } + if (StrLen (TempPassword) > PasswordSize / sizeof (CHAR16)) { + FreePool (TempPassword); + return EFI_NOT_READY; } + StrnCpy (Password, TempPassword, PasswordSize / sizeof (CHAR16)); + FreePool (TempPassword); // // Retrive uncommitted data from Browser @@ -786,7 +793,6 @@ DriverSampleInit ( { EFI_STATUS Status; EFI_STATUS SavedStatus; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; EFI_HII_HANDLE HiiHandle[2]; EFI_SCREEN_DESCRIPTOR Screen; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; @@ -878,26 +884,17 @@ DriverSampleInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList ( - 2, - &mFormSetGuid, - DriverSampleStrings, - VfrBin - ); - if (PackageList == NULL) { + HiiHandle[0] = HiiAddPackages ( + &mFormSetGuid, + DriverHandle[0], + DriverSampleStrings, + VfrBin, + NULL + ); + if (HiiHandle[0] == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - DriverHandle[0], - &HiiHandle[0] - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; - } PrivateData->HiiHandle[0] = HiiHandle[0]; // @@ -913,26 +910,17 @@ DriverSampleInit ( PrivateData->DriverHandle[1] = DriverHandle[1]; - PackageList = HiiLibPreparePackageList ( - 2, - &mInventoryGuid, - DriverSampleStrings, - InventoryBin - ); - if (PackageList == NULL) { + HiiHandle[1] = HiiAddPackages ( + &mInventoryGuid, + DriverHandle[1], + DriverSampleStrings, + InventoryBin, + NULL + ); + if (HiiHandle[1] == NULL) { return EFI_OUT_OF_RESOURCES; } - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - DriverHandle[1], - &HiiHandle[1] - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { - return Status; - } PrivateData->HiiHandle[1] = HiiHandle[1]; // @@ -941,9 +929,8 @@ DriverSampleInit ( // NewString = L"700 Mhz"; - Status = HiiLibSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString); - if (EFI_ERROR (Status)) { - return Status; + if (HiiSetString (HiiHandle[0], STRING_TOKEN (STR_CPU_STRING2), NewString, NULL) == 0) { + return EFI_OUT_OF_RESOURCES; } // diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h index 3317e4f..ded3312 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h @@ -34,6 +34,7 @@ Revision History #include #include +#include #include #include #include @@ -53,7 +54,7 @@ extern UINT8 VfrMyIfrNVDataBlockName[]; // // This is the generated IFR binary data for each formset defined in VFR. -// This data array is ready to be used as input of HiiLibPreparePackageList() to +// This data array is ready to be used as input of HiiAddPackages() to // create a packagelist (which contains Form packages, String packages, etc). // extern UINT8 VfrBin[]; @@ -61,7 +62,7 @@ extern UINT8 InventoryBin[]; // // This is the generated String package data for all .UNI files. -// This data array is ready to be used as input of HiiLibPreparePackageList() to +// This data array is ready to be used as input of HiiAddPackages() to // create a packagelist (which contains Form packages, String packages, etc). // extern UINT8 DriverSampleStrings[]; diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf index 3ed56e9..657d0ca 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf @@ -46,6 +46,7 @@ [LibraryClasses] + BaseLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c index 76068e5..0025f24 100644 --- a/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c +++ b/MdeModulePkg/Universal/Network/IScsiDxe/IScsiConfig.c @@ -715,7 +715,7 @@ IScsiFormCallback ( UnicodeSPrint (PortString, (UINTN) 128, L"Port %s", ConfigFormEntry->MacString); DeviceFormTitleToken = (EFI_STRING_ID) STR_ISCSI_DEVICE_FORM_TITLE; - HiiLibSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString); + HiiSetString (Private->RegisteredHandle, DeviceFormTitleToken, PortString, NULL); IScsiConvertDeviceConfigDataToIfrNvData (ConfigFormEntry, IfrNvData); @@ -840,13 +840,13 @@ IScsiConfigUpdateForm ( // Compose the Port string and create a new EFI_STRING_ID. // UnicodeSPrint (PortString, 128, L"Port %s", ConfigFormEntry->MacString); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleToken, PortString); + ConfigFormEntry->PortTitleToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); // // Compose the help string of this port and create a new EFI_STRING_ID. // UnicodeSPrint (PortString, 128, L"Set the iSCSI parameters on port %s", ConfigFormEntry->MacString); - HiiLibNewString (mCallbackInfo->RegisteredHandle, &ConfigFormEntry->PortTitleHelpToken, PortString); + ConfigFormEntry->PortTitleHelpToken = HiiSetString (mCallbackInfo->RegisteredHandle, 0, PortString, NULL); InsertTailList (&mIScsiConfigFormList, &ConfigFormEntry->Link); mNumberOfIScsiDevices++; @@ -931,7 +931,6 @@ IScsiConfigFormInit ( { EFI_STATUS Status; EFI_HII_DATABASE_PROTOCOL *HiiDatabase; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; ISCSI_FORM_CALLBACK_INFO *CallbackInfo; Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase); @@ -974,19 +973,16 @@ IScsiConfigFormInit ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (2, &mVendorGuid, IScsiDxeStrings, IScsiConfigDxeBin); - ASSERT (PackageList != NULL); - - Status = HiiDatabase->NewPackageList ( - HiiDatabase, - PackageList, - CallbackInfo->DriverHandle, - &CallbackInfo->RegisteredHandle - ); - FreePool (PackageList); - if (EFI_ERROR (Status)) { + CallbackInfo->RegisteredHandle = HiiAddPackages ( + &mVendorGuid, + CallbackInfo->DriverHandle, + IScsiDxeStrings, + IScsiConfigDxeBin, + NULL + ); + if (CallbackInfo->RegisteredHandle == NULL) { FreePool(CallbackInfo); - return Status; + return EFI_OUT_OF_RESOURCES; } mCallbackInfo = CallbackInfo; diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c index e612d4f..02f5556 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c @@ -108,17 +108,15 @@ UpdateCheckBoxStringToken ( { CHAR16 Str[MAXIMUM_VALUE_CHARACTERS]; EFI_STRING_ID Id; - EFI_STATUS Status; ASSERT (Statement != NULL); ASSERT (Statement->Operand == EFI_IFR_NUMERIC_OP); UnicodeValueToString (Str, 0, Statement->VarStoreInfo.VarName, MAXIMUM_VALUE_CHARACTERS - 1); - - Status = HiiLibNewString (FormSet->HiiHandle, &Id, Str); - if (EFI_ERROR (Status)) { - return Status; + Id = HiiSetString (FormSet->HiiHandle, 0, Str, NULL); + if (Id == 0) { + return EFI_OUT_OF_RESOURCES; } Statement->VarStoreInfo.VarName = Id; diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c index 26acccd..f5963ce 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c @@ -525,7 +525,6 @@ InitializeSetup ( ) { EFI_STATUS Status; - EFI_HII_PACKAGE_LIST_HEADER *PackageList; // // Locate required Hii relative protocols @@ -554,15 +553,13 @@ InitializeSetup ( // // Publish our HII data // - PackageList = HiiLibPreparePackageList (1, &gSetupBrowserGuid, SetupBrowserStrings); - ASSERT (PackageList != NULL); - Status = mHiiDatabase->NewPackageList ( - mHiiDatabase, - PackageList, - ImageHandle, - &gHiiHandle - ); - ASSERT_EFI_ERROR (Status); + gHiiHandle = HiiAddPackages ( + &gSetupBrowserGuid, + ImageHandle, + SetupBrowserStrings, + NULL + ); + ASSERT (gHiiHandle != NULL); // // Initialize Driver private data @@ -603,11 +600,9 @@ NewString ( ) { EFI_STRING_ID StringId; - EFI_STATUS Status; - StringId = 0; - Status = HiiLibNewString (HiiHandle, &StringId, String); - ASSERT_EFI_ERROR (Status); + StringId = HiiSetString (HiiHandle, 0, String, NULL); + ASSERT (StringId != 0); return StringId; } @@ -631,7 +626,8 @@ DeleteString ( CHAR16 NullChar; NullChar = CHAR_NULL; - return HiiLibSetString (HiiHandle, StringId, &NullChar); + HiiSetString (HiiHandle, StringId, &NullChar, NULL); + return EFI_SUCCESS; } @@ -651,29 +647,11 @@ GetToken ( IN EFI_HII_HANDLE HiiHandle ) { - EFI_STATUS Status; - CHAR16 *String; - UINTN BufferLength; + EFI_STRING String; - // - // Set default string size assumption at no more than 256 bytes - // - BufferLength = 0x100; - String = AllocateZeroPool (BufferLength); + String = HiiGetString (HiiHandle, Token, NULL); ASSERT (String != NULL); - - Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength); - - if (Status == EFI_BUFFER_TOO_SMALL) { - FreePool (String); - String = AllocateZeroPool (BufferLength); - ASSERT (String != NULL); - - Status = HiiLibGetString (HiiHandle, Token, String, &BufferLength); - } - ASSERT_EFI_ERROR (Status); - - return String; + return (CHAR16 *) String; } diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h index b19d1ba..b352482 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h @@ -41,6 +41,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include "Colors.h" diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf index bd4ba10..77951ee 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf +++ b/MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf @@ -59,7 +59,8 @@ DebugLib PrintLib HiiLib - + DevicePathLib + [Guids] gEfiIfrTianoGuid ## CONSUMES ## GUID gEfiIfrFrameworkGuid ## CONSUMES ## GUID diff --git a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c index 42074ca..4d2fc88 100644 --- a/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c +++ b/MdeModulePkg/Universal/SetupBrowserDxe/Ui.c @@ -1448,6 +1448,102 @@ AdjustDateAndTimePosition ( return PadLineNumber; } +/** + Find HII Handle in the HII database associated with given Device Path. + + If DevicePath is NULL, then ASSERT. + + @param DevicePath Device Path associated with the HII package list + handle. + + @retval Handle HII package list Handle associated with the Device + Path. + @retval NULL Hii Package list handle is not found. + +**/ +EFI_HII_HANDLE +EFIAPI +DevicePathToHiiHandle ( + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *TmpDevicePath; + UINTN BufferSize; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE Handle; + EFI_HANDLE DriverHandle; + EFI_HII_HANDLE *HiiHandles; + EFI_HII_HANDLE HiiHandle; + + ASSERT (DevicePath != NULL); + + TmpDevicePath = DevicePath; + // + // Locate Device Path Protocol handle buffer + // + Status = gBS->LocateDevicePath ( + &gEfiDevicePathProtocolGuid, + &TmpDevicePath, + &DriverHandle + ); + if (EFI_ERROR (Status) || !IsDevicePathEnd (TmpDevicePath)) { + return NULL; + } + + // + // Retrieve all HII Handles from HII database + // + BufferSize = 0x1000; + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + if (Status == EFI_BUFFER_TOO_SMALL) { + FreePool (HiiHandles); + HiiHandles = AllocatePool (BufferSize); + ASSERT (HiiHandles != NULL); + + Status = mHiiDatabase->ListPackageLists ( + mHiiDatabase, + EFI_HII_PACKAGE_TYPE_ALL, + NULL, + &BufferSize, + HiiHandles + ); + } + + if (EFI_ERROR (Status)) { + FreePool (HiiHandles); + return NULL; + } + + // + // Search Hii Handle by Driver Handle + // + HiiHandle = NULL; + HandleCount = BufferSize / sizeof (EFI_HII_HANDLE); + for (Index = 0; Index < HandleCount; Index++) { + Status = mHiiDatabase->GetPackageListHandle ( + mHiiDatabase, + HiiHandles[Index], + &Handle + ); + if (!EFI_ERROR (Status) && (Handle == DriverHandle)) { + HiiHandle = HiiHandles[Index]; + break; + } + } + + FreePool (HiiHandles); + return HiiHandle; +} /** Display menu and wait for user to select one menu option, then return it. @@ -2382,7 +2478,7 @@ UiDisplayMenu ( } } - Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath); + Selection->Handle = DevicePathToHiiHandle (DevicePath); if (Selection->Handle == NULL) { // // If target Hii Handle not found, exit -- cgit v1.1