u-boot-brain/tools/binman/etype/collection.py
Simon Glass 631f752de5 binman: Support obtaining section contents immediately
Generally the content of sections is not built until the final assembly
of the image. This is partly to avoid wasting time, since the entries
within sections may change multiple times as binman works through its
various stages. This works quite well since sections exist in a strict
hierarchy, so they can be processed in a depth-first manner.

However the 'collection' entry type does not have this luxury. If it
contains a section within its 'content' list, then it must produce the
section contents, if available. That section is typically a sibling
node, i.e. not part oc the collection's hierarchy.

Add a new 'required' argument to section.GetData() to support this. When
required is True, any referenced sections are immediately built. If this
is not possible (because one of the subentries does not have its data yet)
then an error is produced.

The test for this uses a 'collection' entry type, referencing a section as
its first member. This forces a call to _BuildSectionData() with required
set to False, at first, then True later, when the image is assembled.

Signed-off-by: Simon Glass <sjg@chromium.org>
2021-03-27 16:26:48 +13:00

68 lines
2.2 KiB
Python

# SPDX-License-Identifier: GPL-2.0+
# Copyright 2021 Google LLC
# Written by Simon Glass <sjg@chromium.org>
#
# Support for a collection of entries from other parts of an image
from collections import OrderedDict
import os
from binman.entry import Entry
from dtoc import fdt_util
class Entry_collection(Entry):
"""An entry which contains a collection of other entries
Properties / Entry arguments:
- content: List of phandles to entries to include
This allows reusing the contents of other entries. The contents of the
listed entries are combined to form this entry. This serves as a useful
base class for entry types which need to process data from elsewhere in
the image, not necessarily child entries.
"""
def __init__(self, section, etype, node):
super().__init__(section, etype, node)
self.content = fdt_util.GetPhandleList(self._node, 'content')
if not self.content:
self.Raise("Collection must have a 'content' property")
def GetContents(self, required):
"""Get the contents of this entry
Args:
required: True if the data must be present, False if it is OK to
return None
Returns:
bytes content of the entry
"""
# Join up all the data
self.Info('Getting contents, required=%s' % required)
data = b''
for entry_phandle in self.content:
entry_data = self.section.GetContentsByPhandle(entry_phandle, self,
required)
if not required and entry_data is None:
self.Info('Contents not available yet')
# Data not available yet
return None
data += entry_data
self.Info('Returning contents size %x' % len(data))
return data
def ObtainContents(self):
data = self.GetContents(False)
if data is None:
return False
self.SetContents(data)
return True
def ProcessContents(self):
# The blob may have changed due to WriteSymbols()
data = self.GetContents(True)
return self.ProcessContentsUpdate(data)