]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py
IntelFsp2Pkg: Support Config File and Binary delta comparison
[mirror_edk2.git] / IntelFsp2Pkg / Tools / ConfigEditor / GenYamlCfg.py
index 611a9a9c726602fd0f338d919ea4407101953f55..b593885807df04242a2475256965192464d05230 100644 (file)
@@ -13,6 +13,7 @@ import string
 import operator as op\r
 import ast\r
 import tkinter.messagebox as messagebox\r
+import tkinter\r
 \r
 from datetime import date\r
 from collections import OrderedDict\r
@@ -583,7 +584,6 @@ class CGenYamlCfg:
         self._mode = ''\r
         self._debug = False\r
         self._macro_dict = {}\r
-        self.bin_offset = []\r
         self.binseg_dict = {}\r
         self.initialize()\r
 \r
@@ -1046,6 +1046,7 @@ option format '%s' !" % option)
                 try:\r
                     value = self.reformat_value_str(act_cfg['value'],\r
                                                     act_cfg['length'])\r
+\r
                 except Exception:\r
                     value = act_cfg['value']\r
             length = bit_len // 8\r
@@ -1298,18 +1299,85 @@ option format '%s' !" % option)
         self.traverse_cfg_tree(_get_field_value, top)\r
         return result\r
 \r
+    data_diff = ''\r
+\r
+    def find_data_difference(self, act_val, act_cfg):\r
+        # checks for any difference between BSF and Binary file\r
+        config_val = ''\r
+        if act_val != act_cfg['value']:\r
+\r
+            if 'DEC' in act_cfg['type']:\r
+                bsf_val = '0x%x' % int(act_val)\r
+                if bsf_val != act_cfg['value']:\r
+                    config_val = bsf_val\r
+                else:\r
+                    config_val = ''\r
+            else:\r
+                config_val = act_val\r
+\r
+            available_fv1 = 'none'\r
+            available_fv2 = 'none'\r
+\r
+            if self.detect_fsp():\r
+                if len(self.available_fv) >= 1:\r
+                    if len(self.available_fv) > 1:\r
+                        available_fv1 = self.available_fv[1]\r
+                        if self.available_fv[2]:\r
+                            available_fv2 = self.available_fv[2]\r
+            else:\r
+                available_fv1 = self.available_fv[1]\r
+                if act_cfg['length'] == 16:\r
+                    config_val = int(config_val, 16)\r
+                    config_val = '0x%x' % config_val\r
+                    act_cfg['value'] = int(\r
+                        act_cfg['value'], 16)\r
+                    act_cfg['value'] = '0x%x' %  \\r
+                        act_cfg['value']\r
+\r
+            if config_val:\r
+                string = ('.' + act_cfg['cname'])\r
+                if (act_cfg['path'].endswith(self.available_fv[0] + string)\r
+                    or act_cfg['path'].endswith(available_fv1 + string)\r
+                    or act_cfg['path'].endswith(available_fv2 + string)) \\r
+                    and 'BsfSkip' not in act_cfg['cname'] \\r
+                        and 'Reserved' not in act_cfg['name']:\r
+                    if act_cfg['option'] != '':\r
+                        if act_cfg['length'] == 8:\r
+                            config_val = int(config_val, 16)\r
+                            config_val = '0x%x' % config_val\r
+                            act_cfg['value'] = int(\r
+                                act_cfg['value'], 16)\r
+                            act_cfg['value'] = '0x%x' %  \\r
+                                act_cfg['value']\r
+                        option = act_cfg['option']\r
+\r
+                        cfg_val = ''\r
+                        bin_val = ''\r
+                        for i in option.split(','):\r
+                            if act_cfg['value'] in i:\r
+                                bin_val = i\r
+                            elif config_val in i:\r
+                                cfg_val = i\r
+                        if cfg_val != '' and bin_val != '':\r
+                            self.data_diff += '\n\nBinary:        ' \\r
+                                + act_cfg['name'] \\r
+                                + ': ' + bin_val.replace(' ', '') \\r
+                                + '\nConfig file:   ' \\r
+                                + act_cfg['name'] + ': ' \\r
+                                + cfg_val.replace(' ', '') + '\n'\r
+                    else:\r
+                        self.data_diff += '\n\nBinary:        ' \\r
+                            + act_cfg['name'] + ': ' + act_cfg['value'] \\r
+                            + '\nConfig file:   ' + act_cfg['name'] \\r
+                            + ': ' + config_val + '\n'\r
+\r
     def set_field_value(self, top, value_bytes, force=False):\r
         def _set_field_value(name, cfgs, level):\r
             if 'indx' not in cfgs:\r
                 return\r
             act_cfg = self.get_item_by_index(cfgs['indx'])\r
             actual_offset = act_cfg['offset'] - struct_info['offset']\r
