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.

aoeboot.c 1.7KB

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