]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
binman: Allow selecting default FIT configuration
authorSimon Glass <sjg@chromium.org>
Sun, 6 Sep 2020 16:39:08 +0000 (10:39 -0600)
committerSimon Glass <sjg@chromium.org>
Tue, 22 Sep 2020 18:54:13 +0000 (12:54 -0600)
Add a new entry argument to the fit entry which allows selection of the
default configuration to use. This is the 'default' property in the
'configurations' node.

Update the Makefile to pass in the value of DEVICE_TREE or
CONFIG_DEFAULT_DEVICE_TREE to provide this information.

Signed-off-by: Simon Glass <sjg@chromium.org>
Suggested-by: Michal Simek <michal.simek@xilinx.com>
Makefile
tools/binman/README.entries
tools/binman/etype/fit.py
tools/binman/ftest.py
tools/binman/test/172_fit_fdt.dts [moved from tools/binman/test/170_fit_fdt.dts with 95% similarity]

index 07cd28f3a618f02bb80cefa6741ff613d1fdab99..2de0527e2ddb1c92a387de091f4fc09496711281 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1321,6 +1321,7 @@ u-boot.ldr:       u-boot
 # binman
 # ---------------------------------------------------------------------------
 # Use 'make BINMAN_DEBUG=1' to enable debugging
+default_dt := $(if $(DEVICE_TREE),$(DEVICE_TREE),$(CONFIG_DEFAULT_DEVICE_TREE))
 quiet_cmd_binman = BINMAN  $@
 cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
                 --toolpath $(objtree)/tools \
@@ -1329,6 +1330,7 @@ cmd_binman = $(srctree)/tools/binman/binman $(if $(BINMAN_DEBUG),-D) \
                -I . -I $(srctree) -I $(srctree)/board/$(BOARDDIR) \
                -I arch/$(ARCH)/dts -a of-list=$(CONFIG_OF_LIST) \
                -a atf-bl31-path=${BL31} \
+               -a default-dt=$(default_dt) \
                $(BINMAN_$(@F))
 
 OBJCOPYFLAGS_u-boot.ldr.hex := -I binary -O ihex
index d2628dffd5d68554e86f606e2e495d57aa4ca27c..c1d436563e89e12a8228198947bb23bde3007d7d 100644 (file)
@@ -402,6 +402,10 @@ Available substitutions for '@' nodes are:
 Note that if no devicetree files are provided (with '-a of-list' as above)
 then no nodes will be generated.
 
+The 'default' property, if present, will be automatically set to the name
+if of configuration whose devicetree matches the 'default-dt' entry
+argument, e.g. with '-a default-dt=sun50i-a64-pine64-lts'.
+
 
 Properties (in the 'fit' node itself):
     fit,external-offset: Indicates that the contents of the FIT are external
index c291eb26bad6386b901a9375432b504bd16550d6..de4745c55211e0247f8e14dd2980ae1be86191f1 100644 (file)
@@ -90,6 +90,14 @@ class Entry_fit(Entry):
     Note that if no devicetree files are provided (with '-a of-list' as above)
     then no nodes will be generated.
 
+    The 'default' property, if present, will be automatically set to the name
+    if of configuration whose devicetree matches the 'default-dt' entry
+    argument, e.g. with '-a default-dt=sun50i-a64-pine64-lts'.
+
+    Available substitutions for '@' property values are:
+
+        DEFAULT-SEQ  Sequence number of the default fdt,as provided by the
+                     'default-dt' entry argument
 
     Properties (in the 'fit' node itself):
         fit,external-offset: Indicates that the contents of the FIT are external
@@ -121,6 +129,8 @@ class Entry_fit(Entry):
                 [EntryArg(self._fit_list_prop.value, str)])
             if fdts is not None:
                 self._fdts = fdts.split()
+        self._fit_default_dt = self.GetEntryArgsOrProps([EntryArg('default-dt',
+                                                                  str)])[0]
 
     def ReadNode(self):
         self._ReadSubnodes()
