Skip to contentSkip to conversation

Cyclone V Board handsoff script

PATCH In review Brian Sune 2 participants 2 messages Oct 31, 2025 – Nov 17, 2025

lore
Share & tools
lore

Brian Sune

author
#0 lore raw

PATCH v2 1/1 Cyclone V Board handsoff script

Since turning from old build flow.
New Altera SoCFPGA requires converting handsoff
conversion via the python script. This is from
official provided, and now sync to U-Boot with
better location at tools/cv_xxxx. Meantime,
requirement.txt is also provided to further
explain the libraries require for these scripts.

---
 tools/cv_bsp_generator/cv_bsp_generator.py | 100 ++++
 tools/cv_bsp_generator/doc.py              | 243 +++++++++
 tools/cv_bsp_generator/emif.py             | 424 +++++++++++++++
 tools/cv_bsp_generator/hps.py              | 571 +++++++++++++++++++++
 tools/cv_bsp_generator/iocsr.py            | 203 ++++++++
 tools/cv_bsp_generator/model.py            | 114 ++++
 tools/cv_bsp_generator/renderer.py         | 196 +++++++
 tools/cv_bsp_generator/requirements.txt    |   5 +
 tools/cv_bsp_generator/streamer.py         | 102 ++++
 tools/cv_bsp_generator/xmlgrok.py          |  32 ++
 10 files changed, 1990 insertions(+)
 create mode 100755 tools/cv_bsp_generator/cv_bsp_generator.py
 create mode 100755 tools/cv_bsp_generator/doc.py
 create mode 100755 tools/cv_bsp_generator/emif.py
 create mode 100755 tools/cv_bsp_generator/hps.py
 create mode 100755 tools/cv_bsp_generator/iocsr.py
 create mode 100755 tools/cv_bsp_generator/model.py
 create mode 100755 tools/cv_bsp_generator/renderer.py
 create mode 100644 tools/cv_bsp_generator/requirements.txt
 create mode 100755 tools/cv_bsp_generator/streamer.py
 create mode 100755 tools/cv_bsp_generator/xmlgrok.py
