1 /* $NetBSD: bootxx.c,v 1.11 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>
43 #include <sys/bootblock.h>
44 #include <machine/mon.h>
49 int copyboot(struct open_file
*, char *);
52 * This is the address where we load the second-stage boot loader.
54 #define LOADADDR 0x4000
57 * The contents of the sun68k_bbinfo below are set by installboot(8)
58 * to hold the filesystem data of the second-stage boot program
59 * (typically `/ufsboot'): filesystem block size, # of filesystem
60 * blocks and the block numbers themselves.
62 struct shared_bbinfo bbinfo
= {
63 { SUN68K_BBINFO_MAGIC
},
65 SHARED_BBINFO_MAXBLOCKS
,
78 printf("bootxx: open...\n");
81 if (devopen(&f
, 0, &addr
)) {
82 putstr("bootxx: devopen failed\n");
86 addr
= (char*)LOADADDR
;
87 error
= copyboot(&f
, addr
);
88 f
.f_dev
->dv_close(&f
);
91 printf("bootxx: start 0x%x\n", (long)addr
);
96 /* copyboot had a problem... */
101 copyboot(struct open_file
*fp
, char *addr
)
107 /* Need to use a buffer that can be mapped into DVMA space. */
108 buf
= alloc(bbinfo
.bbi_block_size
);
110 panic("bootxx: alloc failed");
112 for (i
= 0; i
< bbinfo
.bbi_block_count
; i
++) {
114 if ((blknum
= bbinfo
.bbi_block_table
[i
]) == 0)
118 printf("bootxx: block # %d = %d\n", i
, blknum
);
120 if ((fp
->f_dev
->dv_strategy
)(fp
->f_devdata
, F_READ
, blknum
,
121 bbinfo
.bbi_block_size
, buf
, &n
))
123 putstr("bootxx: read failed\n");
126 if (n
!= bbinfo
.bbi_block_size
) {
127 putstr("bootxx: short read\n");
130 memcpy(addr
, buf
, bbinfo
.bbi_block_size
);
131 addr
+= bbinfo
.bbi_block_size
;