Commit Graph

399 Commits

Author SHA1 Message Date
Richard Hughes
52441f28a4 Allow objects to deserialize to XML
This makes a lot more sense; we can parse a firmware and export the same XML
we would use in a .builder.xml file. This allows us to two two things:

 * Check we can round trip from XML -> binary -> XML

 * Using a .builder.xml file we can check ->write() is endian safe
2021-03-15 12:07:30 +00:00
Richard Hughes
408b056984 trivial: Use fu_byte_array_append_bytes() in more places 2021-03-15 09:46:02 +00:00
Richard Hughes
1ad1458caf dfu: Allow setting the DFU version
The 'version' shadows the variable of the same name in the FuFirmware subclass.
2021-03-15 09:46:02 +00:00
Richard Hughes
664226a350 spi: Move all the IFD parsing to the new 'spi' plugin
We do not want to export this unfinished API, and it's probably best just to
not compile it by default until it is actually useful.
2021-03-15 09:45:17 +00:00
Richard Hughes
1c0ed3ab1d srec: Detect overflow to avoid adding ~4GB of 0xFF padding
Fixes https://oss-fuzz.com/testcase-detail/5468114109202432
2021-03-14 09:50:39 +00:00
Richard Hughes
752c8de149 trivial: Fix up gtk-doc comment for fu_firmware_set_size() 2021-03-13 16:23:26 +00:00
Richard Hughes
d2cdfcdb95 trivial: Fix up gtk-doc for fu_firmware_parse() 2021-03-13 16:09:35 +00:00
Richard Hughes
d27bfc08fd srec: Fix a fuzzing failure when trying to build zero sized firmware 2021-03-11 15:48:02 +00:00
Richard Hughes
88969d10c4 srec: Actually include the address in the written data 2021-03-11 15:48:02 +00:00
Richard Hughes
74db340d93 trivial: Add fu_byte_array_align_up() for future usage 2021-03-11 15:47:13 +00:00
Richard Hughes
8f63180ed0 trivial: Add fu_firmware_get_size()
The idea here is to return the size of the firmware, including the header,
footer or other encapsulation. It would be expected that this value would
include the alignment if provided.
2021-03-11 10:23:26 +00:00
Richard Hughes
7c0560c37f srec: Add support for writing firmware 2021-03-10 21:39:01 -06:00
Richard Hughes
db38dca4c8 trivial: Only print the FuFirmware version once... 2021-03-10 19:21:39 +00:00
Richard Hughes
58d52ede18 trivial: Add fu_common_align_up() for future usage 2021-03-10 17:06:57 +00:00
Richard Hughes
55853e3f2d trivial: Add fu_firmware_get_alignment()
I need this from two different FuFirmware superclasses, and I think it makes
sense in the base object.
2021-03-10 16:13:39 +00:00
Richard Hughes
e9664e8448 trivial: Add fu_byte_array_append_bytes() helper 2021-03-10 14:01:11 +00: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
2d84386034 Remove unused, unsafe and deprecated functions from libfwupdplugin
Keeping *internal* API and ABI compatibility makes working with an already
complex codebase more mentally demanding than it needs to be.

Remember: plugins should be in-tree and upstream! If your out of tree plugin
stops working then it should be upstream.

The public-facing libfwupd will remain API and ABI stable for obvious reasons.
2021-03-09 15:47:56 +00:00
Richard Hughes
aaf74006da trivial: Fix up the Since tags for FuIfd
This was not included in the 1_5_X branch.
2021-03-09 15:35:29 +00:00
Richard Hughes
f2849d24cc Add missing uint64 read and write helpers 2021-03-05 19:34:54 +00:00
Richard Hughes
a76a0da7aa Add fu_device_set_battery_level()
We want to make it as easy as possible for devices to refuse to update on low
battery, as this will likely be one of the WWCB requirements.

Ideally devices will check the battery level inside the firmware, but by also
providing the battery level to fwupd we can give the user a warning *before*
the update has started and without switching the device into bootloader mode.
2021-03-05 12:27:10 +00:00
Richard Hughes
e19ebe7177 Add an Intel Flash Descriptor parser 2021-03-05 10:51:34 +00:00
Richard Hughes
32ffdb2677 Add helper API to write in a safer way 2021-03-05 09:34:18 +00:00
Richard Hughes
bf3732f994 pixart: Use the bluetooth UUID to set the logical ID
This means you can have more than one device attached to the same controller.
2021-03-03 15:36:42 +00:00
Richard Hughes
2ad99bb402 Relax fu_common_bytes_pad() to return the blob if longer than the pad size
This means the caller does not have to do this each time.
2021-03-03 14:29:29 +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
Mario Limonciello
3df7dd3708 libfwupdplugin: don't allow device updates while needing activation 2021-03-03 07:32:35 +00:00
Richard Hughes
6122034a19 Show a warning when parsing invalid quirk files
I just wasted more than two hours of my life over `DeviceID`.
2021-03-02 06:31:55 +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
Ricardo Cañuelo
3ed91d52a4 Support for GATT characteristic signals/notifications
NOTE that currently this is implemented for GATT characteristics only,
but can be extended to other types of objects.

