iPXE
console_cmd.c File Reference

Console management commands. More...

#include <string.h>
#include <getopt.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/console.h>
#include <ipxe/image.h>
#include <ipxe/pixbuf.h>
#include <ipxe/ansiesc.h>
#include <ipxe/ansicol.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Data Structures

struct  console_options
 "console" options More...
struct  colour_options
 "colour" options More...
struct  cpair_options
 "cpair" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int console_exec (int argc, char **argv)
 "console" command
static int colour_exec (int argc, char **argv)
 "colour" command
static int cpair_exec (int argc, char **argv)
 "cpair" command
 COMMAND (console, console_exec)
 Console management commands.
 COMMAND (colour, colour_exec)
 COMMAND (cpair, cpair_exec)

Variables

static struct option_descriptor console_opts []
 "console" option list
static struct command_descriptor console_cmd
 "console" command descriptor
static struct option_descriptor colour_opts []
 "colour" option list
static struct command_descriptor colour_cmd
 "colour" command descriptor
static struct option_descriptor cpair_opts []
 "cpair" option list
static struct command_descriptor cpair_cmd
 "cpair" command descriptor

Detailed Description

Console management commands.

Definition in file console_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ console_exec()

int console_exec ( int argc,
char ** argv )
static

"console" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 87 of file console_cmd.c.

87 {
88 struct console_options opts;
89 struct image *image = NULL;
90 int rc;
91
92 /* Parse options */
93 if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
94 goto err_parse;
95
96 /* Handle background picture, if applicable */
97 if ( opts.picture ) {
98
99 /* Acquire image */
100 if ( ( rc = imgacquire ( opts.picture, 0, &image ) ) != 0 )
101 goto err_acquire;
102
103 /* Convert to pixel buffer */
104 if ( ( rc = image_pixbuf ( image, &opts.config.pixbuf ) ) != 0){
105 printf ( "Could not use picture: %s\n",
106 strerror ( rc ) );
107 goto err_pixbuf;
108 }
109
110 /* Apply image's width and height if none specified */
111 if ( ! opts.config.width )
112 opts.config.width = opts.config.pixbuf->width;
113 if ( ! opts.config.height )
114 opts.config.height = opts.config.pixbuf->height;
115 }
116
117 /* Configure console */
118 if ( ( rc = console_configure ( &opts.config ) ) != 0 ) {
119 printf ( "Could not configure console: %s\n", strerror ( rc ) );
120 goto err_configure;
121 }
122
123 /* Reapply default colour pair and clear screen */
125 printf ( CSI "2J" CSI "H" );
126
127 err_configure:
128 pixbuf_put ( opts.config.pixbuf );
129 err_pixbuf:
130 /* Discard image unless --keep was specified */
131 if ( image && ( ! opts.keep ) )
133 err_acquire:
134 err_parse:
135 return rc;
136}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
void ansicol_set_pair(unsigned int cpair)
Set ANSI foreground and background colour.
Definition ansicol.c:90
#define CSI
Control Sequence Introducer.
Definition ansiesc.h:96
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
int console_configure(struct console_configuration *config)
Configure console.
Definition console.c:147
static struct command_descriptor console_cmd
"console" command descriptor
Definition console_cmd.c:77
#define CPAIR_DEFAULT
Default colour pair.
Definition ansicol.h:38
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition imgmgmt.c:143
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
int image_pixbuf(struct image *image, struct pixel_buffer **pixbuf)
Create pixel buffer from image.
Definition pixbuf.c:100
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
"console" options
Definition console_cmd.c:45
An executable image.
Definition image.h:24
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References ansicol_set_pair(), console_cmd, console_configure(), CPAIR_DEFAULT, CSI, image_pixbuf(), imgacquire(), NULL, opts, parse_options(), printf(), rc, strerror(), and unregister_image().

Referenced by COMMAND().

◆ colour_exec()

int colour_exec ( int argc,
char ** argv )
static

"colour" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 165 of file console_cmd.c.

