Commit Graph

172 Commits

Author SHA1 Message Date
Richard Hughes
196dbec5ae trivial: Add fu_security_attrs_append_internal() for future code 2021-10-29 13:11:21 +01:00
Jason Gerecke
835975d66c trivial: Add "full" CRC8 function
The CRC32 and CRC16 algorithms have "full" functions that allow callers to
provide their own polynomial and initial CRC value. Provide the same ability
to users of the CRC8 algorithm.
2021-10-26 18:15:23 +01:00
Richard Hughes
6235a8222a Share the Common Flash Memory Interface quirks between plugins
Now two plugins are using hardcoded SPI constants for various CFI chips,
and it makes sense to have some common quirk data that can be used by
both.

Add a FuSpiChip helper object that can be used by FuDevice subclasses
to get the specific SPI commands to use for each flash ID.
2021-10-20 12:19:39 +01:00
Richard Hughes
15bf534e3f Set the verfmt of the returned device when the daemon device is unset
This regressed in 1.5.5 when we migrated FWUPD_DEVICE_FLAG_MD_SET_VERFMT
into FU_DEVICE_INTERNAL_FLAG_MD_SET_VERFMT and forgot to copy the system
device internal flags.
2021-10-18 06:57:09 +01:00
Richard Hughes
bd43647554 Add fu_usb_device_new_with_context() helpers
This means the context is set at construction time, which is much less
fragile than setting the context manually.
2021-10-15 15:59:34 +01:00
Richard Hughes
dbf92be359 trivial: Add fu_device_add_string() for future use 2021-10-14 15:49:58 +01:00
Richard Hughes
d3706e0e0b Show the user a warning if updating may affect full-disk-encryption
Additionally, if the client does not set the feature flag `fde-warning`,
add an extra paragraph into the update description.

Fixes https://github.com/fwupd/fwupd/issues/3829
2021-10-09 08:09:38 +01:00
Richard Hughes
20a1b12afe trivial: Ensure paths in /var exist before starting the daemon
On an immutable system these might have been factory reset to empty.
2021-10-08 17:22:24 +01:00
Richard Hughes
35fff9684e trivial: Export the CFU enum conversion functions
We need these in the CFU plugin too.
2021-09-25 21:16:18 +01:00
Richard Hughes
450e8e1c17 Add FuCfuPayload and FuCfuOffer
We can use these in the future elantp plugin, and I'm sure we'll need
them again in the future for an *actual* CFU plugin.
2021-09-20 14:43:34 +01: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
3162c8540d Add new API for splitting an untrusted string
Using fu_common_strnsplit() has the drawback that a malicious user (or
a fuzzer!) could create a file with 5,000,000 newlines, and then pass
that into any parser that tokenizes into lines. This causes millions of
tiny allocations and quickly dirties hundreds of megabytes of RSS due
to heap overheads.

Rather than splitting a huge array and then processing each line, set
up a callback to process each line and only allocate the next string if
the token was parsed correctly. This means that we don't even dup the
buffer before we start parsing, rather than allocating everything and
then failing at the first hurdle.

Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38696
2021-09-17 14:46:45 +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
Richard Hughes
33a24c77b7 trivial: Add fu_plugin_set_config_value() for future usage 2021-09-07 17:25:37 +01:00
Richard Hughes
09770c60f0 trivial: Fork for 1_6_X 2021-08-09 09:24:03 +01:00
Richard Hughes
f42b44e427 Remove some deprecated API 2021-08-06 19:49:53 +01:00
Richard Hughes
a5a978b3f6 Rename some confusing API
More than one person has asked about 'why call fu_plugin_update() for a
reinstall or downgrade' and I didn't have a very good answer.

The plugin API is not officially stable, and we should fix things to be
less confusing. Use the same verbs as the FuDevice vfuncs instead.
2021-08-06 19:49:53 +01:00
Richard Hughes
0efa97229a Automatically clear the update error as required
This is less fragile than patching all the callers.
2021-07-23 13:16:47 +01:00
Peter Marheine
464425fb5c SMBIOS: try reading from /sys/class/dmi if direct access fails
The raw SMBIOS tables that Linux exposes in /sys/firmware/dmi
are restricted to being readable by root only. If running as
non-root access is still permitted by fields that have been
pre-parsed by the kernel in /sys/class/dmi, most of which are
world-readable. This allows the daemon to load most HWIDs even
if running as a non-root user, as is done on Chromium OS.
2021-07-23 09:46:45 +01:00
Richard Hughes
55f6fd435a Add a ->get_results() vfunc that can be used by subclasses of FuDevice 2021-07-22 12:47:54 +01:00
Richard Hughes
15b668c0c6 Open the device proxy in the engine where required
The benefit of using the proxy device is that we can 'use' the proxy
device for device access, but 'report' the progress on the passed
FuDevice instance.

This means the front-end reports the device status correctly when
updating composite devices that us proxies.

The comment always said we should move it to the daemon if another
plugin started doing this, and that is now.
2021-07-17 17:20:01 +01:00
Richard Hughes
19abf996c7 Allow the daemon to request interactive action from the end user
The "return error and hope the client resubmits the firmware again"
pattern is clunky. There are two plugins doing this now, and about to
be one more.

This adds FwupdRequest which provides a structured way of asking the
user to perform an action, e.g. to replug the device or to press a
special key or button.

This replaces much of the UpdateMessage and UpdateImage API although
it is still used internally. Clients capable of processing the new
DeviceRequest signal should add REQUESTS to their feature flags.

