[BACK]Return to boot1.c CVS log [TXT][DIR] Up to [local] / sys / arch / landisk / stand / xxboot

Annotation of sys/arch/landisk/stand/xxboot/boot1.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: boot1.c,v 1.1 2006/11/08 17:46:56 deraadt Exp $       */
                      2: /*     $NetBSD: boot1.c,v 1.1 2006/09/01 21:26:19 uwe Exp $    */
                      3:
                      4: /*-
                      5:  * Copyright (c) 2003 The NetBSD Foundation, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to The NetBSD Foundation
                      9:  * by David Laight.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. All advertising materials mentioning features or use of this software
                     20:  *    must display the following acknowledgement:
                     21:  *        This product includes software developed by the NetBSD
                     22:  *        Foundation, Inc. and its contributors.
                     23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
                     24:  *    contributors may be used to endorse or promote products derived
                     25:  *    from this software without specific prior written permission.
                     26:  *
                     27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
                     28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
                     31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     37:  * POSSIBILITY OF SUCH DAMAGE.
                     38:  */
                     39:
                     40: #include <sys/param.h>
                     41: #include <lib/libsa/stand.h>
                     42: #include <lib/libsa/ufs.h>
                     43:
                     44: #include <sys/disklabel.h>
                     45:
                     46: #define        XSTR(x) #x
                     47: #define        STR(x)  XSTR(x)
                     48:
                     49: static uint32_t bios_sector;
                     50:
                     51: const char *boot1(uint32_t *);
                     52: void putstr(const char *str);
                     53: int raise(int sig);
                     54: int blkdevstrategy(void *, int, daddr_t, size_t, void *, size_t *);
                     55: int blkdevopen(struct open_file *, ...);
                     56: int blkdevclose(struct open_file *);
                     57:
                     58:
                     59: extern struct disklabel ptn_disklabel;
                     60:
                     61: struct fs_ops file_system[] = {
                     62:        { ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek,
                     63:          ufs_stat, ufs_readdir },
                     64: };
                     65: int nfsys = NENTS(file_system);
                     66:
                     67: struct devsw devsw[] = {
                     68:        { "dk", blkdevstrategy, blkdevopen, blkdevclose, noioctl },
                     69: };
                     70: int     ndevs = NENTS(devsw);
                     71:
                     72: const char *
                     73: boot1(uint32_t *sector)
                     74: {
                     75:         struct stat sb;
                     76:        int fd;
                     77:
                     78:        bios_sector = *sector;
                     79:
                     80:        putstr("\r\nOpenBSD/" MACHINE " Primary Bootstrap\r\n");
                     81:
                     82:        do {
                     83:                /*
                     84:                 * Nothing at the start of the MBR partition, fallback on
                     85:                 * partition 'a' from the disklabel in this MBR partition.
                     86:                 */
                     87:                if (ptn_disklabel.d_magic != DISKMAGIC)
                     88:                        break;
                     89:                if (ptn_disklabel.d_magic2 != DISKMAGIC)
                     90:                        break;
                     91:                if (ptn_disklabel.d_partitions[0].p_fstype == FS_UNUSED)
                     92:                        break;
                     93:
                     94:                bios_sector = ptn_disklabel.d_partitions[0].p_offset;
                     95:                *sector = bios_sector;
                     96:                fd = open("boot", 0);
                     97:        } while (0);
                     98:
                     99:        if (fd == -1 || fstat(fd, &sb) == -1)
                    100:                return "Can't open /boot.\r\n";
                    101:
                    102: #if 0
                    103:        if (sb.st_size > SECONDARY_MAX_LOAD)
                    104:                return "/boot too large.\r\n";
                    105: #endif
                    106:
                    107:        if (read(fd, (void *)LOADADDRESS, sb.st_size) != sb.st_size)
                    108:                return "/boot load failed.\r\n";
                    109:
                    110:        if (*(uint32_t *)(LOADADDRESS + 4) != 0x20041110)
                    111:                return "Invalid /boot file format.\r\n";
                    112:
                    113:        return 0;
                    114: }
                    115:
                    116: int
                    117: blkdevopen(struct open_file *f, ...)
                    118: {
                    119:        return 0;
                    120: }
                    121: int
                    122: blkdevclose(struct open_file *f)
                    123: {
                    124:        return 0;
                    125: }
                    126:
                    127: int
                    128: blkdevstrategy(void *devdata, int flag, daddr_t dblk, size_t size, void *buf, size_t *rsize)
                    129: {
                    130:
                    131:        if (flag != F_READ)
                    132:                return EROFS;
                    133:
                    134:        if (size & (DEV_BSIZE - 1))
                    135:                return EINVAL;
                    136:
                    137:        if (rsize)
                    138:                *rsize = size;
                    139:
                    140:        if (size != 0 && readsects(0x40, bios_sector + dblk, buf,
                    141:                                   size / DEV_BSIZE) != 0)
                    142:                return EIO;
                    143:
                    144:        return 0;
                    145: }
                    146:
                    147: /* ARGUSED */
                    148: int
                    149: raise(int sig)
                    150: {
                    151:
                    152:        return 0;
                    153: }
                    154:
                    155: void
                    156: twiddle(void)
                    157: {
                    158:        static int pos;
                    159:
                    160:        putchar("|/-\\"[pos++ & 3]);
                    161:        putchar('\b');
                    162: }
                    163:
                    164: int
                    165: devopen(struct open_file *f, const char *fname, char **file)
                    166: {
                    167:        *file = (char *)fname;
                    168:        f->f_flags |= F_NODEV;
                    169:        f->f_dev = &devsw[0];
                    170:        return (0);
                    171: }

CVSweb