예제 #1
0
def load_system(cmd_options, cmd_arguments):
    "Read in the rulebase and handle command-line arguments."
    global debug, configfile, configuration
    debug = 0
    configfile = None

    if not cmd_arguments:
        rulebase = "rules.out"
    else:
        rulebase = cmd_arguments[0]
    try:
        open(rulebase, 'rb')
    except IOError:
        print lang["NOFILE"] % (rulebase, )
        raise SystemExit
    configuration = cmlsystem.CMLSystem(rulebase)

    process_options(configuration, cmd_options)

    configuration.debug_emit(
        1, lang["PARAMS"] % (configfile, configuration.prefix))

    # Perhaps the user needs modules enabled initially
    if configuration.trit_tie and cml.evaluate(configuration.trit_tie):
        configuration.trits_enabled = 1

    # Don't count all these automatically generated settings
    # for purposes of figuring out whether we should confirm a quit.
    configuration.commits = 0

    return configuration
예제 #2
0
def load_system(cmd_options, cmd_arguments):
    "Read in the rulebase and handle command-line arguments."
    global debug, configfile, configuration
    debug = 0;
    configfile = None

    if not cmd_arguments:
        rulebase = "rules.out"
    else:
        rulebase = cmd_arguments[0]
    try:
	open(rulebase, 'rb')
    except IOError:
        print lang["NOFILE"] % (rulebase,)
        raise SystemExit
    configuration = cmlsystem.CMLSystem(rulebase)

    process_options(configuration, cmd_options)

    configuration.debug_emit(1, lang["PARAMS"] % (configfile,configuration.prefix))

    # Perhaps the user needs modules enabled initially
    if configuration.trit_tie and cml.evaluate(configuration.trit_tie):
        configuration.trits_enabled = 1

    # Don't count all these automatically generated settings
    # for purposes of figuring out whether we should confirm a quit.
    configuration.commits = 0

    return configuration
예제 #3
0
 def PRIORITY(symbols, cnf=configuration):
     global config
     legend = "PRIORITY" + `symbols`
     dict = cnf.dictionary
     symbols = map(lambda x, d=dict: d[x], symbols)
     for i in range(len(symbols) - 1):
         if cml.evaluate(symbols[i]):
             for j in range(i+1, len(symbols)):
                 cnf.set_symbol(symbols[j], n)
                 symbols[j].setprop(legend)
             break