tools/cv_bsp_generator/cv_bsp_generator.py new file +100 -0
new file mode 100755
index 00000000000..aff597d3978
@@ -0,0 +1,100 @@
+#! /usr/bin/env python
+# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+"""
+Bsp preloader header file generator
+
+Process the handoff files from Quartus and convert them to headers
+usable by U-Boot. Includes the qts filter.sh capability to generate
+correct format for headers to be used for mainline Uboot on FPGA,
+namely Cyclone V & Arria V.
+
+Copyright (C) 2022 Intel Corporation <www.intel.com>
+
+Author: Lee, Kah Jing <[email protected]>
+"""
+import glob
+import optparse
+import os
+import shutil
+import emif
+import hps
+import iocsr
+import renderer
+import model
+import collections
+import sys
+
+def printUsage():
+    """ usage string """
+    print ("Usage:\n\t%s\n" % ("sys.argv[0], --input_dir=<path to iswinfo directory> --output_dir=<path store output files>"))
+    exit(1)
+
+def verifyInputDir(dir):
+    """ check if the input directory exists """
+    if not os.path.isdir(dir):
+        print ("There is no such directory '%s'!\n" % (dir))
+        exit(1)
+
+def verifyOutputDir(dir):
+    """ check if the output directory exists """
+    if not os.path.isdir(dir):
+        os.makedirs(dir)
+
+if __name__ == '__main__':
+    # Do some rudimentary command line processing until it is proven we need something
+    # heavier, such as argparse (preferred, but 2.7+ only) or optparse
+
+    inputDir = '.'
+    outputDir = '.'
+
+    progVersion = '%prog 1.0'
+    progDesc = 'Generate board-specific files for the preloader'
+    optParser = optparse.OptionParser(version=progVersion, description=progDesc)
+    optParser.add_option('-i', '--input-dir', action='store', type='string', dest='inputDir', default='.',
+                         help='input-dir is usually the iswinfo directory')
+    optParser.add_option('-o', '--output-dir', action='store', type='string', dest='outputDir', default='.',
+                         help='output-dir is usually the directory containing the preloader source')
+
+    (options, args) = optParser.parse_args()
+
+    for arg in args:
+        print ("***WARNING: I don't understand '%s', so I am ignoring it\n" % (arg))
+
+    inputDir = options.inputDir
+    verifyInputDir(inputDir)
+    outputDir = options.outputDir
+
+    verifyOutputDir(outputDir)
+
+    emif = emif.EMIFGrokker(inputDir, outputDir, 'emif.xml')
+    hps = hps.HPSGrokker(inputDir, outputDir)
+
+    pllConfigH = outputDir + "/" + "pll_config.h"
+    print ("Generating file: " + pllConfigH)
+    hpsModel = model.hps.create(inputDir + "/" + "hps.xml")
+    emifModel = model.emif.create(inputDir +"/" + "emif.xml")
+
+    content=str(renderer.pll_config_h(hpsModel, emifModel))
+    f = open(pllConfigH, "w")
+    f.write(content)
+    f.close()
+
+    # For all the .hiof files, make a iocsr_config.[h|c]
+    # Only support single hiof file currently
+    hiof_list = glob.glob(inputDir + os.sep + "*.hiof")
+    if len(hiof_list) < 1:
+        print ("***Error: No .hiof files found in input!")
+
+    elif len(hiof_list) > 1:
+        print ("***Error: We don't handle more than one .hiof file yet")
+        print ("          Only the last .hiof file in the list will be converted")
+        print ("          hiof files found:")
+        for f in hiof_list:
+            print ("              " + f)
+
+    for hiof_file_path in hiof_list:
+        hiof_file = os.path.basename(hiof_file_path)
+        # Avoid IOCSRGrokker having to parse hps.xml to determine
+        # device family for output file name, instead we'll just
+        # get it from HPSGrokker
+        iocsr = iocsr.IOCSRGrokker(hps.getDeviceFamily(), inputDir, outputDir, hiof_file)
tools/cv_bsp_generator/doc.py new file +243 -0

243 lines not on this page · raw message

tools/cv_bsp_generator/emif.py new file +424 -0

424 lines not on this page · raw message

tools/cv_bsp_generator/hps.py new file +571 -0

571 lines not on this page · raw message

tools/cv_bsp_generator/iocsr.py new file +203 -0

203 lines not on this page · raw message

tools/cv_bsp_generator/model.py new file +114 -0

114 lines not on this page · raw message

tools/cv_bsp_generator/renderer.py new file +196 -0

196 lines not on this page · raw message

tools/cv_bsp_generator/requirements.txt new file +5 -0
new file mode 100644
index 00000000000..2ad65d1c331
@@ -0,0 +1,5 @@
+# requirements.txt for cv_bsp_generator.py
+# All dependencies are either standard library modules
+# or local Python files included in this BSP tool.
+# No external pip packages are required.
+
tools/cv_bsp_generator/streamer.py new file +102 -0

102 lines not on this page · raw message

tools/cv_bsp_generator/xmlgrok.py new file +32 -0
new file mode 100755
index 00000000000..fae1d745bfd
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
+"""
+XML node parser
+
+Copyright (C) 2022 Intel Corporation <www.intel.com>
+
+Author: Lee, Kah Jing <[email protected]>
+"""
+import xml.dom
+
+def isElementNode(XMLNode):
+    """ check if the node is element node """
+    return XMLNode.nodeType == xml.dom.Node.ELEMENT_NODE
+
+def firstElementChild(XMLNode):
+    """ Calling firstChild on an Node of type Element often (always?)
+    returns a Node of Text type.  How annoying!  Return the first Element
+    child
+    """
+    child = XMLNode.firstChild
+    while child != None and not isElementNode(child):
+        child = nextElementSibling(child)
+    return child
+
+def nextElementSibling(XMLNode):
+    """ nextElementSibling will return the next sibling of XMLNode that is
+    an Element Node Type
+    """
+    sib = XMLNode.nextSibling
+    while sib != None and not isElementNode(sib):
+        sib = sib.nextSibling
+    return sib
Signature · 1 line
2.25.1
Reviewed-by Tien Fong Chee on v2 1/1
#1 lore raw
Quoted 31 lines · Brian Sune

Since turning from old build flow.
New Altera SoCFPGA requires converting handsoff conversion via the python script. This is from official provided, and now sync to U-Boot with better location at tools/cv_xxxx. Meantime, requirement.txt is also provided to further explain the libraries require for these scripts.

---
  tools/cv_bsp_generator/cv_bsp_generator.py | 100 ++++
  tools/cv_bsp_generator/doc.py              | 243 +++++++++
  tools/cv_bsp_generator/emif.py             | 424 +++++++++++++++
  tools/cv_bsp_generator/hps.py              | 571 +++++++++++++++++++++
  tools/cv_bsp_generator/iocsr.py            | 203 ++++++++
  tools/cv_bsp_generator/model.py            | 114 ++++
  tools/cv_bsp_generator/renderer.py         | 196 +++++++
  tools/cv_bsp_generator/requirements.txt    |   5 +
  tools/cv_bsp_generator/streamer.py         | 102 ++++
  tools/cv_bsp_generator/xmlgrok.py          |  32 ++
  10 files changed, 1990 insertions(+)

create mode 100755 tools/cv_bsp_generator/cv_bsp_generator.py create mode 100755 tools/cv_bsp_generator/doc.py create mode 100755 tools/cv_bsp_generator/emif.py create mode 100755 tools/cv_bsp_generator/hps.py create mode 100755 tools/cv_bsp_generator/iocsr.py create mode 100755 tools/cv_bsp_generator/model.py create mode 100755 tools/cv_bsp_generator/renderer.py create mode 100644 tools/cv_bsp_generator/requirements.txt create mode 100755 tools/cv_bsp_generator/streamer.py create mode 100755 tools/cv_bsp_generator/xmlgrok.py

[...]

Best regards,
Tien Fong