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

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