3
0

fbset.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Mini fbset implementation for busybox
  4. *
  5. * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  8. *
  9. * This is a from-scratch implementation of fbset; but the de facto fbset
  10. * implementation was a good reference. fbset (original) is released under
  11. * the GPL, and is (c) 1995-1999 by:
  12. * Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
  13. */
  14. //config:config FBSET
  15. //config: bool "fbset (6.2 kb)"
  16. //config: default y
  17. //config: help
  18. //config: fbset is used to show or change the settings of a Linux frame buffer
  19. //config: device. The frame buffer device provides a simple and unique
  20. //config: interface to access a graphics display. Enable this option
  21. //config: if you wish to enable the 'fbset' utility.
  22. //config:
  23. //config:config FEATURE_FBSET_FANCY
  24. //config: bool "Enable extra options"
  25. //config: default y
  26. //config: depends on FBSET
  27. //config: help
  28. //config: This option enables extended fbset options, allowing one to set the
  29. //config: framebuffer size, color depth, etc. interface to access a graphics
  30. //config: display. Enable this option if you wish to enable extended fbset
  31. //config: options.
  32. //config:
  33. //config:config FEATURE_FBSET_READMODE
  34. //config: bool "Enable readmode support"
  35. //config: default y
  36. //config: depends on FBSET
  37. //config: help
  38. //config: This option allows fbset to read the video mode database stored by
  39. //config: default as /etc/fb.modes, which can be used to set frame buffer
  40. //config: device to pre-defined video modes.
  41. //applet:IF_FBSET(APPLET(fbset, BB_DIR_USR_SBIN, BB_SUID_DROP))
  42. //kbuild:lib-$(CONFIG_FBSET) += fbset.o
  43. //usage:#define fbset_trivial_usage
  44. //usage: "[OPTIONS] [MODE]"
  45. //usage:#define fbset_full_usage "\n\n"
  46. //usage: "Show and modify frame buffer settings"
  47. //usage:
  48. //usage:#define fbset_example_usage
  49. //usage: "$ fbset\n"
  50. //usage: "mode \"1024x768-76\"\n"
  51. //usage: " # D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz\n"
  52. //usage: " geometry 1024 768 1024 768 16\n"
  53. //usage: " timings 12714 128 32 16 4 128 4\n"
  54. //usage: " accel false\n"
  55. //usage: " rgba 5/11,6/5,5/0,0/0\n"
  56. //usage: "endmode\n"
  57. #include "libbb.h"
  58. #define DEFAULTFBDEV FB_0
  59. #define DEFAULTFBMODE "/etc/fb.modes"
  60. /* Stuff stolen from the kernel's fb.h */
  61. #define FB_ACTIVATE_ALL 64
  62. enum {
  63. FBIOGET_VSCREENINFO = 0x4600,
  64. FBIOPUT_VSCREENINFO = 0x4601
  65. };
  66. struct fb_bitfield {
  67. uint32_t offset; /* beginning of bitfield */
  68. uint32_t length; /* length of bitfield */
  69. uint32_t msb_right; /* !=0: Most significant bit is right */
  70. };
  71. struct fb_var_screeninfo {
  72. uint32_t xres; /* visible resolution */
  73. uint32_t yres;
  74. uint32_t xres_virtual; /* virtual resolution */
  75. uint32_t yres_virtual;
  76. uint32_t xoffset; /* offset from virtual to visible */
  77. uint32_t yoffset; /* resolution */
  78. uint32_t bits_per_pixel;
  79. uint32_t grayscale; /* !=0 Graylevels instead of colors */
  80. struct fb_bitfield red; /* bitfield in fb mem if true color, */
  81. struct fb_bitfield green; /* else only length is significant */
  82. struct fb_bitfield blue;
  83. struct fb_bitfield transp; /* transparency */
  84. uint32_t nonstd; /* !=0 Non standard pixel format */
  85. uint32_t activate; /* see FB_ACTIVATE_x */
  86. uint32_t height; /* height of picture in mm */
  87. uint32_t width; /* width of picture in mm */
  88. uint32_t accel_flags; /* acceleration flags (hints) */
  89. /* Timing: All values in pixclocks, except pixclock (of course) */
  90. uint32_t pixclock; /* pixel clock in ps (pico seconds) */
  91. uint32_t left_margin; /* time from sync to picture */
  92. uint32_t right_margin; /* time from picture to sync */
  93. uint32_t upper_margin; /* time from sync to picture */
  94. uint32_t lower_margin;
  95. uint32_t hsync_len; /* length of horizontal sync */
  96. uint32_t vsync_len; /* length of vertical sync */
  97. uint32_t sync; /* see FB_SYNC_x */
  98. uint32_t vmode; /* see FB_VMODE_x */
  99. uint32_t reserved[6]; /* Reserved for future compatibility */
  100. };
  101. static void copy_if_gt0(uint32_t *src, uint32_t *dst, unsigned cnt)
  102. {
  103. do {
  104. if ((int32_t) *src > 0)
  105. *dst = *src;
  106. src++;
  107. dst++;
  108. } while (--cnt);
  109. }
  110. static NOINLINE void copy_changed_values(
  111. struct fb_var_screeninfo *base,
  112. struct fb_var_screeninfo *set)
  113. {
  114. //if ((int32_t) set->xres > 0) base->xres = set->xres;
  115. //if ((int32_t) set->yres > 0) base->yres = set->yres;
  116. //if ((int32_t) set->xres_virtual > 0) base->xres_virtual = set->xres_virtual;
  117. //if ((int32_t) set->yres_virtual > 0) base->yres_virtual = set->yres_virtual;
  118. copy_if_gt0(&set->xres, &base->xres, 4);
  119. if ((int32_t) set->bits_per_pixel > 0) base->bits_per_pixel = set->bits_per_pixel;
  120. //copy_if_gt0(&set->bits_per_pixel, &base->bits_per_pixel, 1);
  121. //if ((int32_t) set->pixclock > 0) base->pixclock = set->pixclock;
  122. //if ((int32_t) set->left_margin > 0) base->left_margin = set->left_margin;
  123. //if ((int32_t) set->right_margin > 0) base->right_margin = set->right_margin;
  124. //if ((int32_t) set->upper_margin > 0) base->upper_margin = set->upper_margin;
  125. //if ((int32_t) set->lower_margin > 0) base->lower_margin = set->lower_margin;
  126. //if ((int32_t) set->hsync_len > 0) base->hsync_len = set->hsync_len;
  127. //if ((int32_t) set->vsync_len > 0) base->vsync_len = set->vsync_len;
  128. //if ((int32_t) set->sync > 0) base->sync = set->sync;
  129. //if ((int32_t) set->vmode > 0) base->vmode = set->vmode;
  130. copy_if_gt0(&set->pixclock, &base->pixclock, 9);
  131. }
  132. enum {
  133. CMD_FB = 1,
  134. CMD_DB = 2,
  135. CMD_GEOMETRY = 3,
  136. CMD_TIMING = 4,
  137. CMD_ACCEL = 5,
  138. CMD_HSYNC = 6,
  139. CMD_VSYNC = 7,
  140. CMD_LACED = 8,
  141. CMD_DOUBLE = 9,
  142. /* CMD_XCOMPAT = 10, */
  143. CMD_ALL = 11,
  144. CMD_INFO = 12,
  145. CMD_SHOW = 13,
  146. CMD_CHANGE = 14,
  147. #if ENABLE_FEATURE_FBSET_FANCY
  148. CMD_XRES = 100,
  149. CMD_YRES = 101,
  150. CMD_VXRES = 102,
  151. CMD_VYRES = 103,
  152. CMD_DEPTH = 104,
  153. CMD_MATCH = 105,
  154. CMD_PIXCLOCK = 106,
  155. CMD_LEFT = 107,
  156. CMD_RIGHT = 108,
  157. CMD_UPPER = 109,
  158. CMD_LOWER = 110,
  159. CMD_HSLEN = 111,
  160. CMD_VSLEN = 112,
  161. CMD_CSYNC = 113,
  162. CMD_GSYNC = 114,
  163. CMD_EXTSYNC = 115,
  164. CMD_BCAST = 116,
  165. CMD_RGBA = 117,
  166. CMD_STEP = 118,
  167. CMD_MOVE = 119,
  168. #endif
  169. };
  170. static const struct cmdoptions_t {
  171. const char name[9];
  172. const unsigned char param_count;
  173. const unsigned char code;
  174. } g_cmdoptions[] ALIGN1 = {
  175. /*"12345678" + NUL */
  176. //TODO: convert to index_in_strings()
  177. { "fb" , 1, CMD_FB },
  178. { "db" , 1, CMD_DB },
  179. { "a" , 0, CMD_ALL },
  180. { "i" , 0, CMD_INFO },
  181. { "g" , 5, CMD_GEOMETRY },
  182. { "t" , 7, CMD_TIMING },
  183. { "accel" , 1, CMD_ACCEL },
  184. { "hsync" , 1, CMD_HSYNC },
  185. { "vsync" , 1, CMD_VSYNC },
  186. { "laced" , 1, CMD_LACED },
  187. { "double" , 1, CMD_DOUBLE },
  188. { "show" , 0, CMD_SHOW },
  189. { "s" , 0, CMD_SHOW },
  190. #if ENABLE_FEATURE_FBSET_FANCY
  191. { "all" , 0, CMD_ALL },
  192. { "xres" , 1, CMD_XRES },
  193. { "yres" , 1, CMD_YRES },
  194. { "vxres" , 1, CMD_VXRES },
  195. { "vyres" , 1, CMD_VYRES },
  196. { "depth" , 1, CMD_DEPTH },
  197. { "match" , 0, CMD_MATCH },
  198. { "geometry", 5, CMD_GEOMETRY },
  199. { "pixclock", 1, CMD_PIXCLOCK },
  200. { "left" , 1, CMD_LEFT },
  201. { "right" , 1, CMD_RIGHT },
  202. { "upper" , 1, CMD_UPPER },
  203. { "lower" , 1, CMD_LOWER },
  204. { "hslen" , 1, CMD_HSLEN },
  205. { "vslen" , 1, CMD_VSLEN },
  206. { "timings" , 7, CMD_TIMING },
  207. { "csync" , 1, CMD_CSYNC },
  208. { "gsync" , 1, CMD_GSYNC },
  209. { "extsync" , 1, CMD_EXTSYNC },
  210. { "bcast" , 1, CMD_BCAST },
  211. { "rgba" , 1, CMD_RGBA },
  212. { "step" , 1, CMD_STEP },
  213. { "move" , 1, CMD_MOVE },
  214. #endif
  215. };
  216. /* taken from linux/fb.h */
  217. enum {
  218. FB_SYNC_HOR_HIGH_ACT = 1, /* horizontal sync high active */
  219. FB_SYNC_VERT_HIGH_ACT = 2, /* vertical sync high active */
  220. #if ENABLE_FEATURE_FBSET_READMODE
  221. FB_VMODE_INTERLACED = 1, /* interlaced */
  222. FB_VMODE_DOUBLE = 2, /* double scan */
  223. FB_SYNC_EXT = 4, /* external sync */
  224. FB_SYNC_COMP_HIGH_ACT = 8, /* composite sync high active */
  225. #endif
  226. };
  227. #if ENABLE_FEATURE_FBSET_READMODE
  228. static void ss(uint32_t *x, uint32_t flag, char *buf, const char *what)
  229. {
  230. if (strcmp(buf, what) == 0)
  231. *x &= ~flag;
  232. else
  233. *x |= flag;
  234. }
  235. /* Mode db file contains mode definitions like this:
  236. * mode "800x600-48-lace"
  237. * # D: 36.00 MHz, H: 33.835 kHz, V: 96.39 Hz
  238. * geometry 800 600 800 600 8
  239. * timings 27778 56 80 79 11 128 12
  240. * laced true
  241. * hsync high
  242. * vsync high
  243. * endmode
  244. */
  245. static NOINLINE int read_mode_db(struct fb_var_screeninfo *base, const char *fn,
  246. const char *mode)
  247. {
  248. char *token[2], *p, *s;
  249. parser_t *parser = config_open(fn);
  250. while (config_read(parser, token, 2, 1, "# \t\r", PARSE_NORMAL)) {
  251. if (strcmp(token[0], "mode") != 0 || !token[1])
  252. continue;
  253. p = strstr(token[1], mode);
  254. if (!p)
  255. continue;
  256. s = p + strlen(mode);
  257. //bb_error_msg("CHECK[%s][%s][%d]", mode, p-1, *s);
  258. /* exact match? */
  259. if (((!*s || isspace(*s)) && '"' != s[-1]) /* end-of-token */
  260. || ('"' == *s && '"' == p[-1]) /* ends with " but starts with " too! */
  261. ) {
  262. //bb_error_msg("FOUND[%s][%s][%s][%d]", token[1], p, mode, isspace(*s));
  263. break;
  264. }
  265. }
  266. if (!token[0])
  267. return 0;
  268. while (config_read(parser, token, 2, 1, "# \t", PARSE_NORMAL)) {
  269. int i;
  270. //bb_error_msg("???[%s][%s]", token[0], token[1]);
  271. if (strcmp(token[0], "endmode") == 0) {
  272. //bb_error_msg("OK[%s]", mode);
  273. return 1;
  274. }
  275. p = token[1];
  276. i = index_in_strings(
  277. "geometry\0timings\0interlaced\0double\0vsync\0hsync\0csync\0extsync\0rgba\0",
  278. token[0]);
  279. switch (i) {
  280. case 0:
  281. if (sizeof(int) == sizeof(base->xres)) {
  282. sscanf(p, "%d %d %d %d %d",
  283. &base->xres, &base->yres,
  284. &base->xres_virtual, &base->yres_virtual,
  285. &base->bits_per_pixel);
  286. } else {
  287. int base_xres, base_yres;
  288. int base_xres_virtual, base_yres_virtual;
  289. int base_bits_per_pixel;
  290. sscanf(p, "%d %d %d %d %d",
  291. &base_xres, &base_yres,
  292. &base_xres_virtual, &base_yres_virtual,
  293. &base_bits_per_pixel);
  294. base->xres = base_xres;
  295. base->yres = base_yres;
  296. base->xres_virtual = base_xres_virtual;
  297. base->yres_virtual = base_yres_virtual;
  298. base->bits_per_pixel = base_bits_per_pixel;
  299. }
  300. //bb_error_msg("GEO[%s]", p);
  301. break;
  302. case 1:
  303. if (sizeof(int) == sizeof(base->xres)) {
  304. sscanf(p, "%d %d %d %d %d %d %d",
  305. &base->pixclock,
  306. &base->left_margin, &base->right_margin,
  307. &base->upper_margin, &base->lower_margin,
  308. &base->hsync_len, &base->vsync_len);
  309. } else {
  310. int base_pixclock;
  311. int base_left_margin, base_right_margin;
  312. int base_upper_margin, base_lower_margin;
  313. int base_hsync_len, base_vsync_len;
  314. sscanf(p, "%d %d %d %d %d %d %d",
  315. &base_pixclock,
  316. &base_left_margin, &base_right_margin,
  317. &base_upper_margin, &base_lower_margin,
  318. &base_hsync_len, &base_vsync_len);
  319. base->pixclock = base_pixclock;
  320. base->left_margin = base_left_margin;
  321. base->right_margin = base_right_margin;
  322. base->upper_margin = base_upper_margin;
  323. base->lower_margin = base_lower_margin;
  324. base->hsync_len = base_hsync_len;
  325. base->vsync_len = base_vsync_len;
  326. }
  327. //bb_error_msg("TIM[%s]", p);
  328. break;
  329. case 2:
  330. case 3: {
  331. static const uint32_t syncs[] = {FB_VMODE_INTERLACED, FB_VMODE_DOUBLE};
  332. ss(&base->vmode, syncs[i-2], p, "false");
  333. //bb_error_msg("VMODE[%s]", p);
  334. break;
  335. }
  336. case 4:
  337. case 5:
  338. case 6: {
  339. static const uint32_t syncs[] = {FB_SYNC_VERT_HIGH_ACT, FB_SYNC_HOR_HIGH_ACT, FB_SYNC_COMP_HIGH_ACT};
  340. ss(&base->sync, syncs[i-4], p, "low");
  341. //bb_error_msg("SYNC[%s]", p);
  342. break;
  343. }
  344. case 7:
  345. ss(&base->sync, FB_SYNC_EXT, p, "false");
  346. //bb_error_msg("EXTSYNC[%s]", p);
  347. break;
  348. case 8: {
  349. int red_offset, red_length;
  350. int green_offset, green_length;
  351. int blue_offset, blue_length;
  352. int transp_offset, transp_length;
  353. sscanf(p, "%d/%d,%d/%d,%d/%d,%d/%d",
  354. &red_length, &red_offset,
  355. &green_length, &green_offset,
  356. &blue_length, &blue_offset,
  357. &transp_length, &transp_offset);
  358. base->red.offset = red_offset;
  359. base->red.length = red_length;
  360. base->red.msb_right = 0;
  361. base->green.offset = green_offset;
  362. base->green.length = green_length;
  363. base->green.msb_right = 0;
  364. base->blue.offset = blue_offset;
  365. base->blue.length = blue_length;
  366. base->blue.msb_right = 0;
  367. base->transp.offset = transp_offset;
  368. base->transp.length = transp_length;
  369. base->transp.msb_right = 0;
  370. }
  371. }
  372. }
  373. return 0;
  374. }
  375. #endif
  376. static NOINLINE void showmode(struct fb_var_screeninfo *v)
  377. {
  378. double drate = 0, hrate = 0, vrate = 0;
  379. if (v->pixclock) {
  380. drate = 1e12 / v->pixclock;
  381. hrate = drate / (v->left_margin + v->xres + v->right_margin + v->hsync_len);
  382. vrate = hrate / (v->upper_margin + v->yres + v->lower_margin + v->vsync_len);
  383. }
  384. printf("\nmode \"%ux%u-%u\"\n"
  385. #if ENABLE_FEATURE_FBSET_FANCY
  386. "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
  387. #endif
  388. "\tgeometry %u %u %u %u %u\n"
  389. "\ttimings %u %u %u %u %u %u %u\n"
  390. "\taccel %s\n"
  391. "\trgba %u/%u,%u/%u,%u/%u,%u/%u\n"
  392. "endmode\n\n",
  393. v->xres, v->yres, (int) (vrate + 0.5),
  394. #if ENABLE_FEATURE_FBSET_FANCY
  395. drate / 1e6, hrate / 1e3, vrate,
  396. #endif
  397. v->xres, v->yres, v->xres_virtual, v->yres_virtual, v->bits_per_pixel,
  398. v->pixclock, v->left_margin, v->right_margin, v->upper_margin, v->lower_margin,
  399. v->hsync_len, v->vsync_len,
  400. (v->accel_flags > 0 ? "true" : "false"),
  401. v->red.length, v->red.offset, v->green.length, v->green.offset,
  402. v->blue.length, v->blue.offset, v->transp.length, v->transp.offset);
  403. }
  404. int fbset_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  405. int fbset_main(int argc, char **argv)
  406. {
  407. enum {
  408. OPT_CHANGE = (1 << 0),
  409. OPT_SHOW = (1 << 1),
  410. OPT_READMODE = (1 << 2),
  411. OPT_ALL = (1 << 3),
  412. };
  413. struct fb_var_screeninfo var_old, var_set;
  414. int fh, i;
  415. unsigned options = 0;
  416. const char *fbdev = DEFAULTFBDEV;
  417. IF_FEATURE_FBSET_READMODE(const char *modefile = DEFAULTFBMODE;)
  418. char *thisarg;
  419. char *mode = mode; /* for compiler */
  420. memset(&var_set, 0xff, sizeof(var_set)); /* set all to -1 */
  421. /* parse cmd args.... why do they have to make things so difficult? */
  422. argv++;
  423. argc--;
  424. for (; argc > 0 && (thisarg = *argv) != NULL; argc--, argv++) {
  425. if (thisarg[0] != '-') {
  426. if (!ENABLE_FEATURE_FBSET_READMODE || argc != 1)
  427. bb_show_usage();
  428. mode = thisarg;
  429. options |= OPT_READMODE;
  430. goto contin;
  431. }
  432. for (i = 0; i < ARRAY_SIZE(g_cmdoptions); i++) {
  433. if (strcmp(thisarg + 1, g_cmdoptions[i].name) != 0)
  434. continue;
  435. if (argc <= g_cmdoptions[i].param_count)
  436. bb_show_usage();
  437. switch (g_cmdoptions[i].code) {
  438. case CMD_FB:
  439. fbdev = argv[1];
  440. break;
  441. case CMD_DB:
  442. IF_FEATURE_FBSET_READMODE(modefile = argv[1];)
  443. break;
  444. case CMD_ALL:
  445. options |= OPT_ALL;
  446. break;
  447. case CMD_SHOW:
  448. options |= OPT_SHOW;
  449. break;
  450. case CMD_GEOMETRY:
  451. var_set.xres = xatou32(argv[1]);
  452. var_set.yres = xatou32(argv[2]);
  453. var_set.xres_virtual = xatou32(argv[3]);
  454. var_set.yres_virtual = xatou32(argv[4]);
  455. var_set.bits_per_pixel = xatou32(argv[5]);
  456. break;
  457. case CMD_TIMING:
  458. var_set.pixclock = xatou32(argv[1]);
  459. var_set.left_margin = xatou32(argv[2]);
  460. var_set.right_margin = xatou32(argv[3]);
  461. var_set.upper_margin = xatou32(argv[4]);
  462. var_set.lower_margin = xatou32(argv[5]);
  463. var_set.hsync_len = xatou32(argv[6]);
  464. var_set.vsync_len = xatou32(argv[7]);
  465. break;
  466. case CMD_ACCEL:
  467. break;
  468. case CMD_HSYNC:
  469. var_set.sync |= FB_SYNC_HOR_HIGH_ACT;
  470. break;
  471. case CMD_VSYNC:
  472. var_set.sync |= FB_SYNC_VERT_HIGH_ACT;
  473. break;
  474. #if ENABLE_FEATURE_FBSET_FANCY
  475. case CMD_XRES:
  476. var_set.xres = xatou32(argv[1]);
  477. break;
  478. case CMD_YRES:
  479. var_set.yres = xatou32(argv[1]);
  480. break;
  481. case CMD_DEPTH:
  482. var_set.bits_per_pixel = xatou32(argv[1]);
  483. break;
  484. case CMD_PIXCLOCK:
  485. var_set.pixclock = xatou32(argv[1]);
  486. break;
  487. #endif
  488. default:
  489. bb_perror_msg_and_die("option '%s' not handled",
  490. g_cmdoptions[i].name);
  491. }
  492. switch (g_cmdoptions[i].code) {
  493. case CMD_FB:
  494. case CMD_DB:
  495. case CMD_ALL:
  496. case CMD_SHOW:
  497. break;
  498. default:
  499. /* other commands imply changes */
  500. options |= OPT_CHANGE;
  501. }
  502. argc -= g_cmdoptions[i].param_count;
  503. argv += g_cmdoptions[i].param_count;
  504. goto contin;
  505. }
  506. bb_show_usage();
  507. contin: ;
  508. }
  509. fh = xopen(fbdev, O_RDONLY);
  510. xioctl(fh, FBIOGET_VSCREENINFO, &var_old);
  511. if (options & OPT_READMODE) {
  512. #if ENABLE_FEATURE_FBSET_READMODE
  513. if (!read_mode_db(&var_old, modefile, mode)) {
  514. bb_error_msg_and_die("unknown video mode '%s'", mode);
  515. }
  516. options |= OPT_CHANGE;
  517. #endif
  518. }
  519. if (options & OPT_CHANGE) {
  520. copy_changed_values(&var_old, &var_set);
  521. if (options & OPT_ALL)
  522. var_old.activate = FB_ACTIVATE_ALL;
  523. xioctl(fh, FBIOPUT_VSCREENINFO, &var_old);
  524. }
  525. if (options == 0 || (options & OPT_SHOW))
  526. showmode(&var_old);
  527. if (ENABLE_FEATURE_CLEAN_UP)
  528. close(fh);
  529. return EXIT_SUCCESS;
  530. }