-            set_value = True\r
-            for each in self.bin_offset:\r
-                if actual_offset in range(each[0], (each[0] + each[2]) * 8):\r
-                    if each[1] < 0:\r
-                        set_value = False\r
-            if set_value and force or act_cfg['value'] == '':\r
+            if force or act_cfg['value'] == '':\r
                 value = get_bits_from_bytes(full_bytes,\r
                                             actual_offset,\r
                                             act_cfg['length'])\r
@@ -1321,6 +1389,7 @@ option format '%s' !" % option)
                                                         act_val)\r
                 act_cfg['value'] = self.format_value_to_str(\r
                     value, act_cfg['length'], act_val)\r
+                self.find_data_difference(act_val, act_cfg)\r
 \r
         if 'indx' in top:\r
             # it is config option\r
@@ -1438,6 +1507,9 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
 \r
         return bin_segs\r
 \r
+    available_fv = []\r
+    missing_fv = []\r
+\r
     def extract_cfg_from_bin(self, bin_data):\r
         # get cfg bin length\r
         cfg_bins = bytearray()\r
@@ -1445,12 +1517,12 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
         Dummy_offset = 0\r
         for each in bin_segs:\r
             if each[1] != -1:\r
-                self.bin_offset.append([Dummy_offset, each[1], each[2]])\r
                 cfg_bins.extend(bin_data[each[1]:each[1] + each[2]])\r
+                self.available_fv.append(each[0])\r
             else:\r
+                self.missing_fv.append(each[0])\r
                 string = each[0] + ' is not availabe.'\r
                 messagebox.showinfo('', string)\r
-                self.bin_offset.append([Dummy_offset, each[1], each[2]])\r
                 cfg_bins.extend(bytearray(each[2]))\r
             Dummy_offset += each[2]\r
         return cfg_bins\r
@@ -1476,10 +1548,41 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
         print('Patched the loaded binary successfully !')\r
         return bin_data\r
 \r
+    def show_data_difference(self, data_diff):\r
+        # Displays if any data difference detected in BSF and Binary file\r
+        pop_up_text = 'There are differences in Config file and binary '\\r
+            'data detected!\n'\r
+        pop_up_text += data_diff\r
+\r
+        window = tkinter.Tk()\r
+        window.title("Data Difference")\r
+        window.resizable(1, 1)\r
+        # Window Size\r
+        window.geometry("800x400")\r
+        frame = tkinter.Frame(window, height=800, width=700)\r
+        frame.pack(side=tkinter.BOTTOM)\r
+        # Vertical (y) Scroll Bar\r
+        scroll = tkinter.Scrollbar(window)\r
+        scroll.pack(side=tkinter.RIGHT, fill=tkinter.Y)\r
+\r
+        text = tkinter.Text(window, wrap=tkinter.NONE,\r
+                            yscrollcommand=scroll.set,\r
+                            width=700, height=400)\r
+        text.insert(tkinter.INSERT, pop_up_text)\r
+        text.pack()\r
+        # Configure the scrollbars\r
+        scroll.config(command=text.yview)\r
+        exit_button = tkinter.Button(\r
+            window, text="Close", command=window.destroy)\r
+        exit_button.pack(in_=frame, side=tkinter.RIGHT, padx=20, pady=10)\r
+\r
     def load_default_from_bin(self, bin_data):\r
         self._old_bin = bin_data\r
         cfg_bins = self.extract_cfg_from_bin(bin_data)\r
         self.set_field_value(self._cfg_tree, cfg_bins, True)\r
+\r
+        if self.data_diff:\r
+            self.show_data_difference(self.data_diff)\r
         return cfg_bins\r
 \r
     def generate_binary_array(self, path=''):\r