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.

iscsiboot.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #include <ipxe/iscsi.h>
  7. #include <ipxe/netdevice.h>
  8. #include <ipxe/ibft.h>
  9. #include <ipxe/sanboot.h>
  10. #include <int13.h>
  11. FILE_LICENCE ( GPL2_OR_LATER );
  12. static int iscsiboot ( const char *root_path ) {
  13. struct scsi_device *scsi;
  14. struct int13_drive *drive;
  15. int rc;
  16. scsi = zalloc ( sizeof ( *scsi ) );
  17. if ( ! scsi ) {
  18. rc = -ENOMEM;
  19. goto err_alloc_scsi;
  20. }
  21. drive = zalloc ( sizeof ( *drive ) );
  22. if ( ! drive ) {
  23. rc = -ENOMEM;
  24. goto err_alloc_drive;
  25. }
  26. if ( ( rc = iscsi_attach ( scsi, root_path ) ) != 0 ) {
  27. printf ( "Could not attach iSCSI device: %s\n",
  28. strerror ( rc ) );
  29. goto err_attach;
  30. }
  31. if ( ( rc = init_scsidev ( scsi ) ) != 0 ) {
  32. printf ( "Could not initialise iSCSI device: %s\n",
  33. strerror ( rc ) );
  34. goto err_init;
  35. }
  36. drive->blockdev = &scsi->blockdev;
  37. /* FIXME: ugly, ugly hack */
  38. struct net_device *netdev = last_opened_netdev();
  39. struct iscsi_session *iscsi =
  40. container_of ( scsi->backend, struct iscsi_session, refcnt );
  41. ibft_fill_data ( netdev, iscsi );
  42. register_int13_drive ( drive );
  43. printf ( "Registered as BIOS drive %#02x\n", drive->drive );
  44. printf ( "Booting from BIOS drive %#02x\n", drive->drive );
  45. rc = int13_boot ( drive->drive );
  46. printf ( "Boot failed\n" );
  47. /* Leave drive registered, if instructed to do so */
  48. if ( keep_san() )
  49. return rc;
  50. printf ( "Unregistering BIOS drive %#02x\n", drive->drive );
  51. unregister_int13_drive ( drive );
  52. err_init:
  53. iscsi_detach ( scsi );
  54. err_attach:
  55. free ( drive );
  56. err_alloc_drive:
  57. free ( scsi );
  58. err_alloc_scsi:
  59. return rc;
  60. }
  61. struct sanboot_protocol iscsi_sanboot_protocol __sanboot_protocol = {
  62. .prefix = "iscsi:",
  63. .boot = iscsiboot,
  64. };