Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

pxe_preboot.c 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. #if 0
  25. #include "pxe.h"
  26. #include "pxe_callbacks.h"
  27. /**
  28. * UNLOAD BASE CODE STACK
  29. *
  30. * @v None -
  31. * @ret ...
  32. *
  33. */
  34. PXENV_EXIT_t pxenv_unload_stack ( struct s_PXENV_UNLOAD_STACK *unload_stack ) {
  35. int success;
  36. DBG ( "PXENV_UNLOAD_STACK" );
  37. success = ensure_pxe_state ( CAN_UNLOAD );
  38. /* We need to call cleanup() at some point. The network card
  39. * has already been disabled by ENSURE_CAN_UNLOAD(), but for
  40. * the sake of completeness we should call the console_fini()
  41. * etc. that are part of cleanup().
  42. *
  43. * There seems to be a lack of consensus on which is the final
  44. * PXE API call to make, but it's a fairly safe bet that all
  45. * the potential shutdown sequences will include a call to
  46. * PXENV_UNLOAD_STACK at some point, so we may as well do it
  47. * here.
  48. */
  49. cleanup();
  50. if ( ! success ) {
  51. unload_stack->Status = PXENV_STATUS_KEEP_ALL;
  52. return PXENV_EXIT_FAILURE;
  53. }
  54. unload_stack->Status = PXENV_STATUS_SUCCESS;
  55. return PXENV_EXIT_SUCCESS;
  56. }
  57. /* PXENV_GET_CACHED_INFO
  58. *
  59. * Status: working
  60. */
  61. PXENV_EXIT_t pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO
  62. *get_cached_info ) {
  63. BOOTPLAYER_t *cached_info = &pxe_stack->cached_info;
  64. DBG ( "PXENV_GET_CACHED_INFO %d", get_cached_info->PacketType );
  65. ENSURE_READY ( get_cached_info );
  66. /* Fill in cached_info structure in our pxe_stack */
  67. /* I don't think there's actually any way we can be called in
  68. * the middle of a DHCP request...
  69. */
  70. cached_info->opcode = BOOTP_REP;
  71. /* We only have Ethernet drivers */
  72. cached_info->Hardware = ETHER_TYPE;
  73. cached_info->Hardlen = ETH_ALEN;
  74. /* PXESPEC: "Client sets" says the spec, but who's filling in
  75. * this structure? It ain't the client.
  76. */
  77. cached_info->Gatehops = 0;
  78. cached_info->ident = 0;
  79. cached_info->seconds = 0;
  80. cached_info->Flags = BOOTP_BCAST;
  81. /* PXESPEC: What do 'Client' and 'Your' IP address refer to? */
  82. cached_info->cip = arptable[ARP_CLIENT].ipaddr.s_addr;
  83. cached_info->yip = arptable[ARP_CLIENT].ipaddr.s_addr;
  84. cached_info->sip = arptable[ARP_SERVER].ipaddr.s_addr;
  85. /* PXESPEC: Does "GIP" mean "Gateway" or "Relay agent"? */
  86. cached_info->gip = arptable[ARP_GATEWAY].ipaddr.s_addr;
  87. memcpy ( cached_info->CAddr, arptable[ARP_CLIENT].node, ETH_ALEN );
  88. /* Nullify server name */
  89. cached_info->Sname[0] = '\0';
  90. memcpy ( cached_info->bootfile, KERNEL_BUF,
  91. sizeof(cached_info->bootfile) );
  92. /* Copy DHCP vendor options */
  93. memcpy ( &cached_info->vendor.d, bootp_data.bootp_reply.bp_vend,
  94. sizeof(cached_info->vendor.d) );
  95. /* Copy to user-specified buffer, or set pointer to our buffer */
  96. get_cached_info->BufferLimit = sizeof(*cached_info);
  97. /* PXESPEC: says to test for Buffer == NULL *and* BufferSize =
  98. * 0, but what are we supposed to do with a null buffer of
  99. * non-zero size?!
  100. */
  101. if ( IS_NULL_SEGOFF16 ( get_cached_info->Buffer ) ) {
  102. /* Point back to our buffer */
  103. PTR_TO_SEGOFF16 ( cached_info, get_cached_info->Buffer );
  104. get_cached_info->BufferSize = sizeof(*cached_info);
  105. } else {
  106. /* Copy to user buffer */
  107. size_t size = sizeof(*cached_info);
  108. void *buffer = SEGOFF16_TO_PTR ( get_cached_info->Buffer );
  109. if ( get_cached_info->BufferSize < size )
  110. size = get_cached_info->BufferSize;
  111. DBG ( " to %x", virt_to_phys ( buffer ) );
  112. memcpy ( buffer, cached_info, size );
  113. /* PXESPEC: Should we return an error if the user
  114. * buffer is too small? We do return the actual size
  115. * of the buffer via BufferLimit, so the user does
  116. * have a way to detect this already.
  117. */
  118. }
  119. get_cached_info->Status = PXENV_STATUS_SUCCESS;
  120. return PXENV_EXIT_SUCCESS;
  121. }
  122. /* PXENV_RESTART_TFTP
  123. *
  124. * Status: working
  125. */
  126. PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
  127. *restart_tftp ) {
  128. PXENV_EXIT_t tftp_exit;
  129. DBG ( "PXENV_RESTART_TFTP" );
  130. ENSURE_READY ( restart_tftp );
  131. /* Words cannot describe the complete mismatch between the PXE
  132. * specification and any possible version of reality...
  133. */
  134. restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
  135. restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
  136. DBG ( "(" );
  137. tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
  138. DBG ( ")" );
  139. if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
  140. /* Fire up the new NBP */
  141. restart_tftp->Status = xstartpxe();
  142. /* Not sure what "SUCCESS" actually means, since we can only
  143. * return if the new NBP failed to boot...
  144. */
  145. return PXENV_EXIT_SUCCESS;
  146. }
  147. /* PXENV_START_UNDI
  148. *
  149. * Status: working
  150. */
  151. PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
  152. unsigned char bus, devfn;
  153. DBG ( "PXENV_START_UNDI" );
  154. ENSURE_MIDWAY(start_undi);
  155. /* Record PCI bus & devfn passed by caller, so we know which
  156. * NIC they want to use.
  157. *
  158. * If they don't match our already-existing NIC structure, set
  159. * values to ensure that the specified NIC is used at the next
  160. * call to pxe_intialise_nic().
  161. */
  162. bus = ( start_undi->AX >> 8 ) & 0xff;
  163. devfn = start_undi->AX & 0xff;
  164. #warning "device probing mechanism has completely changed"
  165. #if 0
  166. if ( ( pci->dev.driver == NULL ) ||
  167. ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
  168. /* This is quite a bit of a hack and relies on
  169. * knowledge of the internal operation of Etherboot's
  170. * probe mechanism.
  171. */
  172. DBG ( " set PCI %hhx:%hhx.%hhx",
  173. bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
  174. dev->type = BOOT_NIC;
  175. dev->to_probe = PROBE_PCI;
  176. memset ( &dev->state, 0, sizeof(dev->state) );
  177. pci->advance = 1;
  178. pci->dev.use_specified = 1;
  179. pci->dev.bus = bus;
  180. pci->dev.devfn = devfn;
  181. }
  182. #endif
  183. start_undi->Status = PXENV_STATUS_SUCCESS;
  184. return PXENV_EXIT_SUCCESS;
  185. }
  186. /* PXENV_STOP_UNDI
  187. *
  188. * Status: working
  189. */
  190. PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
  191. DBG ( "PXENV_STOP_UNDI" );
  192. if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
  193. stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
  194. return PXENV_EXIT_FAILURE;
  195. }
  196. stop_undi->Status = PXENV_STATUS_SUCCESS;
  197. return PXENV_EXIT_SUCCESS;
  198. }
  199. /* PXENV_START_BASE
  200. *
  201. * Status: won't implement (requires major structural changes)
  202. */
  203. PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
  204. DBG ( "PXENV_START_BASE" );
  205. /* ENSURE_READY ( 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. }
  222. #endif