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