Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

pxe_preboot.c 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /** @file
  2. *
  3. * PXE Preboot API
  4. *
  5. */
  6. /* PXE API interface for Etherboot.
  7. *
  8. * Copyright (C) 2004 Michael Brown <mbrown@fensystems.co.uk>.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of the
  13. * License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. */
  24. #include <stdint.h>
  25. #include <string.h>
  26. #include <malloc.h>
  27. #include <gpxe/uaccess.h>
  28. #include <gpxe/dhcp.h>
  29. #include "pxe.h"
  30. #include "pxe_callbacks.h"
  31. /**
  32. * UNLOAD BASE CODE STACK
  33. *
  34. * @v None -
  35. * @ret ...
  36. *
  37. */
  38. PXENV_EXIT_t pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) {
  39. DBG ( "PXENV_UNLOAD_STACK" );
  40. #if 0
  41. /* We need to call cleanup() at some point. The network card
  42. * has already been disabled by ENSURE_CAN_UNLOAD(), but for
  43. * the sake of completeness we should call the console_fini()
  44. * etc. that are part of cleanup().
  45. *
  46. * There seems to be a lack of consensus on which is the final
  47. * PXE API call to make, but it's a fairly safe bet that all
  48. * the potential shutdown sequences will include a call to
  49. * PXENV_UNLOAD_STACK at some point, so we may as well do it
  50. * here.
  51. */
  52. cleanup();
  53. if ( ! success ) {
  54. unload_stack->Status = PXENV_STATUS_KEEP_ALL;
  55. return PXENV_EXIT_FAILURE;
  56. }
  57. #endif
  58. unload_stack->Status = PXENV_STATUS_SUCCESS;
  59. return PXENV_EXIT_SUCCESS;
  60. }
  61. /* PXENV_GET_CACHED_INFO
  62. *
  63. * Status: working
  64. */
  65. PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
  66. *get_cached_info ) {
  67. struct dhcp_packet dhcppkt;
  68. void *data = NULL;
  69. size_t len;
  70. int msgtype;
  71. struct dhcp_option_block *options;
  72. userptr_t buffer;
  73. int rc;
  74. DBG ( "PXENV_GET_CACHED_INFO %d", get_cached_info->PacketType );
  75. /* This is really, really awkward to support with our multiple
  76. * sources of options.
  77. */
  78. if ( get_cached_info->BufferLimit == 0 ) {
  79. DBG ( " without an external buffer. Aargh." );
  80. goto err;
  81. }
  82. DBG ( " to %04x:%04x+%x\n", get_cached_info->Buffer.segment,
  83. get_cached_info->Buffer.offset, get_cached_info->BufferLimit );
  84. /* Allocate space for temporary copy */
  85. len = get_cached_info->BufferLimit;
  86. data = malloc ( len );
  87. if ( ! data ) {
  88. DBG ( " out of memory" );
  89. goto err;
  90. }
  91. /* Construct DHCP packet */
  92. if ( get_cached_info->PacketType == PXENV_PACKET_TYPE_DHCP_DISCOVER ) {
  93. msgtype = DHCPDISCOVER;
  94. options = &dhcp_request_options;
  95. } else {
  96. msgtype = DHCPACK;
  97. options = NULL;
  98. }
  99. if ( ( rc = create_dhcp_packet ( pxe_netdev, msgtype, data, len,
  100. &dhcppkt ) ) != 0 ) {
  101. DBG ( " failed to build packet" );
  102. goto err;
  103. }
  104. if ( ( rc = copy_dhcp_packet_options ( &dhcppkt, options ) ) != 0 ) {
  105. DBG ( " failed to copy options" );
  106. goto err;
  107. }
  108. /* Copy packet to client buffer */
  109. buffer = real_to_user ( get_cached_info->Buffer.segment,
  110. get_cached_info->Buffer.offset );
  111. copy_to_user ( buffer, 0, data, len );
  112. free ( data );
  113. get_cached_info->Status = PXENV_STATUS_SUCCESS;
  114. return PXENV_EXIT_SUCCESS;
  115. err:
  116. if ( data )
  117. free ( data );
  118. get_cached_info->Status = PXENV_STATUS_OUT_OF_RESOURCES;
  119. return PXENV_EXIT_FAILURE;
  120. }
  121. /* PXENV_RESTART_TFTP
  122. *
  123. * Status: working
  124. */
  125. PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
  126. *restart_tftp ) {
  127. DBG ( "PXENV_RESTART_TFTP" );
  128. #if 0
  129. /* Words cannot describe the complete mismatch between the PXE
  130. * specification and any possible version of reality...
  131. */
  132. restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
  133. restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
  134. DBG ( "(" );
  135. tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
  136. DBG ( ")" );
  137. if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
  138. /* Fire up the new NBP */
  139. restart_tftp->Status = xstartpxe();
  140. #endif
  141. /* Not sure what "SUCCESS" actually means, since we can only
  142. * return if the new NBP failed to boot...
  143. */
  144. return PXENV_EXIT_SUCCESS;
  145. }
  146. /* PXENV_START_UNDI
  147. *
  148. * Status: working
  149. */
  150. PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
  151. DBG ( "PXENV_START_UNDI" );
  152. #if 0
  153. /* Record PCI bus & devfn passed by caller, so we know which
  154. * NIC they want to use.
  155. *
  156. * If they don't match our already-existing NIC structure, set
  157. * values to ensure that the specified NIC is used at the next
  158. * call to pxe_intialise_nic().
  159. */
  160. bus = ( start_undi->AX >> 8 ) & 0xff;
  161. devfn = start_undi->AX & 0xff;
  162. #warning "device probing mechanism has completely changed"
  163. #if 0
  164. if ( ( pci->dev.driver == NULL ) ||
  165. ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
  166. /* This is quite a bit of a hack and relies on
  167. * knowledge of the internal operation of Etherboot's
  168. * probe mechanism.
  169. */
  170. DBG ( " set PCI %hhx:%hhx.%hhx",
  171. bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
  172. dev->type = BOOT_NIC;
  173. dev->to_probe = PROBE_PCI;
  174. memset ( &dev->state, 0, sizeof(dev->state) );
  175. pci->advance = 1;
  176. pci->dev.use_specified = 1;
  177. pci->dev.bus = bus;
  178. pci->dev.devfn = devfn;
  179. }
  180. #endif
  181. #endif
  182. start_undi->Status = PXENV_STATUS_SUCCESS;
  183. return PXENV_EXIT_SUCCESS;
  184. }
  185. /* PXENV_STOP_UNDI
  186. *
  187. * Status: working
  188. */
  189. PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
  190. DBG ( "PXENV_STOP_UNDI" );
  191. #if 0
  192. if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
  193. stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
  194. return PXENV_EXIT_FAILURE;
  195. }
  196. #endif
  197. stop_undi->Status = PXENV_STATUS_SUCCESS;
  198. return PXENV_EXIT_SUCCESS;
  199. }
  200. /* PXENV_START_BASE
  201. *
  202. * Status: won't implement (requires major structural changes)
  203. */
  204. PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
  205. DBG ( "PXENV_START_BASE" );
  206. start_base->Status = PXENV_STATUS_UNSUPPORTED;
  207. return PXENV_EXIT_FAILURE;
  208. }
  209. /* PXENV_STOP_BASE
  210. *
  211. * Status: working
  212. */
  213. PXENV_EXIT_t pxenv_stop_base ( struct s_PXENV_STOP_BASE *stop_base ) {
  214. DBG ( "PXENV_STOP_BASE" );
  215. /* The only time we will be called is when the NBP is trying
  216. * to shut down the PXE stack. There's nothing we need to do
  217. * in this call.
  218. */
  219. stop_base->Status = PXENV_STATUS_SUCCESS;
  220. return PXENV_EXIT_SUCCESS;
  221. }