[PATCH 0/2] Allow to append a list of directories in u_boot_pylib/tools.py

The idea here is not to have to pass twice the FDT directory, i.e. once with the 'fit,fdt-list-dir' property in the device tree passed to binman and in the input arguments of binman with '-I' option. The method append_input_dirs() can be used to append a list of directories to the existing list of input directories. The method avoids duplicates and the method ReadNode() of the class Entry_fit calls tools.append_input_dirs() to add the FDT directory to the list of input directories.
Paul HENRYS (2): tools: u_boot_pylib: Allow to append input directories to indir tools: binman: etype: fit: Append DTB directory to the list of input directories
tools/binman/etype/fit.py | 2 ++ tools/binman/ftest.py | 5 ++++- tools/u_boot_pylib/tools.py | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-)

append_input_dirs() can be used to append a list of input directories to indir global list.
Signed-off-by: Paul HENRYS paul.henrys_ext@softathome.com --- tools/u_boot_pylib/tools.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
diff --git a/tools/u_boot_pylib/tools.py b/tools/u_boot_pylib/tools.py index 187725b501..0499a75526 100644 --- a/tools/u_boot_pylib/tools.py +++ b/tools/u_boot_pylib/tools.py @@ -123,6 +123,22 @@ def set_input_dirs(dirname): indir = dirname tout.debug("Using input directories %s" % indir)
+def append_input_dirs(dirname): + """Append a list of input directories to the current list of input + directories + + Args: + dirname: a list of paths to input directories to use for obtaining + files needed by binman to place in the image. + """ + global indir + + for dir in dirname: + if dirname not in indir: + indir.append(dirname) + + tout.debug("Updated input directories %s" % indir) + def get_input_filename(fname, allow_missing=False): """Return a filename for use as input.

On Mon, 25 Nov 2024 at 11:17, Paul HENRYS paul.henrys_ext@softathome.com wrote:
append_input_dirs() can be used to append a list of input directories to indir global list.
Signed-off-by: Paul HENRYS paul.henrys_ext@softathome.com
tools/u_boot_pylib/tools.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/tools/u_boot_pylib/tools.py b/tools/u_boot_pylib/tools.py index 187725b501..0499a75526 100644 --- a/tools/u_boot_pylib/tools.py +++ b/tools/u_boot_pylib/tools.py @@ -123,6 +123,22 @@ def set_input_dirs(dirname): indir = dirname tout.debug("Using input directories %s" % indir)
+def append_input_dirs(dirname):
- """Append a list of input directories to the current list of input
- directories
- Args:
dirname: a list of paths to input directories to use for obtaining
files needed by binman to place in the image.
- """
- global indir
- for dir in dirname:
if dirname not in indir:
indir.append(dirname)
- tout.debug("Updated input directories %s" % indir)
def get_input_filename(fname, allow_missing=False): """Return a filename for use as input.
-- 2.43.0

When specifying a directory containing DTBs with 'fit,fdt-list-dir', it can be handy not to have to also specify this directory to the input directories of binman with '-I' option and use the method tools.append_input_dirs() append it. This avoids to have to specify the DTB directory in both the device tree provided to binman and through '-I' option to binman.
Signed-off-by: Paul HENRYS paul.henrys_ext@softathome.com --- tools/binman/etype/fit.py | 2 ++ tools/binman/ftest.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 343094a16e..803fb66ea8 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -477,6 +477,8 @@ class Entry_fit(Entry_section): self._fdt_dir = fdt_util.GetString(self._node, 'fit,fdt-list-dir') if self._fdt_dir: indir = tools.get_input_filename(self._fdt_dir) + if indir: + tools.append_input_dirs(indir) fdts = glob.glob('*.dtb', root_dir=indir) self._fdts = [os.path.splitext(f)[0] for f in sorted(fdts)] else: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4a2a9f2288..a553ca9e56 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -4285,14 +4285,17 @@ class TestFunctional(unittest.TestCase): entry_args = { 'default-dt': 'test-fdt2', } + extra_indirs = None if use_fdt_list: entry_args['of-list'] = 'test-fdt1 test-fdt2' if default_dt: entry_args['default-dt'] = default_dt + if use_fdt_list: + extra_indirs = [os.path.join(self._indir, TEST_FDT_SUBDIR)] data = self._DoReadFileDtb( dts, entry_args=entry_args, - extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)])[0] + extra_indirs=extra_indirs)[0] self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) fit_data = data[len(U_BOOT_DATA):-len(U_BOOT_NODTB_DATA)]

Hi Paul,
On Mon, 25 Nov 2024 at 11:17, Paul HENRYS paul.henrys_ext@softathome.com wrote:
When specifying a directory containing DTBs with 'fit,fdt-list-dir', it can be handy not to have to also specify this directory to the input directories of binman with '-I' option and use the method tools.append_input_dirs() append it. This avoids to have to specify the DTB directory in both the device tree provided to binman and through '-I' option to binman.
Signed-off-by: Paul HENRYS paul.henrys_ext@softathome.com
tools/binman/etype/fit.py | 2 ++ tools/binman/ftest.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-)
Reviewed-by: Simon Glass sjg@chromium.org
But please add something to the FIT docs (and regenerate entries.rst) so people know about this.
I would actually prefer something ephemeral, i.e. that just adds the extra dirs for FIT and not the whole of Binman, but that's a minor point and would be more complicated to implement.
diff --git a/tools/binman/etype/fit.py b/tools/binman/etype/fit.py index 343094a16e..803fb66ea8 100644 --- a/tools/binman/etype/fit.py +++ b/tools/binman/etype/fit.py @@ -477,6 +477,8 @@ class Entry_fit(Entry_section): self._fdt_dir = fdt_util.GetString(self._node, 'fit,fdt-list-dir') if self._fdt_dir: indir = tools.get_input_filename(self._fdt_dir)
if indir:
tools.append_input_dirs(indir) fdts = glob.glob('*.dtb', root_dir=indir) self._fdts = [os.path.splitext(f)[0] for f in sorted(fdts)] else:
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 4a2a9f2288..a553ca9e56 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -4285,14 +4285,17 @@ class TestFunctional(unittest.TestCase): entry_args = { 'default-dt': 'test-fdt2', }
extra_indirs = None if use_fdt_list: entry_args['of-list'] = 'test-fdt1 test-fdt2' if default_dt: entry_args['default-dt'] = default_dt
if use_fdt_list:
extra_indirs = [os.path.join(self._indir, TEST_FDT_SUBDIR)] data = self._DoReadFileDtb( dts, entry_args=entry_args,
extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)])[0]
extra_indirs=extra_indirs)[0] self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):]) fit_data = data[len(U_BOOT_DATA):-len(U_BOOT_NODTB_DATA)]
-- 2.43.0
Regards, Simon

On Mon, 25 Nov 2024 19:16:52 +0100, Paul HENRYS wrote:
The idea here is not to have to pass twice the FDT directory, i.e. once with the 'fit,fdt-list-dir' property in the device tree passed to binman and in the input arguments of binman with '-I' option. The method append_input_dirs() can be used to append a list of directories to the existing list of input directories. The method avoids duplicates and the method ReadNode() of the class Entry_fit calls tools.append_input_dirs() to add the FDT directory to the list of input directories.
[...]
Applied to u-boot/next, thanks!
participants (3)
-
Paul HENRYS
-
Simon Glass
-
Tom Rini