public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable.
@ 2018-10-18  7:12 Zhaozh1x
  2018-10-21 10:47 ` Feng, Bob C
  2018-10-24  7:26 ` Feng, Bob C
  0 siblings, 2 replies; 4+ messages in thread
From: Zhaozh1x @ 2018-10-18  7:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: Zhaozh1x, Liming Gao, Yonghong Zhu, Bob Feng

V2:
Make the code of patch both compatible for Python2 and Python3.

V1:
If different PCDs refer to the same EFI variable, then do EFI variable
combination, according to the VariableOffset of different PCDS.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: ZhiqiangX Zhao <zhiqiangx.zhao@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
---
 BaseTools/Source/Python/AutoGen/GenVar.py | 97 ++++++++++---------------------
 1 file changed, 30 insertions(+), 67 deletions(-)

diff --git a/BaseTools/Source/Python/AutoGen/GenVar.py b/BaseTools/Source/Python/AutoGen/GenVar.py
index 036f00e2bb..98f88e2497 100644
--- a/BaseTools/Source/Python/AutoGen/GenVar.py
+++ b/BaseTools/Source/Python/AutoGen/GenVar.py
@@ -56,51 +56,7 @@ class VariableMgr(object):
         value_str += ",".join(default_var_bin_strip)
         value_str += "}"
         return value_str
-    def Do_combine(self,sku_var_info_offset_list):
-        newvalue = {}
-        for item in sku_var_info_offset_list:
-            data_type = item.data_type
-            value_list = item.default_value.strip("{").strip("}").split(",")
-            if data_type in DataType.TAB_PCD_NUMERIC_TYPES:
-                data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]]
-                data = value_list[0]
-                value_list = []
-                for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)):
-                    value_list.append(hex(unpack("B", data_byte)[0]))
-            newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = value_list
-        try:
-            newvaluestr = "{" + ",".join(VariableMgr.assemble_variable(newvalue)) +"}"
-        except:
-            EdkLogger.error("build", AUTOGEN_ERROR, "Variable offset conflict in PCDs: %s \n" % (" and ".join(item.pcdname for item in sku_var_info_offset_list)))
-        return newvaluestr
-    def Do_Merge(self,sku_var_info_offset_list):
-        StructrurePcds = sorted([item for item in sku_var_info_offset_list if item.StructurePcd], key = lambda x: x.PcdDscLine, reverse =True )
-        Base = StructrurePcds[0]
-        BaseValue = Base.default_value.strip("{").strip("}").split(",")
-        Override = [item for item in sku_var_info_offset_list if not item.StructurePcd and item.PcdDscLine > Base.PcdDscLine]
-        newvalue = {}
-        for item in Override:
-            data_type = item.data_type
-            value_list = item.default_value.strip("{").strip("}").split(",")
-            if data_type in DataType.TAB_PCD_NUMERIC_TYPES:
-                data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[data_type]]
-                data = value_list[0]
-                value_list = []
-                for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)):
-                    value_list.append(hex(unpack("B", data_byte)[0]))
-            newvalue[int(item.var_offset, 16) if item.var_offset.upper().startswith("0X") else int(item.var_offset)] = (value_list,item.pcdname,item.PcdDscLine)
-        for offset in newvalue:
-            value_list,itemPcdname,itemPcdDscLine = newvalue[offset]
-            if offset > len(BaseValue) or (offset + len(value_list) > len(BaseValue)):
-                EdkLogger.error("build", AUTOGEN_ERROR, "The EFI Variable referred by PCD %s in line %s exceeds variable size: %s\n" % (itemPcdname,itemPcdDscLine,hex(len(BaseValue))))
-            for i in xrange(len(value_list)):
-                BaseValue[offset + i] = value_list[i]
-        newvaluestr =  "{" + ",".join(BaseValue) +"}"
-        return newvaluestr
-    def NeedMerge(self,sku_var_info_offset_list):
-        if [item for item in sku_var_info_offset_list if item.StructurePcd]:
-            return True
-        return False
+
     def combine_variable(self):
         indexedvarinfo = collections.OrderedDict()
         for item in self.VarInfo:
