iPXE
Macros | Functions | Variables
embedded.c File Reference

Embedded image support. More...

#include <string.h>
#include <ipxe/image.h>
#include <ipxe/uaccess.h>
#include <ipxe/init.h>

Go to the source code of this file.

Macros

#define EMBED(_index, _path, _name)
 
#define EMBED(_index, _path, _name)
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void embedded_init (void)
 Register all embedded images. More...
 
struct init_fn embedded_init_fn __init_fn (INIT_LATE)
 Embedded image initialisation function. More...
 

Variables

static struct image embedded_images []
 

Detailed Description

Embedded image support.

Embedded images are images built into the iPXE binary and do not require fetching over the network.

Definition in file embedded.c.

Macro Definition Documentation

◆ EMBED [1/2]

#define EMBED (   _index,
  _path,
  _name 
)
Value:
extern char embedded_image_ ## _index ## _data[]; \
extern char embedded_image_ ## _index ## _len[]; \
__asm__ ( ".section \".rodata\", \"a\", " PROGBITS "\n\t" \
"\nembedded_image_" #_index "_data:\n\t" \
".incbin \"" _path "\"\n\t" \
"\nembedded_image_" #_index "_end:\n\t" \
".equ embedded_image_" #_index "_len, " \
"( embedded_image_" #_index "_end - " \
" embedded_image_" #_index "_data )\n\t" \
".previous\n\t" );
#define PROGBITS
Definition: compiler.h:61

Definition at line 33 of file embedded.c.

◆ EMBED [2/2]

#define EMBED (   _index,
  _path,
  _name 
)
Value:
{ \
.refcnt = REF_INIT ( ref_no_free ), \
.name = _name, \
.data = ( userptr_t ) ( embedded_image_ ## _index ## _data ), \
.len = ( size_t ) embedded_image_ ## _index ## _len, \
},
__SIZE_TYPE__ size_t
Definition: stdint.h:6
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

Definition at line 33 of file embedded.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ embedded_init()

static void embedded_init ( void  )
static

Register all embedded images.

Definition at line 46 of file embedded.c.

46  {
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 
61  /* virt_to_user() cannot be used in a static
62  * initialiser, so we cast the pointer to a userptr_t
63  * in the initialiser and fix it up here. (This will
64  * actually be a no-op on most platforms.)
65  */
66  data = ( ( void * ) image->data );
67  image->data = virt_to_user ( data );
68 
69  DBG ( "Embedded image \"%s\": %zd bytes at %p\n",
70  image->name, image->len, data );
71 
72  if ( ( rc = register_image ( image ) ) != 0 ) {
73  DBG ( "Could not register embedded image \"%s\": "
74  "%s\n", image->name, strerror ( rc ) );
75  return;
76  }
77  }
78 
79  /* Select the first image */
80  image = &embedded_images[0];
81  if ( ( rc = image_select ( image ) ) != 0 ) {
82  DBG ( "Could not select embedded image \"%s\": %s\n",
83  image->name, strerror ( rc ) );
84  return;
85  }
86 
87  /* Trust the selected image implicitly */
88  image_trust ( image );
89 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int image_select(struct image *image)
Select image for execution.
Definition: image.c:503
userptr_t data
Raw file image.
Definition: image.h:41
static struct image embedded_images[]
Definition: embedded.c:39
An executable image.
Definition: image.h:24
int register_image(struct image *image)
Register executable image.
Definition: image.c:264
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:43
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
uint8_t data[48]
Additional event data.
Definition: ena.h:22
static void image_trust(struct image *image)
Set image as trusted.
Definition: image.h:246
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
char * name
Name.
Definition: image.h:34

References data, image::data, DBG, embedded_images, image_select(), image_trust(), image::len, image::name, rc, register_image(), strerror(), and virt_to_user().

◆ __init_fn()

struct init_fn embedded_init_fn __init_fn ( INIT_LATE  )

Embedded image initialisation function.

Variable Documentation

◆ embedded_images

struct image embedded_images[]
static
Initial value:
= {
EMBED_ALL
}

Definition at line 39 of file embedded.c.

Referenced by embedded_init().