iPXE
runtime.c File Reference

Command line and initrd passed to iPXE at runtime. More...

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/init.h>
#include <ipxe/image.h>
#include <ipxe/script.h>
#include <realmode.h>

Go to the source code of this file.

Macros

#define cmdline_phys   __use_data16 ( cmdline_phys )
#define initrd_phys   __use_data16 ( initrd_phys )
#define initrd_len
#define colour   &cmdline_image
 Colour for debug messages.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
uint32_t __bss16 (cmdline_phys)
 Command line physical address.
uint32_t __bss16 (initrd_phys)
 initrd physical address
uint32_t __bss16 (initrd_len)
 initrd length
static void cmdline_image_free (struct refcnt *refcnt)
 Free command line image.
static void cmdline_strip (char *cmdline, const char *cruft)
 Strip unwanted cruft from command line.
static int cmdline_init (void)
 Initialise command line.
static int initrd_init (void)
 Initialise initrd.
static void runtime_init (void)
 Initialise command line and initrd.
struct startup_fn runtime_startup_fn __startup_fn (STARTUP_NORMAL)
 Command line and initrd initialisation function.

Variables

static char * cmdline_copy
 Internal copy of the command line.
static struct image cmdline_image
 Embedded script representing the command line.

Detailed Description

Command line and initrd passed to iPXE at runtime.

Definition in file runtime.c.

Macro Definition Documentation

◆ cmdline_phys

#define cmdline_phys   __use_data16 ( cmdline_phys )

Definition at line 49 of file runtime.c.

Referenced by __bss16(), and cmdline_init().

◆ initrd_phys

#define initrd_phys   __use_data16 ( initrd_phys )

Definition at line 56 of file runtime.c.

Referenced by __bss16(), and initrd_init().

◆ initrd_len

#define initrd_len ( void)
Value:
#define __use_data16(variable)
Definition libkir.h:20
#define initrd_len
Definition runtime.c:63

Definition at line 63 of file runtime.c.

Referenced by __bss16(), bzimage_check_initrds(), fdt_bootargs(), fdt_create(), initrd_init(), and lkrn_exec().

◆ colour

#define colour   &cmdline_image

Colour for debug messages.

Definition at line 86 of file runtime.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ __bss16() [1/3]

uint32_t __bss16 ( cmdline_phys )

Command line physical address.

This can be set by the prefix.

References cmdline_phys.

◆ __bss16() [2/3]

uint32_t __bss16 ( initrd_phys )

initrd physical address

This can be set by the prefix.

References initrd_phys.

◆ __bss16() [3/3]

uint32_t __bss16 ( initrd_len )

initrd length

This can be set by the prefix.

References initrd_len.

◆ cmdline_image_free()

void cmdline_image_free ( struct refcnt * refcnt)
static

Free command line image.

Definition at line 69 of file runtime.c.

69 {
70 struct image *image = container_of ( refcnt, struct image, refcnt );
71
72 DBGC ( image, "RUNTIME freeing command line\n" );
75}
#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
static char * cmdline_copy
Internal copy of the command line.
Definition runtime.c:66
#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 cmdline_copy, container_of, DBGC, free, and free_image().

◆ cmdline_strip()

void cmdline_strip ( char * cmdline,
const char * cruft )
static

Strip unwanted cruft from command line.

Parameters
cmdlineCommand line
cruftInitial substring of cruft to strip

Definition at line 94 of file runtime.c.

94 {
95 char *strip;
96 char *strip_end;
97
98 /* Find unwanted cruft, if present */
99 if ( ! ( strip = strstr ( cmdline, cruft ) ) )
100 return;
101
102 /* Strip unwanted cruft */
103 strip_end = strchr ( strip, ' ' );
104 if ( strip_end ) {
105 *strip_end = '\0';
106 DBGC ( colour, "RUNTIME stripping \"%s\"\n", strip );
107 strcpy ( strip, ( strip_end + 1 ) );
108 } else {
109 DBGC ( colour, "RUNTIME stripping \"%s\"\n", strip );
110 *strip = '\0';
111 }
112}
#define colour
Colour for debug messages.
Definition acpi.c:42
uint32_t cmdline
Definition multiboot.h:4
char * strchr(const char *src, int character)
Find character within a string.
Definition string.c:272
char * strstr(const char *haystack, const char *needle)
Find substring.
Definition string.c:310
char * strcpy(char *dest, const char *src)
Copy string.
Definition string.c:347

References cmdline, colour, DBGC, strchr(), strcpy(), and strstr().

Referenced by cmdline_init().

◆ cmdline_init()

int cmdline_init ( void )
static

Initialise command line.

Return values
rcReturn status code

Definition at line 119 of file runtime.c.

