fbset.c 17 KB

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