[iscsi] Change default initiator name prefix to "iqn.2000-01.org.etherboot:"
[people/dverkamp/gpxe.git] / src / image / embedded.c
1 /** @file
2  *
3  * Take a possible embedded image and put it in a struct image
4  * data structure.
5  */
6
7 #include <gpxe/image.h>
8 #include <gpxe/malloc.h>
9 #include <gpxe/uaccess.h>
10 #include <gpxe/umalloc.h>
11 #include <gpxe/embedded.h>
12
13 extern char _embedded_image_start[], _embedded_image_end[];
14
15 struct image *embedded_image(void)
16 {
17         static int reclaimed = 0;
18         struct image *image;
19         size_t eisize = _embedded_image_end - _embedded_image_start;
20
21         if ( !eisize )
22                 return NULL;    /* No embedded image */
23
24         if ( reclaimed )
25                 return NULL;    /* Already reclaimed */
26
27         DBG ( "Embedded image: %zd bytes at %p\n",
28               eisize, _embedded_image_start );
29
30         image = alloc_image();
31         if (!image)
32                 return NULL;
33
34         image->len     = eisize;
35         image->data    = umalloc(eisize);
36         if (image->data == UNULL) {
37                 image_put(image);
38                 return image = NULL;
39         }
40         copy_to_user(image->data, 0, _embedded_image_start, eisize);
41         register_image(image);
42
43         /* Reclaim embedded image memory */
44         reclaimed = 1;
45         mpopulate(_embedded_image_start, eisize);
46
47         return image;
48 }
49