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