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.4KB

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