sboot.c revision 1.6 1 /* $NetBSD: sboot.c,v 1.6 2008/01/12 09:54:33 tsutsui Exp $ */
2
3 /*
4 *
5 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Charles D. Cranor
19 * and Seth Widoff.
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34 /*
35 * main driver, plus machdep stuff
36 */
37
38 #include "sboot.h"
39
40 void sboot(void);
41
42 extern char bootprog_rev[];
43
44 void
45 sboot(void)
46 {
47 char buf[128], *ebuf;
48
49 buf[0] = '0';
50 consinit();
51 printf("\nsboot: serial line bootstrap program (&end = %p) [%s]\n\n",
52 &end, bootprog_rev);
53 if (reboot) { /* global flag from AAstart.s */
54 reboot = 0;
55 printf("[rebooting...]\n");
56 buf[0] = 'b';
57 buf[1] = 0;
58 do_cmd(buf, &buf[1]);
59 }
60 for (;;) {
61 printf(">>> ");
62 ebuf = ngets(buf, sizeof(buf));
63 do_cmd(buf, ebuf);
64 }
65 /* not reached */
66 }
67
68 /*
69 * exit to rom
70 */
71
72 void
73 callrom(void)
74 {
75
76 __asm("trap #15; .word 0x0063");
77 }
78
79 /*
80 * do_cmd: do a command
81 */
82
83 void
84 do_cmd(char *buf, char *ebuf)
85 {
86
87 switch (*buf) {
88 case '\0':
89 return;
90 case 'a':
91 if (rev_arp()) {
92 printf("My ip address is: %d.%d.%d.%d\n",
93 myip[0], myip[1], myip[2], myip[3]);
94 printf("Server ip address is: %d.%d.%d.%d\n",
95 servip[0], servip[1], servip[2], servip[3]);
96 } else {
97 printf("Failed.\n");
98 }
99 return;
100 case 'e':
101 printf("exiting to ROM\n");
102 callrom();
103 return;
104 case 'f':
105 if (do_get_file() == 1) {
106 printf("Download Failed\n");
107 } else {
108 printf("Download was a success!\n");
109 }
110 return;
111 case 'b':
112 le_init();
113 if (rev_arp()) {
114 printf("My ip address is: %d.%d.%d.%d\n",
115 myip[0], myip[1], myip[2], myip[3]);
116 printf("Server ip address is: %d.%d.%d.%d\n",
117 servip[0], servip[1], servip[2], servip[3]);
118 } else {
119 printf("REVARP: Failed.\n");
120 return;
121 }
122 if (do_get_file() == 1) {
123 printf("Download Failed\n");
124 return;
125 } else {
126 printf("Download was a success!\n");
127 }
128 /*FALLTHROUGH*/
129 case 'g':
130 printf("Start @ 0x%x ... \n", LOAD_ADDR);
131 go(LOAD_ADDR, buf+1, ebuf);
132 return;
133 case 'h':
134 case '?':
135 printf("valid commands\n");
136 printf("a - send a RARP\n");
137 printf("b - boot the system\n");
138 printf("e - exit to ROM\n");
139 printf("f - ftp the boot file\n");
140 printf("g - execute the boot file\n");
141 printf("h - help\n");
142 printf("i - init LANCE enet chip\n");
143 return;
144 case 'i':
145 le_init();
146 return;
147 default:
148 printf("sboot: %s: Unknown command\n", buf);
149 }
150 }
151