Commit Graph

110 Commits

Author SHA1 Message Date
Richard Hughes
f3ec632492 trivial: Add some new helper API for future functionality 2022-04-26 14:30:28 +01:00
Richard Hughes
f042bbd42c Add fu_common_reverse_uint8() for future functionality 2022-03-31 16:34:27 +01:00
Richard Hughes
e8f0d76da7 Do not leak child processes when cancelling
See https://github.com/fwupd/fwupd/pull/4372
2022-03-15 14:01:45 +00:00
Richard Hughes
308e03a6f4 Sanitize the instance ID parts more carefully
The only users of `SERIO\FWID` and `I2C\NAME` are already 'safe' and
the device GUIDs should all be unchanged.

There are no current users of the `MTD\NAME` instance IDs, and these
are the ones that may be more unpredictable and in need of sanity.
2022-02-18 08:23:39 +00:00
Richard Hughes
38bab8fc4f Allow overriding daemon parameters using /var/etc/fwupd/daemon.conf
This is super useful for debugging immutable systems like ChromeOS.
2022-01-21 11:52:06 +00:00
Richard Hughes
1c62194dd3 trivial: Fix fu_common_dump_full() header when specifying both flags 2022-01-04 22:06:33 +00:00
Richard Hughes
7e640f81e5 trivial: Fix build warnings when compiling on Windows 2021-12-30 15:18:22 +00:00
Richard Hughes
f76880182f Do not allow UEFI updates when the lid is closed
Most vendors do not mirror the firmware update to an external display,
and some don't behave correctly when the lid is shut and the machine is
docked. Add this quirk just for Lenovo for now.

Fixes https://github.com/fwupd/firmware-lenovo/issues/181
2021-12-29 19:18:26 +00:00
Richard Hughes
60d266cbc6 Add support for UF2 devices
A UF2 device exposes a VFAT block device (sometimes called a Mass
Storage Device) which has a virtual file called `INFO_UF2.TXT` where
metadata can be read. It may also have a the current firmware exported
as a file called `CURRENT.UF2` which is in a 512 byte-block UF2 format.

Writing any file to the MSD will cause the firmware to be written.
Sometimes the device will restart and the volume will be unmounted
and then mounted again. In some cases the volume may not “come back”
until the user manually puts the device back in programming mode.

Match the block devices using the VID*PID, UUID or label, and then
create a UF2 device which can be used to flash firmware.

Note: We only read metadata from allow-listed IDs to avoid causing
regressions on non-UF2 volumes. To get the UUID and label you can
use commands like:

    udisksctl info -b /dev/sda1
2021-12-21 10:06:18 +00:00
Richard Hughes
bcf000d7cc Add fu_common_get_contents_stream() for future usage 2021-12-15 14:24:30 +00:00
Richard Hughes
52fd89f9ab Add fu_memmem_safe() with fallback code for win32 2021-12-15 12:57:49 +00:00
Mario Limonciello
0b56a58b65 trivial: win32: fix subprocess call
```
19:22:39:0430 FuCommon             running 'curl.exe https://cdn.fwupd.org/downloads/firmware.xml.gz.jcat --output C:\Users\mlimonci\AppData\Local\Microsoft\Windows\INetCache\fwupd\firmware.xml.gz.jcat --cacert C:\Program Files (x86)\fwupd\bin\..\bin\ca-bundle.crt'
19:22:39:0515 GLib-GObject         invalid cast from 'GWin32InputStream' to 'GPollableInputStream'
19:22:39:0515 GLib-GIO             g_pollable_input_stream_create_source: assertion 'G_IS_POLLABLE_INPUT_STREAM (stream)' failed
19:22:39:0516 GLib                 g_source_attach: assertion 'source != NULL' failed
19:22:39:0516 GLib                 g_source_set_callback: assertion 'source != NULL' failed
```
2021-12-15 06:46:27 -06:00
Mario Limonciello
12bdc7d3ad trivial: win32: discover the running directory
This should allow launching fwupdtool.exe from anywhere outside
of PATH
2021-12-15 06:46:27 -06:00
Mario Limonciello
4960ae34ba trivial: win32: discover user's profile directory
For anything that is normally in /var on Linux, write it
here so that users don't need admin rights.
2021-12-15 06:46:27 -06:00
Richard Hughes
58d36dcbe5 Check the value range when parsing the quirk keys
At the moment there isn't an error if you enter something like

    CfiDeviceCmdReadId = 0×12
