Patch for:

1. Get default value base on the priority: default opcode has highest priority and get from minimum or first option has lowest.
2. When default value saved in expression, not set default value for this question.
Signed-off-by: ydong10
Reviewed-by: lgao4

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12738 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
ydong10 2011-11-18 07:05:17 +00:00
parent 191daa25f4
commit ef40f0f6d6
2 changed files with 119 additions and 111 deletions

View File

@ -654,33 +654,28 @@ InsertDefaultValue (
for (Link = BlockData->DefaultValueEntry.ForwardLink; Link != &BlockData->DefaultValueEntry; Link = Link->ForwardLink) { for (Link = BlockData->DefaultValueEntry.ForwardLink; Link != &BlockData->DefaultValueEntry; Link = Link->ForwardLink) {
DefaultValueArray = BASE_CR (Link, IFR_DEFAULT_DATA, Entry); DefaultValueArray = BASE_CR (Link, IFR_DEFAULT_DATA, Entry);
if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) { if (DefaultValueArray->DefaultId == DefaultValueData->DefaultId) {
if (DefaultValueData->OpCode == EFI_IFR_DEFAULT_OP) { //
// // DEFAULT_VALUE_FROM_OPCODE has high priority, DEFAULT_VALUE_FROM_DEFAULT has low priority.
// Update the default value array in BlockData. //
// if (DefaultValueData->Type > DefaultValueArray->Type) {
DefaultValueArray->Value = DefaultValueData->Value;
} else if (DefaultValueArray->OpCode != EFI_IFR_DEFAULT_OP) {
// //
// Update the default value array in BlockData. // Update the default value array in BlockData.
// //
DefaultValueArray->Value = DefaultValueData->Value; DefaultValueArray->Value = DefaultValueData->Value;
DefaultValueArray->Type = DefaultValueData->Type;
DefaultValueArray->Cleaned = DefaultValueData->Cleaned;
} }
FreePool (DefaultValueData);
return; return;
} else if (DefaultValueArray->DefaultId > DefaultValueData->DefaultId) { }
//
// Insert new default value data in the front of this default value array.
//
InsertTailList (Link, &DefaultValueData->Entry);
return;
}
} }
// //
// Insert new default value data in tail. // Insert new default value data in tail.
// //
InsertTailList (Link, &DefaultValueData->Entry); DefaultValueArray = AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));
return; ASSERT (DefaultValueArray != NULL);
CopyMem (DefaultValueArray, DefaultValueData, sizeof (IFR_DEFAULT_DATA));
InsertTailList (Link, &DefaultValueArray->Entry);
} }
/** /**
@ -1001,7 +996,8 @@ ParseIfrData (
EFI_IFR_CHECKBOX *IfrCheckBox; EFI_IFR_CHECKBOX *IfrCheckBox;
EFI_IFR_PASSWORD *IfrPassword; EFI_IFR_PASSWORD *IfrPassword;
EFI_IFR_STRING *IfrString; EFI_IFR_STRING *IfrString;
IFR_DEFAULT_DATA *DefaultData; IFR_DEFAULT_DATA DefaultData;
IFR_DEFAULT_DATA *DefaultDataPtr;
IFR_BLOCK_DATA *BlockData; IFR_BLOCK_DATA *BlockData;
CHAR16 *VarStoreName; CHAR16 *VarStoreName;
UINT16 VarOffset; UINT16 VarOffset;
@ -1012,6 +1008,8 @@ ParseIfrData (
EFI_STRING TempStr; EFI_STRING TempStr;
UINTN LengthString; UINTN LengthString;
BOOLEAN FirstOneOfOption; BOOLEAN FirstOneOfOption;
LIST_ENTRY *LinkData;
LIST_ENTRY *LinkDefault;
LengthString = 0; LengthString = 0;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
@ -1019,8 +1017,9 @@ ParseIfrData (
NameStr = NULL; NameStr = NULL;
TempStr = NULL; TempStr = NULL;
BlockData = NULL; BlockData = NULL;
DefaultData = NULL; DefaultDataPtr = NULL;
FirstOneOfOption = FALSE; FirstOneOfOption = FALSE;
ZeroMem (&DefaultData, sizeof (IFR_DEFAULT_DATA));
// //
// Go through the form package to parse OpCode one by one. // Go through the form package to parse OpCode one by one.
@ -1158,14 +1157,14 @@ ParseIfrData (
// //
// Add new the map between default id and default name. // Add new the map between default id and default name.
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultDataPtr = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));
if (DefaultData == NULL) { if (DefaultDataPtr == NULL) {
Status = EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done; goto Done;
} }
DefaultData->DefaultId = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId; DefaultDataPtr->DefaultId = ((EFI_IFR_DEFAULTSTORE *) IfrOpHdr)->DefaultId;
InsertTailList (&DefaultIdArray->Entry, &DefaultData->Entry); InsertTailList (&DefaultIdArray->Entry, &DefaultDataPtr->Entry);
DefaultData = NULL; DefaultDataPtr = NULL;
break; break;
case EFI_IFR_FORM_OP: case EFI_IFR_FORM_OP:
@ -1251,43 +1250,32 @@ ParseIfrData (
// //
// Numeric minimum value will be used as default value when no default is specified. // Numeric minimum value will be used as default value when no default is specified.
// //
DefaultData.Type = DEFAULT_VALUE_FROM_DEFAULT;
//
// Set standard ID
//
VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
//
// Prepare new DefaultValue
//
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));
if (DefaultData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
DefaultData->OpCode = IfrOpHdr->OpCode;
DefaultData->DefaultId = VarDefaultId;
switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) { switch (IfrOneOf->Flags & EFI_IFR_NUMERIC_SIZE) {
case EFI_IFR_NUMERIC_SIZE_1: case EFI_IFR_NUMERIC_SIZE_1:
DefaultData->Value = (UINT64) IfrOneOf->data.u8.MinValue; DefaultData.Value = (UINT64) IfrOneOf->data.u8.MinValue;
break; break;
case EFI_IFR_NUMERIC_SIZE_2: case EFI_IFR_NUMERIC_SIZE_2:
CopyMem (&DefaultData->Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16)); CopyMem (&DefaultData.Value, &IfrOneOf->data.u16.MinValue, sizeof (UINT16));
break; break;
case EFI_IFR_NUMERIC_SIZE_4: case EFI_IFR_NUMERIC_SIZE_4:
CopyMem (&DefaultData->Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32)); CopyMem (&DefaultData.Value, &IfrOneOf->data.u32.MinValue, sizeof (UINT32));
break; break;
case EFI_IFR_NUMERIC_SIZE_8: case EFI_IFR_NUMERIC_SIZE_8:
CopyMem (&DefaultData->Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64)); CopyMem (&DefaultData.Value, &IfrOneOf->data.u64.MinValue, sizeof (UINT64));
break; break;
} }
// //
// Add DefaultValue into current BlockData // Set default value base on the DefaultId list get from IFR data.
// //
InsertDefaultValue (BlockData, DefaultData); 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);
}
} }
break; break;
@ -1411,28 +1399,24 @@ ParseIfrData (
// //
// Prepare new DefaultValue // Prepare new DefaultValue
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultData.DefaultId = VarDefaultId;
if (DefaultData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
DefaultData->OpCode = IfrOpHdr->OpCode;
DefaultData->DefaultId = VarDefaultId;
if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT) == EFI_IFR_CHECKBOX_DEFAULT) { if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT) == EFI_IFR_CHECKBOX_DEFAULT) {
// //
// When flag is set, defautl value is TRUE. // When flag is set, defautl value is TRUE.
// //
DefaultData->Value = 1; DefaultData.Type = DEFAULT_VALUE_FROM_FLAG;
DefaultData.Value = 1;
} else { } else {
// //
// When flag is not set, defautl value is FASLE. // When flag is not set, defautl value is FASLE.
// //
DefaultData->Value = 0; DefaultData.Type = DEFAULT_VALUE_FROM_DEFAULT;
DefaultData.Value = 0;
} }
// //
// Add DefaultValue into current BlockData // Add DefaultValue into current BlockData
// //
InsertDefaultValue (BlockData, DefaultData); InsertDefaultValue (BlockData, &DefaultData);
// //
// Add default value for Manufacture ID by CheckBox Flag // Add default value for Manufacture ID by CheckBox Flag
@ -1441,28 +1425,24 @@ ParseIfrData (
// //
// Prepare new DefaultValue // Prepare new DefaultValue
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultData.DefaultId = VarDefaultId;
if (DefaultData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
DefaultData->OpCode = IfrOpHdr->OpCode;
DefaultData->DefaultId = VarDefaultId;
if ((IfrCheckBox->Flags & EFI_IFR_CHECKBOX_DEFAULT_MFG) == EFI_IFR_CHECKBOX_DEFAULT_MFG) { 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, defautl value is TRUE.
// //
DefaultData->Value = 1; DefaultData.Type = DEFAULT_VALUE_FROM_FLAG;
DefaultData.Value = 1;
} else { } else {
// //
// When flag is not set, defautl value is FASLE. // When flag is not set, defautl value is FASLE.
// //
DefaultData->Value = 0; DefaultData.Type = DEFAULT_VALUE_FROM_DEFAULT;
DefaultData.Value = 0;
} }
// //
// Add DefaultValue into current BlockData // Add DefaultValue into current BlockData
// //
InsertDefaultValue (BlockData, DefaultData); InsertDefaultValue (BlockData, &DefaultData);
break; break;
case EFI_IFR_STRING_OP: case EFI_IFR_STRING_OP:
@ -1671,54 +1651,51 @@ ParseIfrData (
break; break;
} }
//
// 1. Set default value for OneOf option when flag field has default attribute.
//
if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) || if (((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) ||
(BlockData->OpCode == EFI_IFR_ONE_OF_OP && FirstOneOfOption)) { ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG)) {
// //
// This flag is used to specify whether this option is the first. Set it to FALSE for the following options. // This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
// The first oneof option value will be used as default value when no default value is specified. // The first oneof option value will be used as default value when no default value is specified.
// //
FirstOneOfOption = FALSE; FirstOneOfOption = FALSE;
//
// Set standard ID to Manufacture ID
//
VarDefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
//
// Prepare new DefaultValue // Prepare new DefaultValue
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultData.Type = DEFAULT_VALUE_FROM_FLAG;
if (DefaultData == NULL) { DefaultData.Value = IfrOneOfOption->Value.u64;
Status = EFI_OUT_OF_RESOURCES; if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT) == EFI_IFR_OPTION_DEFAULT) {
goto Done; DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
InsertDefaultValue (BlockData, &DefaultData);
}
if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG) {
DefaultData.DefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING;
InsertDefaultValue (BlockData, &DefaultData);
} }
DefaultData->OpCode = IfrOpHdr->OpCode;
DefaultData->DefaultId = VarDefaultId;
DefaultData->Value = IfrOneOfOption->Value.u64;
//
// Add DefaultValue into current BlockData
//
InsertDefaultValue (BlockData, DefaultData);
}
if ((IfrOneOfOption->Flags & EFI_IFR_OPTION_DEFAULT_MFG) == EFI_IFR_OPTION_DEFAULT_MFG) {
// }
// Set default ID to Manufacture ID
// //
VarDefaultId = EFI_HII_DEFAULT_CLASS_MANUFACTURING; // 2. Set as the default value when this is the first option.
// The first oneof option value will be used as default value when no default value is specified.
//
if (FirstOneOfOption) {
// This flag is used to specify whether this option is the first. Set it to FALSE for the following options.
FirstOneOfOption = FALSE;
// //
// Prepare new DefaultValue // Prepare new DefaultValue
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultData.Type = DEFAULT_VALUE_FROM_DEFAULT;
if (DefaultData == NULL) { DefaultData.Value = IfrOneOfOption->Value.u64;
Status = EFI_OUT_OF_RESOURCES; for (LinkData = DefaultIdArray->Entry.ForwardLink; LinkData != &DefaultIdArray->Entry; LinkData = LinkData->ForwardLink) {
goto Done; DefaultDataPtr = BASE_CR (LinkData, IFR_DEFAULT_DATA, Entry);
} DefaultData.DefaultId = DefaultDataPtr->DefaultId;
DefaultData->OpCode = IfrOpHdr->OpCode; InsertDefaultValue (BlockData, &DefaultData);
DefaultData->DefaultId = VarDefaultId; }
DefaultData->Value = IfrOneOfOption->Value.u64;
//
// Add DefaultValue into current BlockData
//
InsertDefaultValue (BlockData, DefaultData);
} }
break; break;
@ -1747,18 +1724,25 @@ ParseIfrData (
// //
// Prepare new DefaultValue // Prepare new DefaultValue
// //
DefaultData = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA)); DefaultData.Type = DEFAULT_VALUE_FROM_OPCODE;
if (DefaultData == NULL) { DefaultData.DefaultId = VarDefaultId;
Status = EFI_OUT_OF_RESOURCES; DefaultData.Value = IfrDefault->Value.u64;
goto Done;
// If the value field is expression, set the cleaned flag.
if (IfrDefault->Type == EFI_IFR_TYPE_OTHER) {
DefaultData.Cleaned = TRUE;
} }
DefaultData->OpCode = IfrOpHdr->OpCode;
DefaultData->DefaultId = VarDefaultId;
DefaultData->Value = IfrDefault->Value.u64;
// //
// Add DefaultValue into current BlockData // Add DefaultValue into current BlockData
// //
InsertDefaultValue (BlockData, DefaultData); 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
// use it.
//
DefaultData.Cleaned = FALSE;
break; break;
case EFI_IFR_END_OP: case EFI_IFR_END_OP:
// //
@ -1779,6 +1763,18 @@ ParseIfrData (
} }
Done: Done:
for (LinkData = VarStorageData->BlockEntry.ForwardLink; LinkData != &VarStorageData->BlockEntry; LinkData = LinkData->ForwardLink) {
BlockData = BASE_CR (LinkData, IFR_BLOCK_DATA, Entry);
for (LinkDefault = BlockData->DefaultValueEntry.ForwardLink; LinkDefault != &BlockData->DefaultValueEntry; ) {
DefaultDataPtr = BASE_CR (LinkDefault, IFR_DEFAULT_DATA, Entry);
LinkDefault = LinkDefault->ForwardLink;
if (DefaultDataPtr->Cleaned == TRUE) {
RemoveEntryList (&DefaultDataPtr->Entry);
FreePool (DefaultDataPtr);
}
}
}
return Status; return Status;
} }

View File

@ -80,9 +80,21 @@ typedef struct {
LIST_ENTRY DefaultValueEntry; // Link to its default value array LIST_ENTRY DefaultValueEntry; // Link to its default value array
} IFR_BLOCK_DATA; } IFR_BLOCK_DATA;
//
// Get default value from IFR data.
//
typedef enum {
DEFAULT_VALUE_FROM_DEFAULT = 0, // Get from the minimum or first one when not set default value.
DEFAULT_VALUE_FROM_FLAG, // Get default value from the defalut flag.
DEFAULT_VALUE_FROM_OPCODE // Get default value from default opcode, highest priority.
} DEFAULT_VALUE_TYPE;
typedef struct { typedef struct {
LIST_ENTRY Entry; LIST_ENTRY Entry;
UINT8 OpCode; DEFAULT_VALUE_TYPE Type;
BOOLEAN Cleaned; // Whether this value is cleaned
// TRUE Cleaned, the value can't be used
// FALSE Not cleaned, the value can be used.
UINT16 DefaultId; UINT16 DefaultId;
UINT64 Value; UINT64 Value;
} IFR_DEFAULT_DATA; } IFR_DEFAULT_DATA;