Listening for property changes in a bluez characteristic requires a
long-lived connection or proxy, so this also refactors bluez device
UUIDs into a simple object that keeps the path, the proxy and the signal
id in case a callback is registered for this UUID.

An additional advantage of this is that fwupd no longer creates a
throwaway proxy object for every read and write UUID operation.
2021-02-26 18:19:06 +01:00
Richard Hughes
0b6c67a3e3 trivial: Set the GError when calling ioctl() on an un-opened device
I've not yet worked out the real bug, but it was unexpected to crash the daemon
when open failed, rather than for a critical misuse of the API.
2021-02-25 16:21:56 +00:00
Richard Hughes
14c0f7c80e trivial: Fix the debug output for FuDevice 2021-02-25 15:47:25 +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
253e6e4f17 Add a backend ID to the device
This is typically a Linux sysfs path or USB platform ID and is used in a
different way to the physical ID. The physical ID is only set for some devices
after setup() and depends on the subsystem list, and this would not be defined
for devices that do not match a plugin.

This also fixes an regression where the FuDeviceList fails to match the new
FuUdevDevice device in fu_device_list_get_by_guids_removed() and instead
silently gets 'fixed up' only if FWUPD_DEVICE_FLAG_NO_GUID_MATCHING is not set.

This also allows us to move the various backends device caches to FuBackend as
we now have a suitable ID that is for just the backend to use.
2021-02-24 16:49:42 +00:00
Richard Hughes
53de7e25a4 trivial: Only allow verify-update for plugins that support _CAN_VERIFY
If the user explicitly specifies the device-id then we do not do the front-end
filtering. If the device detaches without being able to attach then the hardware
could be left in the bootloader state.

See https://github.com/fwupd/fwupd/issues/2926#issuecomment-784234180
2021-02-23 14:48:00 +00:00
Ricardo Cañuelo
01e87896f5 Fix GVariant declarations in fu_bluez_device_write
References to opt_variant and val_variant are sunk in a subsequent
variant creation and consumed by g_dbus_proxy_call_sync. They don't need
to be freed in this context.
2021-02-23 15:35:52 +01:00
Richard Hughes
61e4ff7684 trivial: Fix up two gtk-doc typos 2021-02-23 10:21:52 +00:00
Richard Hughes
edac3d7d3f trivial: Fix spelling of BlueZ in various places 2021-02-23 10:21:52 +00:00
Richard Hughes
ed0af24406 trivial: Use fwupd_device_remove_flag() to remove a single flag 2021-02-22 22:48:56 +00:00
Richard Hughes
a76de3279b Add a test BLE plugin for a demo 2021-02-22 16:53:41 +01:00
Ricardo Cañuelo
536fb85e21 Add initial support for Bluez bluetooth devices
Bare skeleton for what will be the Bluez backend and the base bluetooth
device class.
2021-02-22 16:53:41 +01:00
Richard Hughes
ad3cfc0fea Convert MBR types to GPT GUIDs to help find the ESP
Fixes https://github.com/fwupd/fwupd/issues/2916
2021-02-22 13:00:33 +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
86c6c2d4a3 Add fu_firmware_set_version_raw()
A few plugins need this now, so move it into the base class.
2021-02-16 15:24:29 +00:00
Ricardo Cañuelo
a92026476b Fix ioctl error checking
fu_udev_device_ioctl() interprets the return value of ioctl() as the
error cause and generates a misleading error message (permission
denied).
Fix it to use errno for error checking and reporting.
2021-02-15 16:39:00 +01:00
Richard Hughes
665c5feaca ihex: Never add more than 1 Intel hex signature
If you can create a 1Mb file with hundreds of thousands of zero-byte signatures
it takes a *long* time to parse the image.
2021-02-14 22:03:57 +00:00
Richard Hughes
ffbb1175d0 trivial: Do not consider all whitespace a valid strsafe string 2021-02-14 22:03:57 +00:00
Richard Hughes
a4e0de462c trivial: Fix AddressSanitizer heap-buffer-overflow 2021-02-14 22:03:57 +00:00
Richard Hughes
60a4b56802 srec: Fix an overflow causing an infinite loop when parsing 2021-02-12 20:51:39 +00:00