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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. /* This is really, really awkward to support with our multiple
  77. * sources of options.
  78. */
  79. if ( get_cached_info->BufferLimit == 0 ) {
  80. get_cached_info->Buffer.segment = rm_ds;
  81. get_cached_info->Buffer.offset =
  82. ( unsigned int ) ( & __from_data16 ( dhcp_basemem ) );
  83. get_cached_info->BufferLimit = sizeof ( dhcp_basemem );
  84. }
  85. DBG ( " to %04x:%04x+%x", get_cached_info->Buffer.segment,
  86. get_cached_info->Buffer.offset, get_cached_info->BufferLimit );
  87. /* Allocate space for temporary copy */
  88. len = get_cached_info->BufferLimit;
  89. data = malloc ( len );
  90. if ( ! data ) {
  91. DBG ( " out of memory" );
  92. goto err;
  93. }
  94. /* Construct DHCP packet */
  95. if ( get_cached_info->PacketType == PXENV_PACKET_TYPE_DHCP_DISCOVER ) {
  96. msgtype = DHCPDISCOVER;
  97. options = &dhcp_request_options;
  98. } else {
  99. msgtype = DHCPACK;
  100. options = NULL;
  101. }
  102. if ( ( rc = create_dhcp_packet ( pxe_netdev, msgtype, data, len,
  103. &dhcppkt ) ) != 0 ) {
  104. DBG ( " failed to build packet" );
  105. goto err;
  106. }
  107. if ( ( rc = copy_dhcp_packet_options ( &dhcppkt, options ) ) != 0 ) {
  108. DBG ( " failed to copy options" );
  109. goto err;
  110. }
  111. /* Copy packet to client buffer */
  112. buffer = real_to_user ( get_cached_info->Buffer.segment,
  113. get_cached_info->Buffer.offset );
  114. len = dhcppkt.len;
  115. copy_to_user ( buffer, 0, data, len );
  116. get_cached_info->BufferSize = len;
  117. free ( data );
  118. get_cached_info->Status = PXENV_STATUS_SUCCESS;
  119. return PXENV_EXIT_SUCCESS;
  120. err:
  121. if ( data )
  122. free ( data );
  123. get_cached_info->Status = PXENV_STATUS_OUT_OF_RESOURCES;
  124. return PXENV_EXIT_FAILURE;
  125. }
  126. /* PXENV_RESTART_TFTP
  127. *
  128. * Status: working
  129. */
  130. PXENV_EXIT_t pxenv_restart_tftp ( struct s_PXENV_TFTP_READ_FILE
  131. *restart_tftp ) {
  132. DBG ( "PXENV_RESTART_TFTP" );
  133. #if 0
  134. /* Words cannot describe the complete mismatch between the PXE
  135. * specification and any possible version of reality...
  136. */
  137. restart_tftp->Buffer = PXE_LOAD_ADDRESS; /* Fixed by spec, apparently */
  138. restart_tftp->BufferSize = get_free_base_memory() - PXE_LOAD_ADDRESS; /* Near enough */
  139. DBG ( "(" );
  140. tftp_exit = pxe_api_call ( PXENV_TFTP_READ_FILE, (union u_PXENV_ANY*)restart_tftp );
  141. DBG ( ")" );
  142. if ( tftp_exit != PXENV_EXIT_SUCCESS ) return tftp_exit;
  143. /* Fire up the new NBP */
  144. restart_tftp->Status = xstartpxe();
  145. #endif
  146. /* Not sure what "SUCCESS" actually means, since we can only
  147. * return if the new NBP failed to boot...
  148. */
  149. return PXENV_EXIT_SUCCESS;
  150. }
  151. /* PXENV_START_UNDI
  152. *
  153. * Status: working
  154. */
  155. PXENV_EXIT_t pxenv_start_undi ( struct s_PXENV_START_UNDI *start_undi ) {
  156. DBG ( "PXENV_START_UNDI" );
  157. #if 0
  158. /* Record PCI bus & devfn passed by caller, so we know which
  159. * NIC they want to use.
  160. *
  161. * If they don't match our already-existing NIC structure, set
  162. * values to ensure that the specified NIC is used at the next
  163. * call to pxe_intialise_nic().
  164. */
  165. bus = ( start_undi->AX >> 8 ) & 0xff;
  166. devfn = start_undi->AX & 0xff;
  167. #warning "device probing mechanism has completely changed"
  168. #if 0
  169. if ( ( pci->dev.driver == NULL ) ||
  170. ( pci->dev.bus != bus ) || ( pci->dev.devfn != devfn ) ) {
  171. /* This is quite a bit of a hack and relies on
  172. * knowledge of the internal operation of Etherboot's
  173. * probe mechanism.
  174. */
  175. DBG ( " set PCI %hhx:%hhx.%hhx",
  176. bus, PCI_SLOT(devfn), PCI_FUNC(devfn) );
  177. dev->type = BOOT_NIC;
  178. dev->to_probe = PROBE_PCI;
  179. memset ( &dev->state, 0, sizeof(dev->state) );
  180. pci->advance = 1;
  181. pci->dev.use_specified = 1;
  182. pci->dev.bus = bus;
  183. pci->dev.devfn = devfn;
  184. }
  185. #endif
  186. #endif
  187. start_undi->Status = PXENV_STATUS_SUCCESS;
  188. return PXENV_EXIT_SUCCESS;
  189. }
  190. /* PXENV_STOP_UNDI
  191. *
  192. * Status: working
  193. */
  194. PXENV_EXIT_t pxenv_stop_undi ( struct s_PXENV_STOP_UNDI *stop_undi ) {
  195. DBG ( "PXENV_STOP_UNDI" );
  196. #if 0
  197. if ( ! ensure_pxe_state(CAN_UNLOAD) ) {
  198. stop_undi->Status = PXENV_STATUS_KEEP_UNDI;
  199. return PXENV_EXIT_FAILURE;
  200. }
  201. #endif
  202. stop_undi->Status = PXENV_STATUS_SUCCESS;
  203. return PXENV_EXIT_SUCCESS;
  204. }
  205. /* PXENV_START_BASE
  206. *
  207. * Status: won't implement (requires major structural changes)
  208. */
  209. PXENV_EXIT_t pxenv_start_base ( struct s_PXENV_START_BASE *start_base ) {
  210. DBG ( "PXENV_START_BASE" );
  211. start_base->Status = PXENV_STATUS_UNSUPPORTED;
  212. return PXENV_EXIT_FAILURE;
  213. }
  214. /* PXENV_STOP_BASE
  215. *
  216. * Status: working
  217. */
  218. PXENV_EXIT_t pxenv_stop_base ( struct s_PXENV_STOP_BASE *stop_base ) {
  219. DBG ( "PXENV_STOP_BASE" );
  220. /* The only time we will be called is when the NBP is trying
  221. * to shut down the PXE stack. There's nothing we need to do
  222. * in this call.
  223. */
  224. stop_base->Status = PXENV_STATUS_SUCCESS;
  225. return PXENV_EXIT_SUCCESS;
  226. }