[gPXE] [PATCH 1/2] consolidate int13 boot code

Dave Hansen dave at sr71.net
Fri Oct 15 19:05:54 EDT 2010


Each of the users of the int13 drive registration routines basically
does the same thing.  Register the drive, try to boot it.  Return
error on failure, and unregiser unless keep_san is set.

This patch consolidates each of those users into a common helper
function.  Perhaps keepsan.c needs a new name, but I think this is
a decent place to put it.
---
 src/arch/i386/include/int13.h               |    1 +
 src/arch/i386/interface/pcbios/aoeboot.c    |   13 +-----------
 src/arch/i386/interface/pcbios/ib_srpboot.c |   13 +-----------
 src/arch/i386/interface/pcbios/int13.c      |    1 +
 src/arch/i386/interface/pcbios/iscsiboot.c  |   13 +-----------
 src/arch/i386/interface/pcbios/keepsan.c    |   29 ++++++++++++++++++++++++++-
 src/include/gpxe/sanboot.h                  |    3 +-
 7 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/src/arch/i386/include/int13.h b/src/arch/i386/include/int13.h
index e1884d9..fbd13c0 100644
--- a/src/arch/i386/include/int13.h
+++ b/src/arch/i386/include/int13.h
@@ -288,5 +288,6 @@ struct master_boot_record {
 extern void register_int13_drive ( struct int13_drive *drive );
 extern void unregister_int13_drive ( struct int13_drive *drive );
 extern int int13_boot ( unsigned int drive );
+extern int register_and_boot_drive ( struct int13_drive *drive );
 
 #endif /* INT13_H */
diff --git a/src/arch/i386/interface/pcbios/aoeboot.c b/src/arch/i386/interface/pcbios/aoeboot.c
index 2670b15..f30e950 100644
--- a/src/arch/i386/interface/pcbios/aoeboot.c
+++ b/src/arch/i386/interface/pcbios/aoeboot.c
@@ -49,18 +49,7 @@ static int aoeboot ( const char *root_path ) {
 
 	drive->blockdev = &ata->blockdev;
 
-	register_int13_drive ( drive );
-	printf ( "Registered as BIOS drive %#02x\n", drive->drive );
-	printf ( "Booting from BIOS drive %#02x\n", drive->drive );
-	rc = int13_boot ( drive->drive );
-	printf ( "Boot failed\n" );
-
-	/* Leave drive registered, if instructed to do so */
-	if ( keep_san() )
-		return rc;
-
-	printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
-	unregister_int13_drive ( drive );
+	rc = register_and_boot_drive ( drive );
 
  err_init:
 	aoe_detach ( ata );
diff --git a/src/arch/i386/interface/pcbios/ib_srpboot.c b/src/arch/i386/interface/pcbios/ib_srpboot.c
index b1cbc33..247a4f8 100644
--- a/src/arch/i386/interface/pcbios/ib_srpboot.c
+++ b/src/arch/i386/interface/pcbios/ib_srpboot.c
@@ -44,18 +44,7 @@ static int ib_srpboot ( const char *root_path ) {
 		container_of ( scsi->backend, struct srp_device, refcnt );
 	sbft_fill_data ( srp );
 
-	register_int13_drive ( drive );
-	printf ( "Registered as BIOS drive %#02x\n", drive->drive );
-	printf ( "Booting from BIOS drive %#02x\n", drive->drive );
-	rc = int13_boot ( drive->drive );
-	printf ( "Boot failed\n" );
-
-	/* Leave drive registered, if instructed to do so */
-	if ( keep_san() )
-		return rc;
-
-	printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
-	unregister_int13_drive ( drive );
+	rc = register_and_boot_drive ( drive );
 
  err_init:
 	srp_detach ( scsi );
diff --git a/src/arch/i386/interface/pcbios/int13.c b/src/arch/i386/interface/pcbios/int13.c
index 87b613a..6f8a32c 100644
--- a/src/arch/i386/interface/pcbios/int13.c
+++ b/src/arch/i386/interface/pcbios/int13.c
@@ -713,3 +713,4 @@ int int13_boot ( unsigned int drive ) {
 
 	return -ECANCELED; /* -EIMPOSSIBLE */
 }
+
diff --git a/src/arch/i386/interface/pcbios/iscsiboot.c b/src/arch/i386/interface/pcbios/iscsiboot.c
index 00efd8f..1ec083a 100644
--- a/src/arch/i386/interface/pcbios/iscsiboot.c
+++ b/src/arch/i386/interface/pcbios/iscsiboot.c
@@ -46,18 +46,7 @@ static int iscsiboot ( const char *root_path ) {
 		container_of ( scsi->backend, struct iscsi_session, refcnt );
 	ibft_fill_data ( netdev, iscsi );
 
-	register_int13_drive ( drive );
-	printf ( "Registered as BIOS drive %#02x\n", drive->drive );
-	printf ( "Booting from BIOS drive %#02x\n", drive->drive );
-	rc = int13_boot ( drive->drive );
-	printf ( "Boot failed\n" );
-
-	/* Leave drive registered, if instructed to do so */
-	if ( keep_san() )
-		return rc;
-
-	printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
-	unregister_int13_drive ( drive );
+	rc = register_and_boot_drive ( drive );
 
  err_init:
 	iscsi_detach ( scsi );
diff --git a/src/arch/i386/interface/pcbios/keepsan.c b/src/arch/i386/interface/pcbios/keepsan.c
index 904e017..22ba4b5 100644
--- a/src/arch/i386/interface/pcbios/keepsan.c
+++ b/src/arch/i386/interface/pcbios/keepsan.c
@@ -5,6 +5,7 @@
 #include <gpxe/init.h>
 #include <gpxe/sanboot.h>
 #include <usr/autoboot.h>
+#include <int13.h>
 
 struct setting keep_san_setting __setting = {
 	.name = "keep-san",
@@ -13,7 +14,7 @@ struct setting keep_san_setting __setting = {
 	.type = &setting_type_int8,
 };
 
-int keep_san ( void ) {
+static int keep_san ( void ) {
 	int keep_san;
 
 	keep_san = fetch_intz_setting ( NULL, &keep_san_setting );
@@ -24,3 +25,29 @@ int keep_san ( void ) {
 	shutdown_exit_flags |= SHUTDOWN_KEEP_DEVICES;
 	return 1;
 }
+
+/**
+ * Register an INT 13 drive with the BIOS, and possibly boot it
+ *
+ * @v drive		Drive number
+ * @ret rc		Return status code
+ *
+ * If a boot operation is requested and performed successfully,
+ * this function will never return.
+ */
+int register_and_boot_drive ( struct int13_drive *drive ) {
+	int rc;
+
+	register_int13_drive ( drive );
+	printf ( "Registered as BIOS drive %#02x\n", drive->drive );
+	printf ( "Booting from BIOS drive %#02x\n", drive->drive );
+	rc = int13_boot ( drive->drive );
+	printf ( "Boot failed\n" );
+
+	/* Leave drive registered, if instructed to do so */
+	if ( !keep_san() ) {
+		printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
+		unregister_int13_drive ( drive );
+	}
+	return rc;
+}
diff --git a/src/include/gpxe/sanboot.h b/src/include/gpxe/sanboot.h
index fd06316..20b5063 100644
--- a/src/include/gpxe/sanboot.h
+++ b/src/include/gpxe/sanboot.h
@@ -15,6 +15,7 @@ struct sanboot_protocol {
 
 #define __sanboot_protocol __table_entry ( SANBOOT_PROTOCOLS, 01 )
 
-extern int keep_san ( void );
+struct int13_drive;
+int register_and_boot_drive ( struct int13_drive *drive );
 
 #endif /* _GPXE_SANBOOT_H */
-- 
1.7.1.rc2



More information about the gPXE mailing list