blob: 9583b3fa5f6b880d8d4109dcc4015e10b6425b73 [file] [log] [blame]
Simon Glassc55a50f2018-09-14 04:57:19 -06001# SPDX-License-Identifier: GPL-2.0+
2# Copyright 2018 Google, Inc
3# Written by Simon Glass <sjg@chromium.org>
4#
5# Holds and modifies the state information held by binman
6#
7
8import re
9from sets import Set
10
11import os
12import tools
13
14# Records the device-tree files known to binman, keyed by filename (e.g.
15# 'u-boot-spl.dtb')
16fdt_files = {}
17
18# Arguments passed to binman to provide arguments to entries
19entry_args = {}
20
Simon Glass2a72cc72018-09-14 04:57:20 -060021# Set of all device tree files references by images
22fdt_set = Set()
23
24# Same as above, but excluding the main one
25fdt_subset = Set()
26
27# The DTB which contains the full image information
28main_dtb = None
29
Simon Glassc55a50f2018-09-14 04:57:19 -060030def GetFdt(fname):
31 """Get the Fdt object for a particular device-tree filename
32
33 Binman keeps track of at least one device-tree file called u-boot.dtb but
34 can also have others (e.g. for SPL). This function looks up the given
35 filename and returns the associated Fdt object.
36
37 Args:
38 fname: Filename to look up (e.g. 'u-boot.dtb').
39
40 Returns:
41 Fdt object associated with the filename
42 """
43 return fdt_files[fname]
44
45def GetFdtPath(fname):
46 """Get the full pathname of a particular Fdt object
47
48 Similar to GetFdt() but returns the pathname associated with the Fdt.
49
50 Args:
51 fname: Filename to look up (e.g. 'u-boot.dtb').
52
53 Returns:
54 Full path name to the associated Fdt
55 """
56 return fdt_files[fname]._fname
57
58def SetEntryArgs(args):
59 """Set the value of the entry args
60
61 This sets up the entry_args dict which is used to supply entry arguments to
62 entries.
63
64 Args:
65 args: List of entry arguments, each in the format "name=value"
66 """
67 global entry_args
68
69 entry_args = {}
70 if args:
71 for arg in args:
72 m = re.match('([^=]*)=(.*)', arg)
73 if not m:
74 raise ValueError("Invalid entry arguemnt '%s'" % arg)
75 entry_args[m.group(1)] = m.group(2)
76
77def GetEntryArg(name):
78 """Get the value of an entry argument
79
80 Args:
81 name: Name of argument to retrieve
82
83 Returns:
84 String value of argument
85 """
86 return entry_args.get(name)
Simon Glass2a72cc72018-09-14 04:57:20 -060087
88def Prepare(dtb):
89 """Get device tree files ready for use
90
91 This sets up a set of device tree files that can be retrieved by GetFdts().
92 At present there is only one, that for U-Boot proper.
93
94 Args:
95 dtb: Main dtb
96 """
97 global fdt_set, fdt_subset, fdt_files, main_dtb
98 # Import these here in case libfdt.py is not available, in which case
99 # the above help option still works.
100 import fdt
101 import fdt_util
102
103 # If we are updating the DTBs we need to put these updated versions
104 # where Entry_blob_dtb can find them. We can ignore 'u-boot.dtb'
105 # since it is assumed to be the one passed in with options.dt, and
106 # was handled just above.
107 main_dtb = dtb
108 fdt_files.clear()
109 fdt_files['u-boot.dtb'] = dtb
110 fdt_set = Set()
111 fdt_subset = Set()
112
113def GetFdts():
114 """Yield all device tree files being used by binman
115
116 Yields:
117 Device trees being used (U-Boot proper, SPL, TPL)
118 """
119 yield main_dtb
120