Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

pxe_image.c 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. *
  19. * You can also choose to distribute this program under the terms of
  20. * the Unmodified Binary Distribution Licence (as given in the file
  21. * COPYING.UBDL), provided that you have satisfied its requirements.
  22. */
  23. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. /**
  25. * @file
  26. *
  27. * PXE image format
  28. *
  29. */
  30. #include <pxe.h>
  31. #include <pxe_call.h>
  32. #include <pic8259.h>
  33. #include <ipxe/uaccess.h>
  34. #include <ipxe/image.h>
  35. #include <ipxe/segment.h>
  36. #include <ipxe/netdevice.h>
  37. #include <ipxe/features.h>
  38. #include <ipxe/console.h>
  39. #include <ipxe/efi/efi.h>
  40. #include <ipxe/efi/IndustryStandard/PeImage.h>
  41. FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
  42. /** PXE command line */
  43. const char *pxe_cmdline;
  44. /**
  45. * Execute PXE image
  46. *
  47. * @v image PXE image
  48. * @ret rc Return status code
  49. */
  50. static int pxe_exec ( struct image *image ) {
  51. userptr_t buffer = real_to_user ( 0, 0x7c00 );
  52. struct net_device *netdev;
  53. int rc;
  54. /* Verify and prepare segment */
  55. if ( ( rc = prep_segment ( buffer, image->len, image->len ) ) != 0 ) {
  56. DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
  57. image, strerror ( rc ) );
  58. return rc;
  59. }
  60. /* Copy image to segment */
  61. memcpy_user ( buffer, 0, image->data, 0, image->len );
  62. /* Arbitrarily pick the most recently opened network device */
  63. if ( ( netdev = last_opened_netdev() ) == NULL ) {
  64. DBGC ( image, "IMAGE %p could not locate PXE net device\n",
  65. image );
  66. return -ENODEV;
  67. }
  68. netdev_get ( netdev );
  69. /* Activate PXE */
  70. pxe_activate ( netdev );
  71. /* Construct fake DHCP packets */
  72. pxe_fake_cached_info();
  73. /* Set PXE command line */
  74. pxe_cmdline = image->cmdline;
  75. /* Reset console since PXE NBP will probably use it */
  76. console_reset();
  77. /* Disable IRQ, if applicable */
  78. if ( netdev_irq_supported ( netdev ) && netdev->dev->desc.irq )
  79. disable_irq ( netdev->dev->desc.irq );
  80. /* Start PXE NBP */
  81. rc = pxe_start_nbp();
  82. /* Clear PXE command line */
  83. pxe_cmdline = NULL;
  84. /* Deactivate PXE */
  85. pxe_deactivate();
  86. /* Try to reopen network device. Ignore errors, since the NBP
  87. * may have called PXENV_STOP_UNDI.
  88. */
  89. netdev_open ( netdev );
  90. netdev_put ( netdev );
  91. return rc;
  92. }
  93. /**
  94. * Probe PXE image
  95. *
  96. * @v image PXE file
  97. * @ret rc Return status code
  98. */
  99. int pxe_probe ( struct image *image ) {
  100. /* Images too large to fit in base memory cannot be PXE
  101. * images. We include this check to help prevent unrecognised
  102. * images from being marked as PXE images, since PXE images
  103. * have no signature we can check against.
  104. */
  105. if ( image->len > ( 0xa0000 - 0x7c00 ) )
  106. return -ENOEXEC;
  107. /* Rejecting zero-length images is also useful, since these
  108. * end up looking to the user like bugs in iPXE.
  109. */
  110. if ( ! image->len )
  111. return -ENOEXEC;
  112. return 0;
  113. }
  114. /**
  115. * Probe PXE image (with rejection of potential EFI images)
  116. *
  117. * @v image PXE file
  118. * @ret rc Return status code
  119. */
  120. int pxe_probe_no_mz ( struct image *image ) {
  121. uint16_t magic;
  122. int rc;
  123. /* Probe PXE image */
  124. if ( ( rc = pxe_probe ( image ) ) != 0 )
  125. return rc;
  126. /* Reject image with an "MZ" signature which may indicate an
  127. * EFI image incorrectly handed out to a BIOS system.
  128. */
  129. if ( image->len >= sizeof ( magic ) ) {
  130. copy_from_user ( &magic, image->data, 0, sizeof ( magic ) );
  131. if ( magic == cpu_to_le16 ( EFI_IMAGE_DOS_SIGNATURE ) ) {
  132. DBGC ( image, "IMAGE %p may be an EFI image\n",
  133. image );
  134. return -ENOTTY;
  135. }
  136. }
  137. return 0;
  138. }
  139. /** PXE image type */
  140. struct image_type pxe_image_type[] __image_type ( PROBE_PXE ) = {
  141. {
  142. .name = "PXE-NBP",
  143. .probe = pxe_probe_no_mz,
  144. .exec = pxe_exec,
  145. },
  146. {
  147. .name = "PXE-NBP (may be EFI?)",
  148. .probe = pxe_probe,
  149. .exec = pxe_exec,
  150. },
  151. };