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

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