Home | History | Annotate | Line # | Download | only in pxeboot
main.c revision 1.4.2.2
      1  1.4.2.2  thorpej /*	$NetBSD: main.c,v 1.4.2.2 2002/02/20 03:00:28 thorpej Exp $	*/
      2  1.4.2.2  thorpej 
      3  1.4.2.2  thorpej /*
      4  1.4.2.2  thorpej  * Copyright (c) 1996
      5  1.4.2.2  thorpej  * 	Matthias Drochner.  All rights reserved.
      6  1.4.2.2  thorpej  * Copyright (c) 1996
      7  1.4.2.2  thorpej  * 	Perry E. Metzger.  All rights reserved.
      8  1.4.2.2  thorpej  *
      9  1.4.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.4.2.2  thorpej  * modification, are permitted provided that the following conditions
     11  1.4.2.2  thorpej  * are met:
     12  1.4.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.4.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.4.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.4.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.4.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.4.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.4.2.2  thorpej  *    must display the following acknowledgements:
     19  1.4.2.2  thorpej  *	This product includes software developed for the NetBSD Project
     20  1.4.2.2  thorpej  *	by Matthias Drochner.
     21  1.4.2.2  thorpej  *	This product includes software developed for the NetBSD Project
     22  1.4.2.2  thorpej  *	by Perry E. Metzger.
     23  1.4.2.2  thorpej  * 4. The names of the authors may not be used to endorse or promote products
     24  1.4.2.2  thorpej  *    derived from this software without specific prior written permission.
     25  1.4.2.2  thorpej  *
     26  1.4.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     27  1.4.2.2  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     28  1.4.2.2  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     29  1.4.2.2  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     30  1.4.2.2  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     31  1.4.2.2  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     32  1.4.2.2  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     33  1.4.2.2  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     34  1.4.2.2  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     35  1.4.2.2  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     36  1.4.2.2  thorpej  *
     37  1.4.2.2  thorpej  */
     38  1.4.2.2  thorpej 
     39  1.4.2.2  thorpej #include <lib/libkern/libkern.h>
     40  1.4.2.2  thorpej 
     41  1.4.2.2  thorpej #include <lib/libsa/stand.h>
     42  1.4.2.2  thorpej 
     43  1.4.2.2  thorpej #include <libi386.h>
     44  1.4.2.2  thorpej #include "pxeboot.h"
     45  1.4.2.2  thorpej 
     46  1.4.2.2  thorpej int errno;
     47  1.4.2.2  thorpej int debug;
     48  1.4.2.2  thorpej int try_bootp = 1;
     49  1.4.2.2  thorpej 
     50  1.4.2.2  thorpej extern char	bootprog_name[], bootprog_rev[], bootprog_date[],
     51  1.4.2.2  thorpej 		bootprog_maker[];
     52  1.4.2.2  thorpej 
     53  1.4.2.2  thorpej #define TIMEOUT 5
     54  1.4.2.2  thorpej 
     55  1.4.2.2  thorpej int	main(void);
     56  1.4.2.2  thorpej 
     57  1.4.2.2  thorpej void	command_help __P((char *));
     58  1.4.2.2  thorpej void	command_quit __P((char *));
     59  1.4.2.2  thorpej void	command_boot __P((char *));
     60  1.4.2.2  thorpej 
     61  1.4.2.2  thorpej const struct bootblk_command commands[] = {
     62  1.4.2.2  thorpej 	{ "help",	command_help },
     63  1.4.2.2  thorpej 	{ "?",		command_help },
     64  1.4.2.2  thorpej 	{ "quit",	command_quit },
     65  1.4.2.2  thorpej 	{ "boot",	command_boot },
     66  1.4.2.2  thorpej 	{ NULL,		NULL },
     67  1.4.2.2  thorpej };
     68  1.4.2.2  thorpej 
     69  1.4.2.2  thorpej #ifdef COMPAT_OLDBOOT
     70  1.4.2.2  thorpej int
     71  1.4.2.2  thorpej parsebootfile(const char *fname, char **fsname, char **devname,
     72  1.4.2.2  thorpej     u_int *unit, u_int *partition, const char **file)
     73  1.4.2.2  thorpej {
     74  1.4.2.2  thorpej 	return (EINVAL);
     75  1.4.2.2  thorpej }
     76  1.4.2.2  thorpej 
     77  1.4.2.2  thorpej int
     78  1.4.2.2  thorpej biosdisk_gettype(struct open_file *f)
     79  1.4.2.2  thorpej {
     80  1.4.2.2  thorpej 	return (0);
     81  1.4.2.2  thorpej }
     82  1.4.2.2  thorpej #endif
     83  1.4.2.2  thorpej 
     84  1.4.2.2  thorpej static int
     85  1.4.2.2  thorpej bootit(const char *filename, int howto)
     86  1.4.2.2  thorpej {
     87  1.4.2.2  thorpej 	if (exec_netbsd(filename, 0, howto) < 0)
     88  1.4.2.2  thorpej 		printf("boot: %s\n", strerror(errno));
     89  1.4.2.2  thorpej 	else
     90  1.4.2.2  thorpej 		printf("boot returned\n");
     91  1.4.2.2  thorpej 	return (-1);
     92  1.4.2.2  thorpej }
     93  1.4.2.2  thorpej 
     94  1.4.2.2  thorpej static void
     95  1.4.2.2  thorpej print_banner(void)
     96  1.4.2.2  thorpej {
     97  1.4.2.2  thorpej 	int base = getbasemem();
     98  1.4.2.2  thorpej 	int ext = getextmem();
     99  1.4.2.2  thorpej 
    100  1.4.2.2  thorpej 	printf("\n"
    101  1.4.2.2  thorpej 	       ">> %s, Revision %s\n"
    102  1.4.2.2  thorpej 	       ">> (%s, %s)\n"
    103  1.4.2.2  thorpej 	       ">> Memory: %d/%d k\n",
    104  1.4.2.2  thorpej 	       bootprog_name, bootprog_rev,
    105  1.4.2.2  thorpej 	       bootprog_maker, bootprog_date,
    106  1.4.2.2  thorpej 	       base, ext);
    107  1.4.2.2  thorpej }
    108  1.4.2.2  thorpej 
    109  1.4.2.2  thorpej int
    110  1.4.2.2  thorpej main(void)
    111  1.4.2.2  thorpej {
    112  1.4.2.2  thorpej         char c;
    113  1.4.2.2  thorpej 
    114  1.4.2.2  thorpej #ifdef SUPPORT_SERIAL
    115  1.4.2.2  thorpej 	initio(SUPPORT_SERIAL);
    116  1.4.2.2  thorpej #else
    117  1.4.2.2  thorpej 	initio(CONSDEV_PC);
    118  1.4.2.2  thorpej #endif
    119  1.4.2.2  thorpej 	gateA20();
    120  1.4.2.2  thorpej 
    121  1.4.2.2  thorpej 	print_banner();
    122  1.4.2.2  thorpej 
    123  1.4.2.2  thorpej 	printf("Press return to boot now, any other key for boot menu\n");
    124  1.4.2.2  thorpej 	printf("Starting in ");
    125  1.4.2.2  thorpej 
    126  1.4.2.2  thorpej 	c = awaitkey(TIMEOUT, 1);
    127  1.4.2.2  thorpej 	if ((c != '\r') && (c != '\n') && (c != '\0')) {
    128  1.4.2.2  thorpej 		printf("type \"?\" or \"help\" for help.\n");
    129  1.4.2.2  thorpej 		bootmenu();	/* does not return */
    130  1.4.2.2  thorpej 	}
    131  1.4.2.2  thorpej 
    132  1.4.2.2  thorpej 	/*
    133  1.4.2.2  thorpej 	 * The file name provided here is just a default.  If the
    134  1.4.2.2  thorpej 	 * DHCP server provides a file name, we'll use that instead.
    135  1.4.2.2  thorpej 	 */
    136  1.4.2.2  thorpej 	bootit("netbsd", 0);
    137  1.4.2.2  thorpej 
    138  1.4.2.2  thorpej 	/*
    139  1.4.2.2  thorpej 	 * If that fails, let the BIOS try the next boot device.
    140  1.4.2.2  thorpej 	 */
    141  1.4.2.2  thorpej 	return (1);
    142  1.4.2.2  thorpej }
    143  1.4.2.2  thorpej 
    144  1.4.2.2  thorpej /* ARGSUSED */
    145  1.4.2.2  thorpej void
    146  1.4.2.2  thorpej command_help(char *arg)
    147  1.4.2.2  thorpej {
    148  1.4.2.2  thorpej 	printf("commands are:\n"
    149  1.4.2.2  thorpej 	       "boot [filename] [-adsqv]\n"
    150  1.4.2.2  thorpej 	       "     (ex. \"netbsd.old -s\"\n"
    151  1.4.2.2  thorpej 	       "help|?\n"
    152  1.4.2.2  thorpej 	       "quit\n");
    153  1.4.2.2  thorpej }
    154  1.4.2.2  thorpej 
    155  1.4.2.2  thorpej /* ARGSUSED */
    156  1.4.2.2  thorpej void
    157  1.4.2.2  thorpej command_quit(char *arg)
    158  1.4.2.2  thorpej {
    159  1.4.2.2  thorpej 	printf("Exiting... goodbye...\n");
    160  1.4.2.2  thorpej 	exit(0);
    161  1.4.2.2  thorpej }
    162  1.4.2.2  thorpej 
    163  1.4.2.2  thorpej void
    164  1.4.2.2  thorpej command_boot(char *arg)
    165  1.4.2.2  thorpej {
    166  1.4.2.2  thorpej 	char *filename;
    167  1.4.2.2  thorpej 	int howto;
    168  1.4.2.2  thorpej 
    169  1.4.2.2  thorpej 	if (parseboot(arg, &filename, &howto))
    170  1.4.2.2  thorpej 		bootit(filename, howto);
    171  1.4.2.2  thorpej }
    172