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)
 
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 75 of file efi_cmdline.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_cmdline_free()

static void efi_cmdline_free ( struct refcnt refcnt)
static

Free command line image.

Parameters
refcntReference count

Definition at line 58 of file efi_cmdline.c.

58  {
59  struct image *image = container_of ( refcnt, struct image, refcnt );
60 
61  DBGC ( image, "CMDLINE freeing command line\n" );
62  free_image ( refcnt );
64 }
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:23
A reference counter.
Definition: refcnt.h:26
void free_image(struct refcnt *refcnt)
Free executable image.
Definition: image.c:85
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static char * efi_cmdline_copy
Internal copy of the command line.
Definition: efi_cmdline.c:51

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 82 of file efi_cmdline.c.

82  {
83  char *cmdline;
84  size_t len;
85  int rc;
86 
87  /* Do nothing if no command line was specified */
88  if ( ! efi_cmdline_len ) {
89  DBGC ( colour, "CMDLINE found no command line\n" );
90  return 0;
91  }
92 
93  /* Allocate ASCII copy of command line */
94  len = ( ( efi_cmdline_len / sizeof ( efi_cmdline[0] ) ) + 1 /* NUL */ );
96  if ( ! efi_cmdline_copy ) {
97  rc = -ENOMEM;
98  goto err_alloc;
99  }
101  snprintf ( cmdline, len, "%ls", efi_cmdline );
102  DBGC ( colour, "CMDLINE found command line \"%s\"\n", cmdline );
103 
104  /* Mark command line as consumed */
105  efi_cmdline_len = 0;
106 
107  /* Strip image name and surrounding whitespace */
108  while ( isspace ( *cmdline ) )
109  cmdline++;
110  while ( *cmdline && ( ! isspace ( *cmdline ) ) )
111  cmdline++;
112  while ( isspace ( *cmdline ) )
113  cmdline++;
114  DBGC ( colour, "CMDLINE using command line \"%s\"\n", cmdline );
115 
116  /* Prepare and register image */
119  if ( efi_cmdline_image.len &&
120  ( ( rc = register_image ( &efi_cmdline_image ) ) != 0 ) ) {
121  DBGC ( colour, "CMDLINE could not register command line: %s\n",
122  strerror ( rc ) );
123  goto err_register_image;
124  }
125 
126  /* Drop our reference to the image */
128 
129  return 0;
130 
131  err_register_image:
133  err_alloc:
134  return rc;
135 }
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:45
const void * data
Read-only data.
Definition: image.h:50
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:534
ring len
Length.
Definition: dwmac.h:231
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
int isspace(int character)
Check to see if character is a space.
Definition: ctype.c:41
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
static void image_put(struct image *image)
Decrement reference count on an image.
Definition: image.h:249
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:620
#define colour
Colour for debug messages.
Definition: efi_cmdline.c:75
static char * efi_cmdline_copy
Internal copy of the command line.
Definition: efi_cmdline.c:51
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
size_t efi_cmdline_len
Length of EFI command line (in bytes)
Definition: efi_cmdline.c:48
uint32_t cmdline
Definition: multiboot.h:16
static struct image efi_cmdline_image
Embedded script representing the command line.
Definition: efi_cmdline.c:67

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 141 of file efi_cmdline.c.

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

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 45 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 48 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 51 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:88
static void efi_cmdline_free(struct refcnt *refcnt)
Free command line image.
Definition: efi_cmdline.c:58
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition: image.h:91
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77

Embedded script representing the command line.

Definition at line 67 of file efi_cmdline.c.

Referenced by efi_cmdline_init().