165 {
166 struct colour_options opts;
167 unsigned int colour;
168 int rc;
169
170 /* Initialise options */
171 memset ( &opts, 0, sizeof ( opts ) );
172 opts.basic = COLOUR_DEFAULT;
173 opts.rgb = ANSICOL_NO_RGB;
174
175 /* Parse options */
176 if ( ( rc = reparse_options ( argc, argv, &colour_cmd, &opts ) ) != 0 )
177 return rc;
178
179 /* Parse colour index */
180 if ( ( rc = parse_integer ( argv[optind], &colour ) ) != 0 )
181 return rc;
182
183 /* Define colour */
184 if ( ( rc = ansicol_define ( colour, opts.basic, opts.rgb ) ) != 0 ) {
185 printf ( "Could not define colour: %s\n", strerror ( rc ) );
186 return rc;
187 }
188
189 /* Reapply default colour pair, in case definition has changed */
191
192 return 0;
193}
#define colour
Colour for debug messages.
Definition acpi.c:42
#define ANSICOL_NO_RGB
RGB value for "not defined".
Definition ansicol.h:30
#define COLOUR_DEFAULT
Default colour (usually white foreground, black background)
Definition ansicol.h:17
int ansicol_define(unsigned int colour, unsigned int basic, uint32_t rgb)
Define ANSI colour.
Definition ansicoldef.c:126
static struct command_descriptor colour_cmd
"colour" command descriptor
int optind
Current option index.
Definition getopt.c:52
void * memset(void *dest, int character, size_t len) __nonnull
int reparse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Reparse command-line options.
Definition parseopt.c:402
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition parseopt.c:92
"colour" options

References ansicol_define(), ANSICOL_NO_RGB, ansicol_set_pair(), colour, colour_cmd, COLOUR_DEFAULT, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

Referenced by COMMAND().

◆ cpair_exec()

int cpair_exec ( int argc,
char ** argv )
static

"cpair" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 222 of file console_cmd.c.

222 {
223 struct cpair_options opts;
224 unsigned int cpair;
225 int rc;
226
227 /* Initialise options */
228 memset ( &opts, 0, sizeof ( opts ) );
229 opts.foreground = COLOUR_DEFAULT;
230 opts.background = COLOUR_DEFAULT;
231
232 /* Parse options */
233 if ( ( rc = reparse_options ( argc, argv, &cpair_cmd, &opts ) ) != 0 )
234 return rc;
235
236 /* Parse colour pair index */
237 if ( ( rc = parse_integer ( argv[optind], &cpair ) ) != 0 )
238 return rc;
239
240 /* Define colour pair */
241 if ( ( rc = ansicol_define_pair ( cpair, opts.foreground,
242 opts.background ) ) != 0 ) {
243 printf ( "Could not define colour pair: %s\n",
244 strerror ( rc ) );
245 return rc;
246 }
247
248 /* Reapply default colour pair, in case definition has changed */
250
251 return 0;
252}
int ansicol_define_pair(unsigned int cpair, unsigned int foreground, unsigned int background)
Define ANSI colour pair.
Definition ansicol.c:111
static struct command_descriptor cpair_cmd
"cpair" command descriptor
"cpair" options

References ansicol_define_pair(), ansicol_set_pair(), COLOUR_DEFAULT, cpair_cmd, CPAIR_DEFAULT, memset(), optind, opts, parse_integer(), printf(), rc, reparse_options(), and strerror().

Referenced by COMMAND().

◆ COMMAND() [1/3]

COMMAND ( console ,
console_exec  )

Console management commands.

References console_exec().

◆ COMMAND() [2/3]

COMMAND ( colour ,
colour_exec  )

References colour, and colour_exec().

◆ COMMAND() [3/3]

COMMAND ( cpair ,
cpair_exec  )

References cpair_exec().

Variable Documentation

◆ console_opts

