Commit Graph

61 Commits

Author SHA1 Message Date
Mario Limonciello
1d44dce78a trivial: remove some unused variables 2021-06-23 08:29:56 -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
Mario Limonciello
78b78d8edd trivial: update python black style to 21.6b0 2021-06-16 06:41:46 -05:00
Sergii Dmytruk
c0d0ce4e1a Switch from sysctl to ioctl for ESRT on FreeBSD
Initial version of the patch was rejected and rewritten.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-15 17:25:16 +01:00
Sergii Dmytruk
9c21e4e135 Depend on libefivar in uefi-capsule
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-15 17:25:16 +01:00
Mario Limonciello
73cdf067ed trivial: fixup includes for a variety of plugins 2021-06-14 10:12:45 +01: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
Sergii Dmytruk
4558e5f317 Fix two off-by-one errors in uefi-capsule plugin
Data is accessed at offset 0x13, so the code must abort if size is
0x13 when you can access only offsets 0x00 through 0x12.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 11:18:57 +01:00
Sergii Dmytruk
cac4f98420 Improve error message in fu-uefi-backend-freebsd
"not supported" doesn't explain much.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-06-07 11:18:41 +01:00
Richard Hughes
03726227b7 uefi-capsule: Add FreeBSD ESRT support
Based on a patch by Sergii Dmytruk <sergii.dmytruk@3mdeb.com>, many thanks.
2021-05-25 17:17:45 +01:00
Richard Hughes
6c07675558 uefi-capsule: Split out the Linux specific ESRT enumeration
This allows us to add the same functionality for FreeBSD and Windows.
2021-05-25 17:17:45 +01:00
Richard Hughes
1113a7aa11 trivial: Allow setting FuUefiDevice properties at construction 2021-05-25 17:17:45 +01:00
Sergii Dmytruk
1a328fd3ad Branch explicitly per OS type
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-05-18 06:49:47 +01:00
Sergii Dmytruk
3d0e624ed3 Include <efivar-dp.h> explicitly
On FreeBSD <efivar.h> doesn't include <efivar-dp.h>.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-05-18 06:49:47 +01:00
Sergii Dmytruk
113a91985b Handle missing defaults in fu-uefi-devpath.c
FreeBSD's libefivar native implementation doesn't provide these defines.

Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
2021-05-18 06:49:47 +01:00
Richard Hughes
769cbbf8af Add support for the PHAT table
On Alterlake and newer hardware the Platform Health Assessment Record
data can be used by the IHV to debug why a specific capsule update
failed. Any custom firmware loaded by the OEM can be identified and
used to further debug the root cause.
2021-05-12 12:02:33 +01:00
Richard Hughes
1ac05ef3bd trivial: Codespell fixes 2021-04-26 10:29:39 +01:00
Mario Limonciello
99832622e1 uefi-capsule: Move EFI binary into a subproject
This will allow distributions to package and distribute the unsigned
EFI binary separately, similar to what has been done for GRUB.
2021-04-23 13:59:10 -05:00
bubbleguuum
751edfab65 Fix /etc/os-release ID_LIKE field parsing
Parse ID_LIKE according to 'man os-release':
"A space-separated list of operating system identifiers in the same
syntax as the ID= setting"
2021-04-19 14:46:54 +01:00
Ross Burton
57961cddac Add option to disable the UEFI capsule splash screen generation
The dependencies to generate the "updating..." splash screen are non-trivial, and
pointless in headless systems.  Add an option to disable the generation entirely.
2021-04-13 12:31:17 +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
1f9c035788 trivial: fix some trailing whitespace problems across the project 2021-04-09 16:02:20 +01:00
Richard Hughes
13524af202 Write BMP data directly without using PIL
This allows us to drop a build-time dep.
2021-04-09 15:59:51 +01:00
Mario Limonciello
6d1afc3e87 trivial: reformat all python code with black 2021-04-08 10:43:29 -05:00
Javier Martinez Canillas
f2327011a7 uefi-capsule: Include crt0 for arm and aarch64 that add a SBAT section
Due the lack of pei-aarch64 support in binutils, the gnu-efi crt0 harcodes
the PE32+ sections among other things. These crt0 aren't aware of the SBAT
section and so custom ones have to be used.

