|
@@ -16,6 +16,7 @@ import os
|
|
|
import struct
|
|
|
import unittest
|
|
|
|
|
|
+from dtb_platdata import Ftype
|
|
|
from dtb_platdata import get_value
|
|
|
from dtb_platdata import tab_to
|
|
|
from dtoc import dtb_platdata
|
|
@@ -65,6 +66,18 @@ C_HEADER = C_HEADER_PRE + '''
|
|
|
#include <dt-structs.h>
|
|
|
'''
|
|
|
|
|
|
+UCLASS_HEADER_COMMON = '''/*
|
|
|
+ * DO NOT MODIFY
|
|
|
+ *
|
|
|
+ * Declares the uclass instances (struct uclass).
|
|
|
+ * This was generated by dtoc from a .dtb (device tree binary) file.
|
|
|
+ */
|
|
|
+'''
|
|
|
+
|
|
|
+UCLASS_HEADER = UCLASS_HEADER_COMMON + '''
|
|
|
+/* This file is not used: --instantiate was not enabled */
|
|
|
+'''
|
|
|
+
|
|
|
# Scanner saved from a previous run of the tests (to speed things up)
|
|
|
saved_scan = None
|
|
|
|
|
@@ -245,31 +258,35 @@ DM_UCLASS_DRIVER_DECL(pmic);
|
|
|
|
|
|
/* driver declarations - these allow DM_DRIVER_GET() to be used */
|
|
|
DM_DRIVER_DECL(sandbox_i2c);
|
|
|
-DM_DRIVER_DECL(sandbox_pmic);
|
|
|
DM_DRIVER_DECL(root_driver);
|
|
|
+DM_DRIVER_DECL(denx_u_boot_test_bus);
|
|
|
DM_DRIVER_DECL(sandbox_spl_test);
|
|
|
DM_DRIVER_DECL(sandbox_spl_test);
|
|
|
-DM_DRIVER_DECL(sandbox_spl_test);
|
|
|
+DM_DRIVER_DECL(denx_u_boot_fdt_test);
|
|
|
+DM_DRIVER_DECL(denx_u_boot_fdt_test);
|
|
|
|
|
|
/* device declarations - these allow DM_DEVICE_REF() to be used */
|
|
|
-DM_DEVICE_DECL(i2c_at_0);
|
|
|
-DM_DEVICE_DECL(pmic_at_9);
|
|
|
+DM_DEVICE_DECL(i2c);
|
|
|
DM_DEVICE_DECL(root);
|
|
|
+DM_DEVICE_DECL(some_bus);
|
|
|
DM_DEVICE_DECL(spl_test);
|
|
|
-DM_DEVICE_DECL(spl_test2);
|
|
|
DM_DEVICE_DECL(spl_test3);
|
|
|
+DM_DEVICE_DECL(test);
|
|
|
+DM_DEVICE_DECL(test0);
|
|
|
|
|
|
/* uclass driver declarations - needed for DM_UCLASS_DRIVER_REF() */
|
|
|
DM_UCLASS_DRIVER_DECL(i2c);
|
|
|
DM_UCLASS_DRIVER_DECL(misc);
|
|
|
-DM_UCLASS_DRIVER_DECL(pmic);
|
|
|
DM_UCLASS_DRIVER_DECL(root);
|
|
|
+DM_UCLASS_DRIVER_DECL(testbus);
|
|
|
+DM_UCLASS_DRIVER_DECL(testfdt);
|
|
|
|
|
|
/* uclass declarations - needed for DM_UCLASS_REF() */
|
|
|
DM_UCLASS_DECL(i2c);
|
|
|
DM_UCLASS_DECL(misc);
|
|
|
-DM_UCLASS_DECL(pmic);
|
|
|
DM_UCLASS_DECL(root);
|
|
|
+DM_UCLASS_DECL(testbus);
|
|
|
+DM_UCLASS_DECL(testfdt);
|
|
|
'''
|
|
|
struct_text = HEADER + '''
|
|
|
struct dtd_sandbox_i2c {
|
|
@@ -394,6 +411,101 @@ U_BOOT_DRVINFO(spl_test3) = {
|
|
|
\t.parent_idx\t= -1,
|
|
|
};
|
|
|
|
|
|
+'''
|
|
|
+ uclass_text = UCLASS_HEADER
|
|
|
+ uclass_text_inst = '''
|
|
|
+
|
|
|
+#include <common.h>
|
|
|
+#include <dm.h>
|
|
|
+#include <dt-structs.h>
|
|
|
+
|
|
|
+/*
|
|
|
+ * uclass declarations
|
|
|
+ *
|
|
|
+ * Sequence numbers:
|
|
|
+ * i2c: UCLASS_I2C
|
|
|
+ * 4: /i2c
|
|
|
+ * misc: UCLASS_MISC
|
|
|
+ * 0: /spl-test
|
|
|
+ * 1: /spl-test3
|
|
|
+ * root: UCLASS_ROOT
|
|
|
+ * 0: /
|
|
|
+ * testbus: UCLASS_TEST_BUS
|
|
|
+ * 2: /some-bus
|
|
|
+ * testfdt: UCLASS_TEST_FDT
|
|
|
+ * 1: /some-bus/test
|
|
|
+ * 2: /some-bus/test0
|
|
|
+ */
|
|
|
+
|
|
|
+struct list_head uclass_head = {
|
|
|
+ .prev = &DM_UCLASS_REF(testfdt)->sibling_node,
|
|
|
+ .next = &DM_UCLASS_REF(i2c)->sibling_node,
|
|
|
+};
|
|
|
+
|
|
|
+DM_UCLASS_INST(i2c) = {
|
|
|
+ .uc_drv = DM_UCLASS_DRIVER_REF(i2c),
|
|
|
+ .sibling_node = {
|
|
|
+ .prev = &uclass_head,
|
|
|
+ .next = &DM_UCLASS_REF(misc)->sibling_node,
|
|
|
+ },
|
|
|
+ .dev_head = {
|
|
|
+ .prev = &DM_DEVICE_REF(i2c)->uclass_node,
|
|
|
+ .next = &DM_DEVICE_REF(i2c)->uclass_node,
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+DM_UCLASS_INST(misc) = {
|
|
|
+ .uc_drv = DM_UCLASS_DRIVER_REF(misc),
|
|
|
+ .sibling_node = {
|
|
|
+ .prev = &DM_UCLASS_REF(i2c)->sibling_node,
|
|
|
+ .next = &DM_UCLASS_REF(root)->sibling_node,
|
|
|
+ },
|
|
|
+ .dev_head = {
|
|
|
+ .prev = &DM_DEVICE_REF(spl_test3)->uclass_node,
|
|
|
+ .next = &DM_DEVICE_REF(spl_test)->uclass_node,
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+DM_UCLASS_INST(root) = {
|
|
|
+ .uc_drv = DM_UCLASS_DRIVER_REF(root),
|
|
|
+ .sibling_node = {
|
|
|
+ .prev = &DM_UCLASS_REF(misc)->sibling_node,
|
|
|
+ .next = &DM_UCLASS_REF(testbus)->sibling_node,
|
|
|
+ },
|
|
|
+ .dev_head = {
|
|
|
+ .prev = &DM_DEVICE_REF(root)->uclass_node,
|
|
|
+ .next = &DM_DEVICE_REF(root)->uclass_node,
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+DM_UCLASS_INST(testbus) = {
|
|
|
+ .uc_drv = DM_UCLASS_DRIVER_REF(testbus),
|
|
|
+ .sibling_node = {
|
|
|
+ .prev = &DM_UCLASS_REF(root)->sibling_node,
|
|
|
+ .next = &DM_UCLASS_REF(testfdt)->sibling_node,
|
|
|
+ },
|
|
|
+ .dev_head = {
|
|
|
+ .prev = &DM_DEVICE_REF(some_bus)->uclass_node,
|
|
|
+ .next = &DM_DEVICE_REF(some_bus)->uclass_node,
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+#include <dm/test.h>
|
|
|
+u8 _testfdt_priv_[sizeof(struct dm_test_uc_priv)]
|
|
|
+ __attribute__ ((section (".priv_data")));
|
|
|
+DM_UCLASS_INST(testfdt) = {
|
|
|
+ .priv_ = _testfdt_priv_,
|
|
|
+ .uc_drv = DM_UCLASS_DRIVER_REF(testfdt),
|
|
|
+ .sibling_node = {
|
|
|
+ .prev = &DM_UCLASS_REF(testbus)->sibling_node,
|
|
|
+ .next = &uclass_head,
|
|
|
+ },
|
|
|
+ .dev_head = {
|
|
|
+ .prev = &DM_DEVICE_REF(test0)->uclass_node,
|
|
|
+ .next = &DM_DEVICE_REF(test)->uclass_node,
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
'''
|
|
|
|
|
|
def test_simple(self):
|
|
@@ -422,7 +534,7 @@ U_BOOT_DRVINFO(spl_test3) = {
|
|
|
self.run_test(['all'], dtb_file, output)
|
|
|
data = tools.ReadFile(output, binary=False)
|
|
|
self._check_strings(self.decl_text + self.platdata_text +
|
|
|
- self.struct_text, data)
|
|
|
+ self.struct_text + self.uclass_text, data)
|
|
|
|
|
|
def test_driver_alias(self):
|
|
|
"""Test output from a device tree file with a driver alias"""
|
|
@@ -1125,7 +1237,7 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|
|
self.run_test(['all'], dtb_file, output)
|
|
|
data = tools.ReadFile(output, binary=False)
|
|
|
self._check_strings(self.decl_text + self.platdata_text +
|
|
|
- self.struct_text, data)
|
|
|
+ self.struct_text + self.uclass_text, data)
|
|
|
|
|
|
def test_no_command(self):
|
|
|
"""Test running dtoc without a command"""
|
|
@@ -1141,7 +1253,7 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|
|
with self.assertRaises(ValueError) as exc:
|
|
|
self.run_test(['invalid-cmd'], dtb_file, output)
|
|
|
self.assertIn(
|
|
|
- "Unknown command 'invalid-cmd': (use: decl, platdata, struct)",
|
|
|
+ "Unknown command 'invalid-cmd': (use: decl, platdata, struct, uclass)",
|
|
|
str(exc.exception))
|
|
|
|
|
|
def test_output_conflict(self):
|
|
@@ -1169,12 +1281,12 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|
|
['all'], dtb_file, False, None, [outdir], None, False,
|
|
|
warning_disabled=True, scan=copy_scan())
|
|
|
fnames = glob.glob(outdir + '/*')
|
|
|
- self.assertEqual(5, len(fnames))
|
|
|
+ self.assertEqual(6, len(fnames))
|
|
|
|
|
|
leafs = set(os.path.basename(fname) for fname in fnames)
|
|
|
self.assertEqual(
|
|
|
{'dt-structs-gen.h', 'source.dts', 'dt-plat.c', 'source.dtb',
|
|
|
- 'dt-decl.h'},
|
|
|
+ 'dt-uclass.c', 'dt-decl.h'},
|
|
|
leafs)
|
|
|
|
|
|
def setup_process_test(self):
|
|
@@ -1363,7 +1475,7 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|
|
|
|
|
def test_simple_inst(self):
|
|
|
"""Test output from some simple nodes with instantiate enabled"""
|
|
|
- dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
|
|
+ dtb_file = get_dtb_file('dtoc_test_inst.dts')
|
|
|
output = tools.GetOutputFilename('output')
|
|
|
|
|
|
self.run_test(['decl'], dtb_file, output, True)
|
|
@@ -1379,3 +1491,29 @@ U_BOOT_DRVINFO(spl_test2) = {
|
|
|
self._check_strings(C_HEADER_PRE + '''
|
|
|
/* This file is not used: --instantiate was enabled */
|
|
|
''', data)
|
|
|
+
|
|
|
+ self.run_test(['uclass'], dtb_file, output, True)
|
|
|
+ with open(output) as infile:
|
|
|
+ data = infile.read()
|
|
|
+
|
|
|
+ self._check_strings(UCLASS_HEADER_COMMON + self.uclass_text_inst, data)
|
|
|
+
|
|
|
+ def test_inst_no_hdr(self):
|
|
|
+ """Test dealing with a struct that has no header"""
|
|
|
+ dtb_file = get_dtb_file('dtoc_test_inst.dts')
|
|
|
+ output = tools.GetOutputFilename('output')
|
|
|
+
|
|
|
+ # Run it once to set everything up
|
|
|
+ plat = self.run_test(['decl'], dtb_file, output, True)
|
|
|
+ scan = plat._scan
|
|
|
+
|
|
|
+ # Restart the output file and delete any record of the uclass' struct
|
|
|
+ plat.setup_output(Ftype.SOURCE, output)
|
|
|
+ del scan._structs['dm_test_uc_priv']
|
|
|
+
|
|
|
+ # Now generate the uclasses, which should provide a warning
|
|
|
+ with test_util.capture_sys_output() as (stdout, _):
|
|
|
+ plat.generate_uclasses()
|
|
|
+ self.assertEqual(
|
|
|
+ 'Warning: Cannot find header file for struct dm_test_uc_priv',
|
|
|
+ stdout.getvalue().strip())
|