ib_srpboot.c

Go to the documentation of this file.
00001 #include <stdint.h>
00002 #include <string.h>
00003 #include <stdlib.h>
00004 #include <stdio.h>
00005 #include <errno.h>
00006 #include <gpxe/sanboot.h>
00007 #include <int13.h>
00008 #include <gpxe/srp.h>
00009 #include <gpxe/sbft.h>
00010 
00011 FILE_LICENCE ( GPL2_OR_LATER );
00012 
00013 static int ib_srpboot ( const char *root_path ) {
00014         struct scsi_device *scsi;
00015         struct int13_drive *drive;
00016         int rc;
00017 
00018         scsi = zalloc ( sizeof ( *scsi ) );
00019         if ( ! scsi ) {
00020                 rc = -ENOMEM;
00021                 goto err_alloc_scsi;
00022         }
00023         drive = zalloc ( sizeof ( *drive ) );
00024         if ( ! drive ) {
00025                 rc = -ENOMEM;
00026                 goto err_alloc_drive;
00027         }
00028 
00029         if ( ( rc = srp_attach ( scsi, root_path ) ) != 0 ) {
00030                 printf ( "Could not attach IB_SRP device: %s\n",
00031                          strerror ( rc ) );
00032                 goto err_attach;
00033         }
00034         if ( ( rc = init_scsidev ( scsi ) ) != 0 ) {
00035                 printf ( "Could not initialise IB_SRP device: %s\n",
00036                          strerror ( rc ) );
00037                 goto err_init;
00038         }
00039 
00040         drive->blockdev = &scsi->blockdev;
00041 
00042         /* FIXME: ugly, ugly hack */
00043         struct srp_device *srp =
00044                 container_of ( scsi->backend, struct srp_device, refcnt );
00045         sbft_fill_data ( srp );
00046 
00047         register_int13_drive ( drive );
00048         printf ( "Registered as BIOS drive %#02x\n", drive->drive );
00049         printf ( "Booting from BIOS drive %#02x\n", drive->drive );
00050         rc = int13_boot ( drive->drive );
00051         printf ( "Boot failed\n" );
00052 
00053         /* Leave drive registered, if instructed to do so */
00054         if ( keep_san() )
00055                 return rc;
00056 
00057         printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
00058         unregister_int13_drive ( drive );
00059 
00060  err_init:
00061         srp_detach ( scsi );
00062  err_attach:
00063         free ( drive );
00064  err_alloc_drive:
00065         free ( scsi );
00066  err_alloc_scsi:
00067         return rc;
00068 }
00069 
00070 struct sanboot_protocol ib_srp_sanboot_protocol __sanboot_protocol = {
00071         .prefix = "ib_srp:",
00072         .boot = ib_srpboot,
00073 };

Generated on Tue Apr 6 20:00:50 2010 for gPXE by  doxygen 1.5.7.1