blob: d2667cf84e481544dacc65a6d5b825b983443e50 [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Erik Andersen1c5b2581999-12-16 20:59:36 +00002/*
3 * Mini fbset implementation for busybox
4 *
5 * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * This is a from-scratch implementation of fbset; but the de facto fbset
22 * implementation was a good reference. fbset (original) is released under
Eric Andersenc7bda1c2004-03-15 08:29:22 +000023 * the GPL, and is (c) 1995-1999 by:
Erik Andersen1c5b2581999-12-16 20:59:36 +000024 * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
25 */
26
Erik Andersen1c5b2581999-12-16 20:59:36 +000027#include <stdio.h>
28#include <stdlib.h>
29#include <unistd.h>
30#include <fcntl.h>
31#include <errno.h>
32#include <ctype.h>
Eric Andersened3ef502001-01-27 08:24:39 +000033#include <string.h>
Eric Andersen1eceb122003-07-14 19:32:40 +000034#include <stdint.h>
Erik Andersen1c5b2581999-12-16 20:59:36 +000035#include <sys/ioctl.h>
Eric Andersencbe31da2001-02-20 06:14:08 +000036#include "busybox.h"
Erik Andersen1c5b2581999-12-16 20:59:36 +000037
Eric Andersen5f284552003-11-14 03:11:29 +000038#define DEFAULTFBDEV FB_0
Erik Andersen1c5b2581999-12-16 20:59:36 +000039#define DEFAULTFBMODE "/etc/fb.modes"
40
Mark Whitley59ab0252001-01-23 22:30:04 +000041enum {
Rob Landleybc68cd12006-03-10 19:22:06 +000042 OPT_CHANGE = (1 << 0),
43 OPT_INFO = (1 << 1),
44 OPT_READMODE = (1 << 2),
45
Mark Whitley59ab0252001-01-23 22:30:04 +000046 CMD_FB = 1,
47 CMD_DB = 2,
48 CMD_GEOMETRY = 3,
49 CMD_TIMING = 4,
50 CMD_ACCEL = 5,
51 CMD_HSYNC = 6,
52 CMD_VSYNC = 7,
53 CMD_LACED = 8,
54 CMD_DOUBLE = 9,
Tim Rikerc1ef7bd2006-01-25 00:08:53 +000055/* CMD_XCOMPAT = 10, */
Mark Whitley59ab0252001-01-23 22:30:04 +000056 CMD_ALL = 11,
57 CMD_INFO = 12,
58 CMD_CHANGE = 13,
Erik Andersen1c5b2581999-12-16 20:59:36 +000059
Eric Andersenbdfd0d72001-10-24 05:00:29 +000060#ifdef CONFIG_FEATURE_FBSET_FANCY
Mark Whitley59ab0252001-01-23 22:30:04 +000061 CMD_XRES = 100,
62 CMD_YRES = 101,
63 CMD_VXRES = 102,
64 CMD_VYRES = 103,
65 CMD_DEPTH = 104,
66 CMD_MATCH = 105,
67 CMD_PIXCLOCK = 106,
68 CMD_LEFT = 107,
69 CMD_RIGHT = 108,
70 CMD_UPPER = 109,
71 CMD_LOWER = 110,
72 CMD_HSLEN = 111,
73 CMD_VSLEN = 112,
74 CMD_CSYNC = 113,
75 CMD_GSYNC = 114,
76 CMD_EXTSYNC = 115,
77 CMD_BCAST = 116,
78 CMD_RGBA = 117,
79 CMD_STEP = 118,
80 CMD_MOVE = 119,
Erik Andersen1c5b2581999-12-16 20:59:36 +000081#endif
Mark Whitley59ab0252001-01-23 22:30:04 +000082};
Erik Andersen1c5b2581999-12-16 20:59:36 +000083
84static unsigned int g_options = 0;
85
Eric Andersenc873d612000-09-21 04:09:58 +000086/* Stuff stolen from the kernel's fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +000087enum {
88 FBIOGET_VSCREENINFO = 0x4600,
89 FBIOPUT_VSCREENINFO = 0x4601
90};
Eric Andersenc873d612000-09-21 04:09:58 +000091struct fb_bitfield {
Eric Andersen1eceb122003-07-14 19:32:40 +000092 uint32_t offset; /* beginning of bitfield */
93 uint32_t length; /* length of bitfield */
Eric Andersenc7bda1c2004-03-15 08:29:22 +000094 uint32_t msb_right; /* != 0 : Most significant bit is */
95 /* right */
Eric Andersenc873d612000-09-21 04:09:58 +000096};
97struct fb_var_screeninfo {
Eric Andersen1eceb122003-07-14 19:32:40 +000098 uint32_t xres; /* visible resolution */
99 uint32_t yres;
100 uint32_t xres_virtual; /* virtual resolution */
101 uint32_t yres_virtual;
102 uint32_t xoffset; /* offset from virtual to visible */
103 uint32_t yoffset; /* resolution */
Eric Andersenc873d612000-09-21 04:09:58 +0000104
Eric Andersen1eceb122003-07-14 19:32:40 +0000105 uint32_t bits_per_pixel; /* guess what */
106 uint32_t grayscale; /* != 0 Graylevels instead of colors */
Eric Andersenc873d612000-09-21 04:09:58 +0000107
108 struct fb_bitfield red; /* bitfield in fb mem if true color, */
109 struct fb_bitfield green; /* else only length is significant */
110 struct fb_bitfield blue;
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000111 struct fb_bitfield transp; /* transparency */
Eric Andersenc873d612000-09-21 04:09:58 +0000112
Eric Andersen1eceb122003-07-14 19:32:40 +0000113 uint32_t nonstd; /* != 0 Non standard pixel format */
Eric Andersenc873d612000-09-21 04:09:58 +0000114
Eric Andersen1eceb122003-07-14 19:32:40 +0000115 uint32_t activate; /* see FB_ACTIVATE_* */
Eric Andersenc873d612000-09-21 04:09:58 +0000116
Eric Andersen1eceb122003-07-14 19:32:40 +0000117 uint32_t height; /* height of picture in mm */
118 uint32_t width; /* width of picture in mm */
Eric Andersenc873d612000-09-21 04:09:58 +0000119
Eric Andersen1eceb122003-07-14 19:32:40 +0000120 uint32_t accel_flags; /* acceleration flags (hints) */
Eric Andersenc873d612000-09-21 04:09:58 +0000121
122 /* Timing: All values in pixclocks, except pixclock (of course) */
Eric Andersen1eceb122003-07-14 19:32:40 +0000123 uint32_t pixclock; /* pixel clock in ps (pico seconds) */
124 uint32_t left_margin; /* time from sync to picture */
125 uint32_t right_margin; /* time from picture to sync */
126 uint32_t upper_margin; /* time from sync to picture */
127 uint32_t lower_margin;
128 uint32_t hsync_len; /* length of horizontal sync */
129 uint32_t vsync_len; /* length of vertical sync */
130 uint32_t sync; /* see FB_SYNC_* */
131 uint32_t vmode; /* see FB_VMODE_* */
132 uint32_t reserved[6]; /* Reserved for future compatibility */
Eric Andersenc873d612000-09-21 04:09:58 +0000133};
134
135
"Vladimir N. Oleynik"b399a962006-02-01 12:41:35 +0000136static const struct cmdoptions_t {
Aaron Lehmann60694412002-08-13 04:19:23 +0000137 const char *name;
138 const unsigned char param_count;
139 const unsigned char code;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000140} g_cmdoptions[] = {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000141 {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000142 "-fb", 1, CMD_FB}, {
143 "-db", 1, CMD_DB}, {
144 "-a", 0, CMD_ALL}, {
145 "-i", 0, CMD_INFO}, {
146 "-g", 5, CMD_GEOMETRY}, {
147 "-t", 7, CMD_TIMING}, {
148 "-accel", 1, CMD_ACCEL}, {
149 "-hsync", 1, CMD_HSYNC}, {
150 "-vsync", 1, CMD_VSYNC}, {
151 "-laced", 1, CMD_LACED}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000152 "-double", 1, CMD_DOUBLE}, {
Eric Andersenc8c10c52000-07-06 17:23:23 +0000153 "-n", 0, CMD_CHANGE}, {
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000154#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +0000155 "-all", 0, CMD_ALL}, {
156 "-xres", 1, CMD_XRES}, {
157 "-yres", 1, CMD_YRES}, {
158 "-vxres", 1, CMD_VXRES}, {
159 "-vyres", 1, CMD_VYRES}, {
160 "-depth", 1, CMD_DEPTH}, {
161 "-match", 0, CMD_MATCH}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000162 "-geometry", 5, CMD_GEOMETRY}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000163 "-pixclock", 1, CMD_PIXCLOCK}, {
164 "-left", 1, CMD_LEFT}, {
165 "-right", 1, CMD_RIGHT}, {
166 "-upper", 1, CMD_UPPER}, {
167 "-lower", 1, CMD_LOWER}, {
168 "-hslen", 1, CMD_HSLEN}, {
169 "-vslen", 1, CMD_VSLEN}, {
Erik Andersen7ab9c7e2000-05-12 19:41:47 +0000170 "-timings", 7, CMD_TIMING}, {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000171 "-csync", 1, CMD_CSYNC}, {
172 "-gsync", 1, CMD_GSYNC}, {
173 "-extsync", 1, CMD_EXTSYNC}, {
174 "-bcast", 1, CMD_BCAST}, {
175 "-rgba", 1, CMD_RGBA}, {
176 "-step", 1, CMD_STEP}, {
Erik Andersen9cf3bfa2000-04-13 18:49:43 +0000177 "-move", 1, CMD_MOVE}, {
Erik Andersen1c5b2581999-12-16 20:59:36 +0000178#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000179 0, 0, 0}
Erik Andersen1c5b2581999-12-16 20:59:36 +0000180};
181
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000182#ifdef CONFIG_FEATURE_FBSET_READMODE
Matt Kraai269e07c2000-10-28 16:56:32 +0000183/* taken from linux/fb.h */
Rob Landleybc68cd12006-03-10 19:22:06 +0000184enum {
185 FB_VMODE_INTERLACED = 1, /* interlaced */
186 FB_VMODE_DOUBLE = 2, /* double scan */
187 FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
188 FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
189 FB_SYNC_EXT = 4, /* external sync */
190 FB_SYNC_COMP_HIGH_ACT = 8 /* composite sync high active */
191};
Matt Kraai269e07c2000-10-28 16:56:32 +0000192#endif
Erik Andersen1c5b2581999-12-16 20:59:36 +0000193static int readmode(struct fb_var_screeninfo *base, const char *fn,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000194 const char *mode)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000195{
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000196#ifdef CONFIG_FEATURE_FBSET_READMODE
Erik Andersene49d5ec2000-02-08 19:58:47 +0000197 FILE *f;
198 char buf[256];
199 char *p = buf;
200
Manuel Novoa III cad53642003-03-19 09:13:01 +0000201 f = bb_xfopen(fn, "r");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000202 while (!feof(f)) {
203 fgets(buf, sizeof(buf), f);
204 if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
205 p += 5;
206 if ((p = strstr(buf, mode))) {
207 p += strlen(mode);
208 if (!isspace(*p) && (*p != 0) && (*p != '"')
209 && (*p != '\r') && (*p != '\n'))
210 continue; /* almost, but not quite */
211 while (!feof(f)) {
212 fgets(buf, sizeof(buf), f);
Eric Andersen6f96e672000-07-12 23:01:04 +0000213
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000214 if ((p = strstr(buf, "geometry "))) {
215 p += 9;
Eric Andersen6f96e672000-07-12 23:01:04 +0000216
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000217 sscanf(p, "%d %d %d %d %d",
218 &(base->xres), &(base->yres),
219 &(base->xres_virtual), &(base->yres_virtual),
220 &(base->bits_per_pixel));
221 } else if ((p = strstr(buf, "timings "))) {
222 p += 8;
Eric Andersen6f96e672000-07-12 23:01:04 +0000223
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000224 sscanf(p, "%d %d %d %d %d %d %d",
225 &(base->pixclock),
226 &(base->left_margin), &(base->right_margin),
227 &(base->upper_margin), &(base->lower_margin),
228 &(base->hsync_len), &(base->vsync_len));
229 } else if ((p = strstr(buf, "laced "))) {
230 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000231
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000232 if (strstr(buf, "false")) {
233 base->vmode &= ~FB_VMODE_INTERLACED;
234 } else {
235 base->vmode |= FB_VMODE_INTERLACED;
236 }
237 } else if ((p = strstr(buf, "double "))) {
238 p += 7;
Eric Andersen6f96e672000-07-12 23:01:04 +0000239
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000240 if (strstr(buf, "false")) {
241 base->vmode &= ~FB_VMODE_DOUBLE;
242 } else {
243 base->vmode |= FB_VMODE_DOUBLE;
244 }
245 } else if ((p = strstr(buf, "vsync "))) {
246 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000247
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000248 if (strstr(buf, "low")) {
249 base->sync &= ~FB_SYNC_VERT_HIGH_ACT;
250 } else {
251 base->sync |= FB_SYNC_VERT_HIGH_ACT;
252 }
253 } else if ((p = strstr(buf, "hsync "))) {
254 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000255
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000256 if (strstr(buf, "low")) {
257 base->sync &= ~FB_SYNC_HOR_HIGH_ACT;
258 } else {
259 base->sync |= FB_SYNC_HOR_HIGH_ACT;
260 }
261 } else if ((p = strstr(buf, "csync "))) {
262 p += 6;
Eric Andersen6f96e672000-07-12 23:01:04 +0000263
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000264 if (strstr(buf, "low")) {
265 base->sync &= ~FB_SYNC_COMP_HIGH_ACT;
266 } else {
267 base->sync |= FB_SYNC_COMP_HIGH_ACT;
268 }
269 } else if ((p = strstr(buf, "extsync "))) {
270 p += 8;
271
272 if (strstr(buf, "false")) {
273 base->sync &= ~FB_SYNC_EXT;
274 } else {
275 base->sync |= FB_SYNC_EXT;
276 }
277 }
Eric Andersenc7bda1c2004-03-15 08:29:22 +0000278
Eric Andersen6f96e672000-07-12 23:01:04 +0000279 if (strstr(buf, "endmode"))
Erik Andersene49d5ec2000-02-08 19:58:47 +0000280 return 1;
281 }
282 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000283 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000284 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000285#else
Manuel Novoa III cad53642003-03-19 09:13:01 +0000286 bb_error_msg( "mode reading not compiled in");
Erik Andersen1c5b2581999-12-16 20:59:36 +0000287#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000288 return 0;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000289}
290
Aaron Lehmann60694412002-08-13 04:19:23 +0000291static inline void setmode(struct fb_var_screeninfo *base,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000292 struct fb_var_screeninfo *set)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000293{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000294 if ((int) set->xres > 0)
295 base->xres = set->xres;
296 if ((int) set->yres > 0)
297 base->yres = set->yres;
298 if ((int) set->xres_virtual > 0)
299 base->xres_virtual = set->xres_virtual;
300 if ((int) set->yres_virtual > 0)
301 base->yres_virtual = set->yres_virtual;
302 if ((int) set->bits_per_pixel > 0)
303 base->bits_per_pixel = set->bits_per_pixel;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000304}
305
Aaron Lehmann60694412002-08-13 04:19:23 +0000306static inline void showmode(struct fb_var_screeninfo *v)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000307{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000308 double drate = 0, hrate = 0, vrate = 0;
309
310 if (v->pixclock) {
311 drate = 1e12 / v->pixclock;
312 hrate =
313 drate / (v->left_margin + v->xres + v->right_margin +
314 v->hsync_len);
315 vrate =
316 hrate / (v->upper_margin + v->yres + v->lower_margin +
317 v->vsync_len);
318 }
Aaron Lehmann60694412002-08-13 04:19:23 +0000319 printf("\nmode \"%ux%u-%u\"\n"
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000320#ifdef CONFIG_FEATURE_FBSET_FANCY
Aaron Lehmann60694412002-08-13 04:19:23 +0000321 "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
Erik Andersen1c5b2581999-12-16 20:59:36 +0000322#endif
Aaron Lehmann60694412002-08-13 04:19:23 +0000323 "\tgeometry %u %u %u %u %u\n\ttimings %u %u %u %u %u %u %u\n\taccel %s\n\trgba %u/%u,%u/%u,%u/%u,%u/%u\nendmode\n\n",
324 v->xres, v->yres, (int) (vrate + 0.5),
325#ifdef CONFIG_FEATURE_FBSET_FANCY
326 drate / 1e6, hrate / 1e3, vrate,
327#endif
328 v->xres, v->yres, v->xres_virtual, v->yres_virtual,
329 v->bits_per_pixel, v->pixclock, v->left_margin,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000330 v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
Aaron Lehmann60694412002-08-13 04:19:23 +0000331 v->vsync_len, (v->accel_flags > 0 ? "true" : "false"), v->red.length,
Erik Andersene49d5ec2000-02-08 19:58:47 +0000332 v->red.offset, v->green.length, v->green.offset, v->blue.length,
333 v->blue.offset, v->transp.length, v->transp.offset);
Erik Andersen1c5b2581999-12-16 20:59:36 +0000334}
335
Erik Andersen1c5b2581999-12-16 20:59:36 +0000336#ifdef STANDALONE
337int main(int argc, char **argv)
Erik Andersene49d5ec2000-02-08 19:58:47 +0000338#else
Rob Landleydfba7412006-03-06 20:47:33 +0000339int fbset_main(int argc, char **argv)
Erik Andersen1c5b2581999-12-16 20:59:36 +0000340#endif
341{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000342 struct fb_var_screeninfo var, varset;
343 int fh, i;
344 char *fbdev = DEFAULTFBDEV;
345 char *modefile = DEFAULTFBMODE;
346 char *thisarg, *mode = NULL;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000347
Erik Andersene49d5ec2000-02-08 19:58:47 +0000348 memset(&varset, 0xFF, sizeof(varset));
349
350 /* parse cmd args.... why do they have to make things so difficult? */
351 argv++;
352 argc--;
353 for (; argc > 0 && (thisarg = *argv); argc--, argv++) {
354 for (i = 0; g_cmdoptions[i].name; i++) {
355 if (!strcmp(thisarg, g_cmdoptions[i].name)) {
356 if (argc - 1 < g_cmdoptions[i].param_count)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000357 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000358 switch (g_cmdoptions[i].code) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000359 case CMD_FB:
360 fbdev = argv[1];
361 break;
362 case CMD_DB:
363 modefile = argv[1];
364 break;
365 case CMD_GEOMETRY:
366 varset.xres = strtoul(argv[1], 0, 0);
367 varset.yres = strtoul(argv[2], 0, 0);
368 varset.xres_virtual = strtoul(argv[3], 0, 0);
369 varset.yres_virtual = strtoul(argv[4], 0, 0);
370 varset.bits_per_pixel = strtoul(argv[5], 0, 0);
371 break;
372 case CMD_TIMING:
373 varset.pixclock = strtoul(argv[1], 0, 0);
374 varset.left_margin = strtoul(argv[2], 0, 0);
375 varset.right_margin = strtoul(argv[3], 0, 0);
376 varset.upper_margin = strtoul(argv[4], 0, 0);
377 varset.lower_margin = strtoul(argv[5], 0, 0);
378 varset.hsync_len = strtoul(argv[6], 0, 0);
379 varset.vsync_len = strtoul(argv[7], 0, 0);
380 break;
Tim Rikerc1ef7bd2006-01-25 00:08:53 +0000381 case CMD_CHANGE:
382 g_options |= OPT_CHANGE;
383 break;
Eric Andersenbdfd0d72001-10-24 05:00:29 +0000384#ifdef CONFIG_FEATURE_FBSET_FANCY
Erik Andersene49d5ec2000-02-08 19:58:47 +0000385 case CMD_XRES:
386 varset.xres = strtoul(argv[1], 0, 0);
387 break;
388 case CMD_YRES:
389 varset.yres = strtoul(argv[1], 0, 0);
390 break;
Eric Andersen927c3bd2002-09-17 08:44:56 +0000391 case CMD_DEPTH:
392 varset.bits_per_pixel = strtoul(argv[1], 0, 0);
393 break;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000394#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000395 }
396 argc -= g_cmdoptions[i].param_count;
397 argv += g_cmdoptions[i].param_count;
398 break;
399 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000400 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000401 if (!g_cmdoptions[i].name) {
402 if (argc == 1) {
403 mode = *argv;
404 g_options |= OPT_READMODE;
405 } else {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000406 bb_show_usage();
Erik Andersene49d5ec2000-02-08 19:58:47 +0000407 }
408 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000409 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000410
Erik Andersene49d5ec2000-02-08 19:58:47 +0000411 if ((fh = open(fbdev, O_RDONLY)) < 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000412 bb_perror_msg_and_die("fbset(open)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000413 if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000414 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000415 if (g_options & OPT_READMODE) {
416 if (!readmode(&var, modefile, mode)) {
Manuel Novoa III cad53642003-03-19 09:13:01 +0000417 bb_error_msg("Unknown video mode `%s'", mode);
Matt Kraai3e856ce2000-12-01 02:55:13 +0000418 return EXIT_FAILURE;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000419 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000420 }
Erik Andersen1c5b2581999-12-16 20:59:36 +0000421
Erik Andersene49d5ec2000-02-08 19:58:47 +0000422 setmode(&var, &varset);
423 if (g_options & OPT_CHANGE)
424 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
Manuel Novoa III cad53642003-03-19 09:13:01 +0000425 bb_perror_msg_and_die("fbset(ioctl)");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000426 showmode(&var);
Erik Andersen298854f2000-03-23 01:09:18 +0000427 /* Don't close the file, as exiting will take care of that */
428 /* close(fh); */
Erik Andersene49d5ec2000-02-08 19:58:47 +0000429
Matt Kraai3e856ce2000-12-01 02:55:13 +0000430 return EXIT_SUCCESS;
Erik Andersen1c5b2581999-12-16 20:59:36 +0000431}