Commit Graph

321 Commits

Author SHA1 Message Date
Richard Hughes
2d00cda464 Remove PLUGINBUILDDIR and use G_TEST_SRCDIR and G_TEST_BUILDDIR instead
This allows us to override the location we load data files from, which
allows us to do more kinds of installed tests in the future.

Also, move the global data/tests content into the place that it is used
as it was getting impossible to manage.
2021-10-21 18:36:22 +01:00
Richard Hughes
478e44bc19 trivial: Do not use g_assert() in self test code
Note that g_assert() should not be used in unit tests, since it is a
no-op when compiling with G_DISABLE_ASSERT. Use g_assert() in production
code, and g_assert_true() in unit tests.

See https://github.com/fwupd/fwupd/issues/3790
2021-09-24 22:20:21 +01:00
Richard Hughes
431dbee65a Lower the GUsb dep to allow compiling on RHEL-8
This is something that I keep being asked to do...
2021-09-24 06:50:59 -05:00
Richard Hughes
1ff96eb4b3 Restore the ABI for fu_device_detach() and provide new symbols
Quite a few plugins are using a FuDeviceLocker to detach then attach in
the error path, and finding them isn't easy as we explicitly cast to a
FuDeviceLockerFunc.

For sanity, just provide both symbols so we can do the right thing in
both cases. It seems like a sensible thing to allow.

Fixes https://github.com/fwupd/fwupd/issues/3771
2021-09-17 16:35:21 +01:00
Richard Hughes
40cd18fa97 Allow using a per-device global percentage completion
It's actually quite hard to build a front-end for fwupd at the moment
as you're never sure when the progress bar is going to zip back to 0%
and start all over again. Some plugins go 0..100% for write, others
go 0..100% for erase, then again for write, then *again* for verify.

By creating a helper object we can easily split up the progress of the
specific task, e.g. write_firmware().

We can encode at the plugin level "the erase takes 50% of the time, the
write takes 40% and the read takes 10%". This means we can have a
progressbar which goes up just once at a consistent speed.
2021-09-13 14:28:15 +01:00
Mario Limonciello
55de39c077 trivial: reformat the whole tree to match new format 2021-08-24 11:18:40 -05:00
Richard Hughes
6a8f285ee2 Check the quirk format as part of precommit 2021-08-23 18:10:12 +01:00
Jing-Jie Zhou
8b477ed5e8 modified. DeviceInstanceId is deprecated! 2021-08-23 06:50:28 -05:00
Jierger Zhou
3fbdbd64aa dfu: add quirks for AVer ATLAS CAM/CAM520 Pro2 2021-08-23 06:50:28 -05:00
Jerry Zhang
dfc0254683 dfu: Introduct a quirk to allow zero polltimeout in dfuDNLOAD.
Some Poly usb devices report zero in the bwPollTimeout field of
GET_STATUS request. The host can issue the next DFU_DNLOAD
request immediately without any delay.

Introduced a private flag to skip the default DNLOAD timeout
(5ms) fix. It could remarkably reduce the firmware downloading
time taking into account the large firmware (more than 500MB).
2021-08-16 10:01:27 -05:00
Jerry Zhang
0776918dd8 dfu: Add support for Poly Studio P21 usb device
Specify the Flags in dfu.qurik for Poly Studio P21's camera.
2021-08-04 17:27:11 +01:00
Jerry Zhang
bb5bae8c17 dfu: Add support for more Poly usb devices
Specify the Flags in dfu.qurik for Poly Studio R30, P5 and E70.
2021-07-28 18:46:53 +01:00
Mario Limonciello
798d1ed3ee trivial: update markdown for pre-commit style 2021-07-18 14:42:47 -05:00
Richard Hughes
aaa77c6f51 Allow adding and removing custom flags on devices
The CustomFlags feature is a bit of a hack where we just join the flags
and store in the device metadata section as a string. This makes it
inefficient to check if just one flag exists as we have to split the
string to a temporary array each time.

Rather than adding to the hack by splitting, appending (if not exists)
then joining again, store the flags in the plugin privdata directly.

This allows us to support negating custom properties (e.g. ~hint) and
also allows quirks to append custom values without duplicating them on
each GUID match, e.g.

[USB\VID_17EF&PID_307F]
Plugin = customflag1
[USB\VID_17EF&PID_307F&HUB_0002]
Flags = customflag2

