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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <byteswap.h>
  5. #include <gpxe/aoe.h>
  6. #include <gpxe/ata.h>
  7. #include <gpxe/netdevice.h>
  8. #include <gpxe/settings.h>
  9. #include <gpxe/sanboot.h>
  10. #include <gpxe/abft.h>
  11. #include <int13.h>
  12. /**
  13. * Guess boot network device
  14. *
  15. * @ret netdev Boot network device
  16. */
  17. static struct net_device * guess_boot_netdev ( void ) {
  18. struct net_device *netdev;
  19. /* Just use the first network device */
  20. for_each_netdev ( netdev ) {
  21. if ( netdev->state & NETDEV_OPEN )
  22. return netdev;
  23. }
  24. return NULL;
  25. }
  26. static int aoeboot ( const char *root_path ) {
  27. struct ata_device ata;
  28. struct int13_drive drive;
  29. int rc;
  30. memset ( &ata, 0, sizeof ( ata ) );
  31. memset ( &drive, 0, sizeof ( drive ) );
  32. printf ( "AoE booting from %s\n", root_path );
  33. /* FIXME: ugly, ugly hack */
  34. struct net_device *netdev = guess_boot_netdev();
  35. if ( ( rc = aoe_attach ( &ata, netdev, root_path ) ) != 0 ) {
  36. printf ( "Could not attach AoE device: %s\n",
  37. strerror ( rc ) );
  38. goto error_attach;
  39. }
  40. if ( ( rc = init_atadev ( &ata ) ) != 0 ) {
  41. printf ( "Could not initialise AoE device: %s\n",
  42. strerror ( rc ) );
  43. goto error_init;
  44. }
  45. /* FIXME: ugly, ugly hack */
  46. struct aoe_session *aoe =
  47. container_of ( ata.backend, struct aoe_session, refcnt );
  48. abft_fill_data ( aoe );
  49. drive.blockdev = &ata.blockdev;
  50. register_int13_drive ( &drive );
  51. printf ( "Registered as BIOS drive %#02x\n", drive.drive );
  52. printf ( "Booting from BIOS drive %#02x\n", drive.drive );
  53. rc = int13_boot ( drive.drive );
  54. printf ( "Boot failed\n" );
  55. printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
  56. unregister_int13_drive ( &drive );
  57. error_init:
  58. aoe_detach ( &ata );
  59. error_attach:
  60. return rc;
  61. }
  62. struct sanboot_protocol aoe_sanboot_protocol __sanboot_protocol = {
  63. .prefix = "aoe:",
  64. .boot = aoeboot,
  65. };