1 # Copyright (c) 2016 Google, Inc
2 # Written by Simon Glass <sjg@chromium.org>
4 # SPDX-License-Identifier: GPL-2.0+
6 # Creates binary images from input files controlled by a description
9 from collections import OrderedDict
17 from image import Image
20 # List of images we plan to create
21 # Make this global so that it can be referenced from tests
22 images = OrderedDict()
24 def _ReadImageDesc(binman_node):
25 """Read the image descriptions from the /binman node
27 This normally produces a single Image object called 'image'. But if
28 multiple images are present, they will all be returned.
31 binman_node: Node object of the /binman node
33 OrderedDict of Image objects, each of which describes an image
35 images = OrderedDict()
36 if 'multiple-images' in binman_node.props:
37 for node in binman_node.subnodes:
38 images[node.name] = Image(node.name, node)
40 images['image'] = Image('image', binman_node)
43 def _FindBinmanNode(fdt):
44 """Find the 'binman' node in the device tree
47 fdt: Fdt object to scan
49 Node object of /binman node, or None if not found
51 for node in fdt.GetRoot().subnodes:
52 if node.name == 'binman':
56 def Binman(options, args):
57 """The main control code for binman
59 This assumes that help and test options have already been dealt with. It
60 deals with the core task of building images.
63 options: Command line options object
64 args: Command line arguments (list of strings)
69 pager = os.getenv('PAGER')
72 fname = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
74 command.Run(pager, fname)
77 # Try to figure out which device tree contains our image description
79 dtb_fname = options.dt
83 raise ValueError('Must provide a board to process (use -b <board>)')
84 board_pathname = os.path.join(options.build_dir, board)
85 dtb_fname = os.path.join(board_pathname, 'u-boot.dtb')
88 options.indir.append(board_pathname)
91 tout.Init(options.verbosity)
93 tools.SetInputDirs(options.indir)
94 tools.PrepareOutputDir(options.outdir, options.preserve)
95 fdt = fdt_select.FdtScan(dtb_fname)
96 node = _FindBinmanNode(fdt)
98 raise ValueError("Device tree '%s' does not have a 'binman' "
100 images = _ReadImageDesc(node)
101 for image in images.values():
102 # Perform all steps for this image, including checking and
103 # writing it. This means that errors found with a later
104 # image will be reported after earlier images are already
105 # completed and written, but that does not seem important.
106 image.GetEntryContents()
107 image.GetEntryPositions()
111 image.ProcessEntryContents()
114 tools.FinaliseOutputDir()