1 /* $NetBSD: sboot.c,v 1.7 2011/02/02 17:53:41 chuck Exp $ */ 2 3 /* 4 * Copyright (c) 1995 Charles D. Cranor and Seth Widoff 5 * 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 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 /* 28 * main driver, plus machdep stuff 29 */ 30 31 #include "sboot.h" 32 33 void sboot(void); 34 35 extern char bootprog_rev[]; 36 37 void 38 sboot(void) 39 { 40 char buf[128], *ebuf; 41 42 buf[0] = '0'; 43 consinit(); 44 printf("\nsboot: serial line bootstrap program (&end = %p) [%s]\n\n", 45 &end, bootprog_rev); 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 for (;;) { 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 66 callrom(void) 67 { 68 69 __asm("trap #15; .word 0x0063"); 70 } 71 72 /* 73 * do_cmd: do a command 74 */ 75 76 void 77 do_cmd(char *buf, char *ebuf) 78 { 79 80 switch (*buf) { 81 case '\0': 82 return; 83 case 'a': 84 if (rev_arp()) { 85 printf("My ip address is: %d.%d.%d.%d\n", 86 myip[0], myip[1], myip[2], myip[3]); 87 printf("Server ip address is: %d.%d.%d.%d\n", 88 servip[0], servip[1], servip[2], servip[3]); 89 } else { 90 printf("Failed.\n"); 91 } 92 return; 93 case 'e': 94 printf("exiting to ROM\n"); 95 callrom(); 96 return; 97 case 'f': 98 if (do_get_file() == 1) { 99 printf("Download Failed\n"); 100 } else { 101 printf("Download was a success!\n"); 102 } 103 return; 104 case 'b': 105 le_init(); 106 if (rev_arp()) { 107 printf("My ip address is: %d.%d.%d.%d\n", 108 myip[0], myip[1], myip[2], myip[3]); 109 printf("Server ip address is: %d.%d.%d.%d\n", 110 servip[0], servip[1], servip[2], servip[3]); 111 } else { 112 printf("REVARP: Failed.\n"); 113 return; 114 } 115 if (do_get_file() == 1) { 116 printf("Download Failed\n"); 117 return; 118 } else { 119 printf("Download was a success!\n"); 120 } 121 /*FALLTHROUGH*/ 122 case 'g': 123 printf("Start @ 0x%x ... \n", LOAD_ADDR); 124 go(LOAD_ADDR, buf+1, ebuf); 125 return; 126 case 'h': 127 case '?': 128 printf("valid commands\n"); 129 printf("a - send a RARP\n"); 130 printf("b - boot the system\n"); 131 printf("e - exit to ROM\n"); 132 printf("f - ftp the boot file\n"); 133 printf("g - execute the boot file\n"); 134 printf("h - help\n"); 135 printf("i - init LANCE enet chip\n"); 136 return; 137 case 'i': 138 le_init(); 139 return; 140 default: 141 printf("sboot: %s: Unknown command\n", buf); 142 } 143 } 144