OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [configure.py] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#! /usr/bin/env python2.6
2
# -*- mode: python; coding: utf-8; -*-
3
import os, sys, shelve, shutil
4
from os.path import join
5
from config.projpaths import *
6
from config.configuration import *
7
from scripts.baremetal.baremetal_generator import *
8
from scripts.kernel.generate_kernel_cinfo import *
9
from scripts.cml.generate_container_cml import *
10
from optparse import OptionParser
11
 
12
#
13
# Rarely required. Only required when:
14
# The number of containers defined in the ruleset are not enough.
15
# E.g. you want 16 containers instead of 4.
16
# You want to start from scratch and set _all_ the parameters yourself.
17
#
18
def autogen_rules_file(options, args):
19
    # Prepare default if arch not supplied
20
    if not options.arch:
21
        print "No arch supplied (-a), using `arm' as default."
22
        options.arch = "arm"
23
 
24
    # Prepare default if number of containers not supplied
25
    if not options.ncont:
26
        options.ncont = 4
27
        print "Max container count not supplied (-n), using %d as default." % options.ncont
28
 
29
    return generate_container_cml(options.arch, options.ncont)
30
 
31
 
32
def cml2_header_to_symbols(cml2_header, config):
33
    with file(cml2_header) as header_file:
34
        for line in header_file:
35
            pair = config.line_to_name_value(line)
36
            if pair is not None:
37
                name, value = pair
38
                config.get_all(name, value)
39
                config.get_cpu(name, value)
40
                config.get_arch(name, value)
41
                config.get_subarch(name, value)
42
                config.get_platform(name, value)
43
                config.get_ncpu(name, value)
44
                config.get_ncontainers(name, value)
45
                config.get_container_parameters(name, value)
46
                config.get_toolchain(name, value)
47
 
48
def cml2_update_config_h(config_h_path, config):
49
    with open(config_h_path, "a") as config_h:
50
        config_h.write("#define __ARCH__ " + config.arch + '\n')
51
        config_h.write("#define __PLATFORM__ " + config.platform + '\n')
52
        config_h.write("#define __SUBARCH__ " + config.subarch + '\n')
53
        config_h.write("#define __CPU__ " + config.cpu + '\n')
54
 
55
def configure_kernel(cml_file):
56
    config = configuration()
57
 
58
    if not os.path.exists(BUILDDIR):
59
        os.mkdir(BUILDDIR)
60
 
61
    cml2_configure(cml_file)
62
 
63
 
64
 
65
# Parse options + autogenerate cml rule file if necessary.
66
def build_parse_options():
67
    autogen_true = 0
68
    usage = "usage: %prog [options] arg"
69
    parser = OptionParser(usage)
70
 
71
    parser.add_option("-a", "--arch", type = "string", dest = "arch",
72
                      help = "Use configuration file for architecture")
73
    parser.add_option("-n", "--num-containers", type = "int", dest = "ncont",
74
                      help = "Maximum number of containers that will be "
75
                             "made available in configuration")
76
    parser.add_option("-c", "--configure-first", action = "store_true", dest = "config",
77
                      help = "Tells the build script to run configurator first")
78
    parser.add_option("-f", "--use-file", dest = "cml_file",
79
                      help = "Supply user-defined cml file "
80
                             "(Use only if you want to override default)")
81
    parser.add_option("-r", "--reset-config", action = "store_true",
82
                      default = False, dest = "reset_config",
83
                      help = "Reset configuration file settings "
84
                             "(If you had configured before and changing the "
85
                             "rule file, this will reset existing values to default)")
86
    parser.add_option("-s", "--save-old-config", action = "store_true",
87
                      default = False, dest = "backup_config",
88
                      help = "Backs up old configuration file settings to a .saved file"
89
                             "(Subsequent calls would overwrite. Only meaningful with -r)")
90
    parser.add_option("-p", "--print-config", action = "store_true",
91
                      default = False, dest = "print_config",
92
                      help = "Prints out configuration settings"
93
                             "(Symbol values and container parameters are printed)")
94
    parser.add_option("-q", "--quite", action="store_true", dest="quite", default = False,
95
                      help = "Enable quite mode"
96
                             "(will not be presented with a configuration screen)")
97
 
98
 
99
    (options, args) = parser.parse_args()
100
 
101
    if options.cml_file and options.reset_config:
102
        parser.error("options -f and -r are mutually exclusive")
103
        exit()
104
 
105
    # -f or -r or -n or -a implies -c
106
    if options.cml_file or options.ncont or options.arch or options.reset_config \
