2005-03-08 19:53:11 +01:00
|
|
|
/**************************************************************************
|
2010-04-19 21:16:01 +02:00
|
|
|
iPXE - Network Bootstrap Program
|
2005-03-08 19:53:11 +01:00
|
|
|
|
|
|
|
Literature dealing with the network protocols:
|
|
|
|
ARP - RFC826
|
|
|
|
RARP - RFC903
|
|
|
|
UDP - RFC768
|
|
|
|
BOOTP - RFC951, RFC2132 (vendor extensions)
|
|
|
|
DHCP - RFC2131, RFC2132 (options)
|
|
|
|
TFTP - RFC1350, RFC2347 (options), RFC2348 (blocksize), RFC2349 (tsize)
|
|
|
|
RPC - RFC1831, RFC1832 (XDR), RFC1833 (rpcbind/portmapper)
|
|
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
|
|
|
2008-03-27 00:16:20 +01:00
|
|
|
#include <stdio.h>
|
2011-03-28 19:48:48 +02:00
|
|
|
#include <stdlib.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/init.h>
|
|
|
|
#include <ipxe/features.h>
|
|
|
|
#include <ipxe/shell.h>
|
|
|
|
#include <ipxe/image.h>
|
2011-03-07 18:42:06 +01:00
|
|
|
#include <ipxe/keys.h>
|
|
|
|
#include <usr/prompt.h>
|
2007-01-10 03:03:20 +01:00
|
|
|
#include <usr/autoboot.h>
|
2008-10-31 20:10:28 +01:00
|
|
|
#include <config/general.h>
|
2006-06-01 17:53:05 +02:00
|
|
|
|
2008-03-27 00:16:20 +01:00
|
|
|
#define NORMAL "\033[0m"
|
|
|
|
#define BOLD "\033[1m"
|
|
|
|
#define CYAN "\033[36m"
|
|
|
|
|
2011-03-28 19:48:48 +02:00
|
|
|
/** The "scriptlet" setting */
|
|
|
|
struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
|
|
|
|
.name = "scriptlet",
|
|
|
|
.description = "Boot scriptlet",
|
|
|
|
.tag = DHCP_EB_SCRIPTLET,
|
|
|
|
.type = &setting_type_string,
|
|
|
|
};
|
|
|
|
|
2011-03-07 18:42:06 +01:00
|
|
|
/**
|
|
|
|
* Prompt for shell entry
|
|
|
|
*
|
|
|
|
* @ret enter_shell User wants to enter shell
|
|
|
|
*/
|
|
|
|
static int shell_banner ( void ) {
|
|
|
|
|
|
|
|
/* Skip prompt if timeout is zero */
|
|
|
|
if ( BANNER_TIMEOUT <= 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ( prompt ( "\nPress Ctrl-B for the iPXE command line...",
|
|
|
|
( BANNER_TIMEOUT * 100 ), CTRL_B ) == 0 );
|
|
|
|
}
|
|
|
|
|
2007-01-14 01:16:41 +01:00
|
|
|
/**
|
|
|
|
* Main entry point
|
|
|
|
*
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
2008-11-19 01:18:32 +01:00
|
|
|
__asmcall int main ( void ) {
|
2008-03-27 00:16:20 +01:00
|
|
|
struct feature *feature;
|
2009-02-16 01:28:30 +01:00
|
|
|
struct image *image;
|
2011-03-28 19:48:48 +02:00
|
|
|
char *scriptlet;
|
2005-03-08 19:53:11 +01:00
|
|
|
|
2009-01-08 04:48:30 +01:00
|
|
|
/* Some devices take an unreasonably long time to initialise */
|
2010-04-25 02:47:03 +02:00
|
|
|
printf ( PRODUCT_SHORT_NAME " initialising devices..." );
|
2007-07-04 00:09:56 +02:00
|
|
|
initialise();
|
2007-01-14 01:16:41 +01:00
|
|
|
startup();
|
2010-04-25 02:47:03 +02:00
|
|
|
printf ( "ok\n" );
|
2006-05-02 23:10:45 +02:00
|
|
|
|
2008-10-31 20:10:28 +01:00
|
|
|
/*
|
|
|
|
* Print welcome banner
|
|
|
|
*
|
|
|
|
*
|
2010-04-19 21:16:01 +02:00
|
|
|
* If you wish to brand this build of iPXE, please do so by
|
2008-10-31 20:10:28 +01:00
|
|
|
* defining the string PRODUCT_NAME in config/general.h.
|
|
|
|
*
|
|
|
|
* While nothing in the GPL prevents you from removing all
|
2010-04-19 21:16:01 +02:00
|
|
|
* references to iPXE or http://ipxe.org, we prefer you not to
|
|
|
|
* do so.
|
2008-10-31 20:10:28 +01:00
|
|
|
*
|
|
|
|
*/
|
2010-04-19 21:16:01 +02:00
|
|
|
printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD "iPXE " VERSION
|
|
|
|
NORMAL " -- Open Source Network Boot Firmware -- "
|
|
|
|
CYAN "http://ipxe.org" NORMAL "\n"
|
2008-03-27 00:16:20 +01:00
|
|
|
"Features:" );
|
2009-03-12 20:41:40 +01:00
|
|
|
for_each_table_entry ( feature, FEATURES )
|
2008-03-27 00:16:20 +01:00
|
|
|
printf ( " %s", feature->name );
|
|
|
|
printf ( "\n" );
|
|
|
|
|
2011-03-07 21:42:36 +01:00
|
|
|
/* Boot system */
|
|
|
|
if ( ( image = first_image() ) != NULL ) {
|
|
|
|
/* We have an embedded image; execute it */
|
|
|
|
image_exec ( image );
|
2011-03-28 19:48:48 +02:00
|
|
|
} else if ( shell_banner() ) {
|
|
|
|
/* User wants shell; just give them a shell */
|
|
|
|
shell();
|
2008-03-27 00:16:20 +01:00
|
|
|
} else {
|
2011-03-28 19:48:48 +02:00
|
|
|
fetch_string_setting_copy ( NULL, &scriptlet_setting,
|
|
|
|
&scriptlet );
|
|
|
|
if ( scriptlet ) {
|
|
|
|
/* User has defined a scriptlet; execute it */
|
|
|
|
system ( scriptlet );
|
|
|
|
free ( scriptlet );
|
2009-02-24 06:51:21 +01:00
|
|
|
} else {
|
2011-03-07 21:42:36 +01:00
|
|
|
/* Try booting. If booting fails, offer the
|
|
|
|
* user another chance to enter the shell.
|
|
|
|
*/
|
2009-02-24 06:51:21 +01:00
|
|
|
autoboot();
|
2011-03-07 21:42:36 +01:00
|
|
|
if ( shell_banner() )
|
|
|
|
shell();
|
2009-02-16 01:28:30 +01:00
|
|
|
}
|
2008-03-27 00:16:20 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 21:35:48 +01:00
|
|
|
shutdown_exit();
|
2005-04-12 18:43:18 +02:00
|
|
|
|
2007-01-14 01:16:41 +01:00
|
|
|
return 0;
|
2005-03-08 19:53:11 +01:00
|
|
|
}
|