Add support for variable cell width in ConfigEditor

Current ConfigEditor only supports UINT8 format cell in table.
This patch added support for variable cell width including UINT8,
UINT16, UINT32 in table widget. Test configuration items were
also added in QEMU to test these format.

Signed-off-by: Maurice Ma <maurice.ma@intel.com>
This commit is contained in:
Maurice Ma 2019-09-27 16:36:19 -07:00
parent d313c9c5fc
commit e2d1d73684
3 changed files with 51 additions and 16 deletions

View File

@ -23,7 +23,7 @@ else:
import tkMessageBox as messagebox
import tkFileDialog as filedialog
from GenCfgData import CGenCfgData, Bytes2Str, Bytes2Val, Array2Val
from GenCfgData import CGenCfgData, Bytes2Str, Bytes2Val, Val2Bytes, Array2Val
class CreateToolTip(object):
'''
@ -70,8 +70,11 @@ class CreateToolTip(object):
class ValidatingEntry(Entry):
_Padding = 2
_CharWidth = 1
def __init__(self, master, value="", **kw):
apply(Entry.__init__, (self, master), kw)
Entry.__init__(*(self, master), **kw)
self.Value = value
self.Variable = StringVar()
self.Variable.set(value)
@ -79,6 +82,17 @@ class ValidatingEntry(Entry):
self.config(textvariable=self.Variable)
self.bind("<FocusOut>", self.FocusOut)
@staticmethod
def ToCellWidth (ByteLen):
return ByteLen * 2 * ValidatingEntry._CharWidth + ValidatingEntry._Padding
@staticmethod
def ToByteLen (CellWidth):
return (CellWidth - ValidatingEntry._Padding) // (ValidatingEntry._CharWidth * 2)
def GetByteLen (self):
return ValidatingEntry.ToByteLen (self['width'])
def FocusOut(self, Event):
Value = self.Variable.get()
if len(Value) == 0:
@ -103,8 +117,9 @@ class ValidatingEntry(Entry):
except:
return None
if len(Value) > 2:
return None
MaxLen = self.GetByteLen() * 2
if len(Value) > MaxLen:
Value = Value[:MaxLen]
return Value.upper()
@ -134,12 +149,12 @@ class CustomTable(Frame):
for Col in range(Cols): #Columns
if Idx >= len(Bins):
break
Hex = "%02X" % Bins[Idx]
ValidatingEntry(self, width=4,
justify=CENTER,
value=Hex).grid(row=Row + RowAdj,
column=Col + ColAdj)
Idx += 1
ByteLen = int(ColHdr[Col].split(':')[1])
Value = Bytes2Val (Bins[Idx:Idx+ByteLen])
Hex = ("%%0%dX" % (ByteLen * 2) ) % Value
ValidatingEntry(self, width=ValidatingEntry.ToCellWidth(ByteLen),
justify=CENTER, value=Hex).grid(row=Row + RowAdj, column=Col + ColAdj)
Idx += ByteLen
if Idx >= len(Bins):
break
@ -148,10 +163,12 @@ class CustomTable(Frame):
for Widget in self.winfo_children():
if not isinstance(Widget, ValidatingEntry):
continue
ByteLen = Widget.GetByteLen ()
Hex = Widget.get()
if not Hex:
break
Bins.append(int(Hex, 16) & 0xff)
Values = Val2Bytes (int(Hex, 16) & ((1 << ByteLen * 8) - 1), ByteLen)
Bins.extend(Values)
return Bins
def destroy(self):

View File

@ -446,6 +446,9 @@ EndList
DataList = self.ValueToList(ConfigDict['value'], ConfigDict['length'])
Unit = int(Struct[4:]) // 8
if int(ConfigDict['length']) != Unit * len(DataList):
# Fallback to byte array
Unit = 1
if int(ConfigDict['length']) != len(DataList):
raise Exception("Array size is not proper for '%s' !" % ConfigDict['cname'])
ByteArray = []

View File

@ -141,10 +141,25 @@
# !BSF HELP:{Silicon Test 1}
gCfgData.SiliconTest1 | * | 0x04 | 0x11223347
# !BSF NAME:{Silicon Test 9}
# !BSF TYPE:{EditNum, HEX, (0x00000000,0xFFFFFFFF)}
# !BSF HELP:{Silicon Test 9}
gCfgData.SiliconTest2 | * | 0x04 | 0x11223348
# !BSF NAME:{Silicon Test 2}
# !BSF TYPE:{Table}
# !BSF OPTION:{ 0:1:HEX, 1:1:HEX, 2:1:HEX, 3:1:HEX}
# !BSF HELP:{Silicon Test 2 to show BYTE table configuration}
gCfgData.SiliconTest2 | * | 0x04 | 0x04030201
# !BSF NAME:{Silicon Test 3}
# !BSF TYPE:{Table}
# !BSF OPTION:{ 0:2:HEX, 1:2:HEX}
# !BSF HELP:{Silicon Test 3 to show UINT16 table configuration}
# !HDR STRUCT:{UINT16}
gCfgData.SiliconTest3 | * | 0x08 | {0x1111, 0x2222, 0x3333, 0x4444}
# !BSF NAME:{Silicon Test 4}
# !BSF TYPE:{Table}
# !BSF OPTION:{ 0:4:HEX, 1:4:HEX}
# !BSF HELP:{Silicon Test 4 to show UINT32 table configuration}
# !HDR STRUCT:{UINT32}
gCfgData.SiliconTest4 | * | 0x08 | {0x11112222, 0x33334444}
# !HDR EMBED:{SILICON_CFG_DATA:TAG_200:END}
# ---------------------------------------------------------------------------------------