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