[BACK]Return to bootxx.c CVS log [TXT][DIR] Up to [local] / sys / arch / mvme68k / stand / bootxx

Annotation of sys/arch/mvme68k/stand/bootxx/bootxx.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: bootxx.c,v 1.7 2003/08/20 00:24:43 deraadt Exp $ */
                      2: /*     $NetBSD: bootxx.c,v 1.5 1995/10/13 21:44:57 gwr Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 1994 Paul Kranenburg
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *      This product includes software developed by Paul Kranenburg.
                     19:  * 4. The name of the author may not be used to endorse or promote products
                     20:  *    derived from this software without specific prior written permission
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     23:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     24:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     25:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     26:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     27:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     28:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     29:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     30:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     31:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     32:  */
                     33:
                     34: /*
                     35:  * This is a generic "first-stage" boot program.
                     36:  *
                     37:  * Note that this program has absolutely no filesystem knowledge!
                     38:  *
                     39:  * Instead, this uses a table of disk block numbers that are
                     40:  * filled in by the installboot program such that this program
                     41:  * can load the "second-stage" boot program.
                     42:  */
                     43:
                     44: #include <sys/param.h>
                     45: #include <sys/time.h>
                     46: #include <sys/exec.h>
                     47: #include <machine/prom.h>
                     48:
                     49: #include "stand.h"
                     50: #include "libsa.h"
                     51: #include "libbug.h"
                     52:
                     53: /*
                     54:  * Boot device is derived from ROM provided information.
                     55:  */
                     56: #define LOADADDR       0x6F0000 /* where to load level 2 bootstrap */
                     57:                                /* (l2 must relocate itself) */
                     58:
                     59: /* This determines the largest boot program we can load. */
                     60: #define MAXBLOCKNUM    64
                     61:
                     62: /*
                     63:  * These three names are known by installboot.
                     64:  * The block_table contains starting block numbers,
                     65:  * in terms of 512-byte blocks.  Each non-zero value
                     66:  * will result in a read of block_size bytes.
                     67:  */
                     68: int            block_size = 512;       /* default */
                     69: int            block_count = MAXBLOCKNUM;      /* length of table */
                     70: daddr_t        block_table[MAXBLOCKNUM] = { 0 };
                     71:
                     72: extern         char *version;
                     73:
                     74: static int
                     75: copyboot(struct open_file *fp, char *addr)
                     76: {
                     77:        int     n, i, blknum;
                     78:        struct exec *x;
                     79:
                     80:        addr -= sizeof(struct exec); /* assume OMAGIC, verify below */
                     81:        x = (struct exec *)addr;
                     82:
                     83:        if (!block_count) {
                     84:                printf("bootxx: no data!?!\n");
                     85:                return -1;
                     86:        }
                     87:
                     88:        for (i = 0; i < block_count; i++) {
                     89:
                     90:                if ((blknum = block_table[i]) == 0)
                     91:                        break;
                     92:
                     93: #ifdef DEBUG
                     94:                printf("bootxx: read block # %d = %d\n", i, blknum);
                     95: #endif
                     96:                if ((fp->f_dev->dv_strategy)(fp->f_devdata, F_READ,
                     97:                    blknum, block_size, addr, &n)) {
                     98:                        printf("bootxx: read failed\n");
                     99:                        return -1;
                    100:                }
                    101:                if (n != block_size) {
                    102:                        printf("bootxx: short read\n");
                    103:                        return -1;
                    104:                }
                    105:                addr += block_size;
                    106:        }
                    107:
                    108:        if (N_GETMAGIC(*x) != OMAGIC) {
                    109:                printf("bootxx: secondary bootstrap isn't in OMAGIC format\n");
                    110:                return(-1);
                    111:        }
                    112:
                    113:        return 0;
                    114: }
                    115:
                    116: main(int argc, char *argv[])
                    117: {
                    118:        struct open_file        f;
                    119:        char    *addr;
                    120:        int n, error;
                    121:
                    122:        printf("Boot: bug device: ctrl=%d, dev=%d\n",
                    123:            bugargs.ctrl_lun, bugargs.dev_lun);
                    124:        printf("\nbootxx: first level bootstrap program [%s]\n\n", version);
                    125:
                    126:        f.f_flags = F_RAW;
                    127:        if (devopen(&f, 0, &addr)) {
                    128:                printf("bootxx: open failed\n");
                    129:                _rtt();
                    130:        }
                    131:
                    132:        addr = (char *)LOADADDR;
                    133:        error = copyboot(&f, addr);
                    134:        f.f_dev->dv_close(&f);
                    135:        if (!error) {
                    136:                bugexec((void (*)(void))addr + 8);
                    137:        }
                    138:        /* copyboot had a problem... */
                    139:        _rtt();
                    140: }

CVSweb