dtoc: Add an 'all' command
With upcoming changes, dtoc will output several files for different of-platdata components. Add a way to output all ava!ilable files at once ('all'), to the appropriate directories, without needing to specify each one invidually. This puts the commands in alphabetical order, so update the tests accordingly. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
be44f27156
commit
10cbd3b7da
@ -862,11 +862,14 @@ def run_steps(args, dtb_file, include_disabled, output, output_dirs,
|
|||||||
structs = plat.scan_structs()
|
structs = plat.scan_structs()
|
||||||
plat.scan_phandles()
|
plat.scan_phandles()
|
||||||
|
|
||||||
for cmd in args[0].split(','):
|
cmds = args[0].split(',')
|
||||||
|
if 'all' in cmds:
|
||||||
|
cmds = sorted(OUTPUT_FILES.keys())
|
||||||
|
for cmd in cmds:
|
||||||
outfile = OUTPUT_FILES.get(cmd)
|
outfile = OUTPUT_FILES.get(cmd)
|
||||||
if not outfile:
|
if not outfile:
|
||||||
raise ValueError("Unknown command '%s': (use: %s)" %
|
raise ValueError("Unknown command '%s': (use: %s)" %
|
||||||
(cmd, ', '.join(OUTPUT_FILES.keys())))
|
(cmd, ', '.join(sorted(OUTPUT_FILES.keys()))))
|
||||||
plat.setup_output(outfile.ftype,
|
plat.setup_output(outfile.ftype,
|
||||||
outfile.fname if output_dirs else output)
|
outfile.fname if output_dirs else output)
|
||||||
if cmd == 'struct':
|
if cmd == 'struct':
|
||||||
|
@ -13,11 +13,7 @@ having to link against libfdt. By putting the data from the device tree into
|
|||||||
C structures, normal C code can be used. This helps to reduce the size of the
|
C structures, normal C code can be used. This helps to reduce the size of the
|
||||||
compiled program.
|
compiled program.
|
||||||
|
|
||||||
Dtoc produces two output files:
|
Dtoc produces several output files - see OUTPUT_FILES in dtb_platdata.py
|
||||||
|
|
||||||
dt-structs.h - contains struct definitions
|
|
||||||
dt-platdata.c - contains data from the device tree using the struct
|
|
||||||
definitions, as well as U-Boot driver definitions.
|
|
||||||
|
|
||||||
This tool is used in U-Boot to provide device tree data to SPL without
|
This tool is used in U-Boot to provide device tree data to SPL without
|
||||||
increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
|
increasing the code size of SPL. This supports the CONFIG_SPL_OF_PLATDATA
|
||||||
|
@ -10,6 +10,7 @@ tool.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -302,6 +303,11 @@ U_BOOT_DEVICE(spl_test3) = {
|
|||||||
|
|
||||||
self._check_strings(self.platdata_text, data)
|
self._check_strings(self.platdata_text, data)
|
||||||
|
|
||||||
|
# Try the 'all' command
|
||||||
|
self.run_test(['all'], dtb_file, output)
|
||||||
|
data = tools.ReadFile(output, binary=False)
|
||||||
|
self._check_strings(self.platdata_text + self.struct_text, data)
|
||||||
|
|
||||||
def test_driver_alias(self):
|
def test_driver_alias(self):
|
||||||
"""Test output from a device tree file with a driver alias"""
|
"""Test output from a device tree file with a driver alias"""
|
||||||
dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
|
dtb_file = get_dtb_file('dtoc_test_driver_alias.dts')
|
||||||
@ -888,9 +894,9 @@ U_BOOT_DEVICE(spl_test2) = {
|
|||||||
"""Test output of multiple pieces to a single file"""
|
"""Test output of multiple pieces to a single file"""
|
||||||
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
||||||
output = tools.GetOutputFilename('output')
|
output = tools.GetOutputFilename('output')
|
||||||
self.run_test(['struct,platdata'], dtb_file, output)
|
self.run_test(['all'], dtb_file, output)
|
||||||
data = tools.ReadFile(output, binary=False)
|
data = tools.ReadFile(output, binary=False)
|
||||||
self._check_strings(self.struct_text + self.platdata_text, data)
|
self._check_strings(self.platdata_text + self.struct_text, data)
|
||||||
|
|
||||||
def test_no_command(self):
|
def test_no_command(self):
|
||||||
"""Test running dtoc without a command"""
|
"""Test running dtoc without a command"""
|
||||||
@ -905,7 +911,7 @@ U_BOOT_DEVICE(spl_test2) = {
|
|||||||
output = tools.GetOutputFilename('output')
|
output = tools.GetOutputFilename('output')
|
||||||
with self.assertRaises(ValueError) as exc:
|
with self.assertRaises(ValueError) as exc:
|
||||||
self.run_test(['invalid-cmd'], dtb_file, output)
|
self.run_test(['invalid-cmd'], dtb_file, output)
|
||||||
self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)",
|
self.assertIn("Unknown command 'invalid-cmd': (use: platdata, struct)",
|
||||||
str(exc.exception))
|
str(exc.exception))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -945,3 +951,31 @@ U_BOOT_DEVICE(spl_test2) = {
|
|||||||
self.assertEqual(drv1, drv3)
|
self.assertEqual(drv1, drv3)
|
||||||
self.assertNotEqual(drv1, drv2)
|
self.assertNotEqual(drv1, drv2)
|
||||||
self.assertNotEqual(drv2, drv3)
|
self.assertNotEqual(drv2, drv3)
|
||||||
|
|
||||||
|
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)
|
||||||
|
self.assertIn("Must specify either output or output_dirs, not both",
|
||||||
|
str(exc.exception))
|
||||||
|
|
||||||
|
def test_output_dirs(self):
|
||||||
|
"""Test outputting files to a directory"""
|
||||||
|
# Remove the directory so that files from other tests are not there
|
||||||
|
tools._RemoveOutputDir()
|
||||||
|
tools.PrepareOutputDir(None)
|
||||||
|
|
||||||
|
# This should create the .dts and .dtb in the output directory
|
||||||
|
dtb_file = get_dtb_file('dtoc_test_simple.dts')
|
||||||
|
outdir = tools.GetOutputDir()
|
||||||
|
fnames = glob.glob(outdir + '/*')
|
||||||
|
self.assertEqual(2, len(fnames))
|
||||||
|
|
||||||
|
dtb_platdata.run_steps(['all'], dtb_file, False, None, [outdir], True)
|
||||||
|
fnames = glob.glob(outdir + '/*')
|
||||||
|
self.assertEqual(4, len(fnames))
|
||||||
|
|
||||||
|
leafs = set(os.path.basename(fname) for fname in fnames)
|
||||||
|
self.assertEqual(
|
||||||
|
{'dt-structs-gen.h', 'source.dts', 'dt-platdata.c', 'source.dtb'},
|
||||||
|
leafs)
|
||||||
|
@ -94,6 +94,14 @@ def GetOutputFilename(fname):
|
|||||||
"""
|
"""
|
||||||
return os.path.join(outdir, fname)
|
return os.path.join(outdir, fname)
|
||||||
|
|
||||||
|
def GetOutputDir():
|
||||||
|
"""Return the current output directory
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: The output directory
|
||||||
|
"""
|
||||||
|
return outdir
|
||||||
|
|
||||||
def _FinaliseForTest():
|
def _FinaliseForTest():
|
||||||
"""Remove the output directory (for use by tests)"""
|
"""Remove the output directory (for use by tests)"""
|
||||||
global outdir
|
global outdir
|
||||||
|
Loading…
Reference in New Issue
Block a user