section.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. # SPDX-License-Identifier: GPL-2.0+
  2. # Copyright (c) 2018 Google, Inc
  3. # Written by Simon Glass <sjg@chromium.org>
  4. """Entry-type module for sections (groups of entries)
  5. Sections are entries which can contain other entries. This allows hierarchical
  6. images to be created.
  7. """
  8. from collections import OrderedDict
  9. import concurrent.futures
  10. import re
  11. import sys
  12. from binman.entry import Entry
  13. from binman import state
  14. from dtoc import fdt_util
  15. from patman import tools
  16. from patman import tout
  17. from patman.tools import ToHexSize
  18. class Entry_section(Entry):
  19. """Entry that contains other entries
  20. Properties / Entry arguments: (see binman README for more information):
  21. pad-byte: Pad byte to use when padding
  22. sort-by-offset: True if entries should be sorted by offset, False if
  23. they must be in-order in the device tree description
  24. end-at-4gb: Used to build an x86 ROM which ends at 4GB (2^32)
  25. skip-at-start: Number of bytes before the first entry starts. These
  26. effectively adjust the starting offset of entries. For example,
  27. if this is 16, then the first entry would start at 16. An entry
  28. with offset = 20 would in fact be written at offset 4 in the image
  29. file, since the first 16 bytes are skipped when writing.
  30. name-prefix: Adds a prefix to the name of every entry in the section
  31. when writing out the map
  32. align_default: Default alignment for this section, if no alignment is
  33. given in the entry
  34. Properties:
  35. allow_missing: True if this section permits external blobs to be
  36. missing their contents. The second will produce an image but of
  37. course it will not work.
  38. Since a section is also an entry, it inherits all the properies of entries
  39. too.
  40. A section is an entry which can contain other entries, thus allowing
  41. hierarchical images to be created. See 'Sections and hierarchical images'
  42. in the binman README for more information.
  43. """
  44. def __init__(self, section, etype, node, test=False):
  45. if not test:
  46. super().__init__(section, etype, node)
  47. self._entries = OrderedDict()
  48. self._pad_byte = 0
  49. self._sort = False
  50. self._skip_at_start = None
  51. self._end_4gb = False
  52. def ReadNode(self):
  53. """Read properties from the section node"""
  54. super().ReadNode()
  55. self._pad_byte = fdt_util.GetInt(self._node, 'pad-byte', 0)
  56. self._sort = fdt_util.GetBool(self._node, 'sort-by-offset')
  57. self._end_4gb = fdt_util.GetBool(self._node, 'end-at-4gb')
  58. self._skip_at_start = fdt_util.GetInt(self._node, 'skip-at-start')
  59. if self._end_4gb:
  60. if not self.size:
  61. self.Raise("Section size must be provided when using end-at-4gb")
  62. if self._skip_at_start is not None:
  63. self.Raise("Provide either 'end-at-4gb' or 'skip-at-start'")
  64. else:
  65. self._skip_at_start = 0x100000000 - self.size
  66. else:
  67. if self._skip_at_start is None:
  68. self._skip_at_start = 0
  69. self._name_prefix = fdt_util.GetString(self._node, 'name-prefix')
  70. self.align_default = fdt_util.GetInt(self._node, 'align-default', 0)
  71. filename = fdt_util.GetString(self._node, 'filename')
  72. if filename:
  73. self._filename = filename
  74. self._ReadEntries()
  75. def _ReadEntries(self):
  76. for node in self._node.subnodes:
  77. if node.name.startswith('hash') or node.name.startswith('signature'):
  78. continue
  79. entry = Entry.Create(self, node,
  80. expanded=self.GetImage().use_expanded)
  81. entry.ReadNode()
  82. entry.SetPrefix(self._name_prefix)
  83. self._entries[node.name] = entry
  84. def _Raise(self, msg):
  85. """Raises an error for this section
  86. Args:
  87. msg: Error message to use in the raise string
  88. Raises:
  89. ValueError()
  90. """
  91. raise ValueError("Section '%s': %s" % (self._node.path, msg))
  92. def GetFdts(self):
  93. fdts = {}
  94. for entry in self._entries.values():
  95. fdts.update(entry.GetFdts())
  96. return fdts
  97. def ProcessFdt(self, fdt):
  98. """Allow entries to adjust the device tree
  99. Some entries need to adjust the device tree for their purposes. This
  100. may involve adding or deleting properties.
  101. """
  102. todo = self._entries.values()
  103. for passnum in range(3):
  104. next_todo = []
  105. for entry in todo:
  106. if not entry.ProcessFdt(fdt):
  107. next_todo.append(entry)
  108. todo = next_todo
  109. if not todo:
  110. break
  111. if todo:
  112. self.Raise('Internal error: Could not complete processing of Fdt: remaining %s' %
  113. todo)
  114. return True
  115. def ExpandEntries(self):
  116. super().ExpandEntries()
  117. for entry in self._entries.values():
  118. entry.ExpandEntries()
  119. def AddMissingProperties(self, have_image_pos):
  120. """Add new properties to the device tree as needed for this entry"""
  121. super().AddMissingProperties(have_image_pos)
  122. if self.compress != 'none':
  123. have_image_pos = False
  124. for entry in self._entries.values():
  125. entry.AddMissingProperties(have_image_pos)
  126. def ObtainContents(self):
  127. return self.GetEntryContents()
  128. def GetPaddedDataForEntry(self, entry, entry_data):
  129. """Get the data for an entry including any padding
  130. Gets the entry data and uses the section pad-byte value to add padding
  131. before and after as defined by the pad-before and pad-after properties.
  132. This does not consider alignment.
  133. Args:
  134. entry: Entry to check
  135. Returns:
  136. Contents of the entry along with any pad bytes before and
  137. after it (bytes)
  138. """
  139. pad_byte = (entry._pad_byte if isinstance(entry, Entry_section)
  140. else self._pad_byte)
  141. data = b''
  142. # Handle padding before the entry
  143. if entry.pad_before:
  144. data += tools.GetBytes(self._pad_byte, entry.pad_before)
  145. # Add in the actual entry data
  146. data += entry_data
  147. # Handle padding after the entry
  148. if entry.pad_after:
  149. data += tools.GetBytes(self._pad_byte, entry.pad_after)
  150. if entry.size:
  151. data += tools.GetBytes(pad_byte, entry.size - len(data))
  152. self.Detail('GetPaddedDataForEntry: size %s' % ToHexSize(self.data))
  153. return data
  154. def _BuildSectionData(self, required):
  155. """Build the contents of a section
  156. This places all entries at the right place, dealing with padding before
  157. and after entries. It does not do padding for the section itself (the
  158. pad-before and pad-after properties in the section items) since that is
  159. handled by the parent section.
  160. Args:
  161. required: True if the data must be present, False if it is OK to
  162. return None
  163. Returns:
  164. Contents of the section (bytes)
  165. """
  166. section_data = b''
  167. for entry in self._entries.values():
  168. entry_data = entry.GetData(required)
  169. if not required and entry_data is None:
  170. return None
  171. data = self.GetPaddedDataForEntry(entry, entry_data)
  172. # Handle empty space before the entry
  173. pad = (entry.offset or 0) - self._skip_at_start - len(section_data)
  174. if pad > 0:
  175. section_data += tools.GetBytes(self._pad_byte, pad)
  176. # Add in the actual entry data
  177. section_data += data
  178. self.Detail('GetData: %d entries, total size %#x' %
  179. (len(self._entries), len(section_data)))
  180. return self.CompressData(section_data)
  181. def GetPaddedData(self, data=None):
  182. """Get the data for a section including any padding
  183. Gets the section data and uses the parent section's pad-byte value to
  184. add padding before and after as defined by the pad-before and pad-after
  185. properties. If this is a top-level section (i.e. an image), this is the
  186. same as GetData(), since padding is not supported.
  187. This does not consider alignment.
  188. Returns:
  189. Contents of the section along with any pad bytes before and
  190. after it (bytes)
  191. """
  192. section = self.section or self
  193. if data is None:
  194. data = self.GetData()
  195. return section.GetPaddedDataForEntry(self, data)
  196. def GetData(self, required=True):
  197. """Get the contents of an entry
  198. This builds the contents of the section, stores this as the contents of
  199. the section and returns it
  200. Args:
  201. required: True if the data must be present, False if it is OK to
  202. return None
  203. Returns:
  204. bytes content of the section, made up for all all of its subentries.
  205. This excludes any padding. If the section is compressed, the
  206. compressed data is returned
  207. """
  208. data = self._BuildSectionData(required)
  209. if data is None:
  210. return None
  211. self.SetContents(data)
  212. return data
  213. def GetOffsets(self):
  214. """Handle entries that want to set the offset/size of other entries
  215. This calls each entry's GetOffsets() method. If it returns a list
  216. of entries to update, it updates them.
  217. """
  218. self.GetEntryOffsets()
  219. return {}
  220. def ResetForPack(self):
  221. """Reset offset/size fields so that packing can be done again"""
  222. super().ResetForPack()
  223. for entry in self._entries.values():
  224. entry.ResetForPack()
  225. def Pack(self, offset):
  226. """Pack all entries into the section"""
  227. self._PackEntries()
  228. if self._sort:
  229. self._SortEntries()
  230. self._ExpandEntries()
  231. data = self._BuildSectionData(True)
  232. self.SetContents(data)
  233. self.CheckSize()
  234. offset = super().Pack(offset)
  235. self.CheckEntries()
  236. return offset
  237. def _PackEntries(self):
  238. """Pack all entries into the section"""
  239. offset = self._skip_at_start
  240. for entry in self._entries.values():
  241. offset = entry.Pack(offset)
  242. return offset
  243. def _ExpandEntries(self):
  244. """Expand any entries that are permitted to"""
  245. exp_entry = None
  246. for entry in self._entries.values():
  247. if exp_entry:
  248. exp_entry.ExpandToLimit(entry.offset)
  249. exp_entry = None
  250. if entry.expand_size:
  251. exp_entry = entry
  252. if exp_entry:
  253. exp_entry.ExpandToLimit(self.size)
  254. def _SortEntries(self):
  255. """Sort entries by offset"""
  256. entries = sorted(self._entries.values(), key=lambda entry: entry.offset)
  257. self._entries.clear()
  258. for entry in entries:
  259. self._entries[entry._node.name] = entry
  260. def CheckEntries(self):
  261. """Check that entries do not overlap or extend outside the section"""
  262. max_size = self.size if self.uncomp_size is None else self.uncomp_size
  263. offset = 0
  264. prev_name = 'None'
  265. for entry in self._entries.values():
  266. entry.CheckEntries()
  267. if (entry.offset < self._skip_at_start or
  268. entry.offset + entry.size > self._skip_at_start +
  269. max_size):
  270. entry.Raise('Offset %#x (%d) size %#x (%d) is outside the '
  271. "section '%s' starting at %#x (%d) "
  272. 'of size %#x (%d)' %
  273. (entry.offset, entry.offset, entry.size, entry.size,
  274. self._node.path, self._skip_at_start,
  275. self._skip_at_start, max_size, max_size))
  276. if entry.offset < offset and entry.size:
  277. entry.Raise("Offset %#x (%d) overlaps with previous entry '%s' "
  278. "ending at %#x (%d)" %
  279. (entry.offset, entry.offset, prev_name, offset, offset))
  280. offset = entry.offset + entry.size
  281. prev_name = entry.GetPath()
  282. def WriteSymbols(self, section):
  283. """Write symbol values into binary files for access at run time"""
  284. for entry in self._entries.values():
  285. entry.WriteSymbols(self)
  286. def SetCalculatedProperties(self):
  287. super().SetCalculatedProperties()
  288. for entry in self._entries.values():
  289. entry.SetCalculatedProperties()
  290. def SetImagePos(self, image_pos):
  291. super().SetImagePos(image_pos)
  292. if self.compress == 'none':
  293. for entry in self._entries.values():
  294. entry.SetImagePos(image_pos + self.offset)
  295. def ProcessContents(self):
  296. sizes_ok_base = super(Entry_section, self).ProcessContents()
  297. sizes_ok = True
  298. for entry in self._entries.values():
  299. if not entry.ProcessContents():
  300. sizes_ok = False
  301. return sizes_ok and sizes_ok_base
  302. def WriteMap(self, fd, indent):
  303. """Write a map of the section to a .map file
  304. Args:
  305. fd: File to write the map to
  306. """
  307. Entry.WriteMapLine(fd, indent, self.name, self.offset or 0,
  308. self.size, self.image_pos)
  309. for entry in self._entries.values():
  310. entry.WriteMap(fd, indent + 1)
  311. def GetEntries(self):
  312. return self._entries
  313. def GetContentsByPhandle(self, phandle, source_entry, required):
  314. """Get the data contents of an entry specified by a phandle
  315. This uses a phandle to look up a node and and find the entry
  316. associated with it. Then it returns the contents of that entry.
  317. The node must be a direct subnode of this section.
  318. Args:
  319. phandle: Phandle to look up (integer)
  320. source_entry: Entry containing that phandle (used for error
  321. reporting)
  322. required: True if the data must be present, False if it is OK to
  323. return None
  324. Returns:
  325. data from associated entry (as a string), or None if not found
  326. """
  327. node = self._node.GetFdt().LookupPhandle(phandle)
  328. if not node:
  329. source_entry.Raise("Cannot find node for phandle %d" % phandle)
  330. for entry in self._entries.values():
  331. if entry._node == node:
  332. return entry.GetData(required)
  333. source_entry.Raise("Cannot find entry for node '%s'" % node.name)
  334. def LookupSymbol(self, sym_name, optional, msg, base_addr, entries=None):
  335. """Look up a symbol in an ELF file
  336. Looks up a symbol in an ELF file. Only entry types which come from an
  337. ELF image can be used by this function.
  338. At present the only entry properties supported are:
  339. offset
  340. image_pos - 'base_addr' is added if this is not an end-at-4gb image
  341. size
  342. Args:
  343. sym_name: Symbol name in the ELF file to look up in the format
  344. _binman_<entry>_prop_<property> where <entry> is the name of
  345. the entry and <property> is the property to find (e.g.
  346. _binman_u_boot_prop_offset). As a special case, you can append
  347. _any to <entry> to have it search for any matching entry. E.g.
  348. _binman_u_boot_any_prop_offset will match entries called u-boot,
  349. u-boot-img and u-boot-nodtb)
  350. optional: True if the symbol is optional. If False this function
  351. will raise if the symbol is not found
  352. msg: Message to display if an error occurs
  353. base_addr: Base address of image. This is added to the returned
  354. image_pos in most cases so that the returned position indicates
  355. where the targetted entry/binary has actually been loaded. But
  356. if end-at-4gb is used, this is not done, since the binary is
  357. already assumed to be linked to the ROM position and using
  358. execute-in-place (XIP).
  359. Returns:
  360. Value that should be assigned to that symbol, or None if it was
  361. optional and not found
  362. Raises:
  363. ValueError if the symbol is invalid or not found, or references a
  364. property which is not supported
  365. """
  366. m = re.match(r'^_binman_(\w+)_prop_(\w+)$', sym_name)
  367. if not m:
  368. raise ValueError("%s: Symbol '%s' has invalid format" %
  369. (msg, sym_name))
  370. entry_name, prop_name = m.groups()
  371. entry_name = entry_name.replace('_', '-')
  372. if not entries:
  373. entries = self._entries
  374. entry = entries.get(entry_name)
  375. if not entry:
  376. if entry_name.endswith('-any'):
  377. root = entry_name[:-4]
  378. for name in entries:
  379. if name.startswith(root):
  380. rest = name[len(root):]
  381. if rest in ['', '-img', '-nodtb']:
  382. entry = entries[name]
  383. if not entry:
  384. err = ("%s: Entry '%s' not found in list (%s)" %
  385. (msg, entry_name, ','.join(entries.keys())))
  386. if optional:
  387. print('Warning: %s' % err, file=sys.stderr)
  388. return None
  389. raise ValueError(err)
  390. if prop_name == 'offset':
  391. return entry.offset
  392. elif prop_name == 'image_pos':
  393. value = entry.image_pos
  394. if not self.GetImage()._end_4gb:
  395. value += base_addr
  396. return value
  397. if prop_name == 'size':
  398. return entry.size
  399. else:
  400. raise ValueError("%s: No such property '%s'" % (msg, prop_name))
  401. def GetRootSkipAtStart(self):
  402. """Get the skip-at-start value for the top-level section
  403. This is used to find out the starting offset for root section that
  404. contains this section. If this is a top-level section then it returns
  405. the skip-at-start offset for this section.
  406. This is used to get the absolute position of section within the image.
  407. Returns:
  408. Integer skip-at-start value for the root section containing this
  409. section
  410. """
  411. if self.section:
  412. return self.section.GetRootSkipAtStart()
  413. return self._skip_at_start
  414. def GetStartOffset(self):
  415. """Get the start offset for this section
  416. Returns:
  417. The first available offset in this section (typically 0)
  418. """
  419. return self._skip_at_start
  420. def GetImageSize(self):
  421. """Get the size of the image containing this section
  422. Returns:
  423. Image size as an integer number of bytes, which may be None if the
  424. image size is dynamic and its sections have not yet been packed
  425. """
  426. return self.GetImage().size
  427. def FindEntryType(self, etype):
  428. """Find an entry type in the section
  429. Args:
  430. etype: Entry type to find
  431. Returns:
  432. entry matching that type, or None if not found
  433. """
  434. for entry in self._entries.values():
  435. if entry.etype == etype:
  436. return entry
  437. return None
  438. def GetEntryContents(self):
  439. """Call ObtainContents() for each entry in the section
  440. """
  441. def _CheckDone(entry):
  442. if not entry.ObtainContents():
  443. next_todo.append(entry)
  444. return entry
  445. todo = self._entries.values()
  446. for passnum in range(3):
  447. threads = state.GetThreads()
  448. next_todo = []
  449. if threads == 0:
  450. for entry in todo:
  451. _CheckDone(entry)
  452. else:
  453. with concurrent.futures.ThreadPoolExecutor(
  454. max_workers=threads) as executor:
  455. future_to_data = {
  456. entry: executor.submit(_CheckDone, entry)
  457. for entry in todo}
  458. timeout = 60
  459. if self.GetImage().test_section_timeout:
  460. timeout = 0
  461. done, not_done = concurrent.futures.wait(
  462. future_to_data.values(), timeout=timeout)
  463. # Make sure we check the result, so any exceptions are
  464. # generated. Check the results in entry order, since tests
  465. # may expect earlier entries to fail first.
  466. for entry in todo:
  467. job = future_to_data[entry]
  468. job.result()
  469. if not_done:
  470. self.Raise('Timed out obtaining contents')
  471. todo = next_todo
  472. if not todo:
  473. break
  474. if todo:
  475. self.Raise('Internal error: Could not complete processing of contents: remaining %s' %
  476. todo)
  477. return True
  478. def _SetEntryOffsetSize(self, name, offset, size):
  479. """Set the offset and size of an entry
  480. Args:
  481. name: Entry name to update
  482. offset: New offset, or None to leave alone
  483. size: New size, or None to leave alone
  484. """
  485. entry = self._entries.get(name)
  486. if not entry:
  487. self._Raise("Unable to set offset/size for unknown entry '%s'" %
  488. name)
  489. entry.SetOffsetSize(self._skip_at_start + offset if offset is not None
  490. else None, size)
  491. def GetEntryOffsets(self):
  492. """Handle entries that want to set the offset/size of other entries
  493. This calls each entry's GetOffsets() method. If it returns a list
  494. of entries to update, it updates them.
  495. """
  496. for entry in self._entries.values():
  497. offset_dict = entry.GetOffsets()
  498. for name, info in offset_dict.items():
  499. self._SetEntryOffsetSize(name, *info)
  500. def CheckSize(self):
  501. contents_size = len(self.data)
  502. size = self.size
  503. if not size:
  504. data = self.GetPaddedData(self.data)
  505. size = len(data)
  506. size = tools.Align(size, self.align_size)
  507. if self.size and contents_size > self.size:
  508. self._Raise("contents size %#x (%d) exceeds section size %#x (%d)" %
  509. (contents_size, contents_size, self.size, self.size))
  510. if not self.size:
  511. self.size = size
  512. if self.size != tools.Align(self.size, self.align_size):
  513. self._Raise("Size %#x (%d) does not match align-size %#x (%d)" %
  514. (self.size, self.size, self.align_size,
  515. self.align_size))
  516. return size
  517. def ListEntries(self, entries, indent):
  518. """List the files in the section"""
  519. Entry.AddEntryInfo(entries, indent, self.name, 'section', self.size,
  520. self.image_pos, None, self.offset, self)
  521. for entry in self._entries.values():
  522. entry.ListEntries(entries, indent + 1)
  523. def LoadData(self, decomp=True):
  524. for entry in self._entries.values():
  525. entry.LoadData(decomp)
  526. self.Detail('Loaded data')
  527. def GetImage(self):
  528. """Get the image containing this section
  529. Note that a top-level section is actually an Image, so this function may
  530. return self.
  531. Returns:
  532. Image object containing this section
  533. """
  534. if not self.section:
  535. return self
  536. return self.section.GetImage()
  537. def GetSort(self):
  538. """Check if the entries in this section will be sorted
  539. Returns:
  540. True if to be sorted, False if entries will be left in the order
  541. they appear in the device tree
  542. """
  543. return self._sort
  544. def ReadData(self, decomp=True):
  545. tout.Info("ReadData path='%s'" % self.GetPath())
  546. parent_data = self.section.ReadData(True)
  547. offset = self.offset - self.section._skip_at_start
  548. data = parent_data[offset:offset + self.size]
  549. tout.Info(
  550. '%s: Reading data from offset %#x-%#x (real %#x), size %#x, got %#x' %
  551. (self.GetPath(), self.offset, self.offset + self.size, offset,
  552. self.size, len(data)))
  553. return data
  554. def ReadChildData(self, child, decomp=True):
  555. tout.Debug("ReadChildData for child '%s'" % child.GetPath())
  556. parent_data = self.ReadData(True)
  557. offset = child.offset - self._skip_at_start
  558. tout.Debug("Extract for child '%s': offset %#x, skip_at_start %#x, result %#x" %
  559. (child.GetPath(), child.offset, self._skip_at_start, offset))
  560. data = parent_data[offset:offset + child.size]
  561. if decomp:
  562. indata = data
  563. data = tools.Decompress(indata, child.compress)
  564. if child.uncomp_size:
  565. tout.Info("%s: Decompressing data size %#x with algo '%s' to data size %#x" %
  566. (child.GetPath(), len(indata), child.compress,
  567. len(data)))
  568. return data
  569. def WriteChildData(self, child):
  570. return True
  571. def SetAllowMissing(self, allow_missing):
  572. """Set whether a section allows missing external blobs
  573. Args:
  574. allow_missing: True if allowed, False if not allowed
  575. """
  576. self.allow_missing = allow_missing
  577. for entry in self._entries.values():
  578. entry.SetAllowMissing(allow_missing)
  579. def CheckMissing(self, missing_list):
  580. """Check if any entries in this section have missing external blobs
  581. If there are missing blobs, the entries are added to the list
  582. Args:
  583. missing_list: List of Entry objects to be added to
  584. """
  585. for entry in self._entries.values():
  586. entry.CheckMissing(missing_list)
  587. def _CollectEntries(self, entries, entries_by_name, add_entry):
  588. """Collect all the entries in an section
  589. This builds up a dict of entries in this section and all subsections.
  590. Entries are indexed by path and by name.
  591. Since all paths are unique, entries will not have any conflicts. However
  592. entries_by_name make have conflicts if two entries have the same name
  593. (e.g. with different parent sections). In this case, an entry at a
  594. higher level in the hierarchy will win over a lower-level entry.
  595. Args:
  596. entries: dict to put entries:
  597. key: entry path
  598. value: Entry object
  599. entries_by_name: dict to put entries
  600. key: entry name
  601. value: Entry object
  602. add_entry: Entry to add
  603. """
  604. entries[add_entry.GetPath()] = add_entry
  605. to_add = add_entry.GetEntries()
  606. if to_add:
  607. for entry in to_add.values():
  608. entries[entry.GetPath()] = entry
  609. for entry in to_add.values():
  610. self._CollectEntries(entries, entries_by_name, entry)
  611. entries_by_name[add_entry.name] = add_entry
  612. def MissingArgs(self, entry, missing):
  613. """Report a missing argument, if enabled
  614. For entries which require arguments, this reports an error if some are
  615. missing. If missing entries are being ignored (e.g. because we read the
  616. entry from an image rather than creating it), this function does
  617. nothing.
  618. Args:
  619. missing: List of missing properties / entry args, each a string
  620. """
  621. if not self._ignore_missing:
  622. entry.Raise('Missing required properties/entry args: %s' %
  623. (', '.join(missing)))