1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | ########################################################################################## |
---|
4 | # File : genarch.py |
---|
5 | # Date : 2016 |
---|
6 | # Author : Alain Greiner |
---|
7 | # Copyright (c) UPMC Sorbonne Universites |
---|
8 | ######################################################################################### |
---|
9 | # This python script generates the "arch_info.bin" file required by the ALMOS-MK |
---|
10 | # operating system bootloader and describing the target hardware architecture. |
---|
11 | # It uses an architecture specific, python script that must be called "arch_info.py". |
---|
12 | # |
---|
13 | # The source directory containing the "arch_info.py" file and the destination directory |
---|
14 | # to store the "arch_info.bin" file are defined by parameters on the command line: |
---|
15 | # --arch=string : path to directory containing the "arch_info.py" file |
---|
16 | # --bin=string : path to directory to store the "arch_info.bin" file |
---|
17 | # |
---|
18 | # As the target architecture is generic, the following hardware parameters can be |
---|
19 | # defined on the command line: |
---|
20 | # --x_size=int : number of clusters in a row |
---|
21 | # --y_size=int : number of clusters in a column |
---|
22 | # --nb_cores=int : number of cores per cluster |
---|
23 | # --nb_ttys=int : number of TTY channels |
---|
24 | # --nb_nics=int : number of NIC channels |
---|
25 | # --ioc_type=string : can be IOC_BDV , IOC_HBA , IOC_SDC , IOC_SPI |
---|
26 | # --txt_type=string : can be TXT_TTY , TXT_MTY |
---|
27 | # --fbf_type=string : can be FBF_LTI , FBF_SCL |
---|
28 | # --sys_clk=int : system clock frequency (Hz) |
---|
29 | # |
---|
30 | # The following parameters can be used to generate the optional "hard_config.h" file, |
---|
31 | # that is required to configurate the SystemC virtual prototype, and the "arch_info.xml" |
---|
32 | # file for debug. |
---|
33 | # --hard=string : path to directory to store the "hard_config.h" file |
---|
34 | # --xml=string : path to directory to store the "arch_info.xml" file |
---|
35 | # |
---|
36 | ######################################################################################### |
---|
37 | |
---|
38 | import sys |
---|
39 | |
---|
40 | from arch_classes import * |
---|
41 | from optparse import OptionParser |
---|
42 | |
---|
43 | ################################################################################### |
---|
44 | # define command line arguments |
---|
45 | ################################################################################### |
---|
46 | |
---|
47 | parser = OptionParser() |
---|
48 | |
---|
49 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
50 | help = 'define pathname to directory containing arch_info.py file' ) |
---|
51 | |
---|
52 | parser.add_option( '--bin', type = 'string', dest = 'bin_path', |
---|
53 | help = 'define pathname to directory to store arch_info.bin file' ) |
---|
54 | |
---|
55 | parser.add_option( '--x_size', type = 'int', dest = 'x_size', |
---|
56 | default = 2, |
---|
57 | help = 'define number of clusters in a row' ) |
---|
58 | |
---|
59 | parser.add_option( '--y_size', type = 'int', dest = 'y_size', |
---|
60 | default = 2, |
---|
61 | help = 'define number of clusters in a column' ) |
---|
62 | |
---|
63 | parser.add_option( '--nb_cores', type = 'int', dest = 'nb_cores', |
---|
64 | default = 2, |
---|
65 | help = 'define number of cores per cluster' ) |
---|
66 | |
---|
67 | parser.add_option( '--nb_ttys', type = 'int', dest = 'nb_ttys', |
---|
68 | default = 1, |
---|
69 | help = 'define number of TTY channels' ) |
---|
70 | |
---|
71 | parser.add_option( '--nb_nics', type = 'int', dest = 'nb_nics', |
---|
72 | default = 1, |
---|
73 | help = 'define number ot NIC channels' ) |
---|
74 | |
---|
75 | parser.add_option( '--ioc_type', type = 'string', dest = 'ioc_type', |
---|
76 | default = 'IOC_BDV', |
---|
77 | help = 'IOC type : BDV / HBA / SDC / RDK / SPI' ) |
---|
78 | |
---|
79 | parser.add_option( '--txt_type', type = 'string', dest = 'txt_type', |
---|
80 | default = 'TXT_TTY', |
---|
81 | help = 'TXT type : TTY / RS2 / MTY' ) |
---|
82 | |
---|
83 | parser.add_option( '--fbf_type', type = 'string', dest = 'fbf_type', |
---|
84 | default = 'FBF_SCL', |
---|
85 | help = 'FBF type : LTI / SCL' ) |
---|
86 | |
---|
87 | parser.add_option( '--sys_clk', type = 'int', dest = 'sys_clk', |
---|
88 | default = 50000, |
---|
89 | help = 'system clock frequency (50 KHz simu / 25 MHz FPGA, 600 MHz VLSI)' ) |
---|
90 | |
---|
91 | parser.add_option( '--hard', type = 'string', dest = 'hard_path', |
---|
92 | help = 'define pathname to directory for the hard_config.h file ' ) |
---|
93 | |
---|
94 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
95 | help = 'define pathname to directory for the arch_info.xml file' ) |
---|
96 | |
---|
97 | parser.add_option( '--v', action = 'store_true', dest = 'verbose', |
---|
98 | default = False, |
---|
99 | help = 'display detailed report on arch_info.bin generation' ) |
---|
100 | |
---|
101 | ################################################################################### |
---|
102 | # Get command line arguments |
---|
103 | ################################################################################### |
---|
104 | |
---|
105 | (options,args) = parser.parse_args() |
---|
106 | |
---|
107 | arch_path = options.arch_path # path to arch_info.py file |
---|
108 | bin_path = options.bin_path # path for arch_info.bin file |
---|
109 | |
---|
110 | x_size = options.x_size # number of clusters in a row |
---|
111 | y_size = options.y_size # number of clusters in a column |
---|
112 | nb_cores = options.nb_cores # number of cores in a cluster |
---|
113 | nb_ttys = options.nb_ttys # number of TTY channels |
---|
114 | nb_nics = options.nb_nics # number of NIC channels |
---|
115 | ioc_type = options.ioc_type # ioc controller type |
---|
116 | txt_type = options.txt_type # txt terminal type |
---|
117 | fbf_type = options.fbf_type # fbf terminal type |
---|
118 | sys_clk = options.sys_clk # system clock frequency in Hertz |
---|
119 | |
---|
120 | hard_path = options.hard_path # path for hard_config.h file |
---|
121 | xml_path = options.xml_path # path for arch_info.xml file |
---|
122 | |
---|
123 | verbose = options.verbose # report on arch_info.bin generation |
---|
124 | |
---|
125 | |
---|
126 | ################################################################################### |
---|
127 | # Build the archinfo structure for the selected arch_info.py |
---|
128 | ################################################################################### |
---|
129 | |
---|
130 | if ( arch_path == None ): |
---|
131 | print 'You must define a path to the arch_info.py file on command line' |
---|
132 | sys.exit(1) |
---|
133 | |
---|
134 | # dynamically append arch_path to PYTHONPATH |
---|
135 | sys.path.append( arch_path ) |
---|
136 | |
---|
137 | # import the arch_info.py module (using file name without suffix) |
---|
138 | select = __import__( 'arch_info' ) |
---|
139 | print select |
---|
140 | |
---|
141 | # build the arch_info structure by calling the arch function |
---|
142 | archinfo = select.arch( x_size, |
---|
143 | y_size, |
---|
144 | nb_cores, |
---|
145 | nb_ttys, |
---|
146 | nb_nics, |
---|
147 | ioc_type, |
---|
148 | txt_type, |
---|
149 | fbf_type, |
---|
150 | sys_clk ) |
---|
151 | |
---|
152 | print '[genarch] archinfo build for %s' % archinfo.name |
---|
153 | |
---|
154 | ################################################################################### |
---|
155 | # Generate arch_info.xml file if required. |
---|
156 | ################################################################################### |
---|
157 | |
---|
158 | if ( xml_path != None ): |
---|
159 | pathname = xml_path + '/arch_info.xml' |
---|
160 | f = open ( pathname, 'w' ) |
---|
161 | f.write( archinfo.xml() ) |
---|
162 | |
---|
163 | print '[genarch] %s generated' % pathname |
---|
164 | |
---|
165 | ################################################################################### |
---|
166 | # Generate arch_info.bin file if required. |
---|
167 | ################################################################################### |
---|
168 | |
---|
169 | if ( bin_path != None ): |
---|
170 | pathname = bin_path + '/arch_info.bin' |
---|
171 | f = open ( pathname, 'wb' ) |
---|
172 | f.write( archinfo.cbin( verbose ) ) |
---|
173 | print '[genarch] %s generated' % pathname |
---|
174 | |
---|
175 | ################################################################################### |
---|
176 | # Generate hard_config.h file if required. |
---|
177 | ################################################################################### |
---|
178 | |
---|
179 | if ( hard_path != None ): |
---|
180 | |
---|
181 | pathname = hard_path + '/hard_config.h' |
---|
182 | f = open ( pathname, 'w' ) |
---|
183 | f.write( archinfo.hard_config() ) |
---|
184 | print '[genarch] %s generated' % pathname |
---|
185 | |
---|