From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: Laszlo Ersek <lersek@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] simple firmware.json test tool
Date: Wed, 14 Nov 2018 16:12:52 +0100 [thread overview]
Message-ID: <a17f8629-e628-3b3d-f964-98bcb9b218f3@redhat.com> (raw)
In-Reply-To: <3f72757a-4b4c-9241-dd8f-561886cf3295@redhat.com>
Hi Gerd,
On 20/4/18 17:38, Laszlo Ersek wrote:
> On 04/20/18 12:47, Gerd Hoffmann wrote:
>> 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
>>
>> tools=""
>> if test "$want_tools" = "yes" ; then
>> - tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) $tools"
>> + tools="qemu-img\$(EXESUF) qemu-io\$(EXESUF) qemu-firmware\$(EXESUF) $tools"
>> if [ "$linux" = "yes" -o "$bsd" = "yes" -o "$solaris" = "yes" ] ; then
>> tools="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 $(COMMON_LDADDS)
>>
>> qemu-keymap$(EXESUF): qemu-keymap.o ui/input-keymap.o $(COMMON_LDADDS)
>>
>> +qemu-firmware$(EXESUF): qemu-firmware.o $(COMMON_LDADDS)
>> +
>> fsdev/virtfs-proxy-helper$(EXESUF): fsdev/virtfs-proxy-helper.o fsdev/9p-marshal.o fsdev/9p-iov-marshal.o $(COMMON_LDADDS)
>> fsdev/virtfs-proxy-helper$(EXESUF): LIBS += -lcap
>>
>> 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 = NULL;
>> + FirmwareMappingFlash *flash;
>> + Firmware *fw;
>> + Visitor *v;
>> + int fd, size, rc;
>> + char *buf;
>> +
>> + if (argc != 2) {
>> + fprintf(stderr, "usage: qemu-firmware <firmware-desc.json>\n");
>> + exit(1);
>> + }
>> +
>> + /* read file */
>> + fd = open(argv[1], O_RDONLY);
>> + if (fd < 0) {
>> + fprintf(stderr, "open %s: %s\n", argv[1], strerror(errno));
>> + exit(1);
>> + }
>> + size = lseek(fd, 0, SEEK_END);
>> + if (size < 0) {
>> + perror("lseek");
>> + exit(1);
>> + }
>> + lseek(fd, 0, SEEK_SET);
>> + buf = malloc(size+1);
>> + rc = read(fd, buf, size);
>> + if (rc != size) {
>> + fprintf(stderr, "file read error\n");
>> + exit(1);
>> + }
>> + buf[size] = 0;
>> + close(fd);
>> +
>> + /* parse file */
>> + v = 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?
>> + */
>
> Perhaps print a few shell commands first? Such as:
>
> (
> VARSTORE=$(mktemp)
> trap 'rm -f -- "$VARSTORE"' EXIT
> cat -- '[VARSTORE_TEMPLATE]' >> "$VARSTORE"
> qemu ...
> )
>
> It really does take separate actions, just like when you create a new
> disk image with "qemu-img".
>
> Thanks,
> Laszlo
>
>> + flash = &fw->mapping->u.flash;
>> + printf("-drive if=pflash,index=0,format=%s,file=%s\n",
>> + BlockdevDriver_str(flash->executable->format),
>> + flash->executable->pathname);
>> + printf("-drive if=pflash,index=1,format=%s,file=%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);
>> +}
Any plan to respin this patch?
Thanks,
Phil.
next prev parent reply other threads:[~2018-11-14 15:13 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-20 10:47 [Qemu-devel] [PATCH] simple firmware.json test tool Gerd Hoffmann
2018-04-20 10:51 ` no-reply
2018-04-20 10:51 ` no-reply
2018-04-20 10:53 ` no-reply
2018-04-20 10:55 ` no-reply
2018-04-20 15:38 ` Laszlo Ersek
2018-11-14 15:12 ` Philippe Mathieu-Daudé [this message]
2018-11-15 7:56 ` Gerd Hoffmann
2018-11-15 10:21 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a17f8629-e628-3b3d-f964-98bcb9b218f3@redhat.com \
--to=philmd@redhat.com \
--cc=kraxel@redhat.com \
--cc=lersek@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).