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.

pxe_preboot.c 7.3KB

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