2006-12-20 08:04:08 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
|
|
|
2007-01-04 05:20:08 +01:00
|
|
|
#include <string.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2007-01-10 21:21:42 +01:00
|
|
|
#include <errno.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/netdevice.h>
|
|
|
|
#include <ipxe/dhcp.h>
|
|
|
|
#include <ipxe/settings.h>
|
|
|
|
#include <ipxe/image.h>
|
|
|
|
#include <ipxe/sanboot.h>
|
|
|
|
#include <ipxe/uri.h>
|
2011-01-27 19:48:47 +01:00
|
|
|
#include <ipxe/open.h>
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
#include <ipxe/init.h>
|
2007-01-10 02:55:07 +01:00
|
|
|
#include <usr/ifmgmt.h>
|
2007-01-10 21:38:20 +01:00
|
|
|
#include <usr/route.h>
|
2007-01-12 11:08:27 +01:00
|
|
|
#include <usr/dhcpmgmt.h>
|
|
|
|
#include <usr/imgmgmt.h>
|
2007-01-10 03:03:20 +01:00
|
|
|
#include <usr/autoboot.h>
|
2006-12-20 08:04:08 +01:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Automatic booting
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-05-27 02:52:44 +02:00
|
|
|
/**
|
|
|
|
* Perform PXE menu boot when PXE stack is not available
|
|
|
|
*/
|
|
|
|
__weak int pxe_menu_boot ( struct net_device *netdev __unused ) {
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2007-01-10 21:21:42 +01:00
|
|
|
/**
|
|
|
|
* Identify the boot network device
|
|
|
|
*
|
|
|
|
* @ret netdev Boot network device
|
|
|
|
*/
|
|
|
|
static struct net_device * find_boot_netdev ( void ) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-27 19:48:47 +01:00
|
|
|
* Parse next-server and filename into a URI
|
2007-01-10 21:21:42 +01:00
|
|
|
*
|
2011-01-27 19:48:47 +01:00
|
|
|
* @v next_server Next-server address
|
|
|
|
* @v filename Filename
|
|
|
|
* @ret uri URI, or NULL on failure
|
2007-01-10 21:21:42 +01:00
|
|
|
*/
|
2011-01-27 19:48:47 +01:00
|
|
|
static struct uri * parse_next_server_and_filename ( struct in_addr next_server,
|
|
|
|
const char *filename ) {
|
2011-02-01 03:56:06 +01:00
|
|
|
char buf[ 23 /* "tftp://xxx.xxx.xxx.xxx/" */ + strlen ( filename )
|
|
|
|
+ 1 /* NUL */ ];
|
2008-07-31 17:55:46 +02:00
|
|
|
struct uri *uri;
|
2007-01-10 21:21:42 +01:00
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Parse filename */
|
2008-07-31 17:55:46 +02:00
|
|
|
uri = parse_uri ( filename );
|
2011-01-27 19:48:47 +01:00
|
|
|
if ( ! uri )
|
|
|
|
return NULL;
|
2010-10-22 00:33:41 +02:00
|
|
|
|
|
|
|
/* Construct a tftp:// URI for the filename, if applicable.
|
|
|
|
* We can't just rely on the current working URI, because the
|
|
|
|
* relative URI resolution will remove the distinction between
|
|
|
|
* filenames with and without initial slashes, which is
|
|
|
|
* significant for TFTP.
|
|
|
|
*/
|
2011-01-27 19:48:47 +01:00
|
|
|
if ( ! uri_is_absolute ( uri ) ) {
|
2011-02-01 03:56:06 +01:00
|
|
|
uri_put ( uri );
|
|
|
|
snprintf ( buf, sizeof ( buf ), "tftp://%s/%s",
|
|
|
|
inet_ntoa ( next_server ), filename );
|
|
|
|
uri = parse_uri ( filename );
|
2011-01-27 19:48:47 +01:00
|
|
|
if ( ! uri )
|
|
|
|
return NULL;
|
2008-07-31 17:55:46 +02:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
return uri;
|
2007-07-08 23:01:49 +02:00
|
|
|
}
|
|
|
|
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
/** The "keep-san" setting */
|
|
|
|
struct setting keep_san_setting __setting = {
|
|
|
|
.name = "keep-san",
|
|
|
|
.description = "Preserve SAN connection",
|
|
|
|
.tag = DHCP_EB_KEEP_SAN,
|
|
|
|
.type = &setting_type_int8,
|
|
|
|
};
|
|
|
|
|
2010-10-22 00:03:42 +02:00
|
|
|
/** The "skip-san-boot" setting */
|
|
|
|
struct setting skip_san_boot_setting __setting = {
|
|
|
|
.name = "skip-san-boot",
|
|
|
|
.description = "Do not boot the SAN drive after connecting",
|
|
|
|
.tag = DHCP_EB_SKIP_SAN_BOOT,
|
|
|
|
.type = &setting_type_int8,
|
|
|
|
};
|
|
|
|
|
2007-07-08 23:01:49 +02:00
|
|
|
/**
|
2011-01-27 19:48:47 +01:00
|
|
|
* Boot from filename and root-path URIs
|
2007-07-08 23:01:49 +02:00
|
|
|
*
|
2011-01-27 19:48:47 +01:00
|
|
|
* @v filename Filename
|
2007-07-08 23:01:49 +02:00
|
|
|
* @v root_path Root path
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
2011-01-27 19:48:47 +01:00
|
|
|
int uriboot ( struct uri *filename, struct uri *root_path ) {
|
|
|
|
struct image *image;
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
int drive;
|
|
|
|
int rc;
|
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Allocate image */
|
|
|
|
image = alloc_image();
|
|
|
|
if ( ! image ) {
|
|
|
|
printf ( "Could not allocate image\n" );
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
rc = -ENOMEM;
|
2011-01-27 19:48:47 +01:00
|
|
|
goto err_alloc_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Treat empty URIs as absent */
|
|
|
|
if ( filename && ( ! filename->path ) )
|
|
|
|
filename = NULL;
|
|
|
|
if ( root_path && ( ! uri_is_absolute ( root_path ) ) )
|
|
|
|
root_path = NULL;
|
|
|
|
|
|
|
|
/* If we have both a filename and a root path, ignore an
|
|
|
|
* unsupported URI scheme in the root path, since it may
|
|
|
|
* represent an NFS root.
|
|
|
|
*/
|
|
|
|
if ( filename && root_path &&
|
|
|
|
( xfer_uri_opener ( root_path->scheme ) == NULL ) ) {
|
|
|
|
printf ( "Ignoring unsupported root path\n" );
|
|
|
|
root_path = NULL;
|
2007-07-29 03:31:14 +02:00
|
|
|
}
|
2007-07-08 23:01:49 +02:00
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Hook SAN device, if applicable */
|
|
|
|
if ( root_path ) {
|
|
|
|
drive = san_hook ( root_path, 0 );
|
|
|
|
if ( drive < 0 ) {
|
|
|
|
rc = drive;
|
|
|
|
printf ( "Could not open SAN device: %s\n",
|
|
|
|
strerror ( rc ) );
|
|
|
|
goto err_san_hook;
|
|
|
|
}
|
|
|
|
printf ( "Registered as SAN device %#02x\n", drive );
|
|
|
|
} else {
|
|
|
|
drive = -ENODEV;
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Describe SAN device, if applicable */
|
|
|
|
if ( ( drive >= 0 ) && ( ( rc = san_describe ( drive ) ) != 0 ) ) {
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
printf ( "Could not describe SAN device %#02x: %s\n",
|
|
|
|
drive, strerror ( rc ) );
|
2011-01-27 19:48:47 +01:00
|
|
|
goto err_san_describe;
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Attempt filename or SAN boot as applicable */
|
|
|
|
if ( filename ) {
|
|
|
|
if ( ( rc = imgdownload ( image, filename,
|
|
|
|
register_and_autoexec_image ) ) !=0){
|
|
|
|
printf ( "Could not chain image: %s\n",
|
|
|
|
strerror ( rc ) );
|
|
|
|
}
|
|
|
|
} else if ( root_path ) {
|
|
|
|
if ( fetch_intz_setting ( NULL, &skip_san_boot_setting) == 0 ) {
|
|
|
|
printf ( "Booting from SAN device %#02x\n", drive );
|
|
|
|
rc = san_boot ( drive );
|
|
|
|
printf ( "Boot from SAN device %#02x failed: %s\n",
|
|
|
|
drive, strerror ( rc ) );
|
|
|
|
} else {
|
|
|
|
printf ( "Skipping boot from SAN device %#02x\n",
|
|
|
|
drive );
|
|
|
|
rc = 0;
|
|
|
|
}
|
2010-10-22 00:03:42 +02:00
|
|
|
} else {
|
2011-01-27 19:48:47 +01:00
|
|
|
printf ( "No filename or root path specified\n" );
|
|
|
|
rc = -ENOENT;
|
2010-10-22 00:03:42 +02:00
|
|
|
}
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
err_san_describe:
|
|
|
|
/* Unhook SAN device, if applicable */
|
|
|
|
if ( drive >= 0 ) {
|
|
|
|
if ( fetch_intz_setting ( NULL, &keep_san_setting ) == 0 ) {
|
|
|
|
printf ( "Unregistering SAN device %#02x\n", drive );
|
|
|
|
san_unhook ( drive );
|
|
|
|
} else {
|
|
|
|
printf ( "Preserving connection to SAN device %#02x\n",
|
|
|
|
drive );
|
|
|
|
}
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
}
|
2011-01-27 19:48:47 +01:00
|
|
|
err_san_hook:
|
|
|
|
image_put ( image );
|
|
|
|
err_alloc_image:
|
[block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism. Bring this old code up to
date, with the following benefits:
o Block device commands can be cancelled by the requestor. The INT 13
layer uses this to provide a global timeout on all INT 13 calls,
with the result that an unexpected passive failure mode (such as
an iSCSI target ACKing the request but never sending a response)
will lead to a timeout that gets reported back to the INT 13 user,
rather than simply freezing the system.
o INT 13,00 (reset drive) is now able to reset the underlying block
device. INT 13 users, such as DOS, that use INT 13,00 as a method
for error recovery now have a chance of recovering.
o All block device commands are tagged, with a numerical tag that
will show up in debugging output and in packet captures; this will
allow easier interpretation of bug reports that include both
sources of information.
o The extremely ugly hacks used to generate the boot firmware tables
have been eradicated and replaced with a generic acpi_describe()
method (exploiting the ability of iPXE interfaces to pass through
methods to an underlying interface). The ACPI tables are now
built in a shared data block within .bss16, rather than each
requiring dedicated space in .data16.
o The architecture-independent concept of a SAN device has been
exposed to the iPXE core through the sanboot API, which provides
calls to hook, unhook, boot, and describe SAN devices. This
allows for much more flexible usage patterns (such as hooking an
empty SAN device and then running an OS installer via TFTP).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 17:11:51 +02:00
|
|
|
return rc;
|
2007-07-08 23:01:49 +02:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:04:30 +01:00
|
|
|
/**
|
|
|
|
* Close all open net devices
|
|
|
|
*
|
|
|
|
* Called before a fresh boot attempt in order to free up memory. We
|
|
|
|
* don't just close the device immediately after the boot fails,
|
|
|
|
* because there may still be TCP connections in the process of
|
|
|
|
* closing.
|
|
|
|
*/
|
|
|
|
static void close_all_netdevs ( void ) {
|
|
|
|
struct net_device *netdev;
|
|
|
|
|
|
|
|
for_each_netdev ( netdev ) {
|
|
|
|
ifclose ( netdev );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-08 23:01:49 +02:00
|
|
|
/**
|
2011-01-27 19:48:47 +01:00
|
|
|
* Fetch next-server and filename settings into a URI
|
2007-07-08 23:01:49 +02:00
|
|
|
*
|
2011-01-27 19:48:47 +01:00
|
|
|
* @v settings Settings block
|
|
|
|
* @ret uri URI, or NULL on failure
|
2007-07-08 23:01:49 +02:00
|
|
|
*/
|
2011-01-27 19:48:47 +01:00
|
|
|
struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
|
|
|
|
struct in_addr next_server;
|
2011-01-28 01:24:05 +01:00
|
|
|
char buf[256];
|
|
|
|
char *filename;
|
|
|
|
struct uri *uri;
|
2011-01-27 19:48:47 +01:00
|
|
|
|
|
|
|
/* Fetch next-server setting */
|
|
|
|
fetch_ipv4_setting ( settings, &next_server_setting, &next_server );
|
|
|
|
if ( next_server.s_addr )
|
|
|
|
printf ( "Next server: %s\n", inet_ntoa ( next_server ) );
|
|
|
|
|
|
|
|
/* Fetch filename setting */
|
|
|
|
fetch_string_setting ( settings, &filename_setting,
|
2011-01-28 01:24:05 +01:00
|
|
|
buf, sizeof ( buf ) );
|
|
|
|
if ( buf[0] )
|
|
|
|
printf ( "Filename: %s\n", buf );
|
|
|
|
|
|
|
|
/* Expand filename setting */
|
|
|
|
filename = expand_settings ( buf );
|
|
|
|
if ( ! filename )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Parse next server and filename */
|
|
|
|
uri = parse_next_server_and_filename ( next_server, filename );
|
2011-01-27 19:48:47 +01:00
|
|
|
|
2011-01-28 01:24:05 +01:00
|
|
|
free ( filename );
|
|
|
|
return uri;
|
2011-01-27 19:48:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch root-path setting into a URI
|
|
|
|
*
|
|
|
|
* @v settings Settings block
|
|
|
|
* @ret uri URI, or NULL on failure
|
|
|
|
*/
|
|
|
|
static struct uri * fetch_root_path ( struct settings *settings ) {
|
2011-01-28 01:24:05 +01:00
|
|
|
char buf[256];
|
|
|
|
char *root_path;
|
|
|
|
struct uri *uri;
|
2011-01-27 19:48:47 +01:00
|
|
|
|
|
|
|
/* Fetch root-path setting */
|
|
|
|
fetch_string_setting ( settings, &root_path_setting,
|
2011-01-28 01:24:05 +01:00
|
|
|
buf, sizeof ( buf ) );
|
|
|
|
if ( buf[0] )
|
|
|
|
printf ( "Root path: %s\n", buf );
|
|
|
|
|
|
|
|
/* Expand filename setting */
|
|
|
|
root_path = expand_settings ( buf );
|
|
|
|
if ( ! root_path )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Parse root path */
|
|
|
|
uri = parse_uri ( root_path );
|
2011-01-27 19:48:47 +01:00
|
|
|
|
2011-01-28 01:24:05 +01:00
|
|
|
free ( root_path );
|
|
|
|
return uri;
|
2011-01-27 19:48:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether or not we have a usable PXE menu
|
|
|
|
*
|
|
|
|
* @ret have_menu A usable PXE menu is present
|
|
|
|
*/
|
|
|
|
static int have_pxe_menu ( void ) {
|
2009-02-03 03:46:06 +01:00
|
|
|
struct setting vendor_class_id_setting
|
|
|
|
= { .tag = DHCP_VENDOR_CLASS_ID };
|
|
|
|
struct setting pxe_discovery_control_setting
|
|
|
|
= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
|
|
|
|
struct setting pxe_boot_menu_setting
|
|
|
|
= { .tag = DHCP_PXE_BOOT_MENU };
|
2007-07-08 23:01:49 +02:00
|
|
|
char buf[256];
|
2009-02-03 03:46:06 +01:00
|
|
|
unsigned int pxe_discovery_control;
|
2011-01-27 19:48:47 +01:00
|
|
|
|
|
|
|
fetch_string_setting ( NULL, &vendor_class_id_setting,
|
|
|
|
buf, sizeof ( buf ) );
|
|
|
|
pxe_discovery_control =
|
|
|
|
fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
|
|
|
|
|
|
|
|
return ( ( strcmp ( buf, "PXEClient" ) == 0 ) &&
|
|
|
|
setting_exists ( NULL, &pxe_boot_menu_setting ) &&
|
|
|
|
( ! ( ( pxe_discovery_control & PXEBS_SKIP ) &&
|
|
|
|
setting_exists ( NULL, &filename_setting ) ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot from a network device
|
|
|
|
*
|
|
|
|
* @v netdev Network device
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
int netboot ( struct net_device *netdev ) {
|
|
|
|
struct uri *filename;
|
|
|
|
struct uri *root_path;
|
2007-07-08 23:01:49 +02:00
|
|
|
int rc;
|
|
|
|
|
2010-11-22 22:04:30 +01:00
|
|
|
/* Close all other network devices */
|
|
|
|
close_all_netdevs();
|
|
|
|
|
2007-07-08 23:01:49 +02:00
|
|
|
/* Open device and display device status */
|
|
|
|
if ( ( rc = ifopen ( netdev ) ) != 0 )
|
2011-01-27 19:48:47 +01:00
|
|
|
goto err_ifopen;
|
2007-07-08 23:01:49 +02:00
|
|
|
ifstat ( netdev );
|
|
|
|
|
|
|
|
/* Configure device via DHCP */
|
|
|
|
if ( ( rc = dhcp ( netdev ) ) != 0 )
|
2011-01-27 19:48:47 +01:00
|
|
|
goto err_dhcp;
|
2007-07-08 23:01:49 +02:00
|
|
|
route();
|
|
|
|
|
2009-02-03 03:46:06 +01:00
|
|
|
/* Try PXE menu boot, if applicable */
|
2011-01-27 19:48:47 +01:00
|
|
|
if ( have_pxe_menu() ) {
|
2009-01-31 08:36:05 +01:00
|
|
|
printf ( "Booting from PXE menu\n" );
|
2011-01-27 19:48:47 +01:00
|
|
|
rc = pxe_menu_boot ( netdev );
|
|
|
|
goto err_pxe_menu_boot;
|
2009-01-31 08:36:05 +01:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Fetch next server, filename and root path */
|
|
|
|
filename = fetch_next_server_and_filename ( NULL );
|
|
|
|
if ( ! filename )
|
|
|
|
goto err_filename;
|
|
|
|
root_path = fetch_root_path ( NULL );
|
|
|
|
if ( ! root_path )
|
|
|
|
goto err_root_path;
|
|
|
|
|
|
|
|
/* Boot using next server, filename and root path */
|
|
|
|
if ( ( rc = uriboot ( filename, root_path ) ) != 0 )
|
|
|
|
goto err_uriboot;
|
|
|
|
|
|
|
|
err_uriboot:
|
|
|
|
uri_put ( root_path );
|
|
|
|
err_root_path:
|
|
|
|
uri_put ( filename );
|
|
|
|
err_filename:
|
|
|
|
err_pxe_menu_boot:
|
|
|
|
err_dhcp:
|
|
|
|
err_ifopen:
|
|
|
|
return rc;
|
2007-01-10 21:21:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Boot the system
|
|
|
|
*/
|
2010-11-21 17:39:36 +01:00
|
|
|
int autoboot ( void ) {
|
2007-01-10 21:21:42 +01:00
|
|
|
struct net_device *boot_netdev;
|
|
|
|
struct net_device *netdev;
|
2010-11-21 17:39:36 +01:00
|
|
|
int rc = -ENODEV;
|
2007-01-10 21:21:42 +01:00
|
|
|
|
|
|
|
/* If we have an identifable boot device, try that first */
|
|
|
|
if ( ( boot_netdev = find_boot_netdev() ) )
|
2010-11-21 17:39:36 +01:00
|
|
|
rc = netboot ( boot_netdev );
|
2007-01-10 21:21:42 +01:00
|
|
|
|
|
|
|
/* If that fails, try booting from any of the other devices */
|
|
|
|
for_each_netdev ( netdev ) {
|
|
|
|
if ( netdev == boot_netdev )
|
|
|
|
continue;
|
2010-11-21 17:39:36 +01:00
|
|
|
rc = netboot ( netdev );
|
2007-01-10 21:21:42 +01:00
|
|
|
}
|
2007-01-04 05:20:08 +01:00
|
|
|
|
2007-01-10 02:55:07 +01:00
|
|
|
printf ( "No more network devices\n" );
|
2010-11-21 17:39:36 +01:00
|
|
|
return rc;
|
2006-12-20 08:04:08 +01:00
|
|
|
}
|