annotate TOOLS/TVout/con2fb/con2fb.c @ 15311:b00b16a1ef05

Error out when invalid format is specified
author reimar
date Sun, 01 May 2005 09:02:25 +0000
parents b205f8ca892a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 /* this is userspace utility which allows you to redirect console to another fb device
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 * You can specify devices & consoles by both numbers and devices. Framebuffers numbers
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 * are zero based (/dev/fb0 ... ), consoles begins with 1 (/dev/tty1 ... )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <linux/fb.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <sys/ioctl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 #include <sys/stat.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 #include <sys/types.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <fcntl.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 #include <stdio.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 #include <stdlib.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 #include <string.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 #include <unistd.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 int main(int argc, char* argv[]) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 struct fb_con2fbmap c2m;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 char* fbPath;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 u_int32_t con, fb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 char* e;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 char* progname = strrchr(argv[0], '/');
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 int f;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 if (progname)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 progname++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 progname = argv[0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 if (argc < 3) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 fprintf(stderr, "usage: %s fbdev console\n", progname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 fb = strtoul(argv[1], &e, 10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 if (*e) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 struct stat sbf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 if (stat(argv[1], &sbf)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 fprintf(stderr, "%s: are you sure that %s can be used to describe fbdev?\n", progname, argv[1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 if (!S_ISCHR(sbf.st_mode)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 fprintf(stderr, "%s: %s must be character device\n", progname, argv[1]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 fb = sbf.st_rdev & 0xFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 if (fb >= 32)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 fb >>= 5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 fbPath = argv[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 fbPath = "/dev/fb0";
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 con = strtoul(argv[2], &e, 10);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 if (*e) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 struct stat sbf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 if (stat(argv[2], &sbf)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 fprintf(stderr, "%s: are you sure that %s can be used to describe vt?\n", progname, argv[2]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if (!S_ISCHR(sbf.st_mode)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 fprintf(stderr, "%s: %s must be character device\n", progname, argv[2]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 con = sbf.st_rdev & 0xFF;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 c2m.console = con;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 c2m.framebuffer = fb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 f = open(fbPath, O_RDWR);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 if (f < 0) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 fprintf(stderr, "%s: Cannot open %s\n", progname, fbPath);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 if (ioctl(f, FBIOPUT_CON2FBMAP, &c2m)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 fprintf(stderr, "%s: Cannot set console mapping\n", progname);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 close(f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 close(f);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79