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