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 8from entry import Entry 9import fdt_util 10import tools 11 12class Entry_blob(Entry): 13 def __init__(self, section, etype, node): 14 Entry.__init__(self, section, 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.SetContents(fd.read()) 32 return True 33 34 def GetDefaultFilename(self): 35 return self._filename 36