sboot.c revision 1.2 1 /*
2 *
3 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles D. Cranor
17 * and Seth Widoff.
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 * main driver, plus machdep stuff
34 */
35
36 #include "sboot.h"
37
38 void sboot()
39
40 {
41 char * mesg;
42 char buf[128], *ebuf;
43 buf[0] = '0';
44 consinit();
45 printf("\nsboot: serial line bootstrap program (&end = %x)\n\n", &end);
46 if (reboot) { /* global flag from AAstart.s */
47 reboot = 0;
48 printf("[rebooting...]\n");
49 buf[0] = 'b';
50 buf[1] = 0;
51 do_cmd(buf, &buf[1]);
52 }
53 while (1) {
54 printf(">>> ");
55 ebuf = ngets(buf, sizeof(buf));
56 do_cmd(buf, ebuf);
57 }
58 /* not reached */
59 }
60
61 /*
62 * exit to rom
63 */
64
65 void callrom ()
66 {
67 asm("trap #15; .word 0x0063");
68 }
69
70 /*
71 * do_cmd: do a command
72 */
73
74 void do_cmd(buf, ebuf)
75
76 char *buf, *ebuf;
77
78 {
79 switch (*buf) {
80 case '\0':
81 return;
82 case 'a':
83 if ( rev_arp() ) {
84 printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
85 myip[1], myip[2], myip[3]);
86 printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
87 servip[1], servip[2], servip[3]);
88 } else {
89 printf ("Failed.\n");
90 }
91 return;
92 case 'e':
93 printf("exiting to ROM\n");
94 callrom();
95 return;
96 case 'f':
97 if (do_get_file() == 1) {
98 printf("Download Failed\n");
99 } else {
100 printf("Download was a success!\n");
101 }
102 return;
103 case 'b':
104 le_init();
105 if ( rev_arp() ) {
106 printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
107 myip[1], myip[2], myip[3]);
108 printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
109 servip[1], servip[2], servip[3]);
110 } else {
111 printf ("REVARP: Failed.\n");
112 return;
113 }
114 if (do_get_file() == 1) {
115 printf("Download Failed\n");
116 return;
117 } else {
118 printf("Download was a success!\n");
119 }
120 /*FALLTHROUGH*/
121 case 'g':
122 printf("Start @ 0x%x ... \n", LOAD_ADDR);
123 go(LOAD_ADDR, buf+1, ebuf);
124 return;
125 case 'h':
126 case '?':
127 printf("valid commands\n");
128 printf("a - send a RARP\n");
129 printf("b - boot the system\n");
130 printf("e - exit to ROM\n");
131 printf("f - ftp the boot file\n");
132 printf("g - execute the boot file\n");
133 printf("h - help\n");
134 printf("i - init LANCE enet chip\n");
135 return;
136 case 'i':
137 le_init();
138 return;
139 default:
140 printf("sboot: %s: Unknown command\n", buf);
141 }
142 }
143