From 1077691ac1eb6e192725885e88ab1c7fd43e3044 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Wed, 9 Mar 2022 13:30:15 +0100 Subject: qmi-firmware-update: enable normal update mode even without udev --- src/qmi-firmware-update/qfu-device-selection.c | 78 ++++++++------------------ src/qmi-firmware-update/qfu-device-selection.h | 4 -- src/qmi-firmware-update/qfu-main.c | 37 ++---------- src/qmi-firmware-update/qfu-operation-update.c | 4 -- src/qmi-firmware-update/qfu-operation.h | 3 - src/qmi-firmware-update/qfu-updater.c | 42 -------------- src/qmi-firmware-update/qfu-updater.h | 3 - 7 files changed, 29 insertions(+), 142 deletions(-) (limited to 'src') diff --git a/src/qmi-firmware-update/qfu-device-selection.c b/src/qmi-firmware-update/qfu-device-selection.c index 778ecdf7..138e813f 100644 --- a/src/qmi-firmware-update/qfu-device-selection.c +++ b/src/qmi-firmware-update/qfu-device-selection.c @@ -39,11 +39,12 @@ struct _QfuDeviceSelectionPrivate { guint preferred_busnum; guint preferred_devnum; -#if defined WITH_UDEV /* sysfs path */ gchar *sysfs_path; /* peer port sysfs path */ gchar *peer_port; + +#if defined WITH_UDEV /* generic udev monitor */ QfuHelpersUdevGenericMonitor *monitor; #endif @@ -51,8 +52,6 @@ struct _QfuDeviceSelectionPrivate { /******************************************************************************/ -#if defined WITH_UDEV - static GFile * device_selection_get_single (QfuDeviceSelection *self, QfuHelpersDeviceType device_type) @@ -98,23 +97,6 @@ device_selection_get_single (QfuDeviceSelection *self, return NULL; } -#else - -static GFile * -device_selection_get_single (QfuDeviceSelection *self, - QfuHelpersDeviceType device_type) -{ - - if (!self->priv->preferred_devices[device_type]) { - g_warning ("[qfu,device-selection] no %s device defined", qfu_helpers_device_type_to_string (device_type)); - return NULL; - } - - return g_file_new_for_commandline_arg (self->priv->preferred_devices[device_type]); -} - -#endif - GFile * qfu_device_selection_get_single_cdc_wdm (QfuDeviceSelection *self) { @@ -128,7 +110,6 @@ qfu_device_selection_get_single_tty (QfuDeviceSelection *self) } /******************************************************************************/ -#if defined WITH_UDEV static GList * device_selection_get_multiple (QfuDeviceSelection *self, @@ -167,25 +148,14 @@ device_selection_get_multiple (QfuDeviceSelection *self, return NULL; } -#endif - GList * qfu_device_selection_get_multiple_ttys (QfuDeviceSelection *self) { -#if defined WITH_UDEV return device_selection_get_multiple (self, QFU_HELPERS_DEVICE_TYPE_TTY); -#else - GFile *single; - - single = qfu_device_selection_get_single_tty (self); - return (single ? g_list_append (NULL, single) : NULL); -#endif } /******************************************************************************/ -#if defined WITH_UDEV - GFile * qfu_device_selection_wait_for_cdc_wdm_finish (QfuDeviceSelection *self, GAsyncResult *res, @@ -252,8 +222,6 @@ qfu_device_selection_wait_for_tty (QfuDeviceSelection *self, task); } -#endif - /******************************************************************************/ QfuDeviceSelection * @@ -298,27 +266,26 @@ qfu_device_selection_new (const gchar *preferred_cdc_wdm, self->priv->preferred_busnum = preferred_busnum; self->priv->preferred_devnum = preferred_devnum; -#if defined WITH_UDEV - { - /* Initialize sysfs path from inputs */ - if (preferred_vid || preferred_devnum) - self->priv->sysfs_path = qfu_helpers_find_by_device_info (preferred_vid, preferred_pid, preferred_busnum, preferred_devnum, error); - else if (preferred_cdc_wdm || preferred_tty) - self->priv->sysfs_path = qfu_helpers_find_by_file_path (preferred_cdc_wdm ? preferred_cdc_wdm : preferred_tty, error); - else - g_assert_not_reached (); - - if (!self->priv->sysfs_path) { - g_object_unref (self); - return NULL; - } - - /* look for a peer port */ - self->priv->peer_port = qfu_helpers_find_peer_port (self->priv->sysfs_path, error); - - /* Initialize right away the generic udev monitor for this sysfs path */ - self->priv->monitor = qfu_helpers_udev_generic_monitor_new (self->priv->sysfs_path); + + /* Initialize sysfs path from inputs */ + if (preferred_vid || preferred_devnum) + self->priv->sysfs_path = qfu_helpers_find_by_device_info (preferred_vid, preferred_pid, preferred_busnum, preferred_devnum, error); + else if (preferred_cdc_wdm || preferred_tty) + self->priv->sysfs_path = qfu_helpers_find_by_file_path (preferred_cdc_wdm ? preferred_cdc_wdm : preferred_tty, error); + else + g_assert_not_reached (); + + if (!self->priv->sysfs_path) { + g_object_unref (self); + return NULL; } + + /* look for a peer port */ + self->priv->peer_port = qfu_helpers_find_peer_port (self->priv->sysfs_path, error); + +#if defined WITH_UDEV + /* Initialize right away the generic udev monitor for this sysfs path */ + self->priv->monitor = qfu_helpers_udev_generic_monitor_new (self->priv->sysfs_path); #endif return self; @@ -339,9 +306,10 @@ finalize (GObject *object) #if defined WITH_UDEV if (self->priv->monitor) qfu_helpers_udev_generic_monitor_free (self->priv->monitor); +#endif + g_free (self->priv->sysfs_path); g_free (self->priv->peer_port); -#endif for (i = 0; i < QFU_HELPERS_DEVICE_TYPE_LAST; i++) g_free (self->priv->preferred_devices[i]); diff --git a/src/qmi-firmware-update/qfu-device-selection.h b/src/qmi-firmware-update/qfu-device-selection.h index 66b698e3..1f9991a9 100644 --- a/src/qmi-firmware-update/qfu-device-selection.h +++ b/src/qmi-firmware-update/qfu-device-selection.h @@ -59,7 +59,6 @@ QfuDeviceSelection *qfu_device_selection_new (const gchar *preferred_cdc_w GError **error); GFile *qfu_device_selection_get_single_cdc_wdm (QfuDeviceSelection *self); -#if defined WITH_UDEV void qfu_device_selection_wait_for_cdc_wdm (QfuDeviceSelection *self, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -67,11 +66,9 @@ void qfu_device_selection_wait_for_cdc_wdm (QfuDeviceSelection *self, GFile *qfu_device_selection_wait_for_cdc_wdm_finish (QfuDeviceSelection *self, GAsyncResult *res, GError **error); -#endif /* WITH_UDEV */ GFile *qfu_device_selection_get_single_tty (QfuDeviceSelection *self); GList *qfu_device_selection_get_multiple_ttys (QfuDeviceSelection *self); -#if defined WITH_UDEV void qfu_device_selection_wait_for_tty (QfuDeviceSelection *self, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -79,7 +76,6 @@ void qfu_device_selection_wait_for_tty (QfuDeviceSelection *self, GFile *qfu_device_selection_wait_for_tty_finish (QfuDeviceSelection *self, GAsyncResult *res, GError **error); -#endif /* WITH_UDEV */ G_END_DECLS diff --git a/src/qmi-firmware-update/qfu-main.c b/src/qmi-firmware-update/qfu-main.c index 590d9d47..4ee0b2de 100644 --- a/src/qmi-firmware-update/qfu-main.c +++ b/src/qmi-firmware-update/qfu-main.c @@ -42,20 +42,17 @@ /* Options */ /* Generic device selections */ -#if defined WITH_UDEV -static guint busnum; -static guint devnum; -static guint16 vid; -static guint16 pid; -#endif -static gchar *cdc_wdm_str; -static gchar *tty_str; +static guint busnum; +static guint devnum; +static guint16 vid; +static guint16 pid; +static gchar *cdc_wdm_str; +static gchar *tty_str; #if defined MM_RUNTIME_CHECK_ENABLED static gboolean ignore_mm_runtime_check_flag; #endif -#if defined WITH_UDEV /* Update */ static gboolean action_update_flag; static gchar *firmware_version_str; @@ -65,7 +62,6 @@ static gboolean ignore_version_errors_flag; static gboolean override_download_flag; static gint modem_storage_index_int; static gboolean skip_validation_flag; -#endif /* Reset */ static gboolean action_reset_flag; @@ -89,8 +85,6 @@ static gboolean version_flag; static gboolean help_flag; static gboolean help_examples_flag; -#if defined WITH_UDEV - static gboolean parse_busnum_devnum (const gchar *option_name, const gchar *value, @@ -186,10 +180,7 @@ out: return result; } -#endif /* WITH_UDEV */ - static GOptionEntry context_selection_entries[] = { -#if defined WITH_UDEV { "busnum-devnum", 's', 0, G_OPTION_ARG_CALLBACK, &parse_busnum_devnum, "Select device by bus and device number (in decimal).", "[BUS:]DEV" @@ -198,7 +189,6 @@ static GOptionEntry context_selection_entries[] = { "Select device by device vendor and product id (in hexadecimal).", "VID[:PID]" }, -#endif /* WITH_UDEV */ { "cdc-wdm", 'w', 0, G_OPTION_ARG_FILENAME, &cdc_wdm_str, "Select device by QMI/MBIM cdc-wdm device path (e.g. /dev/cdc-wdm0).", "[PATH]" @@ -210,7 +200,6 @@ static GOptionEntry context_selection_entries[] = { { NULL } }; -#if defined WITH_UDEV static GOptionEntry context_update_entries[] = { { "update", 'u', 0, G_OPTION_ARG_NONE, &action_update_flag, "Launch firmware update process.", @@ -246,7 +235,6 @@ static GOptionEntry context_update_entries[] = { }, { NULL } }; -#endif /* WITH_UDEV */ static GOptionEntry context_reset_entries[] = { { "reset", 'b', 0, G_OPTION_ARG_NONE, &action_reset_flag, @@ -368,7 +356,6 @@ print_help (GOptionContext *context) static void print_help_examples (void) { -#if defined WITH_UDEV g_print ("\n" "********************************************************************************\n" "\n" @@ -451,8 +438,6 @@ print_help_examples (void) " --cdc-wdm /dev/cdc-wdm0 \\\n" " 9999999_9999999_9200_03.05.14.00_00_generic_000.000_001_SPKG_MC.cwe\n"); -#endif /* WITH_UDEV */ - g_print ("\n" "********************************************************************************\n" "\n" @@ -565,11 +550,9 @@ int main (int argc, char **argv) g_option_group_add_entries (group, context_selection_entries); g_option_context_add_group (context, group); -#if defined WITH_UDEV group = g_option_group_new ("update", "Update options (normal mode):", "", NULL, NULL); g_option_group_add_entries (group, context_update_entries); g_option_context_add_group (context, group); -#endif group = g_option_group_new ("reset", "Reset options (normal mode):", "", NULL, NULL); g_option_group_add_entries (group, context_reset_entries); @@ -622,12 +605,10 @@ int main (int argc, char **argv) /* Actions that allow using a cdc-wdm device */ n_actions_cdc_wdm_needed = (action_reset_flag); -#if defined WITH_UDEV n_actions += action_update_flag; n_actions_cdc_wdm_needed += action_update_flag; n_actions_images_needed += action_update_flag; n_actions_device_needed += action_update_flag; -#endif /* We don't allow multiple actions at the same time */ if (n_actions == 0) { @@ -647,11 +628,7 @@ int main (int argc, char **argv) /* device selection must be performed for update and reset operations */ if (n_actions_device_needed) { -#if defined WITH_UDEV device_selection = qfu_device_selection_new (cdc_wdm_str, tty_str, vid, pid, busnum, devnum, &error); -#else - device_selection = qfu_device_selection_new (cdc_wdm_str, tty_str, 0, 0, 0, 0, &error); -#endif if (!device_selection) { g_printerr ("error: couldn't select device:: %s\n", error->message); g_error_free (error); @@ -703,7 +680,6 @@ int main (int argc, char **argv) /* Run */ -#if defined WITH_UDEV if (action_update_flag) { g_assert (QFU_IS_DEVICE_SELECTION (device_selection)); @@ -726,7 +702,6 @@ int main (int argc, char **argv) skip_validation_flag); goto out; } -#endif /* WITH_UDEV */ if (action_update_download_flag) { g_assert (QFU_IS_DEVICE_SELECTION (device_selection)); diff --git a/src/qmi-firmware-update/qfu-operation-update.c b/src/qmi-firmware-update/qfu-operation-update.c index d47d5282..2a751434 100644 --- a/src/qmi-firmware-update/qfu-operation-update.c +++ b/src/qmi-firmware-update/qfu-operation-update.c @@ -115,8 +115,6 @@ operation_update_run (QfuUpdater *updater, return operation.result; } -#if defined WITH_UDEV - gboolean qfu_operation_update_run (const gchar **images, QfuDeviceSelection *device_selection, @@ -148,8 +146,6 @@ qfu_operation_update_run (const gchar **images, return result; } -#endif - gboolean qfu_operation_update_download_run (const gchar **images, QfuDeviceSelection *device_selection) diff --git a/src/qmi-firmware-update/qfu-operation.h b/src/qmi-firmware-update/qfu-operation.h index efb30355..d82882a2 100644 --- a/src/qmi-firmware-update/qfu-operation.h +++ b/src/qmi-firmware-update/qfu-operation.h @@ -30,7 +30,6 @@ G_BEGIN_DECLS -#if defined WITH_UDEV gboolean qfu_operation_update_run (const gchar **images, QfuDeviceSelection *device_selection, const gchar *firmware_version, @@ -41,8 +40,6 @@ gboolean qfu_operation_update_run (const gchar **images, gboolean override_download, guint8 modem_storage_index, gboolean skip_validation); -#endif - gboolean qfu_operation_update_download_run (const gchar **images, QfuDeviceSelection *device_selection); gboolean qfu_operation_verify_run (const gchar **images); diff --git a/src/qmi-firmware-update/qfu-updater.c b/src/qmi-firmware-update/qfu-updater.c index a33fc78e..15d85ad3 100644 --- a/src/qmi-firmware-update/qfu-updater.c +++ b/src/qmi-firmware-update/qfu-updater.c @@ -42,16 +42,13 @@ G_DEFINE_TYPE (QfuUpdater, qfu_updater, G_TYPE_OBJECT) typedef enum { UPDATER_TYPE_UNKNOWN, -#if defined WITH_UDEV UPDATER_TYPE_GENERIC, -#endif UPDATER_TYPE_DOWNLOAD, } UpdaterType; struct _QfuUpdaterPrivate { UpdaterType type; QfuDeviceSelection *device_selection; -#if defined WITH_UDEV gchar *firmware_version; gchar *config_version; gchar *carrier; @@ -60,7 +57,6 @@ struct _QfuUpdaterPrivate { gboolean override_download; guint8 modem_storage_index; gboolean skip_validation; -#endif }; /******************************************************************************/ @@ -86,39 +82,32 @@ static const gchar *progress[] = { #define WAIT_FOR_BOOT_RETRIES 12 typedef enum { -#if defined WITH_UDEV RUN_CONTEXT_STEP_QMI_CLIENT, RUN_CONTEXT_STEP_GET_FIRMWARE_PREFERENCE, RUN_CONTEXT_STEP_SET_FIRMWARE_PREFERENCE, RUN_CONTEXT_STEP_POWER_CYCLE, RUN_CONTEXT_STEP_CLEANUP_QMI_DEVICE, RUN_CONTEXT_STEP_WAIT_FOR_TTY, -#endif RUN_CONTEXT_STEP_SELECT_DEVICE, RUN_CONTEXT_STEP_SELECT_IMAGE, RUN_CONTEXT_STEP_DOWNLOAD_IMAGE, RUN_CONTEXT_STEP_CLEANUP_IMAGE, RUN_CONTEXT_STEP_CLEANUP_DEVICE, -#if defined WITH_UDEV RUN_CONTEXT_STEP_WAIT_FOR_CDC_WDM, RUN_CONTEXT_STEP_WAIT_FOR_BOOT, RUN_CONTEXT_STEP_QMI_CLIENT_AFTER, RUN_CONTEXT_STEP_CLEANUP_QMI_DEVICE_FULL, -#endif RUN_CONTEXT_STEP_LAST } RunContextStep; typedef struct { /* Device selection */ -#if defined WITH_UDEV GFile *cdc_wdm_file; -#endif GFile *serial_file; /* Context step */ RunContextStep step; -#if defined WITH_UDEV /* Old/New info and capabilities */ gchar *revision; gboolean supports_stored_image_management; @@ -131,14 +120,12 @@ typedef struct { gboolean new_supports_firmware_preference_management; QmiMessageDmsGetFirmwarePreferenceOutput *new_firmware_preference; QmiMessageDmsSwiGetCurrentFirmwareOutput *new_current_firmware; -#endif /* List of pending QfuImages to download, and the current one being * processed. */ GList *pending_images; QfuImage *current_image; -#if defined WITH_UDEV /* QMI device and client */ QmiDevice *qmi_device; QmiClientDms *qmi_client; @@ -154,7 +141,6 @@ typedef struct { /* Waiting for boot */ guint wait_for_boot_seconds_elapsed; guint wait_for_boot_retries; -#endif /* Device to use while already in download mode */ QfuQdlDevice *qdl_device; @@ -164,7 +150,6 @@ typedef struct { static void run_context_free (RunContext *ctx) { -#if defined WITH_UDEV if (ctx->current_firmware) qmi_message_dms_swi_get_current_firmware_output_unref (ctx->current_firmware); if (ctx->new_current_firmware) @@ -195,7 +180,6 @@ run_context_free (RunContext *ctx) } if (ctx->cdc_wdm_file) g_object_unref (ctx->cdc_wdm_file); -#endif g_clear_object (&ctx->qdl_device); g_clear_object (&ctx->sahara_device); @@ -213,8 +197,6 @@ qfu_updater_run_finish (QfuUpdater *self, return g_task_propagate_boolean (G_TASK (res), error); } -#if defined WITH_UDEV - static void print_firmware_preference (QmiMessageDmsGetFirmwarePreferenceOutput *firmware_preference, const gchar *prefix) @@ -282,8 +264,6 @@ print_current_firmware (QmiMessageDmsSwiGetCurrentFirmwareOutput *current_firmwa g_print ("%sConfig version: %s\n", prefix, config_version); } -#endif /* WITH_UDEV */ - static void run_context_step_last (GTask *task) { @@ -301,7 +281,6 @@ run_context_step_last (GTask *task) return; } -#if defined WITH_UDEV if (self->priv->type == UPDATER_TYPE_GENERIC) { g_print ("\n" "------------------------------------------------------------------------\n"); @@ -353,7 +332,6 @@ run_context_step_last (GTask *task) g_object_unref (task); return; } -#endif /* WITH_UDEV */ g_assert_not_reached (); } @@ -379,8 +357,6 @@ run_context_step_next (GTask *task, RunContextStep next) g_idle_add ((GSourceFunc) run_context_step_cb, task); } -#if defined WITH_UDEV - static void run_context_step_next_no_idle (GTask *task, RunContextStep next) { @@ -621,8 +597,6 @@ run_context_step_wait_for_cdc_wdm (GTask *task) task); } -#endif /* WITH_UDEV */ - static void run_context_step_cleanup_device (GTask *task) { @@ -888,8 +862,6 @@ run_context_step_select_device (GTask *task) run_context_step_next (task, ctx->step + 1); } -#if defined WITH_UDEV - static void wait_for_tty_ready (QfuDeviceSelection *device_selection, GAsyncResult *res, @@ -1446,29 +1418,23 @@ run_context_step_qmi_client (GTask *task) task); } -#endif /* WITH_UDEV */ - typedef void (* RunContextStepFunc) (GTask *task); static const RunContextStepFunc run_context_step_func[] = { -#if defined WITH_UDEV [RUN_CONTEXT_STEP_QMI_CLIENT] = run_context_step_qmi_client, [RUN_CONTEXT_STEP_GET_FIRMWARE_PREFERENCE] = run_context_step_get_firmware_preference, [RUN_CONTEXT_STEP_SET_FIRMWARE_PREFERENCE] = run_context_step_set_firmware_preference, [RUN_CONTEXT_STEP_POWER_CYCLE] = run_context_step_power_cycle, [RUN_CONTEXT_STEP_CLEANUP_QMI_DEVICE] = run_context_step_cleanup_qmi_device, [RUN_CONTEXT_STEP_WAIT_FOR_TTY] = run_context_step_wait_for_tty, -#endif [RUN_CONTEXT_STEP_SELECT_DEVICE] = run_context_step_select_device, [RUN_CONTEXT_STEP_SELECT_IMAGE] = run_context_step_select_image, [RUN_CONTEXT_STEP_DOWNLOAD_IMAGE] = run_context_step_download_image, [RUN_CONTEXT_STEP_CLEANUP_IMAGE] = run_context_step_cleanup_image, [RUN_CONTEXT_STEP_CLEANUP_DEVICE] = run_context_step_cleanup_device, -#if defined WITH_UDEV [RUN_CONTEXT_STEP_WAIT_FOR_CDC_WDM] = run_context_step_wait_for_cdc_wdm, [RUN_CONTEXT_STEP_WAIT_FOR_BOOT] = run_context_step_wait_for_boot, [RUN_CONTEXT_STEP_QMI_CLIENT_AFTER] = run_context_step_qmi_client_after, [RUN_CONTEXT_STEP_CLEANUP_QMI_DEVICE_FULL] = run_context_step_cleanup_qmi_device_full, -#endif }; G_STATIC_ASSERT (G_N_ELEMENTS (run_context_step_func) == RUN_CONTEXT_STEP_LAST); @@ -1552,7 +1518,6 @@ qfu_updater_run (QfuUpdater *self, } switch (self->priv->type) { -#if defined WITH_UDEV case UPDATER_TYPE_GENERIC: ctx->step = RUN_CONTEXT_STEP_QMI_CLIENT; ctx->cdc_wdm_file = qfu_device_selection_get_single_cdc_wdm (self->priv->device_selection); @@ -1563,7 +1528,6 @@ qfu_updater_run (QfuUpdater *self, return; } break; -#endif case UPDATER_TYPE_DOWNLOAD: ctx->step = RUN_CONTEXT_STEP_SELECT_DEVICE; ctx->serial_file = qfu_device_selection_get_single_tty (self->priv->device_selection); @@ -1584,8 +1548,6 @@ qfu_updater_run (QfuUpdater *self, /******************************************************************************/ -#if defined WITH_UDEV - QfuUpdater * qfu_updater_new (QfuDeviceSelection *device_selection, const gchar *firmware_version, @@ -1616,8 +1578,6 @@ qfu_updater_new (QfuDeviceSelection *device_selection, return self; } -#endif - QfuUpdater * qfu_updater_new_download (QfuDeviceSelection *device_selection) { @@ -1652,13 +1612,11 @@ dispose (GObject *object) static void finalize (GObject *object) { -#if defined WITH_UDEV QfuUpdater *self = QFU_UPDATER (object); g_free (self->priv->firmware_version); g_free (self->priv->config_version); g_free (self->priv->carrier); -#endif G_OBJECT_CLASS (qfu_updater_parent_class)->finalize (object); } diff --git a/src/qmi-firmware-update/qfu-updater.h b/src/qmi-firmware-update/qfu-updater.h index 992193a0..04584aa0 100644 --- a/src/qmi-firmware-update/qfu-updater.h +++ b/src/qmi-firmware-update/qfu-updater.h @@ -52,7 +52,6 @@ struct _QfuUpdaterClass { GType qfu_updater_get_type (void); G_DEFINE_AUTOPTR_CLEANUP_FUNC (QfuUpdater, g_object_unref); -#if defined WITH_UDEV QfuUpdater *qfu_updater_new (QfuDeviceSelection *device_selection, const gchar *firmware_version, const gchar *config_version, @@ -62,8 +61,6 @@ QfuUpdater *qfu_updater_new (QfuDeviceSelection *device_selection, gboolean override_download, guint8 modem_storage_index, gboolean skip_validation); -#endif - QfuUpdater *qfu_updater_new_download (QfuDeviceSelection *device_selection); void qfu_updater_run (QfuUpdater *self, GList *image_file_list, -- cgit v1.2.1