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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. struct image_type pxe_image_type __image_type ( PROBE_PXE );
  34. /**
  35. * Execute PXE image
  36. *
  37. * @v image PXE image
  38. * @ret rc Return status code
  39. */
  40. static int pxe_exec ( struct image *image ) {
  41. struct net_device *netdev;
  42. int rc;
  43. /* Arbitrarily pick the most recently opened network device */
  44. if ( ( netdev = last_opened_netdev() ) == NULL ) {
  45. DBGC ( image, "IMAGE %p could not locate PXE net device\n",
  46. image );
  47. return -ENODEV;
  48. }
  49. /* Activate PXE */
  50. pxe_activate ( netdev );
  51. /* Start PXE NBP */
  52. rc = pxe_start_nbp();
  53. /* Deactivate PXE */
  54. pxe_deactivate();
  55. return rc;
  56. }
  57. /**
  58. * Load PXE image into memory
  59. *
  60. * @v image PXE file
  61. * @ret rc Return status code
  62. */
  63. int pxe_load ( struct image *image ) {
  64. userptr_t buffer = real_to_user ( 0, 0x7c00 );
  65. size_t filesz = image->len;
  66. size_t memsz = image->len;
  67. int rc;
  68. /* Images too large to fit in base memory cannot be PXE
  69. * images. We include this check to help prevent unrecognised
  70. * images from being marked as PXE images, since PXE images
  71. * have no signature we can check against.
  72. */
  73. if ( filesz > ( 0xa0000 - 0x7c00 ) )
  74. return -ENOEXEC;
  75. /* Rejecting zero-length images is also useful, since these
  76. * end up looking to the user like bugs in iPXE.
  77. */
  78. if ( ! filesz )
  79. return -ENOEXEC;
  80. /* There are no signature checks for PXE; we will accept anything */
  81. if ( ! image->type )
  82. image->type = &pxe_image_type;
  83. /* Verify and prepare segment */
  84. if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
  85. DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
  86. image, strerror ( rc ) );
  87. return rc;
  88. }
  89. /* Copy image to segment */
  90. memcpy_user ( buffer, 0, image->data, 0, filesz );
  91. return 0;
  92. }
  93. /** PXE image type */
  94. struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
  95. .name = "PXE",
  96. .load = pxe_load,
  97. .exec = pxe_exec,
  98. };