mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-29 16:10:24 +09:00
dtoc: Rename is_phandle() and adjust it to return more detail
Update this function to return more detail about a property that contains phandles. This will allow (in a future commit) more accurate handling of these properties. Signed-off-by: Simon Glass <sjg@chromium.org> Tested-by: Kever Yang <kever.yang@rock-chips.com>
This commit is contained in:
parent
2925c26bb2
commit
8fed2eb20c
@ -12,6 +12,7 @@ This supports converting device tree data to C structures definitions and
|
|||||||
static data.
|
static data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import collections
|
||||||
import copy
|
import copy
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -44,6 +45,14 @@ TYPE_NAMES = {
|
|||||||
STRUCT_PREFIX = 'dtd_'
|
STRUCT_PREFIX = 'dtd_'
|
||||||
VAL_PREFIX = 'dtv_'
|
VAL_PREFIX = 'dtv_'
|
||||||
|
|
||||||
|
# This holds information about a property which includes phandles.
|
||||||
|
#
|
||||||
|
# max_args: integer: Maximum number or arguments that any phandle uses (int).
|
||||||
|
# args: Number of args for each phandle in the property. The total number of
|
||||||
|
# phandles is len(args). This is a list of integers.
|
||||||
|
PhandleInfo = collections.namedtuple('PhandleInfo', ['max_args', 'args'])
|
||||||
|
|
||||||
|
|
||||||
def conv_name_to_c(name):
|
def conv_name_to_c(name):
|
||||||
"""Convert a device-tree name to a C identifier
|
"""Convert a device-tree name to a C identifier
|
||||||
|
|
||||||
@ -181,20 +190,42 @@ class DtbPlatdata(object):
|
|||||||
self._lines = []
|
self._lines = []
|
||||||
return lines
|
return lines
|
||||||
|
|
||||||
def is_phandle(self, prop):
|
def get_phandle_argc(self, prop, node_name):
|
||||||
"""Check if a node contains phandles
|
"""Check if a node contains phandles
|
||||||
|
|
||||||
We have no reliable way of detecting whether a node uses a phandle
|
We have no reliable way of detecting whether a node uses a phandle
|
||||||
or not. As an interim measure, use a list of known property names.
|
or not. As an interim measure, use a list of known property names.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
prop: Prop object to check
|
prop: Prop object to check
|
||||||
Return:
|
Return:
|
||||||
True if the object value contains phandles, else False
|
Number of argument cells is this is a phandle, else None
|
||||||
"""
|
"""
|
||||||
if prop.name in ['clocks']:
|
if prop.name in ['clocks']:
|
||||||
return True
|
val = prop.value
|
||||||
return False
|
if not isinstance(val, list):
|
||||||
|
val = [val]
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
max_args = 0
|
||||||
|
args = []
|
||||||
|
while i < len(val):
|
||||||
|
phandle = fdt_util.fdt32_to_cpu(val[i])
|
||||||
|
target = self._fdt.phandle_to_node.get(phandle)
|
||||||
|
if not target:
|
||||||
|
raise ValueError("Cannot parse '%s' in node '%s'" %
|
||||||
|
(prop.name, node_name))
|
||||||
|
prop_name = '#clock-cells'
|
||||||
|
cells = target.props.get(prop_name)
|
||||||
|
if not cells:
|
||||||
|
raise ValueError("Node '%s' has no '%s' property" %
|
||||||
|
(target.name, prop_name))
|
||||||
|
num_args = fdt_util.fdt32_to_cpu(cells.value)
|
||||||
|
max_args = max(max_args, num_args)
|
||||||
|
args.append(num_args)
|
||||||
|
i += 1 + num_args
|
||||||
|
return PhandleInfo(max_args, args)
|
||||||
|
return None
|
||||||
|
|
||||||
def scan_dtb(self):
|
def scan_dtb(self):
|
||||||
"""Scan the device tree to obtain a tree of nodes and properties
|
"""Scan the device tree to obtain a tree of nodes and properties
|
||||||
@ -358,14 +389,16 @@ class DtbPlatdata(object):
|
|||||||
for pname, prop in node.props.items():
|
for pname, prop in node.props.items():
|
||||||
if pname in PROP_IGNORE_LIST or pname[0] == '#':
|
if pname in PROP_IGNORE_LIST or pname[0] == '#':
|
||||||
continue
|
continue
|
||||||
if isinstance(prop.value, list):
|
info = self.get_phandle_argc(prop, node.name)
|
||||||
if self.is_phandle(prop):
|
if info:
|
||||||
# Process the list as pairs of (phandle, id)
|
if not isinstance(prop.value, list):
|
||||||
value_it = iter(prop.value)
|
prop.value = [prop.value]
|
||||||
for phandle_cell, _ in zip(value_it, value_it):
|
# Process the list as pairs of (phandle, id)
|
||||||
phandle = fdt_util.fdt32_to_cpu(phandle_cell)
|
value_it = iter(prop.value)
|
||||||
target_node = self._fdt.phandle_to_node[phandle]
|
for phandle_cell, _ in zip(value_it, value_it):
|
||||||
node.phandles.add(target_node)
|
phandle = fdt_util.fdt32_to_cpu(phandle_cell)
|
||||||
|
target_node = self._fdt.phandle_to_node[phandle]
|
||||||
|
node.phandles.add(target_node)
|
||||||
|
|
||||||
|
|
||||||
def generate_structs(self, structs):
|
def generate_structs(self, structs):
|
||||||
@ -383,7 +416,8 @@ class DtbPlatdata(object):
|
|||||||
self.out('struct %s%s {\n' % (STRUCT_PREFIX, name))
|
self.out('struct %s%s {\n' % (STRUCT_PREFIX, name))
|
||||||
for pname in sorted(structs[name]):
|
for pname in sorted(structs[name]):
|
||||||
prop = structs[name][pname]
|
prop = structs[name][pname]
|
||||||
if self.is_phandle(prop):
|
info = self.get_phandle_argc(prop, structs[name])
|
||||||
|
if info:
|
||||||
# For phandles, include a reference to the target
|
# For phandles, include a reference to the target
|
||||||
self.out('\t%s%s[%d]' % (tab_to(2, 'struct phandle_2_cell'),
|
self.out('\t%s%s[%d]' % (tab_to(2, 'struct phandle_2_cell'),
|
||||||
conv_name_to_c(prop.name),
|
conv_name_to_c(prop.name),
|
||||||
@ -423,7 +457,8 @@ class DtbPlatdata(object):
|
|||||||
vals = []
|
vals = []
|
||||||
# For phandles, output a reference to the platform data
|
# For phandles, output a reference to the platform data
|
||||||
# of the target node.
|
# of the target node.
|
||||||
if self.is_phandle(prop):
|
info = self.get_phandle_argc(prop, node.name)
|
||||||
|
if info:
|
||||||
# Process the list as pairs of (phandle, id)
|
# Process the list as pairs of (phandle, id)
|
||||||
value_it = iter(prop.value)
|
value_it = iter(prop.value)
|
||||||
for phandle_cell, id_cell in zip(value_it, value_it):
|
for phandle_cell, id_cell in zip(value_it, value_it):
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
u-boot,dm-pre-reloc;
|
u-boot,dm-pre-reloc;
|
||||||
compatible = "target";
|
compatible = "target";
|
||||||
intval = <1>;
|
intval = <1>;
|
||||||
|
#clock-cells = <1>;
|
||||||
};
|
};
|
||||||
|
|
||||||
phandle-source {
|
phandle-source {
|
||||||
|
Loading…
Reference in New Issue
Block a user