aoeboot.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/aoe.h>
00007 #include <gpxe/ata.h>
00008 #include <gpxe/netdevice.h>
00009 #include <gpxe/sanboot.h>
00010 #include <gpxe/abft.h>
00011 #include <int13.h>
00012 
00013 FILE_LICENCE ( GPL2_OR_LATER );
00014 
00015 static int aoeboot ( const char *root_path ) {
00016         struct ata_device *ata;
00017         struct int13_drive *drive;
00018         int rc;
00019 
00020         ata = zalloc ( sizeof ( *ata ) );
00021         if ( ! ata ) {
00022                 rc = -ENOMEM;
00023                 goto err_alloc_ata;
00024         }
00025         drive = zalloc ( sizeof ( *drive ) );
00026         if ( ! drive ) {
00027                 rc = -ENOMEM;
00028                 goto err_alloc_drive;
00029         }
00030 
00031         /* FIXME: ugly, ugly hack */
00032         struct net_device *netdev = last_opened_netdev();
00033 
00034         if ( ( rc = aoe_attach ( ata, netdev, root_path ) ) != 0 ) {
00035                 printf ( "Could not attach AoE device: %s\n",
00036                          strerror ( rc ) );
00037                 goto err_attach;
00038         }
00039         if ( ( rc = init_atadev ( ata ) ) != 0 ) {
00040                 printf ( "Could not initialise AoE device: %s\n",
00041                          strerror ( rc ) );
00042                 goto err_init;
00043         }
00044 
00045         /* FIXME: ugly, ugly hack */
00046         struct aoe_session *aoe =
00047                 container_of ( ata->backend, struct aoe_session, refcnt );
00048         abft_fill_data ( aoe );
00049 
00050         drive->blockdev = &ata->blockdev;
00051 
00052         register_int13_drive ( drive );
00053         printf ( "Registered as BIOS drive %#02x\n", drive->drive );
00054         printf ( "Booting from BIOS drive %#02x\n", drive->drive );
00055         rc = int13_boot ( drive->drive );
00056         printf ( "Boot failed\n" );
00057 
00058         /* Leave drive registered, if instructed to do so */
00059         if ( keep_san() )
00060                 return rc;
00061 
00062         printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
00063         unregister_int13_drive ( drive );
00064 
00065  err_init:
00066         aoe_detach ( ata );
00067  err_attach:
00068         free ( drive );
00069  err_alloc_drive:
00070         free ( ata );
00071  err_alloc_ata:
00072         return rc;
00073 }
00074 
00075 struct sanboot_protocol aoe_sanboot_protocol __sanboot_protocol = {
00076         .prefix = "aoe:",
00077         .boot = aoeboot,
00078 };

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