]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg PCD: Allow SkuId to be changed only once
authorStar Zeng <star.zeng@intel.com>
Tue, 28 Feb 2017 04:48:39 +0000 (12:48 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 16 Mar 2017 02:17:00 +0000 (10:17 +0800)
Current PI spec has no clear description about whether the
SkuId could be changed multiple times or not during one boot.

If the SkuId could be changed multiple times during one boot,
different modules may get inconsistent PCD values.
And DynamicHii PCD maps to UEFI variable, once one DynamicHii
PCD(UEFI variable) is set for one SkuId, then the PCD value
will be always from UEFI variable but not PCD database, even
the SkuId is set to other value.

This patch is to update PCD drivers to allow SkuId to be
changed only once during one boot.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Universal/PCD/Dxe/Pcd.c
MdeModulePkg/Universal/PCD/Pei/Pcd.c

index 1bb9098c04cf2fe118e4006a39ddc1889ded10ea..9d710bbf1fb7e72d62dbf345e9c026ae7d0f7941 100644 (file)
@@ -3,7 +3,7 @@
   produce the implementation of native PCD protocol and EFI_PCD_PROTOCOL defined in\r
   PI 1.4a Vol3.\r
 \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, 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
@@ -272,19 +272,38 @@ DxePcdSetSku (
   SKU_ID    *SkuIdTable;\r
   UINTN     Index;\r
 \r
+  if (SkuId == mPcdDatabase.DxeDb->SystemSkuId) {\r
+    //\r
+    // The input SKU Id is equal to current SKU Id, return directly.\r
+    //\r
+    return;\r
+  }\r
+\r
+  if (mPcdDatabase.DxeDb->SystemSkuId != (SKU_ID) 0) {\r
+    DEBUG ((DEBUG_ERROR, "PcdDxe - The SKU Id could be changed only once."));\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "PcdDxe - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
+      mPcdDatabase.DxeDb->SystemSkuId,\r
+      (SKU_ID) SkuId\r
+      ));\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
+\r
   SkuIdTable = (SKU_ID *) ((UINT8 *) mPcdDatabase.DxeDb + mPcdDatabase.DxeDb->SkuIdTableOffset);\r
   for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
     if (SkuId == SkuIdTable[Index + 1]) {\r
+      DEBUG ((EFI_D_INFO, "PcdDxe - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
       mPcdDatabase.DxeDb->SystemSkuId = (SKU_ID) SkuId;\r
       return;\r
     }\r
   }\r
 \r
   //\r
-  // Invalid input SkuId, the default SKU Id will be used for the system.\r
+  // Invalid input SkuId, the default SKU Id will be still used for the system.\r
   //\r
-  DEBUG ((EFI_D_INFO, "PcdDxe - Invalid input SkuId, the default SKU Id will be used.\n"));\r
-  mPcdDatabase.DxeDb->SystemSkuId = (SKU_ID) 0;\r
+  DEBUG ((EFI_D_INFO, "PcdDxe - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
   return;\r
 }\r
 \r
index 668860b61c6ccb3590a51002e578451731c76779..a3f7337ceca3b6665f8563d2a2b83c418eff10a0 100644 (file)
@@ -1,7 +1,7 @@
 /** @file \r
   All Pcd Ppi services are implemented here.\r
   \r
-Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -262,19 +262,39 @@ PeiPcdSetSku (
   UINTN             Index;\r
 \r
   PeiPcdDb = GetPcdDatabase();\r
+\r
+  if (SkuId == PeiPcdDb->SystemSkuId) {\r
+    //\r
+    // The input SKU Id is equal to current SKU Id, return directly.\r
+    //\r
+    return;\r
+  }\r
+\r
+  if (PeiPcdDb->SystemSkuId != (SKU_ID) 0) {\r
+    DEBUG ((DEBUG_ERROR, "PcdPei - The SKU Id could be changed only once."));\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "PcdPei - The SKU Id was set to 0x%lx already, it could not be set to 0x%lx any more.",\r
+      PeiPcdDb->SystemSkuId,\r
+      (SKU_ID) SkuId\r
+      ));\r
+    ASSERT (FALSE);\r
+    return;\r
+  }\r
+\r
   SkuIdTable = (SKU_ID *) ((UINT8 *) PeiPcdDb + PeiPcdDb->SkuIdTableOffset);\r
   for (Index = 0; Index < SkuIdTable[0]; Index++) {\r
     if (SkuId == SkuIdTable[Index + 1]) {\r
+      DEBUG ((EFI_D_INFO, "PcdPei - Set current SKU Id to 0x%lx.\n", (SKU_ID) SkuId));\r
       PeiPcdDb->SystemSkuId = (SKU_ID) SkuId;\r
       return;\r
     }\r
   }\r
 \r
   //\r
-  // Invalid input SkuId, the default SKU Id will be used for the system.\r
+  // Invalid input SkuId, the default SKU Id will be still used for the system.\r
   //\r
-  DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be used.\n"));\r
-  PeiPcdDb->SystemSkuId = (SKU_ID) 0;\r
+  DEBUG ((EFI_D_INFO, "PcdPei - Invalid input SkuId, the default SKU Id will be still used.\n"));\r
   return;\r
 }\r
 \r