embedded.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
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
00018
00019
00020
00021 static void __attribute__ (( unused ))
00022 embedded_image_free ( struct refcnt *refcnt __unused ) {
00023
00024 }
00025
00026
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
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
00055
00056 static void embedded_init ( void ) {
00057 int i;
00058 struct image *image;
00059 void *data;
00060 int rc;
00061
00062
00063 if ( ! sizeof ( embedded_images ) )
00064 return;
00065
00066
00067 for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
00068 sizeof ( embedded_images[0] ) ) ; i++ ) {
00069 image = &embedded_images[i];
00070
00071
00072
00073
00074
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
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
00099 struct init_fn embedded_init_fn __init_fn ( INIT_NORMAL ) = {
00100 .initialise = embedded_init,
00101 };