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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdint.h>
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <gpxe/aoe.h>
  5. #include <gpxe/ata.h>
  6. #include <gpxe/netdevice.h>
  7. #include <gpxe/dhcp.h>
  8. #include <int13.h>
  9. #include <usr/aoeboot.h>
  10. /**
  11. * Guess boot network device
  12. *
  13. * @ret netdev Boot network device
  14. */
  15. static struct net_device * guess_boot_netdev ( void ) {
  16. struct net_device *boot_netdev;
  17. /* Just use the first network device */
  18. for_each_netdev ( boot_netdev ) {
  19. return boot_netdev;
  20. }
  21. return NULL;
  22. }
  23. int aoeboot ( const char *root_path ) {
  24. struct ata_device ata;
  25. struct int13_drive drive;
  26. int rc;
  27. memset ( &ata, 0, sizeof ( ata ) );
  28. memset ( &drive, 0, sizeof ( drive ) );
  29. printf ( "AoE booting from %s\n", root_path );
  30. /* FIXME: ugly, ugly hack */
  31. struct net_device *netdev = guess_boot_netdev();
  32. if ( ( rc = aoe_attach ( &ata, netdev, root_path ) ) != 0 ) {
  33. printf ( "Could not attach AoE device: %s\n",
  34. strerror ( rc ) );
  35. goto error_attach;
  36. }
  37. if ( ( rc = init_atadev ( &ata ) ) != 0 ) {
  38. printf ( "Could not initialise AoE device: %s\n",
  39. strerror ( rc ) );
  40. goto error_init;
  41. }
  42. drive.drive = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
  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. printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
  50. unregister_int13_drive ( &drive );
  51. error_init:
  52. aoe_detach ( &ata );
  53. error_attach:
  54. return rc;
  55. }