qemu
/
qemu-edid.c
132 строки · 3.7 Кб
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
12static qemu_edid_info info = {13.prefx = 1280,14.prefy = 800,15};16
17static void usage(FILE *out)18{
19fprintf(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
41int main(int argc, char *argv[])42{
43FILE *outfile = NULL;44uint8_t blob[512];45size_t size;46uint32_t dpi = 100;47int rc;48
49for (;;) {50rc = getopt(argc, argv, "ho:x:y:X:Y:d:v:n:s:");51if (rc == -1) {52break;53}54switch (rc) {55case 'o':56if (outfile) {57fprintf(stderr, "outfile specified twice\n");58exit(1);59}60outfile = fopen(optarg, "w");61if (outfile == NULL) {62fprintf(stderr, "open %s: %s\n", optarg, strerror(errno));63exit(1);64}65break;66case 'x':67if (qemu_strtoui(optarg, NULL, 10, &info.prefx) < 0) {68fprintf(stderr, "not a number: %s\n", optarg);69exit(1);70}71break;72case 'y':73if (qemu_strtoui(optarg, NULL, 10, &info.prefy) < 0) {74fprintf(stderr, "not a number: %s\n", optarg);75exit(1);76}77break;78case 'X':79if (qemu_strtoui(optarg, NULL, 10, &info.maxx) < 0) {80fprintf(stderr, "not a number: %s\n", optarg);81exit(1);82}83break;84case 'Y':85if (qemu_strtoui(optarg, NULL, 10, &info.maxy) < 0) {86fprintf(stderr, "not a number: %s\n", optarg);87exit(1);88}89break;90case 'd':91if (qemu_strtoui(optarg, NULL, 10, &dpi) < 0) {92fprintf(stderr, "not a number: %s\n", optarg);93exit(1);94}95if (dpi == 0) {96fprintf(stderr, "cannot be zero: %s\n", optarg);97exit(1);98}99break;100case 'v':101info.vendor = optarg;102break;103case 'n':104info.name = optarg;105break;106case 's':107info.serial = optarg;108break;109case 'h':110usage(stdout);111exit(0);112default:113usage(stderr);114exit(1);115}116}117
118if (outfile == NULL) {119outfile = stdout;120}121
122info.width_mm = qemu_edid_dpi_to_mm(dpi, info.prefx);123info.height_mm = qemu_edid_dpi_to_mm(dpi, info.prefy);124
125memset(blob, 0, sizeof(blob));126qemu_edid_generate(blob, sizeof(blob), &info);127size = qemu_edid_size(blob);128fwrite(blob, size, 1, outfile);129fflush(outfile);130
131exit(0);132}
133