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

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