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 ".byte 0\n\t" /* NUL */ \
29 ".previous\n\t" );
30EMBED_ALL
31
32/* Image structures for all embedded images */
33#undef EMBED
34#define EMBED( _index, _path, _name ) { \
35 .refcnt = REF_INIT ( free_image ), \
36 .name = _name, \
37 .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ), \
38 .rwdata = embedded_image_ ## _index ## _data, \
39 .len = ABS_VALUE_INIT ( embedded_image_ ## _index ## _len ), \
40},
41static struct image embedded_images[] = {
42 EMBED_ALL
43};
44
45/**
46 * Register all embedded images
47 */
48static void embedded_init ( void ) {
49 int i;
50 struct image *image;
51 void *data;
52 int rc;
53
54 /* Skip if we have no embedded images */
55 if ( ! sizeof ( embedded_images ) )
56 return;
57
58 /* Fix up data pointers and register images */
59 for ( i = 0 ; i < ( int ) ( sizeof ( embedded_images ) /
60 sizeof ( embedded_images[0] ) ) ; i++ ) {
62 DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
63 image->name, image->len, data );
64 if ( ( rc = register_image ( image ) ) != 0 ) {
65 DBG ( "Could not register embedded image \"%s\": "
66 "%s\n", image->name, strerror ( rc ) );
67 return;
68 }
69 }
70
71 /* Select the first image */
73 if ( ( rc = image_select ( image ) ) != 0 ) {
74 DBG ( "Could not select embedded image \"%s\": %s\n",
75 image->name, strerror ( rc ) );
76 return;
77 }
78
79 /* Trust the selected image implicitly */
81}
82
83/** Embedded image initialisation function */
84struct init_fn embedded_init_fn __init_fn ( INIT_LATE ) = {
85 .name = "embedded",
86 .initialise = embedded_init,
87};
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static struct image embedded_images[]
Definition embedded.c:41
static void embedded_init(void)
Register all embedded images.
Definition embedded.c:48
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define DBG(...)
Print a debugging message.
Definition compiler.h:523
#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:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
int register_image(struct image *image)
Register executable image.
Definition image.c:336
int image_select(struct image *image)
Select image for execution.
Definition image.c:597
Executable images.
static void image_trust(struct image *image)
Set image as trusted.
Definition image.h:276
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:63
An initialisation function.
Definition init.h:15