1# SPDX-License-Identifier: GPL-2.0+
2# Copyright (c) 2016 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Entry-type module for a list of external blobs, not built by U-Boot
6#
7
8import os
9
10from binman.etype.blob import Entry_blob
11from dtoc import fdt_util
12from u_boot_pylib import tools
13from u_boot_pylib import tout
14
15class Entry_blob_ext_list(Entry_blob):
16    """List of externally built binary blobs
17
18    This is like blob-ext except that a number of blobs can be provided,
19    typically with some sort of relationship, e.g. all are DDC parameters.
20
21    If any of the external files needed by this llist is missing, binman can
22    optionally ignore it and produce a broken image with a warning.
23
24    Args:
25        filenames: List of filenames to read and include
26    """
27    def __init__(self, section, etype, node):
28        Entry_blob.__init__(self, section, etype, node)
29        self.external = True
30
31    def ReadNode(self):
32        super().ReadNode()
33        self._filenames = fdt_util.GetStringList(self._node, 'filenames')
34        self._pathnames = []
35
36    def ObtainContents(self):
37        missing = False
38        pathnames = []
39        for fname in self._filenames:
40            fname, _ = self.check_fake_fname(fname)
41            pathname = tools.get_input_filename(
42                fname, self.external and self.section.GetAllowMissing())
43            # Allow the file to be missing
44            if not pathname:
45                missing = True
46            pathnames.append(pathname)
47        self._pathnames = pathnames
48
49        if missing:
50            self.SetContents(b'')
51            self.missing = True
52            return True
53
54        data = bytearray()
55        for pathname in pathnames:
56            data += self.ReadFileContents(pathname)
57
58        self.SetContents(data)
59        return True
60