You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

qemu-edid.c 3.4KB

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