...would result in customflag1,customflag2 which is the same as you'd
get from an enumerated device flag doing the same thing.
2021-06-23 07:59:15 +01:00
Richard Hughes
2360aa296a Use an internal device flag rather that using a custom flag
If this is shared between plugins it needs to be specified in a shared
place.
2021-06-21 19:38:00 +01:00
Mario Limonciello
1e06c12e99 trivial: ci: Check for inclusion of private headers during pre-commit
This will improve the pre-commit hook coverage.

For dfu: waive pre-commit checks for internal header file
This is internal to the plugin not to the library.
2021-06-16 08:32:29 -05:00
Richard Hughes
2dd6462c0c trivial: Export the DFU version constants into libfwupdplugin 2021-06-14 07:15:42 -05:00
Mario Limonciello
73cdf067ed trivial: fixup includes for a variety of plugins 2021-06-14 10:12:45 +01:00
Mario Limonciello
64fc650f11 trivial: dfu: depend on plugin_deps rather than hardcoding libraries 2021-06-14 09:25:24 +01:00
Mario Limonciello
1e17457b16 Allow building the documentation with gi-docgen and gtk-doc
Until gi-docgen is declared stable support either of them.
This effectively means that hand builds and CI builds will use
gi-docgen, but distro builds use gtk-doc-tools.
2021-06-09 22:21:53 +01:00
Richard Hughes
20ef071b3c trivial: Style fixes to lots of gtk-doc 2021-05-10 14:35:10 +01:00
Richard Hughes
89d45a0d91 trivial: Standardize on introspection for @error and @cancellable
Also standarize on `Returns:` for the result.
2021-04-28 16:19:50 +01:00
Richard Hughes
5ad6fb2a27 dfu: Do not show an invalid warning on attach
For some hardware, it is quite expected the device just resets.
2021-04-26 19:38:13 +01:00
Richard Hughes
0a37abfce8 dfu: Do not require wildcard-pid when flashing a raw binary file 2021-04-26 19:38:13 +01:00
Richard Hughes
584f1d4c6a dfu: Fall back to binary files when flashing stm32 hardware 2021-04-26 19:38:13 +01:00
Richard Hughes
4fe318bd54 dfu: Fix up some overzealous replacement when renaming the DFU files 2021-04-23 13:59:44 -05:00
Dirk-Jan C. Binnema
cd474377d5 fu_dfu_tool_get_default_device: Avoid use-after-free
fu_dfu_tool_get_default_device returns a newly create FuDfuDevice
'device'; but since it is marked as g_autoptr, it is destroyed when
leaving the scope and the caller receives garbage.

So steal the pointer before leaving the scope.

