1# SPDX-License-Identifier: GPL-2.0+ 2# Copyright (c) 2018 Google, Inc 3# Written by Simon Glass <sjg@chromium.org> 4# 5# Entry-type module for a set of files which are placed in individual 6# sub-entries 7# 8 9import glob 10import os 11 12from section import Entry_section 13import fdt_util 14import state 15import tools 16 17import bsection 18 19class Entry_files(Entry_section): 20 """Entry containing a set of files 21 22 Properties / Entry arguments: 23 - pattern: Filename pattern to match the files to include 24 - compress: Compression algorithm to use: 25 none: No compression 26 lz4: Use lz4 compression (via 'lz4' command-line utility) 27 28 This entry reads a number of files and places each in a separate sub-entry 29 within this entry. To access these you need to enable device-tree updates 30 at run-time so you can obtain the file positions. 31 """ 32 def __init__(self, section, etype, node): 33 Entry_section.__init__(self, section, etype, node) 34 self._pattern = fdt_util.GetString(self._node, 'pattern') 35 if not self._pattern: 36 self.Raise("Missing 'pattern' property") 37 self._compress = fdt_util.GetString(self._node, 'compress', 'none') 38 self._require_matches = fdt_util.GetBool(self._node, 39 'require-matches') 40 41 def ExpandEntries(self): 42 files = tools.GetInputFilenameGlob(self._pattern) 43 if self._require_matches and not files: 44 self.Raise("Pattern '%s' matched no files" % self._pattern) 45 for fname in files: 46 if not os.path.isfile(fname): 47 continue 48 name = os.path.basename(fname) 49 subnode = self._node.FindNode(name) 50 if not subnode: 51 subnode = state.AddSubnode(self._node, name) 52 state.AddString(subnode, 'type', 'blob') 53 state.AddString(subnode, 'filename', fname) 54 state.AddString(subnode, 'compress', self._compress) 55 56 # Read entries again, now that we have some 57 self._section._ReadEntries() 58