You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <gpxe/iscsi.h>
  5. #include <gpxe/dhcp.h>
  6. #include <gpxe/netdevice.h>
  7. #include <gpxe/ibft.h>
  8. #include <int13.h>
  9. #include <usr/iscsiboot.h>
  10. /**
  11. * Guess boot network device
  12. *
  13. * @ret netdev Boot network device
  14. */
  15. static struct net_device * guess_boot_netdev ( void ) {
  16. struct net_device *boot_netdev;
  17. /* Just use the first network device */
  18. for_each_netdev ( boot_netdev ) {
  19. return boot_netdev;
  20. }
  21. return NULL;
  22. }
  23. int iscsiboot ( const char *root_path ) {
  24. struct scsi_device scsi;
  25. struct int13_drive drive;
  26. int rc;
  27. memset ( &scsi, 0, sizeof ( scsi ) );
  28. memset ( &drive, 0, sizeof ( drive ) );
  29. printf ( "iSCSI booting from %s\n", root_path );
  30. if ( ( rc = iscsi_attach ( &scsi, root_path ) ) != 0 ) {
  31. printf ( "Could not attach iSCSI device: %s\n",
  32. strerror ( rc ) );
  33. goto error_attach;
  34. }
  35. if ( ( rc = init_scsidev ( &scsi ) ) != 0 ) {
  36. printf ( "Could not initialise iSCSI device: %s\n",
  37. strerror ( rc ) );
  38. goto error_init;
  39. }
  40. drive.drive = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
  41. drive.blockdev = &scsi.blockdev;
  42. /* FIXME: ugly, ugly hack */
  43. struct net_device *netdev = guess_boot_netdev();
  44. struct iscsi_session *iscsi =
  45. container_of ( scsi.backend, struct iscsi_session, refcnt );
  46. ibft_fill_data ( netdev, iscsi );
  47. register_int13_drive ( &drive );
  48. printf ( "Registered as BIOS drive %#02x\n", drive.drive );
  49. printf ( "Booting from BIOS drive %#02x\n", drive.drive );
  50. rc = int13_boot ( drive.drive );
  51. printf ( "Boot failed\n" );
  52. printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
  53. unregister_int13_drive ( &drive );
  54. error_init:
  55. iscsi_detach ( &scsi );
  56. error_attach:
  57. return rc;
  58. }