Properties:
_fdt: Fdt object, referencing the device tree
_dtb_fname: Filename of the input device tree binary file
- _valid_nodes: A list of Node object with compatible strings
+ _valid_nodes: A list of Node object with compatible strings. The list
+ is ordered by conv_name_to_c(node.name)
_include_disabled: true to include nodes marked status = "disabled"
_outfile: The current output file (sys.stdout or a real file)
_warning_disabled: true to disable warnings about driver names not found
"""
self._fdt = fdt.FdtScan(self._dtb_fname)
- def scan_node(self, root):
+ def scan_node(self, root, valid_nodes):
"""Scan a node and subnodes to build a tree of node and phandle info
This adds each node to self._valid_nodes.
Args:
root: Root node for scan
+ valid_nodes: List of Node objects to add to
"""
for node in root.subnodes:
if 'compatible' in node.props:
status = node.props.get('status')
if (not self._include_disabled and not status or
status.value != 'disabled'):
- self._valid_nodes.append(node)
+ valid_nodes.append(node)
# recurse to handle any subnodes
- self.scan_node(node)
+ self.scan_node(node, valid_nodes)
def scan_tree(self):
"""Scan the device tree for useful information
_valid_nodes: A list of nodes we wish to consider include in the
platform data
"""
- self._valid_nodes = []
- return self.scan_node(self._fdt.GetRoot())
+ valid_nodes = []
+ self.scan_node(self._fdt.GetRoot(), valid_nodes)
+ self._valid_nodes = sorted(valid_nodes,
+ key=lambda x: conv_name_to_c(x.name))
+ for idx, node in enumerate(self._valid_nodes):
+ node.idx = idx
@staticmethod
def get_num_cells(node):
key (str): Field name
value: Prop object with field information
"""
- structs = {}
+ structs = collections.OrderedDict()
for node in self._valid_nodes:
node_name, _ = self.get_normalized_compat_name(node)
fields = {}
struct_name, _ = self.get_normalized_compat_name(node)
var_name = conv_name_to_c(node.name)
+ self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
self.buf('static struct %s%s %s%s = {\n' %
(STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name))
for pname in sorted(node.props):
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /i2c@0 index 0 */
+static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
+};
+U_BOOT_DEVICE(i2c_at_0) = {
+\t.name\t\t= "sandbox_i2c_test",
+\t.platdata\t= &dtv_i2c_at_0,
+\t.platdata_size\t= sizeof(dtv_i2c_at_0),
+};
+
+/* Node /i2c@0/pmic@9 index 1 */
+static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
+\t.low_power\t\t= true,
+\t.reg\t\t\t= {0x9, 0x0},
+};
+U_BOOT_DEVICE(pmic_at_9) = {
+\t.name\t\t= "sandbox_pmic_test",
+\t.platdata\t= &dtv_pmic_at_9,
+\t.platdata_size\t= sizeof(dtv_pmic_at_9),
+};
+
+/* Node /spl-test index 2 */
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.boolval\t\t= true,
\t.bytearray\t\t= {0x6, 0x0, 0x0},
\t.platdata_size\t= sizeof(dtv_spl_test),
};
+/* Node /spl-test2 index 3 */
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
\t.acpi_name\t\t= "\\\\_SB.GPO0",
\t.bytearray\t\t= {0x1, 0x23, 0x34},
\t.platdata_size\t= sizeof(dtv_spl_test2),
};
+/* Node /spl-test3 index 4 */
static struct dtd_sandbox_spl_test dtv_spl_test3 = {
\t.stringarray\t\t= {"one", "", ""},
};
\t.platdata_size\t= sizeof(dtv_spl_test3),
};
+/* Node /spl-test4 index 5 */
static struct dtd_sandbox_spl_test_2 dtv_spl_test4 = {
};
U_BOOT_DEVICE(spl_test4) = {
\t.platdata_size\t= sizeof(dtv_spl_test4),
};
-static struct dtd_sandbox_i2c_test dtv_i2c_at_0 = {
-};
-U_BOOT_DEVICE(i2c_at_0) = {
-\t.name\t\t= "sandbox_i2c_test",
-\t.platdata\t= &dtv_i2c_at_0,
-\t.platdata_size\t= sizeof(dtv_i2c_at_0),
-};
-
-static struct dtd_sandbox_pmic_test dtv_pmic_at_9 = {
-\t.low_power\t\t= true,
-\t.reg\t\t\t= {0x9, 0x0},
-};
-U_BOOT_DEVICE(pmic_at_9) = {
-\t.name\t\t= "sandbox_pmic_test",
-\t.platdata\t= &dtv_pmic_at_9,
-\t.platdata_size\t= sizeof(dtv_pmic_at_9),
-};
-
''' + C_EMPTY_POPULATE_PHANDLE_DATA, data)
def test_driver_alias(self):
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /gpios@0 index 0 */
static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
\t.gpio_bank_name\t\t= "a",
\t.gpio_controller\t= true,
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /spl-test index 0 */
static struct dtd_invalid dtv_spl_test = {
};
U_BOOT_DEVICE(spl_test) = {
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DEVICE(phandle_target) = {
-\t.name\t\t= "target",
-\t.platdata\t= &dtv_phandle_target,
-\t.platdata_size\t= sizeof(dtv_phandle_target),
-};
-
+/* Node /phandle2-target index 0 */
static struct dtd_target dtv_phandle2_target = {
\t.intval\t\t\t= 0x1,
};
\t.platdata_size\t= sizeof(dtv_phandle2_target),
};
+/* Node /phandle3-target index 1 */
static struct dtd_target dtv_phandle3_target = {
\t.intval\t\t\t= 0x2,
};
\t.platdata_size\t= sizeof(dtv_phandle3_target),
};
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DEVICE(phandle_target) = {
+\t.name\t\t= "target",
+\t.platdata\t= &dtv_phandle_target,
+\t.platdata_size\t= sizeof(dtv_phandle_target),
+};
+
+/* Node /phandle-source index 2 */
static struct dtd_source dtv_phandle_source = {
\t.clocks\t\t\t= {
\t\t\t{NULL, {}},
\t.platdata_size\t= sizeof(dtv_phandle_source),
};
+/* Node /phandle-source2 index 3 */
static struct dtd_source dtv_phandle_source2 = {
\t.clocks\t\t\t= {
\t\t\t{NULL, {}},},
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /phandle-target index 1 */
static struct dtd_target dtv_phandle_target = {
};
U_BOOT_DEVICE(phandle_target) = {
\t.platdata_size\t= sizeof(dtv_phandle_target),
};
+/* Node /phandle-source2 index 0 */
static struct dtd_source dtv_phandle_source2 = {
\t.clocks\t\t\t= {
\t\t\t{NULL, {}},},
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
-static struct dtd_target dtv_phandle_target = {
-\t.intval\t\t\t= 0x0,
-};
-U_BOOT_DEVICE(phandle_target) = {
-\t.name\t\t= "target",
-\t.platdata\t= &dtv_phandle_target,
-\t.platdata_size\t= sizeof(dtv_phandle_target),
-};
-
+/* Node /phandle2-target index 0 */
static struct dtd_target dtv_phandle2_target = {
\t.intval\t\t\t= 0x1,
};
\t.platdata_size\t= sizeof(dtv_phandle2_target),
};
+/* Node /phandle3-target index 1 */
static struct dtd_target dtv_phandle3_target = {
\t.intval\t\t\t= 0x2,
};
\t.platdata_size\t= sizeof(dtv_phandle3_target),
};
+/* Node /phandle-target index 4 */
+static struct dtd_target dtv_phandle_target = {
+\t.intval\t\t\t= 0x0,
+};
+U_BOOT_DEVICE(phandle_target) = {
+\t.name\t\t= "target",
+\t.platdata\t= &dtv_phandle_target,
+\t.platdata_size\t= sizeof(dtv_phandle_target),
+};
+
+/* Node /phandle-source index 2 */
static struct dtd_source dtv_phandle_source = {
\t.cd_gpios\t\t= {
\t\t\t{NULL, {}},
\t.platdata_size\t= sizeof(dtv_phandle_source),
};
+/* Node /phandle-source2 index 3 */
static struct dtd_source dtv_phandle_source2 = {
\t.cd_gpios\t\t= {
\t\t\t{NULL, {}},},
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
\t.platdata_size\t= sizeof(dtv_test1),
};
+/* Node /test2 index 1 */
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654},
};
\t.platdata_size\t= sizeof(dtv_test2),
};
+/* Node /test3 index 2 */
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x1234567890123456, 0x9876543210987654, 0x2, 0x3},
};
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x5678},
};
\t.platdata_size\t= sizeof(dtv_test1),
};
+/* Node /test2 index 1 */
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x12345678, 0x98765432, 0x2, 0x3},
};
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x123400000000, 0x5678},
};
\t.platdata_size\t= sizeof(dtv_test1),
};
+/* Node /test2 index 1 */
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432},
};
\t.platdata_size\t= sizeof(dtv_test2),
};
+/* Node /test3 index 2 */
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x1234567890123456, 0x98765432, 0x2, 0x3},
};
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /test1 index 0 */
static struct dtd_test1 dtv_test1 = {
\t.reg\t\t\t= {0x1234, 0x567800000000},
};
\t.platdata_size\t= sizeof(dtv_test1),
};
+/* Node /test2 index 1 */
static struct dtd_test2 dtv_test2 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654},
};
\t.platdata_size\t= sizeof(dtv_test2),
};
+/* Node /test3 index 2 */
static struct dtd_test3 dtv_test3 = {
\t.reg\t\t\t= {0x12345678, 0x9876543210987654, 0x2, 0x3},
};
with open(output) as infile:
data = infile.read()
self._CheckStrings(C_HEADER + '''
+/* Node /spl-test index 0 */
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
\t.platdata_size\t= sizeof(dtv_spl_test),
};
+/* Node /spl-test2 index 1 */
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
\t.intarray\t\t= 0x5,
};