Fix K8 issues in HiiDataBase

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8325 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lgao4 2009-05-18 12:12:56 +00:00
parent d7dfd027aa
commit 8567300ae4
3 changed files with 192 additions and 111 deletions

View File

@ -921,16 +921,17 @@ InternalHiiGetValueOfNumber (
} }
/** /**
This function shares the same logic to parse ConfigAltResp string This internal function parses IFR data to validate current setting.
for setting default value and validating current setting.
@param ConfigResp @param ConfigResp ConfigResp string contains the current setting.
@param HiiPackageList @param HiiPackageList Point to Hii package list.
@param PackageListLength @param PackageListLength The length of the pacakge.
@param VarGuid @param VarGuid Guid of the buffer storage.
@param VarName @param VarName Name of the buffer storage.
@retval EFI_SUCCESS @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 EFI_STATUS
EFIAPI EFIAPI
@ -1247,6 +1248,13 @@ InternalHiiValidateCurrentSetting (
// Check whether current value is the one of option. // Check whether current value is the one of option.
// //
//
// OneOf question is not in IFR Form. This IFR form is not valid.
//
if (IfrVarStore == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1298,6 +1306,13 @@ InternalHiiValidateCurrentSetting (
// Check the current value is in the numeric range. // Check the current value is in the numeric range.
// //
//
// Numeric question is not in IFR Form. This IFR form is not valid.
//
if (IfrVarStore == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1381,6 +1396,14 @@ InternalHiiValidateCurrentSetting (
// Check value is BOOLEAN type, only 0 and 1 is valid. // Check value is BOOLEAN type, only 0 and 1 is valid.
// //
//
// CheckBox question is not in IFR Form. This IFR form is not valid.
//
if (IfrVarStore == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1428,6 +1451,14 @@ InternalHiiValidateCurrentSetting (
// Check current string length is less than maxsize // Check current string length is less than maxsize
// //
//
// CheckBox question is not in IFR Form. This IFR form is not valid.
//
if (IfrVarStore == NULL) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1558,8 +1589,8 @@ Done:
} }
/** /**
This function shares the same logic to parse ConfigAltResp string This function parses the input ConfigRequest string and its matched IFR code
for setting default value and validating current setting. string for setting default value and validating current setting.
1. For setting default action, Reset the default value specified by DefaultId 1. For setting default action, Reset the default value specified by DefaultId
to the driver configuration got by Request string. to the driver configuration got by Request string.

View File

@ -577,6 +577,10 @@ MergeDefaultString (
SizeAltCfgResp + StrSize (StringPtrDefault), SizeAltCfgResp + StrSize (StringPtrDefault),
(VOID *) (*AltCfgResp) (VOID *) (*AltCfgResp)
); );
if (*AltCfgResp == NULL) {
FreePool (AltConfigHdr);
return EFI_OUT_OF_RESOURCES;
}
StrCat (*AltCfgResp, StringPtrDefault); StrCat (*AltCfgResp, StringPtrDefault);
break; break;
} else { } else {
@ -599,6 +603,7 @@ MergeDefaultString (
StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr); StringPtrDefault = StrStr (StringPtrDefault + 1, AltConfigHdr);
} }
FreePool (AltConfigHdr);
return EFI_SUCCESS; return EFI_SUCCESS;
} }
@ -796,7 +801,7 @@ ParseIfrData (
IN EFI_STRING ConfigHdr, IN EFI_STRING ConfigHdr,
IN IFR_BLOCK_DATA *RequestBlockArray, IN IFR_BLOCK_DATA *RequestBlockArray,
IN OUT IFR_VARSTORAGE_DATA *VarStorageData, IN OUT IFR_VARSTORAGE_DATA *VarStorageData,
OUT IFR_DEFAULT_DATA **PIfrDefaultIdArray OUT IFR_DEFAULT_DATA *DefaultIdArray
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
@ -810,7 +815,6 @@ 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 *DefaultIdArray;
IFR_DEFAULT_DATA *DefaultData; IFR_DEFAULT_DATA *DefaultData;
IFR_BLOCK_DATA *BlockData; IFR_BLOCK_DATA *BlockData;
CHAR16 *VarStoreName; CHAR16 *VarStoreName;
@ -823,9 +827,6 @@ ParseIfrData (
EFI_STRING TempStr; EFI_STRING TempStr;
UINTN LengthString; UINTN LengthString;
//
// Initialize DefaultIdArray to store the map between DeaultId and DefaultName
//
LengthString = 0; LengthString = 0;
Status = EFI_SUCCESS; Status = EFI_SUCCESS;
GuidStr = NULL; GuidStr = NULL;
@ -833,11 +834,6 @@ ParseIfrData (
TempStr = NULL; TempStr = NULL;
BlockData = NULL; BlockData = NULL;
DefaultData = NULL; DefaultData = NULL;
DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));
if (DefaultIdArray == NULL) {
return EFI_OUT_OF_RESOURCES;
}
InitializeListHead (&DefaultIdArray->Entry);
// //
// Go through the form package to parse OpCode one by one. // Go through the form package to parse OpCode one by one.
@ -935,6 +931,13 @@ ParseIfrData (
// Numeric and OneOf has the same opcode structure. // Numeric and OneOf has the same opcode structure.
// //
//
// Numeric and OneOf question is not in IFR Form. This IFR form is not valid.
//
if (VarStorageData->Size == 0) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -993,6 +996,13 @@ ParseIfrData (
// no default value and default id, how to define its default value? // no default value and default id, how to define its default value?
// //
//
// OrderedList question is not in IFR Form. This IFR form is not valid.
//
if (VarStorageData->Size == 0) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1056,6 +1066,13 @@ ParseIfrData (
// default id by DeaultOption DefaultId can override CheckBox Flags and Default value. // default id by DeaultOption DefaultId can override CheckBox Flags and Default value.
// //
//
// CheckBox question is not in IFR Form. This IFR form is not valid.
//
if (VarStorageData->Size == 0) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1170,6 +1187,13 @@ ParseIfrData (
// no default value, only block array // no default value, only block array
// //
//
// String question is not in IFR Form. This IFR form is not valid.
//
if (VarStorageData->Size == 0) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1234,6 +1258,13 @@ ParseIfrData (
// no default value, only block array // no default value, only block array
// //
//
// Password question is not in IFR Form. This IFR form is not valid.
//
if (VarStorageData->Size == 0) {
Status = EFI_INVALID_PARAMETER;
goto Done;
}
// //
// Check whether this question is for the requested varstore. // Check whether this question is for the requested varstore.
// //
@ -1424,7 +1455,7 @@ ParseIfrData (
break; break;
case EFI_IFR_END_OP: case EFI_IFR_END_OP:
// //
// End Opcode is for Var. // End Opcode is for Var question.
// //
if (BlockData != NULL && BlockData->Scope > 0) { if (BlockData != NULL && BlockData->Scope > 0) {
BlockData->Scope--; BlockData->Scope--;
@ -1441,11 +1472,6 @@ ParseIfrData (
} }
Done: Done:
//
// Set the defualt ID array.
//
*PIfrDefaultIdArray = DefaultIdArray;
return Status; return Status;
} }
@ -1456,7 +1482,7 @@ Done:
When Request points to NULL string, the request string and default value string When Request points to NULL string, the request string and default value string
for each varstore in form package will return. for each varstore in form package will return.
@param HiiHandle Hii Handle which Hii Packages are registered. @param DataBaseRecord The DataBaseRecord instance contains the found Hii handle and package.
@param DevicePath Device Path which Hii Config Access Protocol is registered. @param DevicePath Device Path which Hii Config Access Protocol is registered.
@param Request Pointer to a null-terminated Unicode string in @param Request Pointer to a null-terminated Unicode string in
<ConfigRequest> format. When it doesn't contain <ConfigRequest> format. When it doesn't contain
@ -1486,24 +1512,22 @@ Done:
EFI_STATUS EFI_STATUS
EFIAPI EFIAPI
GetFullStringFromHiiFormPackages ( GetFullStringFromHiiFormPackages (
IN EFI_HII_HANDLE HiiHandle, IN HII_DATABASE_RECORD *DataBaseRecord,
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
IN OUT EFI_STRING *Request, IN OUT EFI_STRING *Request,
IN OUT EFI_STRING *AltCfgResp IN OUT EFI_STRING *AltCfgResp
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_HII_PACKAGE_LIST_HEADER *HiiPackageList; UINT8 *HiiFormPackage;
UINT32 PackageListLength; UINTN PackageSize;
UINTN BufferSize; UINTN ResultSize;
IFR_BLOCK_DATA *RequestBlockArray; IFR_BLOCK_DATA *RequestBlockArray;
IFR_BLOCK_DATA *BlockData; IFR_BLOCK_DATA *BlockData;
IFR_BLOCK_DATA *NextBlockData; IFR_BLOCK_DATA *NextBlockData;
IFR_DEFAULT_DATA *DefaultValueData; IFR_DEFAULT_DATA *DefaultValueData;
IFR_DEFAULT_DATA *DefaultId; IFR_DEFAULT_DATA *DefaultId;
IFR_DEFAULT_DATA *DefaultIdArray; IFR_DEFAULT_DATA *DefaultIdArray;
EFI_HII_PACKAGE_HEADER PacakgeHeader;
UINT32 PackageOffset;
IFR_VARSTORAGE_DATA *VarStorageData; IFR_VARSTORAGE_DATA *VarStorageData;
EFI_STRING DefaultAltCfgResp; EFI_STRING DefaultAltCfgResp;
EFI_STRING FullConfigRequest; EFI_STRING FullConfigRequest;
@ -1524,63 +1548,60 @@ GetFullStringFromHiiFormPackages (
// Initialize the local variables. // Initialize the local variables.
// //
RequestBlockArray = NULL; RequestBlockArray = NULL;
DefaultIdArray = NULL;
VarStorageData = NULL; VarStorageData = NULL;
DefaultAltCfgResp = NULL; DefaultAltCfgResp = NULL;
FullConfigRequest = NULL; FullConfigRequest = NULL;
ConfigHdr = NULL; ConfigHdr = NULL;
DefaultIdArray = NULL;
GuidStr = NULL; GuidStr = NULL;
NameStr = NULL; NameStr = NULL;
PathStr = NULL; PathStr = NULL;
HiiFormPackage = NULL;
ResultSize = 0;
PackageSize = 0;
// //
// 1. Get HiiPackage by HiiHandle // 0. Get Hii Form Package by HiiHandle
// //
BufferSize = 0; Status = ExportFormPackages (
HiiPackageList = NULL; &mPrivate,
Status = HiiExportPackageLists (&mPrivate.HiiDatabase, HiiHandle, &BufferSize, HiiPackageList); DataBaseRecord->Handle,
DataBaseRecord->PackageList,
// 0,
// The return status should always be EFI_BUFFER_TOO_SMALL as input buffer's size is 0. PackageSize,
// HiiFormPackage,
if (Status != EFI_BUFFER_TOO_SMALL) { &ResultSize
);
if (EFI_ERROR (Status)) {
return Status; return Status;
} }
HiiPackageList = AllocatePool (BufferSize); HiiFormPackage = AllocatePool (ResultSize);
if (HiiPackageList == NULL) { if (HiiFormPackage == NULL) {
return EFI_OUT_OF_RESOURCES; Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
// //
// Get PackageList on HiiHandle // Get HiiFormPackage by HiiHandle
// //
Status = HiiExportPackageLists (&mPrivate.HiiDatabase, HiiHandle, &BufferSize, HiiPackageList); PackageSize = ResultSize;
ResultSize = 0;
Status = ExportFormPackages (
&mPrivate,
DataBaseRecord->Handle,
DataBaseRecord->PackageList,
0,
PackageSize,
HiiFormPackage,
&ResultSize
);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
// //
// 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray. // 1. Get the request block array by Request String when Request string containts the block array.
// 1) Request is NULL.
// 2) Request is not NULL. And it doesn't contain any BlockArray.
// 3) Request is not NULL. And it containts BlockArray.
//
//
// Initialize VarStorageData to store the var store Block and Default value information.
//
VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA));
if (VarStorageData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
}
InitializeListHead (&VarStorageData->Entry);
InitializeListHead (&VarStorageData->BlockEntry);
//
// Gte the request block array by Request String
// //
StringPtr = NULL; StringPtr = NULL;
if (*Request != NULL) { if (*Request != NULL) {
@ -1695,39 +1716,36 @@ GetFullStringFromHiiFormPackages (
} }
// //
// Get the form package // 2. Parse FormPackage to get BlockArray and DefaultId Array for the request BlockArray.
// //
PackageOffset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);
PackageListLength = ReadUnaligned32 (&HiiPackageList->PackageLength);
while (PackageOffset < PackageListLength) {
CopyMem (&PacakgeHeader, (UINT8 *) HiiPackageList + PackageOffset, sizeof (PacakgeHeader));
if (PacakgeHeader.Type == EFI_HII_PACKAGE_FORMS) {
//
// Reset VarStorageData
//
VarStorageData->Size = 0;
VarStorageData->VarStoreId = 0;
if (VarStorageData->Name != NULL) {
FreePool (VarStorageData->Name);
VarStorageData->Name = NULL;
}
// //
// Parse the opcode in form package // Initialize DefaultIdArray to store the map between DeaultId and DefaultName
// //
Status = ParseIfrData ((UINT8 *) HiiPackageList + PackageOffset, PacakgeHeader.Length, *Request, RequestBlockArray, VarStorageData, &DefaultIdArray); DefaultIdArray = (IFR_DEFAULT_DATA *) AllocateZeroPool (sizeof (IFR_DEFAULT_DATA));
if (EFI_ERROR (Status)) { if (DefaultIdArray == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done; goto Done;
} }
InitializeListHead (&DefaultIdArray->Entry);
// //
// Only one form is in a pacakge list. // Initialize VarStorageData to store the var store Block and Default value information.
// //
break; VarStorageData = (IFR_VARSTORAGE_DATA *) AllocateZeroPool (sizeof (IFR_VARSTORAGE_DATA));
if (VarStorageData == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto Done;
} }
InitializeListHead (&VarStorageData->Entry);
InitializeListHead (&VarStorageData->BlockEntry);
PackageOffset += PacakgeHeader.Length; //
// Parse the opcode in form pacakge to get the default setting.
//
Status = ParseIfrData (HiiFormPackage, (UINT32) PackageSize, *Request, RequestBlockArray, VarStorageData, DefaultIdArray);
if (EFI_ERROR (Status)) {
goto Done;
} }
// //
@ -2011,8 +2029,8 @@ Done:
// //
// Free Pacakge data // Free Pacakge data
// //
if (HiiPackageList != NULL) { if (HiiFormPackage != NULL) {
FreePool (HiiPackageList); FreePool (HiiFormPackage);
} }
return Status; return Status;
@ -2158,6 +2176,7 @@ HiiConfigRoutingExtractConfig (
// //
DriverHandle = NULL; DriverHandle = NULL;
HiiHandle = NULL; HiiHandle = NULL;
Database = NULL;
DevicePathLength = GetDevicePathSize (DevicePath); DevicePathLength = GetDevicePathSize (DevicePath);
for (Link = Private->DatabaseList.ForwardLink; for (Link = Private->DatabaseList.ForwardLink;
Link != &Private->DatabaseList; Link != &Private->DatabaseList;
@ -2208,7 +2227,7 @@ HiiConfigRoutingExtractConfig (
// //
// Get the full request string from IFR when HiiPackage is registered to HiiHandle // Get the full request string from IFR when HiiPackage is registered to HiiHandle
// //
Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &DefaultResults); Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
goto Done; goto Done;
} }
@ -2257,7 +2276,7 @@ HiiConfigRoutingExtractConfig (
// //
if (HiiHandle != NULL) { if (HiiHandle != NULL) {
if (DefaultResults == NULL) { if (DefaultResults == NULL) {
Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &AccessResults); Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &AccessResults);
} else { } else {
Status = MergeDefaultString (&AccessResults, DefaultResults); Status = MergeDefaultString (&AccessResults, DefaultResults);
} }
@ -2425,6 +2444,7 @@ HiiConfigRoutingExportConfig (
HiiHandle = NULL; HiiHandle = NULL;
ConfigRequest = NULL; ConfigRequest = NULL;
DefaultResults = NULL; DefaultResults = NULL;
Database = NULL;
DevicePath = DevicePathFromHandle (ConfigAccessHandles[Index]); DevicePath = DevicePathFromHandle (ConfigAccessHandles[Index]);
DevicePathLength = GetDevicePathSize (DevicePath); DevicePathLength = GetDevicePathSize (DevicePath);
if (DevicePath != NULL) { if (DevicePath != NULL) {
@ -2452,7 +2472,7 @@ HiiConfigRoutingExportConfig (
// Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle // Update AccessResults by getting default setting from IFR when HiiPackage is registered to HiiHandle
// //
if (HiiHandle != NULL && DevicePath != NULL) { if (HiiHandle != NULL && DevicePath != NULL) {
Status = GetFullStringFromHiiFormPackages (HiiHandle, DevicePath, &ConfigRequest, &DefaultResults); Status = GetFullStringFromHiiFormPackages (Database, DevicePath, &ConfigRequest, &DefaultResults);
} }
// //
// Can't parse IFR data to get the request string and default string. // Can't parse IFR data to get the request string and default string.
@ -2473,8 +2493,10 @@ HiiConfigRoutingExportConfig (
// Merge the default sting from IFR code into the got setting from driver. // Merge the default sting from IFR code into the got setting from driver.
// //
if (DefaultResults != NULL) { if (DefaultResults != NULL) {
MergeDefaultString (&AccessResults, DefaultResults); Status = MergeDefaultString (&AccessResults, DefaultResults);
ASSERT_EFI_ERROR (Status);
FreePool (DefaultResults); FreePool (DefaultResults);
DefaultResults = NULL;
} }
// //

View File

@ -484,6 +484,34 @@ FindGlyphBlock (
OUT UINTN *GlyphBufferLen OPTIONAL OUT UINTN *GlyphBufferLen OPTIONAL
); );
/**
This function exports Form packages to a buffer.
This is a internal function.
@param Private Hii database private structure.
@param Handle Identification of a package list.
@param PackageList Pointer to a package list which will be exported.
@param UsedSize The length of buffer be used.
@param BufferSize Length of the Buffer.
@param Buffer Allocated space for storing exported data.
@param ResultSize The size of the already exported content of this
package list.
@retval EFI_SUCCESS Form Packages are exported successfully.
@retval EFI_INVALID_PARAMETER Any input parameter is invalid.
**/
EFI_STATUS
ExportFormPackages (
IN HII_DATABASE_PRIVATE_DATA *Private,
IN EFI_HII_HANDLE Handle,
IN HII_DATABASE_PACKAGE_LIST_INSTANCE *PackageList,
IN UINTN UsedSize,
IN UINTN BufferSize,
IN OUT VOID *Buffer,
IN OUT UINTN *ResultSize
);
// //
// EFI_HII_FONT_PROTOCOL protocol interfaces // EFI_HII_FONT_PROTOCOL protocol interfaces
// //