Commit Graph

18 Commits

Author SHA1 Message Date
Richard Hughes
4b1313b406 Split out the GByte helpers to a new source file 2022-06-14 14:36:52 -05:00
Richard Hughes
3047ed1517 dfu: Set the DfuDevice as a proxy to the DfuTarget
Set the alt_name_for_display as the target name and use the logical ID
as the target alt-name. This allows us to use the ->to_string() vfunc.
2022-05-12 08:38:18 +01:00
Richard Hughes
0b7af7d54b trivial: Ignore the return value of setenv() in most cases
This makes Coverity happy.
2022-04-13 15:08:12 +01:00
Richard Hughes
8b62bf6b64 Set the context in the right place more often 2022-03-16 09:18:29 +00:00
Richard Hughes
b5e7a0be16 Do not use gettext before calling setlocale 2022-02-09 16:56:47 +00:00
Richard Hughes
f885ab6d2a Allow patching firmware files at known offsets
This allows us to replace the 'dfu-tool replace' with a much more
controlled 'fwupdtool firmware-patch' command that patches at a set of
specific offsets.

Drop in the new functionality into the existing firmware ->write()
vfuncs so that the image headers, footers and/or checksums are correct.
2022-01-05 09:51:45 +00:00
Richard Hughes
e17a107ce1 trivial: Cast the g_signal_connect() object to allow static analysis
This is useful when using https://gitlab.freedesktop.org/tartan/tartan
2022-01-03 22:46:23 +00:00
Richard Hughes
da4f50ccf0 dfu: Fix replugging when using dfu-tool to flash hardware
All kinds of things break when using more than one GUsbContext at the
same time.
2021-11-12 15:27:01 +00:00
Richard Hughes
f9cba32625 dfu: Fix critical warning when using dfu-tool
Actually connect to the correct object.

Fixes https://github.com/fwupd/fwupd/issues/3975
2021-11-12 15:27:01 +00: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
Mario Limonciello
73cdf067ed trivial: fixup includes for a variety of plugins 2021-06-14 10:12:45 +01: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
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
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