*
* This is a from-scratch implementation of fbset; but the de facto fbset
* implementation was a good reference. fbset (original) is released under
- * the GPL, and is (c) 1995-1999 by:
+ * the GPL, and is (c) 1995-1999 by:
* Geert Uytterhoeven (Geert.Uytterhoeven@cs.kuleuven.ac.be)
*/
-#include "internal.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
+#include <string.h>
+#include <stdint.h>
#include <sys/ioctl.h>
-#include <linux/fb.h>
-#include <linux/version.h>
+#include "busybox.h"
-#define PERROR(ctx) do { perror(ctx); exit(1); } while(0)
+#define DEFAULTFBDEV FB_0
+#define DEFAULTFBMODE "/etc/fb.modes"
-#ifndef KERNEL_VERSION
-#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-#endif
+static const int OPT_CHANGE = (1 << 0);
+static const int OPT_INFO = (1 << 1);
+static const int OPT_READMODE = (1 << 2);
-#define DEFAULTFBDEV "/dev/fb0"
-#define DEFAULTFBMODE "/etc/fb.modes"
+enum {
+ CMD_FB = 1,
+ CMD_DB = 2,
+ CMD_GEOMETRY = 3,
+ CMD_TIMING = 4,
+ CMD_ACCEL = 5,
+ CMD_HSYNC = 6,
+ CMD_VSYNC = 7,
+ CMD_LACED = 8,
+ CMD_DOUBLE = 9,
+/* CMD_XCOMPAT = 10, */
+ CMD_ALL = 11,
+ CMD_INFO = 12,
+ CMD_CHANGE = 13,
-#define OPT_CHANGE 1
-#define OPT_INFO (1 << 1)
-#define OPT_READMODE (1 << 2)
-
-#define CMD_HELP 0
-#define CMD_FB 1
-#define CMD_DB 2
-#define CMD_GEOMETRY 3
-#define CMD_TIMING 4
-#define CMD_ACCEL 5
-#define CMD_HSYNC 6
-#define CMD_VSYNC 7
-#define CMD_LACED 8
-#define CMD_DOUBLE 9
-/* #define CMD_XCOMPAT 10 */
-#define CMD_ALL 11
-#define CMD_INFO 12
-#define CMD_CHANGE 13
-
-#ifdef BB_FEATURE_FBSET_FANCY
-#define CMD_XRES 100
-#define CMD_YRES 101
-#define CMD_VXRES 102
-#define CMD_VYRES 103
-#define CMD_DEPTH 104
-#define CMD_MATCH 105
-#define CMD_PIXCLOCK 106
-#define CMD_LEFT 107
-#define CMD_RIGHT 108
-#define CMD_UPPER 109
-#define CMD_LOWER 110
-#define CMD_HSLEN 111
-#define CMD_VSLEN 112
-#define CMD_CSYNC 113
-#define CMD_GSYNC 114
-#define CMD_EXTSYNC 115
-#define CMD_BCAST 116
-#define CMD_RGBA 117
-#define CMD_STEP 118
-#define CMD_MOVE 119
+#ifdef CONFIG_FEATURE_FBSET_FANCY
+ CMD_XRES = 100,
+ CMD_YRES = 101,
+ CMD_VXRES = 102,
+ CMD_VYRES = 103,
+ CMD_DEPTH = 104,
+ CMD_MATCH = 105,
+ CMD_PIXCLOCK = 106,
+ CMD_LEFT = 107,
+ CMD_RIGHT = 108,
+ CMD_UPPER = 109,
+ CMD_LOWER = 110,
+ CMD_HSLEN = 111,
+ CMD_VSLEN = 112,
+ CMD_CSYNC = 113,
+ CMD_GSYNC = 114,
+ CMD_EXTSYNC = 115,
+ CMD_BCAST = 116,
+ CMD_RGBA = 117,
+ CMD_STEP = 118,
+ CMD_MOVE = 119,
#endif
+};
static unsigned int g_options = 0;
-struct cmdoptions_t {
- char *name;
- unsigned char param_count;
- unsigned char code;
+/* Stuff stolen from the kernel's fb.h */
+static const int FBIOGET_VSCREENINFO = 0x4600;
+static const int FBIOPUT_VSCREENINFO = 0x4601;
+struct fb_bitfield {
+ uint32_t offset; /* beginning of bitfield */
+ uint32_t length; /* length of bitfield */
+ uint32_t msb_right; /* != 0 : Most significant bit is */
+ /* right */
+};
+struct fb_var_screeninfo {
+ uint32_t xres; /* visible resolution */
+ uint32_t yres;
+ uint32_t xres_virtual; /* virtual resolution */
+ uint32_t yres_virtual;
+ uint32_t xoffset; /* offset from virtual to visible */
+ uint32_t yoffset; /* resolution */
+
+ uint32_t bits_per_pixel; /* guess what */
+ uint32_t grayscale; /* != 0 Graylevels instead of colors */
+
+ struct fb_bitfield red; /* bitfield in fb mem if true color, */
+ struct fb_bitfield green; /* else only length is significant */
+ struct fb_bitfield blue;
+ struct fb_bitfield transp; /* transparency */
+
+ uint32_t nonstd; /* != 0 Non standard pixel format */
+
+ uint32_t activate; /* see FB_ACTIVATE_* */
+
+ uint32_t height; /* height of picture in mm */
+ uint32_t width; /* width of picture in mm */
+
+ uint32_t accel_flags; /* acceleration flags (hints) */
+
+ /* Timing: All values in pixclocks, except pixclock (of course) */
+ uint32_t pixclock; /* pixel clock in ps (pico seconds) */
+ uint32_t left_margin; /* time from sync to picture */
+ uint32_t right_margin; /* time from picture to sync */
+ uint32_t upper_margin; /* time from sync to picture */
+ uint32_t lower_margin;
+ uint32_t hsync_len; /* length of horizontal sync */
+ uint32_t vsync_len; /* length of vertical sync */
+ uint32_t sync; /* see FB_SYNC_* */
+ uint32_t vmode; /* see FB_VMODE_* */
+ uint32_t reserved[6]; /* Reserved for future compatibility */
+};
+
+
+const static struct cmdoptions_t {
+ const char *name;
+ const unsigned char param_count;
+ const unsigned char code;
} g_cmdoptions[] = {
{
- "-h", 0, CMD_HELP}, {
"-fb", 1, CMD_FB}, {
"-db", 1, CMD_DB}, {
"-a", 0, CMD_ALL}, {
"-vsync", 1, CMD_VSYNC}, {
"-laced", 1, CMD_LACED}, {
"-double", 1, CMD_DOUBLE}, {
- "-help", 0, CMD_HELP}, {
"-n", 0, CMD_CHANGE}, {
-#ifdef BB_FEATURE_FBSET_FANCY
- "-help", 0, CMD_HELP}, {
+#ifdef CONFIG_FEATURE_FBSET_FANCY
"-all", 0, CMD_ALL}, {
"-xres", 1, CMD_XRES}, {
"-yres", 1, CMD_YRES}, {
0, 0, 0}
};
+#ifdef CONFIG_FEATURE_FBSET_READMODE
+/* taken from linux/fb.h */
+static const int FB_VMODE_INTERLACED = 1; /* interlaced */
+static const int FB_VMODE_DOUBLE = 2; /* double scan */
+static const int FB_SYNC_HOR_HIGH_ACT = 1; /* horizontal sync high active */
+static const int FB_SYNC_VERT_HIGH_ACT = 2; /* vertical sync high active */
+static const int FB_SYNC_EXT = 4; /* external sync */
+static const int FB_SYNC_COMP_HIGH_ACT = 8; /* composite sync high active */
+#endif
static int readmode(struct fb_var_screeninfo *base, const char *fn,
const char *mode)
{
-#ifdef BB_FEATURE_FBSET_READMODE
+#ifdef CONFIG_FEATURE_FBSET_READMODE
FILE *f;
char buf[256];
char *p = buf;
- if ((f = fopen(fn, "r")) == NULL)
- PERROR("readmode(fopen)");
+ f = bb_xfopen(fn, "r");
while (!feof(f)) {
fgets(buf, sizeof(buf), f);
if ((p = strstr(buf, "mode ")) || (p = strstr(buf, "mode\t"))) {
if ((p = strstr(buf, "geometry "))) {
p += 9;
- sscanf(p, "%d %d %d %d %d",
- &(base->xres), &(base->yres),
- &(base->xres_virtual), &(base->yres_virtual),
+ sscanf(p, "%d %d %d %d %d",
+ &(base->xres), &(base->yres),
+ &(base->xres_virtual), &(base->yres_virtual),
&(base->bits_per_pixel));
} else if ((p = strstr(buf, "timings "))) {
p += 8;
-
+
sscanf(p, "%d %d %d %d %d %d %d",
&(base->pixclock),
&(base->left_margin), &(base->right_margin),
base->sync |= FB_SYNC_EXT;
}
}
-
+
if (strstr(buf, "endmode"))
return 1;
}
}
}
#else
- errorMsg( "mode reading not compiled in\n");
+ bb_error_msg( "mode reading not compiled in");
#endif
return 0;
}
-static void setmode(struct fb_var_screeninfo *base,
+static inline void setmode(struct fb_var_screeninfo *base,
struct fb_var_screeninfo *set)
{
if ((int) set->xres > 0)
base->bits_per_pixel = set->bits_per_pixel;
}
-static void showmode(struct fb_var_screeninfo *v)
+static inline void showmode(struct fb_var_screeninfo *v)
{
double drate = 0, hrate = 0, vrate = 0;
hrate / (v->upper_margin + v->yres + v->lower_margin +
v->vsync_len);
}
- printf("\nmode \"%ux%u-%u\"\n", v->xres, v->yres, (int) (vrate + 0.5));
-#ifdef BB_FEATURE_FBSET_FANCY
- printf("\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n", drate / 1e6,
- hrate / 1e3, vrate);
+ printf("\nmode \"%ux%u-%u\"\n"
+#ifdef CONFIG_FEATURE_FBSET_FANCY
+ "\t# D: %.3f MHz, H: %.3f kHz, V: %.3f Hz\n"
#endif
- printf("\tgeometry %u %u %u %u %u\n", v->xres, v->yres,
- v->xres_virtual, v->yres_virtual, v->bits_per_pixel);
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
- printf("\ttimings %u %u %u %u %u %u %u\n", v->pixclock, v->left_margin,
- v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
- v->vsync_len);
- printf("\taccel %s\n", (v->accel_flags > 0 ? "true" : "false"));
-#else
- printf("\ttimings %lu %lu %lu %lu %lu %lu %lu\n", v->pixclock,
- v->left_margin, v->right_margin, v->upper_margin,
- v->lower_margin, v->hsync_len, v->vsync_len);
+ "\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",
+ v->xres, v->yres, (int) (vrate + 0.5),
+#ifdef CONFIG_FEATURE_FBSET_FANCY
+ drate / 1e6, hrate / 1e3, vrate,
#endif
- printf("\trgba %u/%u,%u/%u,%u/%u,%u/%u\n", v->red.length,
+ v->xres, v->yres, v->xres_virtual, v->yres_virtual,
+ v->bits_per_pixel, v->pixclock, v->left_margin,
+ v->right_margin, v->upper_margin, v->lower_margin, v->hsync_len,
+ v->vsync_len, (v->accel_flags > 0 ? "true" : "false"), v->red.length,
v->red.offset, v->green.length, v->green.offset, v->blue.length,
v->blue.offset, v->transp.length, v->transp.offset);
- printf("endmode\n\n");
-}
-
-static void fbset_usage(void)
-{
-#ifndef BB_FEATURE_TRIVIAL_HELP
- int i;
-#endif
-
-#ifndef STANDALONE
- fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
- BB_VER, BB_BT);
-#endif
- fprintf(stderr, "Usage: fbset [options] [mode]\n");
-#ifndef BB_FEATURE_TRIVIAL_HELP
- fprintf(stderr, "\nShows and modifies frame buffer device settings\n\n");
- fprintf(stderr, "The following options are recognized:\n");
- for (i = 0; g_cmdoptions[i].name; i++)
- fprintf(stderr, "\t%s\n", g_cmdoptions[i].name);
-#endif
- exit(-1);
}
#ifdef STANDALONE
for (i = 0; g_cmdoptions[i].name; i++) {
if (!strcmp(thisarg, g_cmdoptions[i].name)) {
if (argc - 1 < g_cmdoptions[i].param_count)
- fbset_usage();
+ bb_show_usage();
switch (g_cmdoptions[i].code) {
- case CMD_HELP:
- fbset_usage();
case CMD_FB:
fbdev = argv[1];
break;
case CMD_CHANGE:
g_options |= OPT_CHANGE;
break;
-#ifdef BB_FEATURE_FBSET_FANCY
+#ifdef CONFIG_FEATURE_FBSET_FANCY
case CMD_XRES:
varset.xres = strtoul(argv[1], 0, 0);
break;
case CMD_YRES:
varset.yres = strtoul(argv[1], 0, 0);
break;
+ case CMD_DEPTH:
+ varset.bits_per_pixel = strtoul(argv[1], 0, 0);
+ break;
#endif
}
argc -= g_cmdoptions[i].param_count;
mode = *argv;
g_options |= OPT_READMODE;
} else {
- fbset_usage();
+ bb_show_usage();
}
}
}
if ((fh = open(fbdev, O_RDONLY)) < 0)
- PERROR("fbset(open)");
+ bb_perror_msg_and_die("fbset(open)");
if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
- PERROR("fbset(ioctl)");
+ bb_perror_msg_and_die("fbset(ioctl)");
if (g_options & OPT_READMODE) {
if (!readmode(&var, modefile, mode)) {
- fprintf(stderr, "Unknown video mode `%s'\n", mode);
- exit(1);
+ bb_error_msg("Unknown video mode `%s'", mode);
+ return EXIT_FAILURE;
}
}
setmode(&var, &varset);
if (g_options & OPT_CHANGE)
if (ioctl(fh, FBIOPUT_VSCREENINFO, &var))
- PERROR("fbset(ioctl)");
+ bb_perror_msg_and_die("fbset(ioctl)");
showmode(&var);
/* Don't close the file, as exiting will take care of that */
/* close(fh); */
- return (TRUE);
+ return EXIT_SUCCESS;
}