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