xref: /netbsd/sys/arch/hp300/stand/uboot/uboot.c (revision bf9ec67e)
1 /*	$NetBSD: uboot.c,v 1.9 2002/03/16 06:20:08 gmcgarry Exp $	*/
2 
3 /*-
4  * Copyright (c) 1982, 1986, 1990, 1993
5  *	The Regents of the University of California.  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 the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)boot.c	8.1 (Berkeley) 6/10/93
36  */
37 
38 #include <sys/param.h>
39 #include <sys/boot_flag.h>
40 
41 #include <lib/libsa/stand.h>
42 
43 #include <hp300/stand/common/samachdep.h>
44 
45 /*
46  * Boot program... bits in `howto' determine whether boot stops to
47  * ask for system name.	 Boot device is derived from ROM provided
48  * information.
49  */
50 
51 char line[100];
52 
53 extern	u_int opendev;
54 extern	char *lowram;
55 extern	int noconsole;
56 
57 /*
58  * XXX UFS accepts a /, NFS doesn't.
59  */
60 char *name;
61 char *names[] = {
62 	"netbsd",		"netbsd.gz",
63 	"netbsd.bak",		"netbsd.bak.gz",
64 	"netbsd.old",		"netbsd.old.gz",
65 	"onetbsd",		"onetbsd.gz",
66 	NULL
67 };
68 #define NUMNAMES	(sizeof(names) / sizeof(char *))
69 
70 static int bdev, badapt, bctlr, bunit, bpart;
71 
72 void main __P((void));
73 void getbootdev __P((int *));
74 
75 void
76 main()
77 {
78 	int currname = 0;
79 
80 	printf("\n");
81 	printf(">> %s, Revision %s\n", bootprog_name, bootprog_rev);
82 	printf(">> (%s, %s)\n", bootprog_maker, bootprog_date);
83 	printf(">> HP 9000/%s SPU\n", getmachineid());
84 	printf(">> Enter \"reset\" to reset system.\n");
85 
86 	bdev   = B_TYPE(bootdev);
87 	badapt = B_ADAPTOR(bootdev);
88 	bctlr  = B_CONTROLLER(bootdev);
89 	bunit  = B_UNIT(bootdev);
90 	bpart  = B_PARTITION(bootdev);
91 
92 	for (;;) {
93 		name = names[currname++];
94 		if (currname == NUMNAMES)
95 			currname = 0;
96 
97 		if (!noconsole) {
98 			howto = 0;
99 			getbootdev(&howto);
100 		} else
101 			printf(": %s\n", name);
102 		exec_hp300(name, (u_long)lowram, howto);
103 		printf("boot: %s\n", strerror(errno));
104 	}
105 }
106 
107 void
108 getbootdev(howto)
109 	int *howto;
110 {
111 	char c, *ptr = line;
112 
113 	printf("Boot: [[[%s%d%c:]%s][-a][-c][-d][-s][-v][-q]] :- ",
114 	    devsw[bdev].dv_name, bctlr + (8 * badapt), 'a' + bpart, name);
115 
116 	if (tgets(line)) {
117 		if (strcmp(line, "reset") == 0) {
118 			call_req_reboot();      /* reset machine */
119 			printf("panic: can't reboot, halting\n");
120 			asm("stop #0x2700");
121 		}
122 		while ((c = *ptr) != '\0') {
123 			while (c == ' ')
124 				c = *++ptr;
125 			if (!c)
126 				return;
127 			if (c == '-')
128 				while ((c = *++ptr) && c != ' ')
129 					BOOT_FLAG(c, *howto);
130 			else {
131 				name = ptr;
132 				while ((c = *++ptr) && c != ' ');
133 				if (c)
134 					*ptr++ = 0;
135 			}
136 		}
137 	} else
138 		printf("\n");
139 }
140