[PATCH v2 27/33] dtoc: Don't generate platform data with instantiation
Simon Glass
sjg at chromium.org
Wed Feb 3 14:01:15 CET 2021
This file is not used when instantiating devices. Update dtoc to skip
generating its contents and just add a comment instead.
Also it is useful to see the driver name and parent for each device.
Update the file to show that information, to avoid updating the same
tests twice.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
tools/dtoc/dtb_platdata.py | 35 ++++++++++++++++++++++---
tools/dtoc/test_dtoc.py | 53 +++++++++++++++++++++++++++++++-------
2 files changed, 75 insertions(+), 13 deletions(-)
diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py
index 040b7246787..befe7c14901 100644
--- a/tools/dtoc/dtb_platdata.py
+++ b/tools/dtoc/dtb_platdata.py
@@ -786,19 +786,46 @@ class DtbPlatdata():
uclass.node_refs[-1] = ref
uclass.node_refs[len(uclass.devs)] = ref
- def output_node(self, node):
+ def output_node_plat(self, node):
"""Output the C code for a node
Args:
node (fdt.Node): node to output
"""
- self.buf('/* Node %s index %d */\n' % (node.path, node.idx))
+ driver = node.driver
+ parent_driver = node.parent_driver
+
+ line1 = 'Node %s index %d' % (node.path, node.idx)
+ if driver:
+ self.buf('/*\n')
+ self.buf(' * %s\n' % line1)
+ self.buf(' * driver %s parent %s\n' % (driver.name,
+ parent_driver.name if parent_driver else 'None'))
+ self.buf(' */\n')
+ else:
+ self.buf('/* %s */\n' % line1)
self._output_values(node)
self._declare_device(node)
self.out(''.join(self.get_buf()))
+ def check_instantiate(self, require):
+ """Check if self._instantiate is set to the required value
+
+ If not, this outputs a message into the current file
+
+ Args:
+ require: True to require --instantiate, False to require that it not
+ be enabled
+ """
+ if require != self._instantiate:
+ self.out(
+ '/* This file is not used: --instantiate was %senabled */\n' %
+ ('not ' if require else ''))
+ return False
+ return True
+
def generate_plat(self):
"""Generate device defintions for the platform data
@@ -809,6 +836,8 @@ class DtbPlatdata():
See the documentation in doc/driver-model/of-plat.rst for more
information.
"""
+ if not self.check_instantiate(False):
+ return
self.out('/* Allow use of U_BOOT_DRVINFO() in this file */\n')
self.out('#define DT_PLAT_C\n')
self.out('\n')
@@ -818,7 +847,7 @@ class DtbPlatdata():
self.out('\n')
for node in self._valid_nodes:
- self.output_node(node)
+ self.output_node_plat(node)
self.out(''.join(self.get_buf()))
diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py
index a51a7f301ce..c6e33d34227 100755
--- a/tools/dtoc/test_dtoc.py
+++ b/tools/dtoc/test_dtoc.py
@@ -48,13 +48,15 @@ DECL_HEADER = '''/*
*/
'''
-C_HEADER = '''/*
+C_HEADER_PRE = '''/*
* DO NOT MODIFY
*
* Declares the U_BOOT_DRIVER() records and platform data.
* This was generated by dtoc from a .dtb (device tree binary) file.
*/
+'''
+C_HEADER = C_HEADER_PRE + '''
/* Allow use of U_BOOT_DRVINFO() in this file */
#define DT_PLAT_C
@@ -289,9 +291,11 @@ struct dtd_sandbox_spl_test {
\tconst char *\tstringval;
};
'''
-
platdata_text = C_HEADER + '''
-/* Node /i2c at 0 index 0 */
+/*
+ * Node /i2c at 0 index 0
+ * driver sandbox_i2c parent None
+ */
static struct dtd_sandbox_i2c dtv_i2c_at_0 = {
};
U_BOOT_DRVINFO(i2c_at_0) = {
@@ -301,7 +305,10 @@ U_BOOT_DRVINFO(i2c_at_0) = {
\t.parent_idx\t= -1,
};
-/* Node /i2c at 0/pmic at 9 index 1 */
+/*
+ * Node /i2c at 0/pmic at 9 index 1
+ * driver sandbox_pmic parent sandbox_i2c
+ */
static struct dtd_sandbox_pmic dtv_pmic_at_9 = {
\t.low_power\t\t= true,
\t.reg\t\t\t= {0x9, 0x0},
@@ -313,7 +320,10 @@ U_BOOT_DRVINFO(pmic_at_9) = {
\t.parent_idx\t= 0,
};
-/* Node /spl-test index 2 */
+/*
+ * Node /spl-test index 2
+ * driver sandbox_spl_test parent None
+ */
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.boolval\t\t= true,
\t.bytearray\t\t= {0x6, 0x0, 0x0},
@@ -333,7 +343,10 @@ U_BOOT_DRVINFO(spl_test) = {
\t.parent_idx\t= -1,
};
-/* Node /spl-test2 index 3 */
+/*
+ * Node /spl-test2 index 3
+ * driver sandbox_spl_test parent None
+ */
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
\t.acpi_name\t\t= "\\\\_SB.GPO0",
\t.bytearray\t\t= {0x1, 0x23, 0x34},
@@ -352,7 +365,10 @@ U_BOOT_DRVINFO(spl_test2) = {
\t.parent_idx\t= -1,
};
-/* Node /spl-test3 index 4 */
+/*
+ * Node /spl-test3 index 4
+ * driver sandbox_spl_test parent None
+ */
static struct dtd_sandbox_spl_test dtv_spl_test3 = {
\t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10,
\t\t0x0},
@@ -414,7 +430,10 @@ struct dtd_sandbox_gpio {
with open(output) as infile:
data = infile.read()
self._check_strings(C_HEADER + '''
-/* Node /gpios at 0 index 0 */
+/*
+ * Node /gpios at 0 index 0
+ * driver sandbox_gpio parent None
+ */
static struct dtd_sandbox_gpio dtv_gpios_at_0 = {
\t.gpio_bank_name\t\t= "a",
\t.gpio_controller\t= true,
@@ -942,7 +961,10 @@ struct dtd_sandbox_spl_test {
with open(output) as infile:
data = infile.read()
self._check_strings(C_HEADER + '''
-/* Node /spl-test index 0 */
+/*
+ * Node /spl-test index 0
+ * driver sandbox_spl_test parent None
+ */
static struct dtd_sandbox_spl_test dtv_spl_test = {
\t.intval\t\t\t= 0x1,
};
@@ -953,7 +975,10 @@ U_BOOT_DRVINFO(spl_test) = {
\t.parent_idx\t= -1,
};
-/* Node /spl-test2 index 1 */
+/*
+ * Node /spl-test2 index 1
+ * driver sandbox_spl_test parent None
+ */
static struct dtd_sandbox_spl_test dtv_spl_test2 = {
\t.intarray\t\t= 0x5,
};
@@ -1226,3 +1251,11 @@ U_BOOT_DRVINFO(spl_test2) = {
data = infile.read()
self._check_strings(self.decl_text_inst, data)
+
+ self.run_test(['platdata'], dtb_file, output, True)
+ with open(output) as infile:
+ data = infile.read()
+
+ self._check_strings(C_HEADER_PRE + '''
+/* This file is not used: --instantiate was enabled */
+''', data)
--
2.30.0.365.g02bc693789-goog
More information about the U-Boot
mailing list