2018-09-14 19:57:28 +09:00
|
|
|
# SPDX-License-Identifier: GPL-2.0+
|
|
|
|
# Copyright (c) 2018 Google, Inc
|
|
|
|
# Written by Simon Glass <sjg@chromium.org>
|
|
|
|
#
|
|
|
|
# Entry-type module for a set of files which are placed in individual
|
|
|
|
# sub-entries
|
|
|
|
#
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
|
2020-04-18 09:09:03 +09:00
|
|
|
from binman.etype.section import Entry_section
|
|
|
|
from dtoc import fdt_util
|
2020-04-18 09:09:04 +09:00
|
|
|
from patman import tools
|
2018-09-14 19:57:28 +09:00
|
|
|
|
|
|
|
|
|
|
|
class Entry_files(Entry_section):
|
|
|
|
"""Entry containing a set of files
|
|
|
|
|
|
|
|
Properties / Entry arguments:
|
|
|
|
- pattern: Filename pattern to match the files to include
|
2020-10-27 08:40:07 +09:00
|
|
|
- files-compress: Compression algorithm to use:
|
2018-09-14 19:57:28 +09:00
|
|
|
none: No compression
|
|
|
|
lz4: Use lz4 compression (via 'lz4' command-line utility)
|
|
|
|
|
|
|
|
This entry reads a number of files and places each in a separate sub-entry
|
|
|
|
within this entry. To access these you need to enable device-tree updates
|
|
|
|
at run-time so you can obtain the file positions.
|
|
|
|
"""
|
|
|
|
def __init__(self, section, etype, node):
|
2019-08-24 22:22:44 +09:00
|
|
|
# Put this here to allow entry-docs and help to work without libfdt
|
|
|
|
global state
|
2020-04-18 09:09:03 +09:00
|
|
|
from binman import state
|
2019-08-24 22:22:44 +09:00
|
|
|
|
2020-07-10 09:39:35 +09:00
|
|
|
super().__init__(section, etype, node)
|
2018-09-14 19:57:28 +09:00
|
|
|
self._pattern = fdt_util.GetString(self._node, 'pattern')
|
|
|
|
if not self._pattern:
|
|
|
|
self.Raise("Missing 'pattern' property")
|
2020-10-27 08:40:07 +09:00
|
|
|
self._files_compress = fdt_util.GetString(self._node, 'files-compress',
|
|
|
|
'none')
|
2018-09-14 19:57:28 +09:00
|
|
|
self._require_matches = fdt_util.GetBool(self._node,
|
|
|
|
'require-matches')
|
|
|
|
|
|
|
|
def ExpandEntries(self):
|
|
|
|
files = tools.GetInputFilenameGlob(self._pattern)
|
|
|
|
if self._require_matches and not files:
|
|
|
|
self.Raise("Pattern '%s' matched no files" % self._pattern)
|
|
|
|
for fname in files:
|
|
|
|
if not os.path.isfile(fname):
|
|
|
|
continue
|
|
|
|
name = os.path.basename(fname)
|
|
|
|
subnode = self._node.FindNode(name)
|
|
|
|
if not subnode:
|
|
|
|
subnode = state.AddSubnode(self._node, name)
|
|
|
|
state.AddString(subnode, 'type', 'blob')
|
|
|
|
state.AddString(subnode, 'filename', fname)
|
2020-10-27 08:40:07 +09:00
|
|
|
state.AddString(subnode, 'compress', self._files_compress)
|
2018-09-14 19:57:28 +09:00
|
|
|
|
|
|
|
# Read entries again, now that we have some
|
2019-07-09 05:25:47 +09:00
|
|
|
self._ReadEntries()
|