Adding debian version 3.70~pre8+dfsg-1.
[syslinux-debian/hramrach.git] / gpxe / src / usr / iscsiboot.c
blob99edc8795846193edd9f35d19dc513b049b57c5b
1 #include <stdint.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <gpxe/iscsi.h>
5 #include <gpxe/settings.h>
6 #include <gpxe/netdevice.h>
7 #include <gpxe/ibft.h>
8 #include <int13.h>
9 #include <usr/iscsiboot.h>
11 /**
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 ) {
21 return boot_netdev;
24 return NULL;
27 int iscsiboot ( const char *root_path ) {
28 struct scsi_device scsi;
29 struct int13_drive drive;
30 int rc;
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",
39 strerror ( rc ) );
40 goto error_attach;
42 if ( ( rc = init_scsidev ( &scsi ) ) != 0 ) {
43 printf ( "Could not initialise iSCSI device: %s\n",
44 strerror ( rc ) );
45 goto error_init;
48 drive.blockdev = &scsi.blockdev;
50 /* FIXME: ugly, ugly hack */
51 struct net_device *netdev = guess_boot_netdev();
52 struct iscsi_session *iscsi =
53 container_of ( scsi.backend, struct iscsi_session, refcnt );
54 ibft_fill_data ( netdev, iscsi );
56 register_int13_drive ( &drive );
57 printf ( "Registered as BIOS drive %#02x\n", drive.drive );
58 printf ( "Booting from BIOS drive %#02x\n", drive.drive );
59 rc = int13_boot ( drive.drive );
60 printf ( "Boot failed\n" );
62 printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
63 unregister_int13_drive ( &drive );
65 error_init:
66 iscsi_detach ( &scsi );
67 error_attach:
68 return rc;