diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2016-12-05 17:27:42 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2017-01-16 11:24:13 +0100 |
commit | 396c86e44a63396664c11c346172364180b1a58f (patch) | |
tree | 5983600de7e13c99efc585b576b54f2f997279be /src | |
parent | 311fbc31c0d48fb3e231fb0a493876b884554964 (diff) | |
download | external_libqmi-396c86e44a63396664c11c346172364180b1a58f.zip external_libqmi-396c86e44a63396664c11c346172364180b1a58f.tar.gz external_libqmi-396c86e44a63396664c11c346172364180b1a58f.tar.bz2 |
qmi-firmware-update: list of images to flash given as remaining args
And therefore make the image verification action accept multiple file
paths, not just one.
Diffstat (limited to 'src')
-rw-r--r-- | src/qmi-firmware-update/Makefile.am | 2 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-main.c | 85 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-operation-update.c (renamed from src/qmi-firmware-update/qfu-operation-download.c) | 22 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-operation-verify.c | 17 | ||||
-rw-r--r-- | src/qmi-firmware-update/qfu-operation.h | 16 |
5 files changed, 83 insertions, 59 deletions
diff --git a/src/qmi-firmware-update/Makefile.am b/src/qmi-firmware-update/Makefile.am index b8d3944..920e6a6 100644 --- a/src/qmi-firmware-update/Makefile.am +++ b/src/qmi-firmware-update/Makefile.am @@ -41,7 +41,7 @@ nodist_qmi_firmware_update_SOURCES = \ qmi_firmware_update_SOURCES = \ qfu-main.c \ qfu-operation.h \ - qfu-operation-download.c \ + qfu-operation-update.c \ qfu-operation-verify.c \ qfu-updater.h qfu-updater.c \ qfu-udev-helpers.h qfu-udev-helpers.c \ diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c index bfcfcd9..73f02ea 100644 --- a/src/qmi-firmware-update/qfu-main.c +++ b/src/qmi-firmware-update/qfu-main.c @@ -40,9 +40,9 @@ /*****************************************************************************/ /* Options */ -/* Download */ +/* Update */ +static gboolean action_update_flag; static gchar *device_str; -static gchar **image_strv; static gchar *firmware_version_str; static gchar *config_version_str; static gchar *carrier_str; @@ -50,21 +50,22 @@ static gboolean device_open_proxy_flag; static gboolean device_open_mbim_flag; /* Verify */ -static gchar *verify_image_str; +static gboolean action_verify_flag;; /* Main */ -static gboolean verbose_flag; -static gboolean silent_flag; -static gboolean version_flag; -static gboolean help_flag; - -static GOptionEntry context_download_entries[] = { - { "device", 'd', 0, G_OPTION_ARG_FILENAME, &device_str, - "Specify device path.", - "[PATH]" +static gchar **image_strv; +static gboolean verbose_flag; +static gboolean silent_flag; +static gboolean version_flag; +static gboolean help_flag; + +static GOptionEntry context_update_entries[] = { + { "update", 'u', 0, G_OPTION_ARG_NONE, &action_update_flag, + "Launch firmware update process.", + NULL }, - { "image", 'i', 0, G_OPTION_ARG_FILENAME_ARRAY, &image_strv, - "Specify image to download to the device. May be given multiple times.", + { "device", 'd', 0, G_OPTION_ARG_FILENAME, &device_str, + "Specify cdc-wdm device path (e.g. /dev/cdc-wdm0).", "[PATH]" }, { "firmware-version", 'f', 0, G_OPTION_ARG_STRING, &firmware_version_str, @@ -91,14 +92,17 @@ static GOptionEntry context_download_entries[] = { }; static GOptionEntry context_verify_entries[] = { - { "verify-image", 'z', 0, G_OPTION_ARG_FILENAME, &verify_image_str, - "Specify image to verify.", - "[PATH]" + { "verify", 'z', 0, G_OPTION_ARG_NONE, &action_verify_flag, + "Analyze and Verify firmware images.", + NULL }, { NULL } }; static GOptionEntry context_main_entries[] = { + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &image_strv, "", + "FILE1 FILE2..." + }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose_flag, "Run action with verbose logs, including the debug ones.", NULL @@ -119,20 +123,21 @@ static GOptionEntry context_main_entries[] = { }; static const gchar *context_description = - " E.g. a download operation:\n" + " E.g. an update operation:\n" " $ sudo " PROGRAM_NAME " \\\n" - " --verbose \\\n" + " --update \\\n" " --device /dev/cdc-wdm4 \\\n" " --firmware-version 05.05.58.00 \\\n" " --config-version 005.025_002 \\\n" " --carrier Generic \\\n" - " --image SWI9X15C_05.05.58.00.cwe \\\n" - " --image SWI9X15C_05.05.58.00_Generic_005.025_002.nvu\n" + " SWI9X15C_05.05.58.00.cwe \\\n" + " 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" + " --verify \\\n" + " SWI9X15C_05.05.58.00.cwe \\\n" + " SWI9X15C_05.05.58.00_Generic_005.025_002.nvu\n" "\n"; /*****************************************************************************/ @@ -233,8 +238,8 @@ int main (int argc, char **argv) /* Setup option context, process it and destroy it */ context = g_option_context_new ("- Update firmware in QMI devices"); - group = g_option_group_new ("download", "Download options", "", NULL, NULL); - g_option_group_add_entries (group, context_download_entries); + group = g_option_group_new ("update", "Update options", "", NULL, NULL); + g_option_group_add_entries (group, context_update_entries); g_option_context_add_group (context, group); group = g_option_group_new ("verify", "Verify options", "", NULL, NULL); @@ -269,7 +274,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 = (!!verify_image_str + !!image_strv); + n_actions = (action_verify_flag + action_update_flag); if (n_actions == 0) { g_printerr ("error: no actions specified\n"); goto out; @@ -279,17 +284,23 @@ int main (int argc, char **argv) goto out; } - /* Run operation */ - if (image_strv) - result = qfu_operation_download_run (device_str, - firmware_version_str, - config_version_str, - carrier_str, - (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); + /* A list of images must always be provided */ + if (!image_strv) { + g_printerr ("error: no firmware images specified\n"); + goto out; + } + + /* Run */ + if (action_update_flag) + result = qfu_operation_update_run ((const gchar **) image_strv, + device_str, + firmware_version_str, + config_version_str, + carrier_str, + device_open_proxy_flag, + device_open_mbim_flag); + else if (action_verify_flag) + result = qfu_operation_verify_run ((const gchar **) image_strv); else g_assert_not_reached (); diff --git a/src/qmi-firmware-update/qfu-operation-download.c b/src/qmi-firmware-update/qfu-operation-update.c index 6845357..a989cdc 100644 --- a/src/qmi-firmware-update/qfu-operation-download.c +++ b/src/qmi-firmware-update/qfu-operation-update.c @@ -30,10 +30,10 @@ typedef struct { GMainLoop *loop; GCancellable *cancellable; gboolean result; -} DownloadOperation; +} UpdateOperation; static gboolean -signal_handler (DownloadOperation *operation) +signal_handler (UpdateOperation *operation) { operation->result = FALSE; @@ -57,7 +57,7 @@ signal_handler (DownloadOperation *operation) static void run_ready (QfuUpdater *updater, GAsyncResult *res, - DownloadOperation *operation) + UpdateOperation *operation) { GError *error = NULL; @@ -73,15 +73,15 @@ run_ready (QfuUpdater *updater, } gboolean -qfu_operation_download_run (const gchar *device, - const gchar *firmware_version, - const gchar *config_version, - const gchar *carrier, - const gchar **images, - gboolean device_open_proxy, - gboolean device_open_mbim) +qfu_operation_update_run (const gchar **images, + const gchar *device, + const gchar *firmware_version, + const gchar *config_version, + const gchar *carrier, + gboolean device_open_proxy, + gboolean device_open_mbim) { - DownloadOperation operation = { + UpdateOperation operation = { .loop = NULL, .cancellable = NULL, .result = FALSE, diff --git a/src/qmi-firmware-update/qfu-operation-verify.c b/src/qmi-firmware-update/qfu-operation-verify.c index 05e17f9..518a6e6 100644 --- a/src/qmi-firmware-update/qfu-operation-verify.c +++ b/src/qmi-firmware-update/qfu-operation-verify.c @@ -67,8 +67,8 @@ print_image_cwe (QfuImageCwe *image, } } -gboolean -qfu_operation_verify_run (const gchar *image_path) +static gboolean +operation_verify_run_single (const gchar *image_path) { QfuImage *image; GFile *file; @@ -83,6 +83,7 @@ qfu_operation_verify_run (const gchar *image_path) goto out; } + g_print ("\n"); 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))); @@ -101,3 +102,15 @@ out: g_object_unref (image); return result; } + +gboolean +qfu_operation_verify_run (const gchar **images) +{ + guint invalid_images = 0; + guint i; + + for (i = 0; images[i] ; i++) + invalid_images += !operation_verify_run_single (images[i]); + + return !invalid_images; +} diff --git a/src/qmi-firmware-update/qfu-operation.h b/src/qmi-firmware-update/qfu-operation.h index d829f70..296d315 100644 --- a/src/qmi-firmware-update/qfu-operation.h +++ b/src/qmi-firmware-update/qfu-operation.h @@ -26,14 +26,14 @@ G_BEGIN_DECLS -gboolean qfu_operation_download_run (const gchar *device, - const gchar *firmware_version, - const gchar *config_version, - const gchar *carrier, - const gchar **images, - gboolean device_open_proxy, - gboolean device_open_mbim); -gboolean qfu_operation_verify_run (const gchar *image_path); +gboolean qfu_operation_update_run (const gchar **images, + const gchar *device, + const gchar *firmware_version, + const gchar *config_version, + const gchar *carrier, + gboolean device_open_proxy, + gboolean device_open_mbim); +gboolean qfu_operation_verify_run (const gchar **images); G_END_DECLS |