Skip to contentSkip to conversation

update dt-extract-example

PATCH New Sam Ravnborg 1 participant 3 messages Apr 25, 2020

lore
Share & tools
lore
#0 lore raw

cover update dt-extract-example

First one patch to add support for root nodes in dt-extract-example. This will allow us to modify the example for simple-frambuffer to it is more correct without any warnings.
And we may ahve a potential to use this in other places.

Verified that this did not introduce any regressions in mainline kernel.

Looking at the generating output there was one line with wrong ident. Fixed this so reading the generated outlut was a little easier to the eye. The fix has no impact on the checks.

Patching simple-frambuffer.yaml in the kernel will
have to wait a little. At a minimum this patch should be accepted and dt-schema shall have a higher version.

Sam

Sam Ravnborg (2):
tools/dt-extract-example: support examples with root node tools/dt-extract-example: beautify output

 tools/dt-extract-example | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
#1 lore raw

PATCH 1/2 tools/dt-extract-example: support examples with root node

Examples are prefixed with boiler plate in the normal case. In the rare case a root node is required this boiler plate shall not be used.

Example with root node:

    / {
        chosen {
            ...;
        }
    }

Teach the script to recognize that the example starts with a root node and avoid the boiler plate in such cases.
The root node is recognized using a simple regular expression search.

---
 tools/dt-extract-example | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
tools/dt-extract-example +15 -3
index 99e59c3..0e933e4 100755
@@ -4,6 +4,7 @@
 # Copyright 2019 Arm Ltd.
 
 import os
+import re
 import sys
 import ruamel.yaml
 import argparse
@@ -17,11 +18,14 @@ example_template = """
 {example}
 
     }};
+}};
 """
 
 example_header = """
 /dts-v1/;
 /plugin/; // silence any missing phandle references
+"""
+example_start = """
 /{
     compatible = "foo";
     model = "foo";
@@ -49,7 +53,15 @@ if __name__ == "__main__":
 
     if 'examples' in binding.keys():
         for idx,ex in enumerate(binding['examples']):
-            ex = '        '.join(ex.splitlines(True))
-            print(example_template.format(example=ex,example_num=idx))
+            # Check if example contains a root node "/{"
+            root_node = re.search('^/\s*{', ex)
 
-    print("\n};")
+            if not root_node:
+                print(example_start)
+                ex = '        '.join(ex.splitlines(True))
+                print(example_template.format(example=ex,example_num=idx))
+            else:
+                print(ex)
+    else:
+        print(example_start)
+        print("\n};")
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 tools/dt-extract-example: beautify output

In reply to Sam Ravnborg

Fix so first line in the output has same indent as the rest of the lines in the example.
This makes the examples a little easier to read.

---
 tools/dt-extract-example | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tools/dt-extract-example +1 -2
index 0e933e4..f1a222f 100755
@@ -15,8 +15,7 @@ example_template = """
         #address-cells = <1>;
         #size-cells = <1>;
 
-{example}
-
+        {example}
     }};
 }};
 """
Signature · 1 line
2.20.1