Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /** @file
  2. *
  3. * Embedded image support
  4. *
  5. * Embedded images are images built into the gPXE binary and do not require
  6. * fetching over the network.
  7. */
  8. #include <string.h>
  9. #include <gpxe/image.h>
  10. #include <gpxe/uaccess.h>
  11. #include <gpxe/init.h>
  12. /**
  13. * Free embedded image
  14. *
  15. * @v refcnt Reference counter
  16. */
  17. static void __attribute__ (( unused ))
  18. embedded_image_free ( struct refcnt *refcnt __unused ) {
  19. /* Do nothing */
  20. }
  21. /* Raw image data for all embedded images */
  22. #undef EMBED
  23. #define EMBED( _index, _path, _name ) \
  24. extern char embedded_image_ ## _index ## _data[]; \
  25. extern char embedded_image_ ## _index ## _len[]; \
  26. __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" \
  27. "\nembedded_image_" #_index "_data:\n\t" \
  28. ".incbin \"" _path "\"\n\t" \
  29. "\nembedded_image_" #_index "_end:\n\t" \
  30. ".equ embedded_image_" #_index "_len, " \
  31. "( embedded_image_" #_index "_end - " \
  32. " embedded_image_" #_index "_data )\n\t" \
  33. ".previous\n\t" );
  34. EMBED_ALL
  35. /* Image structures for all embedded images */
  36. #undef EMBED
  37. #define EMBED( _index, _path, _name ) { \
  38. .refcnt = { .free = embedded_image_free, }, \
  39. .name = _name, \
  40. .data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
  41. .len = ( size_t ) embedded_image_ ## _index ## _len, \
  42. },
  43. static struct image embedded_images[] = {
  44. EMBED_ALL
  45. };
  46. /**
  47. * Register all embedded images
  48. */
  49. static void embedded_init ( void ) {
  50. int i;
  51. struct image *image;
  52. void *data;
  53. int rc;
  54. /* Skip if we have no embedded images */
  55. if ( ! sizeof ( embedded_images ) )
  56. return;
  57. /* Fix up data pointers and register images */
  58. for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
  59. sizeof ( embedded_images[0] ) ) ; i++ ) {
  60. image = &embedded_images[i];
  61. /* virt_to_user() cannot be used in a static
  62. * initialiser, so we cast the pointer to a userptr_t
  63. * in the initialiser and fix it up here. (This will
  64. * actually be a no-op on most platforms.)
  65. */
  66. data = ( ( void * ) image->data );
  67. image->data = virt_to_user ( data );
  68. DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
  69. image->name, image->len, data );
  70. if ( ( rc = register_image ( image ) ) != 0 ) {
  71. DBG ( "Could not register embedded image \"%s\": "
  72. "%s\n", image->name, strerror ( rc ) );
  73. return;
  74. }
  75. }
  76. /* Load the first image */
  77. image = &embedded_images[0];
  78. if ( ( rc = image_autoload ( image ) ) != 0 ) {
  79. DBG ( "Could not load embedded image \"%s\": %s\n",
  80. image->name, strerror ( rc ) );
  81. return;
  82. }
  83. }
  84. /** Embedded image initialisation function */
  85. struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = {
  86. .initialise = embedded_init,
  87. };