Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

pxe_image.c 2.8KB

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. /**
  19. * @file
  20. *
  21. * PXE image format
  22. *
  23. */
  24. #include <pxe.h>
  25. #include <pxe_call.h>
  26. #include <gpxe/uaccess.h>
  27. #include <gpxe/image.h>
  28. #include <gpxe/segment.h>
  29. #include <gpxe/netdevice.h>
  30. #include <gpxe/features.h>
  31. FEATURE ( FEATURE_IMAGE, "PXE", DHCP_EB_FEATURE_PXE, 1 );
  32. struct image_type pxe_image_type __image_type ( PROBE_PXE );
  33. /**
  34. * Execute PXE image
  35. *
  36. * @v image PXE image
  37. * @ret rc Return status code
  38. */
  39. static int pxe_exec ( struct image *image ) {
  40. struct net_device *netdev;
  41. int rc;
  42. /* Ensure that PXE stack is ready to use */
  43. pxe_init_structures();
  44. pxe_hook_int1a();
  45. /* Arbitrarily pick the first open network device to use for PXE */
  46. for_each_netdev ( netdev ) {
  47. pxe_set_netdev ( netdev );
  48. break;
  49. }
  50. /* Many things will break if pxe_netdev is NULL */
  51. if ( ! pxe_netdev ) {
  52. DBGC ( image, "IMAGE %p could not locate PXE net device\n",
  53. image );
  54. return -ENODEV;
  55. }
  56. /* Start PXE NBP */
  57. rc = pxe_start_nbp();
  58. /* Deactivate PXE */
  59. pxe_set_netdev ( NULL );
  60. pxe_unhook_int1a();
  61. return rc;
  62. }
  63. /**
  64. * Load PXE image into memory
  65. *
  66. * @v image PXE file
  67. * @ret rc Return status code
  68. */
  69. int pxe_load ( struct image *image ) {
  70. userptr_t buffer = real_to_user ( 0, 0x7c00 );
  71. size_t filesz = image->len;
  72. size_t memsz = image->len;
  73. int rc;
  74. /* Images too large to fit in base memory cannot be PXE
  75. * images. We include this check to help prevent unrecognised
  76. * images from being marked as PXE images, since PXE images
  77. * have no signature we can check against.
  78. */
  79. if ( filesz > ( 0xa0000 - 0x7c00 ) )
  80. return -ENOEXEC;
  81. /* There are no signature checks for PXE; we will accept anything */
  82. if ( ! image->type )
  83. image->type = &pxe_image_type;
  84. /* Verify and prepare segment */
  85. if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
  86. DBGC ( image, "IMAGE %p could not prepare segment: %s\n",
  87. image, strerror ( rc ) );
  88. return rc;
  89. }
  90. /* Copy image to segment */
  91. memcpy_user ( buffer, 0, image->data, 0, filesz );
  92. return 0;
  93. }
  94. /** PXE image type */
  95. struct image_type pxe_image_type __image_type ( PROBE_PXE ) = {
  96. .name = "PXE",
  97. .load = pxe_load,
  98. .exec = pxe_exec,
  99. };