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_image.c 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <ipxe/uaccess.h>
  33. #include <ipxe/image.h>
  34. #include <ipxe/segment.h>
  35. #include <ipxe/netdevice.h>
  36. #include <ipxe/features.h>
  37. #include <ipxe/console.h>
  38. FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
  39. /** PXE command line */
  40. const char *pxe_cmdline;
  41. /**
  42. * Execute PXE image
  43. *
  44. * @v image PXE image
  45. * @ret rc Return status code
  46. */
  47. static int pxe_exec ( struct image *image ) {
  48. userptr_t buffer = real_to_user ( 0, 0x7c00 );
  49. struct net_device *netdev;
  50. int rc;
  51. /* Verify and prepare segment */
  52. if ( ( rc = prep_segment ( buffer, image->len, image->len ) ) != 0 ) {
  53. DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
  54. image, strerror ( rc ) );
  55. return rc;
  56. }
  57. /* Copy image to segment */
  58. memcpy_user ( buffer, 0, image->data, 0, image->len );
  59. /* Arbitrarily pick the most recently opened network device */
  60. if ( ( netdev = last_opened_netdev() ) == NULL ) {
  61. DBGC ( image, "IMAGE %p could not locate PXE net device\n",
  62. image );
  63. return -ENODEV;
  64. }
  65. netdev_get ( netdev );
  66. /* Activate PXE */
  67. pxe_activate ( netdev );
  68. /* Set PXE command line */
  69. pxe_cmdline = image->cmdline;
  70. /* Reset console since PXE NBP will probably use it */
  71. console_reset();
  72. /* Start PXE NBP */
  73. rc = pxe_start_nbp();
  74. /* Clear PXE command line */
  75. pxe_cmdline = NULL;
  76. /* Deactivate PXE */
  77. pxe_deactivate();
  78. /* Try to reopen network device. Ignore errors, since the NBP
  79. * may have called PXENV_STOP_UNDI.
  80. */
  81. netdev_open ( netdev );
  82. netdev_put ( netdev );
  83. return rc;
  84. }
  85. /**
  86. * Probe PXE image
  87. *
  88. * @v image PXE file
  89. * @ret rc Return status code
  90. */
  91. int pxe_probe ( struct image *image ) {
  92. /* Images too large to fit in base memory cannot be PXE
  93. * images. We include this check to help prevent unrecognised
  94. * images from being marked as PXE images, since PXE images
  95. * have no signature we can check against.
  96. */
  97. if ( image->len > ( 0xa0000 - 0x7c00 ) )
  98. return -ENOEXEC;
  99. /* Rejecting zero-length images is also useful, since these
  100. * end up looking to the user like bugs in iPXE.
  101. */
  102. if ( ! image->len )
  103. return -ENOEXEC;
  104. return 0;
  105. }
  106. /** PXE image type */
  107. struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
  108. .name = "PXE",
  109. .probe = pxe_probe,
  110. .exec = pxe_exec,
  111. };