binman: Tweak collect_contents_to_file() and docs

Update the return value of this function, fix the 'create' typo and
update the documentation for clarity.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Suggested-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
This commit is contained in:
Simon Glass 2022-03-05 20:18:58 -07:00
parent 17b4ffc56f
commit 6d427c4bcb
3 changed files with 20 additions and 15 deletions

View File

@ -1375,18 +1375,20 @@ Some entry types deal with data obtained from others. For example,
}; };
This shows mkimage being passed a file consisting of SPL and U-Boot proper. It This shows mkimage being passed a file consisting of SPL and U-Boot proper. It
is create by calling `Entry.collect_contents_to_file()`. Note that in this case, is created by calling `Entry.collect_contents_to_file()`. Note that in this
the data is passed to mkimage for processing but does not appear separately in case, the data is passed to mkimage for processing but does not appear
the image. It may not appear at all, depending on what mkimage does. The separately in the image. It may not appear at all, depending on what mkimage
contents of the `mkimage` entry are entirely dependent on the processing done does. The contents of the `mkimage` entry are entirely dependent on the
by the entry, with the provided subnodes (`u-boot-spl` and `u-boot`) simply processing done by the entry, with the provided subnodes (`u-boot-spl` and
providing the input data for that processing. `u-boot`) simply providing the input data for that processing.
Note that `Entry.collect_contents_to_file()` simply concatenates the data from Note that `Entry.collect_contents_to_file()` simply concatenates the data from
the different entries together, with no control over alignment, etc. Another the different entries together, with no control over alignment, etc. Another
approach is to subclass `Entry_section` so that those features become available, approach is to subclass `Entry_section` so that those features become available,
such as `size` and `pad-byte`. Then the contents of the entry can be obtained by such as `size` and `pad-byte`. Then the contents of the entry can be obtained by
calling `BuildSectionData()`. calling `super().BuildSectionData()` in the entry's BuildSectionData()
implementation to get the input data, then write it to a file and process it
however is desired.
There are other ways to obtain data also, depending on the situation. If the There are other ways to obtain data also, depending on the situation. If the
entry type is simply signing data which exists elsewhere in the image, then entry type is simply signing data which exists elsewhere in the image, then
@ -1396,6 +1398,7 @@ is used by `Entry_vblock`, for example::
u_boot: u-boot { u_boot: u-boot {
}; };
vblock { vblock {
content = <&u_boot &dtb>; content = <&u_boot &dtb>;
keyblock = "firmware.keyblock"; keyblock = "firmware.keyblock";
@ -1440,9 +1443,11 @@ The `soc-fw` node is a `blob-ext` (i.e. it reads in a named binary file) whereas
a known blob type. a known blob type.
When adding new entry types you are encouraged to use subnodes to provide the When adding new entry types you are encouraged to use subnodes to provide the
data for processing, unless the `content` approach is more suitable. Ad-hoc data for processing, unless the `content` approach is more suitable. Consider
properties and other methods of obtaining data are discouraged, since it adds to whether the input entries are contained within (or consumed by) the entry, vs
confusion for users. just being 'referenced' by the entry. In the latter case, the `content` approach
makes more sense. Ad-hoc properties and other methods of obtaining data are
discouraged, since it adds to confusion for users.
History / Credits History / Credits
----------------- -----------------

View File

@ -1138,16 +1138,16 @@ features to produce new behaviours.
Returns: Returns:
Tuple: Tuple:
bytes: Concatenated data from all the entries (or False) bytes: Concatenated data from all the entries (or None)
str: Filename of file written (or False if no data) str: Filename of file written (or None if no data)
str: Unique portion of filename (or False if no data) str: Unique portion of filename (or None if no data)
""" """
data = b'' data = b''
for entry in entries: for entry in entries:
# First get the input data and put it in a file. If not available, # First get the input data and put it in a file. If not available,
# try later. # try later.
if not entry.ObtainContents(): if not entry.ObtainContents():
return False, False, False return None, None, None
data += entry.GetData() data += entry.GetData()
uniq = self.GetUniqueName() uniq = self.GetUniqueName()
fname = tools.get_output_filename(f'{prefix}.{uniq}') fname = tools.get_output_filename(f'{prefix}.{uniq}')

View File

@ -53,7 +53,7 @@ class Entry_mkimage(Entry):
def ObtainContents(self): def ObtainContents(self):
data, input_fname, uniq = self.collect_contents_to_file( data, input_fname, uniq = self.collect_contents_to_file(
self._mkimage_entries.values(), 'mkimage') self._mkimage_entries.values(), 'mkimage')
if data is False: if data is None:
return False return False
output_fname = tools.get_output_filename('mkimage-out.%s' % uniq) output_fname = tools.get_output_filename('mkimage-out.%s' % uniq)
if self.mkimage.run_cmd('-d', input_fname, *self._args, if self.mkimage.run_cmd('-d', input_fname, *self._args,