1 /* $NetBSD: bootyy.c,v 1.4 2008/04/28 20:23:38 martin Exp $ */
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * This is a generic "first-stage" boot program.
35 * Note that this program has absolutely no filesystem knowledge!
37 * Instead, this uses a table of disk block numbers that are
38 * filled in by the installboot program such that this program
39 * can load the "second-stage" boot program.
42 #include <sys/param.h>
45 #include <machine/mon.h>
50 int copyboot(struct open_file
*, char *);
52 /* This determines the largest boot program we can load. */
53 #define MAXBLOCKNUM 64
56 * The block size used in the Sun Network Disk protocol.
58 #define SUNND_BSIZE (512)
61 * The first block number we request. This is related to historical
62 * values; in 4.2BSD, the disklabel and the first stage boot program
63 * are together called the bootblocks, and take up the first BBSIZE
64 * bytes of the disk. In 4.2BSD, BBSIZE was 8192 and the disk device
65 * block size was 512 bytes (see the definition of SUNND_BSIZE below),
66 * making the number of blocks taken up by the bootblocks (BBSIZE /
67 * SUNND_BSIZE). This value for FIRSTBLOCKNUM assumes that the
68 * second-stage boot begins immediately after the bootblocks. The
69 * second-stage boot always runs contiguously for MAXBLOCKNUM blocks.
70 * FIRSTBLOCKNUM can be increased, and MAXBLOCKNUM can be adjusted, as
71 * long as they match up with however you're putting together the disk
72 * image that is being served to this client.
74 #define FIRSTBLOCKNUM (8192 / SUNND_BSIZE)
76 int block_size
= SUNND_BSIZE
; /* default */
87 printf("bootyy: open...\n");
90 if (devopen(&f
, 0, &addr
)) {
91 printf("bootyy: devopen failed\n");
95 addr
= (char *)KERN_LOADADDR
;
96 error
= copyboot(&f
, addr
);
97 f
.f_dev
->dv_close(&f
);
100 printf("bootyy: start 0x%x\n", (long)addr
);
105 /* copyboot had a problem... */
110 copyboot(struct open_file
*fp
, char *addr
)
116 /* Need to use a buffer that can be mapped into DVMA space. */
117 buf
= alloc(block_size
);
119 panic("bootyy: alloc failed");
121 for (i
= 0, blknum
= FIRSTBLOCKNUM
; i
< MAXBLOCKNUM
; i
++, blknum
++) {
124 printf("bootyy: block # %d = %d\n", i
, blknum
);
126 if ((fp
->f_dev
->dv_strategy
)(fp
->f_devdata
, F_READ
,
127 blknum
, block_size
, buf
, &n
))
129 printf("bootyy: read failed\n");
132 if (n
!= block_size
) {
133 printf("bootyy: short read\n");
136 memcpy(addr
, buf
, block_size
);