mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-13 19:08:34 +00:00
Allow setting the version format from a quirk entry
This commit is contained in:
parent
83e56c1a6c
commit
a3d5712b9f
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
struct _FuNvmeDevice {
|
struct _FuNvmeDevice {
|
||||||
FuUdevDevice parent_instance;
|
FuUdevDevice parent_instance;
|
||||||
gchar *version_format;
|
|
||||||
guint pci_depth;
|
guint pci_depth;
|
||||||
gint fd;
|
gint fd;
|
||||||
guint64 write_block_size;
|
guint64 write_block_size;
|
||||||
@ -186,13 +185,13 @@ static gboolean
|
|||||||
fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **error)
|
fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **error)
|
||||||
{
|
{
|
||||||
/* unset */
|
/* unset */
|
||||||
if (self->version_format == NULL) {
|
if (fu_device_get_version_format (FU_DEVICE (self)) == FU_VERSION_FORMAT_UNKNOWN) {
|
||||||
fu_device_set_version (FU_DEVICE (self), version);
|
fu_device_set_version (FU_DEVICE (self), version);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* AA.BB.CC.DD */
|
/* AA.BB.CC.DD */
|
||||||
if (g_strcmp0 (self->version_format, "quad") == 0) {
|
if (fu_device_get_version_format (FU_DEVICE (self)) == FU_VERSION_FORMAT_QUAD) {
|
||||||
guint64 tmp = g_ascii_strtoull (version, NULL, 16);
|
guint64 tmp = g_ascii_strtoull (version, NULL, 16);
|
||||||
g_autofree gchar *version_new = NULL;
|
g_autofree gchar *version_new = NULL;
|
||||||
if (tmp == 0 || tmp > G_MAXUINT32) {
|
if (tmp == 0 || tmp > G_MAXUINT32) {
|
||||||
@ -203,17 +202,16 @@ fu_nvme_device_set_version (FuNvmeDevice *self, const gchar *version, GError **e
|
|||||||
version);
|
version);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
version_new = as_utils_version_from_uint32 (tmp, FU_VERSION_FORMAT_QUAD);
|
version_new = fu_common_version_from_uint32 (tmp, FU_VERSION_FORMAT_QUAD);
|
||||||
fu_device_set_version (FU_DEVICE (self), version_new);
|
fu_device_set_version (FU_DEVICE (self), version_new);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* invalid, or not supported */
|
/* invalid, or not supported */
|
||||||
g_set_error (error,
|
g_set_error_literal (error,
|
||||||
G_IO_ERROR,
|
G_IO_ERROR,
|
||||||
G_IO_ERROR_INVALID_DATA,
|
G_IO_ERROR_INVALID_DATA,
|
||||||
"version format %s not recognised",
|
"version format not recognised");
|
||||||
self->version_format);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,10 +420,6 @@ fu_nvme_device_set_quirk_kv (FuDevice *device,
|
|||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
FuNvmeDevice *self = FU_NVME_DEVICE (device);
|
FuNvmeDevice *self = FU_NVME_DEVICE (device);
|
||||||
if (g_strcmp0 (key, "NvmeVersionFormat") == 0) {
|
|
||||||
self->version_format = g_strdup (value);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
if (g_strcmp0 (key, "NvmeBlockSize") == 0) {
|
if (g_strcmp0 (key, "NvmeBlockSize") == 0) {
|
||||||
self->write_block_size = fu_common_strtoull (value);
|
self->write_block_size = fu_common_strtoull (value);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -451,8 +445,6 @@ fu_nvme_device_init (FuNvmeDevice *self)
|
|||||||
static void
|
static void
|
||||||
fu_nvme_device_finalize (GObject *object)
|
fu_nvme_device_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
FuNvmeDevice *self = FU_NVME_DEVICE (object);
|
|
||||||
g_free (self->version_format);
|
|
||||||
G_OBJECT_CLASS (fu_nvme_device_parent_class)->finalize (object);
|
G_OBJECT_CLASS (fu_nvme_device_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ typedef struct {
|
|||||||
GPtrArray *children;
|
GPtrArray *children;
|
||||||
guint remove_delay; /* ms */
|
guint remove_delay; /* ms */
|
||||||
FwupdStatus status;
|
FwupdStatus status;
|
||||||
|
FuVersionFormat version_format;
|
||||||
guint progress;
|
guint progress;
|
||||||
guint order;
|
guint order;
|
||||||
guint priority;
|
guint priority;
|
||||||
@ -676,6 +677,10 @@ fu_device_set_quirk_kv (FuDevice *self,
|
|||||||
fu_device_set_install_duration (self, fu_common_strtoull (value));
|
fu_device_set_install_duration (self, fu_common_strtoull (value));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
if (g_strcmp0 (key, FU_QUIRKS_VERSION_FORMAT) == 0) {
|
||||||
|
fu_device_set_version_format (self, fu_common_version_format_from_string (value));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
if (g_strcmp0 (key, FU_QUIRKS_CHILDREN) == 0) {
|
if (g_strcmp0 (key, FU_QUIRKS_CHILDREN) == 0) {
|
||||||
g_auto(GStrv) sections = g_strsplit (value, ",", -1);
|
g_auto(GStrv) sections = g_strsplit (value, ",", -1);
|
||||||
for (guint i = 0; sections[i] != NULL; i++) {
|
for (guint i = 0; sections[i] != NULL; i++) {
|
||||||
@ -1351,6 +1356,43 @@ fu_device_set_status (FuDevice *self, FwupdStatus status)
|
|||||||
g_object_notify (G_OBJECT (self), "status");
|
g_object_notify (G_OBJECT (self), "status");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_device_get_version_format:
|
||||||
|
* @self: A #FuDevice
|
||||||
|
*
|
||||||
|
* Returns how the device version should be formatted.
|
||||||
|
*
|
||||||
|
* Returns: the version format, e.g. %FU_VERSION_FORMAT_TRIPLET
|
||||||
|
*
|
||||||
|
* Since: 1.2.0
|
||||||
|
**/
|
||||||
|
FuVersionFormat
|
||||||
|
fu_device_get_version_format (FuDevice *self)
|
||||||
|
{
|
||||||
|
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||||
|
g_return_val_if_fail (FU_IS_DEVICE (self), 0);
|
||||||
|
return priv->version_format;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fu_device_set_version_format:
|
||||||
|
* @self: A #FuDevice
|
||||||
|
* @version_format: the version_format value, e.g. %FU_VERSION_FORMAT_TRIPLET
|
||||||
|
*
|
||||||
|
* Sets how the version should be formatted.
|
||||||
|
*
|
||||||
|
* Since: 1.2.0
|
||||||
|
**/
|
||||||
|
void
|
||||||
|
fu_device_set_version_format (FuDevice *self, FuVersionFormat version_format)
|
||||||
|
{
|
||||||
|
FuDevicePrivate *priv = GET_PRIVATE (self);
|
||||||
|
g_return_if_fail (FU_IS_DEVICE (self));
|
||||||
|
if (priv->version_format == version_format)
|
||||||
|
return;
|
||||||
|
priv->version_format = version_format;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* fu_device_get_progress:
|
* fu_device_get_progress:
|
||||||
* @self: A #FuDevice
|
* @self: A #FuDevice
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#include <fwupd.h>
|
#include <fwupd.h>
|
||||||
|
|
||||||
#include "fu-quirks.h"
|
#include "fu-quirks.h"
|
||||||
|
#include "fu-common-version.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
@ -176,6 +177,9 @@ void fu_device_set_remove_delay (FuDevice *self,
|
|||||||
FwupdStatus fu_device_get_status (FuDevice *self);
|
FwupdStatus fu_device_get_status (FuDevice *self);
|
||||||
void fu_device_set_status (FuDevice *self,
|
void fu_device_set_status (FuDevice *self,
|
||||||
FwupdStatus status);
|
FwupdStatus status);
|
||||||
|
FuVersionFormat fu_device_get_version_format (FuDevice *self);
|
||||||
|
void fu_device_set_version_format (FuDevice *self,
|
||||||
|
FuVersionFormat version_format);
|
||||||
void fu_device_set_firmware_size_min (FuDevice *self,
|
void fu_device_set_firmware_size_min (FuDevice *self,
|
||||||
guint64 size_min);
|
guint64 size_min);
|
||||||
void fu_device_set_firmware_size_max (FuDevice *self,
|
void fu_device_set_firmware_size_max (FuDevice *self,
|
||||||
|
@ -242,6 +242,17 @@ gboolean fu_quirks_get_kvs_for_guid (FuQuirks *self,
|
|||||||
*/
|
*/
|
||||||
#define FU_QUIRKS_INSTALL_DURATION "InstallDuration"
|
#define FU_QUIRKS_INSTALL_DURATION "InstallDuration"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* FU_QUIRKS_VERSION_FORMAT:
|
||||||
|
* @key: the device ID, e.g. `HwId=USB\VID_0763&PID_2806`
|
||||||
|
* @value: the quirk format, e.g. `quad`
|
||||||
|
*
|
||||||
|
* Sets the version format the device should use for conversion.
|
||||||
|
*
|
||||||
|
* Since: 1.2.0
|
||||||
|
*/
|
||||||
|
#define FU_QUIRKS_VERSION_FORMAT "VersionFormat"
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __FU_QUIRKS_H */
|
#endif /* __FU_QUIRKS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user