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