Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 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" |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 8 | #include "qemu/bswap.h" |
| 9 | #include "qemu/cutils.h" |
| 10 | #include "hw/display/edid.h" |
| 11 | |
Gerd Hoffmann | c714654 | 2020-10-13 11:16:15 +0200 | [diff] [blame] | 12 | static qemu_edid_info info = { |
Daniel P. Berrangé | de72c4b | 2021-11-29 14:05:08 +0000 | [diff] [blame] | 13 | .prefx = 1280, |
| 14 | .prefy = 800, |
Marc-André Lureau | fd36ead | 2020-09-27 18:57:47 +0400 | [diff] [blame] | 15 | }; |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 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; |
Gerd Hoffmann | bdbe824 | 2021-04-27 17:08:17 +0200 | [diff] [blame] | 44 | uint8_t blob[512]; |
| 45 | size_t size; |
Marc-André Lureau | fd36ead | 2020-09-27 18:57:47 +0400 | [diff] [blame] | 46 | uint32_t dpi = 100; |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 47 | int rc; |
| 48 | |
| 49 | for (;;) { |
| 50 | rc = getopt(argc, argv, "ho:x:y:X:Y:d:v:n:s:"); |
| 51 | if (rc == -1) { |
| 52 | break; |
| 53 | } |
| 54 | switch (rc) { |
| 55 | case 'o': |
| 56 | if (outfile) { |
| 57 | fprintf(stderr, "outfile specified twice\n"); |
| 58 | exit(1); |
| 59 | } |
| 60 | outfile = fopen(optarg, "w"); |
| 61 | if (outfile == NULL) { |
| 62 | fprintf(stderr, "open %s: %s\n", optarg, strerror(errno)); |
| 63 | exit(1); |
| 64 | } |
| 65 | break; |
| 66 | case 'x': |
| 67 | if (qemu_strtoui(optarg, NULL, 10, &info.prefx) < 0) { |
| 68 | fprintf(stderr, "not a number: %s\n", optarg); |
| 69 | exit(1); |
| 70 | } |
| 71 | break; |
| 72 | case 'y': |
| 73 | if (qemu_strtoui(optarg, NULL, 10, &info.prefy) < 0) { |
| 74 | fprintf(stderr, "not a number: %s\n", optarg); |
| 75 | exit(1); |
| 76 | } |
| 77 | break; |
| 78 | case 'X': |
| 79 | if (qemu_strtoui(optarg, NULL, 10, &info.maxx) < 0) { |
| 80 | fprintf(stderr, "not a number: %s\n", optarg); |
| 81 | exit(1); |
| 82 | } |
| 83 | break; |
| 84 | case 'Y': |
| 85 | if (qemu_strtoui(optarg, NULL, 10, &info.maxy) < 0) { |
| 86 | fprintf(stderr, "not a number: %s\n", optarg); |
| 87 | exit(1); |
| 88 | } |
| 89 | break; |
| 90 | case 'd': |
Marc-André Lureau | fd36ead | 2020-09-27 18:57:47 +0400 | [diff] [blame] | 91 | if (qemu_strtoui(optarg, NULL, 10, &dpi) < 0) { |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 92 | fprintf(stderr, "not a number: %s\n", optarg); |
| 93 | exit(1); |
| 94 | } |
Sebastian Mitterle | 82a628f | 2022-10-11 17:12:16 +0200 | [diff] [blame] | 95 | if (dpi == 0) { |
| 96 | fprintf(stderr, "cannot be zero: %s\n", optarg); |
| 97 | exit(1); |
| 98 | } |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 99 | break; |
| 100 | case 'v': |
| 101 | info.vendor = optarg; |
| 102 | break; |
| 103 | case 'n': |
| 104 | info.name = optarg; |
| 105 | break; |
| 106 | case 's': |
| 107 | info.serial = optarg; |
| 108 | break; |
| 109 | case 'h': |
| 110 | usage(stdout); |
| 111 | exit(0); |
| 112 | default: |
| 113 | usage(stderr); |
| 114 | exit(1); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | if (outfile == NULL) { |
| 119 | outfile = stdout; |
| 120 | } |
| 121 | |
Marc-André Lureau | fd36ead | 2020-09-27 18:57:47 +0400 | [diff] [blame] | 122 | info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx); |
| 123 | info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy); |
| 124 | |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 125 | memset(blob, 0, sizeof(blob)); |
| 126 | qemu_edid_generate(blob, sizeof(blob), &info); |
Gerd Hoffmann | bdbe824 | 2021-04-27 17:08:17 +0200 | [diff] [blame] | 127 | size = qemu_edid_size(blob); |
| 128 | fwrite(blob, size, 1, outfile); |
Gerd Hoffmann | 72d277a | 2018-09-25 09:56:42 +0200 | [diff] [blame] | 129 | fflush(outfile); |
| 130 | |
| 131 | exit(0); |
| 132 | } |