,----
| ==697985== Invalid read of size 8
| ==697985==    at 0x4B50F49: g_type_check_instance_is_fundamentally_a (gtype.c:4080)
| ==697985==    by 0x4B3A988: g_object_unref (gobject.c:3421)
| ==697985==    by 0x406CF3: glib_autoptr_clear_GObject (gobject-autocleanups.h:27)
| ==697985==    by 0x406DD5: glib_autoptr_clear_FwupdDevice (gusb-autocleanups.h:17)
| ==697985==    by 0x406E9C: glib_autoptr_clear_FuDevice (fu-device.h:18)
| ==697985==    by 0x406EE3: glib_autoptr_clear_FuUsbDevice (fu-usb-device.h:22)
| ==697985==    by 0x406F6A: glib_autoptr_clear_FuDfuDevice (fu-dfu-device.h:19)
| ==697985==    by 0x406F88: glib_autoptr_cleanup_FuDfuDevice (fu-dfu-device.h:19)
| ==697985==    by 0x40898D: fu_dfu_tool_read (fu-dfu-tool.c:577)
| ==697985==    by 0x407518: fu_dfu_tool_run (fu-dfu-tool.c:162)
| ==697985==    by 0x4097E0: main (fu-dfu-tool.c:959)
| ==697985==  Address 0x67fbfe0 is 640 bytes inside a block of size 672 free'd
| ==697985==    at 0x48430E4: free (vg_replace_malloc.c:755)
| ==697985==    by 0x4BD124C: g_free (gmem.c:199)
| ==697985==    by 0x4BEB76F: g_slice_free1 (gslice.c:1180)
| ==697985==    by 0x4B4FDBB: g_type_free_instance (gtype.c:1993)
| ==697985==    by 0x406CF3: glib_autoptr_clear_GObject (gobject-autocleanups.h:27)
| ==697985==    by 0x406DD5: glib_autoptr_clear_FwupdDevice (gusb-autocleanups.h:17)
| ==697985==    by 0x406E9C: glib_autoptr_clear_FuDevice (fu-device.h:18)
| ==697985==    by 0x406EE3: glib_autoptr_clear_FuUsbDevice (fu-usb-device.h:22)
| ==697985==    by 0x406F6A: glib_autoptr_clear_FuDfuDevice (fu-dfu-device.h:19)
| ==697985==    by 0x406F88: glib_autoptr_cleanup_FuDfuDevice (fu-dfu-device.h:19)
| ==697985==    by 0x407762: fu_dfu_tool_get_default_device (fu-dfu-tool.c:191)
| ==697985==    by 0x408736: fu_dfu_tool_read (fu-dfu-tool.c:592)
| ==697985==  Block was alloc'd at
| ==697985==    at 0x484086F: malloc (vg_replace_malloc.c:380)
| ==697985==    by 0x4BD4938: g_malloc (gmem.c:106)
| ==697985==    by 0x4BEC1F4: g_slice_alloc (gslice.c:1069)
| ==697985==    by 0x4BEC85D: g_slice_alloc0 (gslice.c:1095)
| ==697985==    by 0x4B5511A: g_type_create_instance (gtype.c:1893)
| ==697985==    by 0x4B3CB8C: g_object_new_internal (gobject.c:1939)
| ==697985==    by 0x4B3E107: g_object_new_valist (gobject.c:2282)
| ==697985==    by 0x4B3E63C: g_object_new (gobject.c:1782)
| ==697985==    by 0x40B0CF: fu_dfu_device_new (fu-dfu-device.c:571)
| ==697985==    by 0x407723: fu_dfu_tool_get_default_device (fu-dfu-tool.c:230)
| ==697985==    by 0x408736: fu_dfu_tool_read (fu-dfu-tool.c:592)
| ==697985==    by 0x407518: fu_dfu_tool_run (fu-dfu-tool.c:162)
`----
2021-04-21 10:57:51 +01:00
Richard Hughes
faa35e430b Show a warning if the device has no GType and the plugin has no default
This also renames a symbol to make it clear that you can call it more than once.

Fixes https://github.com/fwupd/fwupd/issues/3148
2021-04-15 16:52:56 +01:00
Richard Hughes
c4bc709359 Do not use help2man to build manual pages
This prevents problems when cross compiling. Using help2man is now also of
limited use; if we can just tell the user to use --help we do not need to keep
the manual in sync.

It also allows us to drop the several other supporting files that we use when
the help2man output isn't actually that useful.

Fixes https://github.com/fwupd/fwupd/issues/3025
2021-04-11 13:42:04 +01:00
Mario Limonciello
9bca3bf53c trivial: correct docstring location for a few python files 2021-04-09 16:02:20 +01:00
Mario Limonciello
1f9c035788 trivial: fix some trailing whitespace problems across the project 2021-04-09 16:02:20 +01:00
Mario Limonciello
6d1afc3e87 trivial: reformat all python code with black 2021-04-08 10:43:29 -05:00
Dirk-Jan C. Binnema
79536a0265 dfu-tool: Avoid runtime warning (overriding error)
We were seeing:

,----
| (dfu-tool:1139827): GLib-WARNING **: 17:34:42.671: GError set over the top of a previous GError or uninitialized memory.
| This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
| The overwriting error message was: no device matches for 1234:abcd
`----

This is because we were attempting to overwrite libgusb's error with one
for fwupd, and glib rightfully complains. So let's prefix it instead.
2021-04-05 14:42:04 -05:00
Richard Hughes
b333e0045c Split out a shared system context
There is a lot of code in fwupd that just assigns a shared object type to
a FuPlugin, and then for each device on that plugin assigns that same shared
object to each FuDevice.

Rather than proxy several kinds of information stores over two different levels
of abstraction create a 'context' which contains the shared *system* state
between the daemon, the plugins and the daemon.

This will allow us to hold other per-machine state in the future, for instance
the system battery level or AC state.
2021-04-01 21:11:29 +01:00
Richard Hughes
1981c63d58 Remove FuFirmwareImage and just use FuFirmware instead
This allows us to 'nest' firmware formats, and removes a ton of duplication.

The aim here is to deprecate FuFirmwareImage -- it's almost always acting
as a 'child' FuFirmware instance, and even copies most of the vfuncs to allow
custom types. If I'm struggling to work out what should be a FuFirmware and
what should be a FuFirmwareImage then a plugin author has no hope.

