From 1d894f13cc7cc5a9daf5a819b08bf38c7844b18b Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Fri, 31 Aug 2018 13:05:51 +0100 Subject: [PATCH] trivial: Move the hwids debug functionality to fwupdtool --- data/bash-completion/fwupdmgr | 1 - data/bash-completion/fwupdtool.in | 1 + src/fu-tool.c | 87 ++++++++++++++++++++++++++++++ src/fu-util.c | 88 ------------------------------- 4 files changed, 88 insertions(+), 89 deletions(-) diff --git a/data/bash-completion/fwupdmgr b/data/bash-completion/fwupdmgr index a8543b8bb..2e27dadb0 100644 --- a/data/bash-completion/fwupdmgr +++ b/data/bash-completion/fwupdmgr @@ -14,7 +14,6 @@ _fwupdmgr_cmd_list=( 'get-results' 'get-topology' 'get-updates' - 'hwids' 'install' 'install-prepared' 'modify-remote' diff --git a/data/bash-completion/fwupdtool.in b/data/bash-completion/fwupdtool.in index 846e90bec..6062e2e50 100644 --- a/data/bash-completion/fwupdtool.in +++ b/data/bash-completion/fwupdtool.in @@ -3,6 +3,7 @@ _fwupdtool_cmd_list=( 'get-devices' 'get-plugins' 'get-topology' + 'hwids' 'install' 'install-blob' 'smbios-dump' diff --git a/src/fu-tool.c b/src/fu-tool.c index 4ff5454f6..69752997d 100644 --- a/src/fu-tool.c +++ b/src/fu-tool.c @@ -759,6 +759,87 @@ fu_util_attach (FuUtilPrivate *priv, gchar **values, GError **error) return fu_device_attach (device, error); } +static gboolean +fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error) +{ + g_autoptr(FuSmbios) smbios = fu_smbios_new (); + g_autoptr(FuHwids) hwids = fu_hwids_new (); + const gchar *hwid_keys[] = { + FU_HWIDS_KEY_BIOS_VENDOR, + FU_HWIDS_KEY_BIOS_VERSION, + FU_HWIDS_KEY_BIOS_MAJOR_RELEASE, + FU_HWIDS_KEY_BIOS_MINOR_RELEASE, + FU_HWIDS_KEY_MANUFACTURER, + FU_HWIDS_KEY_FAMILY, + FU_HWIDS_KEY_PRODUCT_NAME, + FU_HWIDS_KEY_PRODUCT_SKU, + FU_HWIDS_KEY_ENCLOSURE_KIND, + FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, + FU_HWIDS_KEY_BASEBOARD_PRODUCT, + NULL }; + + /* read DMI data */ + if (g_strv_length (values) == 0) { + if (!fu_smbios_setup (smbios, error)) + return FALSE; + } else if (g_strv_length (values) == 1) { + if (!fu_smbios_setup_from_file (smbios, values[0], error)) + return FALSE; + } else { + g_set_error_literal (error, + FWUPD_ERROR, + FWUPD_ERROR_INVALID_ARGS, + "Invalid arguments"); + return FALSE; + } + if (!fu_hwids_setup (hwids, smbios, error)) + return FALSE; + + /* show debug output */ + g_print ("Computer Information\n"); + g_print ("--------------------\n"); + for (guint i = 0; hwid_keys[i] != NULL; i++) { + const gchar *tmp = fu_hwids_get_value (hwids, hwid_keys[i]); + if (tmp == NULL) + continue; + if (g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MAJOR_RELEASE) == 0 || + g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MINOR_RELEASE) == 0) { + guint64 val = g_ascii_strtoull (tmp, NULL, 16); + g_print ("%s: %" G_GUINT64_FORMAT "\n", hwid_keys[i], val); + } else { + g_print ("%s: %s\n", hwid_keys[i], tmp); + } + } + + /* show GUIDs */ + g_print ("\nHardware IDs\n"); + g_print ("------------\n"); + for (guint i = 0; i < 15; i++) { + const gchar *keys = NULL; + g_autofree gchar *guid = NULL; + g_autofree gchar *key = NULL; + g_autofree gchar *keys_str = NULL; + g_auto(GStrv) keysv = NULL; + g_autoptr(GError) error_local = NULL; + + /* get the GUID */ + key = g_strdup_printf ("HardwareID-%u", i); + keys = fu_hwids_get_replace_keys (hwids, key); + guid = fu_hwids_get_guid (hwids, key, &error_local); + if (guid == NULL) { + g_print ("%s\n", error_local->message); + continue; + } + + /* show what makes up the GUID */ + keysv = g_strsplit (keys, "&", -1); + keys_str = g_strjoinv (" + ", keysv); + g_print ("{%s} <- %s\n", guid, keys_str); + } + + return TRUE; +} + int main (int argc, char *argv[]) { @@ -870,6 +951,12 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Detach to bootloader mode"), fu_util_detach); + fu_util_add (priv->cmd_array, + "hwids", + "[FILE]", + /* TRANSLATORS: command description */ + _("Return all the hardware IDs for the machine"), + fu_util_hwids); /* do stuff on ctrl+c */ priv->cancellable = g_cancellable_new (); diff --git a/src/fu-util.c b/src/fu-util.c index f92676728..2f90d0322 100644 --- a/src/fu-util.c +++ b/src/fu-util.c @@ -21,7 +21,6 @@ #include #include -#include "fu-hwids.h" #include "fu-history.h" #include "fu-plugin-private.h" #include "fu-progressbar.h" @@ -2223,87 +2222,6 @@ fu_util_downgrade (FuUtilPrivate *priv, gchar **values, GError **error) return fu_util_update_device_with_release (priv, dev, rel, error); } -static gboolean -fu_util_hwids (FuUtilPrivate *priv, gchar **values, GError **error) -{ - g_autoptr(FuSmbios) smbios = fu_smbios_new (); - g_autoptr(FuHwids) hwids = fu_hwids_new (); - const gchar *hwid_keys[] = { - FU_HWIDS_KEY_BIOS_VENDOR, - FU_HWIDS_KEY_BIOS_VERSION, - FU_HWIDS_KEY_BIOS_MAJOR_RELEASE, - FU_HWIDS_KEY_BIOS_MINOR_RELEASE, - FU_HWIDS_KEY_MANUFACTURER, - FU_HWIDS_KEY_FAMILY, - FU_HWIDS_KEY_PRODUCT_NAME, - FU_HWIDS_KEY_PRODUCT_SKU, - FU_HWIDS_KEY_ENCLOSURE_KIND, - FU_HWIDS_KEY_BASEBOARD_MANUFACTURER, - FU_HWIDS_KEY_BASEBOARD_PRODUCT, - NULL }; - - /* read DMI data */ - if (g_strv_length (values) == 0) { - if (!fu_smbios_setup (smbios, error)) - return FALSE; - } else if (g_strv_length (values) == 1) { - if (!fu_smbios_setup_from_file (smbios, values[0], error)) - return FALSE; - } else { - g_set_error_literal (error, - FWUPD_ERROR, - FWUPD_ERROR_INVALID_ARGS, - "Invalid arguments"); - return FALSE; - } - if (!fu_hwids_setup (hwids, smbios, error)) - return FALSE; - - /* show debug output */ - g_print ("Computer Information\n"); - g_print ("--------------------\n"); - for (guint i = 0; hwid_keys[i] != NULL; i++) { - const gchar *tmp = fu_hwids_get_value (hwids, hwid_keys[i]); - if (tmp == NULL) - continue; - if (g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MAJOR_RELEASE) == 0 || - g_strcmp0 (hwid_keys[i], FU_HWIDS_KEY_BIOS_MINOR_RELEASE) == 0) { - guint64 val = g_ascii_strtoull (tmp, NULL, 16); - g_print ("%s: %" G_GUINT64_FORMAT "\n", hwid_keys[i], val); - } else { - g_print ("%s: %s\n", hwid_keys[i], tmp); - } - } - - /* show GUIDs */ - g_print ("\nHardware IDs\n"); - g_print ("------------\n"); - for (guint i = 0; i < 15; i++) { - const gchar *keys = NULL; - g_autofree gchar *guid = NULL; - g_autofree gchar *key = NULL; - g_autofree gchar *keys_str = NULL; - g_auto(GStrv) keysv = NULL; - g_autoptr(GError) error_local = NULL; - - /* get the GUID */ - key = g_strdup_printf ("HardwareID-%u", i); - keys = fu_hwids_get_replace_keys (hwids, key); - guid = fu_hwids_get_guid (hwids, key, &error_local); - if (guid == NULL) { - g_print ("%s\n", error_local->message); - continue; - } - - /* show what makes up the GUID */ - keysv = g_strsplit (keys, "&", -1); - keys_str = g_strjoinv (" + ", keysv); - g_print ("{%s} <- %s\n", guid, keys_str); - } - - return TRUE; -} - static void fu_util_ignore_cb (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) @@ -2425,12 +2343,6 @@ main (int argc, char *argv[]) /* TRANSLATORS: command description */ _("Get all devices according to the system topology"), fu_util_get_topology); - fu_util_add (priv->cmd_array, - "hwids", - "[FILE]", - /* TRANSLATORS: command description */ - _("Return all the hardware IDs for the machine"), - fu_util_hwids); fu_util_add (priv->cmd_array, "install-prepared", NULL,