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