[1] | 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 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 | # --fbf_size=int : frame buffer width & heigth |
---|
| 26 | # --ioc_type=string : can be IOC_BDV , IOC_HBA , IOC_SDC , IOC_SPI |
---|
| 27 | # |
---|
| 28 | # The following parameters can be used to generate the optional "hard_config.h" file, |
---|
| 29 | # that is required to configurate the SystemC virtual prototype, and the "arch_info.xml" |
---|
| 30 | # file for debug. |
---|
| 31 | # --hard=string : path to directory to store the "hard_config.h" file |
---|
| 32 | # --xml=string : path to directory to store the "arch_info.xml" file |
---|
| 33 | # |
---|
| 34 | ######################################################################################### |
---|
| 35 | |
---|
| 36 | import sys |
---|
| 37 | |
---|
| 38 | from arch_classes import * |
---|
| 39 | from optparse import OptionParser |
---|
| 40 | |
---|
| 41 | ################################################################################### |
---|
| 42 | # define command line arguments |
---|
| 43 | ################################################################################### |
---|
| 44 | |
---|
| 45 | parser = OptionParser() |
---|
| 46 | |
---|
| 47 | parser.add_option( '--arch', type = 'string', dest = 'arch_path', |
---|
| 48 | help = 'define pathname to directory containing arch_info.py file' ) |
---|
| 49 | |
---|
| 50 | parser.add_option( '--bin', type = 'string', dest = 'bin_path', |
---|
| 51 | help = 'define pathname to directory to store arch_info.bin file' ) |
---|
| 52 | |
---|
| 53 | parser.add_option( '--x_size', type = 'int', dest = 'x_size', |
---|
| 54 | default = 2, |
---|
| 55 | help = 'define number of clusters in a row' ) |
---|
| 56 | |
---|
| 57 | parser.add_option( '--y_size', type = 'int', dest = 'y_size', |
---|
| 58 | default = 2, |
---|
| 59 | help = 'define number of clusters in a column' ) |
---|
| 60 | |
---|
| 61 | parser.add_option( '--nb_cores', type = 'int', dest = 'nb_cores', |
---|
| 62 | default = 2, |
---|
| 63 | help = 'define number of cores per cluster' ) |
---|
| 64 | |
---|
| 65 | parser.add_option( '--nb_ttys', type = 'int', dest = 'nb_ttys', |
---|
| 66 | default = 1, |
---|
| 67 | help = 'define number of TTY channels' ) |
---|
| 68 | |
---|
| 69 | parser.add_option( '--nb_nics', type = 'int', dest = 'nb_nics', |
---|
| 70 | default = 1, |
---|
| 71 | help = 'define number ot NIC channels' ) |
---|
| 72 | |
---|
| 73 | parser.add_option( '--fbf_size', type = 'int', dest = 'fbf_size', |
---|
| 74 | default = 128, |
---|
| 75 | help = 'define frame buffer width and heigth' ) |
---|
| 76 | |
---|
| 77 | parser.add_option( '--ioc_type', type = 'string', dest = 'ioc_type', |
---|
| 78 | default = 'IOC_BDV', |
---|
| 79 | help = 'define type of IOC: BDV / HBA / SDC / RDK / SPI' ) |
---|
| 80 | |
---|
| 81 | parser.add_option( '--hard', type = 'string', dest = 'hard_path', |
---|
| 82 | help = 'define pathname to directory for the hard_config.h file ' ) |
---|
| 83 | |
---|
| 84 | parser.add_option( '--xml', type = 'string', dest = 'xml_path', |
---|
| 85 | help = 'define pathname to directory for the arch_info.xml file' ) |
---|
| 86 | |
---|
| 87 | parser.add_option( '--v', action = 'store_true', dest = 'verbose', |
---|
| 88 | default = False, |
---|
| 89 | help = 'display detailed report on arch_info.bin generation' ) |
---|
| 90 | |
---|
| 91 | ################################################################################### |
---|
| 92 | # Get command line arguments |
---|
| 93 | ################################################################################### |
---|
| 94 | |
---|
| 95 | (options,args) = parser.parse_args() |
---|
| 96 | |
---|
| 97 | arch_path = options.arch_path # path to arch_info.py file |
---|
| 98 | bin_path = options.bin_path # path for arch_info.bin file |
---|
| 99 | |
---|
| 100 | x_size = options.x_size # number of clusters in a row |
---|
| 101 | y_size = options.y_size # number of clusters in a column |
---|
| 102 | nb_cores = options.nb_cores # number of cores in a cluster |
---|
| 103 | nb_ttys = options.nb_ttys # number of TTY channels |
---|
| 104 | fbf_size = options.fbf_size # frame buffer width & heigth |
---|
| 105 | nb_nics = options.nb_nics # number of NIC channels |
---|
| 106 | ioc_type = options.ioc_type # ioc controller type |
---|
| 107 | |
---|
| 108 | hard_path = options.hard_path # path for hard_config.h file |
---|
| 109 | xml_path = options.xml_path # path for arch_info.xml file |
---|
| 110 | |
---|
| 111 | verbose = options.verbose # report on arch_info.bin generation |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | ################################################################################### |
---|
| 115 | # Build the archinfo structure for the selected arch_info.py |
---|
| 116 | ################################################################################### |
---|
| 117 | |
---|
| 118 | if ( arch_path == None ): |
---|
| 119 | print 'You must define a path to the arch_info.py file on command line' |
---|
| 120 | sys.exit(1) |
---|
| 121 | |
---|
| 122 | # dynamically append arch_path to PYTHONPATH |
---|
| 123 | sys.path.append( arch_path ) |
---|
| 124 | |
---|
| 125 | # import the arch_info.py module (using file name without suffix) |
---|
| 126 | select = __import__( 'arch_info' ) |
---|
| 127 | print select |
---|
| 128 | |
---|
| 129 | # build the arch_info structure by calling the arch function |
---|
| 130 | archinfo = select.arch( x_size, |
---|
| 131 | y_size, |
---|
| 132 | nb_cores, |
---|
| 133 | nb_ttys, |
---|
| 134 | nb_nics, |
---|
| 135 | fbf_size, |
---|
[279] | 136 | ioc_type ) |
---|
[1] | 137 | |
---|
| 138 | print '[genarch] archinfo build for %s' % archinfo.name |
---|
| 139 | |
---|
| 140 | ################################################################################### |
---|
| 141 | # Generate arch_info.xml file if required. |
---|
| 142 | ################################################################################### |
---|
| 143 | |
---|
| 144 | if ( xml_path != None ): |
---|
| 145 | pathname = xml_path + '/arch_info.xml' |
---|
| 146 | f = open ( pathname, 'w' ) |
---|
| 147 | f.write( archinfo.xml() ) |
---|
| 148 | |
---|
| 149 | print '[genarch] %s generated' % pathname |
---|
| 150 | |
---|
| 151 | ################################################################################### |
---|
| 152 | # Generate arch_info.bin file if required. |
---|
| 153 | ################################################################################### |
---|
| 154 | |
---|
| 155 | if ( bin_path != None ): |
---|
| 156 | pathname = bin_path + '/arch_info.bin' |
---|
| 157 | f = open ( pathname, 'wb' ) |
---|
| 158 | f.write( archinfo.cbin( verbose ) ) |
---|
| 159 | print '[genarch] %s generated' % pathname |
---|
| 160 | |
---|
| 161 | ################################################################################### |
---|
| 162 | # Generate hard_config.h file if required. |
---|
| 163 | ################################################################################### |
---|
| 164 | |
---|
| 165 | if ( hard_path != None ): |
---|
| 166 | |
---|
| 167 | pathname = hard_path + '/hard_config.h' |
---|
| 168 | f = open ( pathname, 'w' ) |
---|
| 169 | f.write( archinfo.hard_config() ) |
---|
| 170 | print '[genarch] %s generated' % pathname |
---|
| 171 | |
---|