iPXE
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.

Functions

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

Variables

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

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()

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" );
65}
static void * efi_cmdline_copy
Internal copy of the command line.
Definition efi_cmdline.c:52
#define DBGC(...)
Definition compiler.h:530
void free_image(struct refcnt *refcnt)
Free executable image.
Definition image.c:89
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
An executable image.
Definition image.h:24
A reference counter.
Definition refcnt.h:27

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

◆ efi_cmdline_init()

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 wchar_t *wcmdline;
85 char *cmdline;
86 size_t len;
87 int rc;
88
89 /* Do nothing if no command line was specified */
90 if ( ! efi_cmdline_len ) {
91 DBGC ( colour, "CMDLINE found no command line\n" );
92 return 0;
93 }
94
95 /* Create wNUL-terminated copy of command line */
96 len = ( efi_cmdline_len + 1 /* possible half CHAR16 */
97 + 2 /* wNUL */ );
99 if ( ! efi_cmdline_copy ) {
100 rc = -ENOMEM;
101 goto err_alloc;
102 }
104 wcmdline = efi_cmdline_copy;
105
106 /* Convert to ASCII in situ */
107 snprintf ( efi_cmdline_copy, len, "%ls", wcmdline );
109 wcmdline = NULL;
110 DBGC ( colour, "CMDLINE found command line \"%s\"\n", cmdline );
111
112 /* Mark command line as consumed */
113 efi_cmdline_len = 0;
114
115 /* Strip image name and surrounding whitespace */
116 while ( isspace ( *cmdline ) )
117 cmdline++;
118 while ( *cmdline && ( ! isspace ( *cmdline ) ) )
119 cmdline++;
120 while ( isspace ( *cmdline ) )
121 cmdline++;
122 DBGC ( colour, "CMDLINE using command line \"%s\"\n", cmdline );
123
124 /* Prepare and register image */
127 if ( efi_cmdline_image.len &&
128 ( ( rc = register_image ( &efi_cmdline_image ) ) != 0 ) ) {
129 DBGC ( colour, "CMDLINE could not register command line: %s\n",
130 strerror ( rc ) );
131 goto err_register_image;
132 }
133
134 /* Drop our reference to the image */
136
137 return 0;
138
139 err_register_image:
141 err_alloc:
142 return rc;
143}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
#define colour
Colour for debug messages.
Definition acpi.c:42
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
int isspace(int character)
Check to see if character is a space.
Definition ctype.c:42
ring len
Length.
Definition dwmac.h:226
size_t efi_cmdline_len
Length of EFI command line (in bytes).
Definition efi_cmdline.c:49
const wchar_t * efi_cmdline
EFI command line (may not be wNUL-terminated.
Definition efi_cmdline.c:46
static struct image efi_cmdline_image
Embedded script representing the command line.
Definition efi_cmdline.c:68
#define ENOMEM
Not enough space.
Definition errno.h:578
int register_image(struct image *image)
Register executable image.
Definition image.c:336
static void image_put(struct image *image)
Decrement reference count on an image.
Definition image.h:258
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:718
uint32_t cmdline
Definition multiboot.h:4
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
size_t strlen(const char *src)
Get length of string.
Definition string.c:244
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References cmdline, colour, DBGC, efi_cmdline, efi_cmdline_copy, efi_cmdline_image, efi_cmdline_len, ENOMEM, image_put(), isspace(), len, memcpy(), NULL, rc, register_image(), snprintf(), strerror(), strlen(), and zalloc().

Referenced by efi_cmdline_startup().

◆ efi_cmdline_startup()

void efi_cmdline_startup ( void )
static

EFI command line startup function.

Definition at line 149 of file efi_cmdline.c.

149 {
150 int rc;
151
152 /* Initialise command line */
153 if ( ( rc = efi_cmdline_init() ) != 0 ) {
154 /* No way to report failure */
155 return;
156 }
157}
static int efi_cmdline_init(void)
Initialise EFI command line.
Definition efi_cmdline.c:83

References efi_cmdline_init(), and rc.

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn efi_cmdline_startup_fn __startup_fn ( STARTUP_NORMAL )

Command line and initrd initialisation function.

References __startup_fn, efi_cmdline_startup(), and STARTUP_NORMAL.

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(), efi_init(), and FILE_SECBOOT().

◆ 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(), efi_init(), and FILE_SECBOOT().

◆ efi_cmdline_copy

void* 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,
}
static void efi_cmdline_free(struct refcnt *refcnt)
Free command line image.
Definition efi_cmdline.c:59
uint32_t type
Operating system type.
Definition ena.h:1
#define IMAGE_STATIC_NAME
Image name is statically allocated.
Definition image.h:99
#define IMAGE_STATIC
Image is statically allocated.
Definition image.h:96
#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.

68 {
69 .refcnt = REF_INIT ( efi_cmdline_free ),
70 .name = "<CMDLINE>",
71 .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ),
72 .type = &script_image_type,
73};

Referenced by efi_cmdline_init().