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