1# SPDX-License-Identifier: GPL-2.0+
2# Copyright 2021 Google LLC
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Entry-type base class for U-Boot or SPL binary with devicetree
6#
7
8from binman.etype.section import Entry_section
9
10class Entry_blob_phase(Entry_section):
11    """Section that holds a phase binary
12
13    This is a base class that should not normally be used directly. It is used
14    when converting a 'u-boot' entry automatically into a 'u-boot-expanded'
15    entry; similarly for SPL.
16    """
17    def __init__(self, section, etype, node, root_fname, dtb_file, bss_pad):
18        """Set up a new blob for a phase
19
20        This holds an executable for a U-Boot phase, optional BSS padding and
21        a devicetree
22
23        Args:
24            section: entry_Section object for this entry's parent
25            etype: Type of object
26            node: Node defining this entry
27            root_fname: Root filename for the binary ('u-boot',
28                'spl/u-boot-spl', etc.)
29            dtb_file: Name of devicetree file ('u-boot.dtb', u-boot-spl.dtb',
30                etc.)
31            bss_pad: True to add BSS padding before the devicetree
32        """
33        # Put this here to allow entry-docs and help to work without libfdt
34        global state
35        from binman import state
36
37        super().__init__(section, etype, node)
38        self.root_fname = root_fname
39        self.dtb_file = dtb_file
40        self.bss_pad = bss_pad
41
42    def ExpandEntries(self):
43        """Create the subnodes"""
44        names = [self.root_fname + '-nodtb', self.root_fname + '-dtb']
45        if self.bss_pad:
46            names.insert(1, self.root_fname + '-bss-pad')
47        for name in names:
48            subnode = state.AddSubnode(self._node, name)
49
50        # Read entries again, now that we have some
51        self._ReadEntries()
52