2021-12-09 13:09:43 +00:00
Richard Hughes
3ffc3fa774 Add fu_common_sum8() common functionality
We now have 9 different plugins all using this functionality, and we're
about to add one more. Move this into common code so that all the
plugins are using the same endian and bufsz-safe versions.
2021-11-26 18:33:11 +03:00
Richard Hughes
0d64780093 trivial: Fix a small memory leak when getting volumes 2021-10-27 15:57:53 +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
357d7ff396 trivial: Fix up a docgen comment typo 2021-10-09 16:22:35 +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
3f82205062 Support loading remotes from /var/lib/fwupd/remotes.d
This allows us to add remotes on /etc immutable systems.
2021-10-08 17:22:24 +01:00
Richard Hughes
1669f532be trivial: Move the metadata directory
This moves the cached metadata location from /var/lib/fwupd/remotes.d
to /var/lib/fwupd/metadata

The former was a bad name as it wasn't a list of remotes, and .d is the
suffix for directories the user can install files into, rather than for
binary content managed entirely by the daemon.
2021-10-08 17:22:24 +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
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
d4fb04d6fc Allow overriding the quirks directory at runtime 2021-09-03 21:14:37 +01:00
Mario Limonciello
55de39c077 trivial: reformat the whole tree to match new format 2021-08-24 11:18:40 -05: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
Mario Limonciello
da895169a7 Add a new path for configuring runtime firmware load path
The kernel allows configuring this, and certain plugins will use this
path to be able to load firmware in the kernel driver through runtime,
but to flash to the device.
2021-07-13 21:57:08 +01:00
Richard Hughes
974d63851d Allow calculating the CRC-16 with the CCITT polynomial 2021-07-03 13:49:50 +01:00
Mario Limonciello
d20a95458d libfwupdplugin: add support for firmware-attributes 2021-06-25 08:12:58 -05:00
Crag Wang
5a384a3f02 trivial: fix for expr check introduced in 3a48af58 2021-06-17 09:17:43 +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
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
4c734c797a trivial: Remove some more _WIN32 defines now we have an OS split 2021-06-07 19:54:12 +01:00
Sergii Dmytruk
080129fc43 Handle bsdisks' UDisks2 implementation on FreeBSD
There is no Manager object, so block devices must be discovered
manually.

Additionally, Type field contains FS name rather than its MBR ID in
hex form or a GPT GUID.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2021-06-07 19:54:12 +01:00
Richard Hughes
d783594ea5 Make fu_common_convert_to_gpt_type() FreeBSD compatible
Based on a patch by Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 19:54:12 +01:00
Sergii Dmytruk
1e5aec4eb1 Correct error msg in fu_common_get_block_devices
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 11:19:30 +01:00
Sergii Dmytruk
8d5784192f Fix formatting in fu_common_get_block_devices ()
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 11:19:17 +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
8792afa894 trivial: Fixup some documentation to use the correct type 2021-05-17 09:27:54 +01:00
Richard Hughes
dbd57ebc43 trivial: Always include the newline for fu_common_string_append_kv() 2021-05-11 21:01:33 +01:00
Richard Hughes
20ef071b3c trivial: Style fixes to lots of gtk-doc 2021-05-10 14:35:10 +01:00
Daniel Campello
a4fbe2a6f4 Switch lock directory from /var/run to /run/lock
This allows for proper locking between executions of fwupdtool in
Chromium OS minijail environment. It is needed after commit
9cf5f8f7ff was introduced.

Change-Id: I37b33c8d1fbe97ec9baddc5f77ea94e2f4ff1fa4
2021-05-05 13:34:49 -06: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
1ac05ef3bd trivial: Codespell fixes 2021-04-26 10:29:39 +01:00
Richard Hughes
d42bd85059 trivial: Do not use the deprecated allow-none introspection argument
It's been deprecated since 2014... oops.

https://blogs.gnome.org/desrt/2014/05/27/allow-none-is-dead-long-live-nullable/
2021-04-19 14:46:42 +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
Richard Hughes
9c318a5a08 trivial: Fix 32 bit overflow in fu_common_get_memory_size()
Spotted by Coverity, thanks!
2021-03-20 17:32:56 +00:00
Norbert Kamiński
76e19930a8 fwupd port for BSD distros
Signed-off-by: Norbert Kamiński <norbert.kaminski@3mdeb.com>
2021-03-19 17:05:09 +00:00