From nobody Fri May 3 12:12:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524221371215295.67701685474265; Fri, 20 Apr 2018 03:49:31 -0700 (PDT) Received: from localhost ([::1]:46779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9Tbd-0003zw-RX for importer@patchew.org; Fri, 20 Apr 2018 06:49:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9TaH-0003Eo-Hd for qemu-devel@nongnu.org; Fri, 20 Apr 2018 06:48:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9TaD-0006Fa-I6 for qemu-devel@nongnu.org; Fri, 20 Apr 2018 06:48:05 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50080 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f9TaD-0006Ei-Bd for qemu-devel@nongnu.org; Fri, 20 Apr 2018 06:48:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86996F1205 for ; Fri, 20 Apr 2018 10:47:57 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-151.ams2.redhat.com [10.36.117.151]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32E4F9C067; Fri, 20 Apr 2018 10:47:51 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 87F1A31FB4; Fri, 20 Apr 2018 12:47:50 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 20 Apr 2018 12:47:43 +0200 Message-Id: <20180420104743.7396-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 20 Apr 2018 10:47:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Fri, 20 Apr 2018 10:47:57 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'kraxel@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] simple firmware.json test tool X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lersek@redhat.com, Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" applies on top of the firmware.json v2 series. --- configure | 2 +- Makefile | 2 ++ qemu-firmware.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 qemu-firmware.c diff --git a/configure b/configure index 0a19b033bc..753f80147b 100755 --- a/configure +++ b/configure @@ -5495,7 +5495,7 @@ fi =20 tools=3D"" if test "$want_tools" =3D "yes" ; then - tools=3D"qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools" + tools=3D"qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-firmware\$(EXESUF) $t= ools" if [ "$linux" =3D "yes" -o "$bsd" =3D "yes" -o "$solaris" =3D "yes" ] ; = then tools=3D"qemu-nbd\$(EXESUF) $tools" fi diff --git a/Makefile b/Makefile index 32034abe15..4d6e627113 100644 --- a/Makefile +++ b/Makefile @@ -543,6 +543,8 @@ qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o $(COM= MON_LDADDS) =20 qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS) =20 +qemu-firmware$(EXESUF): qemu-firmware.o $(COMMON_LDADDS) + fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-m= arshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS) fsdev/virtfs-proxy-helper$(EXESUF): LIBS +=3D -lcap =20 diff --git a/qemu-firmware.c b/qemu-firmware.c new file mode 100644 index 0000000000..792f0fec8f --- /dev/null +++ b/qemu-firmware.c @@ -0,0 +1,81 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/error-report.h" + +#include "qapi/error.h" +#include "qapi/qapi-types-firmware.h" +#include "qapi/qapi-visit-firmware.h" +#include "qapi/qobject-input-visitor.h" + +int main(int argc, char *argv[]) +{ + Error *err =3D NULL; + FirmwareMappingFlash *flash; + Firmware *fw; + Visitor *v; + int fd, size, rc; + char *buf; + + if (argc !=3D 2) { + fprintf(stderr, "usage: qemu-firmware \n"); + exit(1); + } + + /* read file */ + fd =3D open(argv[1], O_RDONLY); + if (fd < 0) { + fprintf(stderr, "open %s: %s\n", argv[1], strerror(errno)); + exit(1); + } + size =3D lseek(fd, 0, SEEK_END); + if (size < 0) { + perror("lseek"); + exit(1); + } + lseek(fd, 0, SEEK_SET); + buf =3D malloc(size+1); + rc =3D read(fd, buf, size); + if (rc !=3D size) { + fprintf(stderr, "file read error\n"); + exit(1); + } + buf[size] =3D 0; + close(fd); + + /* parse file */ + v =3D qobject_input_visitor_new_str(buf, "", &err); + if (!v) { + error_report_err(err); + exit(1); + } + visit_type_Firmware(v, NULL, &fw, &error_fatal); + visit_free(v); + + /* print cmdline */ + switch (fw->mapping->device) { + case FIRMWARE_DEVICE_FLASH: + /* + * FIXME: nvram should be a per-guest copy. + * How to handle that best here? + */ + flash =3D &fw->mapping->u.flash; + printf("-drive if=3Dpflash,index=3D0,format=3D%s,file=3D%s\n", + BlockdevDriver_str(flash->executable->format), + flash->executable->pathname); + printf("-drive if=3Dpflash,index=3D1,format=3D%s,file=3D%s\n", + BlockdevDriver_str(flash->nvram_template->format), + flash->nvram_template->pathname); + break; + case FIRMWARE_DEVICE_MEMORY: + printf("-bios %s\n", fw->mapping->u.memory.pathname); + break; + case FIRMWARE_DEVICE_KERNEL: + printf("-kernel %s\n", fw->mapping->u.kernel.pathname); + break; + default: + fprintf(stderr, "TODO\n"); + break; + } + + exit(0); +} --=20 2.9.3