X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FConfigRouting.c;h=646864f4dfc1bc7a88019562408d011f5f9e2893;hb=9eefa2eca070255762b75cae4cca41b8ba537202;hp=057835232583db0599e9049e08826c58643bbca4;hpb=237e849da45eac8dbd343fbaa9bac40135e879f7;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c index 0578352325..646864f4df 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/ConfigRouting.c @@ -1,7 +1,7 @@ /** @file Implementation of interfaces function for EFI_HII_CONFIG_ROUTING_PROTOCOL. -Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 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 @@ -65,7 +65,7 @@ CalculateConfigStringLen ( @retval EFI_NOT_FOUND The device path is not invalid. @retval EFI_INVALID_PARAMETER Any incoming parameter is invalid. - @retval EFI_OUT_OF_RESOURCES Lake of resources to store neccesary structures. + @retval EFI_OUT_OF_RESOURCES Lake of resources to store necessary structures. @retval EFI_SUCCESS The device path is retrieved and translated to binary format. @@ -264,7 +264,14 @@ GenerateSubStr ( // TemBuffer = ((UINT8 *) Buffer); for (Index = 0; Index < BufferLen; Index ++, TemBuffer ++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + UnicodeValueToStringS ( + TemString, + sizeof (CHAR16) * (Length - StrnLenS (Str, Length)), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, Length - StrnLenS (Str, Length)); } break; case 2: @@ -277,7 +284,14 @@ GenerateSubStr ( // Convert Unicode String to Config String, e.g. "ABCD" => "0041004200430044" // for (; *TemName != L'\0'; TemName++) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemName, 4); + UnicodeValueToStringS ( + TemString, + sizeof (CHAR16) * (Length - StrnLenS (Str, Length)), + PREFIX_ZERO | RADIX_HEX, + *TemName, + 4 + ); + TemString += StrnLenS (TemString, Length - StrnLenS (Str, Length)); } break; case 3: @@ -286,7 +300,14 @@ GenerateSubStr ( // TemBuffer = ((UINT8 *) Buffer) + BufferLen - 1; for (Index = 0; Index < BufferLen; Index ++, TemBuffer --) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + UnicodeValueToStringS ( + TemString, + sizeof (CHAR16) * (Length - StrnLenS (Str, Length)), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, Length - StrnLenS (Str, Length)); } break; default: @@ -436,7 +457,7 @@ AppendToMultiString ( to free memory. @param Len Length of the , in characters. - @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures. @retval EFI_SUCCESS Value of is outputted in Number successfully. @@ -518,7 +539,7 @@ Exit: @param Found The Block whether has been found. @param BufferLen The length of the buffer. - @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures. + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures. @retval EFI_SUCCESS The function finishes successfully. **/ @@ -574,7 +595,7 @@ FindSameBlockElement( @param AltConfigHdr Pointer to a Unicode string in format. @param ConfigAltRespChanged Whether the ConfigAltResp has been changed. - @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures. + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures. @retval EFI_SUCCESS The function finishes successfully. **/ @@ -715,7 +736,7 @@ Exit: @param AltConfigHdr Pointer to a Unicode string in format. @param ConfigAltRespChanged Whether the ConfigAltResp has been changed. - @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary structures. + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures. @retval EFI_SUCCESS The function finishes successfully. **/ @@ -845,7 +866,7 @@ Exit: string for the different varstore buffer. @param AltConfigHdr Pointer to a Unicode string in format. - @retval EFI_OUT_OF_RESOURCES Insufficient resources to store neccessary + @retval EFI_OUT_OF_RESOURCES Insufficient resources to store necessary structures. @retval EFI_SUCCESS The function finishes successfully. @@ -1021,7 +1042,7 @@ MergeDefaultString ( } // - // Get the requestr ConfigHdr + // Get the request ConfigHdr // SizeAltCfgResp = 0; StringPtr = *AltCfgResp; @@ -1151,8 +1172,9 @@ InsertDefaultValue ( if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) { // // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority. + // When default types are DEFAULT_VALUE_FROM_OTHER_DEFAULT, the default value can be overrode. // - if (DefaultValueData->Type > DefaultValueArray->Type) { + if ((DefaultValueData->Type > DefaultValueArray->Type) || (DefaultValueData->Type == DefaultValueArray->Type && DefaultValueData->Type == DefaultValueFromOtherDefault)) { // // Update the default value array in BlockData. // @@ -1203,7 +1225,7 @@ InsertBlockData ( for (Link = BlockLink->ForwardLink; Link != BlockLink; Link = Link->ForwardLink) { BlockArray = BASE_CR (Link, IFR_BLOCK_DATA, Entry); if (BlockArray->Offset == BlockSingleData->Offset) { - if (BlockArray->Width > BlockSingleData->Width) { + if ((BlockArray->Width > BlockSingleData->Width) || (BlockSingleData->IsBitVar && BlockArray->Width == BlockSingleData->Width)) { // // Insert this block data in the front of block array // @@ -1211,7 +1233,7 @@ InsertBlockData ( return; } - if (BlockArray->Width == BlockSingleData->Width) { + if ((!BlockSingleData->IsBitVar) && BlockArray->Width == BlockSingleData->Width) { // // The same block array has been added. // @@ -1248,9 +1270,9 @@ InsertBlockData ( @param[in] HiiHandle A handle that was previously registered in the HII Database. @retval NULL HiiHandle is not registered in the HII database - @retval NULL There are not enough resources available to retrieve the suported + @retval NULL There are not enough resources available to retrieve the supported languages. - @retval NULL The list of suported languages could not be retrieved. + @retval NULL The list of supported languages could not be retrieved. @retval Other A pointer to the Null-terminated ASCII string of supported languages. **/ @@ -1696,7 +1718,7 @@ GetVarStoreType ( } // - // Free alllocated temp string. + // Free allocated temp string. // FreePool (VarStoreName); FreePool (GuidStr); @@ -1754,8 +1776,8 @@ GetElementsFromRequest ( @param Name Varstore name. @param ConfigHdr Current configRequest info. - @retval TRUE This varstore is the requst one. - @retval FALSE This varstore is not the requst one. + @retval TRUE This varstore is the request one. + @retval FALSE This varstore is not the request one. **/ BOOLEAN @@ -1824,8 +1846,8 @@ Done: @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package. @param ConfigHdr Request string ConfigHdr. If it is NULL, the first found varstore will be as ConfigHdr. - @retval TRUE This hii package is the reqeust one. - @retval FALSE This hii package is not the reqeust one. + @retval TRUE This hii package is the request one. + @retval FALSE This hii package is not the request one. **/ BOOLEAN IsThisPackageList ( @@ -1954,10 +1976,11 @@ Done: @param RequestBlockArray The array includes all the request info or NULL. @param HiiHandle The hii handle for this form package. - @param VarStorageData The varstore data strucure. + @param VarStorageData The varstore data structure. @param IfrOpHdr Ifr opcode header for this opcode. @param VarWidth The buffer width for this opcode. @param ReturnData The data block added for this opcode. + @param IsBitVar Whether the the opcode refers to bit storage. @retval EFI_SUCCESS This opcode is required. @retval EFI_NOT_FOUND This opcode is not required. @@ -1971,16 +1994,22 @@ IsThisOpcodeRequired ( IN OUT IFR_VARSTORAGE_DATA *VarStorageData, IN EFI_IFR_OP_HEADER *IfrOpHdr, IN UINT16 VarWidth, - OUT IFR_BLOCK_DATA **ReturnData + OUT IFR_BLOCK_DATA **ReturnData, + IN BOOLEAN IsBitVar ) { IFR_BLOCK_DATA *BlockData; UINT16 VarOffset; EFI_STRING_ID NameId; EFI_IFR_QUESTION_HEADER *IfrQuestionHdr; + UINT16 BitOffset; + UINT16 BitWidth; + UINT16 TotalBits; NameId = 0; VarOffset = 0; + BitOffset = 0; + BitWidth = 0; IfrQuestionHdr = (EFI_IFR_QUESTION_HEADER *)((CHAR8 *) IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)); if (VarStorageData->Type == EFI_HII_VARSTORE_NAME_VALUE) { @@ -1996,7 +2025,23 @@ IsThisOpcodeRequired ( return EFI_NOT_FOUND; } } else { - VarOffset = IfrQuestionHdr->VarStoreInfo.VarOffset; + // + // Get the byte offset/with and bit offset/width + // + if (IsBitVar) { + BitOffset = IfrQuestionHdr->VarStoreInfo.VarOffset; + BitWidth = VarWidth; + VarOffset = BitOffset / 8; + // + // Use current bit width and the bit width before current bit (with same byte offset) to calculate the byte width. + // + TotalBits = BitOffset % 8 + BitWidth; + VarWidth = (TotalBits % 8 == 0 ? TotalBits / 8: TotalBits / 8 + 1); + } else { + VarOffset = IfrQuestionHdr->VarStoreInfo.VarOffset; + BitWidth = VarWidth; + BitOffset = VarOffset * 8; + } // // Check whether this question is in requested block array. @@ -2031,6 +2076,9 @@ IsThisOpcodeRequired ( BlockData->QuestionId = IfrQuestionHdr->QuestionId; BlockData->OpCode = IfrOpHdr->OpCode; BlockData->Scope = IfrOpHdr->Scope; + BlockData->IsBitVar = IsBitVar; + BlockData->BitOffset = BitOffset; + BlockData->BitWidth = BitWidth; InitializeListHead (&BlockData->DefaultValueEntry); // // Add Block Data into VarStorageData BlockEntry @@ -2047,7 +2095,7 @@ IsThisOpcodeRequired ( @param HiiHandle Hii Handle for this hii package. @param Package Pointer to the form package data. - @param PackageLength Length of the pacakge. + @param PackageLength Length of the package. @param ConfigHdr Request string ConfigHdr. If it is NULL, the first found varstore will be as ConfigHdr. @param RequestBlockArray The block array is retrieved from the request string. @@ -2055,7 +2103,7 @@ IsThisOpcodeRequired ( @param DefaultIdArray Point to the got default id and default name array. @retval EFI_SUCCESS The block array and the default value array are got. - @retval EFI_INVALID_PARAMETER The varstore defintion in the differnt form pacakges + @retval EFI_INVALID_PARAMETER The varstore definition in the different form packages are conflicted. @retval EFI_OUT_OF_RESOURCES No enough memory. **/ @@ -2101,6 +2149,10 @@ ParseIfrData ( EFI_IFR_VARSTORE_NAME_VALUE *IfrNameValueVarStore; EFI_HII_PACKAGE_HEADER *PackageHeader; EFI_VARSTORE_ID VarStoreId; + UINT16 SmallestDefaultId; + BOOLEAN SmallestIdFromFlag; + BOOLEAN FromOtherDefaultOpcode; + BOOLEAN QuestionReferBitField; Status = EFI_SUCCESS; BlockData = NULL; @@ -2110,6 +2162,9 @@ ParseIfrData ( FirstOrderedList = FALSE; VarStoreName = NULL; ZeroMem (&DefaultData, sizeof (IFR_DEFAULT_DATA)); + SmallestDefaultId = 0xFFFF; + FromOtherDefaultOpcode = FALSE; + QuestionReferBitField = FALSE; // // Go through the form package to parse OpCode one by one. @@ -2284,7 +2339,7 @@ ParseIfrData ( BlockData = NULL; } - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2316,7 +2371,12 @@ ParseIfrData ( if (IfrOneOf->Question.VarStoreId != VarStoreId) { break; } - VarWidth = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + + if (QuestionReferBitField) { + VarWidth = IfrOneOf->Flags & EDKII_IFR_NUMERIC_SIZE_BIT; + } else { + VarWidth = (UINT16) (1 << (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE)); + } // // The BlockData may allocate by other opcode,need to clean. @@ -2325,7 +2385,7 @@ ParseIfrData ( BlockData = NULL; } - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, QuestionReferBitField); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2351,26 +2411,33 @@ ParseIfrData ( // Numeric minimum value will be used as default value when no default is specified. // DefaultData.Type = DefaultValueFromDefault; - switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) { - case EFI_IFR_NUMERIC_SIZE_1: - DefaultData.Value.u8 = IfrOneOf->data.u8.MinValue; - break; + if (QuestionReferBitField) { + // + // Since default value in bit field was stored as UINT32 type. + // + CopyMem (&DefaultData.Value.u32, &IfrOneOf->data.u32.MinValue, sizeof (UINT32)); + } else { + switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) { + case EFI_IFR_NUMERIC_SIZE_1: + DefaultData.Value.u8 = IfrOneOf->data.u8.MinValue; + break; - case EFI_IFR_NUMERIC_SIZE_2: - CopyMem (&DefaultData.Value.u16, &IfrOneOf->data.u16.MinValue, sizeof (UINT16)); - break; + case EFI_IFR_NUMERIC_SIZE_2: + CopyMem (&DefaultData.Value.u16, &IfrOneOf->data.u16.MinValue, sizeof (UINT16)); + break; - case EFI_IFR_NUMERIC_SIZE_4: - CopyMem (&DefaultData.Value.u32, &IfrOneOf->data.u32.MinValue, sizeof (UINT32)); - break; + case EFI_IFR_NUMERIC_SIZE_4: + CopyMem (&DefaultData.Value.u32, &IfrOneOf->data.u32.MinValue, sizeof (UINT32)); + break; - case EFI_IFR_NUMERIC_SIZE_8: - CopyMem (&DefaultData.Value.u64, &IfrOneOf->data.u64.MinValue, sizeof (UINT64)); - break; + case EFI_IFR_NUMERIC_SIZE_8: + CopyMem (&DefaultData.Value.u64, &IfrOneOf->data.u64.MinValue, sizeof (UINT64)); + break; - default: - Status = EFI_INVALID_PARAMETER; - goto Done; + default: + Status = EFI_INVALID_PARAMETER; + goto Done; + } } // // Set default value base on the DefaultId list get from IFR data. @@ -2414,7 +2481,7 @@ ParseIfrData ( BlockData = NULL; } - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2459,7 +2526,10 @@ ParseIfrData ( BlockData = NULL; } - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + if (QuestionReferBitField) { + VarWidth = 1; + } + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, QuestionReferBitField); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2475,6 +2545,8 @@ ParseIfrData ( // ASSERT (BlockData != NULL); + SmallestIdFromFlag = FALSE; + // // Add default value for standard ID by CheckBox Flag // @@ -2485,21 +2557,24 @@ ParseIfrData ( DefaultData.DefaultId = VarDefaultId; if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT) == EFI_IFR_CHECKBOX_DEFAULT) { // - // When flag is set, defautl value is TRUE. + // When flag is set, default value is TRUE. // DefaultData.Type = DefaultValueFromFlag; - DefaultData.Value.b = TRUE; - } else { - // - // When flag is not set, defautl value is FASLE. - // - DefaultData.Type = DefaultValueFromDefault; - DefaultData.Value.b = FALSE; + if (QuestionReferBitField) { + DefaultData.Value.u32 = TRUE; + } else { + DefaultData.Value.b = TRUE; + } + InsertDefaultValue (BlockData, &DefaultData); + + if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) { + // + // Record the SmallestDefaultId and update the SmallestIdFromFlag. + // + SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; + SmallestIdFromFlag = TRUE; + } } - // - // Add DefaultValue into current BlockData - // - InsertDefaultValue (BlockData, &DefaultData); // // Add default value for Manufacture ID by CheckBox Flag @@ -2511,21 +2586,61 @@ ParseIfrData ( DefaultData.DefaultId = VarDefaultId; if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) == EFI_IFR_CHECKBOX_DEFAULT_MFG) { // - // When flag is set, defautl value is TRUE. + // When flag is set, default value is TRUE. // DefaultData.Type = DefaultValueFromFlag; - DefaultData.Value.b = TRUE; + if (QuestionReferBitField) { + DefaultData.Value.u32 = TRUE; + } else { + DefaultData.Value.b = TRUE; + } + InsertDefaultValue (BlockData, &DefaultData); + + if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) { + // + // Record the SmallestDefaultId and update the SmallestIdFromFlag. + // + SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING; + SmallestIdFromFlag = TRUE; + } + } + if (SmallestIdFromFlag) { + // + // When smallest default Id is given by the flag of CheckBox, set default value with TRUE for other default Id in the DefaultId list. + // + DefaultData.Type = DefaultValueFromOtherDefault; + if (QuestionReferBitField) { + DefaultData.Value.u32 = TRUE; + } else { + DefaultData.Value.b = TRUE; + } + // + // Set default value for all the default id in the DefaultId list. + // + for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) { + DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry); + DefaultData.DefaultId = DefaultDataPtr->DefaultId; + InsertDefaultValue (BlockData, &DefaultData); + } } else { // - // When flag is not set, defautl value is FASLE. + // When flag is not set, default value is FASLE. // DefaultData.Type = DefaultValueFromDefault; - DefaultData.Value.b = FALSE; + if (QuestionReferBitField) { + DefaultData.Value.u32 = FALSE; + } else { + DefaultData.Value.b = FALSE; + } + // + // Set default value for all the default id in the DefaultId list. + // + for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) { + DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry); + DefaultData.DefaultId = DefaultDataPtr->DefaultId; + InsertDefaultValue (BlockData, &DefaultData); + } } - // - // Add DefaultValue into current BlockData - // - InsertDefaultValue (BlockData, &DefaultData); break; case EFI_IFR_DATE_OP: @@ -2558,7 +2673,7 @@ ParseIfrData ( } VarWidth = (UINT16) sizeof (EFI_HII_DATE); - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2600,7 +2715,7 @@ ParseIfrData ( } VarWidth = (UINT16) sizeof (EFI_HII_TIME); - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2642,7 +2757,7 @@ ParseIfrData ( } VarWidth = (UINT16) (IfrString->MaxSize * sizeof (UINT16)); - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2684,7 +2799,7 @@ ParseIfrData ( } VarWidth = (UINT16) (IfrPassword->MaxSize * sizeof (UINT16)); - Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData); + Status = IsThisOpcodeRequired(RequestBlockArray, HiiHandle, VarStorageData, IfrOpHdr, VarWidth, &BlockData, FALSE); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND){ // @@ -2779,6 +2894,7 @@ ParseIfrData ( // // 1. Set default value for OneOf option when flag field has default attribute. + // And set the default value with the smallest default id for other default id in the DefaultId list. // if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) || ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG)) { @@ -2787,6 +2903,8 @@ ParseIfrData ( // The first oneof option value will be used as default value when no default value is specified. // FirstOneOfOption = FALSE; + + SmallestIdFromFlag = FALSE; // Prepare new DefaultValue // @@ -2795,10 +2913,39 @@ ParseIfrData ( if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) { DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; InsertDefaultValue (BlockData, &DefaultData); - } + if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_STANDARD) { + // + // Record the SmallestDefaultId and update the SmallestIdFromFlag. + // + SmallestDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD; + SmallestIdFromFlag = TRUE; + } + } if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG) { DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING; InsertDefaultValue (BlockData, &DefaultData); + if (SmallestDefaultId > EFI_HII_DEFAULT_CLASS_MANUFACTURING) { + // + // Record the SmallestDefaultId and update the SmallestIdFromFlag. + // + SmallestDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING; + SmallestIdFromFlag = TRUE; + } + } + + if (SmallestIdFromFlag) { + // + // When smallest default Id is given by the flag of oneofOption, set this option value for other default Id in the DefaultId list. + // + DefaultData.Type = DefaultValueFromOtherDefault; + // + // Set default value for other default id in the DefaultId list. + // + for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) { + DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry); + DefaultData.DefaultId = DefaultDataPtr->DefaultId; + InsertDefaultValue (BlockData, &DefaultData); + } } } @@ -2844,7 +2991,11 @@ ParseIfrData ( // DefaultData.Type = DefaultValueFromOpcode; DefaultData.DefaultId = VarDefaultId; - CopyMem (&DefaultData.Value, &IfrDefault->Value, IfrDefault->Header.Length - OFFSET_OF (EFI_IFR_DEFAULT, Value)); + if (QuestionReferBitField) { + CopyMem (&DefaultData.Value.u32, &IfrDefault->Value.u32, sizeof (UINT32)); + } else { + CopyMem (&DefaultData.Value, &IfrDefault->Value, IfrDefault->Header.Length - OFFSET_OF (EFI_IFR_DEFAULT, Value)); + } // If the value field is expression, set the cleaned flag. if (IfrDefault->Type == EFI_IFR_TYPE_OTHER) { @@ -2856,8 +3007,27 @@ ParseIfrData ( InsertDefaultValue (BlockData, &DefaultData); // - // After insert the default value, reset the cleaned value for next - // time used. If not set here, need to set the value before everytime + // Set default value for other default id in the DefaultId list. + // when SmallestDefaultId == VarDefaultId means there are two defaults with same default Id. + // If the two defaults are both from default opcode, use the first default as the default value of other default Id. + // If one from flag and the other form default opcode, use the default opcode value as the default value of other default Id. + // + if ((SmallestDefaultId > VarDefaultId) || (SmallestDefaultId == VarDefaultId && !FromOtherDefaultOpcode)) { + FromOtherDefaultOpcode = TRUE; + SmallestDefaultId = VarDefaultId; + for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) { + DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry); + if (DefaultDataPtr->DefaultId != DefaultData.DefaultId){ + DefaultData.Type = DefaultValueFromOtherDefault; + DefaultData.DefaultId = DefaultDataPtr->DefaultId; + InsertDefaultValue (BlockData, &DefaultData); + } + } + } + + // + // After insert the default value, reset the cleaned value for next + // time used. If not set here, need to set the value before every time. // use it. // DefaultData.Cleaned = FALSE; @@ -2867,17 +3037,29 @@ ParseIfrData ( // // End Opcode is for Var question. // + QuestionReferBitField = FALSE; if (BlockData != NULL) { if (BlockData->Scope > 0) { BlockData->Scope--; } if (BlockData->Scope == 0) { BlockData = NULL; + // + // when finishing parsing a question, clean the SmallestDefaultId and GetDefaultFromDefaultOpcode. + // + SmallestDefaultId = 0xFFFF; + FromOtherDefaultOpcode = FALSE; } } break; + case EFI_IFR_GUID_OP: + if (CompareGuid ((EFI_GUID *)((UINT8 *)IfrOpHdr + sizeof (EFI_IFR_OP_HEADER)), &gEdkiiIfrBitVarstoreGuid)) { + QuestionReferBitField = TRUE; + } + break; + default: if (BlockData != NULL) { if (BlockData->Scope > 0) { @@ -3456,6 +3638,212 @@ GetStorageWidth ( return StorageWidth; } +/** + Update the default value in the block data which is used as bit var store. + + For example: + A question value saved in a bit fied: bitoffset = 1; bitwidth = 2;default value = 1. + And corresponding block data info: offset==0; width==1;currently the default value + is saved as 1.Actually the default value 1 need to be set to bit field 1, so the + default value of this block data shuold be:2. + + typedef struct { + UINT8 Bit1 : 1; // + UINT8 Bit2 : 2; // Question saved in Bit2,so originalBlock info: offset = 0; width = 1;(byte level) defaul = 1. + // (default value record for the bit field) + ...... + }ExampleData; + + After function UpdateDefaultValue,the Block info is: offset = 0; width = 1;(byte level) default = 2. + (default value record for the Block) + + UpdateDefaultValue function update default value of bit var block based on the bit field info in the block. + + @param BlockLink The Link of the block data. + +**/ +VOID +UpdateDefaultValue ( + IN LIST_ENTRY *BlockLink +) +{ + LIST_ENTRY *Link; + LIST_ENTRY *ListEntry; + LIST_ENTRY *LinkDefault; + IFR_BLOCK_DATA *BlockData; + IFR_DEFAULT_DATA *DefaultValueData; + UINTN StartBit; + UINTN EndBit; + UINT32 BitFieldDefaultValue; + + for ( Link = BlockLink->ForwardLink; Link != BlockLink; Link = Link->ForwardLink) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + if (!BlockData ->IsBitVar) { + continue; + } + ListEntry = &BlockData->DefaultValueEntry; + // + // Update the default value in the block data with all existing default id. + // + for (LinkDefault = ListEntry->ForwardLink; LinkDefault != ListEntry; LinkDefault = LinkDefault->ForwardLink) { + // + // Get the default data, and the value of the default data is for some field in the block. + // Note: Default value for bit field question is stored as UINT32. + // + DefaultValueData = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry); + BitFieldDefaultValue = DefaultValueData->Value.u32; + + StartBit = BlockData->BitOffset % 8; + EndBit = StartBit + BlockData->BitWidth - 1; + + // + // Set the bit field default value to related bit filed, then we will got the new default vaule for the block data. + // + DefaultValueData->Value.u32 = BitFieldWrite32 (0, StartBit, EndBit, BitFieldDefaultValue); + } + } +} + +/** +Merge the default value in two block datas which have overlap region. + +For bit fields, their related block data may have overlap region, such as: + +typedef struct { + UINT16 Bit1 : 6; // Question1 refer Bit1, Block1: offset = 0; width = 1;(byte level) default = 1 + UINT16 Bit2 : 5; // Question2 refer Bit2, Block2: offset = 0; width = 2;(byte level) default = 5 + // (default value record for the bit field) + ...... +}ExampleData; + +After function UpdateDefaultValue: +Block1: offset = 0; width = 1;(byte level) default = 1 +Block2: offset = 0; width = 2;(byte level) default = 320 (5 * (2 << 6)) +(default value record for block) + +After function MergeBlockDefaultValue: +Block1: offset = 0; width = 1;(byte level) default = 65 +Block2: offset = 0; width = 2;(byte level) default = 321 +(Block1 and Block2 has overlap region, merge the overlap value to Block1 and Blcok2) + +Block1 and Block2 have overlap byte region, but currntly the default value of Block1 only contains +value of Bit1 (low 6 bits),the default value of Block2 only contains the value of Bit2 (middle 5 bits). + +This fuction merge the default value of these two blocks, and make the default value of block1 +also contain the value of lower 2 bits of the Bit2. And make the default value of Block2 also +contain the default value of Bit1. + +We can get the total value of the whole block that just cover these two blocks(in this case is: +block: offset =0; width =2;) then the value of block2 is same as block, the value of block1 is +the first byte value of block. + +@param FirstBlock Point to the block date whose default value need to be merged. +@param SecondBlock Point to the block date whose default value need to be merged. + +**/ +VOID +MergeBlockDefaultValue ( + IN OUT IFR_BLOCK_DATA *FirstBlock, + IN OUT IFR_BLOCK_DATA *SecondBlock +) +{ + LIST_ENTRY *FirstListEntry; + LIST_ENTRY *SecondListEntry; + LIST_ENTRY *FirstDefaultLink; + LIST_ENTRY *SecondDefaultLink; + IFR_DEFAULT_DATA *FirstDefaultValueData; + IFR_DEFAULT_DATA *SecondDefaultValueData; + UINT32 *FirstDefaultValue; + UINT32 *SecondDefaultValue; + UINT64 TotalValue; + UINT64 ShiftedValue; + UINT16 OffsetShift; + + FirstListEntry = &FirstBlock->DefaultValueEntry; + for (FirstDefaultLink = FirstListEntry->ForwardLink; FirstDefaultLink != FirstListEntry; FirstDefaultLink = FirstDefaultLink->ForwardLink) { + FirstDefaultValueData = BASE_CR (FirstDefaultLink, IFR_DEFAULT_DATA, Entry); + SecondListEntry = &SecondBlock->DefaultValueEntry; + for (SecondDefaultLink = SecondListEntry->ForwardLink; SecondDefaultLink != SecondListEntry; SecondDefaultLink = SecondDefaultLink->ForwardLink) { + SecondDefaultValueData = BASE_CR (SecondDefaultLink, IFR_DEFAULT_DATA, Entry); + if (FirstDefaultValueData->DefaultId != SecondDefaultValueData->DefaultId) { + continue; + } + // + // Find default value with same default id in the two blocks. + // Note: Default value for bit field question is stored as UINT32 type. + // + FirstDefaultValue = &FirstDefaultValueData->Value.u32; + SecondDefaultValue = &SecondDefaultValueData->Value.u32; + // + // 1. Get the default value of the whole blcok that can just cover FirstBlock and SecondBlock. + // 2. Get the default value of FirstBlock and SecondBlock form the value of whole block based + // on the offset and width of FirstBlock and SecondBlock. + // + if (FirstBlock->Offset > SecondBlock->Offset) { + OffsetShift = FirstBlock->Offset - SecondBlock->Offset; + ShiftedValue = LShiftU64 ((UINT64) (*FirstDefaultValue), OffsetShift * 8); + TotalValue = ShiftedValue | (UINT64) (*SecondDefaultValue); + *SecondDefaultValue = (UINT32) BitFieldRead64 (TotalValue, 0, SecondBlock->Width * 8 -1); + *FirstDefaultValue = (UINT32) BitFieldRead64 (TotalValue, OffsetShift * 8, OffsetShift * 8 + FirstBlock->Width *8 -1); + } else { + OffsetShift = SecondBlock->Offset -FirstBlock->Offset; + ShiftedValue = LShiftU64 ((UINT64) (*SecondDefaultValue), OffsetShift * 8); + TotalValue = ShiftedValue | (UINT64) (*FirstDefaultValue); + *FirstDefaultValue = (UINT32) BitFieldRead64 (TotalValue, 0, FirstBlock->Width * 8 -1); + *SecondDefaultValue = (UINT32) BitFieldRead64 (TotalValue, OffsetShift * 8, OffsetShift * 8 + SecondBlock->Width *8 -1); + } + } + } +} + +/** + +Update the default value in the block data which used as Bit VarStore + +@param BlockLink The Link of the block data. + +**/ +VOID +UpdateBlockDataArray ( + IN LIST_ENTRY *BlockLink +) +{ + LIST_ENTRY *Link; + LIST_ENTRY *TempLink; + IFR_BLOCK_DATA *BlockData; + IFR_BLOCK_DATA *NextBlockData; + + // + // 1. Update default value in BitVar block data. + // Sine some block datas are used as BitVarStore, then the default value recored in the block + // is for related bit field in the block. so we need to set the default value to the related bit + // fields in the block data if the block data is used as bit varstore, then the default value of + // the block will be updated. + // + UpdateDefaultValue (BlockLink); + + // + // 2.Update default value for overlap BitVar blcok datas. + // For block datas have overlap region, we need to merge the default value in different blocks. + // + for (Link = BlockLink->ForwardLink; Link != BlockLink; Link = Link->ForwardLink) { + BlockData = BASE_CR (Link, IFR_BLOCK_DATA, Entry); + if (!BlockData ->IsBitVar) { + continue; + } + for (TempLink = Link->ForwardLink; TempLink != BlockLink; TempLink = TempLink->ForwardLink) { + NextBlockData = BASE_CR (TempLink, IFR_BLOCK_DATA, Entry); + if (!NextBlockData->IsBitVar || NextBlockData->Offset >= BlockData->Offset + BlockData->Width || BlockData->Offset >= NextBlockData->Offset + NextBlockData->Width) { + continue; + } + // + // Find two blocks are used as bit VarStore and have overlap region, so need to merge default value of these two blocks. + // + MergeBlockDefaultValue (BlockData, NextBlockData); + } + } +} + /** Generate ConfigAltResp string base on the varstore info. @@ -3490,6 +3878,7 @@ GenerateAltConfigResp ( UINTN Width; UINT8 *TmpBuffer; CHAR16 *DefaultString; + UINTN StrSize; BlockData = NULL; DataExist = FALSE; @@ -3499,6 +3888,8 @@ GenerateAltConfigResp ( // Length = StrLen (ConfigHdr) + 1; + UpdateBlockDataArray (&VarStorageData->BlockEntry); + for (Link = DefaultIdArray->Entry.ForwardLink; Link != &DefaultIdArray->Entry; Link = Link->ForwardLink) { DefaultId = BASE_CR (Link, IFR_DEFAULT_DATA, Entry); // @@ -3607,17 +3998,36 @@ GenerateAltConfigResp ( // if (BlockData->OpCode == EFI_IFR_STRING_OP){ DefaultString = InternalGetString(HiiHandle, DefaultValueData->Value.string); - TmpBuffer = (UINT8 *) DefaultString; + TmpBuffer = AllocateZeroPool (Width); + ASSERT (TmpBuffer != NULL); + if (DefaultString != NULL) { + StrSize = StrLen(DefaultString)* sizeof (CHAR16); + if (StrSize > Width) { + StrSize = Width; + } + CopyMem (TmpBuffer, (UINT8 *) DefaultString, StrSize); + } } else { TmpBuffer = (UINT8 *) &(DefaultValueData->Value); } for (; Width > 0 && (TmpBuffer != NULL); Width--) { - StringPtr += UnicodeValueToString (StringPtr, PREFIX_ZERO | RADIX_HEX, TmpBuffer[Width - 1], 2); + UnicodeValueToStringS ( + StringPtr, + Length * sizeof (CHAR16) - ((UINTN)StringPtr - (UINTN)*DefaultAltCfgResp), + PREFIX_ZERO | RADIX_HEX, + TmpBuffer[Width - 1], + 2 + ); + StringPtr += StrnLenS (StringPtr, Length - ((UINTN)StringPtr - (UINTN)*DefaultAltCfgResp) / sizeof (CHAR16)); } if (DefaultString != NULL){ FreePool(DefaultString); DefaultString = NULL; } + if (BlockData->OpCode == EFI_IFR_STRING_OP && TmpBuffer != NULL) { + FreePool(TmpBuffer); + TmpBuffer = NULL; + } } } } @@ -3652,7 +4062,7 @@ GenerateAltConfigResp ( When Request points to NULL, the default value string for each varstore in form package will be merged into a format string and return. - @param PointerProgress Optional parameter, it can be be NULL. + @param PointerProgress Optional parameter, it can be NULL. When it is not NULL, if Request is NULL, it returns NULL. On return, points to a character in the Request string. Points to the string's null terminator if @@ -3716,7 +4126,7 @@ GetFullStringFromHiiFormPackages ( } // - // 1. Get the request block array by Request String when Request string containts the block array. + // 1. Get the request block array by Request String when Request string contains the block array. // StringPtr = NULL; if (*Request != NULL) { @@ -3799,7 +4209,7 @@ GetFullStringFromHiiFormPackages ( // // - // Parse the opcode in form pacakge to get the default setting. + // Parse the opcode in form package to get the default setting. // Status = ParseIfrData (DataBaseRecord->Handle, HiiFormPackage, @@ -3845,7 +4255,7 @@ GetFullStringFromHiiFormPackages ( } // - // 5. Merge string into the input AltCfgResp if the iput *AltCfgResp is not NULL. + // 5. Merge string into the input AltCfgResp if the input *AltCfgResp is not NULL. // if (*AltCfgResp != NULL && DefaultAltCfgResp != NULL) { Status = MergeDefaultString (AltCfgResp, DefaultAltCfgResp); @@ -3918,7 +4328,7 @@ Done: } // - // Free Pacakge data + // Free Package data // if (HiiFormPackage != NULL) { FreePool (HiiFormPackage); @@ -4584,7 +4994,7 @@ HiiConfigRoutingExtractConfig ( // // Attach this to a . There is a '&' - // which seperates the first and the following ones. + // which separates the first and the following ones. // ASSERT (*AccessProgress == 0); @@ -4837,7 +5247,7 @@ HiiConfigRoutingExportConfig ( // // Attach this to a . There is a '&' - // which seperates the first and the following ones. + // which separates the first and the following ones. // if (!FirstElement) { Status = AppendToMultiString (Results, L"&"); @@ -5299,7 +5709,14 @@ HiiBlockToConfig ( TemString = ValueStr; TemBuffer = Value + Width - 1; for (Index = 0; Index < Width; Index ++, TemBuffer --) { - TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2); + UnicodeValueToStringS ( + TemString, + Length * sizeof (CHAR16) - ((UINTN)TemString - (UINTN)ValueStr), + PREFIX_ZERO | RADIX_HEX, + *TemBuffer, + 2 + ); + TemString += StrnLenS (TemString, Length - ((UINTN)TemString - (UINTN)ValueStr) / sizeof (CHAR16)); } FreePool (Value);