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 6.6KB

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