[PATCH v5 2/3] hw/uefi: add 'info firmware-log' hmp monitor command.

Gerd Hoffmann posted 3 patches 1 month ago
Maintainers: "Dr. David Alan Gilbert" <dave@treblig.org>, Gerd Hoffmann <kraxel@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
[PATCH v5 2/3] hw/uefi: add 'info firmware-log' hmp monitor command.
Posted by Gerd Hoffmann 1 month ago
This adds the hmp variant of the query-firmware-log qmp command.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/uefi/ovmf-log.c   | 27 +++++++++++++++++++++++++++
 hmp-commands-info.hx | 13 +++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/hw/uefi/ovmf-log.c b/hw/uefi/ovmf-log.c
index 85dda15ab6ad..e281a980a101 100644
--- a/hw/uefi/ovmf-log.c
+++ b/hw/uefi/ovmf-log.c
@@ -231,3 +231,30 @@ FirmwareLog *qmp_query_firmware_log(Error **errp)
     ret->log = g_base64_encode((const guchar *)log->str, log->len);
     return ret;
 }
+
+void hmp_info_firmware_log(Monitor *mon, const QDict *qdict)
+{
+    g_autofree gchar *log_esc = NULL;
+    g_autofree guchar *log_out = NULL;
+    Error *err = NULL;
+    FirmwareLog *log;
+    gsize log_len;
+
+    log = qmp_query_firmware_log(&err);
+    if (err)  {
+        hmp_handle_error(mon, err);
+        return;
+    }
+
+    g_assert(log != NULL);
+    g_assert(log->log != NULL);
+
+    if (log->version) {
+        g_autofree gchar *esc = g_strescape(log->version, NULL);
+        monitor_printf(mon, "[ firmware version: %s ]\n", esc);
+    }
+
+    log_out = g_base64_decode(log->log, &log_len);
+    log_esc = g_strescape((gchar *)log_out, "\r\n");
+    monitor_printf(mon, "%s\n", log_esc);
+}
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index eaaa880c1b30..f0aef419923c 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -990,3 +990,16 @@ SRST
   ``info cryptodev``
     Show the crypto devices.
 ERST
+
+    {
+        .name       = "firmware-log",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show the firmware (ovmf) debug log",
+        .cmd        = hmp_info_firmware_log,
+    },
+
+SRST
+  ``info firmware-log``
+    Show the firmware (ovmf) debug log.
+ERST
-- 
2.51.0
Re: [PATCH v5 2/3] hw/uefi: add 'info firmware-log' hmp monitor command.
Posted by Markus Armbruster 1 month ago
Gerd Hoffmann <kraxel@redhat.com> writes:

> This adds the hmp variant of the query-firmware-log qmp command.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/uefi/ovmf-log.c   | 27 +++++++++++++++++++++++++++
>  hmp-commands-info.hx | 13 +++++++++++++
>  2 files changed, 40 insertions(+)
>
> diff --git a/hw/uefi/ovmf-log.c b/hw/uefi/ovmf-log.c
> index 85dda15ab6ad..e281a980a101 100644
> --- a/hw/uefi/ovmf-log.c
> +++ b/hw/uefi/ovmf-log.c
> @@ -231,3 +231,30 @@ FirmwareLog *qmp_query_firmware_log(Error **errp)
>      ret->log = g_base64_encode((const guchar *)log->str, log->len);
>      return ret;
>  }
> +
> +void hmp_info_firmware_log(Monitor *mon, const QDict *qdict)
> +{
> +    g_autofree gchar *log_esc = NULL;
> +    g_autofree guchar *log_out = NULL;
> +    Error *err = NULL;
> +    FirmwareLog *log;
> +    gsize log_len;
> +
> +    log = qmp_query_firmware_log(&err);
> +    if (err)  {
> +        hmp_handle_error(mon, err);
> +        return;
> +    }
> +
> +    g_assert(log != NULL);
> +    g_assert(log->log != NULL);

QAPI ensures this, so I wouldn't bother myself.  Up to you.

> +
> +    if (log->version) {
> +        g_autofree gchar *esc = g_strescape(log->version, NULL);
> +        monitor_printf(mon, "[ firmware version: %s ]\n", esc);
> +    }
> +
> +    log_out = g_base64_decode(log->log, &log_len);
> +    log_esc = g_strescape((gchar *)log_out, "\r\n");
> +    monitor_printf(mon, "%s\n", log_esc);
> +}
> diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
> index eaaa880c1b30..f0aef419923c 100644
> --- a/hmp-commands-info.hx
> +++ b/hmp-commands-info.hx
> @@ -990,3 +990,16 @@ SRST
>    ``info cryptodev``
>      Show the crypto devices.
>  ERST
> +
> +    {
> +        .name       = "firmware-log",
> +        .args_type  = "",
> +        .params     = "",
> +        .help       = "show the firmware (ovmf) debug log",
> +        .cmd        = hmp_info_firmware_log,
> +    },
> +
> +SRST
> +  ``info firmware-log``
> +    Show the firmware (ovmf) debug log.
> +ERST

With the update of monitor/hmp.h moved here from PATCH 1
Reviewed-by: Markus Armbruster <armbru@redhat.com>