Also, this allows us go back to the old meaning of _NEEDS_BOOTLOADER,
which was "needs rebooting into a bootloader mode" rather than the
slightly weird "user needs to do something and resubmit request".
2021-07-14 17:03:50 +01:00
Ivan Mikhanchuk
5e04fae8f2 Add functions to read from and write to FU_PATH_KIND_FIRMWARE_SEARCH 2021-07-13 21:57:08 +01:00
Richard Hughes
d938ab62e6 trivial: Add fu_device_add_guid_full() to control behaviour 2021-07-12 19:01:55 +01:00
Richard Hughes
9c31d1fadd trivial: Set the FuContext on more devices 2021-07-12 19:01:55 +01:00
Richard Hughes
488f2e1f37 Export the EFI and IFD parsers
We'll need to use this from another plugin soon.
2021-07-12 10:33:38 +01:00
Richard Hughes
dfaae2e837 Move amdgpu safety check into the plugin
There are now multiple plugins using drm_dp_aux_dev interface which
may potentially be combined with an amdgpu. Prevent exercising this
interface with any plugin using DP aux unless a new enough kernel is
installed.
2021-07-04 17:49:36 +01:00
Richard Hughes
974d63851d Allow calculating the CRC-16 with the CCITT polynomial 2021-07-03 13:49:50 +01:00
Richard Hughes
7b209bb2c1 Watch for children added or removed after setup has been completed
Some devices may 'discover' child devices during poll, rather than the
more usual case of adding them as children during setup.
2021-07-02 13:27:10 +01:00
Richard Hughes
1cee26eba9 Remove the vendor string from the device name where required
This means we don't display something like 'Logitech Logitech Product'
when showing the devices on one line.

This is now required in two plugins so move it to common code. Also
support setting the properties in either order to prevent regressions
when using the device name as part of the instance ID.
2021-06-30 18:43:07 +01:00
Peter Marheine
6281467a6b Add a fu_udev_device_get_children_with_subsystem function
This works like fu_udev_device_get_siblings_with_subsystem but returns child
devices of self rather than siblings.
2021-06-28 10:09:52 +01:00
Richard Hughes
9a2e10c639 trivial: Export the matching fu_udev_device_set_dev() 2021-06-24 14:22:08 +01:00
Richard Hughes
8ae988dda8 Allow writing multiple bytes to the I²C device 2021-06-24 14:22:08 +01:00
Richard Hughes
e2f51539b9 trivial: Add the missing fu_i2c_device_set_bus_number() function 2021-06-24 14:22:08 +01: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
fe7b0794b3 Use the parent physical ID to autoset the device parent
Of course, this only works if the parent and child both export a
FuDevice of the same physical kind, e.g. USB.
2021-06-19 16:57:35 +01:00
Mario Limonciello
3a48af58c2 trivial: move kernel version check into common library code
This will be used by more than one plugin in an upcoming commit.
2021-06-16 14:54:17 -05:00
Richard Hughes
694e774c2a uefi-capsule: Make less Linux-specific
Based on patches by Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 19:54:12 +01:00
Richard Hughes
dfb46d9b56 trivial: Add fu_backend_get_devices() for future use 2021-05-25 17:17:45 +01:00
Richard Hughes
76602389ff Export FuBackend into libfwupdplugin for future use 2021-05-25 17:17:45 +01:00
Richard Hughes
79bbcd792a Store the BSD kernel cmdline string in the failure report
Also split out a kenv helper into common code.
2021-05-25 06:31:46 +01:00
Richard Hughes
99f40fa7a7 Add a FuI2cDevice to abstract I²C devices 2021-05-18 14:29:28 +01:00
Richard Hughes
8fe6a1dd0c trivial: Make FuSrecFirmwareRecord usable from non-C languages 2021-05-11 13:15:27 +01:00
Richard Hughes
c77b4f03a2 Check the versions of libfwupd and libfwupdplugin at startup
This prevents super-hard-to-debug crashes like we saw in #3197 where the user
was mixing PPAs and official versions.
2021-04-30 15:00:04 +01:00
Richard Hughes
e65d28d817 Add a utility to resign firmware files
This can be used like this:

    fwupdtool firmware-sign firmware.cab rhughes_signed.pem rhughes.key

Test signing certificates can be generated using the example script here:
https://github.com/hughsie/libjcat/blob/master/contrib/build-certs.py although
these certificates should not be used for enterprise use.
2021-04-19 12:59:35 +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
Peter Marheine
da9a07ba8f FuUdevDevice: add get_siblings_with_subsystem function
This function returns a list of sibling devices that have a chosen subsystem,
allowing callers to perform a limited walk of the device tree to locate related
devices.
2021-04-15 06:53:06 +01:00
Richard Hughes
be1d77bc7c Add fu_ihex_firmware_set_padding_value() for the analogix plugin 2021-04-12 09:55:44 +01:00
Richard Hughes
7f6f525f21 Add fu_bytes_get_data_safe() to check for zero sized data
Fixes https://github.com/fwupd/fwupd/issues/3122
2021-04-10 13:20:07 +01:00
Richard Hughes
4d76d18d35 Set the system battery state and level on the FuContext shared state
This allows plugins to set the battery power state of the *machine* which means
we can automatically inhibit devices with FWUPD_DEVICE_FLAG_REQUIRE_AC set.

It also allows to set the BatteryThreshold to 25% for Lenovo hardware, and we
can override other vendors with further quirks as required.

Fixes https://github.com/fwupd/fwupd/issues/3084
2021-04-07 08:05:15 +01:00