X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FVariable%2FPei%2FVariable.c;h=77b3eaeb210ddfcf91e249d6ce1304f0638098be;hp=c68a41ddfe7dcb57b8479d54241774c8ad49af6d;hb=4063d37c6a96f534abb0d2861776648fb453ca4d;hpb=77ba12cc618cac1bf9b0200414828d6267791961 diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePkg/Universal/Variable/Pei/Variable.c index c68a41ddfe..77b3eaeb21 100644 --- a/MdeModulePkg/Universal/Variable/Pei/Variable.c +++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c @@ -2,7 +2,7 @@ Implement ReadOnly Variable Services required by PEIM and install PEI ReadOnly Varaiable2 PPI. These services operates the non volatile storage space. -Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2018, 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 @@ -57,7 +57,7 @@ PeimInitializeVariableServices ( @param VarStoreHeader Pointer to the Variable Store Header. - @return Pointer to the first variable header + @return Pointer to the first variable header. **/ VARIABLE_HEADER * @@ -66,18 +66,22 @@ GetStartPointer ( ) { // - // The end of variable store + // The start of variable store // return (VARIABLE_HEADER *) HEADER_ALIGN (VarStoreHeader + 1); } /** - This code gets the pointer to the last variable memory pointer byte. - @param VarStoreHeader Pointer to the Variable Store Header. + Gets the pointer to the end of the variable storage area. + + This function gets pointer to the end of the variable storage + area, according to the input variable store header. + + @param VarStoreHeader Pointer to the Variable Store Header. - @return VARIABLE_HEADER* pointer to last unavailable Variable Header. + @return Pointer to the end of the variable storage area. **/ VARIABLE_HEADER * @@ -495,6 +499,58 @@ CompareWithValidVariable ( return EFI_NOT_FOUND; } +/** + Get HOB variable store. + + @param[out] StoreInfo Return the store info. + @param[out] VariableStoreHeader Return variable store header. + +**/ +VOID +GetHobVariableStore ( + OUT VARIABLE_STORE_INFO *StoreInfo, + OUT VARIABLE_STORE_HEADER **VariableStoreHeader + ) +{ + EFI_HOB_GUID_TYPE *GuidHob; + + // + // Make sure there is no more than one Variable HOB. + // + DEBUG_CODE ( + GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob != NULL) { + if ((GetNextGuidHob (&gEfiAuthenticatedVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Auth Variable HOBs\n")); + ASSERT (FALSE); + } else if (GetFirstGuidHob (&gEfiVariableGuid) != NULL) { + DEBUG ((DEBUG_ERROR, "ERROR: Found one Auth + one Normal Variable HOBs\n")); + ASSERT (FALSE); + } + } else { + GuidHob = GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob != NULL) { + if ((GetNextGuidHob (&gEfiVariableGuid, GET_NEXT_HOB (GuidHob)) != NULL)) { + DEBUG ((DEBUG_ERROR, "ERROR: Found two Normal Variable HOBs\n")); + ASSERT (FALSE); + } + } + } + ); + + GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); + if (GuidHob != NULL) { + *VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + StoreInfo->AuthFlag = TRUE; + } else { + GuidHob = GetFirstGuidHob (&gEfiVariableGuid); + if (GuidHob != NULL) { + *VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); + StoreInfo->AuthFlag = FALSE; + } + } +} + /** Return the variable store header and the store info based on the Index. @@ -523,17 +579,8 @@ GetVariableStore ( VariableStoreHeader = NULL; switch (Type) { case VariableStoreTypeHob: - GuidHob = GetFirstGuidHob (&gEfiAuthenticatedVariableGuid); - if (GuidHob != NULL) { - VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); - StoreInfo->AuthFlag = TRUE; - } else { - GuidHob = GetFirstGuidHob (&gEfiVariableGuid); - if (GuidHob != NULL) { - VariableStoreHeader = (VARIABLE_STORE_HEADER *) GET_GUID_HOB_DATA (GuidHob); - StoreInfo->AuthFlag = FALSE; - } - } + GetHobVariableStore (StoreInfo, &VariableStoreHeader); + break; case VariableStoreTypeNv: @@ -947,9 +994,10 @@ FindVariable ( @param DataSize On entry, points to the size in bytes of the Data buffer. On return, points to the size of the data returned in Data. @param Data Points to the buffer which will hold the returned variable value. + May be NULL with a zero DataSize in order to determine the size of the buffer needed. @retval EFI_SUCCESS The variable was read successfully. - @retval EFI_NOT_FOUND The variable could not be found. + @retval EFI_NOT_FOUND The variable was be found. @retval EFI_BUFFER_TOO_SMALL The DataSize is too small for the resulting data. DataSize is updated with the size required for the specified variable. @@ -965,7 +1013,7 @@ PeiGetVariable ( IN CONST EFI_GUID *VariableGuid, OUT UINT32 *Attributes, IN OUT UINTN *DataSize, - OUT VOID *Data + OUT VOID *Data OPTIONAL ) { VARIABLE_POINTER_TRACK Variable; @@ -978,6 +1026,10 @@ PeiGetVariable ( return EFI_INVALID_PARAMETER; } + if (VariableName[0] == 0) { + return EFI_NOT_FOUND; + } + VariableHeader = NULL; //