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.

ib_srpboot.c 1.6KB

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