Merge tag 'u-boot-rockchip-20200501' of https://gitlab.denx.de/u-boot/custodians...
[platform/kernel/u-boot.git] / tools / binman / etype / cbfs.py
index d73c706..e9aed83 100644 (file)
@@ -7,11 +7,10 @@
 
 from collections import OrderedDict
 
-import cbfs_util
-from cbfs_util import CbfsWriter
-from entry import Entry
-import fdt_util
-import state
+from binman import cbfs_util
+from binman.cbfs_util import CbfsWriter
+from binman.entry import Entry
+from dtoc import fdt_util
 
 class Entry_cbfs(Entry):
     """Entry containing a Coreboot Filesystem (CBFS)
@@ -164,12 +163,17 @@ class Entry_cbfs(Entry):
     both of size 1MB.
     """
     def __init__(self, section, etype, node):
+        # Put this here to allow entry-docs and help to work without libfdt
+        global state
+        from binman import state
+
         Entry.__init__(self, section, etype, node)
         self._cbfs_arg = fdt_util.GetString(node, 'cbfs-arch', 'x86')
         self._cbfs_entries = OrderedDict()
         self._ReadSubnodes()
+        self.reader = None
 
-    def ObtainContents(self):
+    def ObtainContents(self, skip=None):
         arch = cbfs_util.find_arch(self._cbfs_arg)
         if arch is None:
             self.Raise("Invalid architecture '%s'" % self._cbfs_arg)
@@ -179,7 +183,7 @@ class Entry_cbfs(Entry):
         for entry in self._cbfs_entries.values():
             # First get the input data and put it in a file. If not available,
             # try later.
-            if not entry.ObtainContents():
+            if entry != skip and not entry.ObtainContents():
                 return False
             data = entry.GetData()
             cfile = None
@@ -202,7 +206,7 @@ class Entry_cbfs(Entry):
     def _ReadSubnodes(self):
         """Read the subnodes to find out what should go in this IFWI"""
         for node in self._node.subnodes:
-            entry = Entry.Create(self.section, node)
+            entry = Entry.Create(self, node)
             entry.ReadNode()
             entry._cbfs_name = fdt_util.GetString(node, 'cbfs-name', entry.name)
             entry._type = fdt_util.GetString(node, 'cbfs-type')
@@ -262,3 +266,19 @@ 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
+
+    def WriteChildData(self, child):
+        self.ObtainContents(skip=child)
+        return True