<p>Patrick Rudolph has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/26228">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">util/cavium: Add tool to convert devicetree blobs<br><br>Convert Cavium's BDK devicetree blob to a static C file.<br><br>The resulting file must be included in mainboard folder to provide<br>board specific configuration values to BDK functions.<br><br>Example call:<br>python devicetree_convert.py --in sff8104.dtb --out bdk_devicetree.c<br><br>Change-Id: I76a5588aefe4f680228eca46a0e4dba7e695931c<br>Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com><br>---<br>A util/cavium/devicetree_convert.py<br>1 file changed, 57 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/28/26228/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/util/cavium/devicetree_convert.py b/util/cavium/devicetree_convert.py</span><br><span>new file mode 100644</span><br><span>index 0000000..c734d17</span><br><span>--- /dev/null</span><br><span>+++ b/util/cavium/devicetree_convert.py</span><br><span>@@ -0,0 +1,57 @@</span><br><span style="color: hsl(120, 100%, 40%);">+#!/usr/bin/python</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+# devicetree_convert Tool to convert a DTB to a static C file</span><br><span style="color: hsl(120, 100%, 40%);">+# Copyright (C) 2018 Facebook Inc.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+# it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+# the Free Software Foundation; either version 3 of the License, or</span><br><span style="color: hsl(120, 100%, 40%);">+# (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+# This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+# but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+# GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+#</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from pyfdt.pyfdt import FdtBlobParse</span><br><span style="color: hsl(120, 100%, 40%);">+import argparse</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+parser = argparse.ArgumentParser(description='Cavium DTB to C converter')</span><br><span style="color: hsl(120, 100%, 40%);">+parser.add_argument('--indtb', help='Compiled devicetree blob to parse')</span><br><span style="color: hsl(120, 100%, 40%);">+parser.add_argument('--out', help='The file to write')</span><br><span style="color: hsl(120, 100%, 40%);">+parser.add_argument('--verbose', help='Be verbose', action='store_true', default=False)</span><br><span style="color: hsl(120, 100%, 40%);">+args = parser.parse_args()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+outfile = None</span><br><span style="color: hsl(120, 100%, 40%);">+if args.out is not None:</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile = open(args.out, 'w')</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("// This file is part of the coreboot project.\n")</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("// This file is automatically generated.\n")</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("// DO NOT EDIT BY HAND.\n\n")</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("#include <bdk-devicetree.h>\n\n")</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("const struct bdk_devicetree_key_value devtree[] = {\n")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+with open(args.indtb) as infile:</span><br><span style="color: hsl(120, 100%, 40%);">+    dtb = FdtBlobParse(infile)</span><br><span style="color: hsl(120, 100%, 40%);">+    fdt = dtb.to_fdt()</span><br><span style="color: hsl(120, 100%, 40%);">+    for (path, node) in fdt.resolve_path('/cavium,bdk').walk():</span><br><span style="color: hsl(120, 100%, 40%);">+        if "/" in path:</span><br><span style="color: hsl(120, 100%, 40%);">+            path = path.replace("/", "")</span><br><span style="color: hsl(120, 100%, 40%);">+        if len(node) == 1:</span><br><span style="color: hsl(120, 100%, 40%);">+            for i in node:</span><br><span style="color: hsl(120, 100%, 40%);">+                if type(i) is not unicode:</span><br><span style="color: hsl(120, 100%, 40%);">+                    print "%s: Type is not string" % path</span><br><span style="color: hsl(120, 100%, 40%);">+                    continue</span><br><span style="color: hsl(120, 100%, 40%);">+                if args.verbose:</span><br><span style="color: hsl(120, 100%, 40%);">+                    print "%s = %s" % (path, i)</span><br><span style="color: hsl(120, 100%, 40%);">+                if outfile is not None:</span><br><span style="color: hsl(120, 100%, 40%);">+                    outfile.write("{\"%s\", \"%s\"},\n" % (path, i))</span><br><span style="color: hsl(120, 100%, 40%);">+        else:</span><br><span style="color: hsl(120, 100%, 40%);">+            print "%s: Arrays aren't supported" % path</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+if outfile is not None:</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("{0, 0},\n")</span><br><span style="color: hsl(120, 100%, 40%);">+    outfile.write("};\n")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/26228">change 26228</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/26228"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I76a5588aefe4f680228eca46a0e4dba7e695931c </div>
<div style="display:none"> Gerrit-Change-Number: 26228 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Patrick Rudolph <patrick.rudolph@9elements.com> </div>