binman: Make the operation of Entry__testing explicit
[oweals/u-boot.git] / tools / binman / etype / u_boot_dtb_with_ucode.py
index 732d10a14eed341c1574b0a87e9d436317b53a96..1e530d6570af71ce070066549ab303b3953f2438 100644 (file)
@@ -1,12 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0+
 # Copyright (c) 2016 Google, Inc
-## Written by Simon Glass <sjg@chromium.org>
-
-# SPDX-License-Identifier:      GPL-2.0+
+# Written by Simon Glass <sjg@chromium.org>
 #
 # Entry-type module for U-Boot device tree with the microcode removed
 #
 
-import fdt_select
+import fdt
 from entry import Entry
 from blob import Entry_blob
 import tools
@@ -17,8 +16,8 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
     See Entry_u_boot_ucode for full details of the 3 entries involved in this
     process.
     """
-    def __init__(self, image, etype, node):
-        Entry_blob.__init__(self, image, etype, node)
+    def __init__(self, section, etype, node):
+        Entry_blob.__init__(self, section, etype, node)
         self.ucode_data = ''
         self.collate = False
         self.ucode_offset = None
@@ -30,8 +29,12 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
     def ObtainContents(self):
         Entry_blob.ObtainContents(self)
 
-        # If the image does not need microcode, there is nothing to do
-        ucode_dest_entry = self.image.FindEntryType('u-boot-with-ucode-ptr')
+        # If the section does not need microcode, there is nothing to do
+        ucode_dest_entry = self.section.FindEntryType(
+            'u-boot-spl-with-ucode-ptr')
+        if not ucode_dest_entry or not ucode_dest_entry.target_pos:
+            ucode_dest_entry = self.section.FindEntryType(
+                'u-boot-with-ucode-ptr')
         if not ucode_dest_entry or not ucode_dest_entry.target_pos:
             return True
 
@@ -42,9 +45,8 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
             fd.write(self.data)
 
         # Remove the microcode
-        fdt = fdt_select.FdtScan(fname)
-        fdt.Scan()
-        ucode = fdt.GetNode('/microcode')
+        dtb = fdt.FdtScan(fname)
+        ucode = dtb.GetNode('/microcode')
         if not ucode:
             raise self.Raise("No /microcode node found in '%s'" % fname)
 
@@ -55,20 +57,15 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob):
             data_prop = node.props.get('data')
             if data_prop:
                 self.ucode_data += ''.join(data_prop.bytes)
-                if not self.collate:
-                    poffset = data_prop.GetOffset()
-                    if poffset is None:
-                        # We cannot obtain a property offset. Collate instead.
-                        self.collate = True
-                    else:
-                        # Find the offset in the device tree of the ucode data
-                        self.ucode_offset = poffset + 12
-                        self.ucode_size = len(data_prop.bytes)
                 if self.collate:
                     prop = node.DeleteProp('data')
+                else:
+                    # Find the offset in the device tree of the ucode data
+                    self.ucode_offset = data_prop.GetOffset() + 12
+                    self.ucode_size = len(data_prop.bytes)
         if self.collate:
-            fdt.Pack()
-            fdt.Flush()
+            dtb.Pack()
+            dtb.Flush()
 
             # Make this file the contents of this entry
             self._pathname = fname