[U-Boot] [PATCH 42/53] binman: Update Entry.ReadEntry() to work through classes
Simon Glass
sjg at chromium.org
Sat Jul 20 18:24:04 UTC 2019
At present we simply extract the data directly from entries using the
image_pos information. This happens to work on current entry types, but
cannot work if the entry type encodes the data in some way. Update the
ReadData() method to provide the data by calling a new ReadChildData()
method in the parent. This allows the entry_Section class, or possibly
any other container class, to return the correct data in all cases.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/binman/entry.py | 7 ++-----
tools/binman/etype/blob.py | 12 ------------
tools/binman/etype/cbfs.py | 12 ++++++++++++
tools/binman/etype/section.py | 32 ++++++++++++++++++++++++++++++++
4 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/tools/binman/entry.py b/tools/binman/entry.py
index 90192c11b77..8416214fc93 100644
--- a/tools/binman/entry.py
+++ b/tools/binman/entry.py
@@ -714,11 +714,8 @@ features to produce new behaviours.
"""
# Use True here so that we get an uncompressed section to work from,
# although compressed sections are currently not supported
- data = self.section.ReadData(True)
- tout.Info('%s: Reading data from offset %#x-%#x, size %#x (avail %#x)' %
- (self.GetPath(), self.offset, self.offset + self.size,
- self.size, len(data)))
- return data[self.offset:self.offset + self.size]
+ data = self.section.ReadChildData(self, decomp)
+ return data
def LoadData(self, decomp=True):
data = self.ReadData(decomp)
diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py
index 00cad33718c..d15d0789e52 100644
--- a/tools/binman/etype/blob.py
+++ b/tools/binman/etype/blob.py
@@ -67,15 +67,3 @@ class Entry_blob(Entry):
def GetDefaultFilename(self):
return self._filename
-
- def ReadData(self, decomp=True):
- indata = Entry.ReadData(self, decomp)
- if decomp:
- data = tools.Decompress(indata, self.compress)
- if self.uncomp_size:
- tout.Info("%s: Decompressing data size %#x with algo '%s' to data size %#x" %
- (self.GetPath(), len(indata), self.compress,
- len(data)))
- else:
- data = indata
- return data
diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py
index d73c706c444..2bcdf2fd433 100644
--- a/tools/binman/etype/cbfs.py
+++ b/tools/binman/etype/cbfs.py
@@ -262,3 +262,15 @@ class Entry_cbfs(Entry):
def GetEntries(self):
return self._cbfs_entries
+
+ def ReadData(self, decomp=True):
+ data = Entry.ReadData(self, True)
+ return data
+
+ def ReadChildData(self, child, decomp=True):
+ if not self.reader:
+ data = Entry.ReadData(self, True)
+ self.reader = cbfs_util.CbfsReader(data)
+ reader = self.reader
+ cfile = reader.files.get(child.name)
+ return cfile.data if decomp else cfile.orig_data
diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py
index 3ce013d5029..855e291bc43 100644
--- a/tools/binman/etype/section.py
+++ b/tools/binman/etype/section.py
@@ -17,6 +17,7 @@ import sys
from entry import Entry
import fdt_util
import tools
+import tout
class Entry_section(Entry):
@@ -488,3 +489,34 @@ class Entry_section(Entry):
they appear in the device tree
"""
return self._sort
+
+ def ReadData(self, decomp=True):
+ tout.Info("ReadData path='%s'" % self.GetPath())
+ parent_data = self.section.ReadData(True)
+ tout.Info('%s: Reading data from offset %#x-%#x, size %#x' %
+ (self.GetPath(), self.offset, self.offset + self.size,
+ self.size))
+ data = parent_data[self.offset:self.offset + self.size]
+ return data
+
+ def ReadChildData(self, child, decomp=True):
+ """Read the data for a particular child entry
+
+ Args:
+ child: Child entry to read data for
+ decomp: True to return uncompressed data, False to leave the data
+ compressed if it is compressed
+
+ Returns:
+ Data contents of entry
+ """
+ parent_data = self.ReadData(True)
+ data = parent_data[child.offset:child.offset + child.size]
+ if decomp:
+ indata = data
+ data = tools.Decompress(indata, child.compress)
+ if child.uncomp_size:
+ tout.Info("%s: Decompressing data size %#x with algo '%s' to data size %#x" %
+ (child.GetPath(), len(indata), child.compress,
+ len(data)))
+ return data
--
2.22.0.657.g960e92d24f-goog
More information about the U-Boot
mailing list