2005-03-08 18:53:11 +00:00
|
|
|
/**************************************************************************
|
|
|
|
Etherboot - Network Bootstrap Program
|
|
|
|
|
|
|
|
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)
|
|
|
|
NFS - RFC1094, RFC1813 (v3, useful for clarifications, not implemented)
|
|
|
|
IGMP - RFC1112
|
|
|
|
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* #define MDEBUG */
|
|
|
|
|
|
|
|
#include "etherboot.h"
|
|
|
|
#include "dev.h"
|
|
|
|
#include "nic.h"
|
|
|
|
#include "disk.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "cpu.h"
|
2006-08-09 02:30:35 +00:00
|
|
|
#include "cmdline.h"
|
2005-04-08 15:01:17 +00:00
|
|
|
#include "console.h"
|
2006-04-30 01:08:52 +00:00
|
|
|
#include <gpxe/init.h>
|
2005-05-17 13:44:08 +00:00
|
|
|
#include "image.h"
|
2005-03-08 18:53:11 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2006-06-01 15:53:05 +00:00
|
|
|
#include <gpxe/device.h>
|
|
|
|
#include <gpxe/heap.h>
|
|
|
|
#include <gpxe/netdevice.h>
|
2006-12-20 00:26:01 +00:00
|
|
|
#include <gpxe/shell.h>
|
|
|
|
#include <gpxe/shell_banner.h>
|
2007-01-10 02:03:20 +00:00
|
|
|
#include <usr/autoboot.h>
|
2006-06-01 15:53:05 +00:00
|
|
|
|
2005-05-18 14:43:27 +00:00
|
|
|
/* Linker symbols */
|
|
|
|
extern char _bss[], _ebss[];
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
jmp_buf restart_etherboot;
|
|
|
|
int url_port;
|
|
|
|
|
|
|
|
char as_main_program = 1;
|
|
|
|
|
2005-04-12 16:43:18 +00:00
|
|
|
#if 0
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
static inline unsigned long ask_boot(unsigned *index)
|
|
|
|
{
|
|
|
|
unsigned long order = DEFAULT_BOOT_ORDER;
|
|
|
|
*index = DEFAULT_BOOT_INDEX;
|
|
|
|
#ifdef LINUXBIOS
|
|
|
|
order = get_boot_order(order, index);
|
|
|
|
#endif
|
|
|
|
#if defined(ASK_BOOT)
|
|
|
|
#if ASK_BOOT >= 0
|
|
|
|
while(1) {
|
|
|
|
int c = 0;
|
|
|
|
printf(ASK_PROMPT);
|
|
|
|
#if ASK_BOOT > 0
|
|
|
|
{
|
|
|
|
unsigned long time;
|
|
|
|
for ( time = currticks() + ASK_BOOT*TICKS_PER_SEC;
|
|
|
|
!c && !iskey(); ) {
|
|
|
|
if (currticks() > time) c = ANS_DEFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* ASK_BOOT > 0 */
|
|
|
|
if ( !c ) c = getchar();
|
|
|
|
if ((c >= 'a') && (c <= 'z')) c &= 0x5F;
|
|
|
|
if ((c >= ' ') && (c <= '~')) putchar(c);
|
|
|
|
putchar('\n');
|
|
|
|
|
|
|
|
switch(c) {
|
|
|
|
default:
|
|
|
|
/* Nothing useful try again */
|
|
|
|
continue;
|
|
|
|
case ANS_QUIT:
|
|
|
|
order = BOOT_NOTHING;
|
|
|
|
*index = 0;
|
|
|
|
break;
|
|
|
|
case ANS_DEFAULT:
|
|
|
|
/* Preserve the default boot order */
|
|
|
|
break;
|
|
|
|
case ANS_NETWORK:
|
|
|
|
order = (BOOT_NIC << (0*BOOT_BITS)) |
|
|
|
|
(BOOT_NOTHING << (1*BOOT_BITS));
|
|
|
|
*index = 0;
|
|
|
|
break;
|
|
|
|
case ANS_DISK:
|
|
|
|
order = (BOOT_DISK << (0*BOOT_BITS)) |
|
|
|
|
(BOOT_NOTHING << (1*BOOT_BITS));
|
|
|
|
*index = 0;
|
|
|
|
break;
|
|
|
|
case ANS_FLOPPY:
|
|
|
|
order = (BOOT_FLOPPY << (0*BOOT_BITS)) |
|
|
|
|
(BOOT_NOTHING << (1*BOOT_BITS));
|
|
|
|
*index = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
#endif /* ASK_BOOT >= 0 */
|
|
|
|
#endif /* defined(ASK_BOOT) */
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void try_floppy_first(void)
|
|
|
|
{
|
|
|
|
#if (TRY_FLOPPY_FIRST > 0)
|
|
|
|
int i;
|
|
|
|
printf("Trying floppy");
|
|
|
|
disk_init();
|
|
|
|
for (i = TRY_FLOPPY_FIRST; i-- > 0; ) {
|
|
|
|
putchar('.');
|
|
|
|
if (pcbios_disk_read(0, 0, 0, 0, ((char *)FLOPPY_BOOT_LOCATION)) != 0x8000) {
|
|
|
|
printf("using floppy\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("no floppy\n");
|
|
|
|
#endif /* TRY_FLOPPY_FIRST */
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct class_operations {
|
|
|
|
struct dev *dev;
|
|
|
|
int (*probe)(struct dev *dev);
|
|
|
|
int (*load_configuration)(struct dev *dev);
|
|
|
|
int (*load)(struct dev *dev);
|
|
|
|
}
|
|
|
|
operations[] = {
|
|
|
|
{ &nic.dev, eth_probe, eth_load_configuration, eth_load },
|
|
|
|
{ &disk.dev, disk_probe, disk_load_configuration, disk_load },
|
|
|
|
{ &disk.dev, disk_probe, disk_load_configuration, disk_load },
|
|
|
|
};
|
|
|
|
|
2005-04-12 16:43:18 +00:00
|
|
|
#endif
|
|
|
|
|
2006-09-27 04:04:55 +00:00
|
|
|
#if 0
|
2005-03-08 18:53:11 +00:00
|
|
|
static int main_loop(int state);
|
|
|
|
static int exit_ok;
|
|
|
|
static int initialized;
|
2006-09-27 04:04:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int exit_status;
|
2005-03-08 18:53:11 +00:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
MAIN - Kick off routine
|
|
|
|
**************************************************************************/
|
2005-04-08 15:01:17 +00:00
|
|
|
int main ( void ) {
|
2005-03-08 18:53:11 +00:00
|
|
|
|
2006-05-02 21:10:45 +00:00
|
|
|
/* Call all registered initialisation functions */
|
2006-06-01 11:07:31 +00:00
|
|
|
init_heap();
|
2006-05-02 21:10:45 +00:00
|
|
|
call_init_fns ();
|
2006-06-01 11:07:31 +00:00
|
|
|
probe_devices();
|
2006-05-02 21:10:45 +00:00
|
|
|
|
2006-12-20 07:04:08 +00:00
|
|
|
/* Try autobooting if we're not going straight to the shell */
|
|
|
|
if ( ! shell_banner() ) {
|
|
|
|
autoboot();
|
2006-12-20 00:26:01 +00:00
|
|
|
}
|
2006-12-20 07:04:08 +00:00
|
|
|
|
|
|
|
/* Autobooting failed or the user wanted the shell */
|
|
|
|
shell();
|
2005-04-21 18:18:29 +00:00
|
|
|
|
2006-06-01 11:07:31 +00:00
|
|
|
remove_devices();
|
2005-04-10 18:30:34 +00:00
|
|
|
call_exit_fns ();
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
return exit_status;
|
|
|
|
}
|
|
|
|
|
2006-06-01 11:07:31 +00:00
|
|
|
#if 0
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
void exit(int status)
|
|
|
|
{
|
|
|
|
while(!exit_ok)
|
|
|
|
;
|
|
|
|
exit_status = status;
|
|
|
|
longjmp(restart_etherboot, 255);
|
|
|
|
}
|
|
|
|
|
2005-04-12 16:43:18 +00:00
|
|
|
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
static int main_loop(int state)
|
|
|
|
{
|
|
|
|
/* Splitting main into 2 pieces makes the semantics of
|
|
|
|
* which variables are preserved across a longjmp clean
|
|
|
|
* and predictable.
|
|
|
|
*/
|
|
|
|
static unsigned long order;
|
|
|
|
static unsigned boot_index;
|
|
|
|
static struct dev * dev = 0;
|
|
|
|
static struct class_operations *ops;
|
|
|
|
static int type;
|
|
|
|
static int i;
|
|
|
|
|
|
|
|
if (!initialized) {
|
|
|
|
initialized = 1;
|
|
|
|
if (dev && (state >= 1) && (state <= 2)) {
|
|
|
|
dev->how_probe = PROBE_AWAKE;
|
|
|
|
dev->how_probe = ops->probe(dev);
|
|
|
|
if (dev->how_probe == PROBE_FAILED) {
|
|
|
|
state = -1;
|
|
|
|
}
|
2006-03-16 17:40:55 +00:00
|
|
|
if (state == 1) {
|
|
|
|
/* The bootp reply might have been changed, re-parse. */
|
|
|
|
decode_rfc1533(bootp_data.bootp_reply.bp_vend, 0,
|
|
|
|
#ifdef NO_DHCP_SUPPORT
|
|
|
|
BOOTP_VENDOR_LEN + MAX_BOOTP_EXTLEN,
|
|
|
|
#else
|
|
|
|
DHCP_OPT_LEN + MAX_BOOTP_EXTLEN,
|
|
|
|
#endif /* NO_DHCP_SUPPORT */
|
|
|
|
1);
|
|
|
|
}
|
2005-03-08 18:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch(state) {
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
static int firsttime = 1;
|
|
|
|
/* First time through */
|
|
|
|
if (firsttime) {
|
|
|
|
cleanup();
|
|
|
|
firsttime = 0;
|
|
|
|
}
|
|
|
|
#ifdef EXIT_IF_NO_OFFER
|
|
|
|
else {
|
|
|
|
cleanup();
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
i = -1;
|
|
|
|
state = 4;
|
|
|
|
dev = 0;
|
|
|
|
|
|
|
|
/* We just called setjmp ... */
|
|
|
|
order = ask_boot(&boot_index);
|
|
|
|
try_floppy_first();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
cleanup();
|
2005-04-08 15:01:17 +00:00
|
|
|
call_reset_fns();
|
2005-03-08 18:53:11 +00:00
|
|
|
/* Find a dev entry to probe with */
|
|
|
|
if (!dev) {
|
|
|
|
int boot;
|
|
|
|
int failsafe;
|
|
|
|
|
|
|
|
/* Advance to the next device type */
|
|
|
|
i++;
|
|
|
|
boot = (order >> (i * BOOT_BITS)) & BOOT_MASK;
|
|
|
|
type = boot & BOOT_TYPE_MASK;
|
|
|
|
failsafe = (boot & BOOT_FAILSAFE) != 0;
|
|
|
|
if (i >= MAX_BOOT_ENTRIES) {
|
|
|
|
type = BOOT_NOTHING;
|
|
|
|
}
|
|
|
|
if ((i == 0) && (type == BOOT_NOTHING)) {
|
|
|
|
/* Return to caller */
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
if (type >= BOOT_NOTHING) {
|
|
|
|
interruptible_sleep(2);
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ops = &operations[type];
|
|
|
|
dev = ops->dev;
|
|
|
|
dev->how_probe = PROBE_FIRST;
|
|
|
|
dev->type = type;
|
|
|
|
dev->failsafe = failsafe;
|
|
|
|
dev->type_index = 0;
|
|
|
|
} else {
|
|
|
|
/* Advance to the next device of the same type */
|
|
|
|
dev->how_probe = PROBE_NEXT;
|
|
|
|
}
|
|
|
|
state = 3;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
state = -1;
|
2005-04-08 15:01:17 +00:00
|
|
|
/* Removed the following line because it was causing
|
|
|
|
* heap.o to be dragged in unnecessarily. It's also
|
|
|
|
* slightly puzzling: by resetting heap_base, doesn't
|
|
|
|
* this mean that we permanently leak memory?
|
|
|
|
*/
|
|
|
|
/* heap_base = allot(0); */
|
2005-03-08 18:53:11 +00:00
|
|
|
dev->how_probe = ops->probe(dev);
|
|
|
|
if (dev->how_probe == PROBE_FAILED) {
|
|
|
|
dev = 0;
|
|
|
|
state = 4;
|
|
|
|
} else if (boot_index && (i == 0) && (boot_index != (unsigned)dev->type_index)) {
|
|
|
|
printf("Wrong index\n");
|
|
|
|
state = 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
state = -1;
|
|
|
|
if (ops->load_configuration(dev) >= 0) {
|
|
|
|
state = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* Any return from load is a failure */
|
|
|
|
ops->load(dev);
|
|
|
|
state = -1;
|
|
|
|
break;
|
|
|
|
case 256:
|
|
|
|
state = 0;
|
|
|
|
break;
|
|
|
|
case -3:
|
|
|
|
i = MAX_BOOT_ENTRIES;
|
|
|
|
type = BOOT_NOTHING;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
printf("<abort>\n");
|
|
|
|
state = 4;
|
|
|
|
/* At the end goto state 0 */
|
|
|
|
if ((type >= BOOT_NOTHING) || (i >= MAX_BOOT_ENTRIES)) {
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-12 16:43:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-03-08 18:53:11 +00:00
|
|
|
/**************************************************************************
|
|
|
|
LOADKERNEL - Try to load kernel image
|
|
|
|
**************************************************************************/
|
2005-04-30 13:51:49 +00:00
|
|
|
#if 0
|
|
|
|
/* To be split out into individual files */
|
2005-03-08 18:53:11 +00:00
|
|
|
static const struct proto protos[] = {
|
|
|
|
{ "x-tftm", url_tftm },
|
|
|
|
{ "x-slam", url_slam },
|
|
|
|
{ "nfs", nfs },
|
|
|
|
{ "file", url_file },
|
|
|
|
{ "tftp", tftp },
|
|
|
|
{ "http", http },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
CLEANUP - shut down networking and console so that the OS may be called
|
|
|
|
**************************************************************************/
|
2006-08-14 22:52:35 +00:00
|
|
|
#if 0
|
2005-03-08 18:53:11 +00:00
|
|
|
void cleanup(void)
|
|
|
|
{
|
|
|
|
/* Stop receiving packets */
|
2005-04-21 18:18:29 +00:00
|
|
|
disable ( &dev );
|
2005-03-08 18:53:11 +00:00
|
|
|
initialized = 0;
|
|
|
|
}
|
2006-08-14 22:52:35 +00:00
|
|
|
#endif
|
2005-03-08 18:53:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* End:
|
|
|
|
*/
|