Annotation of coherent/d/etc/build/mkdev.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * mkdev.c
        !             3:  * 10/25/90
        !             4:  * Allow the user to configure devices requiring loadable drivers.
        !             5:  * Uses common routines in build0.c: cc -o mkdev mkdev.c build0.c
        !             6:  * Usage: mkdev [ -bdv ] { scsi | at }
        !             7:  * Options:
        !             8:  *     -b      Use special processing when invoked from /etc/build
        !             9:  *     -d      Debug; echo commands without executing
        !            10:  *     -v      Verbose
        !            11:  *
        !            12:  * $Log:       mkdev.c,v $
        !            13:  * Revision 1.6  92/01/17  11:31:17  bin
        !            14:  * another hal update... looks like the final 321 ship version
        !            15:  * 
        !            16:  *
        !            17:  * Roughly, do the following for device "foo" ( at | aha154x | ss )
        !            18:  *
        !            19:  *     cp /drv/foo /tmp/drv/foo
        !            20:  *     make necessary patches "xxx" to /tmp/drv/foo
        !            21:  *     if not "at" device
        !            22:  *             make nodes (mknod -f) for the device
        !            23:  *     if build mode (bflag)
        !            24:  *             if rootdev
        !            25:  *                     append to LDKERFILE:
        !            26:  *                             HD=foo.a
        !            27:  *                             HDUNDEF="-u foocon_"
        !            28:  *                             HDPATCH="drvl_+xx0=foocon_"
        !            29:  *             /etc/drvld -r /tmp/drv/foo
        !            30:  *             append to PATCHFILE:
        !            31:  *                     cp /tmp/drv/foo /mnt/drv/foo
        !            32:  *             if rootdev, also append to PATCHFILE:
        !            33:  *                     /conf/patch /mnt/coherent xxx
        !            34:  *     else - not build mode
        !            35:  *             display message saying patched driver is at /tmp/drv/foo
        !            36:  */
        !            37: 
        !            38: #include <stdio.h>
        !            39: #include <sys/devices.h>
        !            40: #include "build0.h"
        !            41: 
        !            42: #define        VERSION         "V1.4"          /* version number */
        !            43: #define        USAGEMSG        "Usage:\t/etc/mkdev [ -bdv ] [ scsi | at ]\n"
        !            44: #define BUFLEN         50
        !            45: #define AHA_HDS                64
        !            46: #define AHA_DMA                5
        !            47: #define AHA_IRQ                11
        !            48: #define AHA_BASE       0x330
        !            49: #define TANDY_HDS      16
        !            50: 
        !            51: /* Forward. */
        !            52: void   scsi();
        !            53: void   at();
        !            54: 
        !            55: /* Globals. */
        !            56: int    bflag;                          /* Invoked from /etc/build. */
        !            57: 
        !            58: main(argc, argv) int argc; char *argv[];
        !            59: {
        !            60:        register char *s;
        !            61: 
        !            62:        argv0 = argv[0];
        !            63:        usagemsg = USAGEMSG;
        !            64:        if (argc > 1 && argv[1][0] == '-') {
        !            65:                for (s = &argv[1][1]; *s; ++s) {
        !            66:                        switch(*s) {
        !            67:                        case 'b':       ++bflag;        break;
        !            68:                        case 'd':       ++dflag;        break;
        !            69:                        case 'v':       ++vflag;        break;
        !            70:                        case 'V':
        !            71:                                fprintf(stderr, "mkdev: %s\n", VERSION);
        !            72:                                break;
        !            73:                        default:        usage();        break;
        !            74:                        }
        !            75:                }
        !            76:                --argc;
        !            77:                ++argv;
        !            78:        }
        !            79: 
        !            80:        if (argc == 1) {
        !            81:                usage();
        !            82:        } else {
        !            83:                /* Do specified things. */
        !            84:                while (--argc > 0) {
        !            85:                        if (strcmp(argv[1], "scsi") == 0)
        !            86:                                scsi();
        !            87:                        else if (strcmp(argv[1], "at") == 0)
        !            88:                                at();
        !            89:                        else
        !            90:                                usage();
        !            91:                        ++argv;
        !            92:                }
        !            93:        }
        !            94:        exit(0);
        !            95: }
        !            96: 
        !            97: void
        !            98: scsi()
        !            99: {
        !           100:        char *dev, *coh;
        !           101:        int i, id, lun, rootflag;
        !           102:        int ss_dev = 0;
        !           103:        int fut_dev = 0;
        !           104:        short nsdrive = 0;
        !           105:        int ss_int = 5, new_int;
        !           106:        unsigned int ss_base = 0xCA00, new_base;
        !           107:        unsigned char ss_patch[80], buf[BUFLEN];
        !           108:        FILE *fp;
        !           109:        int aha_dev = 0, sd_hds = AHA_HDS, sd_dma = AHA_DMA;
        !           110:        int sd_irq = AHA_IRQ, sd_base = AHA_BASE;
        !           111: 
        !           112:        rootflag = 0;
        !           113: #if    0
        !           114:        /* For future use, not much use with only one supported host adapter. */
        !           115: again:
        !           116: #endif
        !           117:        cls(0);
        !           118:        printf(
        !           119: "COHERENT currently supports the following SCSI host adapters:\n"
        !           120: "\n"
        !           121: "(1) Adaptec AHA-154x series\n"
        !           122: "(2) Seagate ST01 or ST02\n"
        !           123: "(3) Future Domain TMC-845/850/860/875/885\n"
        !           124: "(4) Future Domain TMC-840/841/880/881\n"
        !           125: "\n"
        !           126:                );
        !           127: retry:
        !           128:        switch(get_int(0, 4, "Enter a number from the above list or 0 to exit:")) {
        !           129:        case 0:
        !           130:                return;
        !           131:        case 1:
        !           132:                aha_dev = 1;
        !           133:                coh = "aha";
        !           134:                break;
        !           135:        case 2:
        !           136:                ss_dev = 1;
        !           137:                coh = "ss";
        !           138:                break;
        !           139:        case 3:
        !           140:                ss_dev = 1;
        !           141:                fut_dev = 1;
        !           142:                coh = "ss";
        !           143:                nsdrive |= 0x8000;
        !           144:                break;
        !           145:        case 4:
        !           146:                ss_dev = 1;
        !           147:                fut_dev = 1;
        !           148:                coh = "ss";
        !           149:                nsdrive |= 0x4000;
        !           150:                break;
        !           151:        default:
        !           152:                goto retry;             /* should never happen */
        !           153:        }
        !           154: 
        !           155:        /* Make /tmp/drv if not already there. */
        !           156:        if ((i = is_dir("/tmp/drv")) == 0)
        !           157:                sys("/bin/mkdir /tmp/drv", S_FATAL);
        !           158:        else if (i == -1)
        !           159:                fatal("/tmp/drv is not a directory");
        !           160: 
        !           161:        /*
        !           162:         * If Adaptec, allow patching host adapter variables SD_HDS
        !           163:         * for Tandy variant of host BIOS.
        !           164:         */
        !           165:        if (aha_dev) {
        !           166: printf("\nMost versions of the Adaptec BIOS use 64-head translation mode.\n");
        !           167: printf("A few, including some Tandy variants, use 16-head translation mode.\n\n");
        !           168:                if (!yes_no("Do you want 64-head translation mode"))
        !           169:                        sd_hds = TANDY_HDS;
        !           170: printf("\nWhich IRQ does the host adapter use (9/10/11/12/14/15) [%d]? ",
        !           171:        sd_irq);
        !           172:                for (;;) {
        !           173:                        new_int = sd_irq;
        !           174:                        fgets(buf, BUFLEN, stdin);
        !           175:                        sscanf(buf, "%d", &new_int);
        !           176:                        switch(new_int) {
        !           177:                        case 9:
        !           178:                        case 10:
        !           179:                        case 11:
        !           180:                        case 12:
        !           181:                        case 14:
        !           182:                        case 15:
        !           183:                                goto ok_sdirq;
        !           184:                        }
        !           185: printf("Type 9,10,11,12,14,15 or just <Enter> for the default: ");
        !           186:                } /* endwhile */
        !           187: ok_sdirq:
        !           188:                sd_irq = new_int;
        !           189: 
        !           190: printf("\nWhat is the hexadecimal host adapter base port address \n");
        !           191: printf("  (130/134/230/234/330/334) [%x]? ", sd_base);
        !           192:                for (;;) {
        !           193:                        new_int = sd_base;
        !           194:                        fgets(buf, BUFLEN, stdin);
        !           195:                        sscanf(buf, "%x", &new_int);
        !           196:                        switch(new_int) {
        !           197:                        case 0x130:
        !           198:                        case 0x134:
        !           199:                        case 0x230:
        !           200:                        case 0x234:
        !           201:                        case 0x330:
        !           202:                        case 0x334:
        !           203:                                goto ok_sdbase;
        !           204:                        }
        !           205: printf("Type 130,134,230,234,330,334 or just <Enter> for the default: ");
        !           206:                } /* endfor */
        !           207: ok_sdbase:
        !           208:                sd_base = new_int;
        !           209: 
        !           210: printf("\nWhich DMA channel does the host adapter use (0/5/6/7) [%d]? ",
        !           211:        sd_dma);
        !           212:                for (;;) {
        !           213:                        new_int = sd_dma;
        !           214:                        fgets(buf, BUFLEN, stdin);
        !           215:                        sscanf(buf, "%d", &new_int);
        !           216:                        if (new_int != 0 && new_int != 5
        !           217:                        && new_int != 6 && new_int != 7)
        !           218: printf("Type 0,5,6,7 or just <Enter> for the default: ");
        !           219:                        else
        !           220:                                break;
        !           221:                } /* endwhile */
        !           222:                sd_dma = new_int;
        !           223:        }
        !           224: 
        !           225:        /*
        !           226:         * If Seagate or Future Domain, allow patching host adapter
        !           227:         * variables SS_INT and SS_BASE.
        !           228:         */
        !           229:        if (ss_dev) {
        !           230: printf("\nPlease refer to the installation guide for your host adapter.\n");
        !           231: 
        !           232:                /* Get value to patch for SS_INT */
        !           233: printf("\nWhich IRQ number does the host adapter use [%d]? ", ss_int);
        !           234:                while (1) {
        !           235:                        new_int = ss_int;
        !           236:                        fgets(buf, BUFLEN, stdin);
        !           237:                        sscanf(buf, "%d", &new_int);
        !           238:                        if (new_int < 3 || new_int > 15)
        !           239: printf("Type a number between 3 and 15 or just <Enter> for the default: ");
        !           240:                        else
        !           241:                                break;
        !           242:                } /* endwhile */
        !           243:                ss_int = new_int;
        !           244: 
        !           245:                /* Get value to patch for SS_BASE */
        !           246: printf("Your host adapter is configured for a base segment address.  Possible\n");
        !           247: printf("values are: C800, CA00, CC00, CE00, DC00, and DE00.\n");
        !           248: printf("What is your 4-digit hexadecimal base address [%04X]? ", ss_base);
        !           249:                while (1) {
        !           250:                        new_base = ss_base;
        !           251:                        fgets(buf, BUFLEN, stdin);
        !           252:                        sscanf(buf, "%x", &new_base);
        !           253:                        if (new_base < 0xC800 || new_base > 0xDE00)
        !           254: printf("Type a number between C800 and DE00 or just <Enter> for the default: ");
        !           255:                        else
        !           256:                                break;
        !           257:                } /* endwhile */
        !           258:                ss_base = new_base;
        !           259:        }
        !           260:        
        !           261:        /*
        !           262:         * Set rootflag if root partition is on SCSI device.
        !           263:         * If using both AT and SCSI devices, write to drvld.all for
        !           264:         * non-root device.
        !           265:         */
        !           266:        if (bflag) {
        !           267:                cls(0);
        !           268:                if (yes_no(
        !           269: "Does your computer system include both a standard AT-type hard disk\n"
        !           270: "and a SCSI hard disk" )) {
        !           271:                        if (yes_no(
        !           272: "Will the COHERENT root partition be on this SCSI device")) {
        !           273:                                ++rootflag;
        !           274: sys("/bin/echo /etc/drvld -r /drv/at >> /tmp/drvld.all", S_FATAL);
        !           275:                        } else {        /* root is on "at" device */
        !           276: sprintf(cmd, "/bin/echo /etc/drvld -r /drv/%s >> /tmp/drvld.all",
        !           277: (aha_dev)?"aha154x":"ss");
        !           278:                                sys(cmd, S_FATAL);
        !           279:                        }
        !           280:                } else {        /* SCSI-only system */
        !           281:                        ++rootflag;
        !           282:                }
        !           283:        }
        !           284: 
        !           285:        /* Make device nodes. */
        !           286:        cls(0);
        !           287:        printf(
        !           288: "You must specify a SCSI-ID (0 through 7) for each SCSI hard disk device.\n"
        !           289: "Each SCSI hard disk device can contain up to four partitions.\n\n"
        !           290:                );
        !           291: 
        !           292: newdev:
        !           293:        id = get_int(0, 7, "Enter the SCSI-ID:");
        !           294: #if    1
        !           295:        lun = 0;
        !           296:        nsdrive |= (1 << id);
        !           297: #else
        !           298:        lun = get_int(0, 3, "Enter the LUN:");
        !           299: #endif
        !           300: 
        !           301:        /* Make /tmp/dev if bflag. */
        !           302:        if (bflag) {
        !           303:                if ((i = is_dir("/tmp/dev")) == 0)
        !           304:                        sys("/bin/mkdir /tmp/dev", S_FATAL);
        !           305:                else if (i == -1)
        !           306:                        fatal("/tmp/dev is not a directory");
        !           307:        }
        !           308:        dev = (bflag) ? "/tmp/dev" : "/dev";
        !           309: 
        !           310:        /* Make the cooked devices. */
        !           311:        for (i = 0; i < 4; i++) {
        !           312:                sprintf(cmd, "/etc/mknod -f %s/sd%d%c b %d %d",
        !           313:                        dev, id, 'a'+i, SCSI_MAJOR, SCSI_minor(0, id, lun, i));
        !           314:                sys(cmd, S_NONFATAL);
        !           315:        }
        !           316:        sprintf(cmd, "/etc/mknod -f %s/sd%dx b %d %d",
        !           317:                dev, id, SCSI_MAJOR, SCSI_minor(1, id, lun, 0));
        !           318:        sys(cmd, S_NONFATAL);
        !           319: 
        !           320:        /* Make the raw devices. */
        !           321:        for (i = 0; i < 4; i++) {
        !           322:                sprintf(cmd, "/etc/mknod -f %s/rsd%d%c c %d %d",
        !           323:                        dev, id, 'a'+i, SCSI_MAJOR, SCSI_minor(0, id, lun, i));
        !           324:                sys(cmd, S_NONFATAL);
        !           325:        }
        !           326:        sprintf(cmd, "/etc/mknod -f %s/rsd%dx c %d %d",
        !           327:                dev, id, SCSI_MAJOR, SCSI_minor(1, id, lun, 0));
        !           328:        sys(cmd, S_NONFATAL);
        !           329: 
        !           330:        /* Set the device permissions. */
        !           331:        sprintf(cmd, "/bin/chmod 0600 %s/sd* %s/rsd*", dev, dev);
        !           332:        sys(cmd, S_NONFATAL);
        !           333:        sprintf(cmd, "/bin/chown sys %s/sd*[a-d] %s/rsd*[a-d]", dev, dev);
        !           334:        sys(cmd, S_NONFATAL);
        !           335:        sprintf(cmd, "/bin/chgrp sys %s/sd*[a-d] %s/rsd*[a-d]", dev, dev);
        !           336:        sys(cmd, S_NONFATAL);
        !           337:        sprintf(cmd, "/bin/chown root %s/sd*x %s/rsd*x", dev, dev);
        !           338:        sys(cmd, S_NONFATAL);
        !           339:        sprintf(cmd, "/bin/chgrp root %s/sd*x %s/rsd*x", dev, dev);
        !           340:        sys(cmd, S_NONFATAL);
        !           341: 
        !           342:        /* Append lines to /tmp/devices to pass device info to /etc/build. */
        !           343:        if (bflag) {
        !           344:                for (i = 0; i < 4; i++) {
        !           345:                        sprintf(cmd, "/bin/echo sd%dx sd%d%c %d %d >>/tmp/devices",
        !           346:                                id, id, 'a'+i, SCSI_MAJOR, SCSI_minor(0, id, lun, i));
        !           347:                        sys(cmd, S_NONFATAL);
        !           348:                }
        !           349:        }
        !           350:        if (yes_no("Do you have another SCSI hard disk device on this host adapter"))
        !           351:                goto newdev;
        !           352: 
        !           353:        /*
        !           354:         * Ugly patching stuff specific to "ss" driver.
        !           355:         * At this point all SCSI id's attached to the host are known.
        !           356:         */
        !           357:        if (ss_dev) {
        !           358:                int unit;
        !           359: 
        !           360:                /* "ss" device driver requires patching to work at all. */
        !           361:                sprintf(ss_patch,
        !           362:                        "NSDRIVE_=0x%04x SS_INT_=%d SS_BASE_=0x%04x",
        !           363:                        nsdrive, ss_int, ss_base);
        !           364:                sys("/bin/cp /drv/ss /tmp/drv/ss", S_FATAL);
        !           365:                sprintf(cmd, "/conf/patch /tmp/drv/ss %s", ss_patch);
        !           366:                sys(cmd, S_FATAL);
        !           367:                if (bflag) {
        !           368:                        if (rootflag) {
        !           369:                                fp = fopen(LDKERFILE, "a");
        !           370:                                fprintf(fp, "HD=ss.a\n");
        !           371:                                fprintf(fp, "HDUNDEF=\"-u sscon_\"\n");
        !           372:                                fprintf(fp, "HDPATCH=\"drvl_+130=sscon_\"\n");
        !           373:                                fclose(fp);
        !           374:                        }
        !           375:                        sys("/etc/drvld -r /tmp/drv/ss", S_FATAL);
        !           376:                        fp = fopen(PATCHFILE, "a");
        !           377:                        fprintf(fp, "/conf/patch /mnt/drv/ss %s\n", ss_patch);
        !           378:                        if (rootflag)
        !           379:                                fprintf(fp,
        !           380:                                  "/conf/patch /mnt/coherent %s\n", ss_patch);
        !           381:                        fclose(fp);
        !           382:                        /*
        !           383:                         * Allow patching of the loaded driver parameters.
        !           384:                         */
        !           385:                        for (unit = 0; unit < 7; unit++)
        !           386:                                if (nsdrive & (1<<unit)) {
        !           387:                                        sprintf(cmd,
        !           388:                                          "/etc/hdparms -%c%c %s/sd%dx",
        !           389:                                          (rootflag)?'r':'b',
        !           390:                                          (fut_dev)?'f':'s', dev, unit);
        !           391:                                        sys(cmd, S_NONFATAL);
        !           392:                                }
        !           393:                } else
        !           394:                        printf("Patched driver at /tmp/drv/ss\n");
        !           395: 
        !           396:        } /* end of "ss" stuff */
        !           397: 
        !           398:        /*
        !           399:         * Ugly patching stuff specific to "aha154x" driver.
        !           400:         * At this point all SCSI id's attached to the host are known.
        !           401:         */
        !           402:        if (aha_dev) {
        !           403:                /*
        !           404:                 * Tandy Adaptec BIOS spoofs different head count than
        !           405:                 * Adaptec's Own Translation Mode.
        !           406:                 */
        !           407:                sprintf(ss_patch,
        !           408:                  "SD_HDS_=%d SDDMA_=%d SDIRQ_=%d SDBASE_=0x%x ",
        !           409:                  sd_hds, sd_dma, sd_irq, sd_base);
        !           410:                sys("/bin/cp /drv/aha154x /tmp/drv/aha154x", S_FATAL);
        !           411:                sprintf(cmd, "/conf/patch /tmp/drv/aha154x %s", ss_patch);
        !           412:                sys(cmd, S_FATAL);
        !           413:                if (bflag) {
        !           414:                        if (rootflag) {
        !           415:                                fp = fopen(LDKERFILE, "a");
        !           416:                                fprintf(fp, "HD=aha154x.a\n");
        !           417:                                fprintf(fp, "HDUNDEF=\"-u sdcon_\"\n");
        !           418:                                fprintf(fp, "HDPATCH=\"drvl_+130=sdcon_\"\n");
        !           419:                                fclose(fp);
        !           420:                        }
        !           421:                        sys("/etc/drvld -r /tmp/drv/aha154x", S_FATAL);
        !           422:                        fp = fopen(PATCHFILE, "a");
        !           423:                        fprintf(fp, "/conf/patch /mnt/drv/aha154x %s\n",
        !           424:                          ss_patch);
        !           425:                        if (rootflag)
        !           426:                                fprintf(fp,
        !           427:                                  "/conf/patch /mnt/coherent %s\n", ss_patch);
        !           428:                        fclose(fp);
        !           429:                } else
        !           430:                        printf("Patched driver at /tmp/drv/aha154x\n");
        !           431:        } /* end of "aha154x" stuff */
        !           432: 
        !           433: #if    0
        !           434:        if (yes_no("Is there another SCSI host adapter in your system"))
        !           435:                goto again;
        !           436: #endif
        !           437: }
        !           438: 
        !           439: void
        !           440: at()
        !           441: {
        !           442:        unsigned char at_patch[80];
        !           443:        FILE *fp;
        !           444:        int rootflag = 0;
        !           445:        int i;
        !           446: 
        !           447:        /* Make /tmp/drv if not there. */
        !           448:        if ((i = is_dir("/tmp/drv")) == 0)
        !           449:                sys("/bin/mkdir /tmp/drv", S_FATAL);
        !           450:        else if (i == -1)
        !           451:                fatal("/tmp/drv is not a directory");
        !           452: 
        !           453:        cls(0);
        !           454:        sys("/bin/cp /drv/at /tmp/drv/at", S_FATAL);
        !           455:        printf(
        !           456: "Most AT-compatible controllers work with NORMAL polling.\n\n"
        !           457: "Perstor controllers and some IDE hard drives require ALTERNATE polling.\n\n"
        !           458: "If you get \"<Watchdog Timeout>\" or \"at0:TO\" errors with normal polling,\n"
        !           459: "use alternate polling.\n\n");
        !           460: 
        !           461:        if (yes_no("Use ALTERNATE polling"))
        !           462:                strcpy(at_patch, "ATSREG_=0x1F7 ");
        !           463:        else
        !           464:                strcpy(at_patch, "ATSREG_=0x3F6 ");
        !           465:        sprintf(cmd, "/conf/patch /tmp/drv/at %s", at_patch);
        !           466:        sys(cmd, S_FATAL);
        !           467: 
        !           468:        if (bflag){
        !           469:                if (yes_no(
        !           470: "Will the COHERENT root partition be on an AT-type (non-SCSI) drive")) {
        !           471:                        ++rootflag;
        !           472:                        fp = fopen(LDKERFILE, "a");
        !           473:                        fprintf(fp, "HD=at.a\n");
        !           474:                        fprintf(fp, "HDUNDEF=\"-u atcon_\"\n");
        !           475:                        fprintf(fp, "HDPATCH=\"drvl_+110=atcon_\"\n");
        !           476:                        fclose(fp);
        !           477:                }
        !           478:                sys("/etc/drvld -r /tmp/drv/at", S_FATAL);
        !           479:                fp = fopen(PATCHFILE, "a");
        !           480:                fprintf(fp, "/conf/patch /mnt/drv/at %s\n", at_patch);
        !           481:                if (rootflag)
        !           482:                        fprintf(fp,
        !           483:                          "/conf/patch /mnt/coherent %s\n", at_patch);
        !           484:                fclose(fp);
        !           485:        } else
        !           486:                printf("Patched driver at /tmp/drv/at\n");
        !           487: }
        !           488: /* end of mkdev.c */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.