U-Boot operates in several phases, typically TPL, SPL and U-Boot proper.
The latter does not use dtoc.
In some rare cases different drivers are used for two phases. For example,
in TPL it may not be necessary to use the full PCI subsystem, so a simple
driver can be used instead.
This works in the build system simply by compiling in one driver or the
other (e.g. PCI driver + uclass for SPL; simple_bus for TPL). But dtoc has
no way of knowing which code is compiled in for which phase, since it does
not inspect Makefiles or dependency graphs.
So to make this work for dtoc, we need to be able to explicitly mark
drivers with their phase. This is done by adding an empty macro to the
driver. Add support for this in dtoc.
Signed-off-by: Simon Glass <sjg@chromium.org>
*/
#define DM_DRIVER_ALIAS(__name, __alias)
+/**
+ * Declare a macro to indicate which phase of U-Boot this driver is fore.
+ *
+ *
+ * This macro produces no code but its information will be parsed by dtoc. The
+ * macro can be only be used once in a driver. Put it within the U_BOOT_DRIVER()
+ * declaration, e.g.:
+ *
+ * U_BOOT_DRIVER(cpu) = {
+ * .name = ...
+ * ...
+ * DM_PHASE(tpl)
+ * };
+ */
+#define DM_PHASE(_phase)
+
/**
* dev_get_plat() - Get the platform data for a device
*
}
-def run_steps(args, dtb_file, include_disabled, output, output_dirs,
+def run_steps(args, dtb_file, include_disabled, output, output_dirs, phase,
warning_disabled=False, drivers_additional=None, basedir=None,
scan=None):
"""Run all the steps of the dtoc tool
output_dirs (tuple of str):
Directory to put C output files
Directory to put H output files
+ phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
+ or 'tpl'. None if not known
warning_disabled (bool): True to avoid showing warnings about missing
drivers
drivers_additional (list): List of additional drivers to use during
raise ValueError('Must specify either output or output_dirs, not both')
if not scan:
- scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional)
+ scan = src_scan.Scanner(basedir, warning_disabled, drivers_additional,
+ phase)
scan.scan_drivers()
do_process = True
else:
help='Include disabled nodes')
parser.add_option('-o', '--output', action='store',
help='Select output filename')
+parser.add_option('-p', '--phase', type=str,
+ help='set phase of U-Boot this invocation is for (spl/tpl)')
parser.add_option('-P', '--processes', type=int,
help='set number of processes to use for running tests')
parser.add_option('-t', '--test', action='store_true', dest='test',
else:
dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled,
options.output,
- [options.c_output_dir, options.h_output_dir])
+ [options.c_output_dir, options.h_output_dir],
+ phase=options.phase)
child_plat (str): struct name of the per_child_plat_auto member,
e.g. 'pci_child_plat'
used (bool): True if the driver is used by the structs being output
+ phase (str): Which phase of U-Boot to use this driver
"""
def __init__(self, name, fname):
self.name = name
self.child_priv = ''
self.child_plat = ''
self.used = False
+ self.phase = ''
def __eq__(self, other):
return (self.name == other.name and
_structs: Dict of all structs found in U-Boot:
key: Name of struct
value: Struct object
+ _phase: The phase of U-Boot that we are generating data for, e.g. 'spl'
+ or 'tpl'. None if not known
"""
- def __init__(self, basedir, warning_disabled, drivers_additional):
+ def __init__(self, basedir, warning_disabled, drivers_additional, phase=''):
"""Set up a new Scanner
"""
if not basedir:
self._compat_to_driver = {}
self._uclass = {}
self._structs = {}
+ self._phase = phase
def get_driver(self, name):
"""Get a driver given its name
re_of_match = re.compile(
r'\.of_match\s*=\s*(of_match_ptr\()?([a-z0-9_]+)(\))?,')
+ re_phase = re.compile('^\s*DM_PHASE\((.*)\).*$')
+
# 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')
m_plat = re_plat.match(line)
m_cplat = re_child_plat.match(line)
m_cpriv = re_child_priv.match(line)
+ m_phase = re_phase.match(line)
if m_priv:
driver.priv = m_priv.group(1)
elif m_plat:
driver.uclass_id = m_id.group(1)
elif m_of_match:
compat = m_of_match.group(2)
+ elif m_phase:
+ driver.phase = m_phase.group(1)
elif '};' in line:
if driver.uclass_id and compat:
if compat not in of_match:
dtb_file (str): Filename of .dtb file
output (str): Filename of output file
"""
- dtb_platdata.run_steps(args, dtb_file, False, output, [], True,
- None, None, scan=copy_scan())
+ dtb_platdata.run_steps(args, dtb_file, False, output, [], None,
+ warning_disabled=True, scan=copy_scan())
def test_name(self):
"""Test conversion of device tree names to C identifiers"""
output = tools.GetOutputFilename('output')
with test_util.capture_sys_output() as _:
dtb_platdata.run_steps(['struct'], dtb_file, False, output, [],
- scan=copy_scan())
+ None, scan=copy_scan())
with open(output) as infile:
data = infile.read()
self._check_strings(HEADER + '''
with test_util.capture_sys_output() as _:
dtb_platdata.run_steps(['platdata'], dtb_file, False, output, [],
- scan=copy_scan())
+ None, scan=copy_scan())
with open(output) as infile:
data = infile.read()
self._check_strings(C_HEADER + '''
def test_output_conflict(self):
"""Test a conflict between and output dirs and output file"""
with self.assertRaises(ValueError) as exc:
- dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], True,
- scan=copy_scan())
+ dtb_platdata.run_steps(['all'], None, False, 'out', ['cdir'], None,
+ warning_disabled=True, scan=copy_scan())
self.assertIn("Must specify either output or output_dirs, not both",
str(exc.exception))
fnames = glob.glob(outdir + '/*')
self.assertEqual(2, len(fnames))
- dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True,
- scan=copy_scan())
+ dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], None,
+ warning_disabled=True, scan=copy_scan())
fnames = glob.glob(outdir + '/*')
self.assertEqual(4, len(fnames))
self.assertIn('i2c_tegra', scan._drivers)
drv = scan._drivers['i2c_tegra']
self.assertEqual('i2c_tegra', drv.name)
+ self.assertEqual('', drv.phase)
def test_priv(self):
"""Test collection of struct info from drivers"""
.plat_auto = sizeof(struct some_plat),
.per_child_auto = sizeof(struct some_cpriv),
.per_child_plat_auto = sizeof(struct some_cplat),
+ DM_PHASE(tpl)
};
'''
scan = src_scan.Scanner(None, False, None)
self.assertEqual('some_plat', drv.plat)
self.assertEqual('some_cpriv', drv.child_priv)
self.assertEqual('some_cplat', drv.child_plat)
+ self.assertEqual('tpl', drv.phase)
self.assertEqual(1, len(scan._drivers))
def test_uclass_scan(self):