]> git.ipfire.org Git - thirdparty/u-boot.git/blob - tools/binman/etype/blob.py
SPDX: Convert all of our single license tags to Linux Kernel style
[thirdparty/u-boot.git] / tools / binman / etype / blob.py
1 # SPDX-License-Identifier: GPL-2.0+
2 # Copyright (c) 2016 Google, Inc
3 # Written by Simon Glass <sjg@chromium.org>
4 #
5 # Entry-type module for blobs, which are binary objects read from files
6 #
7
8 from entry import Entry
9 import fdt_util
10 import tools
11
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)
16
17 def ObtainContents(self):
18 self._filename = self.GetDefaultFilename()
19 self._pathname = tools.GetInputFilename(self._filename)
20 self.ReadContents()
21 return True
22
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.
31 self.data = fd.read()
32 self.contents_size = len(self.data)
33 return True
34
35 def GetDefaultFilename(self):
36 return self._filename