X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FLibrary%2FUefiHiiLib%2FHiiLib.c;h=b740d43aad4b387ee507047f62f2de326b319598;hb=9f4048f7f8cd4b6bd5eee0f0c4bfd4eb6926a536;hp=ba197fd7f9caf9779d4e50f0917cb3bfb494a5eb;hpb=62b658dd7fc1a617b2bfc81b58d168a6ecb10608;p=mirror_edk2.git diff --git a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c index ba197fd7f9..b740d43aad 100644 --- a/MdeModulePkg/Library/UefiHiiLib/HiiLib.c +++ b/MdeModulePkg/Library/UefiHiiLib/HiiLib.c @@ -1,8 +1,8 @@ /** @file HII Library implementation that uses DXE protocols and services. - Copyright (c) 2006 - 2008, Intel Corporation
- All rights reserved. This program and the accompanying materials + Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
+ This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -31,6 +31,11 @@ typedef struct { UINT8 Scope; } IFR_BLOCK_DATA; +typedef struct { + EFI_VARSTORE_ID VarStoreId; + UINT16 Size; +} IFR_VARSTORAGE_DATA; + // // Template // @@ -105,10 +110,10 @@ InternalHiiExtractGuidFromHiiHandle ( /** 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. + with the same PackageListGuid and DeviceHandle, 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. @@ -129,7 +134,7 @@ InternalHiiExtractGuidFromHiiHandle ( to packages terminated by a NULL. @retval NULL A HII Handle has already been registered in the HII Database with - the same PackageListGuid. + the same PackageListGuid and DeviceHandle. @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. @@ -145,7 +150,6 @@ HiiAddPackages ( ) { EFI_STATUS Status; - EFI_HII_HANDLE *HiiHandleBuffer; VA_LIST Args; UINT32 *Package; EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; @@ -155,16 +159,6 @@ HiiAddPackages ( ASSERT (PackageListGuid != NULL); - // - // Check to see if an HII Handle has already been registered with the same - // PackageListGuid - // - HiiHandleBuffer = HiiGetHiiHandles (PackageListGuid); - if (HiiHandleBuffer != NULL) { - FreePool (HiiHandleBuffer); - return NULL; - } - // // Calculate the length of all the packages in the variable argument list // @@ -192,7 +186,7 @@ HiiAddPackages ( PackageListHeader = AllocateZeroPool (Length); // - // If the Packahge List can not be allocated, then return a NULL HII Handle + // If the Package List can not be allocated, then return a NULL HII Handle // if (PackageListHeader == NULL) { return NULL; @@ -272,18 +266,19 @@ HiiRemovePackages ( /** - Retrieves the array of all the HII Handles or the HII handle of a specific - package list in the HII Database. + Retrieves the array of all the HII Handles or the HII handles of a specific + package list GUID 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 + HII Handles associated 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. + are returned. If this parameter is not NULL, + then zero or more HII Handles associated with + PackageListGuid are returned. @retval NULL No HII handles were found in the HII database @retval NULL The array of HII Handles could not be retrieved @@ -301,7 +296,8 @@ HiiGetHiiHandles ( EFI_HII_HANDLE TempHiiHandleBuffer; EFI_HII_HANDLE *HiiHandleBuffer; EFI_GUID Guid; - UINTN Index; + UINTN Index1; + UINTN Index2; // // Retrieve the size required for the buffer of all HII handles. @@ -364,27 +360,151 @@ HiiGetHiiHandles ( // return HiiHandleBuffer; } else { - for (Index = 0; HiiHandleBuffer[Index] != NULL; Index++) { - Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index], &Guid); + for (Index1 = 0, Index2 = 0; HiiHandleBuffer[Index1] != NULL; Index1++) { + Status = InternalHiiExtractGuidFromHiiHandle (HiiHandleBuffer[Index1], &Guid); ASSERT_EFI_ERROR (Status); if (CompareGuid (&Guid, PackageListGuid)) { - HiiHandleBuffer[0] = HiiHandleBuffer[Index]; - HiiHandleBuffer[1] = NULL; - return HiiHandleBuffer; + HiiHandleBuffer[Index2++] = HiiHandleBuffer[Index1]; } } - FreePool (HiiHandleBuffer); - return NULL; + if (Index2 > 0) { + HiiHandleBuffer[Index2] = NULL; + return HiiHandleBuffer; + } else { + FreePool (HiiHandleBuffer); + return NULL; + } + } +} + +/** + This function allows a caller to extract the form set opcode form the Hii Handle. + The returned buffer is allocated using AllocatePool().The caller is responsible + for freeing the allocated buffer using FreePool(). + + @param Handle The HII handle. + @param Buffer On return, points to a pointer which point to the buffer that contain the formset opcode. + @param BufferSize On return, points to the length of the buffer. + + @retval EFI_OUT_OF_RESOURCES No enough memory resource is allocated. + @retval EFI_NOT_FOUND Can't find the package data for the input Handle. + @retval EFI_INVALID_PARAMETER The input parameters are not correct. + @retval EFI_SUCCESS Get the formset opcode from the hii handle successfully. + +**/ +EFI_STATUS +EFIAPI +HiiGetFormSetFromHiiHandle( + IN EFI_HII_HANDLE Handle, + OUT EFI_IFR_FORM_SET **Buffer, + OUT UINTN *BufferSize + ) +{ + EFI_STATUS Status; + UINTN PackageListSize; + UINTN TempSize; + EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; + UINT8 *Package; + UINT8 *OpCodeData; + UINT8 *FormSetBuffer; + UINT8 *TempBuffer; + UINT32 Offset; + UINT32 Offset2; + UINT32 PackageListLength; + EFI_HII_PACKAGE_HEADER PackageHeader; + + TempSize = 0; + FormSetBuffer = NULL; + TempBuffer = NULL; + + // + // Get HII PackageList + // + PackageListSize = 0; + HiiPackageList = NULL; + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList); + if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) { + return Status; + } + + HiiPackageList = AllocatePool (PackageListSize); + if (HiiPackageList == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = gHiiDatabase->ExportPackageLists (gHiiDatabase, Handle, &PackageListSize, HiiPackageList); + ASSERT_EFI_ERROR (Status); + + // + // Get Form package from this HII package List + // + Status = EFI_NOT_FOUND; + Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength); + + while (Offset < PackageListLength) { + Package = ((UINT8 *) HiiPackageList) + Offset; + CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER)); + Offset += PackageHeader.Length; + + if (PackageHeader.Type != EFI_HII_PACKAGE_FORMS) { + continue; + } + + // + // Search FormSet Opcode in this Form Package + // + Offset2 = sizeof (EFI_HII_PACKAGE_HEADER); + while (Offset2 < PackageHeader.Length) { + OpCodeData = Package + Offset2; + Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length; + + if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode != EFI_IFR_FORM_SET_OP) { + continue; + } + + if (FormSetBuffer != NULL){ + TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, FormSetBuffer); + FreePool(FormSetBuffer); + FormSetBuffer = NULL; + if (TempBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + CopyMem (TempBuffer + TempSize, OpCodeData, ((EFI_IFR_OP_HEADER *) OpCodeData)->Length); + } else { + TempBuffer = AllocateCopyPool (TempSize + ((EFI_IFR_OP_HEADER *) OpCodeData)->Length, OpCodeData); + if (TempBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + } + TempSize += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length; + FormSetBuffer = TempBuffer; + + Status = EFI_SUCCESS; + // + //One form package has one formset, exit current form package to search other form package in the packagelist. + // + break; + } } +Done: + FreePool (HiiPackageList); + + *BufferSize = TempSize; + *Buffer = (EFI_IFR_FORM_SET *)FormSetBuffer; + + return Status; } /** 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. - If String is NULL, then ASSERT(). + If ConfigString is NULL, then ASSERT(). - @param[in] String Pointer to a Null-terminated Unicode string. + @param[in] ConfigString Pointer to a Null-terminated Unicode string. @return Pointer to the Null-terminated Unicode result string. @@ -469,10 +589,10 @@ InternalHiiBlockToConfig ( allocated using AllocatePool(). The caller is then responsible for freeing the buffer using FreePool(). - @param[in] VariableName Pointer to a Null-terminated Unicode string. This - is an optional parameter that may be NULL. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. + @param[in] VariableName Pointer to a Null-terminated Unicode string. This + is an optional parameter that may be NULL. @param[in] SetResultsData If not NULL, then this parameter specified the buffer of uncommited data to set. If this parameter is NULL, then the caller is requesting to get the uncommited data @@ -576,17 +696,17 @@ InternalHiiBrowserCallback ( @param[in] Guid Pointer to an EFI_GUID that is the routing information GUID. Each of the 16 bytes in Guid is converted to - a 2 Unicode character hexidecimal string. This is + a 2 Unicode character hexadecimal string. This is an optional parameter that may be NULL. @param[in] Name Pointer to a Null-terminated Unicode string that is the routing information NAME. This is an optional parameter that may be NULL. Each 16-bit Unicode character in Name is converted to a 4 character Unicode - hexidecimal string. + hexadecimal string. @param[in] DriverHandle The driver handle which supports a Device Path Protocol that is the routing information PATH. Each byte of the Device Path associated with DriverHandle is converted - to a 2 Unicode character hexidecimal string. + to a 2 Unicode character hexadecimal string. @retval NULL DriverHandle does not support the Device Path Protocol. @retval Other A pointer to the Null-terminate Unicode string @@ -607,6 +727,7 @@ HiiConstructConfigHdr ( CHAR16 *ReturnString; UINTN Index; UINT8 *Buffer; + UINTN MaxLen; // // Compute the length of Name in Unicode characters. @@ -637,7 +758,8 @@ HiiConstructConfigHdr ( // GUID=32&NAME=NameLength&PATH=DevicePathSize // | 5 | sizeof (EFI_GUID) * 2 | 6 | NameStrLen*4 | 6 | DevicePathSize * 2 | 1 | // - String = AllocateZeroPool ((5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1) * sizeof (CHAR16)); + MaxLen = 5 + sizeof (EFI_GUID) * 2 + 6 + NameLength * 4 + 6 + DevicePathSize * 2 + 1; + String = AllocateZeroPool (MaxLen * sizeof (CHAR16)); if (String == NULL) { return NULL; } @@ -645,7 +767,8 @@ HiiConstructConfigHdr ( // // Start with L"GUID=" // - ReturnString = StrCpy (String, L"GUID="); + StrCpyS (String, MaxLen, L"GUID="); + ReturnString = String; String += StrLen (String); if (Guid != NULL) { @@ -653,14 +776,21 @@ HiiConstructConfigHdr ( // Append Guid converted to 32 // for (Index = 0, Buffer = (UINT8 *)Guid; Index < sizeof (EFI_GUID); Index++) { - String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2); + UnicodeValueToStringS ( + String, + MaxLen * sizeof (CHAR16) - ((UINTN)String - (UINTN)ReturnString), + PREFIX_ZERO | RADIX_HEX, + *(Buffer++), + 2 + ); + String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16)); } } // // Append L"&NAME=" // - StrCpy (String, L"&NAME="); + StrCatS (ReturnString, MaxLen, L"&NAME="); String += StrLen (String); if (Name != NULL) { @@ -668,21 +798,35 @@ HiiConstructConfigHdr ( // Append Name converted to NameLength // for (; *Name != L'\0'; Name++) { - String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *Name, 4); + UnicodeValueToStringS ( + String, + sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString), + PREFIX_ZERO | RADIX_HEX, + *Name, + 4 + ); + String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16)); } } // // Append L"&PATH=" // - StrCpy (String, L"&PATH="); + StrCatS (ReturnString, MaxLen, L"&PATH="); String += StrLen (String); // // Append the device path associated with DriverHandle converted to DevicePathSize // for (Index = 0, Buffer = (UINT8 *)DevicePath; Index < DevicePathSize; Index++) { - String += UnicodeValueToString (String, PREFIX_ZERO | RADIX_HEX, *(Buffer++), 2); + UnicodeValueToStringS ( + String, + sizeof (CHAR16) * MaxLen - ((UINTN)String - (UINTN)ReturnString), + PREFIX_ZERO | RADIX_HEX, + *(Buffer++), + 2 + ); + String += StrnLenS (String, MaxLen - ((UINTN)String - (UINTN)ReturnString) / sizeof (CHAR16)); } // @@ -787,7 +931,7 @@ InternalHiiGetBufferFromString ( StringPtr = (CHAR16 *) DataBuffer; ZeroMem (TemStr, sizeof (TemStr)); for (Index = 0; Index < Length; Index += 4) { - StrnCpy (TemStr, ConfigHdr + Index, 4); + StrnCpyS (TemStr, sizeof (TemStr) / sizeof (CHAR16), ConfigHdr + Index, 4); StringPtr[Index/4] = (CHAR16) StrHexToUint64 (TemStr); } // @@ -800,7 +944,6 @@ InternalHiiGetBufferFromString ( default: return EFI_INVALID_PARAMETER; - break; } return EFI_SUCCESS; @@ -920,49 +1063,103 @@ InternalHiiGetValueOfNumber ( return EFI_SUCCESS; } +/** + Get value from config request resp string. + + @param ConfigElement ConfigResp string contains the current setting. + @param VarName The variable name which need to get value. + @param VarValue The return value. + + @retval EFI_SUCCESS Get the value for the VarName + @retval EFI_OUT_OF_RESOURCES The memory is not enough. +**/ +EFI_STATUS +GetValueFromRequest ( + IN CHAR16 *ConfigElement, + IN CHAR16 *VarName, + OUT UINT64 *VarValue + ) +{ + UINT8 *TmpBuffer; + CHAR16 *StringPtr; + UINTN Length; + EFI_STATUS Status; + + // + // Find VarName related string. + // + StringPtr = StrStr (ConfigElement, VarName); + ASSERT (StringPtr != NULL); + + // + // Skip the "VarName=" string + // + StringPtr += StrLen (VarName) + 1; + + // + // Get Offset + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + return Status; + } + + *VarValue = 0; + CopyMem (VarValue, TmpBuffer, (((Length + 1) / 2) < sizeof (UINT64)) ? ((Length + 1) / 2) : sizeof (UINT64)); + + FreePool (TmpBuffer); + + return EFI_SUCCESS; +} + /** This internal function parses IFR data to validate current setting. - @param ConfigResp ConfigResp string contains the current setting. + Base on the NameValueType, if it is TRUE, RequestElement and HiiHandle is valid; + else the VarBuffer and CurrentBlockArray is valid. + @param HiiPackageList Point to Hii package list. @param PackageListLength The length of the pacakge. @param VarGuid Guid of the buffer storage. @param VarName Name of the buffer storage. + @param VarBuffer The data buffer for the storage. + @param CurrentBlockArray The block array from the config Requst string. + @param RequestElement The config string for this storage. + @param HiiHandle The HiiHandle for this formset. + @param NameValueType Whether current storage is name/value varstore or not. @retval EFI_SUCCESS The current setting is valid. @retval EFI_OUT_OF_RESOURCES The memory is not enough. @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. **/ EFI_STATUS -EFIAPI -InternalHiiValidateCurrentSetting ( - IN EFI_STRING ConfigResp, +ValidateQuestionFromVfr ( IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList, IN UINTN PackageListLength, IN EFI_GUID *VarGuid, - IN CHAR16 *VarName + IN CHAR16 *VarName, + IN UINT8 *VarBuffer, + IN IFR_BLOCK_DATA *CurrentBlockArray, + IN CHAR16 *RequestElement, + IN EFI_HII_HANDLE HiiHandle, + IN BOOLEAN NameValueType ) -{ - IFR_BLOCK_DATA *CurrentBlockArray; - IFR_BLOCK_DATA *BlockData; - IFR_BLOCK_DATA *NewBlockData; +{ IFR_BLOCK_DATA VarBlockData; - EFI_STRING StringPtr; - UINTN Length; - UINT8 *TmpBuffer; UINT16 Offset; UINT16 Width; UINT64 VarValue; - LIST_ENTRY *Link; - UINT8 *VarBuffer; - UINTN MaxBufferSize; + EFI_IFR_TYPE_VALUE TmpValue; EFI_STATUS Status; - EFI_HII_PACKAGE_HEADER PacakgeHeader; + EFI_HII_PACKAGE_HEADER PackageHeader; UINT32 PackageOffset; UINT8 *PackageData; UINTN IfrOffset; EFI_IFR_OP_HEADER *IfrOpHdr; EFI_IFR_VARSTORE *IfrVarStore; + EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueStore; + EFI_IFR_VARSTORE_EFI *IfrEfiVarStore; + IFR_VARSTORAGE_DATA VarStoreData; EFI_IFR_ONE_OF *IfrOneOf; EFI_IFR_NUMERIC *IfrNumeric; EFI_IFR_ONE_OF_OPTION *IfrOneOfOption; @@ -970,255 +1167,114 @@ InternalHiiValidateCurrentSetting ( EFI_IFR_STRING *IfrString; CHAR8 *VarStoreName; UINTN Index; - - // - // 1. Get the current setting to current block data array and Convert them into VarBuffer - // + CHAR16 *QuestionName; + CHAR16 *StringPtr; - // - // Skip ConfigHdr string - // - StringPtr = ConfigResp; - StringPtr = StrStr (ConfigResp, L"&OFFSET"); - if (StringPtr == NULL) { - // - // No ConfigBlock value is requied to be validated. - // EFI_SUCCESS directly return. - // - return EFI_SUCCESS; - } - // // Initialize the local variables. // - Index = 0; - VarStoreName = NULL; - Status = EFI_SUCCESS; - BlockData = NULL; - NewBlockData = NULL; - TmpBuffer = NULL; - MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE; - VarBuffer = AllocateZeroPool (MaxBufferSize); - if (VarBuffer == NULL) { - return EFI_OUT_OF_RESOURCES; - } + Index = 0; + VarStoreName = NULL; + Status = EFI_SUCCESS; + VarValue = 0; + IfrVarStore = NULL; + IfrNameValueStore = NULL; + IfrEfiVarStore = NULL; + ZeroMem (&VarStoreData, sizeof (IFR_VARSTORAGE_DATA)); + ZeroMem (&VarBlockData, sizeof (VarBlockData)); // - // Init CurrentBlockArray - // - CurrentBlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); - if (CurrentBlockArray == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - InitializeListHead (&CurrentBlockArray->Entry); - - // - // Parse each if exists - // Only format is supported by this help function. - // ::= &'OFFSET='&'WIDTH=' + // Check IFR value is in block data, then Validate Value // - while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) { - // - // Skip the &OFFSET= string - // - StringPtr += StrLen (L"&OFFSET="); + PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); + while (PackageOffset < PackageListLength) { + CopyMem (&PackageHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PackageHeader)); // - // Get Offset + // Parse IFR opcode from the form package. // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - Offset = 0; - CopyMem ( - &Offset, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) - ); - FreePool (TmpBuffer); - TmpBuffer = NULL; + if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) { + IfrOffset = sizeof (PackageHeader); + PackageData = (UINT8 *) HiiPackageList + PackageOffset; + while (IfrOffset < PackageHeader.Length) { + IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset); + // + // Validate current setting to the value built in IFR opcode + // + switch (IfrOpHdr->OpCode) { + case EFI_IFR_VARSTORE_OP: + // + // VarStoreId has been found. No further found. + // + if (VarStoreData.VarStoreId != 0) { + break; + } + // + // Find the matched VarStoreId to the input VarGuid and VarName + // + IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr; + if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) { + VarStoreName = (CHAR8 *) IfrVarStore->Name; + for (Index = 0; VarStoreName[Index] != 0; Index ++) { + if ((CHAR16) VarStoreName[Index] != VarName[Index]) { + break; + } + } + // + // The matched VarStore is found. + // + if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) { + IfrVarStore = NULL; + } + } else { + IfrVarStore = NULL; + } - StringPtr += Length; - if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - StringPtr += StrLen (L"&WIDTH="); + if (IfrVarStore != NULL) { + VarStoreData.VarStoreId = IfrVarStore->VarStoreId; + VarStoreData.Size = IfrVarStore->Size; + } + break; + case EFI_IFR_VARSTORE_NAME_VALUE_OP: + // + // VarStoreId has been found. No further found. + // + if (VarStoreData.VarStoreId != 0) { + break; + } + // + // Find the matched VarStoreId to the input VarGuid + // + IfrNameValueStore = (EFI_IFR_VARSTORE_NAME_VALUE *) IfrOpHdr; + if (!CompareGuid ((EFI_GUID *) (VOID *) &IfrNameValueStore->Guid, VarGuid)) { + IfrNameValueStore = NULL; + } - // - // Get Width - // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - Width = 0; - CopyMem ( - &Width, - TmpBuffer, - (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) - ); - FreePool (TmpBuffer); - TmpBuffer = NULL; + if (IfrNameValueStore != NULL) { + VarStoreData.VarStoreId = IfrNameValueStore->VarStoreId; + } + break; + case EFI_IFR_VARSTORE_EFI_OP: + // + // VarStore is found. Don't need to search any more. + // + if (VarStoreData.VarStoreId != 0) { + break; + } - StringPtr += Length; - if (*StringPtr != 0 && *StringPtr != L'&') { - Status = EFI_INVALID_PARAMETER; - goto Done; - } + IfrEfiVarStore = (EFI_IFR_VARSTORE_EFI *) IfrOpHdr; - if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - StringPtr += StrLen (L"&VALUE="); + // + // If the length is small than the structure, this is from old efi + // varstore definition. Old efi varstore get config directly from + // GetVariable function. + // + if (IfrOpHdr->Length < sizeof (EFI_IFR_VARSTORE_EFI)) { + break; + } - // - // Get Value - // - Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); - if (EFI_ERROR (Status)) { - goto Done; - } - - StringPtr += Length; - if (*StringPtr != 0 && *StringPtr != L'&') { - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - // - // Check whether VarBuffer is enough - // - if ((UINTN) (Offset + Width) > MaxBufferSize) { - VarBuffer = ReallocatePool ( - MaxBufferSize, - Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE, - VarBuffer - ); - if (VarBuffer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE; - } - - // - // Update the Block with configuration info - // - CopyMem (VarBuffer + Offset, TmpBuffer, Width); - FreePool (TmpBuffer); - TmpBuffer = NULL; - - // - // Set new Block Data - // - NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); - if (NewBlockData == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Done; - } - NewBlockData->Offset = Offset; - NewBlockData->Width = Width; - - // - // Insert the new block data into the block data array. - // - for (Link = CurrentBlockArray->Entry.ForwardLink; Link != &CurrentBlockArray->Entry; Link = Link->ForwardLink) { - BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); - if (NewBlockData->Offset == BlockData->Offset) { - if (NewBlockData->Width > BlockData->Width) { - BlockData->Width = NewBlockData->Width; - } - FreePool (NewBlockData); - break; - } else if (NewBlockData->Offset < BlockData->Offset) { - // - // Insert new block data as the previous one of this link. - // - InsertTailList (Link, &NewBlockData->Entry); - break; - } - } - - // - // Insert new block data into the array tail. - // - if (Link == &CurrentBlockArray->Entry) { - InsertTailList (Link, &NewBlockData->Entry); - } - - // - // If '\0', parsing is finished. - // - if (*StringPtr == 0) { - break; - } - // - // Go to next ConfigBlock - // - } - - // - // Merge the aligned block data into the single block data. - // - Link = CurrentBlockArray->Entry.ForwardLink; - while ((Link != &CurrentBlockArray->Entry) && (Link->ForwardLink != &CurrentBlockArray->Entry)) { - BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); - NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); - if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { - if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { - BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); - } - RemoveEntryList (Link->ForwardLink); - FreePool (NewBlockData); - continue; - } - Link = Link->ForwardLink; - } - - if (IsListEmpty (&CurrentBlockArray->Entry)) { - Status = EFI_SUCCESS; - goto Done; - } - - // - // 2. Check IFR value is in block data, then Validate Vaule - // - ZeroMem (&VarBlockData, sizeof (VarBlockData)); - VarValue = 0; - IfrVarStore = NULL; - PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - while (PackageOffset < PackageListLength) { - CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader)); - - // - // Parse IFR opcode from the form package. - // - if (PacakgeHeader.Type == EFI_HII_PACKAGE_FORMS) { - IfrOffset = sizeof (PacakgeHeader); - PackageData = (UINT8 *) HiiPackageList + PackageOffset; - while (IfrOffset < PacakgeHeader.Length) { - IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset); - // - // Validate current setting to the value built in IFR opcode - // - switch (IfrOpHdr->OpCode) { - case EFI_IFR_VARSTORE_OP: - // - // VarStoreId has been found. No further found. - // - if (IfrVarStore != NULL) { - break; - } - // - // Find the matched VarStoreId to the input VarGuid and VarName - // - IfrVarStore = (EFI_IFR_VARSTORE *) IfrOpHdr; - if (CompareGuid ((EFI_GUID *) (VOID *) &IfrVarStore->Guid, VarGuid)) { - VarStoreName = (CHAR8 *) IfrVarStore->Name; + if (CompareGuid ((EFI_GUID *) (VOID *) &IfrEfiVarStore->Guid, VarGuid)) { + VarStoreName = (CHAR8 *) IfrEfiVarStore->Name; for (Index = 0; VarStoreName[Index] != 0; Index ++) { if ((CHAR16) VarStoreName[Index] != VarName[Index]) { break; @@ -1228,19 +1284,27 @@ InternalHiiValidateCurrentSetting ( // The matched VarStore is found. // if ((VarStoreName[Index] != 0) || (VarName[Index] != 0)) { - IfrVarStore = NULL; + IfrEfiVarStore = NULL; } } else { - IfrVarStore = NULL; + IfrEfiVarStore = NULL; + } + + if (IfrEfiVarStore != NULL) { + // + // Find the matched VarStore + // + VarStoreData.VarStoreId = IfrEfiVarStore->VarStoreId; + VarStoreData.Size = IfrEfiVarStore->Size; } break; case EFI_IFR_FORM_OP: + case EFI_IFR_FORM_MAP_OP: // // Check the matched VarStoreId is found. // - if (IfrVarStore == NULL) { - Status = EFI_SUCCESS; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_SUCCESS; } break; case EFI_IFR_ONE_OF_OP: @@ -1251,53 +1315,66 @@ InternalHiiValidateCurrentSetting ( // // OneOf question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrOneOf = (EFI_IFR_ONE_OF *) IfrOpHdr; - if (IfrOneOf->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrOneOf->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - - // - // Get Offset by Question header and Width by DataType Flags - // - Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrOneOf->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { // - // This question is not in the current configuration string. Skip it. + // Get Offset by Question header and Width by DataType Flags // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + Offset = IfrOneOf->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); // - // This question exceeds the var store size. + // Check whether this question is in current block array. // - Status = EFI_INVALID_PARAMETER; - goto Done; - } + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } - // - // Get the current value for oneof opcode - // - VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); + // + // Get the current value for oneof opcode + // + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); + } // // Set Block Data, to be checked in the following Oneof option opcode. // - VarBlockData.Offset = Offset; - VarBlockData.Width = Width; VarBlockData.OpCode = IfrOpHdr->OpCode; VarBlockData.Scope = IfrOpHdr->Scope; break; @@ -1309,87 +1386,134 @@ InternalHiiValidateCurrentSetting ( // // Numeric question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrNumeric = (EFI_IFR_NUMERIC *) IfrOpHdr; - if (IfrNumeric->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrNumeric->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - - // - // Get Offset by Question header and Width by DataType Flags - // - Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; - Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrNumeric->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { // - // This question is not in the current configuration string. Skip it. + // Get Offset by Question header and Width by DataType Flags // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + Offset = IfrNumeric->Question.VarStoreInfo.VarOffset; + Width = (UINT16) (1 << (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE)); // - // This question exceeds the var store size. + // Check whether this question is in current block array. // - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - // - // Check the current value is in the numeric range. - // - VarValue = 0; - CopyMem (&VarValue, VarBuffer + Offset, Width); - switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { - case EFI_IFR_NUMERIC_SIZE_1: - if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) { + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { // - // Not in the valid range. + // This question is not in the current configuration string. Skip it. // - Status = EFI_INVALID_PARAMETER; - goto Done; + break; } - break; - case EFI_IFR_NUMERIC_SIZE_2: - if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) { + // + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { // - // Not in the valid range. + // This question exceeds the var store size. // - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } - break; - case EFI_IFR_NUMERIC_SIZE_4: - if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) { - // - // Not in the valid range. - // - Status = EFI_INVALID_PARAMETER; - goto Done; + + // + // Check the current value is in the numeric range. + // + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); + } + if ((IfrNumeric->Flags & EFI_IFR_DISPLAY) == 0) { + switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + if ((INT8) VarValue < (INT8) IfrNumeric->data.u8.MinValue || (INT8) VarValue > (INT8) IfrNumeric->data.u8.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if ((INT16) VarValue < (INT16) IfrNumeric->data.u16.MinValue || (INT16) VarValue > (INT16) IfrNumeric->data.u16.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if ((INT32) VarValue < (INT32) IfrNumeric->data.u32.MinValue || (INT32) VarValue > (INT32) IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if ((INT64) VarValue < (INT64) IfrNumeric->data.u64.MinValue || (INT64) VarValue > (INT64) IfrNumeric->data.u64.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; } - break; - case EFI_IFR_NUMERIC_SIZE_8: - if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) { - // - // Not in the valid range. - // - Status = EFI_INVALID_PARAMETER; - goto Done; + } else { + switch (IfrNumeric->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + if ((UINT8) VarValue < IfrNumeric->data.u8.MinValue || (UINT8) VarValue > IfrNumeric->data.u8.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_2: + if ((UINT16) VarValue < IfrNumeric->data.u16.MinValue || (UINT16) VarValue > IfrNumeric->data.u16.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_4: + if ((UINT32) VarValue < IfrNumeric->data.u32.MinValue || (UINT32) VarValue > IfrNumeric->data.u32.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; + case EFI_IFR_NUMERIC_SIZE_8: + if ((UINT64) VarValue < IfrNumeric->data.u64.MinValue || (UINT64) VarValue > IfrNumeric->data.u64.MaxValue) { + // + // Not in the valid range. + // + return EFI_INVALID_PARAMETER; + } + break; } - break; } - break; case EFI_IFR_CHECKBOX_OP: // @@ -1399,52 +1523,69 @@ InternalHiiValidateCurrentSetting ( // // CheckBox question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrCheckBox = (EFI_IFR_CHECKBOX *) IfrOpHdr; - if (IfrCheckBox->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrCheckBox->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - - // - // Get Offset by Question header - // - Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; - Width = sizeof (BOOLEAN); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrCheckBox->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + if (StrStr (RequestElement, QuestionName) == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + + Status = GetValueFromRequest (RequestElement, QuestionName, &VarValue); + if (EFI_ERROR (Status)) { + return Status; + } + } else { // - // This question is not in the current configuration string. Skip it. + // Get Offset by Question header // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + Offset = IfrCheckBox->Question.VarStoreInfo.VarOffset; + Width = (UINT16) sizeof (BOOLEAN); + // + // Check whether this question is in current block array. + // + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage // - // This question exceeds the var store size. + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } + // + // Check the current value is in the numeric range. // - Status = EFI_INVALID_PARAMETER; - goto Done; + VarValue = 0; + CopyMem (&VarValue, VarBuffer + Offset, Width); } - // // Boolean type, only 1 and 0 is valid. // - if (*(VarBuffer + Offset) > 1) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarValue > 1) { + return EFI_INVALID_PARAMETER; } - break; case EFI_IFR_STRING_OP: // @@ -1454,50 +1595,74 @@ InternalHiiValidateCurrentSetting ( // // CheckBox question is not in IFR Form. This IFR form is not valid. // - if (IfrVarStore == NULL) { - Status = EFI_INVALID_PARAMETER; - goto Done; + if (VarStoreData.VarStoreId == 0) { + return EFI_INVALID_PARAMETER; } // // Check whether this question is for the requested varstore. // IfrString = (EFI_IFR_STRING *) IfrOpHdr; - if (IfrString->Question.VarStoreId != IfrVarStore->VarStoreId) { + if (IfrString->Question.VarStoreId != VarStoreData.VarStoreId) { break; } - // - // Get Offset/Width by Question header and OneOf Flags + // Get Width by OneOf Flags // - Offset = IfrString->Question.VarStoreInfo.VarOffset; Width = (UINT16) (IfrString->MaxSize * sizeof (UINT16)); - // - // Check whether this question is in current block array. - // - if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + if (NameValueType) { + QuestionName = HiiGetString (HiiHandle, IfrString->Question.VarStoreInfo.VarName, NULL); + ASSERT (QuestionName != NULL); + + StringPtr = StrStr (RequestElement, QuestionName); + if (StringPtr == NULL) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // - // This question is not in the current configuration string. Skip it. + // Skip the "=". + // + StringPtr += 1; + // - break; - } - // - // Check this var question is in the var storage - // - if ((Offset + Width) > IfrVarStore->Size) { + // Check current string length is less than maxsize // - // This question exceeds the var store size. + if (StrSize (StringPtr) > Width) { + return EFI_INVALID_PARAMETER; + } + } else { // - Status = EFI_INVALID_PARAMETER; - goto Done; - } - - // - // Check current string length is less than maxsize - // - if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) { - Status = EFI_INVALID_PARAMETER; - goto Done; + // Get Offset/Width by Question header and OneOf Flags + // + Offset = IfrString->Question.VarStoreInfo.VarOffset; + // + // Check whether this question is in current block array. + // + if (!BlockArrayCheck (CurrentBlockArray, Offset, Width)) { + // + // This question is not in the current configuration string. Skip it. + // + break; + } + // + // Check this var question is in the var storage + // + if ((Offset + Width) > VarStoreData.Size) { + // + // This question exceeds the var store size. + // + return EFI_INVALID_PARAMETER; + } + + // + // Check current string length is less than maxsize + // + if (StrSize ((CHAR16 *) (VarBuffer + Offset)) > Width) { + return EFI_INVALID_PARAMETER; + } } break; case EFI_IFR_ONE_OF_OPTION_OP: @@ -1516,7 +1681,10 @@ InternalHiiValidateCurrentSetting ( // // Check current value is the value of one of option. // - if (VarValue == IfrOneOfOption->Value.u64) { + ASSERT (IfrOneOfOption->Type <= EFI_IFR_TYPE_NUM_SIZE_64); + ZeroMem (&TmpValue, sizeof (EFI_IFR_TYPE_VALUE)); + CopyMem (&TmpValue, &IfrOneOfOption->Value, IfrOneOfOption->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value)); + if (VarValue == TmpValue.u64) { // // The value is one of option value. // Set OpCode to Zero, don't need check again. @@ -1524,7 +1692,6 @@ InternalHiiValidateCurrentSetting ( VarBlockData.OpCode = 0; } } - break; case EFI_IFR_END_OP: // @@ -1538,8 +1705,7 @@ InternalHiiValidateCurrentSetting ( // OneOf value doesn't belong to one of option value. // if ((VarBlockData.Scope == 0) && (VarBlockData.OpCode == EFI_IFR_ONE_OF_OP)) { - Status = EFI_INVALID_PARAMETER; - goto Done; + return EFI_INVALID_PARAMETER; } break; default: @@ -1561,14 +1727,339 @@ InternalHiiValidateCurrentSetting ( // break; } - - // - // Go to next package. - // - PackageOffset += PacakgeHeader.Length; + + // + // Go to next package. + // + PackageOffset += PackageHeader.Length; + } + + return EFI_SUCCESS; +} + +/** + This internal function parses IFR data to validate current setting. + + @param ConfigElement ConfigResp element string contains the current setting. + @param CurrentBlockArray Current block array. + @param VarBuffer Data buffer for this varstore. + + @retval EFI_SUCCESS The current setting is valid. + @retval EFI_OUT_OF_RESOURCES The memory is not enough. + @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. +**/ +EFI_STATUS +GetBlockDataInfo ( + IN CHAR16 *ConfigElement, + OUT IFR_BLOCK_DATA **CurrentBlockArray, + OUT UINT8 **VarBuffer + ) +{ + IFR_BLOCK_DATA *BlockData; + IFR_BLOCK_DATA *NewBlockData; + EFI_STRING StringPtr; + UINTN Length; + UINT8 *TmpBuffer; + UINT16 Offset; + UINT16 Width; + LIST_ENTRY *Link; + UINTN MaxBufferSize; + EFI_STATUS Status; + IFR_BLOCK_DATA *BlockArray; + UINT8 *DataBuffer; + + // + // Initialize the local variables. + // + Status = EFI_SUCCESS; + BlockData = NULL; + NewBlockData = NULL; + TmpBuffer = NULL; + BlockArray = NULL; + MaxBufferSize = HII_LIB_DEFAULT_VARSTORE_SIZE; + DataBuffer = AllocateZeroPool (MaxBufferSize); + if (DataBuffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Init BlockArray + // + BlockArray = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); + if (BlockArray == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + InitializeListHead (&BlockArray->Entry); + + StringPtr = StrStr (ConfigElement, L"&OFFSET="); + ASSERT (StringPtr != NULL); + + // + // Parse each if exists + // Only format is supported by this help function. + // ::= &'OFFSET='&'WIDTH=' + // + while (*StringPtr != 0 && StrnCmp (StringPtr, L"&OFFSET=", StrLen (L"&OFFSET=")) == 0) { + // + // Skip the &OFFSET= string + // + StringPtr += StrLen (L"&OFFSET="); + + // + // Get Offset + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + Offset = 0; + CopyMem ( + &Offset, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) + ); + FreePool (TmpBuffer); + TmpBuffer = NULL; + + StringPtr += Length; + if (StrnCmp (StringPtr, L"&WIDTH=", StrLen (L"&WIDTH=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&WIDTH="); + + // + // Get Width + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + Width = 0; + CopyMem ( + &Width, + TmpBuffer, + (((Length + 1) / 2) < sizeof (UINT16)) ? ((Length + 1) / 2) : sizeof (UINT16) + ); + FreePool (TmpBuffer); + TmpBuffer = NULL; + + StringPtr += Length; + if (*StringPtr != 0 && *StringPtr != L'&') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + if (StrnCmp (StringPtr, L"&VALUE=", StrLen (L"&VALUE=")) != 0) { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + StringPtr += StrLen (L"&VALUE="); + + // + // Get Value + // + Status = InternalHiiGetValueOfNumber (StringPtr, &TmpBuffer, &Length); + if (EFI_ERROR (Status)) { + goto Done; + } + + StringPtr += Length; + if (*StringPtr != 0 && *StringPtr != L'&') { + Status = EFI_INVALID_PARAMETER; + goto Done; + } + + // + // Check whether VarBuffer is enough + // + if ((UINTN) (Offset + Width) > MaxBufferSize) { + DataBuffer = ReallocatePool ( + MaxBufferSize, + Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE, + DataBuffer + ); + if (DataBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + MaxBufferSize = Offset + Width + HII_LIB_DEFAULT_VARSTORE_SIZE; + } + + // + // Update the Block with configuration info + // + CopyMem (DataBuffer + Offset, TmpBuffer, Width); + FreePool (TmpBuffer); + TmpBuffer = NULL; + + // + // Set new Block Data + // + NewBlockData = (IFR_BLOCK_DATA *) AllocateZeroPool (sizeof (IFR_BLOCK_DATA)); + if (NewBlockData == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; + } + NewBlockData->Offset = Offset; + NewBlockData->Width = Width; + + // + // Insert the new block data into the block data array. + // + for (Link = BlockArray->Entry.ForwardLink; Link != &BlockArray->Entry; Link = Link->ForwardLink) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + if (NewBlockData->Offset == BlockData->Offset) { + if (NewBlockData->Width > BlockData->Width) { + BlockData->Width = NewBlockData->Width; + } + FreePool (NewBlockData); + break; + } else if (NewBlockData->Offset < BlockData->Offset) { + // + // Insert new block data as the previous one of this link. + // + InsertTailList (Link, &NewBlockData->Entry); + break; + } + } + + // + // Insert new block data into the array tail. + // + if (Link == &BlockArray->Entry) { + InsertTailList (Link, &NewBlockData->Entry); + } + + // + // If '\0', parsing is finished. + // + if (*StringPtr == 0) { + break; + } + // + // Go to next ConfigBlock + // + } + + // + // Merge the aligned block data into the single block data. + // + Link = BlockArray->Entry.ForwardLink; + while ((Link != &BlockArray->Entry) && (Link->ForwardLink != &BlockArray->Entry)) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + NewBlockData = BASE_CR (Link->ForwardLink, IFR_BLOCK_DATA, Entry); + if ((NewBlockData->Offset >= BlockData->Offset) && (NewBlockData->Offset <= (BlockData->Offset + BlockData->Width))) { + if ((NewBlockData->Offset + NewBlockData->Width) > (BlockData->Offset + BlockData->Width)) { + BlockData->Width = (UINT16) (NewBlockData->Offset + NewBlockData->Width - BlockData->Offset); + } + RemoveEntryList (Link->ForwardLink); + FreePool (NewBlockData); + continue; + } + Link = Link->ForwardLink; + } + + *VarBuffer = DataBuffer; + *CurrentBlockArray = BlockArray; + return EFI_SUCCESS; + +Done: + if (DataBuffer != NULL) { + FreePool (DataBuffer); + } + + if (BlockArray != NULL) { + // + // Free Link Array CurrentBlockArray + // + while (!IsListEmpty (&BlockArray->Entry)) { + BlockData = BASE_CR (BlockArray->Entry.ForwardLink, IFR_BLOCK_DATA, Entry); + RemoveEntryList (&BlockData->Entry); + FreePool (BlockData); + } + FreePool (BlockArray); + } + + return Status; +} + +/** + This internal function parses IFR data to validate current setting. + + @param ConfigResp ConfigResp string contains the current setting. + @param HiiPackageList Point to Hii package list. + @param PackageListLength The length of the pacakge. + @param VarGuid Guid of the buffer storage. + @param VarName Name of the buffer storage. + @param HiiHandle The HiiHandle for this package. + + @retval EFI_SUCCESS The current setting is valid. + @retval EFI_OUT_OF_RESOURCES The memory is not enough. + @retval EFI_INVALID_PARAMETER The config string or the Hii package is invalid. +**/ +EFI_STATUS +EFIAPI +InternalHiiValidateCurrentSetting ( + IN EFI_STRING ConfigResp, + IN EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList, + IN UINTN PackageListLength, + IN EFI_GUID *VarGuid, + IN CHAR16 *VarName, + IN EFI_HII_HANDLE HiiHandle + ) +{ + CHAR16 *StringPtr; + EFI_STATUS Status; + IFR_BLOCK_DATA *CurrentBlockArray; + IFR_BLOCK_DATA *BlockData; + UINT8 *VarBuffer; + BOOLEAN NameValueType; + + CurrentBlockArray = NULL; + VarBuffer = NULL; + StringPtr = NULL; + Status = EFI_SUCCESS; + + // + // If StringPtr != NULL, get the request elements. + // + if (StrStr (ConfigResp, L"&OFFSET=") != NULL) { + Status = GetBlockDataInfo(ConfigResp, &CurrentBlockArray, &VarBuffer); + if (EFI_ERROR (Status)) { + return Status; + } + NameValueType = FALSE; + } else { + // + // Skip header part. + // + StringPtr = StrStr (ConfigResp, L"PATH="); + ASSERT (StringPtr != NULL); + + if (StrStr (StringPtr, L"&") != NULL) { + NameValueType = TRUE; + } else { + // + // Not found Request element, return success. + // + return EFI_SUCCESS; + } } -Done: + Status = ValidateQuestionFromVfr( + HiiPackageList, + PackageListLength, + VarGuid, + VarName, + VarBuffer, + CurrentBlockArray, + ConfigResp, + HiiHandle, + NameValueType + ); + if (VarBuffer != NULL) { FreePool (VarBuffer); } @@ -1582,12 +2073,40 @@ Done: RemoveEntryList (&BlockData->Entry); FreePool (BlockData); } - FreePool (CurrentBlockArray); + FreePool (CurrentBlockArray); } return Status; } +/** + Check whether the ConfigRequest string has the request elements. + For EFI_HII_VARSTORE_BUFFER type, the request has "&OFFSET=****&WIDTH=****..." format. + For EFI_HII_VARSTORE_NAME_VALUE type, the request has "&NAME1**&NAME2..." format. + + @param ConfigRequest The input config request string. + + @retval TRUE The input include config request elements. + @retval FALSE The input string not includes. + +**/ +BOOLEAN +GetElementsFromRequest ( + IN EFI_STRING ConfigRequest + ) +{ + EFI_STRING TmpRequest; + + TmpRequest = StrStr (ConfigRequest, L"PATH="); + ASSERT (TmpRequest != NULL); + + if ((StrStr (TmpRequest, L"&OFFSET=") != NULL) || (StrStr (TmpRequest, L"&") != NULL)) { + return TRUE; + } + + return FALSE; +} + /** This function parses the input ConfigRequest string and its matched IFR code string for setting default value and validating current setting. @@ -1609,7 +2128,7 @@ Done: @param DefaultId Specifies the type of defaults to retrieve only for setting default action. @param ActionType Action supports setting defaults and validate current setting. - @retval TURE Action runs successfully. + @retval TRUE Action runs successfully. @retval FALSE Action is not valid or Action can't be executed successfully.. **/ BOOLEAN @@ -1634,18 +2153,13 @@ InternalHiiIfrValueAction ( UINT32 Index; EFI_GUID *VarGuid; EFI_STRING VarName; - EFI_STRING_ID DefaultName; - UINT8 *PackageData; - UINTN IfrOffset; - EFI_IFR_OP_HEADER *IfrOpHdr; EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; - UINT32 PackageOffset; UINTN PackageListLength; - EFI_HII_PACKAGE_HEADER PacakgeHeader; + UINTN MaxLen; EFI_DEVICE_PATH_PROTOCOL *DevicePath; EFI_DEVICE_PATH_PROTOCOL *TempDevicePath; - + ConfigAltResp = NULL; ConfigResp = NULL; VarGuid = NULL; @@ -1656,7 +2170,6 @@ InternalHiiIfrValueAction ( Index = 0; TempDriverHandle = NULL; HiiHandle = NULL; - PackageData = NULL; HiiPackageList = NULL; // @@ -1774,16 +2287,12 @@ InternalHiiIfrValueAction ( // Its default value and validating can't execute by parsing IFR data. // Directly jump into the next ConfigAltResp string for another pair Guid, Name, and Path. // - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; goto NextConfigAltResp; } - - // - // 2. Get DefaultName string ID by parsing the PacakgeList - // // - // Get HiiPackage by HiiHandle + // 2. Get HiiPackage by HiiHandle // PackageListLength = 0; HiiPackageList = NULL; @@ -1811,59 +2320,9 @@ InternalHiiIfrValueAction ( goto Done; } - // - // Parse the form package and get the default name string ID. - // - if (ActionType == ACTION_SET_DEFAUTL_VALUE) { - PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); - Status = EFI_NOT_FOUND; - while (PackageOffset < PackageListLength) { - CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader)); - - // - // Parse IFR opcode to get default store opcode - // - if (PacakgeHeader.Type == EFI_HII_PACKAGE_FORMS) { - IfrOffset = sizeof (PacakgeHeader); - PackageData = (UINT8 *) HiiPackageList + PackageOffset; - while (IfrOffset < PacakgeHeader.Length) { - IfrOpHdr = (EFI_IFR_OP_HEADER *) (PackageData + IfrOffset); - // - // Match DefaultId to find its DefaultName - // - if (IfrOpHdr->OpCode == EFI_IFR_DEFAULTSTORE_OP) { - if (((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId == DefaultId) { - DefaultName = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultName; - Status = EFI_SUCCESS; - break; - } - } - IfrOffset += IfrOpHdr->Length; - } - // - // Only one form is in a package list. - // - break; - } - - // - // Go to next package. - // - PackageOffset += PacakgeHeader.Length; - } - - // - // Not found the matched default string ID - // - if (EFI_ERROR (Status)) { - Status = EFI_SUCCESS; - goto NextConfigAltResp; - } - } - // // 3. Call ConfigRouting GetAltCfg(ConfigRoute, , Guid, Name, DevicePath, AltCfgId, AltCfgResp) - // Get the default configuration string according to the found defaultname string ID. + // Get the default configuration string according to the default ID. // Status = gHiiConfigRouting->GetAltConfig ( gHiiConfigRouting, @@ -1871,7 +2330,7 @@ InternalHiiIfrValueAction ( VarGuid, VarName, DevicePath, - (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultName:NULL, // it can be NULL to get the current setting. + (ActionType == ACTION_SET_DEFAUTL_VALUE) ? &DefaultId:NULL, // it can be NULL to get the current setting. &ConfigResp ); @@ -1885,7 +2344,7 @@ InternalHiiIfrValueAction ( // // Only the ConfigHdr is found. Not any block data is found. No data is required to be validated and set. // - if (StrStr (ConfigResp, L"&OFFSET=") == NULL) { + if (!GetElementsFromRequest (ConfigResp)) { goto NextConfigAltResp; } @@ -1902,7 +2361,7 @@ InternalHiiIfrValueAction ( // // Current Setting is in ConfigResp, will be set into buffer, then check it again. // - Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName); + Status = InternalHiiValidateCurrentSetting (ConfigResp, HiiPackageList, PackageListLength, VarGuid, VarName, HiiHandle); } if (EFI_ERROR (Status)) { @@ -1918,10 +2377,10 @@ NextConfigAltResp: HiiPackageList = NULL; } - if (ConfigResp != NULL) { - FreePool (ConfigResp); - ConfigResp = NULL; - } + if (ConfigResp != NULL) { + FreePool (ConfigResp); + ConfigResp = NULL; + } // // Free the allocated buffer. @@ -1953,14 +2412,15 @@ NextConfigAltResp: // Construct ConfigAltHdr string "&&ALTCFG=\0" // | 1 | StrLen (ConfigHdr) | 8 | 1 | // - ConfigAltHdr = AllocateZeroPool ((1 + StringPtr - StringHdr + 8 + 1) * sizeof (CHAR16)); + MaxLen = 1 + StringPtr - StringHdr + 8 + 1; + ConfigAltHdr = AllocateZeroPool ( MaxLen * sizeof (CHAR16)); if (ConfigAltHdr == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; } - StrCpy (ConfigAltHdr, L"&"); - StrnCat (ConfigAltHdr, StringHdr, StringPtr - StringHdr); - StrCat (ConfigAltHdr, L"&ALTCFG="); + StrCpyS (ConfigAltHdr, MaxLen, L"&"); + StrnCatS (ConfigAltHdr, MaxLen, StringHdr, StringPtr - StringHdr); + StrCatS (ConfigAltHdr, MaxLen, L"&ALTCFG="); // // Skip all AltResp (AltConfigHdr ConfigBody) for the same ConfigHdr @@ -2029,7 +2489,7 @@ Done: /** Validate the current configuration by parsing HII form IFR opcode. - NULL request string support depends on the ExtractConfig interface of + NULL request string support depends on the ExportConfig interface of HiiConfigRouting protocol in UEFI specification. @param Request A null-terminated Unicode string in @@ -2037,7 +2497,7 @@ Done: If it is NULL, all current configuration for the entirety of the current HII database will be validated. - @retval TURE Current configuration is valid. + @retval TRUE Current configuration is valid. @retval FALSE Current configuration is invalid. **/ BOOLEAN @@ -2062,7 +2522,7 @@ HiiValidateSettings ( entirety of the current HII database will be reset. @param DefaultId Specifies the type of defaults to retrieve. - @retval TURE The default value is set successfully. + @retval TRUE The default value is set successfully. @retval FALSE The default value can't be found and set. **/ BOOLEAN @@ -2093,7 +2553,7 @@ HiiSetToDefaults ( @param StartSearchString Pointer to the Null-terminated Unicode string that marks the start of the value string to compare. @param StopSearchString Pointer to the Null-terminated Unicode string that - marks the end of the vakue string to compare. + marks the end of the value string to compare. @retval FALSE StartSearchString is not present in FirstString. @retval FALSE StartSearchString is not present in SecondString. @@ -2209,15 +2669,15 @@ HiiIsConfigHdrMatch ( } /** - Retrieves uncommited data from the Form Browser and converts it to a binary + Retrieves uncommitted data from the Form Browser and converts it to a binary buffer. - @param[in] VariableName Pointer to a Null-terminated Unicode string. This - is an optional parameter that may be NULL. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. - @param[in] BufferSize Length in bytes of buffer to hold retrived data. - @param[out] Block Buffer of data to be updated. + @param[in] VariableName Pointer to a Null-terminated Unicode string. This + is an optional parameter that may be NULL. + @param[in] BufferSize Length in bytes of buffer to hold retrieved data. + @param[out] Buffer Buffer of data to be updated. @retval FALSE The uncommitted data could not be retrieved. @retval TRUE The uncommitted data was retrieved. @@ -2228,8 +2688,8 @@ EFIAPI HiiGetBrowserData ( IN CONST EFI_GUID *VariableGuid, OPTIONAL IN CONST CHAR16 *VariableName, OPTIONAL - IN UINTN BlockSize, - OUT UINT8 *Block + IN UINTN BufferSize, + OUT UINT8 *Buffer ) { EFI_STRING ResultsData; @@ -2268,8 +2728,8 @@ HiiGetBrowserData ( Status = gHiiConfigRouting->ConfigToBlock ( gHiiConfigRouting, ConfigResp, - Block, - &BlockSize, + Buffer, + &BufferSize, &Progress ); // @@ -2289,10 +2749,10 @@ HiiGetBrowserData ( If Buffer is NULL, then ASSERT(). - @param[in] VariableName Pointer to a Null-terminated Unicode string. This - is an optional parameter that may be NULL. @param[in] VariableGuid Pointer to an EFI_GUID structure. This is an optional parameter that may be NULL. + @param[in] VariableName Pointer to a Null-terminated Unicode string. This + is an optional parameter that may be NULL. @param[in] BufferSize Length, in bytes, of Buffer. @param[in] Buffer Buffer of data to commit. @param[in] RequestElement An optional field to specify which part of the @@ -2424,12 +2884,14 @@ HiiAllocateOpCodeHandle ( } /** - Frees an OpCode Handle that was peviously allocated with HiiAllocateOpCodeHandle(). + Frees an OpCode Handle that was previously allocated with HiiAllocateOpCodeHandle(). When an OpCode Handle is freed, all of the opcodes associated with the OpCode Handle are also freed. If OpCodeHandle is NULL, then ASSERT(). + @param[in] OpCodeHandle Handle to the buffer of opcodes. + **/ VOID EFIAPI @@ -2448,6 +2910,13 @@ HiiFreeOpCodeHandle ( FreePool (OpCodeBuffer); } +/** + Internal function gets the current position of opcode buffer. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + + @return Current position of opcode buffer. +**/ UINTN EFIAPI InternalHiiOpCodeHandlePosition ( @@ -2457,6 +2926,13 @@ InternalHiiOpCodeHandlePosition ( return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Position; } +/** + Internal function gets the start pointer of opcode buffer. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + + @return Pointer to the opcode buffer base. +**/ UINT8 * EFIAPI InternalHiiOpCodeHandleBuffer ( @@ -2466,11 +2942,20 @@ InternalHiiOpCodeHandleBuffer ( return ((HII_LIB_OPCODE_BUFFER *)OpCodeHandle)->Buffer; } +/** + Internal function reserves the enough buffer for current opcode. + When the buffer is not enough, Opcode buffer will be extended. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] Size Size of current opcode. + + @return Pointer to the current opcode. +**/ UINT8 * EFIAPI InternalHiiGrowOpCodeHandle ( - VOID *OpCodeHandle, - UINTN Size + IN VOID *OpCodeHandle, + IN UINTN Size ) { HII_LIB_OPCODE_BUFFER *OpCodeBuffer; @@ -2485,9 +2970,7 @@ InternalHiiGrowOpCodeHandle ( OpCodeBuffer->BufferSize + (Size + HII_LIB_OPCODE_ALLOCATION_SIZE), OpCodeBuffer->Buffer ); - if (Buffer == NULL) { - return NULL; - } + ASSERT (Buffer != NULL); OpCodeBuffer->Buffer = Buffer; OpCodeBuffer->BufferSize += (Size + HII_LIB_OPCODE_ALLOCATION_SIZE); } @@ -2496,6 +2979,18 @@ InternalHiiGrowOpCodeHandle ( return Buffer; } +/** + Internal function creates opcode based on the template opcode. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] OpCodeTemplate Pointer to the template buffer of opcode. + @param[in] OpCode OpCode IFR value. + @param[in] OpCodeSize Size of opcode. + @param[in] ExtensionSize Size of extended opcode. + @param[in] Scope Scope bit of opcode. + + @return Pointer to the current opcode with opcode data. +**/ UINT8 * EFIAPI InternalHiiCreateOpCodeExtended ( @@ -2521,6 +3016,16 @@ InternalHiiCreateOpCodeExtended ( return (UINT8 *)CopyMem (Buffer, Header, OpCodeSize); } +/** + Internal function creates opcode based on the template opcode for the normal opcode. + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] OpCodeTemplate Pointer to the template buffer of opcode. + @param[in] OpCode OpCode IFR value. + @param[in] OpCodeSize Size of opcode. + + @return Pointer to the current opcode with opcode data. +**/ UINT8 * EFIAPI InternalHiiCreateOpCode ( @@ -2650,7 +3155,7 @@ HiiCreateOneOfOptionOpCode ( OpCode.Type = Type; CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]); - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OPTION_OP, OFFSET_OF(EFI_IFR_ONE_OF_OPTION, Value) + mHiiDefaultTypeToWidth[Type]); } /** @@ -2686,7 +3191,7 @@ HiiCreateDefaultOpCode ( OpCode.DefaultId = DefaultId; CopyMem (&OpCode.Value, &Value, mHiiDefaultTypeToWidth[Type]); - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DEFAULT_OP, OFFSET_OF(EFI_IFR_DEFAULT, Value) + mHiiDefaultTypeToWidth[Type]); } /** @@ -2774,7 +3279,7 @@ HiiCreateActionOpCode ( { EFI_IFR_ACTION OpCode; - ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.QuestionId = QuestionId; @@ -2864,7 +3369,7 @@ HiiCreateGotoOpCode ( { EFI_IFR_REF OpCode; - ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.Header.Prompt = Prompt; @@ -2876,6 +3381,82 @@ HiiCreateGotoOpCode ( return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, sizeof (OpCode)); } +/** + Create EFI_IFR_REF_OP, EFI_IFR_REF2_OP, EFI_IFR_REF3_OP and EFI_IFR_REF4_OP opcode. + + When RefDevicePath is not zero, EFI_IFR_REF4 opcode will be created. + When RefDevicePath is zero and RefFormSetId is not NULL, EFI_IFR_REF3 opcode will be created. + When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is not zero, EFI_IFR_REF2 opcode will be created. + When RefDevicePath is zero, RefFormSetId is NULL and RefQuestionId is zero, EFI_IFR_REF opcode will be created. + + If OpCodeHandle is NULL, then ASSERT(). + If any reserved bits are set in QuestionFlags, then ASSERT(). + + @param[in] OpCodeHandle The handle to the buffer of opcodes. + @param[in] RefFormId The Destination Form ID. + @param[in] Prompt The string ID for Prompt. + @param[in] Help The string ID for Help. + @param[in] QuestionFlags The flags in Question Header + @param[in] QuestionId Question ID. + @param[in] RefQuestionId The question on the form to which this link is referring. + If its value is zero, then the link refers to the top of the form. + @param[in] RefFormSetId The form set to which this link is referring. If its value is NULL, and RefDevicePath is + zero, then the link is to the current form set. + @param[in] RefDevicePath The string identifier that specifies the string containing the text representation of + the device path to which the form set containing the form specified by FormId. + If its value is zero, then the link refers to the current page. + + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the created opcode. + +**/ +UINT8 * +EFIAPI +HiiCreateGotoExOpCode ( + IN VOID *OpCodeHandle, + IN EFI_FORM_ID RefFormId, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN EFI_QUESTION_ID QuestionId, + IN EFI_QUESTION_ID RefQuestionId, + IN EFI_GUID *RefFormSetId, OPTIONAL + IN EFI_STRING_ID RefDevicePath + ) +{ + EFI_IFR_REF4 OpCode; + UINTN OpCodeSize; + + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + + ZeroMem (&OpCode, sizeof (OpCode)); + OpCode.Question.Header.Prompt = Prompt; + OpCode.Question.Header.Help = Help; + OpCode.Question.QuestionId = QuestionId; + OpCode.Question.Flags = QuestionFlags; + OpCode.FormId = RefFormId; + OpCode.QuestionId = RefQuestionId; + OpCode.DevicePath = RefDevicePath; + if (RefFormSetId != NULL) { + CopyMem (&OpCode.FormSetId, RefFormSetId, sizeof (OpCode.FormSetId)); + } + + // + // Cacluate OpCodeSize based on the input Ref value. + // Try to use the small OpCode to save size. + // + OpCodeSize = sizeof (EFI_IFR_REF); + if (RefDevicePath != 0) { + OpCodeSize = sizeof (EFI_IFR_REF4); + } else if (RefFormSetId != NULL) { + OpCodeSize = sizeof (EFI_IFR_REF3); + } else if (RefQuestionId != 0) { + OpCodeSize = sizeof (EFI_IFR_REF2); + } + + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_REF_OP, OpCodeSize); +} + /** Create EFI_IFR_CHECKBOX_OP opcode. @@ -2886,7 +3467,8 @@ HiiCreateGotoOpCode ( @param[in] OpCodeHandle Handle to the buffer of opcodes. @param[in] QuestionId Question ID @param[in] VarStoreId Storage ID - @param[in] VarOffset Offset in Storage + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair. @param[in] Prompt String ID for Prompt @param[in] Help String ID for Help @param[in] QuestionFlags Flags in Question Header @@ -2915,7 +3497,7 @@ HiiCreateCheckBoxOpCode ( EFI_IFR_CHECKBOX OpCode; UINTN Position; - ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.QuestionId = QuestionId; @@ -2947,7 +3529,8 @@ HiiCreateCheckBoxOpCode ( @param[in] OpCodeHandle Handle to the buffer of opcodes. @param[in] QuestionId Question ID @param[in] VarStoreId Storage ID - @param[in] VarOffset Offset in Storage + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair. @param[in] Prompt String ID for Prompt @param[in] Help String ID for Help @param[in] QuestionFlags Flags in Question Header @@ -2981,9 +3564,11 @@ HiiCreateNumericOpCode ( { EFI_IFR_NUMERIC OpCode; UINTN Position; + UINTN Length; - ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + Length = 0; ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.QuestionId = QuestionId; OpCode.Question.VarStoreId = VarStoreId; @@ -2998,33 +3583,39 @@ HiiCreateNumericOpCode ( OpCode.data.u8.MinValue = (UINT8)Minimum; OpCode.data.u8.MaxValue = (UINT8)Maximum; OpCode.data.u8.Step = (UINT8)Step; + Length = 3; break; case EFI_IFR_NUMERIC_SIZE_2: OpCode.data.u16.MinValue = (UINT16)Minimum; OpCode.data.u16.MaxValue = (UINT16)Maximum; OpCode.data.u16.Step = (UINT16)Step; + Length = 6; break; case EFI_IFR_NUMERIC_SIZE_4: OpCode.data.u32.MinValue = (UINT32)Minimum; OpCode.data.u32.MaxValue = (UINT32)Maximum; OpCode.data.u32.Step = (UINT32)Step; + Length = 12; break; case EFI_IFR_NUMERIC_SIZE_8: OpCode.data.u64.MinValue = Minimum; OpCode.data.u64.MaxValue = Maximum; OpCode.data.u64.Step = Step; + Length = 24; break; } + Length += OFFSET_OF (EFI_IFR_NUMERIC, data); + if (DefaultsOpCodeHandle == NULL) { - return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode)); + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length); } Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); - InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, sizeof (OpCode), 0, 1); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_NUMERIC_OP, Length, 0, 1); InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle); HiiCreateEndOpCode (OpCodeHandle); return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position; @@ -3040,7 +3631,8 @@ HiiCreateNumericOpCode ( @param[in] OpCodeHandle Handle to the buffer of opcodes. @param[in] QuestionId Question ID @param[in] VarStoreId Storage ID - @param[in] VarOffset Offset in Storage + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair. @param[in] Prompt String ID for Prompt @param[in] Help String ID for Help @param[in] QuestionFlags Flags in Question Header @@ -3073,7 +3665,7 @@ HiiCreateStringOpCode ( EFI_IFR_STRING OpCode; UINTN Position; - ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); ZeroMem (&OpCode, sizeof (OpCode)); OpCode.Question.Header.Prompt = Prompt; @@ -3107,7 +3699,8 @@ HiiCreateStringOpCode ( @param[in] OpCodeHandle Handle to the buffer of opcodes. @param[in] QuestionId Question ID @param[in] VarStoreId Storage ID - @param[in] VarOffset Offset in Storage + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair. @param[in] Prompt String ID for Prompt @param[in] Help String ID for Help @param[in] QuestionFlags Flags in Question Header @@ -3137,6 +3730,7 @@ HiiCreateOneOfOpCode ( { EFI_IFR_ONE_OF OpCode; UINTN Position; + UINTN Length; ASSERT (OptionsOpCodeHandle != NULL); ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED | EFI_IFR_FLAG_OPTIONS_ONLY))) == 0); @@ -3150,8 +3744,11 @@ HiiCreateOneOfOpCode ( OpCode.Question.Flags = QuestionFlags; OpCode.Flags = OneOfFlags; + Length = OFFSET_OF (EFI_IFR_ONE_OF, data); + Length += (1 << (OneOfFlags & EFI_IFR_NUMERIC_SIZE)) * 3; + Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); - InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, sizeof (OpCode), 0, 1); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_ONE_OF_OP, Length, 0, 1); InternalHiiAppendOpCodes (OpCodeHandle, OptionsOpCodeHandle); if (DefaultsOpCodeHandle != NULL) { InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle); @@ -3170,7 +3767,8 @@ HiiCreateOneOfOpCode ( @param[in] OpCodeHandle Handle to the buffer of opcodes. @param[in] QuestionId Question ID @param[in] VarStoreId Storage ID - @param[in] VarOffset Offset in Storage + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair. @param[in] Prompt String ID for Prompt @param[in] Help String ID for Help @param[in] QuestionFlags Flags in Question Header @@ -3228,17 +3826,184 @@ HiiCreateOrderedListOpCode ( return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position; } +/** + Create EFI_IFR_TEXT_OP opcode. + + If OpCodeHandle is NULL, then ASSERT(). + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] Prompt String ID for Prompt. + @param[in] Help String ID for Help. + @param[in] TextTwo String ID for TextTwo. + + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the created opcode. + +**/ +UINT8 * +EFIAPI +HiiCreateTextOpCode ( + IN VOID *OpCodeHandle, + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN EFI_STRING_ID TextTwo + ) +{ + EFI_IFR_TEXT OpCode; + + ZeroMem (&OpCode, sizeof (OpCode)); + OpCode.Statement.Prompt = Prompt; + OpCode.Statement.Help = Help; + OpCode.TextTwo = TextTwo; + + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TEXT_OP, sizeof (OpCode)); +} + +/** + Create EFI_IFR_DATE_OP opcode. + + If OpCodeHandle is NULL, then ASSERT(). + If any reserved bits are set in QuestionFlags, then ASSERT(). + If any reserved bits are set in DateFlags, then ASSERT(). + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] QuestionId Question ID + @param[in] VarStoreId Storage ID, optional. If DateFlags is not + QF_DATE_STORAGE_NORMAL, this parameter is ignored. + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair, optional. If DateFlags is not + QF_DATE_STORAGE_NORMAL, this parameter is ignored. + @param[in] Prompt String ID for Prompt + @param[in] Help String ID for Help + @param[in] QuestionFlags Flags in Question Header + @param[in] DateFlags Flags for date opcode + @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This + is an optional parameter that may be NULL. + + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the created opcode. + +**/ +UINT8 * +EFIAPI +HiiCreateDateOpCode ( + IN VOID *OpCodeHandle, + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, OPTIONAL + IN UINT16 VarOffset, OPTIONAL + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 DateFlags, + IN VOID *DefaultsOpCodeHandle OPTIONAL + ) +{ + EFI_IFR_DATE OpCode; + UINTN Position; + + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + ASSERT ((DateFlags & (~(EFI_QF_DATE_YEAR_SUPPRESS | EFI_QF_DATE_MONTH_SUPPRESS | EFI_QF_DATE_DAY_SUPPRESS | EFI_QF_DATE_STORAGE))) == 0); + + ZeroMem (&OpCode, sizeof (OpCode)); + OpCode.Question.Header.Prompt = Prompt; + OpCode.Question.Header.Help = Help; + OpCode.Question.QuestionId = QuestionId; + OpCode.Question.VarStoreId = VarStoreId; + OpCode.Question.VarStoreInfo.VarOffset = VarOffset; + OpCode.Question.Flags = QuestionFlags; + OpCode.Flags = DateFlags; + + if (DefaultsOpCodeHandle == NULL) { + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode)); + } + + Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_DATE_OP, sizeof (OpCode), 0, 1); + InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle); + HiiCreateEndOpCode (OpCodeHandle); + return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position; +} + +/** + Create EFI_IFR_TIME_OP opcode. + + If OpCodeHandle is NULL, then ASSERT(). + If any reserved bits are set in QuestionFlags, then ASSERT(). + If any reserved bits are set in TimeFlags, then ASSERT(). + + @param[in] OpCodeHandle Handle to the buffer of opcodes. + @param[in] QuestionId Question ID + @param[in] VarStoreId Storage ID, optional. If TimeFlags is not + QF_TIME_STORAGE_NORMAL, this parameter is ignored. + @param[in] VarOffset Offset in Storage or String ID of the name (VarName) + for this name/value pair, optional. If TimeFlags is not + QF_TIME_STORAGE_NORMAL, this parameter is ignored. + @param[in] Prompt String ID for Prompt + @param[in] Help String ID for Help + @param[in] QuestionFlags Flags in Question Header + @param[in] TimeFlags Flags for time opcode + @param[in] DefaultsOpCodeHandle Handle for a buffer of DEFAULT opcodes. This + is an optional parameter that may be NULL. + + @retval NULL There is not enough space left in Buffer to add the opcode. + @retval Other A pointer to the created opcode. + +**/ +UINT8 * +EFIAPI +HiiCreateTimeOpCode ( + IN VOID *OpCodeHandle, + IN EFI_QUESTION_ID QuestionId, + IN EFI_VARSTORE_ID VarStoreId, OPTIONAL + IN UINT16 VarOffset, OPTIONAL + IN EFI_STRING_ID Prompt, + IN EFI_STRING_ID Help, + IN UINT8 QuestionFlags, + IN UINT8 TimeFlags, + IN VOID *DefaultsOpCodeHandle OPTIONAL + ) +{ + EFI_IFR_TIME OpCode; + UINTN Position; + + ASSERT ((QuestionFlags & (~(EFI_IFR_FLAG_READ_ONLY | EFI_IFR_FLAG_CALLBACK | EFI_IFR_FLAG_RESET_REQUIRED))) == 0); + ASSERT ((TimeFlags & (~(QF_TIME_HOUR_SUPPRESS | QF_TIME_MINUTE_SUPPRESS | QF_TIME_SECOND_SUPPRESS | QF_TIME_STORAGE))) == 0); + + ZeroMem (&OpCode, sizeof (OpCode)); + OpCode.Question.Header.Prompt = Prompt; + OpCode.Question.Header.Help = Help; + OpCode.Question.QuestionId = QuestionId; + OpCode.Question.VarStoreId = VarStoreId; + OpCode.Question.VarStoreInfo.VarOffset = VarOffset; + OpCode.Question.Flags = QuestionFlags; + OpCode.Flags = TimeFlags; + + if (DefaultsOpCodeHandle == NULL) { + return InternalHiiCreateOpCode (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode)); + } + + Position = InternalHiiOpCodeHandlePosition (OpCodeHandle); + InternalHiiCreateOpCodeExtended (OpCodeHandle, &OpCode, EFI_IFR_TIME_OP, sizeof (OpCode), 0, 1); + InternalHiiAppendOpCodes (OpCodeHandle, DefaultsOpCodeHandle); + HiiCreateEndOpCode (OpCodeHandle); + return InternalHiiOpCodeHandleBuffer (OpCodeHandle) + Position; +} + /** This is the internal worker function to update the data in a form specified by FormSetGuid, FormId and Label. - @param FormSetGuid The optional Formset GUID. - @param FormId The Form ID. - @param Package The package header. - - @param TempPacakge The resultant package. + @param[in] FormSetGuid The optional Formset GUID. + @param[in] FormId The Form ID. + @param[in] Package The package header. + @param[in] OpCodeBufferStart An OpCode buffer that contains the set of IFR + opcodes to be inserted or replaced in the form. + @param[in] OpCodeBufferEnd An OpCcode buffer that contains the IFR opcode + that marks the end of a replace operation in the form. + @param[out] TempPackage The resultant package. @retval EFI_SUCCESS The function completes successfully. + @retval EFI_NOT_FOUND The updated opcode or endopcode is not found. **/ EFI_STATUS @@ -3288,7 +4053,7 @@ InternalHiiUpdateFormPackageData ( } else { GetFormSet = FALSE; } - } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP) { + } else if (IfrOpHdr->OpCode == EFI_IFR_FORM_OP || IfrOpHdr->OpCode == EFI_IFR_FORM_MAP_OP) { if (CompareMem (&((EFI_IFR_FORM *) IfrOpHdr)->FormId, &FormId, sizeof (EFI_FORM_ID)) == 0) { GetForm = TRUE; } else { @@ -3394,22 +4159,22 @@ InternalHiiUpdateFormPackageData ( The form to update is specified by Handle, FormSetGuid, and FormId. Binary comparisons of IFR opcodes are performed from the beginning of the form being updated until an IFR opcode is found that exactly matches the first IFR opcode - specifed by StartOpCodeHandle. The following rules are used to determine if + specified by StartOpCodeHandle. The following rules are used to determine if an insert, replace, or delete operation is performed. 1) If no matches are found, then NULL is returned. 2) If a match is found, and EndOpCodeHandle is NULL, then all of the IFR opcodes - from StartOpcodeHandle except the first opcode are inserted immediately after - the matching IFR opcode in the form beng updated. + from StartOpCodeHandle except the first opcode are inserted immediately after + the matching IFR opcode in the form to be updated. 3) If a match is found, and EndOpCodeHandle is not NULL, then a search is made - from the matching IFR opcode until an IFR opcode exatly matches the first + from the matching IFR opcode until an IFR opcode exactly matches the first IFR opcode specified by EndOpCodeHandle. If no match is found for the first IFR opcode specified by EndOpCodeHandle, then NULL is returned. If a match is found, then all of the IFR opcodes between the start match and the end match are deleted from the form being updated and all of the IFR opcodes - from StartOpcodeHandle except the first opcode are inserted immediately after + from StartOpCodeHandle except the first opcode are inserted immediately after the matching start IFR opcode. If StartOpCcodeHandle only contains one - IFR instruction, then the result of ths operation will delete all of the IFR + IFR instruction, then the result of this operation will delete all of the IFR opcodes between the start end matches. If HiiHandle is NULL, then ASSERT(). @@ -3450,8 +4215,8 @@ HiiUpdateForm ( IN EFI_HII_HANDLE HiiHandle, IN EFI_GUID *FormSetGuid, OPTIONAL IN EFI_FORM_ID FormId, - IN VOID *StartOpcodeHandle, - IN VOID *EndOpcodeHandle OPTIONAL + IN VOID *StartOpCodeHandle, + IN VOID *EndOpCodeHandle OPTIONAL ) { EFI_STATUS Status; @@ -3462,7 +4227,7 @@ HiiUpdateForm ( UINTN BufferSize; UINT8 *UpdateBufferPos; EFI_HII_PACKAGE_HEADER *Package; - EFI_HII_PACKAGE_HEADER *TempPacakge; + EFI_HII_PACKAGE_HEADER *TempPackage; EFI_HII_PACKAGE_HEADER PackageHeader; BOOLEAN Updated; HII_LIB_OPCODE_BUFFER *OpCodeBufferStart; @@ -3472,19 +4237,19 @@ HiiUpdateForm ( // Input update data can't be NULL. // ASSERT (HiiHandle != NULL); - ASSERT (StartOpcodeHandle != NULL); + ASSERT (StartOpCodeHandle != NULL); UpdatePackageList = NULL; - TempPacakge = NULL; + TempPackage = NULL; HiiPackageList = NULL; // - // Restrive buffer data from Opcode Handle + // Retrieve buffer data from Opcode Handle // - OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpcodeHandle; - OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpcodeHandle; + OpCodeBufferStart = (HII_LIB_OPCODE_BUFFER *) StartOpCodeHandle; + OpCodeBufferEnd = (HII_LIB_OPCODE_BUFFER *) EndOpCodeHandle; // - // Get the orginal package list + // Get the original package list // BufferSize = 0; HiiPackageList = NULL; @@ -3520,8 +4285,8 @@ HiiUpdateForm ( // // Allocate temp buffer to store the temp updated package buffer // - TempPacakge = AllocateZeroPool (BufferSize); - if (TempPacakge == NULL) { + TempPackage = AllocateZeroPool (BufferSize); + if (TempPackage == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Finish; } @@ -3535,7 +4300,7 @@ HiiUpdateForm ( UpdateBufferPos += sizeof (EFI_HII_PACKAGE_LIST_HEADER); // - // Go through each package to find the matched pacakge and update one by one + // Go through each package to find the matched package and update one by one // Updated = FALSE; Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER); @@ -3549,9 +4314,9 @@ HiiUpdateForm ( // // Check this package is the matched package. // - Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPacakge); + Status = InternalHiiUpdateFormPackageData (FormSetGuid, FormId, Package, OpCodeBufferStart, OpCodeBufferEnd, TempPackage); // - // The matched package is found. Its pacakge buffer will be updated by the input new data. + // The matched package is found. Its package buffer will be updated by the input new data. // if (!EFI_ERROR(Status)) { // @@ -3561,7 +4326,7 @@ HiiUpdateForm ( // // Add updated package buffer // - Package = TempPacakge; + Package = TempPackage; } } @@ -3581,7 +4346,7 @@ HiiUpdateForm ( WriteUnaligned32 (&UpdatePackageList->PackageLength, (UINT32) BufferSize); // - // Update Pacakge to show form + // Update Package to show form // Status = gHiiDatabase->UpdatePackageList (gHiiDatabase, HiiHandle, UpdatePackageList); } else { @@ -3600,8 +4365,8 @@ Finish: FreePool (UpdatePackageList); } - if (TempPacakge != NULL) { - FreePool (TempPacakge); + if (TempPackage != NULL) { + FreePool (TempPackage); } return Status;