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