Home | History | Annotate | Line # | Download | only in sboot
sboot.c revision 1.3
      1 /*	$NetBSD: sboot.c,v 1.3 1998/01/05 07:03:06 perry 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()
     41 
     42 {
     43   char * mesg;
     44   char buf[128], *ebuf;
     45   buf[0] = '0';
     46   consinit();
     47   printf("\nsboot: serial line bootstrap program (&end = %x)\n\n", &end);
     48   if (reboot) {  /* global flag from AAstart.s */
     49     reboot = 0;
     50     printf("[rebooting...]\n");
     51     buf[0] = 'b';
     52     buf[1] = 0;
     53     do_cmd(buf, &buf[1]);
     54   }
     55   while (1) {
     56     printf(">>> ");
     57     ebuf = ngets(buf, sizeof(buf));
     58     do_cmd(buf, ebuf);
     59   }
     60   /* not reached */
     61 }
     62 
     63 /*
     64  * exit to rom
     65  */
     66 
     67 void callrom ()
     68 {
     69   asm("trap #15; .word 0x0063");
     70 }
     71 
     72 /*
     73  * do_cmd: do a command
     74  */
     75 
     76 void do_cmd(buf, ebuf)
     77 
     78 char *buf, *ebuf;
     79 
     80 {
     81   switch (*buf) {
     82   case '\0':
     83     return;
     84   case 'a':
     85     if ( rev_arp() ) {
     86 	printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
     87 		myip[1], myip[2], myip[3]);
     88 	printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
     89 		servip[1], servip[2], servip[3]);
     90     } else  {
     91 	printf ("Failed.\n");
     92     }
     93     return;
     94   case 'e':
     95     printf("exiting to ROM\n");
     96     callrom();
     97     return;
     98   case 'f':
     99     if (do_get_file() == 1) {
    100       printf("Download Failed\n");
    101     } else {
    102       printf("Download was a success!\n");
    103     }
    104     return;
    105   case 'b':
    106     le_init();
    107     if ( rev_arp() ) {
    108 	printf ("My ip address is: %d.%d.%d.%d\n", myip[0],
    109 		myip[1], myip[2], myip[3]);
    110 	printf ("Server ip address is: %d.%d.%d.%d\n", servip[0],
    111 		servip[1], servip[2], servip[3]);
    112     } else  {
    113 	printf ("REVARP: Failed.\n");
    114 	return;
    115     }
    116     if (do_get_file() == 1) {
    117         printf("Download Failed\n");
    118         return;
    119     } else {
    120         printf("Download was a success!\n");
    121     }
    122     /*FALLTHROUGH*/
    123   case 'g':
    124     printf("Start @ 0x%x ... \n", LOAD_ADDR);
    125     go(LOAD_ADDR, buf+1, ebuf);
    126     return;
    127   case 'h':
    128   case '?':
    129     printf("valid commands\n");
    130     printf("a - send a RARP\n");
    131     printf("b - boot the system\n");
    132     printf("e - exit to ROM\n");
    133     printf("f - ftp the boot file\n");
    134     printf("g - execute the boot file\n");
    135     printf("h - help\n");
    136     printf("i - init LANCE enet chip\n");
    137     return;
    138   case 'i':
    139     le_init();
    140     return;
    141   default:
    142     printf("sboot: %s: Unknown command\n", buf);
    143   }
    144 }
    145