iPXE
Macros | Functions | Variables
efi_cmdline.c File Reference

EFI command line. More...

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/script.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 71 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 56 of file efi_cmdline.c.

56  {
57  struct image *image = container_of ( refcnt, struct image, refcnt );
58 
59  DBGC ( image, "CMDLINE freeing command line\n" );
61 }
#define DBGC(...)
Definition: compiler.h:505
An executable image.
Definition: image.h:24
A reference counter.
Definition: refcnt.h:26
#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:49

References container_of, DBGC, efi_cmdline_copy, and free.

◆ efi_cmdline_init()

static int efi_cmdline_init ( void  )
static

Initialise EFI command line.

Return values
rcReturn status code

Definition at line 78 of file efi_cmdline.c.

78  {
79  char *cmdline;
80  size_t len;
81  int rc;
82 
83  /* Do nothing if no command line was specified */
84  if ( ! efi_cmdline_len ) {
85  DBGC ( colour, "CMDLINE found no command line\n" );
86  return 0;
87  }
88 
89  /* Allocate ASCII copy of command line */
90  len = ( ( efi_cmdline_len / sizeof ( efi_cmdline[0] ) ) + 1 /* NUL */ );
92  if ( ! efi_cmdline_copy ) {
93  rc = -ENOMEM;
94  goto err_alloc;
95  }
97  snprintf ( cmdline, len, "%ls", efi_cmdline );
98  DBGC ( colour, "CMDLINE found command line \"%s\"\n", cmdline );
99 
100  /* Mark command line as consumed */
101  efi_cmdline_len = 0;
102 
103  /* Strip image name and surrounding whitespace */
104  while ( isspace ( *cmdline ) )
105  cmdline++;
106  while ( *cmdline && ( ! isspace ( *cmdline ) ) )
107  cmdline++;
108  while ( isspace ( *cmdline ) )
109  cmdline++;
110  DBGC ( colour, "CMDLINE using command line \"%s\"\n", cmdline );
111 
112  /* Prepare and register image */
115  if ( efi_cmdline_image.len &&
116  ( ( rc = register_image ( &efi_cmdline_image ) ) != 0 ) ) {
117  DBGC ( colour, "CMDLINE could not register command line: %s\n",
118  strerror ( rc ) );
119  goto err_register_image;
120  }
121 
122  /* Drop our reference to the image */
124 
125  return 0;
126 
127  err_register_image:
129  err_alloc:
130  return rc;
131 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
userptr_t data
Raw file image.
Definition: image.h:41
const wchar_t * efi_cmdline
EFI command line (may not be wNUL-terminated.
Definition: efi_cmdline.c:43
#define DBGC(...)
Definition: compiler.h:505
#define ENOMEM
Not enough space.
Definition: errno.h:534
int register_image(struct image *image)
Register executable image.
Definition: image.c:267
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
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:228
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
#define colour
Colour for debug messages.
Definition: efi_cmdline.c:71
static char * efi_cmdline_copy
Internal copy of the command line.
Definition: efi_cmdline.c:49
uint32_t len
Length.
Definition: ena.h:14
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
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:46
uint32_t cmdline
Definition: multiboot.h:16
static struct image efi_cmdline_image
Embedded script representing the command line.
Definition: efi_cmdline.c:64

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

Referenced by efi_cmdline_startup().

◆ efi_cmdline_startup()

static void efi_cmdline_startup ( void  )
static

EFI command line startup function.

Definition at line 137 of file efi_cmdline.c.

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

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 43 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 46 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 49 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,
}
static void efi_cmdline_free(struct refcnt *refcnt)
Free command line image.
Definition: efi_cmdline.c:56
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77

Embedded script representing the command line.

Definition at line 64 of file efi_cmdline.c.

Referenced by efi_cmdline_init().