struct option_descriptor console_opts[]
static
Initial value:
= {
struct console_options, config.width, parse_integer ),
struct console_options, config.height, parse_integer ),
struct console_options, config.left, parse_integer ),
OPTION_DESC ( "right", 'r', required_argument,
struct console_options, config.right, parse_integer ),
struct console_options, config.top, parse_integer ),
OPTION_DESC ( "bottom", 'b', required_argument,
struct console_options, config.bottom, parse_integer ),
OPTION_DESC ( "depth", 'd', required_argument,
struct console_options, config.depth, parse_integer ),
OPTION_DESC ( "picture", 'p', required_argument,
struct console_options, picture, parse_string ),
OPTION_DESC ( "keep", 'k', no_argument,
struct console_options, keep, parse_flag ),
}
@ required_argument
Option requires an argument.
Definition getopt.h:19
@ no_argument
Option does not take an argument.
Definition getopt.h:17
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
int parse_string(char *text, char **value)
Parse string value.
Definition parseopt.c:74
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"console" option list

Definition at line 55 of file console_cmd.c.

55 {
57 struct console_options, config.width, parse_integer ),
59 struct console_options, config.height, parse_integer ),
60 OPTION_DESC ( "left", 'l', required_argument,
61 struct console_options, config.left, parse_integer ),
62 OPTION_DESC ( "right", 'r', required_argument,
63 struct console_options, config.right, parse_integer ),
64 OPTION_DESC ( "top", 't', required_argument,
65 struct console_options, config.top, parse_integer ),
66 OPTION_DESC ( "bottom", 'b', required_argument,
67 struct console_options, config.bottom, parse_integer ),
68 OPTION_DESC ( "depth", 'd', required_argument,
69 struct console_options, config.depth, parse_integer ),
70 OPTION_DESC ( "picture", 'p', required_argument,
71 struct console_options, picture, parse_string ),
72 OPTION_DESC ( "keep", 'k', no_argument,
73 struct console_options, keep, parse_flag ),
74};

◆ console_cmd

struct command_descriptor console_cmd
static
Initial value:
=
static struct option_descriptor console_opts[]
"console" option list
Definition console_cmd.c:55
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"console" command descriptor

Definition at line 77 of file console_cmd.c.

Referenced by console_exec(), and PROVIDE_REQUIRING_SYMBOL().

◆ colour_opts

struct option_descriptor colour_opts[]
static
Initial value:
= {
OPTION_DESC ( "basic", 'b', required_argument,
struct colour_options, basic, parse_integer ),
struct colour_options, rgb, parse_integer ),
}

"colour" option list

Definition at line 147 of file console_cmd.c.

147 {
148 OPTION_DESC ( "basic", 'b', required_argument,
149 struct colour_options, basic, parse_integer ),
150 OPTION_DESC ( "rgb", 'r', required_argument,
151 struct colour_options, rgb, parse_integer ),
152};

◆ colour_cmd

struct command_descriptor colour_cmd
static
Initial value:
=
COMMAND_DESC ( struct colour_options, colour_opts, 1, 1, "<colour>" )
static struct option_descriptor colour_opts[]
"colour" option list

"colour" command descriptor

Definition at line 155 of file console_cmd.c.

Referenced by colour_exec().

◆ cpair_opts

struct option_descriptor cpair_opts[]
static
Initial value:
= {
OPTION_DESC ( "foreground", 'f', required_argument,
struct cpair_options, foreground, parse_integer ),
OPTION_DESC ( "background", 'b', required_argument,
struct cpair_options, background, parse_integer ),
}

"cpair" option list

Definition at line 204 of file console_cmd.c.

204 {
205 OPTION_DESC ( "foreground", 'f', required_argument,
206 struct cpair_options, foreground, parse_integer ),
207 OPTION_DESC ( "background", 'b', required_argument,
208 struct cpair_options, background, parse_integer ),
209};

◆ cpair_cmd

struct command_descriptor cpair_cmd
static
Initial value:
=
COMMAND_DESC ( struct cpair_options, cpair_opts, 1, 1, "<cpair>" )
static struct option_descriptor cpair_opts[]
"cpair" option list

"cpair" command descriptor

Definition at line 212 of file console_cmd.c.

Referenced by cpair_exec().