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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/abft.h>
  10. #include <int13.h>
  11. #include <usr/aoeboot.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 *boot_netdev;
  19. /* Just use the first network device */
  20. for_each_netdev ( boot_netdev ) {
  21. return boot_netdev;
  22. }
  23. return NULL;
  24. }
  25. int aoeboot ( const char *root_path ) {
  26. struct ata_device ata;
  27. struct int13_drive drive;
  28. int rc;
  29. memset ( &ata, 0, sizeof ( ata ) );
  30. memset ( &drive, 0, sizeof ( drive ) );
  31. printf ( "AoE booting from %s\n", root_path );
  32. /* FIXME: ugly, ugly hack */
  33. struct net_device *netdev = guess_boot_netdev();
  34. if ( ( rc = aoe_attach ( &ata, netdev, root_path ) ) != 0 ) {
  35. printf ( "Could not attach AoE device: %s\n",
  36. strerror ( rc ) );
  37. goto error_attach;
  38. }
  39. if ( ( rc = init_atadev ( &ata ) ) != 0 ) {
  40. printf ( "Could not initialise AoE device: %s\n",
  41. strerror ( rc ) );
  42. goto error_init;
  43. }
  44. /* FIXME: ugly, ugly hack */
  45. struct aoe_session *aoe =
  46. container_of ( ata.backend, struct aoe_session, refcnt );
  47. abft_fill_data ( aoe );
  48. drive.blockdev = &ata.blockdev;
  49. register_int13_drive ( &drive );
  50. printf ( "Registered as BIOS drive %#02x\n", drive.drive );
  51. printf ( "Booting from BIOS drive %#02x\n", drive.drive );
  52. rc = int13_boot ( drive.drive );
  53. printf ( "Boot failed\n" );
  54. printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
  55. unregister_int13_drive ( &drive );
  56. error_init:
  57. aoe_detach ( &ata );
  58. error_attach:
  59. return rc;
  60. }