4 #include <gpxe/iscsi.h>
6 #include <gpxe/netdevice.h>
9 #include <usr/iscsiboot.h>
12 * Guess boot network device
14 * @ret netdev Boot network device
16 static struct net_device * guess_boot_netdev ( void ) {
17 struct net_device *boot_netdev;
19 /* Just use the first network device */
20 for_each_netdev ( boot_netdev ) {
27 int iscsiboot ( const char *root_path ) {
28 struct scsi_device scsi;
29 struct int13_drive drive;
32 memset ( &scsi, 0, sizeof ( scsi ) );
33 memset ( &drive, 0, sizeof ( drive ) );
35 printf ( "iSCSI booting from %s\n", root_path );
37 if ( ( rc = iscsi_attach ( &scsi, root_path ) ) != 0 ) {
38 printf ( "Could not attach iSCSI device: %s\n",
42 if ( ( rc = init_scsidev ( &scsi ) ) != 0 ) {
43 printf ( "Could not initialise iSCSI device: %s\n",
48 drive.drive = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
49 drive.blockdev = &scsi.blockdev;
51 /* FIXME: ugly, ugly hack */
52 struct net_device *netdev = guess_boot_netdev();
53 struct iscsi_session *iscsi =
54 container_of ( scsi.backend, struct iscsi_session, refcnt );
55 ibft_fill_data ( netdev, iscsi );
57 register_int13_drive ( &drive );
58 printf ( "Registered as BIOS drive %#02x\n", drive.drive );
59 printf ( "Booting from BIOS drive %#02x\n", drive.drive );
60 rc = int13_boot ( drive.drive );
61 printf ( "Boot failed\n" );
63 printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
64 unregister_int13_drive ( &drive );
67 iscsi_detach ( &scsi );