diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-11-29 23:23:55 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-01-16 11:24:13 +0100 |
commit | dc8fb3c994a4c3b6550e3edbee002bbc861b8e56 (patch) | |
tree | d288ddac73ccf6611d06685b2ec0ffffae9974e6 | |
parent | 661e69663bfffc8f79e4015419022a8f880933eb (diff) | |
download | external_libqmi-dc8fb3c994a4c3b6550e3edbee002bbc861b8e56.zip external_libqmi-dc8fb3c994a4c3b6550e3edbee002bbc861b8e56.tar.gz external_libqmi-dc8fb3c994a4c3b6550e3edbee002bbc861b8e56.tar.bz2 |
qmi-firmware-update: implement firmware image analysis operation
-rw-r--r-- | src/qmi-firmware-update/Makefile.am | 1 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-main.c | 31 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-operation-verify.c | 69 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-operation.h | 1 |
4 files changed, 94 insertions, 8 deletions
diff --git a/src/qmi-firmware-update/Makefile.am b/src/qmi-firmware-update/Makefile.am index dbf76f4..aec2fbb 100644 --- a/src/qmi-firmware-update/Makefile.am +++ b/src/qmi-firmware-update/Makefile.am @@ -40,6 +40,7 @@ qmi_firmware_update_SOURCES = \ qfu-main.c \ qfu-operation.h \ qfu-operation-download.c \ + qfu-operation-verify.c \ qfu-updater.h qfu-updater.c \ qfu-udev-helpers.h qfu-udev-helpers.c \ qfu-download-helpers.h qfu-download-helpers.c \ diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c index 9596e86..bfcfcd9 100644 --- a/src/qmi-firmware-update/qfu-main.c +++ b/src/qmi-firmware-update/qfu-main.c @@ -49,6 +49,9 @@ static gchar *carrier_str; static gboolean device_open_proxy_flag; static gboolean device_open_mbim_flag; +/* Verify */ +static gchar *verify_image_str; + /* Main */ static gboolean verbose_flag; static gboolean silent_flag; @@ -87,6 +90,14 @@ static GOptionEntry context_download_entries[] = { { NULL } }; +static GOptionEntry context_verify_entries[] = { + { "verify-image", 'z', 0, G_OPTION_ARG_FILENAME, &verify_image_str, + "Specify image to verify.", + "[PATH]" + }, + { NULL } +}; + static GOptionEntry context_main_entries[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag, "Run action with verbose logs, including the debug ones.", @@ -117,6 +128,11 @@ static const gchar *context_description = " --carrier Generic \\\n" " --image SWI9X15C_05.05.58.00.cwe \\\n" " --image SWI9X15C_05.05.58.00_Generic_005.025_002.nvu\n" + "\n" + " E.g. a verify operation:\n" + " $ sudo " PROGRAM_NAME " \\\n" + " --verbose \\\n" + " --verify-image SWI9X15C_05.05.58.00.cwe\n" "\n"; /*****************************************************************************/ @@ -221,6 +237,10 @@ int main (int argc, char **argv) g_option_group_add_entries (group, context_download_entries); g_option_context_add_group (context, group); + group = g_option_group_new ("verify", "Verify options", "", NULL, NULL); + g_option_group_add_entries (group, context_verify_entries); + g_option_context_add_group (context, group); + g_option_context_add_main_entries (context, context_main_entries, NULL); g_option_context_set_description (context, context_description); g_option_context_set_help_enabled (context, FALSE); @@ -249,7 +269,7 @@ int main (int argc, char **argv) qmi_utils_set_traces_enabled (TRUE); /* We don't allow multiple actions at the same time */ - n_actions = (!!image_strv); + n_actions = (!!verify_image_str + !!image_strv); if (n_actions == 0) { g_printerr ("error: no actions specified\n"); goto out; @@ -268,6 +288,8 @@ int main (int argc, char **argv) (const gchar **) image_strv, device_open_proxy_flag, device_open_mbim_flag); + else if (verify_image_str) + result = qfu_operation_verify_run (verify_image_str); else g_assert_not_reached (); @@ -275,13 +297,6 @@ out: /* Clean exit for a clean memleak report */ if (context) g_option_context_free (context); - if (updater) - g_object_unref (updater); - if (cancellable) - g_object_unref (cancellable); - if (loop) - g_main_loop_unref (loop); - return (result ? EXIT_SUCCESS : EXIT_FAILURE); } diff --git a/src/qmi-firmware-update/qfu-operation-verify.c b/src/qmi-firmware-update/qfu-operation-verify.c new file mode 100644 index 0000000..0c1bd94 --- /dev/null +++ b/src/qmi-firmware-update/qfu-operation-verify.c @@ -0,0 +1,69 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * qmi-firmware-update -- Command line tool to update firmware in QMI devices + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Copyright (C) 2016 Zodiac Inflight Innovations + * Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es> + */ + +#include <glib-object.h> +#include <gio/gio.h> + +#include "qfu-operation.h" +#include "qfu-image.h" +#include "qfu-image-cwe.h" +#include "qfu-image-factory.h" +#include "qfu-enum-types.h" + +gboolean +qfu_operation_verify_run (const gchar *image_path) +{ + QfuImage *image; + GFile *file; + GError *error = NULL; + gboolean result = FALSE; + + file = g_file_new_for_commandline_arg (image_path); + image = qfu_image_factory_build (file, NULL, &error); + if (!image) { + g_printerr ("error: couldn't detect image type: %s", + error->message); + g_error_free (error); + goto out; + } + + g_print ("Firmware image:\n"); + g_print (" filename: %s\n", qfu_image_get_display_name (image)); + g_print (" detected type: %s\n", qfu_image_type_get_string (qfu_image_get_image_type (image))); + g_print (" size: %" G_GOFFSET_FORMAT " bytes\n", qfu_image_get_size (image)); + g_print (" header: %" G_GOFFSET_FORMAT " bytes\n", qfu_image_get_header_size (image)); + g_print (" data: %" G_GOFFSET_FORMAT " bytes\n", qfu_image_get_data_size (image)); + g_print (" data chunks: %" G_GUINT16_FORMAT " (%lu bytes/chunk)\n", qfu_image_get_n_data_chunks (image), (gulong) QFU_IMAGE_CHUNK_SIZE); + + if (QFU_IS_IMAGE_CWE (image)) { + g_print (" [cwe] type: %s\n", qfu_image_cwe_header_get_type (QFU_IMAGE_CWE (image))); + g_print (" [cwe] product: %s\n", qfu_image_cwe_header_get_product (QFU_IMAGE_CWE (image))); + g_print (" [cwe] version: %s\n", qfu_image_cwe_header_get_version (QFU_IMAGE_CWE (image))); + g_print (" [cwe] date: %s\n", qfu_image_cwe_header_get_date (QFU_IMAGE_CWE (image))); + } + + result = TRUE; + +out: + if (image) + g_object_unref (image); + return result; +} diff --git a/src/qmi-firmware-update/qfu-operation.h b/src/qmi-firmware-update/qfu-operation.h index de7f5ad..d829f70 100644 --- a/src/qmi-firmware-update/qfu-operation.h +++ b/src/qmi-firmware-update/qfu-operation.h @@ -33,6 +33,7 @@ gboolean qfu_operation_download_run (const gchar *device, const gchar **images, gboolean device_open_proxy, gboolean device_open_mbim); +gboolean qfu_operation_verify_run (const gchar *image_path); G_END_DECLS |