@@ -109,30 +65,37 @@ class VariableMgr(object):
             indexedvarinfo[(item.skuname, item.defaultstoragename, item.var_name, item.var_guid)].append(item)
         for key in indexedvarinfo:
             sku_var_info_offset_list = indexedvarinfo[key]
-            if len(sku_var_info_offset_list) == 1:
-                continue
-
+            sku_var_info_offset_list.sort(key=lambda x:x.PcdDscLine)
+            FirstOffset = int(sku_var_info_offset_list[0].var_offset, 16) if sku_var_info_offset_list[0].var_offset.upper().startswith("0X") else int(sku_var_info_offset_list[0].var_offset)
+            fisrtvalue_list = sku_var_info_offset_list[0].default_value.strip("{").strip("}").split(",")
+            firstdata_type = sku_var_info_offset_list[0].data_type
+            if firstdata_type in DataType.TAB_PCD_NUMERIC_TYPES:
+                fisrtdata_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[firstdata_type]]
+                fisrtdata = fisrtvalue_list[0]
+                fisrtvalue_list = []
+                for data_byte in pack(fisrtdata_flag, int(fisrtdata, 16) if fisrtdata.upper().startswith('0X') else int(fisrtdata)):
+                    fisrtvalue_list.append(hex(unpack("B", data_byte)[0]))
+            newvalue_list = ["0x00"] * FirstOffset + fisrtvalue_list
+
+            for var_item in sku_var_info_offset_list[1:]:
+                CurOffset = int(var_item.var_offset, 16) if var_item.var_offset.upper().startswith("0X") else int(var_item.var_offset)
+                CurvalueList = var_item.default_value.strip("{").strip("}").split(",")
+                Curdata_type = var_item.data_type
+                if Curdata_type in DataType.TAB_PCD_NUMERIC_TYPES:
+                    data_flag = DataType.PACK_CODE_BY_SIZE[MAX_SIZE_TYPE[Curdata_type]]
+                    data = CurvalueList[0]
+                    CurvalueList = []
+                    for data_byte in pack(data_flag, int(data, 16) if data.upper().startswith('0X') else int(data)):
+                        CurvalueList.append(hex(unpack("B", data_byte)[0]))
+                if CurOffset > len(newvalue_list):
+                    newvalue_list = newvalue_list + ["0x00"] * (CurOffset - len(newvalue_list)) + CurvalueList
+                else:
+                    newvalue_list[CurOffset : CurOffset + len(CurvalueList)] = CurvalueList
+
+            newvaluestr =  "{" + ",".join(newvalue_list) +"}"
             n = sku_var_info_offset_list[0]
-
-            if self.NeedMerge(sku_var_info_offset_list):
-                newvaluestr = self.Do_Merge(sku_var_info_offset_list)
-            else:
-                newvaluestr = self.Do_combine(sku_var_info_offset_list)
-
             indexedvarinfo[key] =  [var_info(n.pcdindex, n.pcdname, n.defaultstoragename, n.skuname, n.var_name, n.var_guid, "0x00", n.var_attribute, newvaluestr, newvaluestr, DataType.TAB_VOID,n.PcdDscLine,n.StructurePcd)]
-        self.VarInfo = [item[0] for item in indexedvarinfo.values()]
-
-    @staticmethod
-    def assemble_variable(valuedict):
-        ordered_valuedict_keys = sorted(valuedict.keys())
-        var_value = []
-        for current_valuedict_key in ordered_valuedict_keys:
-            if current_valuedict_key < len(var_value):
-                raise
-            for _ in xrange(current_valuedict_key - len(var_value)):
-                var_value.append('0x00')
-            var_value += valuedict[current_valuedict_key]
-        return var_value
+        self.VarInfo = [item[0] for item in list(indexedvarinfo.values())]
 
     def process_variable_data(self):
 
-- 
2.14.1.windows.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-10-24  7:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-18  7:12 [PATCH V2] BaseTool: Support different PCDs that refers to the same EFI variable Zhaozh1x
2018-10-21 10:47 ` Feng, Bob C
2018-10-22 15:14   ` Carsey, Jaben
2018-10-24  7:26 ` Feng, Bob C

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox