iPXE
Macros | Functions | Variables
efi_cmdline.c File Reference

EFI command line. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/script.h>
#include <ipxe/uaccess.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_cmdline.h>

Go to the source code of this file.

Macros

#define colour   &efi_cmdline_image
 Colour for debug messages. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
static void efi_cmdline_free (struct refcnt *refcnt)
 Free command line image. More...
 
static int efi_cmdline_init (void)
 Initialise EFI command line. More...
 
static void efi_cmdline_startup (void)
 EFI command line startup function. More...
 
struct startup_fn efi_cmdline_startup_fn __startup_fn (STARTUP_NORMAL)
 Command line and initrd initialisation function. More...
 

Variables

const wchar_tefi_cmdline
 EFI command line (may not be wNUL-terminated. More...
 
size_t efi_cmdline_len
 Length of EFI command line (in bytes) More...
 
static char * efi_cmdline_copy
 Internal copy of the command line. More...
 
static struct image efi_cmdline_image
 Embedded script representing the command line. More...
 

Detailed Description

EFI command line.

Definition in file efi_cmdline.c.

Macro Definition Documentation

◆ colour

#define colour   &efi_cmdline_image

Colour for debug messages.

Definition at line 76 of file efi_cmdline.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ efi_cmdline_free()

static void efi_cmdline_free ( struct refcnt refcnt)
static

Free command line image.

Parameters
refcntReference count

Definition at line 59 of file efi_cmdline.c.

59  {
60  struct image *image = container_of ( refcnt, struct image, refcnt );
61 
62  DBGC ( image, "CMDLINE freeing command line\n" );
63  free_image ( refcnt );
65 }
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
A reference counter.
Definition: refcnt.h:27
void free_image(struct refcnt *refcnt)
Free executable image.
Definition: image.c:86
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
static char * efi_cmdline_copy
Internal copy of the command line.
Definition: efi_cmdline.c:52

References container_of, DBGC, efi_cmdline_copy, free, and free_image().

◆ efi_cmdline_init()

static int efi_cmdline_init ( void  )
static

Initialise EFI command line.

Return values
rcReturn status code

Definition at line 83 of file efi_cmdline.c.

83  {
84  char *cmdline;
85  size_t len;
86  int rc;
87 
88  /* Do nothing if no command line was specified */
89  if ( ! efi_cmdline_len ) {
90  DBGC ( colour, "CMDLINE found no command line\n" );
91  return 0;
92  }
93 
94  /* Allocate ASCII copy of command line */
95  len = ( ( efi_cmdline_len / sizeof ( efi_cmdline[0] ) ) + 1 /* NUL */ );
97  if ( ! efi_cmdline_copy ) {
98  rc = -ENOMEM;
99  goto err_alloc;
100  }
102  snprintf ( cmdline, len, "%ls", efi_cmdline );
103  DBGC ( colour, "CMDLINE found command line \"%s\"\n", cmdline );
104 
105  /* Mark command line as consumed */
106  efi_cmdline_len = 0;
107 
108  /* Strip image name and surrounding whitespace */
109  while ( isspace ( *cmdline ) )
110  cmdline++;
111  while ( *cmdline && ( ! isspace ( *cmdline ) ) )
112  cmdline++;
113  while ( isspace ( *cmdline ) )
114  cmdline++;
115  DBGC ( colour, "CMDLINE using command line \"%s\"\n", cmdline );
116 
117  /* Prepare and register image */
120  if ( efi_cmdline_image.len &&
121  ( ( rc = register_image ( &efi_cmdline_image ) ) != 0 ) ) {
122  DBGC ( colour, "CMDLINE could not register command line: %s\n",
123  strerror ( rc ) );
124  goto err_register_image;
125  }
126 
127  /* Drop our reference to the image */
129 
130  return 0;
131 
132  err_register_image:
134  err_alloc:
135  return rc;
136 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const wchar_t * efi_cmdline
EFI command line (may not be wNUL-terminated.
Definition: efi_cmdline.c:46
const void * data
Read-only data.
Definition: image.h:51
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:535
ring len
Length.
Definition: dwmac.h:231
int register_image(struct image *image)
Register executable image.
Definition: image.c:315
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
size_t len
Length of raw file image.
Definition: image.h:56
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:42
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:250
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
#define colour
Colour for debug messages.
Definition: efi_cmdline.c:76
static char * efi_cmdline_copy
Internal copy of the command line.
Definition: efi_cmdline.c:52
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383
size_t efi_cmdline_len
Length of EFI command line (in bytes)
Definition: efi_cmdline.c:49
uint32_t cmdline
Definition: multiboot.h:16
static struct image efi_cmdline_image
Embedded script representing the command line.
Definition: efi_cmdline.c:68

References cmdline, colour, image::data, DBGC, efi_cmdline, efi_cmdline_copy, efi_cmdline_image, efi_cmdline_len, ENOMEM, image_put(), isspace(), image::len, len, malloc(), rc, register_image(), snprintf(), strerror(), and strlen().

Referenced by efi_cmdline_startup().

◆ efi_cmdline_startup()

static void efi_cmdline_startup ( void  )
static

EFI command line startup function.

Definition at line 142 of file efi_cmdline.c.

142  {
143  int rc;
144 
145  /* Initialise command line */
146  if ( ( rc = efi_cmdline_init() ) != 0 ) {
147  /* No way to report failure */
148  return;
149  }
150 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int efi_cmdline_init(void)
Initialise EFI command line.
Definition: efi_cmdline.c:83

References efi_cmdline_init(), and rc.

◆ __startup_fn()

struct startup_fn efi_cmdline_startup_fn __startup_fn ( STARTUP_NORMAL  )

Command line and initrd initialisation function.

Variable Documentation

◆ efi_cmdline

const wchar_t* efi_cmdline

EFI command line (may not be wNUL-terminated.

Definition at line 46 of file efi_cmdline.c.

Referenced by efi_cmdline_init(), and efi_init().

◆ efi_cmdline_len

size_t efi_cmdline_len

Length of EFI command line (in bytes)

Definition at line 49 of file efi_cmdline.c.

Referenced by efi_cmdline_init(), and efi_init().

◆ efi_cmdline_copy

char* efi_cmdline_copy
static

Internal copy of the command line.

Definition at line 52 of file efi_cmdline.c.

Referenced by efi_cmdline_free(), and efi_cmdline_init().

◆ efi_cmdline_image

struct image efi_cmdline_image
static
Initial value:
= {
.refcnt = REF_INIT ( efi_cmdline_free ),
.name = "<CMDLINE>",
.type = &script_image_type,
}
uint32_t type
Operating system type.
Definition: ena.h:12
#define IMAGE_STATIC
Image is statically allocated.
Definition: image.h:89
static void efi_cmdline_free(struct refcnt *refcnt)
Free command line image.
Definition: efi_cmdline.c:59
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition: image.h:92
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:78

Embedded script representing the command line.

Definition at line 68 of file efi_cmdline.c.

Referenced by efi_cmdline_init().