1 /* $NetBSD: bootxx.c,v 1.15 2008/04/28 20:23:29 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 <sys/exec_elf.h>
46 #include <sys/exec_aout.h>
47 #include <machine/prom.h>
49 #include <lib/libsa/stand.h>
53 int copyboot(struct open_file
*, u_long
*);
56 * Boot device is derived from ROM provided information.
58 #define LOADADDR 0x11000 /* where to load level 2 bootstrap */
59 /* (l2 must relocate itself) */
61 extern int block_size
;
62 extern int block_count
; /* length of table */
64 extern int32_t block_table
[];
66 extern char bootprog_name
[], bootprog_rev
[];
78 printf("Boot: bug device: ctrl=%d, dev=%d\n",
79 bugargs
.ctrl_lun
, bugargs
.dev_lun
);
80 printf("\nbootxx: %s first level bootstrap program [%s]\n\n",
81 bootprog_name
, bootprog_rev
);
84 if (devopen(&f
, 0, &foo
)) {
85 printf("bootxx: open failed\n");
90 error
= copyboot(&f
, &addr
);
91 f
.f_dev
->dv_close(&f
);
93 bugexec((void *)addr
);
95 /* copyboot had a problem... */
100 copyboot(struct open_file
*fp
, u_long
*addr
)
104 char *laddr
= (char *) *addr
;
110 x
= (union boothead
*)laddr
;
113 printf("bootxx: no data!?!\n");
117 for (i
= 0; i
< block_count
; i
++) {
118 if ((blknum
= block_table
[i
]) == 0)
121 printf("bootxx: read block # %d = %d\n", i
, blknum
);
123 if ((fp
->f_dev
->dv_strategy
)(fp
->f_devdata
, F_READ
,
124 blknum
, block_size
, laddr
, &n
)) {
125 printf("bootxx: read failed\n");
128 if (n
!= block_size
) {
129 printf("bootxx: short read\n");
135 if (N_GETMAGIC(x
->ah
) == OMAGIC
)
136 *addr
+= sizeof(x
->ah
);
137 else if (memcmp(x
->eh
.e_ident
, ELFMAG
, SELFMAG
) == 0) {
138 Elf32_Phdr
*ep
= (Elf32_Phdr
*)(*addr
+ x
->eh
.e_phoff
);
139 *addr
+= ep
->p_offset
;
141 printf("bootxx: secondary bootstrap isn't an executable\n");