Skip to content

Commit cc2f57f

Browse files
kahjingl90Alif Zakuan Yuslaimi
authored andcommitted
arm: socfpga: Add bsp-generator scripts with qts-filter
HSD#14015480674 & HSD#14015550009: Remove the requirement on the bsp-create-settings script to generate uboot header files. It will 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 to be used for mainline Uboot on FPGA, namely Cyclone V & Arria V. Usage of each .py scripts: cv_bsp_generator.py : main wrapper to generate uboot required files doc.py : templates for creating documents of generic data model emif.py : parse handoff files to create sdram_config.h hps.py : parse hps.xml to create pinmux_config.h file iocsr.py : process the hiof file from Quartus and generate iocsr .h usable by U-Boot model.py : wrapper for XML DOM parser renderer.py : construction of a specific file format using required data model, in the case, generate the pll_config.h streamer.py : generate license, file header and close tag xmlgrok.py : xml tag navigator Signed-off-by: Kah Jing Lee <kah.jing.lee@intel.com>
1 parent e31a181 commit cc2f57f

File tree

10 files changed

+1986
-60
lines changed

10 files changed

+1986
-60
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#! /usr/bin/env python
2+
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3+
"""
4+
Bsp preloader header file generator
5+
6+
Process the handoff files from Quartus and convert them to headers
7+
usable by U-Boot. Includes the qts filter.sh capability to generate
8+
correct format for headers to be used for mainline Uboot on FPGA,
9+
namely Cyclone V & Arria V.
10+
11+
Copyright (C) 2022 Intel Corporation <www.intel.com>
12+
13+
Author: Lee, Kah Jing <kah.jing.lee@intel.com>
14+
"""
15+
import glob
16+
import optparse
17+
import os
18+
import shutil
19+
import emif
20+
import hps
21+
import iocsr
22+
import renderer
23+
import model
24+
import collections
25+
import sys
26+
27+
def printUsage():
28+
""" usage string """
29+
print ("Usage:\n\t%s\n" % ("sys.argv[0], --input_dir=<path to iswinfo directory> --output_dir=<path store output files>"))
30+
exit(1)
31+
32+
def verifyInputDir(dir):
33+
""" check if the input directory exists """
34+
if not os.path.isdir(dir):
35+
print ("There is no such directory '%s'!\n" % (dir))
36+
exit(1)
37+
38+
def verifyOutputDir(dir):
39+
""" check if the output directory exists """
40+
if not os.path.isdir(dir):
41+
os.makedirs(dir)
42+
43+
if __name__ == '__main__':
44+
# Do some rudimentary command line processing until it is proven we need something
45+
# heavier, such as argparse (preferred, but 2.7+ only) or optparse
46+
47+
inputDir = '.'
48+
outputDir = '.'
49+
50+
progVersion = '%prog 1.0'
51+
progDesc = 'Generate board-specific files for the preloader'
52+
optParser = optparse.OptionParser(version=progVersion, description=progDesc)
53+
optParser.add_option('-i', '--input-dir', action='store', type='string', dest='inputDir', default='.',
54+
help='input-dir is usually the iswinfo directory')
55+
optParser.add_option('-o', '--output-dir', action='store', type='string', dest='outputDir', default='.',
56+
help='output-dir is usually the directory containing the preloader source')
57+
58+
(options, args) = optParser.parse_args()
59+
60+
for arg in args:
61+
print ("***WARNING: I don't understand '%s', so I am ignoring it\n" % (arg))
62+
63+
inputDir = options.inputDir
64+
verifyInputDir(inputDir)
65+
outputDir = options.outputDir
66+
67+
verifyOutputDir(outputDir)
68+
69+
emif = emif.EMIFGrokker(inputDir, outputDir, 'emif.xml')
70+
hps = hps.HPSGrokker(inputDir, outputDir)
71+
72+
pllConfigH = outputDir + "/" + "pll_config.h"
73+
print ("Generating file: " + pllConfigH)
74+
hpsModel = model.hps.create(inputDir + "/" + "hps.xml")
75+
emifModel = model.emif.create(inputDir +"/" + "emif.xml")
76+
77+
content=str(renderer.pll_config_h(hpsModel, emifModel))
78+
f = open(pllConfigH, "w")
79+
f.write(content)
80+
f.close()
81+
82+
# For all the .hiof files, make a iocsr_config.[h|c]
83+
# Only support single hiof file currently
84+
hiof_list = glob.glob(inputDir + os.sep + "*.hiof")
85+
if len(hiof_list) < 1:
86+
print ("***Error: No .hiof files found in input!")
87+
88+
elif len(hiof_list) > 1:
89+
print ("***Error: We don't handle more than one .hiof file yet")
90+
print (" Only the last .hiof file in the list will be converted")
91+
print (" hiof files found:")
92+
for f in hiof_list:
93+
print (" " + f)
94+
95+
for hiof_file_path in hiof_list:
96+
hiof_file = os.path.basename(hiof_file_path)
97+
# Avoid IOCSRGrokker having to parse hps.xml to determine
98+
# device family for output file name, instead we'll just
99+
# get it from HPSGrokker
100+
iocsr = iocsr.IOCSRGrokker(hps.getDeviceFamily(), inputDir, outputDir, hiof_file)
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
# SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2+
"""
3+
Generic document construction classes.
4+
5+
These classes are templates for creating documents that are not bound
6+
to a specific usage or data model.
7+
8+
Copyright (C) 2022 Intel Corporation <www.intel.com>
9+
10+
Author: Lee, Kah Jing <kah.jing.lee@intel.com>
11+
"""
12+
13+
class document(object):
14+
"""
15+
An abstract document class which does not dictate
16+
how a document should be constructed or manipulated.
17+
18+
It's sole purpose is to describe the entire document
19+
in smaller units
20+
"""
21+
22+
class entry(object):
23+
"""
24+
An entry is the smallest unit
25+
"""
26+
27+
def __init__(self, parent):
28+
""" entry initialization """
29+
if parent != None:
30+
parent.add(self)
31+
32+
class block(entry):
33+
"""
34+
A block is the smallest collection unit
35+
consists of entries and blocks.
36+
"""
37+
38+
def __init__(self, parent):
39+
""" block initialization """
40+
super(document.block, self).__init__(parent)
41+
self.entries = []
42+
43+
def add(self, entry):
44+
""" add entry to block """
45+
self.entries.append(entry)
46+
47+
48+
def __init__(self):
49+
""" document initialization """
50+
self.entries = []
51+
52+
def add(self, entry):
53+
""" add entry to entry list """
54+
self.entries.append(entry)
55+
56+
57+
class text(document):
58+
"""
59+
A simple text document implementation
60+
"""
61+
62+
class string(document.entry):
63+
"""
64+
The smallest unit of a text file is a string
65+
"""
66+
67+
def __init__(self, parent, stringString=None):
68+
""" string initialization """
69+
super(text.string, self).__init__(parent)
70+
self.stringString = stringString
71+
72+
def __str__(self):
73+
""" convert None to empty string """
74+
if (self.stringString != None):
75+
return self.stringString
76+
else:
77+
return ""
78+
79+
80+
class line(string):
81+
"""
82+
A line is a string with EOL character
83+
"""
84+
85+
def __str__(self):
86+
""" convert string with newline """
87+
return super(text.line, self).__str__() + "\n"
88+
89+
class block(document.block):
90+
"""
91+
A block of text which can be made up of
92+
strings or lines
93+
"""
94+
95+
def __str__(self):
96+
""" concatenate strings or lines """
97+
blockString = ""
98+
99+
for entry in self.entries:
100+
blockString += str(entry)
101+
102+
return blockString
103+
104+
105+
def __str__(self):
106+
""" concatenate strings or lines """
107+
textString = ""
108+
109+
for entry in self.entries:
110+
textString += str(entry)
111+
112+
return textString
113+
114+
115+
class c_source(text):
116+
"""
117+
A simple C header document implementation
118+
"""
119+
120+
class define(text.string):
121+
"""
122+
C header define
123+
"""
124+
125+
def __init__(self, parent, id, token=None):
126+
""" c header constructor initialization """
127+
super(c_source.define, self).__init__(parent, id)
128+
self.token = token
129+
130+
def __str__(self):
131+
""" c header to strings """
132+
defineString = "#define" + " " + super(c_source.define, self).__str__()
133+
134+
if self.token != None:
135+
defineString += " " + self.token
136+
137+
defineString += "\n"
138+
139+
return defineString
140+
141+
class comment_string(text.string):
142+
"""
143+
C header comment
144+
"""
145+
146+
def __str__(self):
147+
""" c comment """
148+
return "/*" + " " + super(c_source.comment_string, self).__str__() + " " + "*/"
149+
150+
class comment_line(comment_string):
151+
"""
152+
C header comment with newline
153+
"""
154+
155+
def __str__(self):
156+
""" c comment with newline """
157+
return super(c_source.comment_line, self).__str__() + "\n"
158+
159+
class block(text.block):
160+
"""
161+
A simple C block string implementation
162+
"""
163+
164+
def __init__(self, parent, prologue=None, epilogue=None):
165+
""" ifdef block string implementation """
166+
super(c_source.block, self).__init__(parent)
167+
168+
self.prologue = None
169+
self.epilogue = None
170+
171+
if prologue != None:
172+
self.prologue = prologue
173+
174+
if epilogue != None:
175+
self.epilogue = epilogue
176+
177+
def __str__(self):
178+
""" convert ifdef to string """
179+
blockString = ""
180+
181+
if self.prologue != None:
182+
blockString += str(self.prologue)
183+
184+
blockString += super(c_source.block, self).__str__()
185+
186+
if self.epilogue != None:
187+
blockString += str(self.epilogue)
188+
189+
return blockString
190+
191+
class comment_block(block):
192+
"""
193+
A simple C header block comment implementation
194+
"""
195+
196+
def __init__(self, parent, comments):
197+
""" block comment initialization """
198+
super(c_source.comment_block, self).__init__(parent, "/*\n", " */\n")
199+
for comment in comments.split("\n"):
200+
self.add(comment)
201+
202+
def add(self, entry):
203+
""" add line to block comment """
204+
super(c_source.block, self).add(" * " + entry + "\n")
205+
206+
class ifndef_block(block):
207+
"""
208+
A simple C header ifndef implementation
209+
"""
210+
211+
def __init__(self, parent, id):
212+
""" ifndef block initialization """
213+
prologue = text.line(None, "#ifndef" + " " + id)
214+
epilogue = text.block(None)
215+
text.string(epilogue, "#endif")
216+
text.string(epilogue, " ")
217+
c_source.comment_line(epilogue, id)
218+
super(c_source.ifndef_block, self).__init__(parent, prologue, epilogue)
219+
220+
221+
class generated_c_source(c_source):
222+
"""
223+
Caller to generate c format files using the helper classes
224+
"""
225+
226+
def __init__(self, filename):
227+
""" Generate c header file with license, copyright, comment,
228+
ifdef block
229+
"""
230+
super(generated_c_source, self).__init__()
231+
232+
self.entries.append(c_source.comment_line(None, "SPDX-License-Identifier: BSD-3-Clause"))
233+
self.entries.append(c_source.comment_block(None, "Copyright (C) 2022 Intel Corporation <www.intel.com>"))
234+
self.entries.append(c_source.comment_block(None, "Altera SoCFPGA Clock and PLL configuration"))
235+
self.entries.append(text.line(None))
236+
237+
self.body = c_source.ifndef_block(None, filename)
238+
self.body.add(c_source.define(None, filename))
239+
self.entries.append(self.body)
240+
241+
def add(self, entry):
242+
""" add content to be written into c header file """
243+
self.body.add(entry)

0 commit comments

Comments
 (0)