예제 #4
0
def autoconfigure(configuration, hardcompile, debuglevel):
    global config, cpu, cpu_id, pci, isapnp, mca, usbp, usbc, usbi, fs
    global devices, m_devices, misc, net, ide, dmesg, modules, cpu_latch
    global fsmap, reliable
    configuration.interactive = 0	# Don't deduce from visibility.

    config = ConfigFile(configuration, hardcompile, debuglevel)

    #
    # Here is where we query the system state.
    #
    (ARCH, ARCHSYMBOL) = get_arch()
    config.found_y(ARCHSYMBOL)
    config.yak(ARCHSYMBOL)

    # Get the processor type
    cpu     = FieldParser(("/proc/cpuinfo",))
    if ARCHSYMBOL == 'SPARC':
      processors = int(cpu.find("^ncpus active.*: *([0-9]*)"))
      vendor     = cpu.find("^cpu.*: *(.*)")
      cpufam     = cpu.find("^type.*: *([-A-Za-z0-9_]*)")
      mod        = cpu.find("^fpu.*: *(.*)")
      name       = cpu.find("^MMU Type.*: *(.*)")
    else:
      processors = int(cpu.find("^processor.*: *([0-9]*)", -1)) + 1
      vendor  = cpu.find("^vendor_id.*: *([-A-Za-z0-9_]*)")
      cpufam  = cpu.find("^cpu family.*: *([-A-Za-z0-9_]*)")
      mod     = cpu.find("^model.*: *([-A-Za-z0-9_]*)")
      name    = cpu.find("^model name.*: *(.*)")

    cpu_id = vendor + ":" + cpufam + ":" + mod + ":" + name
    cpu_latch = 0

    # Now query for features
    pci     = PCIScanner()
    isapnp  = FieldParser((("/proc/bus/isapnp/devices", 2),))
    mca     = FieldParser(("/proc/mca/pos",))
    usbp    = FieldParser((("/proc/bus/usb/devices", "^P:.*Vendor=([A-Fa-f0-9]*)\s.*ProdID=\([A-Fa-f0-9]*\)"),))
    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]*)"),))
    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]*)"),))
    fs      = FieldParser((("/proc/mounts",3),
                           ("/etc/mtab", 3),
                           ("/etc/fstab", 3)))
    devices = FieldParser((("/proc/devices", "[0-9]+ (.*)"),))
    m_devices = FieldParser((("/proc/misc", "[0-9]+ (.*)"),))
    misc    = FieldParser(("/proc/iomem", "/proc/ioports", "/proc/dma", "/proc/interrupts"))
    net     = FieldParser((("/proc/net/sockstat","^([A-Z0-9]*): inuse [1-9]"),))
    ide     = FieldParser(glob.glob('/proc/ide/hd?/media'))
    dmesg   = FieldParser(("/var/log/dmesg", "dmesg"))
    modules = FieldParser((("/proc/modules", 1),))

    #
    # Tests that won't fit in the rulesfile format
    #

    # Source: linux/i386/kernel/setup.c
    if dmesg.find("Use a PAE"):
        config.found_y("HIGHMEM64G")	
    elif dmesg.find("Use a HIGHMEM"):
        config.found_y("HIGHMEM4G")	##Source: linux/i386/kernel/setup.c
    else:
        highmem = dmesg.find("([0-9]*)MB HIGHMEM avail.")
        if not highmem:
            config.found_y("NOHIGHMEM")
        elif int(highmem) > 3072:
            config.found_y("HIGHMEM64G")
        else:
            config.found_y("HIGHMEM4G")

    # SMP?  This test is reliable.
    if processors == 0:
      processors = len(filter(lambda x: x.find('processor') > -1, cpu.items))

    if processors > 1:
        config.found_y("SMP")
        config.yak("SMP")

    fsmap = {}
    reliable = {}

    #
    # Here are the function calls used by the rules file
    #
    TRUE = 1
    FALSE = 0
    PRESENT = 1
    ABSENT = 0
    
    def DEBUG(str):
        sys.stderr.write("# " + str + "\n")

    # Following three tests are reliable -- that is, if PCI or PNP
    # tests fail we know the feature is *not* there.

    def PCI(prefix, symbol):
        global pci, config
        reliable[symbol] = "PCI"
        if pci.search("^" + prefix):
            config.yak(symbol)
            config.found(symbol, None, "PCI")


    def PCI_CLASS(match, symbol):
        global pci, config
        reliable[symbol] = "PCI_CLASS"
        if pci.search("Class:" + match):
            config.yak(symbol)
            config.found(symbol, None, "PCI_CLASS")

    def PNP(match, symbol):
        global isapnp, config
        reliable[symbol] = "PNP"
        if isapnp.find(match):
            config.yak(symbol)
            config.found(symbol, None, "PNP")

    def MCA(match, symbol):
        global mca, config
        reliable[symbol] = "MCA"
        # FIXME: Not certain I've got the byte order right here
        if mca.find(": " + match[2:] + " " + match[:2]):
            config.yak(symbol)
            config.found(symbol, None, "MCA")

    # USB tests reliably detect connected devices, but the bus is hot-plug.

    def USBP(match, symbol):
        global usbp, config
        if usbp.find(match):
            config.yak(symbol)
            config.found(symbol, None, "USBP")

    def USBC(match, symbol):
        global usbc, config
        if usbc.find(match):
            config.yak(symbol)
            config.found(symbol, None, "USBC")

    def USBI(match, symbol):
        global usbi, config
        if usbi.find(match):
            config.yak(symbol)
            config.found(symbol, None, "USBI")

    # Remaining tests rely on prior kernel configuration.

    def FS(match, symbol):
        global fs, fsmap, config
        if fs.find(r"\b" + match + r"\b"):
            config.yak(symbol)
            config.found(symbol, None, "FS")
        # Also, build the map of file system types to symbols.
        fsmap[match] = symbol

    def DEV(match, symbol):
        global devices, config
        if devices.find(r"\b" + match + r"\b"):
            config.yak(symbol)
            config.found(symbol, None, "DEV")

    def DEVM(match, symbol):
        global m_devices, config
        if m_devices.find(r"\b" + match + r"\b"):
            config.yak(symbol)
            config.found(symbol, None, "DEV_M")

    def CONS(match, symbol):
        global dmesg, config
        if dmesg.find("^Console: .* " + match + " "):
            config.yak(symbol)
            config.found(symbol, None, "CONS")

    def DMESG(match, symbol, truthval=TRUE):
        global dmesg, config
        if dmesg.find(match):
            if truthval:
                config.found(symbol, None, "DMESG")
                config.yak(symbol)
            else:
                config.found_n(symbol, "DMESG")

    def NET(match, symbol):
        global net, config
        if net.find(match):
            config.yak(symbol)
            config.found(symbol, None, "NET")

    def IDE(match, symbol):
        global ide, config
        if ide.find(match):
            config.yak(symbol)
            config.found(symbol, None, "IDE")

    def REQ(match, symbol):
        global misc, config
        if misc.find(match):
            config.yak(symbol)
            config.found(symbol, None, "REQ")

    def CPUTYPE(match, symbol):
        global cpu_latch, config
        if not cpu_latch and re.search(match, cpu_id):
            config.found_y(symbol, "CPUTYPE")
            config.yak(symbol)
            cpu_latch = 1

    def CPUINFO(match, symbol, present=PRESENT, truthval=cml.y):
        global cpu, config
        if (not not cpu.find(match)) == present:
            config.found(symbol, truthval, "CPUINFO")
            if truthval:
                config.yak(symbol)

    def EXISTS(procfile, symbol):
        global config
        if os.path.exists(procfile):
            config.found(symbol, None, "EXISTS")
            config.yak(symbol)
        else:
            config.found(symbol, n, "EXISTS")

    def MODULE(name, symbol):
        global modules, config
        if modules.find(r"\b" + name + r"\b"):
            config.found(symbol, None, "MODULES")
            config.yak(symbol)

    def GREP(pattern, file, symbol):
        global config
        try:
            fp = open(file)
        except IOError:
            return
        if re.compile(pattern).search(fp.read()):
            config.found(symbol, None, "GREP")
            config.yak(symbol)
        fp.close()  

    def LINKTO(file, pattern, symbol):
        global config
        if not os.path.exists(file):
            return
        file = os.readlink(file)
        if re.compile(pattern).search(file):
            config.found(symbol, None, "LINKTO")
            config.yak(symbol)

    # Use this to avoid conflicts

    def PRIORITY(symbols, cnf=configuration):
        global config
        legend = "PRIORITY" + `symbols`
        dict = cnf.dictionary
        symbols = map(lambda x, d=dict: d[x], symbols)
        for i in range(len(symbols) - 1):
            if cml.evaluate(symbols[i]):
                for j in range(i+1, len(symbols)):
                    cnf.set_symbol(symbols[j], n)
                    symbols[j].setprop(legend)
                break

    ########################################################################
    ##
    ## Section            Command         Version        Status
    ## ------------------------------------------------------------------
    ##  /proc features     EXISTS          2.5.2-pre7     Partial 

    ########################################################################
    ## Section: System Features
    ## KernelOutput: /proc/*, /dev/*
    ## Detect system features based on existence of /proc and /dev/* files 
    DEBUG("autoconfigure.rules: EXISTS")

    ## These tests are unreliable; they depend on the current kernel config.
    EXISTS("/proc/sysvipc",		'SYSVIPC')
    EXISTS("/proc/sys",			'SYSCTL')
    EXISTS("/proc/scsi/ide-scsi",	'BLK_DEV_IDESCSI')
    EXISTS("/proc/scsi/imm",		'SCSI_IMM')
    EXISTS("/proc/scsi/ppa",		'SCSI_PPA')
    EXISTS("/dev/.devfsd",		'DEVFS_FS')
    # Giacomo does not have these yet.
    EXISTS("/proc/sys/net/khttpd",	'KHTTPD')
    EXISTS("/proc/sys/kernel/acct",	'BSD_PROCESS_ACCT')
    # This one is reliable, according to the MCA port documentation.
    EXISTS("/proc/mca",			'MCA')
    # This one is reliable too
    EXISTS("/proc/bus/isapnp/devices",	'ISAPNP')

    # Test the new probe function.
    GREP("scsi0", "/proc/scsi/scsi",	'SCSI')

    # These can be bogus because the file or directory in question
    # is empty, or consists of a banner string that does not describe
    # an actual device.  We need to do more analysis here.
    # EXISTS("/proc/bus/pci",		'PCI')
    # EXISTS("/proc/bus/usb",		'USB')
    # EXISTS("/proc/net",		'NET')
    # EXISTS("/proc/scsi",		'SCSI')		

    # These look tempting, but they're no good unless we're on a pure
    # devfs system, without support for old devices, where devices
    # only exist when they're needed.
    # EXISTS("/dev/agpgart",		'AGP')
    # EXISTS("/dev/floppy",		'BLK_DEV_FD')
    # EXISTS("/dev/fd0",		'BLK_DEV_FD')

    
    ########################################################################
    ## Section: Mice
    ## Detect the mouse type by looking at what's behind the /dev/mouse link.
    ## These are probes for 2.4 with the old input core
    LINKTO("/dev/mouse", "psaux",	'PSMOUSE')
    LINKTO("/dev/mouse", "ttyS",	'SERIAL')
    LINKTO("/dev/mouse", "logibm",	'LOGIBUSMOUSE')
    LINKTO("/dev/mouse", "inportbm",	'MS_BUSMOUSE')
    LINKTO("/dev/mouse", "atibm",	'ATIXL_BUSMOUSE')
    ## These are probes for 2.5 with the new input core
    LINKTO("/dev/mouse", "psaux",	'MOUSE_PS2')
    LINKTO("/dev/mouse", "ttyS",	'MOUSE_SERIAL')
    LINKTO("/dev/mouse", "logibm",	'MOUSE_LOGIBM')
    LINKTO("/dev/mouse", "inportbm",	'MOUSE_INPORT')
    LINKTO("/dev/mouse", "atibm",	'MOUSE_ATIXL')

    ########################################################################
    ## Section: IDE devices
    ## KernelOutput: /proc/ide/hd?/media
    ## Detect IDE devices based on contents of /proc files
    ## These tests are unreliable; they depend on the current kernel config.
    IDE('disk', 'BLK_DEV_IDEDISK')
    IDE('cdrom', 'BLK_DEV_IDECD')
    IDE('tape', 'BLK_DEV_IDETAPE')
    IDE('floppy', 'BLK_DEV_FLOPPY')
    EXISTS("/dev/ide/ide0",		'BLK_DEV_IDE')
    EXISTS("/dev/ide/ide1",		'BLK_DEV_IDE')
    EXISTS('/proc/ide/piix',		'PIIX_TUNING')

    ########################################################################
    # Miscellaneous tests that replace Giacomo's ad-hoc ones.
    DEV('pty', 'UNIX98_PTYS')
    REQ('SMBus', 'I2C')
    REQ('ATI.*Mach64', 'FB_ATY')
    #FS(r'xfs', 'XFS_FS')

    ########################################################################
    # This is a near complete set of MCA probes for hardware supported under
    # Linux, according to MCA maintainer David Weinehall.  The exception is
    # the IBMTR card, which cannot be probed reliably.
    if config.enabled("MCA"):
        MCA("ddff", 'BLK_DEV_PS2')
        MCA("df9f", 'BLK_DEV_PS2')
        MCA("628b", 'EEXPRESS')
        MCA("627[cd]", 'EL3')
        MCA("62db", 'EL3')
        MCA("62f6", 'EL3')
        MCA("62f7", 'EL3')
        MCA("6042", 'ELMC')
        MCA("0041", 'ELMC_II')
        MCA("8ef5", 'ELMC_II')
        MCA("61c[89]", 'ULTRAMCA')
        MCA("6fc[012]", 'ULTRAMCA')
        MCA("efd[45]", 'ULTRAMCA')
        MCA("efe5", 'ULTRAMCA')
        MCA("641[036]", 'AT1700')
        MCA("6def", 'DEPCA')
        MCA("6afd", 'SKMC')
        MCA("6be9", 'SKMC')
        MCA("6354", 'NE2_MCA')
        MCA("7154", 'NE2_MCA')
        MCA("56ea", 'NE2_MCA')
        MCA("ffe0", 'IBMLANA')
        MCA("8ef[8cdef]", 'SCSI_IBMMCA')
        MCA("5137", 'SCSI_FD_MCS')
        MCA("60e9", 'SCSI_FD_MCS')
        MCA("6127", 'SCSI_FD_MCS')
        MCA("0092", 'SCSI_NCR_D700')
        MCA("7f4c", 'SCSI_MCA_53C9X')
        MCA("0f1f", 'SCSI_AHA_1542')
        MCA("002d", 'MADGEMC')
        MCA("6ec6", 'SMCTR')
        MCA("62f3", 'SOUND_SB')
        MCA("7113", 'SOUND_SB')

    ########################################################################
    ## This requires Paul Gortmaker's EISA ID patch.
    REQ("EISA", "EISA")	# Someday, IOPORTS()

    ########################################################################
    ## The rest of the table is read in from Giacomo's Catenazzi's rulesfile.
    execfile(rulesfile)

    # If it has a reliable test, but was not found by any test, switch it off.
    # We do things in this order to avoid losing on symbols that are only set
    # to n by PNP and PCI tests.
    baton = cml.Baton(lang["TURNOFF"])
    for symbol in configuration.dictionary.values():
        baton.twirl()
        if symbol.is_symbol() and configuration.saveable(symbol) \
           and reliable.has_key(symbol.name) and not cml.evaluate(symbol):
            config.found(symbol.name, n, reliable[symbol.name])
    baton.end()

    ########################################################################
    ## Resolve conflicts.

    PRIORITY(("SCSI_SYM53C8XX_2", "SCSI_SYM53C8XX", \
                                 "SCSI_NCR53C8XX", "SCSI_GENERIC_NCR5380"))
    PRIORITY(("DE2104X", "TULIP"))

    ## End of probe logic.
    ##
    ########################################################################

    # More tests that don't fit the rulesfile format

    # Filesystem, bus, and controller for root cannot be modules.
    sys.stderr.write(lang["ROOTLOOK"])
    fstab_to_bus_map = {
        r"^/dev/sd" : ("SCSI",),
        r"^/dev/hd" : ("IDE",),
        r"\bnfs\b" : ("NFS_FS", "NFS_ROOT", "NET"),
        }
    ifp = open("/etc/mtab", "r")
    while 1:
        line = ifp.readline()
        if not line:
            break
        fields = line.split()
        mountpoint = fields[1]
        fstype = fields[2]
        if mountpoint == "/":
            # Figure out the drive type of the root partition.
            rootsymbols = []
            for (pattern, symbols) in fstab_to_bus_map.items():
                if re.compile(pattern).search(line):
                    rootsymbols = list(symbols)
            if fsmap.has_key(fstype):
                rootsymbols.append(fsmap[fstype])
            if not rootsymbols:
                sys.stderr.write(lang["ROOTWARN"])
                break
            # We should have a list of `buses' now...
            for roottype in rootsymbols:
                # First we have to force the bus the drive is on to y.
                config.found(roottype, y, "Root filesystem")
                sys.stderr.write(lang["ROOTFS"] % roottype)
                # Then force all bootable hardware previously set modular and
                # dependent on this bus to y.
                bus = configuration.dictionary[roottype]
                for symbol in configuration.dictionary.values():
                    if cml.evaluate(symbol) == m \
                       and symbol.hasprop("BOOTABLE") \
                       and bus.ancestor_of(symbol):
                        config.found(symbol.name, y, "Root filesystem")
                        sys.stderr.write(lang["ROOTHW"] % symbol.name)
    ifp.close()

    # PTY devices
    ptycount = dmesg.find('pty: ([0-9]*) Unix98 ptys')
    if ptycount:
        config.found("UNIX98_PTY_COUNT", int(ptycount))

    # Helper functions.

    def grepcmd(pattern, cmd):
        "Test for PATTERN in the output of COMMAND."
        (status, output) = commands.getstatusoutput(cmd)
        return status == 0 and re.compile(pattern).search(output)

    # Apply those sanity checks

    # Handle a subtle gotcha: if there are multiple NICs, they must be modular.
    if grepcmd("eth[1-3]", "/sbin/ifconfig -a"):
        config.force_dependents_modular("NET_ETHERNET",
                                        "Multiple NICs must be modular")

    # Now freeze complement sets.  With any luck, this will reduce the
    # set of drivers the user actually has to specify to zero.
    #
    # Giacomo writes:
    # "BTW I have done some test with USB, and it seems that you can
    # hotplug USB devices, also with hardcored drivers, and the driver
    # is initialized only at the hotplug event.
    # (This mean that USB devices can be set also to 'y', without
    # losing functionality.
    # This is not true for other 'hotplug' devices. I.e. my
    # parport ZIP will be loaded only at boot time (hardcoded) or
    # at modules loading (module)."
    #
    # So far I have not done anything about this.
    if not hardcompile:
        b = cml.Baton(lang["COMPLEMENT"])
        config.complement("HOTPLUG_PCI",cml.m, b, "PCI_HOTPLUG is a hot-plug bus")
        config.complement("USB",        cml.m, b, "USB is a hot-plug bus")
        config.complement("PCMCIA",     cml.m, b, "PCMCIA is a hot-plug bus")
        config.complement("IEEE1394",   cml.m, b, "IEEE1394 ia a hot-plug bus")
        b.end(lang["DONE"])

    DEBUG(lang["COMPLETE"])