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 char * 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 char * efi_cmdline_copy
Internal copy of the command line.
Definition efi_cmdline.c:52
#define DBGC(...)
Definition compiler.h:505
void free_image(struct refcnt *refcnt)
Free executable image.
Definition image.c:86
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 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}
#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:535
int register_image(struct image *image)
Register executable image.
Definition image.c:315
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
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, malloc(), rc, register_image(), snprintf(), strerror(), and strlen().

Referenced by efi_cmdline_startup().

◆ efi_cmdline_startup()

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}
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

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,
}
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:92
#define IMAGE_STATIC
Image is statically allocated.
Definition image.h:89
#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().