@@ -142,6 +152,22 @@ class Entry_fit(Entry):
             """
             for pname, prop in node.props.items():
                 if not pname.startswith('fit,'):
+                    if pname == 'default':
+                        val = prop.value
+                        # Handle the 'default' property
+                        if val.startswith('@'):
+                            if not self._fdts:
+                                continue
+                            if not self._fit_default_dt:
+                                self.Raise("Generated 'default' node requires default-dt entry argument")
+                            if self._fit_default_dt not in self._fdts:
+                                self.Raise("default-dt entry argument '%s' not found in fdt list: %s" %
+                                           (self._fit_default_dt,
+                                            ', '.join(self._fdts)))
+                            seq = self._fdts.index(self._fit_default_dt)
+                            val = val[1:].replace('DEFAULT-SEQ', str(seq + 1))
+                            fsw.property_string(pname, val)
+                            continue
                     fsw.property(pname, prop.bytes)
 
             rel_path = node.path[len(base_node.path):]
index 78d0e9c2b93e371e90198d3809cf5aca01ae8e01..a269a7497cb6c1ed19b6c86a2acd9e3ff375d5e1 100644 (file)
@@ -3602,7 +3602,7 @@ class TestFunctional(unittest.TestCase):
             """
             cnode = dtb.GetNode('/configurations')
             self.assertIn('default', cnode.props)
-            self.assertEqual('config-1', cnode.props['default'].value)
+            self.assertEqual('config-2', cnode.props['default'].value)
 
             name = 'config-%d' % seq
             fnode = dtb.GetNode('/configurations/%s' % name)
@@ -3615,9 +3615,10 @@ class TestFunctional(unittest.TestCase):
 
         entry_args = {
             'of-list': 'test-fdt1 test-fdt2',
+            'default-dt': 'test-fdt2',
         }
         data = self._DoReadFileDtb(
-            '170_fit_fdt.dts',
+            '172_fit_fdt.dts',
             entry_args=entry_args,
             extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)])[0]
         self.assertEqual(U_BOOT_NODTB_DATA, data[-len(U_BOOT_NODTB_DATA):])
@@ -3639,7 +3640,7 @@ class TestFunctional(unittest.TestCase):
     def testFitFdtMissingList(self):
         """Test handling of a missing 'of-list' entry arg"""
         with self.assertRaises(ValueError) as e:
-            self._DoReadFile('170_fit_fdt.dts')
+            self._DoReadFile('172_fit_fdt.dts')
         self.assertIn("Generator node requires 'of-list' entry argument",
                       str(e.exception))
 
@@ -3657,5 +3658,39 @@ class TestFunctional(unittest.TestCase):
         self.assertIn("Generator node requires 'fit,fdt-list' property",
                       str(e.exception))
 
+    def testFitFdtEmptyList(self):
+        """Test handling of an empty 'of-list' entry arg"""
+        entry_args = {
+            'of-list': '',
+        }
+        data = self._DoReadFileDtb('172_fit_fdt.dts', entry_args=entry_args)[0]
+
+    def testFitFdtMissing(self):
+        """Test handling of a missing 'default-dt' entry arg"""
+        entry_args = {
+            'of-list': 'test-fdt1 test-fdt2',
+        }
+        with self.assertRaises(ValueError) as e:
+            self._DoReadFileDtb(
+                '172_fit_fdt.dts',
+                entry_args=entry_args,
+                extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)])[0]
+        self.assertIn("Generated 'default' node requires default-dt entry argument",
+                      str(e.exception))
+
+    def testFitFdtNotInList(self):
+        """Test handling of a default-dt that is not in the of-list"""
+        entry_args = {
+            'of-list': 'test-fdt1 test-fdt2',
+            'default-dt': 'test-fdt3',
+        }
+        with self.assertRaises(ValueError) as e:
+            self._DoReadFileDtb(
+                '172_fit_fdt.dts',
+                entry_args=entry_args,
+                extra_indirs=[os.path.join(self._indir, TEST_FDT_SUBDIR)])[0]
+        self.assertIn("default-dt entry argument 'test-fdt3' not found in fdt list: test-fdt1, test-fdt2",
+                      str(e.exception))
+
 if __name__ == "__main__":
     unittest.main()
similarity index 95%
rename from tools/binman/test/170_fit_fdt.dts
rename to tools/binman/test/172_fit_fdt.dts
index 89142e910172d400bb45b39d47dfb2e45220c8f6..99d710c57e9b1c49c223799c6fb01408a9720ddc 100644 (file)
@@ -40,7 +40,7 @@
                        };
 
                        configurations {
-                               default = "config-1";
+                               default = "@config-DEFAULT-SEQ";
                                @config-SEQ {
                                        description = "conf-NAME.dtb";
                                        firmware = "uboot";