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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/dhcp.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.drive = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
  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. }