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

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