qemu-edid.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 = 1280,
  13. .prefy = 800,
  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[512];
  42. size_t size;
  43. uint32_t dpi = 100;
  44. int rc;
  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, &dpi) < 0) {
  88. fprintf(stderr, "not a number: %s\n", optarg);
  89. exit(1);
  90. }
  91. if (dpi == 0) {
  92. fprintf(stderr, "cannot be zero: %s\n", optarg);
  93. exit(1);
  94. }
  95. break;
  96. case 'v':
  97. info.vendor = optarg;
  98. break;
  99. case 'n':
  100. info.name = optarg;
  101. break;
  102. case 's':
  103. info.serial = optarg;
  104. break;
  105. case 'h':
  106. usage(stdout);
  107. exit(0);
  108. default:
  109. usage(stderr);
  110. exit(1);
  111. }
  112. }
  113. if (outfile == NULL) {
  114. outfile = stdout;
  115. }
  116. info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx);
  117. info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy);
  118. memset(blob, 0, sizeof(blob));
  119. qemu_edid_generate(blob, sizeof(blob), &info);
  120. size = qemu_edid_size(blob);
  121. fwrite(blob, size, 1, outfile);
  122. fflush(outfile);
  123. exit(0);
  124. }