2018-05-07 06:58:06 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
2016-11-26 12:15:52 +09:00
|
|
|
# Copyright (c) 2016 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Entry-type module for blobs, which are binary objects read from files
|
|
|
|
#
|
|
|
|
|
|
|
|
from entry import Entry
|
|
|
|
import fdt_util
|
|
|
|
import tools
|
|
|
|
|
|
|
|
class Entry_blob(Entry):
|
2018-07-18 04:25:35 +09:00
|
|
|
"""Entry containing an arbitrary binary blob
|
|
|
|
|
|
|
|
Note: This should not be used by itself. It is normally used as a parent
|
|
|
|
class by other entry types.
|
|
|
|
|
|
|
|
Properties / Entry arguments:
|
|
|
|
- filename: Filename of file to read into entry
|
|
|
|
|
|
|
|
This entry reads data from a file and places it in the entry. The
|
|
|
|
default filename is often specified specified by the subclass. See for
|
|
|
|
example the 'u_boot' entry which provides the filename 'u-boot.bin'.
|
|
|
|
"""
|
2018-06-02 00:38:14 +09:00
|
|
|
def __init__(self, section, etype, node):
|
|
|
|
Entry.__init__(self, section, etype, node)
|
2016-11-26 12:15:52 +09:00
|
|
|
self._filename = fdt_util.GetString(self._node, "filename", self.etype)
|
|
|
|
|
|
|
|
def ObtainContents(self):
|
|
|
|
self._filename = self.GetDefaultFilename()
|
|
|
|
self._pathname = tools.GetInputFilename(self._filename)
|
2018-07-18 04:25:50 +09:00
|
|
|
self.ReadBlobContents()
|
2016-11-26 12:15:52 +09:00
|
|
|
return True
|
|
|
|
|
2018-07-18 04:25:50 +09:00
|
|
|
def ReadBlobContents(self):
|
2016-11-26 12:15:52 +09:00
|
|
|
with open(self._pathname) as fd:
|
|
|
|
# We assume the data is small enough to fit into memory. If this
|
|
|
|
# is used for large filesystem image that might not be true.
|
|
|
|
# In that case, Image.BuildImage() could be adjusted to use a
|
|
|
|
# new Entry method which can read in chunks. Then we could copy
|
|
|
|
# the data in chunks and avoid reading it all at once. For now
|
|
|
|
# this seems like an unnecessary complication.
|
2018-07-07 01:27:19 +09:00
|
|
|
self.SetContents(fd.read())
|
2016-11-26 12:15:52 +09:00
|
|
|
return True
|
|
|
|
|
|
|
|
def GetDefaultFilename(self):
|
|
|
|
return self._filename
|