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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [tools/] [cml2-tools/] [autoconfigure.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
#!/usr/bin/env python
2
#
3
#  linux/scripts/autoconfigure.py : Automagical Kernel Configuration.
4
#
5
#  Copyright (C) 2000-2002  Eric S. Raymond <esr@thyrsus.com>
6
#  This is free software, see GNU General Public License 2 for details.
7
#
8
# This script tries to autoconfigure the Linux kernel, detecting the
9
# hardware (devices, ...) and software (protocols, filesystems, ...).
10
# It uses soft detection: no direct IO access to unknown devices, thus
11
# it is always safe to run this script and it never hangs, but it cannot
12
# detect all hardware (mainly misses some very old hardware).  You don't
13
# need root, but you will need a CML2 rulebase handy.
14
#
15
# Most of the smarts in this script is in the file of probe rules
16
# maintained by Giacomo Catenazzi and brought in by execfile.
17
 
18
import sys, getopt, os, glob, commands, re
19
import cml, cmlsystem
20
from cml import y, m, n # For use in the autoprobe rules
21
 
22
lang = {
23
    "COMPLETE":"Configuration complete.",
24
    "COMPLEMENT":"* Computing complement sets",
25
    "DERIVED":"Symbol %s is derived and cannot be set.",
26
    "DONE":"Done",
27
    "EFFECTS":"Side effects:",
28
    "NOCMDLINE":"%s is the wrong type to be set from the command line",
29
    "OPTUNKNOWN":"autoconfigure: unknown option.\n",
30
    "ROOTFS":"* %s will be hard-compiled in for the root filesystem\n",
31
    "ROOTHW":"* %s will be hard-compiled in to run the root device\n",
32
    "ROOTLOOK":"# Looking for your root filesystem...\n",
33
    "ROOTWARN":"** Warning: I could not identify the " \
34
                        "bus type of your root drive!\n",
35
    "SETFAIL" : "%s failed while %s was being set to %s\n",
36
    "SYMUNKNOWN":"cmlconfigure: unknown symbol %s\n",
37
    "TURNOFF":"# Turning off unprobed device symbols",
38
    "UNAME":"Can't determine ARCH, uname failed.",
39
    }
40
 
41
class ConfigFile:
42
    "Object that represents a generated configuration."
43
    def __init__(self, myconfiguration, hardcompile, debuglevel=0):
44
        # Prepare an output object to accept the configuration file
45
        self.hardcompile = hardcompile
46
        self.myconfiguration = myconfiguration
47
        myconfiguration.debug = debuglevel
48
        self.modified = {}
49
        self.emitted = {}
50
        if debuglevel:
51
            sys.stderr.write("* Debug level %d" % debuglevel)
52
 
53
    # 'found'     sets the value 'y/m' (driver detected)
54
    # 'found_y'   sets the value 'y' (driver detected, forces built-in)
55
    # 'found_m'   sets the value 'm' (driver detected, build as module)
56
    # 'found_n'   sets the value 'n' (driver not needed)
57
    #
58
    #  The priority is: y > m > n > 'other'
59
    def found(self, symbol, val=None, label=None):
60
        if type(symbol) == type(""):
61
            symbol = self.myconfiguration.dictionary.get(symbol)
62
        # Ignore obsolete symbols
63
        if not symbol:
64
            return
65
        # Ignore attempts to set derived symbols.  Some autoprobes
66
        # do this because they were composed in ignorance of the rulebase.
67
        elif symbol.is_derived():
68
            return
69
        # If no value specified, play some tricks.
70
        if val == None:
71
            if symbol.type=="bool" or (self.hardcompile and symbol.type=="trit"):
72
                val = cml.y
73
            elif symbol.type == "trit":
74
                val = cml.m
75
            elif symbol.is_numeric():
76
                val = 0
77
            elif symbol.type == "string":
78
                val = ""
79
        if not self.modified.has_key(symbol) or symbol.eval() < val:
80
            self.myconfiguration.set_symbol(symbol, val)
81
            self.modified[symbol] = 1
82
            (ok, effects, violations) = self.myconfiguration.set_symbol(symbol, val)
83
            if ok:
84
                if label:
85
                    symbol.setprop(label)
86
            else:
87
                for violation in violations:
88
                    sys.stderr.write(lang["SETFAIL"] % (`violation`, symbol.name, val))
89
 
90
    def found_y(self, var, label=None): self.found(var, cml.y, label)
91
    def found_m(self, var, label=None): self.found(var, cml.m, label)
92
    def found_n(self, var, label=None): self.found(var, cml.n, label)
93
 
94
    def yak(self, symbol):
95
        if not self.emitted.has_key(symbol):
96
            try:
97
                entry = self.myconfiguration.dictionary[symbol]
98
                if entry.prompt:
99
                    sys.stderr.write("* " + symbol + ": " + entry.prompt + "\n")
100
                    self.emitted[symbol] = 1
101
            except KeyError:
102
                sys.stderr.write("! Obsolete symbol: " + symbol + "\n")
103
 
104
    def complement(self, symbol, value, baton, label):
105
        "Force a complement set to a specified value."
106
        symbol = self.myconfiguration.dictionary[symbol]
107
        if not symbol.eval():
108
            return
109
        for driver in self.myconfiguration.dictionary.values():
110
            if baton: baton.twirl()
111
            if driver.is_symbol() and driver.is_logical() \
112
                    and self.myconfiguration.is_visible(driver) \
113
                    and driver.setcount == 0 \
114
                    and symbol.ancestor_of(driver):
115
                set_to = value
116
                if driver.type == "bool" and value == cml.m:
117
                    set_to = cml.y
118
                self.found(driver.name, set_to, label)
119
 
120
    def force_dependents_modular(self, symbol, legend):
121
        "Force all trit-valued dependents of a symbol to be modular."
122
        net_ethernet = self.myconfiguration.dictionary[symbol]
123
        for driver in self.myconfiguration.dictionary.values():
124
            if driver.is_symbol() and driver.type == "trit" \
125
                        and driver.eval() == cml.y \
126
                        and self.myconfiguration.is_visible(driver) \
127
                        and net_ethernet.ancestor_of(driver):
128
                driver.setprop(legend)
129
                self.found(driver, cml.m)
130
 
131
    def enabled(self, symbol):
132
        "Is a given symbol enabled?"
133
        return self.myconfiguration.dictionary[symbol]
134
 
135
# Now define classes for probing and reporting the system state
136
 
137
class PCIDevice:
138
    "Identification data for a device on the PCI bus."
139
    def __init__(self, procdata):
140
        "Initialize PCI device ID data based on what's in a /proc entry."
141
        procdata = map(ord, procdata)
142
        self.vendor = "%02x%02x" % (procdata[1], procdata[0])
143
        self.device = "%02x%02x" % (procdata[3], procdata[2])
144
        if procdata[14]:
145
            self.subvendor = None
146
            self.subdevice = None
147
        else:
148
            self.subvendor = "%02x%02x" % (procdata[45], procdata[44])
149
            self.subdevice = "%02x%02x" % (procdata[47], procdata[46])
150
        self.revision = "%02x" % procdata[8]
151
        self.deviceclass = "%02x%02x" % (procdata[11], procdata[10])
152
        self.interface = "%02x" % procdata[9]
153
        # Here is the digest format:
154
        #    "pci: xxxx,yyyy,zz:Class:aabb,cc"  or
155
        #    "pci: xxxx,yyyy,ssss,rrrr,zz:Class:aabbb,cc"
156
        #   where: xxxx,yyyy: the vendor and device id
157
        #         ssss,rrrr: the sub-vendor and sub-device id
158
        #         zz: revision
159
        #         aabb,cc: Device Class, Interface
160
        self.digest = self.vendor + "," + self.device
161
        if self.subvendor:
162
            self.digest += "," + self.subvendor + "," + self.subdevice
163
        self.digest += ",%s;Class:%s,%s\n" % (self.revision,self.deviceclass,self.interface)
164
    def __repr__(self):
165
        return "pci: " + self.digest
166
 
167
class PCIScanner:
168
    "Encapsulate the PCI hardware registry state."
169
    def __init__(self):
170
        "Unpack data from the PCI hardware registry."
171
        self.devices = []
172
        for f in glob.glob("/proc/bus/pci/??/*"):
173
            dfp = open(f)
174
            self.devices.append(PCIDevice(dfp.read()))
175
            dfp.close()
176
    def search(self, pattern):
177
        "Search for a device match by prefix in the digest."
178
        pattern = re.compile(pattern, re.I)
179
        return not not filter(lambda x, p=pattern: p.search(x.digest), self.devices)
180
    def __repr__(self):
181
        return "".join(map(repr, self.devices))
182
 
183
class FieldParser:
184
    "Parse entire lines, or a given field, out of a file or command output."
185
    def __init__(self, sources):
186
        self.items = []
187
        for item in sources:
188
            if type(item) == type(()):
189
                file = item[0]
190
                field = item[1]
191
            else:
192
                file = item
193
                field = None
194
            try:
195
                if file[0] == '/':
196
                    ifp = open(file, "r")
197
                    lines = ifp.readlines()
198
                    ifp.close()
199
                else:
200
                    (status, output) = commands.getstatusoutput(file)
201
                    if status:
202
                        raise IOError
203
                    lines = output.split("\n")
204
            except IOError:
205
                continue
206
            # No field specified, capture entire line
207
            if not field:
208
                self.items += lines
209
            # Numeric (1-origin) field index, capture that
210
            # space-separated field.
211
            elif type(field) == type(0):
212
                for line in lines:
213
                    fields = line.split()
214
                    if len(fields) >= field and fields[field-1] not in self.items:
215
                        self.items.append(fields[field-1])
216
            # Regexp specified, collect group 1
217
            else:
218
                for line in lines:
219
                    lookfor = re.compile(field)
220
                    match = lookfor.search(line)
221
                    if match:
222
                        res = match.group(1)
223
                        if res not in self.items:
224
                            self.items.append(res)
225
    def find(self, str, ind=0):
226
        "Is given string or regexp pattern found in the file?"
227
        match = re.compile(str)
228
        result = filter(lambda x: x, map(lambda x, ma=match: ma.search(x), self.items))
229
        if result:
230
            result = result[ind]
231
            if result.groups():
232
                result = ",".join(result.groups())
233
        return result
234
    def __repr__(self):
235
        return `self.items`
236
 
237
#
238
# Main sequence begins here
239
#
240
 
241
def get_arch():
242
    # Get the architecture (taken from top-level Unix makefile).
243
    (error, ARCH) = commands.getstatusoutput('uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/')
244
    if error:
245
        sys.stderr.write(lang["UNAME"])
246
        raise SystemExit, 1
247
    # A platform symbol has to be set, otherwise many assignments will fail
248
    ARCHSYMBOL = re.compile("i.86").sub("x86", ARCH)
249
    ARCHSYMBOL = ARCHSYMBOL.replace("superh", "sh")
250
    ARCHSYMBOL = ARCHSYMBOL.replace("sparc32", "sparc")
251
    ARCHSYMBOL = ARCHSYMBOL.replace("sparc64", "sparc")
252
    ARCHSYMBOL = ARCHSYMBOL.upper()
253
    return(ARCH, ARCHSYMBOL)
254
 
255
# We can't assume 2.1 nested scopes, so refer shared stuff to global level.
256
config = cpu = cpu_id = pci = isapnp = mca = usbp = usbc = usbi = None
257
fs = devices = m_devices = misc = net = ide = dmesg = None
258
modules = cpu_latch = None
259
fsmap = {}
260
reliable = {}
261
 
262
def autoconfigure(configuration, hardcompile, debuglevel):
263
    global config, cpu, cpu_id, pci, isapnp, mca, usbp, usbc, usbi, fs
264
    global devices, m_devices, misc, net, ide, dmesg, modules, cpu_latch
265
    global fsmap, reliable
266
    configuration.interactive = 0        # Don't deduce from visibility.
267
 
268
    config = ConfigFile(configuration, hardcompile, debuglevel)
269
 
270
    #
271
    # Here is where we query the system state.
272
    #
273
    (ARCH, ARCHSYMBOL) = get_arch()
274
    config.found_y(ARCHSYMBOL)
275
    config.yak(ARCHSYMBOL)
276
 
277
    # Get the processor type
278
    cpu     = FieldParser(("/proc/cpuinfo",))
279
    if ARCHSYMBOL == 'SPARC':
280
      processors = int(cpu.find("^ncpus active.*: *([0-9]*)"))
281
      vendor     = cpu.find("^cpu.*: *(.*)")
282
      cpufam     = cpu.find("^type.*: *([-A-Za-z0-9_]*)")
283
      mod        = cpu.find("^fpu.*: *(.*)")
284
      name       = cpu.find("^MMU Type.*: *(.*)")
285
    else:
286
      processors = int(cpu.find("^processor.*: *([0-9]*)", -1)) + 1
287
      vendor  = cpu.find("^vendor_id.*: *([-A-Za-z0-9_]*)")
288
      cpufam  = cpu.find("^cpu family.*: *([-A-Za-z0-9_]*)")
289
      mod     = cpu.find("^model.*: *([-A-Za-z0-9_]*)")
290
      name    = cpu.find("^model name.*: *(.*)")
291
 
292
    cpu_id = vendor + ":" + cpufam + ":" + mod + ":" + name
293
    cpu_latch = 0
294
 
295
    # Now query for features
296
    pci     = PCIScanner()
297
    isapnp  = FieldParser((("/proc/bus/isapnp/devices", 2),))
298
    mca     = FieldParser(("/proc/mca/pos",))
299
    usbp    = FieldParser((("/proc/bus/usb/devices", "^P:.*Vendor=([A-Fa-f0-9]*)\s.*ProdID=\([A-Fa-f0-9]*\)"),))
300
    usbc    = FieldParser((("/proc/bus/usb/devices", "^D:.*Cls=([A-Fa-f0-9]*)[^A-Fa-f0-9].*Sub=([A-Fa-f0-9]*)[^A-Fa-f0-9].*Prot=([A-Fa-f0-9]*)"),))
301
    usbi    = FieldParser((("/proc/bus/usb/devices", "^I:.*Cls=([A-Fa-f0-9]*)[^A-Fa-f0-9].*Sub=([A-Fa-f0-9]*)[^A-Fa-f0-9].*Prot=([A-Fa-f0-9]*)"),))
302
    fs      = FieldParser((("/proc/mounts",3),
303
                           ("/etc/mtab", 3),
304
                           ("/etc/fstab", 3)))
305
    devices = FieldParser((("/proc/devices", "[0-9]+ (.*)"),))
306
    m_devices = FieldParser((("/proc/misc", "[0-9]+ (.*)"),))
307
    misc    = FieldParser(("/proc/iomem", "/proc/ioports", "/proc/dma", "/proc/interrupts"))
308
    net     = FieldParser((("/proc/net/sockstat","^([A-Z0-9]*): inuse [1-9]"),))
309
    ide     = FieldParser(glob.glob('/proc/ide/hd?/media'))
310
    dmesg   = FieldParser(("/var/log/dmesg", "dmesg"))
311
    modules = FieldParser((("/proc/modules", 1),))
312
 
313
    #
314
    # Tests that won't fit in the rulesfile format
315
    #
316
 
317
    # Source: linux/i386/kernel/setup.c
318
    if dmesg.find("Use a PAE"):
319
        config.found_y("HIGHMEM64G")
320
    elif dmesg.find("Use a HIGHMEM"):
321
        config.found_y("HIGHMEM4G")     ##Source: linux/i386/kernel/setup.c
322
    else:
323
        highmem = dmesg.find("([0-9]*)MB HIGHMEM avail.")
324
        if not highmem:
325
            config.found_y("NOHIGHMEM")
326
        elif int(highmem) > 3072:
327
            config.found_y("HIGHMEM64G")
328
        else:
329
            config.found_y("HIGHMEM4G")
330
 
331
    # SMP?  This test is reliable.
332
    if processors == 0:
333
      processors = len(filter(lambda x: x.find('processor') > -1, cpu.items))
334
 
335
    if processors > 1:
336
        config.found_y("SMP")
337
        config.yak("SMP")
338
 
339
    fsmap = {}
340
    reliable = {}
341
 
342
    #
343
    # Here are the function calls used by the rules file
344
    #
345
    TRUE = 1
346
    FALSE = 0
347
    PRESENT = 1
348
    ABSENT = 0
349
 
350
    def DEBUG(str):
351
        sys.stderr.write("# " + str + "\n")
352
 
353
    # Following three tests are reliable -- that is, if PCI or PNP
354
    # tests fail we know the feature is *not* there.
355
 
356
    def PCI(prefix, symbol):
357
        global pci, config
358
        reliable[symbol] = "PCI"
359
        if pci.search("^" + prefix):
360
            config.yak(symbol)
361
            config.found(symbol, None, "PCI")
362
 
363
 
364
    def PCI_CLASS(match, symbol):
365
        global pci, config
366
        reliable[symbol] = "PCI_CLASS"
367
        if pci.search("Class:" + match):
368
            config.yak(symbol)
369
            config.found(symbol, None, "PCI_CLASS")
370
 
371
    def PNP(match, symbol):
372
        global isapnp, config
373
        reliable[symbol] = "PNP"
374
        if isapnp.find(match):
375
            config.yak(symbol)
376
            config.found(symbol, None, "PNP")
377
 
378
    def MCA(match, symbol):
379
        global mca, config
380
        reliable[symbol] = "MCA"
381
        # FIXME: Not certain I've got the byte order right here
382
        if mca.find(": " + match[2:] + " " + match[:2]):
383
            config.yak(symbol)
384
            config.found(symbol, None, "MCA")
385
 
386
    # USB tests reliably detect connected devices, but the bus is hot-plug.
387
 
388
    def USBP(match, symbol):
389
        global usbp, config
390
        if usbp.find(match):
391
            config.yak(symbol)
392
            config.found(symbol, None, "USBP")
393
 
394
    def USBC(match, symbol):
395
        global usbc, config
396
        if usbc.find(match):
397
            config.yak(symbol)
398
            config.found(symbol, None, "USBC")
399
 
400
    def USBI(match, symbol):
401
        global usbi, config
402
        if usbi.find(match):
403
            config.yak(symbol)
404
            config.found(symbol, None, "USBI")
405
 
406
    # Remaining tests rely on prior kernel configuration.
407
 
408
    def FS(match, symbol):
409
        global fs, fsmap, config
410
        if fs.find(r"\b" + match + r"\b"):
411
            config.yak(symbol)
412
            config.found(symbol, None, "FS")
413
        # Also, build the map of file system types to symbols.
414
        fsmap[match] = symbol
415
 
416
    def DEV(match, symbol):
417
        global devices, config
418
        if devices.find(r"\b" + match + r"\b"):
419
            config.yak(symbol)
420
            config.found(symbol, None, "DEV")
421
 
422
    def DEVM(match, symbol):
423
        global m_devices, config
424
        if m_devices.find(r"\b" + match + r"\b"):
425
            config.yak(symbol)
426
            config.found(symbol, None, "DEV_M")
427
 
428
    def CONS(match, symbol):
429
        global dmesg, config
430
        if dmesg.find("^Console: .* " + match + " "):
431
            config.yak(symbol)
432
            config.found(symbol, None, "CONS")
433
 
434
    def DMESG(match, symbol, truthval=TRUE):
435
        global dmesg, config
436
        if dmesg.find(match):
437
            if truthval:
438
                config.found(symbol, None, "DMESG")
439
                config.yak(symbol)
440
            else:
441
                config.found_n(symbol, "DMESG")
442
 
443
    def NET(match, symbol):
444
        global net, config
445
        if net.find(match):
446
            config.yak(symbol)
447
            config.found(symbol, None, "NET")
448
 
449
    def IDE(match, symbol):
450
        global ide, config
451
        if ide.find(match):
452
            config.yak(symbol)
453
            config.found(symbol, None, "IDE")
454
 
455
    def REQ(match, symbol):
456
        global misc, config
457
        if misc.find(match):
458
            config.yak(symbol)
459
            config.found(symbol, None, "REQ")
460
 
461
    def CPUTYPE(match, symbol):
462
        global cpu_latch, config
463
        if not cpu_latch and re.search(match, cpu_id):
464
            config.found_y(symbol, "CPUTYPE")
465
            config.yak(symbol)
466
            cpu_latch = 1
467
 
468
    def CPUINFO(match, symbol, present=PRESENT, truthval=cml.y):
469
        global cpu, config
470
        if (not not cpu.find(match)) == present:
471
            config.found(symbol, truthval, "CPUINFO")
472
            if truthval:
473
                config.yak(symbol)
474
 
475
    def EXISTS(procfile, symbol):
476
        global config
477
        if os.path.exists(procfile):
478
            config.found(symbol, None, "EXISTS")
479
            config.yak(symbol)
480
        else:
481
            config.found(symbol, n, "EXISTS")
482
 
483
    def MODULE(name, symbol):
484
        global modules, config
485
        if modules.find(r"\b" + name + r"\b"):
486
            config.found(symbol, None, "MODULES")
487
            config.yak(symbol)
488
 
489
    def GREP(pattern, file, symbol):
490
        global config
491
        try:
492
            fp = open(file)
493
        except IOError:
494
            return
495
        if re.compile(pattern).search(fp.read()):
496
            config.found(symbol, None, "GREP")
497
            config.yak(symbol)
498
        fp.close()
499
 
500
    def LINKTO(file, pattern, symbol):
501
        global config
502
        if not os.path.exists(file):
503
            return
504
        file = os.readlink(file)
505
        if re.compile(pattern).search(file):
506
            config.found(symbol, None, "LINKTO")
507
            config.yak(symbol)
508
 
509
    # Use this to avoid conflicts
510
 
511
    def PRIORITY(symbols, cnf=configuration):
512
        global config
513
        legend = "PRIORITY" + `symbols`
514
        dict = cnf.dictionary
515
        symbols = map(lambda x, d=dict: d[x], symbols)
516
        for i in range(len(symbols) - 1):
517
            if cml.evaluate(symbols[i]):
518
                for j in range(i+1, len(symbols)):
519
                    cnf.set_symbol(symbols[j], n)
520
                    symbols[j].setprop(legend)
521
                break
522
 
523
    ########################################################################
524
    ##
525
    ## Section            Command         Version        Status
526
    ## ------------------------------------------------------------------
527
    ##  /proc features     EXISTS          2.5.2-pre7     Partial 
528
 
529
    ########################################################################
530
    ## Section: System Features
531
    ## KernelOutput: /proc/*, /dev/*
532
    ## Detect system features based on existence of /proc and /dev/* files 
533
    DEBUG("autoconfigure.rules: EXISTS")
534
 
535
    ## These tests are unreliable; they depend on the current kernel config.
536
    EXISTS("/proc/sysvipc",             'SYSVIPC')
537
    EXISTS("/proc/sys",                 'SYSCTL')
538
    EXISTS("/proc/scsi/ide-scsi",       'BLK_DEV_IDESCSI')
539
    EXISTS("/proc/scsi/imm",            'SCSI_IMM')
540
    EXISTS("/proc/scsi/ppa",            'SCSI_PPA')
541
    EXISTS("/dev/.devfsd",              'DEVFS_FS')
542
    # Giacomo does not have these yet.
543
    EXISTS("/proc/sys/net/khttpd",      'KHTTPD')
544
    EXISTS("/proc/sys/kernel/acct",     'BSD_PROCESS_ACCT')
545
    # This one is reliable, according to the MCA port documentation.
546
    EXISTS("/proc/mca",                 'MCA')
547
    # This one is reliable too
548
    EXISTS("/proc/bus/isapnp/devices",  'ISAPNP')
549
 
550
    # Test the new probe function.
551
    GREP("scsi0", "/proc/scsi/scsi",    'SCSI')
552
 
553
    # These can be bogus because the file or directory in question
554
    # is empty, or consists of a banner string that does not describe
555
    # an actual device.  We need to do more analysis here.
556
    # EXISTS("/proc/bus/pci",           'PCI')
557
    # EXISTS("/proc/bus/usb",           'USB')
558
    # EXISTS("/proc/net",               'NET')
559
    # EXISTS("/proc/scsi",              'SCSI')         
560
 
561
    # These look tempting, but they're no good unless we're on a pure
562
    # devfs system, without support for old devices, where devices
563
    # only exist when they're needed.
564
    # EXISTS("/dev/agpgart",            'AGP')
565
    # EXISTS("/dev/floppy",             'BLK_DEV_FD')
566
    # EXISTS("/dev/fd0",                'BLK_DEV_FD')
567
 
568
 
569
    ########################################################################
570
    ## Section: Mice
571
    ## Detect the mouse type by looking at what's behind the /dev/mouse link.
572
    ## These are probes for 2.4 with the old input core
573
    LINKTO("/dev/mouse", "psaux",       'PSMOUSE')
574
    LINKTO("/dev/mouse", "ttyS",        'SERIAL')
575
    LINKTO("/dev/mouse", "logibm",      'LOGIBUSMOUSE')
576
    LINKTO("/dev/mouse", "inportbm",    'MS_BUSMOUSE')
577
    LINKTO("/dev/mouse", "atibm",       'ATIXL_BUSMOUSE')
578
    ## These are probes for 2.5 with the new input core
579
    LINKTO("/dev/mouse", "psaux",       'MOUSE_PS2')
580
    LINKTO("/dev/mouse", "ttyS",        'MOUSE_SERIAL')
581
    LINKTO("/dev/mouse", "logibm",      'MOUSE_LOGIBM')
582
    LINKTO("/dev/mouse", "inportbm",    'MOUSE_INPORT')
583
    LINKTO("/dev/mouse", "atibm",       'MOUSE_ATIXL')
584
 
585
    ########################################################################
586
    ## Section: IDE devices
587
    ## KernelOutput: /proc/ide/hd?/media
588
    ## Detect IDE devices based on contents of /proc files
589
    ## These tests are unreliable; they depend on the current kernel config.
590
    IDE('disk', 'BLK_DEV_IDEDISK')
591
    IDE('cdrom', 'BLK_DEV_IDECD')
592
    IDE('tape', 'BLK_DEV_IDETAPE')
593
    IDE('floppy', 'BLK_DEV_FLOPPY')
594
    EXISTS("/dev/ide/ide0",             'BLK_DEV_IDE')
595
    EXISTS("/dev/ide/ide1",             'BLK_DEV_IDE')
596
    EXISTS('/proc/ide/piix',            'PIIX_TUNING')
597
 
598
    ########################################################################
599
    # Miscellaneous tests that replace Giacomo's ad-hoc ones.
600
    DEV('pty', 'UNIX98_PTYS')
601
    REQ('SMBus', 'I2C')
602
    REQ('ATI.*Mach64', 'FB_ATY')
603
    #FS(r'xfs', 'XFS_FS')
604
 
605
    ########################################################################
606
    # This is a near complete set of MCA probes for hardware supported under
607
    # Linux, according to MCA maintainer David Weinehall.  The exception is
608
    # the IBMTR card, which cannot be probed reliably.
609
    if config.enabled("MCA"):
610
        MCA("ddff", 'BLK_DEV_PS2')
611
        MCA("df9f", 'BLK_DEV_PS2')
612
        MCA("628b", 'EEXPRESS')
613
        MCA("627[cd]", 'EL3')
614
        MCA("62db", 'EL3')
615
        MCA("62f6", 'EL3')
616
        MCA("62f7", 'EL3')
617
        MCA("6042", 'ELMC')
618
        MCA("0041", 'ELMC_II')
619
        MCA("8ef5", 'ELMC_II')
620
        MCA("61c[89]", 'ULTRAMCA')
621
        MCA("6fc[012]", 'ULTRAMCA')
622
        MCA("efd[45]", 'ULTRAMCA')
623
        MCA("efe5", 'ULTRAMCA')
624
        MCA("641[036]", 'AT1700')
625
        MCA("6def", 'DEPCA')
626
        MCA("6afd", 'SKMC')
627
        MCA("6be9", 'SKMC')
628
        MCA("6354", 'NE2_MCA')
629
        MCA("7154", 'NE2_MCA')
630
        MCA("56ea", 'NE2_MCA')
631
        MCA("ffe0", 'IBMLANA')
632
        MCA("8ef[8cdef]", 'SCSI_IBMMCA')
633
        MCA("5137", 'SCSI_FD_MCS')
634
        MCA("60e9", 'SCSI_FD_MCS')
635
        MCA("6127", 'SCSI_FD_MCS')
636
        MCA("0092", 'SCSI_NCR_D700')
637
        MCA("7f4c", 'SCSI_MCA_53C9X')
638
        MCA("0f1f", 'SCSI_AHA_1542')
639
        MCA("002d", 'MADGEMC')
640
        MCA("6ec6", 'SMCTR')
641
        MCA("62f3", 'SOUND_SB')
642
        MCA("7113", 'SOUND_SB')
643
 
644
    ########################################################################
645
    ## This requires Paul Gortmaker's EISA ID patch.
646
    REQ("EISA", "EISA") # Someday, IOPORTS()
647
 
648
    ########################################################################
649
    ## The rest of the table is read in from Giacomo's Catenazzi's rulesfile.
650
    execfile(rulesfile)
651
 
652
    # If it has a reliable test, but was not found by any test, switch it off.
653
    # We do things in this order to avoid losing on symbols that are only set
654
    # to n by PNP and PCI tests.
655
    baton = cml.Baton(lang["TURNOFF"])
656
    for symbol in configuration.dictionary.values():
657
        baton.twirl()
658
        if symbol.is_symbol() and configuration.saveable(symbol) \
659
           and reliable.has_key(symbol.name) and not cml.evaluate(symbol):
660
            config.found(symbol.name, n, reliable[symbol.name])
661
    baton.end()
662
 
663
    ########################################################################
664
    ## Resolve conflicts.
665
 
666
    PRIORITY(("SCSI_SYM53C8XX_2", "SCSI_SYM53C8XX", \
667
                                 "SCSI_NCR53C8XX", "SCSI_GENERIC_NCR5380"))
668
    PRIORITY(("DE2104X", "TULIP"))
669
 
670
    ## End of probe logic.
671
    ##
672
    ########################################################################
673
 
674
    # More tests that don't fit the rulesfile format
675
 
676
    # Filesystem, bus, and controller for root cannot be modules.
677
    sys.stderr.write(lang["ROOTLOOK"])
678
    fstab_to_bus_map = {
679
        r"^/dev/sd" : ("SCSI",),
680
        r"^/dev/hd" : ("IDE",),
681
        r"\bnfs\b" : ("NFS_FS", "NFS_ROOT", "NET"),
682
        }
683
    ifp = open("/etc/mtab", "r")
684
    while 1:
685
        line = ifp.readline()
686
        if not line:
687
            break
688
        fields = line.split()
689
        mountpoint = fields[1]
690
        fstype = fields[2]
691
        if mountpoint == "/":
692
            # Figure out the drive type of the root partition.
693
            rootsymbols = []
694
            for (pattern, symbols) in fstab_to_bus_map.items():
695
                if re.compile(pattern).search(line):
696
                    rootsymbols = list(symbols)
697
            if fsmap.has_key(fstype):
698
                rootsymbols.append(fsmap[fstype])
699
            if not rootsymbols:
700
                sys.stderr.write(lang["ROOTWARN"])
701
                break
702
            # We should have a list of `buses' now...
703
            for roottype in rootsymbols:
704
                # First we have to force the bus the drive is on to y.
705
                config.found(roottype, y, "Root filesystem")
706
                sys.stderr.write(lang["ROOTFS"] % roottype)
707
                # Then force all bootable hardware previously set modular and
708
                # dependent on this bus to y.
709
                bus = configuration.dictionary[roottype]
710
                for symbol in configuration.dictionary.values():
711
                    if cml.evaluate(symbol) == m \
712
                       and symbol.hasprop("BOOTABLE") \
713
                       and bus.ancestor_of(symbol):
714
                        config.found(symbol.name, y, "Root filesystem")
715
                        sys.stderr.write(lang["ROOTHW"] % symbol.name)
716
    ifp.close()
717
 
718
    # PTY devices
719
    ptycount = dmesg.find('pty: ([0-9]*) Unix98 ptys')
720
    if ptycount:
721
        config.found("UNIX98_PTY_COUNT", int(ptycount))
722
 
723
    # Helper functions.
724
 
725
    def grepcmd(pattern, cmd):
726
        "Test for PATTERN in the output of COMMAND."
727
        (status, output) = commands.getstatusoutput(cmd)
728
        return status == 0 and re.compile(pattern).search(output)
729
 
730
    # Apply those sanity checks
731
 
732
    # Handle a subtle gotcha: if there are multiple NICs, they must be modular.
733
    if grepcmd("eth[1-3]", "/sbin/ifconfig -a"):
734
        config.force_dependents_modular("NET_ETHERNET",
735
                                        "Multiple NICs must be modular")
736
 
737
    # Now freeze complement sets.  With any luck, this will reduce the
738
    # set of drivers the user actually has to specify to zero.
739
    #
740
    # Giacomo writes:
741
    # "BTW I have done some test with USB, and it seems that you can
742
    # hotplug USB devices, also with hardcored drivers, and the driver
743
    # is initialized only at the hotplug event.
744
    # (This mean that USB devices can be set also to 'y', without
745
    # losing functionality.
746
    # This is not true for other 'hotplug' devices. I.e. my
747
    # parport ZIP will be loaded only at boot time (hardcoded) or
748
    # at modules loading (module)."
749
    #
750
    # So far I have not done anything about this.
751
    if not hardcompile:
752
        b = cml.Baton(lang["COMPLEMENT"])
753
        config.complement("HOTPLUG_PCI",cml.m, b, "PCI_HOTPLUG is a hot-plug bus")
754
        config.complement("USB",        cml.m, b, "USB is a hot-plug bus")
755
        config.complement("PCMCIA",     cml.m, b, "PCMCIA is a hot-plug bus")
756
        config.complement("IEEE1394",   cml.m, b, "IEEE1394 ia a hot-plug bus")
757
        b.end(lang["DONE"])
758
 
759
    DEBUG(lang["COMPLETE"])
760
 
761
def process_define(myconfiguration, val, freeze):
762
    "Process a -d=xxx or -D=xxx option."
763
    parts = val.split("=")
764
    sym = parts[0]
765
    if myconfiguration.dictionary.has_key(sym):
766
        sym = myconfiguration.dictionary[sym]
767
    else:
768
        myconfiguration.errout.write(lang["SYMUNKNOWN"] % (`sym`,))
769
        sys.exit(1)
770
    if sym.is_derived():
771
        myconfiguration.debug_emit(1, lang["DERIVED"] % (`sym`,))
772
        sys.exit(1)
773
    elif sym.is_logical():
774
        if len(parts) == 1:
775
            val = 'y'
776
        elif parts[1] == 'y':
777
            val = 'y'
778
        elif parts[1] == 'm':
779
            myconfiguration.trits_enabled = 1
780
            val = 'm'
781
        elif parts[1] == 'n':
782
            val = 'n'
783
    elif len(parts) == 1:
784
        print lang["NOCMDLINE"] % (`sym`,)
785
        sys.exit(1)
786
    else:
787
        val = parts[1]
788
    (ok, effects, violation) = myconfiguration.set_symbol(sym,
789
                                     myconfiguration.value_from_string(sym, val),
790
                                     freeze)
791
    if effects:
792
        sys.stderr.write(lang["EFFECTS"] + "\n")
793
        sys.stderr.write("\n".join(effects) + "\n\n")
794
    if not ok:
795
        sys.stderr.write((lang["ROLLBACK"] % (sym.name, val)) + "\n")
796
        sys.stderr.write("\n".join(violation)+"\n")
797
 
798
if __name__ == "__main__":
799
    # Process command-line options
800
    try:
801
        (options, arguments) = getopt.getopt(sys.argv[1:], "d:D:hr:st:v",
802
                                             ("hardcompile",
803
                                              "rules=",
804
                                              "standalone",
805
                                              "target=",
806
                                              "verbose"))
807
    except getopt.GetoptError:
808
        sys.stderr.write(lang["OPTUNKNOWN"])
809
        raise SystemExit, 2
810
 
811
    autoprobe_debug = hardcompile = standalone = 0
812
    objtree = os.environ.get("KBUILD_OBJTREE")
813
    rulesfile = "autoconfigure.rules"
814
    freeze_em = []
815
    set_em = []
816
 
817
    for (opt, val) in options:
818
        if opt == '-D':
819
            freeze_em.append(val)
820
        elif opt == '-d':
821
            set_em.append(val)
822
        elif opt in ("-v", "--verbose"):
823
            autoprobe_debug += 1
824
        elif opt in ("--hardcompile", "-h"):
825
            hardcompile = 1
826
        elif opt in ("--rules", "-r"):
827
            rulesfile = val
828
        elif opt in ("--standalone", "-s"):
829
            standalone = 1
830
        elif opt in ("--target", "-t"):
831
            objtree = os.path.expanduser(val)
832
 
833
    if objtree == None:
834
        objtree = "."
835
 
836
    #
837
    # Now use the rulebase information
838
    #
839
    rulebase = os.path.join(objtree, "rules.out")
840
    if not os.path.exists(rulebase):
841
        sys.stderr.write("autoconfigure: rulebase %s does not exist!\n" % rulebase)
842
        raise SystemExit, 1
843
    configuration = cmlsystem.CMLSystem(rulebase)
844
    if not cmlsystem:
845
        sys.stderr.write("autoconfigure: rulebase %s could not be read!\n" % rulebase)
846
        raise SystemExit, 1
847
 
848
    # Autoconfigure into the configuration object.
849
    for sym in freeze_em:
850
        process_define(configuration, sym, 1)
851
    for sym in set_em:
852
        process_define(configuration, sym, 0)
853
    autoconfigure(configuration, hardcompile, autoprobe_debug)
854
 
855
    # Write out this configuration, we're done.
856
    if standalone:
857
        configuration.save(sys.stdout, None, "normal")
858
    else:
859
        configuration.save(sys.stdout, None, "probe")
860
 
861
# End

powered by: WebSVN 2.1.0

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