119 {
120 char *cmdline;
121 int rc;
122
123 /* Do nothing if no command line was specified */
124 if ( ! cmdline_phys ) {
125 DBGC ( colour, "RUNTIME found no command line\n" );
126 return 0;
127 }
128
129 /* Allocate and copy command line */
130 cmdline_copy = strdup ( phys_to_virt ( cmdline_phys ) );
131 if ( ! cmdline_copy ) {
132 DBGC ( colour, "RUNTIME could not allocate command line\n" );
133 rc = -ENOMEM;
134 goto err_alloc_cmdline_copy;
135 }
137 DBGC ( colour, "RUNTIME found command line \"%s\" at %08x\n",
139
140 /* Mark command line as consumed */
141 cmdline_phys = 0;
142
143 /* Strip unwanted cruft from the command line */
144 cmdline_strip ( cmdline, "BOOT_IMAGE=" );
145 cmdline_strip ( cmdline, "initrd=" );
146 while ( isspace ( *cmdline ) )
147 cmdline++;
148 DBGC ( colour, "RUNTIME using command line \"%s\"\n", cmdline );
149
150 /* Prepare and register image */
151 cmdline_image.data = cmdline;
152 cmdline_image.len = strlen ( cmdline );
153 if ( cmdline_image.len ) {
154 if ( ( rc = register_image ( &cmdline_image ) ) != 0 ) {
155 DBGC ( colour, "RUNTIME could not register command "
156 "line: %s\n", strerror ( rc ) );
157 goto err_register_image;
158 }
159 }
160
161 /* Drop our reference to the image */
163
164 return 0;
165
166 err_register_image:
168 err_alloc_cmdline_copy:
169 return rc;
170}
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
#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
static struct image cmdline_image
Embedded script representing the command line.
Definition runtime.c:78
#define cmdline_phys
Definition runtime.c:49
static void cmdline_strip(char *cmdline, const char *cruft)
Strip unwanted cruft from command line.
Definition runtime.c:94
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
char * strdup(const char *src)
Duplicate string.
Definition string.c:394
size_t strlen(const char *src)
Get length of string.
Definition string.c:244

References cmdline, cmdline_copy, cmdline_image, cmdline_phys, cmdline_strip(), colour, DBGC, ENOMEM, image_put(), isspace(), rc, register_image(), strdup(), strerror(), and strlen().

Referenced by runtime_init().

◆ initrd_init()

int initrd_init ( void )
static

Initialise initrd.

Return values
rcReturn status code

Definition at line 177 of file runtime.c.

177 {
178 struct image *image;
179
180 /* Do nothing if no initrd was specified */
181 if ( ! initrd_phys ) {
182 DBGC ( colour, "RUNTIME found no initrd\n" );
183 return 0;
184 }
185 if ( ! initrd_len ) {
186 DBGC ( colour, "RUNTIME found empty initrd\n" );
187 return 0;
188 }
189 DBGC ( colour, "RUNTIME found initrd at [%x,%x)\n",
191
192 /* Create initrd image */
193 image = image_memory ( "<INITRD>", phys_to_virt ( initrd_phys ),
194 initrd_len );
195 if ( ! image ) {
196 DBGC ( colour, "RUNTIME could not create initrd image\n" );
197 return -ENOMEM;
198 }
199
200 /* Mark initrd as consumed */
201 initrd_phys = 0;
202
203 return 0;
204}
struct image * image_memory(const char *name, const void *data, size_t len)
Create registered image from block of memory.
Definition image.c:609
#define initrd_phys
Definition runtime.c:56

References colour, DBGC, ENOMEM, image_memory(), initrd_len, and initrd_phys.

Referenced by runtime_init().

◆ runtime_init()

void runtime_init ( void )
static

Initialise command line and initrd.

Definition at line 210 of file runtime.c.

210 {
211 int rc;
212
213 /* Initialise command line */
214 if ( ( rc = cmdline_init() ) != 0 ) {
215 /* No way to report failure */
216 return;
217 }
218
219 /* Initialise initrd */
220 if ( ( rc = initrd_init() ) != 0 ) {
221 /* No way to report failure */
222 return;
223 }
224}
static int initrd_init(void)
Initialise initrd.
Definition runtime.c:177
static int cmdline_init(void)
Initialise command line.
Definition runtime.c:119

References cmdline_init(), initrd_init(), and rc.

Referenced by __startup_fn().

◆ __startup_fn()

struct startup_fn runtime_startup_fn __startup_fn ( STARTUP_NORMAL )

Command line and initrd initialisation function.

References __startup_fn, runtime_init(), and STARTUP_NORMAL.

Variable Documentation

◆ cmdline_copy

char* cmdline_copy
static

Internal copy of the command line.

Definition at line 66 of file runtime.c.

Referenced by cmdline_image_free(), and cmdline_init().

◆ cmdline_image

struct image cmdline_image
static
Initial value:
= {
.name = "<CMDLINE>",
.type = &script_image_type,
}
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
static void cmdline_image_free(struct refcnt *refcnt)
Free command line image.
Definition runtime.c:69

Embedded script representing the command line.

Definition at line 78 of file runtime.c.

78 {
79 .refcnt = REF_INIT ( cmdline_image_free ),
80 .name = "<CMDLINE>",
81 .flags = ( IMAGE_STATIC | IMAGE_STATIC_NAME ),
82 .type = &script_image_type,
83};

Referenced by cmdline_init().