mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-25 14:10:43 +00:00
dtoc: Collect priv/plat struct info from drivers
In order to output variables to hold the priv/plat information used by each device, dtoc needs to know the struct for each. With this, it can declare this at build time: u8 xxx_priv [sizeof(struct <name>)]; Collect the various struct names from the drivers. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
36b2220cbd
commit
c8b19b0694
2 changed files with 55 additions and 2 deletions
|
@ -61,6 +61,11 @@ class Driver:
|
|||
value: Driver data, e,g, 'ROCKCHIP_SYSCON_GRF', or None
|
||||
fname: Filename where the driver was found
|
||||
priv (str): struct name of the priv_auto member, e.g. 'serial_priv'
|
||||
plat (str): struct name of the plat_auto member, e.g. 'serial_plat'
|
||||
child_priv (str): struct name of the per_child_auto member,
|
||||
e.g. 'pci_child_priv'
|
||||
child_plat (str): struct name of the per_child_plat_auto member,
|
||||
e.g. 'pci_child_plat'
|
||||
"""
|
||||
def __init__(self, name, fname):
|
||||
self.name = name
|
||||
|
@ -68,12 +73,16 @@ class Driver:
|
|||
self.uclass_id = None
|
||||
self.compat = None
|
||||
self.priv = ''
|
||||
self.plat = ''
|
||||
self.child_priv = ''
|
||||
self.child_plat = ''
|
||||
|
||||
def __eq__(self, other):
|
||||
return (self.name == other.name and
|
||||
self.uclass_id == other.uclass_id and
|
||||
self.compat == other.compat and
|
||||
self.priv == other.priv)
|
||||
self.priv == other.priv and
|
||||
self.plat == other.plat)
|
||||
|
||||
def __repr__(self):
|
||||
return ("Driver(name='%s', uclass_id='%s', compat=%s, priv=%s)" %
|
||||
|
@ -230,8 +239,11 @@ class Scanner:
|
|||
re_of_match = re.compile(
|
||||
r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
|
||||
|
||||
# Matches the struct name for priv
|
||||
# Matches the struct name for priv, plat
|
||||
re_priv = self._get_re_for_member('priv_auto')
|
||||
re_plat = self._get_re_for_member('plat_auto')
|
||||
re_child_priv = self._get_re_for_member('per_child_auto')
|
||||
re_child_plat = self._get_re_for_member('per_child_plat_auto')
|
||||
|
||||
prefix = ''
|
||||
for line in buff.splitlines():
|
||||
|
@ -250,8 +262,17 @@ class Scanner:
|
|||
m_id = re_id.search(line)
|
||||
m_of_match = re_of_match.search(line)
|
||||
m_priv = re_priv.match(line)
|
||||
m_plat = re_plat.match(line)
|
||||
m_cplat = re_child_plat.match(line)
|
||||
m_cpriv = re_child_priv.match(line)
|
||||
if m_priv:
|
||||
driver.priv = m_priv.group(1)
|
||||
elif m_plat:
|
||||
driver.plat = m_plat.group(1)
|
||||
elif m_cplat:
|
||||
driver.child_plat = m_cplat.group(1)
|
||||
elif m_cpriv:
|
||||
driver.child_priv = m_cpriv.group(1)
|
||||
elif m_id:
|
||||
driver.uclass_id = m_id.group(1)
|
||||
elif m_of_match:
|
||||
|
|
|
@ -231,3 +231,35 @@ U_BOOT_DRIVER(i2c_tegra) = {
|
|||
self.assertIn('i2c_tegra', scan._drivers)
|
||||
drv = scan._drivers['i2c_tegra']
|
||||
self.assertEqual('i2c_tegra', drv.name)
|
||||
|
||||
def test_priv(self):
|
||||
"""Test collection of struct info from drivers"""
|
||||
buff = '''
|
||||
static const struct udevice_id test_ids[] = {
|
||||
{ .compatible = "nvidia,tegra114-i2c", .data = TYPE_114 },
|
||||
{ }
|
||||
};
|
||||
|
||||
U_BOOT_DRIVER(testing) = {
|
||||
.name = "testing",
|
||||
.id = UCLASS_I2C,
|
||||
.of_match = test_ids,
|
||||
.priv_auto = sizeof(struct some_priv),
|
||||
.plat_auto = sizeof(struct some_plat),
|
||||
.per_child_auto = sizeof(struct some_cpriv),
|
||||
.per_child_plat_auto = sizeof(struct some_cplat),
|
||||
};
|
||||
'''
|
||||
scan = src_scan.Scanner(None, False, None)
|
||||
scan._parse_driver('file.c', buff)
|
||||
self.assertIn('testing', scan._drivers)
|
||||
drv = scan._drivers['testing']
|
||||
self.assertEqual('testing', drv.name)
|
||||
self.assertEqual('UCLASS_I2C', drv.uclass_id)
|
||||
self.assertEqual(
|
||||
{'nvidia,tegra114-i2c': 'TYPE_114'}, drv.compat)
|
||||
self.assertEqual('some_priv', drv.priv)
|
||||
self.assertEqual('some_plat', drv.plat)
|
||||
self.assertEqual('some_cpriv', drv.child_priv)
|
||||
self.assertEqual('some_cplat', drv.child_plat)
|
||||
self.assertEqual(1, len(scan._drivers))
|
||||
|
|
Loading…
Reference in a new issue