]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp
Sync BaseTools Branch (version r2149) to EDKII main trunk.
[mirror_edk2.git] / BaseTools / Source / C / VfrCompile / VfrUtilityLib.cpp
index 3797cd822841d2f5eaa4c78fecdeef6428539be4..b839a0ab0e6a7d8ed98f97b22f5a4275429e3337 100644 (file)
@@ -2,7 +2,7 @@
   \r
   Vfr common library functions.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -622,6 +622,9 @@ CVfrVarDataTypeDB::ExtractFieldNameAndArrary (
     if (*VarStr == ']') {\r
       VarStr++;\r
     }\r
+    if (*VarStr == '.') {\r
+      VarStr++;\r
+    }\r
     return VFR_RETURN_SUCCESS;\r
   case ']':\r
     return VFR_RETURN_DATA_STRING_ERROR;\r
@@ -1456,10 +1459,8 @@ CVfrDataStorage::DeclareNameVarStoreBegin (
     return VFR_RETURN_FATAL_ERROR;\r
   }\r
 \r
-  for (pNode = mNameVarStoreList; pNode != NULL; pNode = pNode->mNext) {\r
-    if (strcmp (pNode->mVarStoreName, StoreName) == 0) {\r
-      return VFR_RETURN_REDEFINED;\r
-    }\r
+  if (GetVarStoreId (StoreName, &VarStoreId) == VFR_RETURN_SUCCESS) {\r
+    return VFR_RETURN_REDEFINED;\r
   }\r
 \r
   VarStoreId = GetFreeVarStoreId (EFI_VFR_VARSTORE_NAME);\r
@@ -1531,10 +1532,8 @@ CVfrDataStorage::DeclareEfiVarStore (
     return VFR_RETURN_EFIVARSTORE_SIZE_ERROR;\r
   }\r
 \r
-  for (pNode = mEfiVarStoreList; pNode != NULL; pNode = pNode->mNext) {\r
-    if (strcmp (pNode->mVarStoreName, StoreName) == 0) {\r
-      return VFR_RETURN_REDEFINED;\r
-    }\r
+  if (GetVarStoreId (StoreName, &VarStoreId) == VFR_RETURN_SUCCESS) {\r
+    return VFR_RETURN_REDEFINED;\r
   }\r
 \r
   VarStoreId = GetFreeVarStoreId (EFI_VFR_VARSTORE_EFI);\r
@@ -1560,11 +1559,16 @@ CVfrDataStorage::DeclareBufferVarStore (
 {\r
   SVfrVarStorageNode   *pNew = NULL;\r
   SVfrDataType         *pDataType = NULL;\r
+  EFI_VARSTORE_ID      TempVarStoreId;\r
 \r
   if ((StoreName == NULL) || (Guid == NULL) || (DataTypeDB == NULL)) {\r
     return VFR_RETURN_FATAL_ERROR;\r
   }\r
 \r
+  if (GetVarStoreId (StoreName, &TempVarStoreId) == VFR_RETURN_SUCCESS) {\r
+    return VFR_RETURN_REDEFINED;\r
+  }\r
+\r
   CHECK_ERROR_RETURN(DataTypeDB->GetDataType (TypeName, &pDataType), VFR_RETURN_SUCCESS);\r
 \r
   if (VarStoreId == EFI_VARSTORE_ID_INVALID) {\r
@@ -1590,12 +1594,51 @@ CVfrDataStorage::DeclareBufferVarStore (
   return VFR_RETURN_SUCCESS;\r
 }\r
 \r
+EFI_VFR_RETURN_CODE \r
+CVfrDataStorage::GetVarStoreByDataType (\r
+  IN  CHAR8              *DataTypeName,\r
+  OUT SVfrVarStorageNode **VarNode\r
+  )\r
+{\r
+  SVfrVarStorageNode    *pNode;\r
+  SVfrVarStorageNode    *MatchNode;\r
+  \r
+  //\r
+  // Framework VFR uses Data type name as varstore name, so don't need check again.\r
+  //\r
+  if (VfrCompatibleMode) {\r
+    return VFR_RETURN_UNDEFINED;\r
+  }\r
+\r
+  MatchNode = NULL;\r
+  for (pNode = mBufferVarStoreList; pNode != NULL; pNode = pNode->mNext) {\r
+    if (strcmp (pNode->mStorageInfo.mDataType->mTypeName, DataTypeName) == 0) {\r
+      if (MatchNode == NULL) {\r
+        MatchNode = pNode;\r
+      } else {\r
+        //\r
+        // More than one varstores referred the same data structures.\r
+        //\r
+        return VFR_RETURN_VARSTORE_DATATYPE_REDEFINED_ERROR;\r
+      }\r
+    }\r
+  }\r
+  \r
+  if (MatchNode == NULL) {\r
+    return VFR_RETURN_UNDEFINED;\r
+  }\r
+\r
+  *VarNode = MatchNode;\r
+  return VFR_RETURN_SUCCESS;\r
+}\r
+\r
 EFI_VFR_RETURN_CODE \r
 CVfrDataStorage::GetVarStoreId (\r
   IN  CHAR8           *StoreName,\r
   OUT EFI_VARSTORE_ID *VarStoreId\r
   )\r
 {\r
+  EFI_VFR_RETURN_CODE   ReturnCode;\r
   SVfrVarStorageNode    *pNode;\r
 \r
   for (pNode = mBufferVarStoreList; pNode != NULL; pNode = pNode->mNext) {\r
@@ -1623,8 +1666,18 @@ CVfrDataStorage::GetVarStoreId (
   }\r
 \r
   mCurrVarStorageNode = NULL;\r
-  *VarStoreId        = EFI_VARSTORE_ID_INVALID;\r
-  return VFR_RETURN_UNDEFINED;\r
+  *VarStoreId         = EFI_VARSTORE_ID_INVALID;\r
+\r
+  //\r
+  // Assume that Data strucutre name is used as StoreName, and check again. \r
+  //\r
+  ReturnCode = GetVarStoreByDataType (StoreName, &pNode);\r
+  if (pNode != NULL) {\r
+    mCurrVarStorageNode = pNode;\r
+    *VarStoreId = pNode->mVarStoreId;\r
+  }\r
+  \r
+  return ReturnCode;\r
 }\r
 \r
 EFI_VFR_RETURN_CODE\r
@@ -1634,6 +1687,7 @@ CVfrDataStorage::GetBufferVarStoreDataTypeName (
   )\r
 {\r
   SVfrVarStorageNode    *pNode;\r
+  EFI_VFR_RETURN_CODE   ReturnCode;\r
 \r
   if ((StoreName == NULL) || (DataTypeName == NULL)) {\r
     return VFR_RETURN_FATAL_ERROR;\r
@@ -1645,8 +1699,16 @@ CVfrDataStorage::GetBufferVarStoreDataTypeName (
     }\r
   }\r
 \r
+  ReturnCode = VFR_RETURN_UNDEFINED;\r
+  //\r
+  // Assume that Data strucutre name is used as StoreName, and check again. \r
+  //\r
   if (pNode == NULL) {\r
-    return VFR_RETURN_UNDEFINED;\r
+    ReturnCode = GetVarStoreByDataType (StoreName, &pNode);\r
+  }\r
+\r
+  if (pNode == NULL) {\r
+    return ReturnCode;\r
   }\r
 \r
   if (pNode->mStorageInfo.mDataType == NULL) {\r
@@ -1664,6 +1726,7 @@ CVfrDataStorage::GetVarStoreType (
   )\r
 {\r
   SVfrVarStorageNode    *pNode;\r
+  EFI_VFR_RETURN_CODE   ReturnCode;\r
 \r
   if (StoreName == NULL) {\r
     return VFR_RETURN_FATAL_ERROR;\r
@@ -1691,7 +1754,16 @@ CVfrDataStorage::GetVarStoreType (
   }\r
 \r
   VarStoreType = EFI_VFR_VARSTORE_INVALID;\r
-  return VFR_RETURN_UNDEFINED;\r
+\r
+  //\r
+  // Assume that Data strucutre name is used as StoreName, and check again. \r
+  //\r
+  ReturnCode = GetVarStoreByDataType (StoreName, &pNode);\r
+  if (pNode != NULL) {\r
+    VarStoreType = pNode->mVarStoreType;\r
+  }\r
+  \r
+  return ReturnCode;\r
 }\r
 \r
 EFI_VFR_VARSTORE_TYPE\r
@@ -1841,6 +1913,7 @@ CVfrDataStorage::BufferVarStoreRequestElementAdd (
 {\r
   SVfrVarStorageNode    *pNode = NULL;\r
   EFI_IFR_TYPE_VALUE    Value = gZeroEfiIfrTypeValue;\r
+  EFI_VFR_RETURN_CODE   ReturnCode;\r
 \r
   for (pNode = mBufferVarStoreList; pNode != NULL; pNode = pNode->mNext) {\r
     if (strcmp (pNode->mVarStoreName, StoreName) == 0) {\r
@@ -1848,8 +1921,16 @@ CVfrDataStorage::BufferVarStoreRequestElementAdd (
     }\r
   }\r
 \r
+  ReturnCode = VFR_RETURN_UNDEFINED;\r
+  //\r
+  // Assume that Data strucutre name is used as StoreName, and check again. \r
+  //\r
   if (pNode == NULL) {\r
-    return VFR_RETURN_UNDEFINED;\r
+    ReturnCode = GetVarStoreByDataType (StoreName, &pNode);\r
+  }\r
+\r
+  if (pNode == NULL) {\r
+    return ReturnCode;\r
   }\r
 \r
   gCVfrBufferConfig.Open ();\r