1 # Copyright (c) 2016 Google, Inc
2 # Written by Simon Glass <sjg@chromium.org>
4 # SPDX-License-Identifier: GPL-2.0+
6 # Entry-type module for blobs, which are binary objects read from files
9 from entry import Entry
13 class Entry_blob(Entry):
14 def __init__(self, image, etype, node):
15 Entry.__init__(self, image, etype, node)
16 self._filename = fdt_util.GetString(self._node, "filename", self.etype)
18 def ObtainContents(self):
19 self._filename = self.GetDefaultFilename()
20 self._pathname = tools.GetInputFilename(self._filename)
24 def ReadContents(self):
25 with open(self._pathname) as fd:
26 # We assume the data is small enough to fit into memory. If this
27 # is used for large filesystem image that might not be true.
28 # In that case, Image.BuildImage() could be adjusted to use a
29 # new Entry method which can read in chunks. Then we could copy
30 # the data in chunks and avoid reading it all at once. For now
31 # this seems like an unnecessary complication.
33 self.contents_size = len(self.data)
36 def GetDefaultFilename(self):