Преглед на файлове

[cmdline] Add "console" command to configure console

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown преди 11 години
родител
ревизия
0b81be823d
променени са 3 файла, в които са добавени 129 реда и са изтрити 0 реда
  1. 3
    0
      src/config/config.c
  2. 1
    0
      src/config/general.h
  3. 125
    0
      src/hci/commands/console_cmd.c

+ 3
- 0
src/config/config.c Целия файл

@@ -278,6 +278,9 @@ REQUIRE_OBJECT ( neighbour_cmd );
278 278
 #ifdef PING_CMD
279 279
 REQUIRE_OBJECT ( ping_cmd );
280 280
 #endif
281
+#ifdef CONSOLE_CMD
282
+REQUIRE_OBJECT ( console_cmd );
283
+#endif
281 284
 
282 285
 /*
283 286
  * Drag in miscellaneous objects

+ 1
- 0
src/config/general.h Целия файл

@@ -135,6 +135,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
135 135
 //#define PARAM_CMD		/* Form parameter commands */
136 136
 //#define NEIGHBOUR_CMD		/* Neighbour management commands */
137 137
 //#define PING_CMD		/* Ping command */
138
+//#define CONSOLE_CMD		/* Console command */
138 139
 
139 140
 /*
140 141
  * ROM-specific options

+ 125
- 0
src/hci/commands/console_cmd.c Целия файл

@@ -0,0 +1,125 @@
1
+/*
2
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+/** @file
23
+ *
24
+ * Console management commands
25
+ *
26
+ */
27
+
28
+#include <string.h>
29
+#include <getopt.h>
30
+#include <ipxe/command.h>
31
+#include <ipxe/parseopt.h>
32
+#include <ipxe/console.h>
33
+#include <ipxe/image.h>
34
+#include <ipxe/pixbuf.h>
35
+#include <usr/imgmgmt.h>
36
+
37
+/** "console" options */
38
+struct console_options {
39
+	/** Console configuration */
40
+	struct console_configuration config;
41
+	/** Picture URI */
42
+	char *picture;
43
+	/** Keep picture after configuration */
44
+	int keep;
45
+};
46
+
47
+/** "console" option list */
48
+static struct option_descriptor console_opts[] = {
49
+	OPTION_DESC ( "x", 'x', required_argument,
50
+		      struct console_options, config.width, parse_integer ),
51
+	OPTION_DESC ( "y", 'y', required_argument,
52
+		      struct console_options, config.height, parse_integer ),
53
+	OPTION_DESC ( "bpp", 'b', required_argument,
54
+		      struct console_options, config.bpp, parse_integer ),
55
+	OPTION_DESC ( "picture", 'p', required_argument,
56
+		      struct console_options, picture, parse_string ),
57
+	OPTION_DESC ( "keep", 'k', no_argument,
58
+		      struct console_options, keep, parse_flag ),
59
+};
60
+
61
+/** "console" command descriptor */
62
+static struct command_descriptor console_cmd =
63
+	COMMAND_DESC ( struct console_options, console_opts, 0, 0, NULL );
64
+
65
+/**
66
+ * "console" command
67
+ *
68
+ * @v argc		Argument count
69
+ * @v argv		Argument list
70
+ * @ret rc		Return status code
71
+ */
72
+static int console_exec ( int argc, char **argv ) {
73
+	struct console_options opts;
74
+	struct image *image = NULL;
75
+	int rc;
76
+
77
+	/* Parse options */
78
+	if ( ( rc = parse_options ( argc, argv, &console_cmd, &opts ) ) != 0 )
79
+		goto err_parse;
80
+
81
+	/* Handle background picture, if applicable */
82
+	if ( opts.picture ) {
83
+
84
+		/* Acquire image */
85
+		if ( ( rc = imgacquire ( opts.picture, &image ) ) != 0 )
86
+			goto err_acquire;
87
+
88
+		/* Convert to pixel buffer */
89
+		if ( ( rc = image_pixbuf ( image, &opts.config.pixbuf ) ) != 0){
90
+			printf ( "Could not use picture: %s\n",
91
+				 strerror ( rc ) );
92
+			goto err_pixbuf;
93
+		}
94
+
95
+		/* Apply image's width and height if none specified */
96
+		if ( ! opts.config.width )
97
+			opts.config.width = opts.config.pixbuf->width;
98
+		if ( ! opts.config.height )
99
+			opts.config.height = opts.config.pixbuf->height;
100
+	}
101
+
102
+	/* Configure console */
103
+	if ( ( rc = console_configure ( &opts.config ) ) != 0 ) {
104
+		printf ( "Could not configure console: %s\n", strerror ( rc ) );
105
+		goto err_configure;
106
+	}
107
+
108
+ err_configure:
109
+	pixbuf_put ( opts.config.pixbuf );
110
+ err_pixbuf:
111
+	/* Discard image unless --keep was specified */
112
+	if ( image && ( ! opts.keep ) )
113
+		unregister_image ( image );
114
+ err_acquire:
115
+ err_parse:
116
+	return rc;
117
+}
118
+
119
+/** Console management commands */
120
+struct command console_commands[] __command = {
121
+	{
122
+		.name = "console",
123
+		.exec = console_exec,
124
+	},
125
+};

Loading…
Отказ
Запис