For simple payloads we were adding bytes into an image and then the image into
a firmware. This gets really messy when most plugins are treating the FuFirmware
*as* the binary firmware file.

The GBytes saved in the FuFirmware would be considered the payload with the
aim of not using FuFirmwareImage in the single-image case.
2021-03-09 21:14:12 +00:00
Richard Hughes
c81b755872 Be more strict for custom quirk keys
Rather than trying to guess typos, force each plugin to register the quirk
keys it supports, so we can show a sensible warning if required at startup on
the console.
2021-03-03 08:30:34 +00:00
Richard Hughes
7d132b728c Simplify the quirk file format
The best way of not getting something wrong is to not require it in the first
place...

All plugins now use DeviceInstanceId-style quirk matches and we can just drop
the prefix in all files. We were treating HwId=, Guid= and DeviceInstanceId= in
exactly the same way -- they're just converted to GUIDs when building the silo!
2021-03-03 08:30:34 +00:00
Richard Hughes
54c683c009 dfu: Use DeviceInstanceIDs to merge AVR quirk metadata
This means we can use the standard ->set_quirk_kv() vfunc rather than using
FuQuirks directly with a custom group.
2021-03-03 08:30:34 +00:00
Richard Hughes
f6ee6043c5 dfu: Correctly erase STM32 devices when transfer size is less than sector size 2021-03-01 17:04:34 +00:00
Richard Hughes
f32e4c0666 dfu: Do not use a heuristic to set the device status
This breaks on all STM32 devices and should be unnecessary now.
2021-03-01 17:04:34 +00:00
Richard Hughes
aeba5f7f53 dfu: Fix writing to the GD32VF103 bootloader
Just set the alt_name rather than creating one giant sector and use the GD32
serial number for the sector map fixup.

See c2c8215061
2021-03-01 17:04:34 +00:00
Richard Hughes
b3f9841924 Support more than one protocol for a given device
Devices may want to support more than one protocol, and for some devices
(e.g. Unifying peripherals stuck in bootloader mode) you might not even be able
to query for the correct protocol anyway.
2021-03-01 16:14:36 +00:00
Richard Hughes
2a0766b523 dfu: Mark the GD32 sectors as erasable 2021-02-26 18:46:28 +00:00
Richard Hughes
416562f9af dfu: Do not show a critical error when flashing footer-less binary files 2021-02-26 18:46:28 +00:00
Richard Hughes
d271cebee5 trivial: Fix compile warning with newer libgusb versions 2021-02-26 16:44:31 +00:00
Richard Hughes
078beafb2d Add a new internal flag to opt-in to GUID matching
It is far too easy to forget to set FWUPD_DEVICE_FLAG_NO_GUID_MATCHING for new
plugins, and without it it all works really well *until* a user has two devices
of the same type installed at the same time and then one 'disappears' for hard
to explain reasons. Typically we only need it for replug anyway!

Explicitly opt-in to this rarely-required behaviour, with the default to just
use the physical and logical IDs. Also document the update behavior for each
plugin to explain why the flag is being used.

This allows you to have two identical Unifying plugged in without one of them
being hidden from the user, at the same time allowing a HIDRAW<->USB transition
when going to and from bootloader and runtime modes.

This removes the workaround added in 99eb3f06b6.

Fixes https://github.com/fwupd/fwupd/issues/2915
2021-02-25 15:47:25 +00:00
Richard Hughes
8aebd44404 dfu: Modernize the coding style to match the other plugings
Use a Fu prefix for source objects and files and use @self.

No logic changes.
2021-02-24 10:36:45 +00:00
Richard Hughes
2e1245728f Call the superclass directly from subclassed devices
This allows a device subclass to call the parent method after doing an initial
action, or even deliberately not call the *generic* parent method at all.

It also simplifies the plugins; you no longer have to remember what the plugin
is deriving from and accidentally clobber the wrong superclass method.
2021-02-18 16:18:34 +00:00
Richard Hughes
a22c13c637 Move the plugin build logic to the plugins themselves 2021-02-18 14:46:20 +00:00
Richard Hughes
87a8091bed trivial: Fix a crash using fu_firmware_image_get_chunks()
Add a GError as it can return NULL for invalid circumstances. It's okay to
change the API as this symbol has not yet been in a tarball release.
2021-02-11 13:13:06 +00:00