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.

embedded.c 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 embedded_image_free ( struct refcnt *refcnt __unused ) {
  18. /* Do nothing */
  19. }
  20. /* Raw image data for all embedded images */
  21. #undef EMBED
  22. #define EMBED( _index, _path, _name ) \
  23. extern char embedded_image_ ## _index ## _data[]; \
  24. extern char embedded_image_ ## _index ## _len[]; \
  25. __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t" \
  26. "\nembedded_image_" #_index "_data:\n\t" \
  27. ".incbin \"" _path "\"\n\t" \
  28. "\nembedded_image_" #_index "_end:\n\t" \
  29. ".equ embedded_image_" #_index "_len, " \
  30. "( embedded_image_" #_index "_end - " \
  31. " embedded_image_" #_index "_data )\n\t" \
  32. ".previous\n\t" );
  33. EMBED_ALL
  34. /* Image structures for all embedded images */
  35. #undef EMBED
  36. #define EMBED( _index, _path, _name ) { \
  37. .refcnt = { .free = embedded_image_free, }, \
  38. .name = _name, \
  39. .data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
  40. .len = ( size_t ) embedded_image_ ## _index ## _len, \
  41. },
  42. static struct image embedded_images[] = {
  43. EMBED_ALL
  44. };
  45. /**
  46. * Register all embedded images
  47. */
  48. static void embedded_init ( void ) {
  49. unsigned int i;
  50. struct image *image;
  51. void *data;
  52. int rc;
  53. /* Fix up data pointers and register images */
  54. for ( i = 0 ; i < ( sizeof ( embedded_images ) /
  55. sizeof ( embedded_images[0] ) ) ; i++ ) {
  56. image = &embedded_images[i];
  57. /* virt_to_user() cannot be used in a static
  58. * initialiser, so we cast the pointer to a userptr_t
  59. * in the initialiser and fix it up here. (This will
  60. * actually be a no-op on most platforms.)
  61. */
  62. data = ( ( void * ) image->data );
  63. image->data = virt_to_user ( data );
  64. DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
  65. image->name, image->len, data );
  66. if ( ( rc = register_image ( image ) ) != 0 ) {
  67. DBG ( "Could not register embedded image \"%s\": "
  68. "%s\n", image->name, strerror ( rc ) );
  69. return;
  70. }
  71. }
  72. /* Load the first image */
  73. image = &embedded_images[0];
  74. if ( ( rc = image_autoload ( image ) ) != 0 ) {
  75. DBG ( "Could not load embedded image \"%s\": %s\n",
  76. image->name, strerror ( rc ) );
  77. return;
  78. }
  79. }
  80. /** Embedded image initialisation function */
  81. struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = {
  82. .initialise = embedded_init,
  83. };