]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - 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>
5 # Entry-type module for blobs, which are binary objects read from files
8 from binman
.entry
import Entry
9 from binman
import state
10 from dtoc
import fdt_util
11 from u_boot_pylib
import tools
12 from u_boot_pylib
import tout
14 class Entry_blob(Entry
):
15 """Arbitrary binary blob
17 Note: This should not be used by itself. It is normally used as a parent
18 class by other entry types.
20 Properties / Entry arguments:
21 - filename: Filename of file to read into entry
22 - compress: Compression algorithm to use:
24 lz4: Use lz4 compression (via 'lz4' command-line utility)
26 This entry reads data from a file and places it in the entry. The
27 default filename is often specified specified by the subclass. See for
28 example the 'u-boot' entry which provides the filename 'u-boot.bin'.
30 If compression is enabled, an extra 'uncomp-size' property is written to
31 the node (if enabled with -u) which provides the uncompressed size of the
34 def __init__(self
, section
, etype
, node
, auto_write_symbols
=False):
35 super().__init
__(section
, etype
, node
,
36 auto_write_symbols
=auto_write_symbols
)
37 self
._filename
= fdt_util
.GetString(self
._node
, 'filename', self
.etype
)
38 self
.elf_fname
= fdt_util
.GetString(self
._node
, 'elf-filename',
40 self
.elf_base_sym
= fdt_util
.GetString(self
._node
, 'elf-base-sym')
41 if not self
.auto_write_symbols
:
42 if fdt_util
.GetBool(self
._node
, 'write-symbols'):
43 self
.auto_write_symbols
= True
45 def ObtainContents(self
, fake_size
=0):
46 self
._filename
= self
.GetDefaultFilename()
47 self
._pathname
= tools
.get_input_filename(self
._filename
,
48 self
.external
and (self
.optional
or self
.section
.GetAllowMissing()))
49 # Allow the file to be missing
50 if not self
._pathname
:
51 self
._pathname
, faked
= self
.check_fake_fname(self
._filename
,
58 self
.ReadBlobContents()
61 def ReadFileContents(self
, pathname
):
62 """Read blob contents into memory
64 This function compresses the data before returning if needed.
66 We assume the data is small enough to fit into memory. If this
67 is used for large filesystem image that might not be true.
68 In that case, Image.BuildImage() could be adjusted to use a
69 new Entry method which can read in chunks. Then we could copy
70 the data in chunks and avoid reading it all at once. For now
71 this seems like an unnecessary complication.
74 pathname (str): Pathname to read from
79 state
.TimingStart('read')
80 indata
= tools
.read_file(pathname
)
81 state
.TimingAccum('read')
82 state
.TimingStart('compress')
83 data
= self
.CompressData(indata
)
84 state
.TimingAccum('compress')
87 def ReadBlobContents(self
):
88 data
= self
.ReadFileContents(self
._pathname
)
89 self
.SetContents(data
)
92 def GetDefaultFilename(self
):
95 def ProcessContents(self
):
96 # The blob may have changed due to WriteSymbols()
97 return self
.ProcessContentsUpdate(self
.data
)
99 def CheckFakedBlobs(self
, faked_blobs_list
):
100 """Check if any entries in this section have faked external blobs
102 If there are faked blobs, the entries are added to the list
105 faked_blobs_list: List of Entry objects to be added to
108 faked_blobs_list
.append(self
)