]>
Commit | Line | Data |
---|---|---|
72d277a7 GH |
1 | /* |
2 | * QEMU EDID test tool. | |
3 | * | |
4 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
5 | * See the COPYING file in the top-level directory. | |
6 | */ | |
7 | #include "qemu/osdep.h" | |
8 | #include "qemu-common.h" | |
9 | #include "qemu/bswap.h" | |
10 | #include "qemu/cutils.h" | |
11 | #include "hw/display/edid.h" | |
12 | ||
13 | static qemu_edid_info info; | |
14 | ||
15 | static void usage(FILE *out) | |
16 | { | |
17 | fprintf(out, | |
18 | "\n" | |
19 | "This is a test tool for the qemu edid generator.\n" | |
20 | "\n" | |
21 | "Typically you'll pipe the output into edid-decode\n" | |
22 | "to check if the generator works correctly.\n" | |
23 | "\n" | |
24 | "usage: qemu-edid <options>\n" | |
25 | "options:\n" | |
26 | " -h print this text\n" | |
27 | " -o <file> set output file (stdout by default)\n" | |
28 | " -v <vendor> set monitor vendor (three letters)\n" | |
29 | " -n <name> set monitor name\n" | |
30 | " -s <serial> set monitor serial\n" | |
31 | " -d <dpi> set display resolution\n" | |
32 | " -x <prefx> set preferred width\n" | |
33 | " -y <prefy> set preferred height\n" | |
34 | " -X <maxx> set maximum width\n" | |
35 | " -Y <maxy> set maximum height\n" | |
36 | "\n"); | |
37 | } | |
38 | ||
39 | int main(int argc, char *argv[]) | |
40 | { | |
41 | FILE *outfile = NULL; | |
42 | uint8_t blob[256]; | |
43 | int rc; | |
44 | ||
45 | for (;;) { | |
46 | rc = getopt(argc, argv, "ho:x:y:X:Y:d:v:n:s:"); | |
47 | if (rc == -1) { | |
48 | break; | |
49 | } | |
50 | switch (rc) { | |
51 | case 'o': | |
52 | if (outfile) { | |
53 | fprintf(stderr, "outfile specified twice\n"); | |
54 | exit(1); | |
55 | } | |
56 | outfile = fopen(optarg, "w"); | |
57 | if (outfile == NULL) { | |
58 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); | |
59 | exit(1); | |
60 | } | |
61 | break; | |
62 | case 'x': | |
63 | if (qemu_strtoui(optarg, NULL, 10, &info.prefx) < 0) { | |
64 | fprintf(stderr, "not a number: %s\n", optarg); | |
65 | exit(1); | |
66 | } | |
67 | break; | |
68 | case 'y': | |
69 | if (qemu_strtoui(optarg, NULL, 10, &info.prefy) < 0) { | |
70 | fprintf(stderr, "not a number: %s\n", optarg); | |
71 | exit(1); | |
72 | } | |
73 | break; | |
74 | case 'X': | |
75 | if (qemu_strtoui(optarg, NULL, 10, &info.maxx) < 0) { | |
76 | fprintf(stderr, "not a number: %s\n", optarg); | |
77 | exit(1); | |
78 | } | |
79 | break; | |
80 | case 'Y': | |
81 | if (qemu_strtoui(optarg, NULL, 10, &info.maxy) < 0) { | |
82 | fprintf(stderr, "not a number: %s\n", optarg); | |
83 | exit(1); | |
84 | } | |
85 | break; | |
86 | case 'd': | |
87 | if (qemu_strtoui(optarg, NULL, 10, &info.dpi) < 0) { | |
88 | fprintf(stderr, "not a number: %s\n", optarg); | |
89 | exit(1); | |
90 | } | |
91 | break; | |
92 | case 'v': | |
93 | info.vendor = optarg; | |
94 | break; | |
95 | case 'n': | |
96 | info.name = optarg; | |
97 | break; | |
98 | case 's': | |
99 | info.serial = optarg; | |
100 | break; | |
101 | case 'h': | |
102 | usage(stdout); | |
103 | exit(0); | |
104 | default: | |
105 | usage(stderr); | |
106 | exit(1); | |
107 | } | |
108 | } | |
109 | ||
110 | if (outfile == NULL) { | |
111 | outfile = stdout; | |
112 | } | |
113 | ||
114 | memset(blob, 0, sizeof(blob)); | |
115 | qemu_edid_generate(blob, sizeof(blob), &info); | |
116 | fwrite(blob, sizeof(blob), 1, outfile); | |
117 | fflush(outfile); | |
118 | ||
119 | exit(0); | |
120 | } |