2
0

qemu-edid.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/bswap.h"
  9. #include "qemu/cutils.h"
  10. #include "hw/display/edid.h"
  11. static qemu_edid_info info = {
  12. .prefx = 1024,
  13. .prefy = 768,
  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. int main(int argc, char *argv[])
  39. {
  40. FILE *outfile = NULL;
  41. uint8_t blob[256];
  42. uint32_t dpi = 100;
  43. int rc;
  44. for (;;) {
  45. rc = getopt(argc, argv, "ho:x:y:X:Y:d:v:n:s:");
  46. if (rc == -1) {
  47. break;
  48. }
  49. switch (rc) {
  50. case 'o':
  51. if (outfile) {
  52. fprintf(stderr, "outfile specified twice\n");
  53. exit(1);
  54. }
  55. outfile = fopen(optarg, "w");
  56. if (outfile == NULL) {
  57. fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));
  58. exit(1);
  59. }
  60. break;
  61. case 'x':
  62. if (qemu_strtoui(optarg, NULL, 10, &info.prefx) < 0) {
  63. fprintf(stderr, "not a number: %s\n", optarg);
  64. exit(1);
  65. }
  66. break;
  67. case 'y':
  68. if (qemu_strtoui(optarg, NULL, 10, &info.prefy) < 0) {
  69. fprintf(stderr, "not a number: %s\n", optarg);
  70. exit(1);
  71. }
  72. break;
  73. case 'X':
  74. if (qemu_strtoui(optarg, NULL, 10, &info.maxx) < 0) {
  75. fprintf(stderr, "not a number: %s\n", optarg);
  76. exit(1);
  77. }
  78. break;
  79. case 'Y':
  80. if (qemu_strtoui(optarg, NULL, 10, &info.maxy) < 0) {
  81. fprintf(stderr, "not a number: %s\n", optarg);
  82. exit(1);
  83. }
  84. break;
  85. case 'd':
  86. if (qemu_strtoui(optarg, NULL, 10, &dpi) < 0) {
  87. fprintf(stderr, "not a number: %s\n", optarg);
  88. exit(1);
  89. }
  90. break;
  91. case 'v':
  92. info.vendor = optarg;
  93. break;
  94. case 'n':
  95. info.name = optarg;
  96. break;
  97. case 's':
  98. info.serial = optarg;
  99. break;
  100. case 'h':
  101. usage(stdout);
  102. exit(0);
  103. default:
  104. usage(stderr);
  105. exit(1);
  106. }
  107. }
  108. if (outfile == NULL) {
  109. outfile = stdout;
  110. }
  111. info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx);
  112. info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy);
  113. memset(blob, 0, sizeof(blob));
  114. qemu_edid_generate(blob, sizeof(blob), &info);
  115. fwrite(blob, sizeof(blob), 1, outfile);
  116. fflush(outfile);
  117. exit(0);
  118. }