107
       or not os.path.exists(BUILDDIR) or not os.path.exists(CONFIG_SHELVE_DIR):
108
        options.config = 1
109
 
110
    return options, args
111
 
112
 
113
def configure_system(options, args):
114
    #
115
    # Configure only if we are told to do so.
116
    #
117
    if not options.config:
118
        return
119
 
120
    if not os.path.exists(BUILDDIR):
121
        os.mkdir(BUILDDIR)
122
 
123
    #
124
    # If we have an existing config file or one supplied in options
125
    # and we're not forced to autogenerate, we use the config file.
126
    #
127
    # Otherwise we autogenerate a ruleset and compile it, and create
128
    # a configuration file from it from scratch.
129
    #
130
    if (options.cml_file or os.path.exists(CML2_CONFIG_FILE)) \
131
            and not options.reset_config:
132
        if options.cml_file:
133
            cml2_config_file = options.cml_file
134
        else:
135
            cml2_config_file = CML2_CONFIG_FILE
136
 
137
        #
138
        # If we have a valid config file but not a rules file,
139
        # we still need to autogenerate the rules file.
140
        #
141
        if not os.path.exists(CML2_COMPILED_RULES):
142
            rules_file = autogen_rules_file(options, args)
143
 
144
            # Compile rules file.
145
            os.system(CML2TOOLSDIR + '/cmlcompile.py -o ' + \
146
                      CML2_COMPILED_RULES + ' ' + rules_file)
147
 
148
        #
149
        # If there was an existing config file in default cml path
150
        # and -s was supplied, save it.
151
        #
152
        if os.path.exists(CML2_CONFIG_FILE) and options.backup_config:
153
            shutil.copy(CML2_CONFIG_FILE, CML2_CONFIG_FILE_SAVED)
154
 
155
        if options.quite:
156
                # Create configuration from existing file
157
                os.system(CML2TOOLSDIR + '/cmlconfigure.py -b -o ' + \
158
                        CML2_CONFIG_FILE + ' -i ' + cml2_config_file + \
159
                        ' ' + CML2_COMPILED_RULES)
160
        else:
161
                # Create configuration from existing file
162
                os.system(CML2TOOLSDIR + '/cmlconfigure.py -c -o ' + \
163
                        CML2_CONFIG_FILE + ' -i ' + cml2_config_file + \
164
                        ' ' + CML2_COMPILED_RULES)
165
 
166
    else:
167
        rules_file = autogen_rules_file(options, args)
168
 
169
        # Compile rules file.
170
        os.system(CML2TOOLSDIR + '/cmlcompile.py -o ' + \
171
                  CML2_COMPILED_RULES + ' ' + rules_file)
172
 
173
        # Create configuration from scratch
174
        os.system(CML2TOOLSDIR + '/cmlconfigure.py -c -o ' + \
175
                  CML2_CONFIG_FILE + ' ' + CML2_COMPILED_RULES)
176
 
177
    # After configure, if user might have chosen to quit without saving
178
    if not os.path.exists(CML2_CONFIG_FILE):
179
        print "Exiting without saving configuration."
180
        sys.exit()
181
 
182
    # Create header file
183
    os.system(TOOLSDIR + '/cml2header.py -o ' + \
184
              CML2_CONFIG_H + ' -i ' + CML2_CONFIG_FILE)
185
 
186
    # The rest:
187
    if not os.path.exists(os.path.dirname(CONFIG_H)):
188
        os.mkdir(os.path.dirname(CONFIG_H))
189
 
190
    shutil.copy(CML2_CONFIG_H, CONFIG_H)
191
 
192
    config = configuration()
193
    cml2_header_to_symbols(CML2_CONFIG_H, config)
194
    cml2_update_config_h(CONFIG_H, config)
195
 
196
    configuration_save(config)
197
 
198
    # Generate baremetal container files if new ones defined
199
    baremetal_cont_gen = BaremetalContGenerator()
200
    baremetal_cont_gen.baremetal_container_generate(config)
201
 
202
   # Print out the configuration if asked
203
    if options.print_config:
204
        config.config_print()
205
 
206
    return config
207
 
208
# Generate kernel cinfo structure for container definitions
209
def generate_cinfo():
210
    config = configuration_retrieve()
211
    generate_kernel_cinfo(config, KERNEL_CINFO_PATH)
212
 
213
if __name__ == "__main__":
214
    opts, args = build_parse_options()
215
 
216
    # We force configuration when calling this script
217
    # whereas build.py can provide it as an option
218
    opts.config = 1
219
 
220
    configure_system(opts, args)

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.