[U-Boot] [PATCH 21/37] binman: Allow text directly in the node

Simon Glass sjg at chromium.org
Fri Jun 28 14:09:03 UTC 2019


At present text entries use an indirect method to specify the text to use,
with a label pointing to the text itself.

Allow the text to be directly written into the node. This is more
convenient in cases where the text is constant.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 tools/binman/README.entries    |  9 +++++++++
 tools/binman/etype/text.py     | 23 +++++++++++++++++++----
 tools/binman/ftest.py          |  2 +-
 tools/binman/test/066_text.dts |  5 +++++
 4 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/tools/binman/README.entries b/tools/binman/README.entries
index 702fc9fda08..9cbdbbaadef 100644
--- a/tools/binman/README.entries
+++ b/tools/binman/README.entries
@@ -312,6 +312,8 @@ Properties / Entry arguments:
         that contains the string to place in the entry
     <xxx> (actual name is the value of text-label): contains the string to
         place in the entry.
+    <text>: The text to place in the entry (overrides the above mechanism).
+        This is useful when the text is constant.
 
 Example node:
 
@@ -334,6 +336,13 @@ It is also possible to put the string directly in the node:
         message = "a message directly in the node"
     };
 
+or just:
+
+    text {
+        size = <8>;
+        text = "some text directly in the node"
+    };
+
 The text is not itself nul-terminated. This can be achieved, if required,
 by setting the size of the entry to something larger than the text.
 
diff --git a/tools/binman/etype/text.py b/tools/binman/etype/text.py
index 9ee04d7c9d8..da1813a638e 100644
--- a/tools/binman/etype/text.py
+++ b/tools/binman/etype/text.py
@@ -22,6 +22,8 @@ class Entry_text(Entry):
             that contains the string to place in the entry
         <xxx> (actual name is the value of text-label): contains the string to
             place in the entry.
+        <text>: The text to place in the entry (overrides the above mechanism).
+            This is useful when the text is constant.
 
     Example node:
 
@@ -44,15 +46,28 @@ class Entry_text(Entry):
             message = "a message directly in the node"
         };
 
+    or just:
+
+        text {
+            size = <8>;
+            text = "some text directly in the node"
+        };
+
     The text is not itself nul-terminated. This can be achieved, if required,
     by setting the size of the entry to something larger than the text.
     """
     def __init__(self, section, etype, node):
         Entry.__init__(self, section, etype, node)
-        label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
-        self.text_label = tools.ToStr(label) if type(label) != str else label
-        value, = self.GetEntryArgsOrProps([EntryArg(self.text_label, str)])
-        value = tools.ToBytes(value) if value is not None else value
+        value = fdt_util.GetString(self._node, 'text')
+        if value:
+            value = tools.ToBytes(value)
+        else:
+            label, = self.GetEntryArgsOrProps([EntryArg('text-label', str)])
+            self.text_label = label
+            if self.text_label:
+                value, = self.GetEntryArgsOrProps([EntryArg(self.text_label,
+                                                            str)])
+                value = tools.ToBytes(value) if value is not None else value
         self.value = value
 
     def ObtainContents(self):
diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py
index 8577adb5380..c74e12d13c8 100644
--- a/tools/binman/ftest.py
+++ b/tools/binman/ftest.py
@@ -1286,7 +1286,7 @@ class TestFunctional(unittest.TestCase):
         expected = (tools.ToBytes(TEXT_DATA) +
                     tools.GetBytes(0, 8 - len(TEXT_DATA)) +
                     tools.ToBytes(TEXT_DATA2) + tools.ToBytes(TEXT_DATA3) +
-                    b'some text')
+                    b'some text' + b'more text')
         self.assertEqual(expected, data)
 
     def testEntryDocs(self):
diff --git a/tools/binman/test/066_text.dts b/tools/binman/test/066_text.dts
index 59b1fed0ef8..f23a75ae929 100644
--- a/tools/binman/test/066_text.dts
+++ b/tools/binman/test/066_text.dts
@@ -24,5 +24,10 @@
 			text-label = "test-id4";
 			test-id4 = "some text";
 		};
+		/* Put text directly in the node */
+		text5 {
+			type = "text";
+			text = "more text";
+		};
 	};
 };
-- 
2.22.0.410.gd8fdbe21b5-goog



More information about the U-Boot mailing list