iPXE
embedded.c
Go to the documentation of this file.
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 
9 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
10 
11 #include <string.h>
12 #include <ipxe/image.h>
13 #include <ipxe/init.h>
14 
15 /* Raw image data for all embedded images */
16 #undef EMBED
17 #define EMBED( _index, _path, _name ) \
18  extern char embedded_image_ ## _index ## _data[]; \
19  extern size_t ABS_SYMBOL ( embedded_image_ ## _index ## _len ); \
20  __asm__ ( ".section \".data\", \"aw\", " PROGBITS "\n\t" \
21  "\nembedded_image_" #_index "_data:\n\t" \
22  ".incbin \"" _path "\"\n\t" \
23  "\nembedded_image_" #_index "_end:\n\t" \
24  ".equ embedded_image_" #_index "_len, " \
25  "( embedded_image_" #_index "_end - " \
26  " embedded_image_" #_index "_data )\n\t" \
27  ".previous\n\t" );
28 EMBED_ALL
29 
30 /* Image structures for all embedded images */
31 #undef EMBED
32 #define EMBED( _index, _path, _name ) { \
33  .refcnt = REF_INIT ( free_image ), \
34  .name = _name, \
35  .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
36  .rwdata = embedded_image_ ## _index ## _data, \
37  .len = ABS_VALUE_INIT ( embedded_image_ ## _index ## _len ), \
38 },
39 static struct image embedded_images[] = {
40  EMBED_ALL
41 };
42 
43 /**
44  * Register all embedded images
45  */
46 static void embedded_init ( void ) {
47  int i;
48  struct image *image;
49  void *data;
50  int rc;
51 
52  /* Skip if we have no embedded images */
53  if ( ! sizeof ( embedded_images ) )
54  return;
55 
56  /* Fix up data pointers and register images */
57  for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
58  sizeof ( embedded_images[0] ) ) ; i++ ) {
59  image = &embedded_images[i];
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 
69  /* Select the first image */
70  image = &embedded_images[0];
71  if ( ( rc = image_select ( image ) ) != 0 ) {
72  DBG ( "Could not select embedded image \"%s\": %s\n",
73  image->name, strerror ( rc ) );
74  return;
75  }
76 
77  /* Trust the selected image implicitly */
78  image_trust ( image );
79 }
80 
81 /** Embedded image initialisation function */
82 struct init_fn embedded_init_fn __init_fn ( INIT_LATE ) = {
83  .name = "embedded",
84  .initialise = embedded_init,
85 };
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int image_select(struct image *image)
Select image for execution.
Definition: image.c:564
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static void embedded_init(void)
Register all embedded images.
Definition: embedded.c:46
static struct image embedded_images[]
Definition: embedded.c:39
An executable image.
Definition: image.h:23
struct init_fn embedded_init_fn __init_fn(INIT_LATE)
Embedded image initialisation function.
An initialisation function.
Definition: init.h:14
Executable images.
const char * name
Definition: init.h:15
int register_image(struct image *image)
Register executable image.
Definition: image.c:314
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
size_t len
Length of raw file image.
Definition: image.h:55
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define INIT_LATE
Late initialisation.
Definition: init.h:32
static void image_trust(struct image *image)
Set image as trusted.
Definition: image.h:267
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
char * name
Name.
Definition: image.h:37
String functions.