In the same vein as commit cfd1f2f42a ("uefi-capsule: Ensure SBAT metadata
is added correctly") included custom linker scripts, this change add a set
of crt0 for arm and aarch64 that hardcode a SBAT section in the PE headers.

These are the crt0 from gnu-efi plus the following fixes from Peter Jones:

* Include .sbat in section headers
* Fix some PE headers
* Calculate the VirtualSize of .sbat separately
* Put .rel* and .dyn* in .rodata
2021-04-07 13:46:58 +01:00
Javier Martinez Canillas
011db8e467 uefi-capsule: Sync linker scripts with latest used by shim
The linker scripts used in the project were copied from the shim project,
but there were a few fixes made after this original copy.

Until binutils have proper pei-aarch64 support, the linker scripts should
be kept in sync to make sure that the PE32+ binaries are built correctly.

The fixes included in this change are the following:

 * Include missing .text sections in PE/COFF binary (Chris Coulson)
 * Put .sbat after _edata (Peter Jones)
 * Fix some PE headers for arm and aarch64 (Peter Jones)
 * Include the aligned part in SizeOfRawData of sbat for arm and aarch64 (Gary Lin)
 * Swizzle some sections to make old sbsign happier for arm and aarch64 (Peter Jones)
 * Put .rel* and .dyn* in .rodata for arm and aarch64 (Peter Jones)
2021-04-07 13:46:58 +01: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
b9ac0bc029 Add fu_device_inhibit() to mark the device as non-updatable
We already have two things managing the UPDATABLE_HIDDEN->UPDATABLE transition,
and we're about to add a third.

Add a 'stackable' inhibit-style API so we do not accidentally mark a device as
updatable when it should remain hidden.
2021-03-31 19:19:46 +01:00
Steve McIntyre
50348e1104 Tweak the SBAT output for a vendor string
The format is meant to be "<project>.<vendor>" with a period as a
separator.

Signed-off-by: Steve McIntyre <93sam@debian.org>
2021-03-26 15:21:15 +00:00
Richard Hughes
a5966f7085 trivial: Codespell fixes 2021-03-19 16:42:33 +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
Gary Lin
b283395049 uefi-capsule: Specify the section flags for .sbat
When using "objcopy -O binary" to generate AArch64 EFI images, it
silently drops the sections without "alloc" or "load" or the sections
with "unload", and this caused the content of .sbat was skipped in the
final EFI image.

This commit sets the common read-only data section flags to .sbat to
make sure the content will be copied.

Signed-off-by: Gary Lin <glin@suse.com>
2021-03-09 09:09:24 +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
05217338b3 uefi: Do not use fu_plugin_has_custom_flag() in _init()
This means we can defer loading the quirks until all the plugins have loaded.
2021-03-02 06:33:46 +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
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
Mario Limonciello
41d874ba52 trivial: add linker script for armhf
fixes FTBFS in Debian:
https://buildd.debian.org/status/fetch.php?pkg=fwupd&arch=armhf&ver=1.5.7-1&stamp=1614100547&raw=0
2021-02-24 08:14:17 -06:00
Richard Hughes
ed0af24406 trivial: Use fwupd_device_remove_flag() to remove a single flag 2021-02-22 22:48:56 +00:00
Chris Coulson
cfd1f2f42a uefi-capsule: Ensure SBAT metadata is added correctly
The current approach of adding SBAT metadata after linking is creating
an image that is badly formed in 2 ways:

 * The SBAT section's file offset and size are not a multiple of the
   file alignment.

 * The SBAT section has a virtual address of zero. EDK2 loads the header
   here, and so it gets rejected.

This changes the approach to match shim, where an object file is
created with a .sbat section and then the linker takes care of placing
the section at a more appropriate virtual address.

See https://github.com/vathpela/gnu-efi/pull/14 for the section addition.
2021-02-22 16:19:19 +00:00
Richard Hughes
9df6764d93 uefi-capsule: Set the component generation to 1
See https://github.com/rhboot/shim/blob/main/SBAT.md
2021-02-18 13:23:18 -06:00
Richard Hughes
ec52942bc5 uefi-capsule: Include all the sections when using objcopy
Fixes the regression introduced in fde4b1676a
2021-02-18 13:23:18 -06:00
Richard Hughes
a22c13c637 Move the plugin build logic to the plugins themselves 2021-02-18 14:46:20 +00:00
Richard Hughes
6d656a940d Allow building without SBAT metadata
Two reasons:

 * It seems a bit antisocial to hard-require all this data without fair warning
 * The aarch64 pesign crashes when trying to sign the binary with SBAT metadata
2021-02-16 11:04:47 +00:00
Richard Hughes
124f2295ee trivial: Untie efi_os_dir from the SBAT distro ID
We happily fallback with an unset -Defi_os_dir and it gets confusing explaining
why the EFI dir needs to be set on a non-supported system.

In practice they'll probably have the same eventual value on most supported
distributions.

Fixes https://github.com/fwupd/fwupd/issues/2873
2021-02-12 16:01:00 +00:00
Javier Martinez Canillas
17c0a6c239 uefi-capsule: Fix objcopy failing to add a .sbat section on aarch64
The objcopy tool only has support for pei-x86_64 and pei-i386 targets, and
so trying to add a .sbat section for fwupdaa64.efi fails with this error:

objcopy: plugins/uefi-capsule/efi/fwupdaa64.efi: file format not recognized

To fix this issue, add the .sbat section to the ELF fwup.so shared object
and keep that section when generating the resulting fwupdaa64.efi binary.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
2021-02-12 13:29:55 +00:00
Javier Martinez Canillas
378b00018b uefi-capsule: Add SBAT metadata to the fwupd EFI binary
The Secure Boot Advanced Targeting (SBAT) [0] is a Generation Number Based
Revocation mechanism that is meant to replace the DBX revocation file list.

Binaries must contain a .sbat data section that has a set entries, each of
them consisting of UTF-8 strings as comma separated values. Allow to embed
this information into the fwupd EFI binary at build time.

The SBAT metadata must contain at least two entries. One that defines the
SBAT version used and another one that defines the component generation.

Downstream users can add additional entries if have changes that make them
diverge from the upstream code and potentially add other vulnerabilities.

[0]: https://github.com/rhboot/shim/blob/sbat/SBAT.md
2021-02-10 16:40:59 +00:00
Richard Hughes
2849116b33 uefi-capsule: Read the BMP in a more safe way 2021-02-10 16:29:57 +00:00
Richard Hughes
8887b9128b uefi-capsule: Use an integer for EfivarNvramUsed
This is much easier to parse on the LVFS.

Fixes https://github.com/fwupd/fwupd/issues/2834
2021-02-06 14:23:09 +00:00
Javier Martinez Canillas
fde4b1676a uefi: Rewrite generate_binary.sh script in Python
The generate_binary.sh is a script that calls the objcopy tool and
genpeimg in the case of Windows, to generate a PE binary file.

But doesn't have to be a shell script and could be rewritten as a
python script. This will make this code to generate a PE binary
easier to extend if needed.

Also, the only reason that's a template is to define the objcopy
tool used, but this can also be passed as a positional argument.
2021-02-04 12:51:05 +00:00
Richard Hughes
5d7fb6ad88 uefi-capsule: Check if the fwupd BootXXXX entry exists on failure
Some systems remove the BootXXXX entry we add (so we can run fwupdx64.efi) and
thus the firmware update does not run. Most commonly this failure is seen with
Lenovo systems that call the helpful option 'Boot Order Lock'.

Hopefully when we depend on the new kernel bios interface sysfs API in we can
check in ->prepare(), not after reboot, but until that we can mark the update
failure as transient as the user can actually fix the problem themselves.

Fixes https://github.com/fwupd/fwupd/issues/2801
2021-01-27 14:49:57 +00:00