embedded.c

Go to the documentation of this file.
00001 /** @file
00002  *
00003  * Embedded image support
00004  *
00005  * Embedded images are images built into the gPXE binary and do not require
00006  * fetching over the network.
00007  */
00008 
00009 FILE_LICENCE ( GPL2_OR_LATER );
00010 
00011 #include <string.h>
00012 #include <gpxe/image.h>
00013 #include <gpxe/uaccess.h>
00014 #include <gpxe/init.h>
00015 
00016 /**
00017  * Free embedded image
00018  *
00019  * @v refcnt            Reference counter
00020  */
00021 static void __attribute__ (( unused ))
00022 embedded_image_free ( struct refcnt *refcnt __unused ) {
00023         /* Do nothing */
00024 }
00025 
00026 /* Raw image data for all embedded images */
00027 #undef EMBED
00028 #define EMBED( _index, _path, _name )                                   \
00029         extern char embedded_image_ ## _index ## _data[];               \
00030         extern char embedded_image_ ## _index ## _len[];                \
00031         __asm__ ( ".section \".rodata\", \"a\", @progbits\n\t"          \
00032                   "\nembedded_image_" #_index "_data:\n\t"              \
00033                   ".incbin \"" _path "\"\n\t"                           \
00034                   "\nembedded_image_" #_index "_end:\n\t"               \
00035                   ".equ embedded_image_" #_index "_len, "               \
00036                         "( embedded_image_" #_index "_end - "           \
00037                         "  embedded_image_" #_index "_data )\n\t"       \
00038                   ".previous\n\t" );
00039 EMBED_ALL
00040 
00041 /* Image structures for all embedded images */
00042 #undef EMBED
00043 #define EMBED( _index, _path, _name ) {                                 \
00044         .refcnt = { .free = embedded_image_free, },                     \
00045         .name = _name,                                                  \
00046         .data = ( userptr_t ) ( embedded_image_ ## _index ## _data ),   \
00047         .len = ( size_t ) embedded_image_ ## _index ## _len,            \
00048 },
00049 static struct image embedded_images[] = {
00050         EMBED_ALL
00051 };
00052 
00053 /**
00054  * Register all embedded images
00055  */
00056 static void embedded_init ( void ) {
00057         int i;
00058         struct image *image;
00059         void *data;
00060         int rc;
00061 
00062         /* Skip if we have no embedded images */
00063         if ( ! sizeof ( embedded_images ) )
00064                 return;
00065 
00066         /* Fix up data pointers and register images */
00067         for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
00068                                     sizeof ( embedded_images[0] ) ) ; i++ ) {
00069                 image = &embedded_images[i];
00070 
00071                 /* virt_to_user() cannot be used in a static
00072                  * initialiser, so we cast the pointer to a userptr_t
00073                  * in the initialiser and fix it up here.  (This will
00074                  * actually be a no-op on most platforms.)
00075                  */
00076                 data = ( ( void * ) image->data );
00077                 image->data = virt_to_user ( data );
00078 
00079                 DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
00080                       image->name, image->len, data );
00081 
00082                 if ( ( rc = register_image ( image ) ) != 0 ) {
00083                         DBG ( "Could not register embedded image \"%s\": "
00084                               "%s\n", image->name, strerror ( rc ) );
00085                         return;
00086                 }
00087         }
00088 
00089         /* Load the first image */
00090         image = &embedded_images[0];
00091         if ( ( rc = image_autoload ( image ) ) != 0 ) {
00092                 DBG ( "Could not load embedded image \"%s\": %s\n",
00093                       image->name, strerror ( rc ) );
00094                 return;
00095         }
00096 }
00097 
00098 /** Embedded image initialisation function */
00099 struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = {
00100         .initialise = embedded_init,
00101 };

Generated on Tue Apr 6 20:01:06 2010 for gPXE by  doxygen 1.5.7.1