Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

aoeboot.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * AoE boot information block
  14. *
  15. * Must be placed at 40:f0.
  16. *
  17. * This structure needs to be replaced by an ACPI table or similar.
  18. */
  19. struct aoe_boot_info {
  20. /** Must be 0x01 */
  21. uint8_t one;
  22. /** Client MAC address */
  23. uint8_t client[ETH_ALEN];
  24. /** Server MAC address */
  25. uint8_t server[ETH_ALEN];
  26. /** Shelf number */
  27. uint16_t shelf;
  28. /** Slot number */
  29. uint8_t slot;
  30. } __attribute__ (( packed ));
  31. /**
  32. * Guess boot network device
  33. *
  34. * @ret netdev Boot network device
  35. */
  36. static struct net_device * guess_boot_netdev ( void ) {
  37. struct net_device *boot_netdev;
  38. /* Just use the first network device */
  39. for_each_netdev ( boot_netdev ) {
  40. return boot_netdev;
  41. }
  42. return NULL;
  43. }
  44. int aoeboot ( const char *root_path ) {
  45. struct ata_device ata;
  46. struct int13_drive drive;
  47. int rc;
  48. memset ( &ata, 0, sizeof ( ata ) );
  49. memset ( &drive, 0, sizeof ( drive ) );
  50. printf ( "AoE booting from %s\n", root_path );
  51. /* FIXME: ugly, ugly hack */
  52. struct net_device *netdev = guess_boot_netdev();
  53. if ( ( rc = aoe_attach ( &ata, netdev, root_path ) ) != 0 ) {
  54. printf ( "Could not attach AoE device: %s\n",
  55. strerror ( rc ) );
  56. goto error_attach;
  57. }
  58. if ( ( rc = init_atadev ( &ata ) ) != 0 ) {
  59. printf ( "Could not initialise AoE device: %s\n",
  60. strerror ( rc ) );
  61. goto error_init;
  62. }
  63. /* FIXME: ugly, ugly hack */
  64. struct aoe_session *aoe =
  65. container_of ( ata.backend, struct aoe_session, refcnt );
  66. struct aoe_boot_info boot_info;
  67. boot_info.one = 0x01;
  68. memcpy ( boot_info.client, netdev->ll_addr,
  69. sizeof ( boot_info.client ) );
  70. memcpy ( boot_info.server, aoe->target,
  71. sizeof ( boot_info.server ) );
  72. boot_info.shelf = htons ( aoe->major );
  73. boot_info.slot = aoe->minor;
  74. copy_to_real ( 0x40, 0xf0, &boot_info, sizeof ( boot_info ) );
  75. abft_fill_data ( aoe );
  76. drive.drive = find_global_dhcp_num_option ( DHCP_EB_BIOS_DRIVE );
  77. drive.blockdev = &ata.blockdev;
  78. register_int13_drive ( &drive );
  79. printf ( "Registered as BIOS drive %#02x\n", drive.drive );
  80. printf ( "Booting from BIOS drive %#02x\n", drive.drive );
  81. rc = int13_boot ( drive.drive );
  82. printf ( "Boot failed\n" );
  83. printf ( "Unregistering BIOS drive %#02x\n", drive.drive );
  84. unregister_int13_drive ( &drive );
  85. error_init:
  86. aoe_detach ( &ata );
  87. error_attach:
  88. return rc;
  89. }