1# Copyright (c) 2016 Google, Inc 2# Written by Simon Glass <sjg@chromium.org> 3# 4# SPDX-License-Identifier: GPL-2.0+ 5# 6# Entry-type module for blobs, which are binary objects read from files 7# 8 9from entry import Entry 10import fdt_util 11import tools 12 13class 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) 17 18 def ObtainContents(self): 19 self._filename = self.GetDefaultFilename() 20 self._pathname = tools.GetInputFilename(self._filename) 21 self.ReadContents() 22 return True 23 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. 32 self.data = fd.read() 33 self.contents_size = len(self.data) 34 return True 35 36 def GetDefaultFilename(self): 37 return self._filename 38