1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-07 17:17:44 +03:00
Commit Graph

656 Commits

Author SHA1 Message Date
Max Resch
a6089431d5 sd-stub: Provide initrd with LINUX_EFI_INITRD_MEDIA_GUID
Register a LINUX_EFI_INITRD_MEDIA_GUID DevicePath with a LoadFile2Protocol interface and serve the initrd to a supported Linux kernel (Version 5.8+)
Leave the x86 code for older kernels in place until supported kernels become more mainstream
2021-10-11 14:40:49 +02:00
Lennart Poettering
2ccd598635 stub: also move magic string in stub into .sdmagic PE section
We already did that for sd-boot, hence do it for sd-stub the same way.

Also, move the __attribute__ stuff to the beginning of the statement,
rather than the middle. Mostly just because we usually put it first for
implementations for identifiers (for prototypes we put it last).
2021-10-11 14:09:28 +02:00
Jan Janssen
39ddc32a86 bootctl: Add set-timeout verb
Fixes: #18766
2021-10-08 15:32:50 +02:00
Jan Janssen
52b6b35643 sd-boot: Allow disabling timeout 2021-10-08 15:26:55 +02:00
Luca Boccassi
6eb736727a boot/sha256: sd-ify and move to src/fundamental 2021-10-08 13:11:00 +01:00
Lennart Poettering
edcd27dcaf tree-wide: remove a few unnecessary inclusions of ftw.h 2021-10-07 11:58:26 +02:00
Lennart Poettering
d8e32c471f basic: split out glyph/emoji related calls from locale-util.[ch] into glyph-util.[ch]
These functions are used pretty much independently of locale, i.e. the
only info relevant is whether th locale is UTF-8 or not. Hence let's
give this its own pair of .c/.h files.
2021-10-05 16:14:37 +02:00
Lennart Poettering
bf819d3ac2 basic: split out sync() family of calls from fs-util.[ch] into new c/h file
No changes in code, just some splitting out.
2021-10-05 15:47:32 +02:00
Lennart Poettering
8e8415e0d5 boot: prefer IMAGE_VERSION from os-release as version string
If the field exists it's probably the best version we have for sorting,
since it will change on every single OS image update.
2021-09-23 17:48:26 +02:00
Lennart Poettering
3a6249127e boot: add get_os_indications_supported() helper
We inquire the EFI var for this at two places, let's add a helper that
queries it and gracefully handles it if we can't get it, by returning a
zero mask, i.e. no features supported.
2021-09-23 17:24:28 +02:00
Lennart Poettering
0d43ce5266 stub: various modernizations to linux.c
Let's make some stuff const. Most importanly call AllocatePages() with
a pointer to an EFI_PHYSICAL_ADDRESS instead of a pointer to a
pointer. On 64bit this makes no difference, but on i386 this is simply
not correct, since EFI_PHYSICAL_ADDRESS is 64bit there, even though
pointers are 32bit.
2021-09-23 17:24:28 +02:00
Lennart Poettering
a0a644be70 boot: add helper for converting EFI_PHYSICAL_ADDRESS to a pointer
This isn't trivial when trying to be compatible with 32bit archs, hence
add a set of helper macro-like functions that make the conversion safe.
2021-09-23 17:24:28 +02:00
Lennart Poettering
61b6249552 boot: move TPM conditionalization into measure.h header
Let's move conditionalization of tpm_log_load_options() into the
measure.h to encapsulate the ifdeffery a bit more.
2021-09-23 17:24:10 +02:00
Lennart Poettering
ef6ff81a53 boot: port more code over to get_file_info_harder() 2021-09-23 17:24:10 +02:00
Lennart Poettering
19c896e99c boot: port more code to readdir_harder() 2021-09-23 17:24:10 +02:00
Lennart Poettering
4cbecde937 boot: use _cleanup_freepool_ at more places 2021-09-23 17:24:10 +02:00
Lennart Poettering
77c015820c boot: port more code to use open_directory() helper 2021-09-23 17:24:10 +02:00
Lennart Poettering
2553a5482c boot: automatically load drop-in EFI drivers off the ESP
Fixes: #15617
2021-09-23 17:24:10 +02:00
Lennart Poettering
d72f81be74 boot: split out code that loads the various menu entries into helper call
Just some refactoring, no real code changes.
2021-09-23 17:24:10 +02:00
Lennart Poettering
0be2a06ac7 boot: split out code that sets various EFI vars from main()
Just some refactoring, no actual code changes.
2021-09-23 17:24:10 +02:00
Lennart Poettering
6e161dc860 stub: make splash image payload const 2021-09-23 17:24:10 +02:00
Lennart Poettering
94b81afb08 stub: show splash screen earlier
let's move showing of the splash screen to the earliest place we know
the splash bmp address. After all a splash screen is all about showing
as early as we can. This matters as doing TPM stuff or packing up a
large cpio might take time.

While we are at it, move the conditionalization of the splash screen
into the function instead of doing it ahead of calling it. This should
encapsulate things more nicely.
2021-09-23 17:24:10 +02:00
Lennart Poettering
5a186322a1 stub: split out code that sets the various efi vars into function of its own
Just some refactoring, no code changes beyond the splitting out.
2021-09-23 17:24:09 +02:00
Lennart Poettering
e6e24af507 boot: unify code that measures image options/kernel command line 2021-09-23 17:24:09 +02:00
Lennart Poettering
faacf1807e boot: stop making TPM PCR to measure kernel command line into configurable
Everyone appears to use PCR 8 for this, hence I think it's safe to
hardcode that in systemd too.

It's also documented, like here:

https://www.gnu.org/software/grub/manual/grub/html_node/Measured-Boot.html

or here:

https://github.com/rhboot/shim/blob/main/README.tpm

(And the previous name was a bit confusing, since we don't actually just
measure one thing anymore, but mutliple things into multiple PCRs...)
2021-09-23 17:24:09 +02:00
Lennart Poettering
845707aae2 stub: when booting a kernel foo.efi then pack foo.efi.extra.d/*.{cred,raw} up as synthetic initrd
This adds support for the EFI stub to look for credential files and
sysext files next to the EFI kernel image being loaded, and pack them up
in an initrd cpio image, and pass them to the kernel.

Specifically, for a kernel image foo.efi it looks for
foo.efi.extra.d/*.cred and packs these files up in an initrd, placing it
inside a directory /.extra/credentials/. It then looks for
foo.efi.extra.d/*.raw and pack these files up in an initrd, placing them
inside a directory /.extra/sysexts/. It then concatenates any other
initrd with these two initrds, so they are combined.

Or in other words auxiliary files placed next to the kernel image are
picked up automatically by the EFI stub and be made available in the
initrd in the /.extra/ directory.

What's the usecase for this? This is supposed to be useful in context of
implementing fully trusted initrds, i.e. initrds that are not built
locally on the system and unsigned/unmeasured – as we do things
currently —, but instead are built by the vendor, and measured to TPM.
The idea is that a basic initrd is always linked into the kernel EFI
image anyway. This will already be sufficient for many cases. However,
in some cases it is necessary to parameterize initrds, or to extend the
basic initrds with additional subsystems (e.g. think complex storage, or
passing server info/certificates/… to initrds). The idea is that the
parameterization is done using the "credentials" logic we already have
in systemd, with these credential files (which can optionally be
encrypted+authenticated by TPM2) being placed in the ESP next to the
kernel image. And the initrd extension via the "sysext" logic we already
have in systemd too.

Note that the files read by this code are not verified immediately, they
are copied *as-is* and placed into /.extra/ in the initrd. In a trusted
environment they need to be validated later, but before first use. For
the credentials logic this should be done via the TPM2
encryption/authentication logic. For the sysext stuff the idea is that
this is done via signed images, as implemented by #20691.
2021-09-23 17:24:09 +02:00
Lennart Poettering
80b2f4d92c boot: generalize sorting code
Let's make this generic, so that we can reuse it elsewhere later.
2021-09-23 17:23:45 +02:00
Lennart Poettering
c6dfe36044 boot: add a bunch of new helper calls 2021-09-23 17:23:45 +02:00
Lennart Poettering
88657f7575 boot: add a way to indicate overflow in ALIGN_TO() 2021-09-23 17:10:21 +02:00
Anssi Hannula
26d54e1263 bootctl: Fix update not adding EFI entry if Boot IDs are non-consecutive
"bootctl update" tries to add sd-boot to the EFI boot loader list if it
is not already there. To do so, it uses find_slot() which finds the
proper BootXXXX slot ID to use and also returns 1 if an existing sd-boot
entry was found at this ID or 0 if it is a new unused ID. In "update"
case install_variables() only writes the entry in case 0 (no existing
entry).

However, find_slot() erroneously returns 1 if it finds a gap in the Boot
IDs (i.e. when not resorting to max(ids) + 1). This causes
"bootctl update" to not add a missing systemd-boot boot entry if the
existing BootXXXX entry IDs are not consecutive.

Fix that by returning 0 in find_slot() when an empty gap ID is selected
to make it match the behavior when selecting an empty non-gap ID.
2021-09-23 17:05:20 +02:00
Lennart Poettering
5b5d365d73 stub: prepare section pointers in separate steps
In a follow-up patch we are going to modify the initrd, hence prepare
the pointers/"physical addresses" to it, first, so that we can do so
easily.

Also, do some other tweaks and cleanups to physical address/pointer
conversion.
2021-09-20 22:18:27 +02:00
Lennart Poettering
e41d3d8929 stub: use proper enums instead of hardcoded numeric indexes for identifying PE sections 2021-09-20 22:18:22 +02:00
Lennart Poettering
04394aa185 boot: ReallocatePool() supports NULL pointers as first argument
Just like userspace realloc() the EFIlib ReallocatePool() function is
happy to use a NULL pointer as input, in which case it is equivalent to
AllocatePool(). See:

269ef9dbc7/lib/misc.c (L57)
2021-09-20 22:18:17 +02:00
Lennart Poettering
ff3aa8d1e0 boot: modernize measure.c
Let's use _cleanup_freepool_, compound literals for initialization,
OFFSETOF() and let's remove some unnecessary casts.

No change in behaviour.
2021-09-20 22:18:12 +02:00
Lennart Poettering
b4f25c649d boot: move TCG/TPM protocol definitions into missing_efi.h
That's what it is for...
2021-09-20 22:18:08 +02:00
Lennart Poettering
2da0a7e154 boot: use cleanup-based file handle closing a bit more 2021-09-20 22:18:03 +02:00
Lennart Poettering
70d24fedc1 boot: invert if check, to reduce indentation level 2021-09-20 22:17:49 +02:00
Jan Janssen
1b965abc66 sd-boot: Add support for changing console mode at runtime 2021-09-15 16:32:18 +02:00
Jan Janssen
134144abc8 sd-boot: Simplify setting console mode 2021-09-15 10:48:19 +02:00
Jan Janssen
de829ff593 sd-boot: Fix assertion fail
The UEFI Platform Initialization Specification says that both
parameters may be NULL.
2021-09-11 23:33:17 +09:00
Emil Renner Berthing
6e86342bb8 sd-boot: Support installing new devicetree
The Bootloader Specification says "devicetree refers to the binary
device tree to use when executing the kernel..", but systemd-boot
didn't actually do anything when encountering this stanza until now.

Add support for loading, applying fixups if relevant, and installing the
new device tree before executing the kernel.
2021-09-10 16:48:47 +09:00
Lennart Poettering
206284f5b0 efi: drop spaces between function name and "("
When pulling in the SHA256 implementation from glibc, only some of the
coding style was adjusted to ours, other was not. Let's make things a
bit more consistent.
2021-09-01 23:23:34 +02:00
Lennart Poettering
c0ad07b190 efi: make EFI_GUID generally constant
The GUIDs we usually deal with should be considered constant. Hence make
them so. Unfortunately the prototypes for various functions doesn't mark
them as const (but still decorates them with "IN", clarifying they are
input-only), hence we need to cast things at various places. We already
cast in similar fashion in many other cases, hence unify things here in
one style.

Making the EFI_GUID constant (and in particular so when specified in C99
compound literal style) allows compilers to merge multiple instances of
them.
2021-09-01 23:23:34 +02:00
Lennart Poettering
fbe3d9591f
Merge pull request #20490 from poettering/id128-format-compound-literal
compound literal love for sd_id128_to_string()
2021-08-20 13:33:51 +02:00
Alfonso Sánchez-Beato
d48f9174cf src/boot/efi/linux: fix linux_exec prototype
Callers to linux_exec() are actually passing an EFI_HANDLE, not a pointer to
it. linux_efi_handover(), which is called by linux_exec(), also expects an
EFI_HANDLE.
2021-08-20 12:33:09 +02:00
Lennart Poettering
85b55869bc tree-wide: port everything over to new sd-id128 compund literal bliss 2021-08-20 11:09:48 +02:00
Jan Janssen
87167331c9 sd-boot: Use UEFI provided CRC32 2021-08-18 22:01:09 +01:00
Jan Janssen
2e65d6103d sd-boot: Draw custom edit cursor
Firmware likes to draw the EFI provided cursor in a weird way that
makes it invisible sometimes. This is even more likely to happen
if unusual colors are picked. It also fails to draw attention to the
user by being very small and not blinking.

Additionally, to make it more clear that we are in edit mode, we
now default to inverting the general default color and use that for
our line edit.

Fixes: #19301
2021-08-17 13:59:13 +02:00
Jan Janssen
e313e934db sd-boot: Add compile-time color support
Fixes: #10139
2021-08-17 13:59:12 +02:00
Jan Janssen
8a8e5666ce sd-boot: Improve key bindings
Making keys case insensitive should help if caps lock is on.
We are not advertising them at runtime or in the manual to
reduce the noise.

This also hides the quit and version commands from the help
string. They are mostly for devs and otherwise have little
to no use to normal users. The latter overlaps with print
status which is still advertised.
2021-08-17 13:57:21 +02:00
Jan Janssen
1ab39cc10e sd-boot: Render title entries centered and not to entire screen width 2021-08-17 13:57:19 +02:00
Jan Janssen
c005f4375e sd-boot: Introduce print_at helper function 2021-08-17 13:53:07 +02:00
Jan Janssen
54af753f3a sd-boot: Fix marking EFI var default entry
Fixes: #18072
2021-08-17 13:49:22 +02:00
Jan Janssen
64bb56e58b sd-boot: Allow automatic entries to be default 2021-08-16 15:52:15 +02:00
Jan Janssen
730b719406 sd-boot: Improve selection of initial entries to show 2021-08-16 15:52:09 +02:00
Jan Janssen
4a59f399c9 sd-boot: Detect windows boot loader title from BCD 2021-08-16 10:51:02 +02:00
Jan Janssen
43ee1fe086 sd-boot: Add memmem_safe and memory_startswith 2021-08-16 10:50:58 +02:00
Jan Janssen
12450f2e77 sd-boot: Try harder to detect ourselves
By moving our magic string into its own PE section, we can forego
grepping for it.
2021-08-16 10:49:18 +02:00
Jan Janssen
1328150d85 sd-boot: Fix PE section parsing
We only need the PE header offset from the DOS header, not
its size. Previously, the section table could be cut off in the middle.

While we are at it, also modernize the remaining code.
2021-08-16 10:49:12 +02:00
Jan Janssen
dba0c9832b sd-boot: Allow on/off and t/f for booleans too 2021-08-12 16:10:06 +02:00
Jan Janssen
ec97e40c29 sd-boot: Provide error messages when parsing a config option fails 2021-08-12 16:10:06 +02:00
Jan Janssen
e98d271e57 sd-boot: Rework console input handling
Fixes: #15847
Probably fixes: #19191
2021-08-12 16:10:02 +02:00
Jan Janssen
b3fc3a3ced sd-boot: Use StrSize where it makes sense 2021-08-12 09:48:37 +02:00
Jan Janssen
508df915b6 sd-boot: Assert all the things! 2021-08-12 09:48:37 +02:00
Jan Janssen
7a7267bf55 sd-boot: Add assert implementation
There is a ASSERT() macro from gnu-efi, but that does not show any
output to ConOut. Having to do some additional setup just to get
some debug output is tedious and outright difficult on real hardware.
2021-08-12 09:48:37 +02:00
Jan Janssen
b52fafb26d sd-boot: Fix possible null pointer dereference
Auto entries are showing garbage for the version in print_status()
because StrDuplicate does not expect null pointers.
2021-08-12 09:48:37 +02:00
Jan Janssen
b2cf9922a4 sd-boot: Don't use magic integer constants 2021-08-12 09:48:37 +02:00
Jan Janssen
8aba0eec49 sd-boot: Unify error handling
log_error_stall() and log_error_status_stall() will ensure the user has
a chance to catch an error message by stalling and also forcing a
lightred/black color on it. Also, convert several Print() calls to it
since they are actually error messages.
2021-08-12 09:48:27 +02:00
Lennart Poettering
e8b08edcdf tree-wide: use memmem_safe()
Let's be paranoid and do something useful if we operate with empty
haystack/needle. This doesn't actually fix anything, as the places as
far as I can see check for non-emptyness already beforehand, but I will
sleep safer at night, if we don't even allow the trap to be fallen in,
ever, even if the code is changed sooner or later.
2021-08-10 14:55:50 +02:00
Lennart Poettering
d8782cc5c2 memory-util: add mempmem_safe()
This is like memmem_safe() but returns a pointer after the needle,
instead to the beginning of the needle.

This is then used at one place. Not much, but it makes me sleep safer at
night, as it avoids the manual counting done so far.
2021-08-10 14:55:50 +02:00
longpanda
2846007ecf Fix the "Failed to open random seed ..." message.
When boot ArchLinux from Ventoy, it always print `Failed to open random seed file: write protected.`
As Ventoy emulate the ISO file as a read-only CDROM, I didn't test with a real physical CDROM drive, but maybe it also has such problem.
As we use `EFI_FILE_MODE_WRITE`  to open the `loader\random-seed` file, so I think it's better to check the result with both  `EFI_WRITE_PROTECTED` and `EFI_NOT_FOUND`.
2021-08-09 10:56:01 +02:00
Max Resch
3c79a56d53 sd-boot: time measurements for the ARM64
This adds assembly to read the platform timer from the CP15 coprocessor
register `cntpct_el0` and the frequency from `cntfrq_el0`
2021-08-06 13:40:00 +01:00
Zbigniew Jędrzejewski-Szmek
04499a70fb Drop the text argument from assert_not_reached()
In general we almost never hit those asserts in production code, so users see
them very rarely, if ever. But either way, we just need something that users
can pass to the developers.

We have quite a few of those asserts, and some have fairly nice messages, but
many are like "WTF?" or "???" or "unexpected something". The error that is
printed includes the file location, and function name. In almost all functions
there's at most one assert, so the function name alone is enough to identify
the failure for a developer. So we don't get much extra from the message, and
we might just as well drop them.

Dropping them makes our code a tiny bit smaller, and most importantly, improves
development experience by making it easy to insert such an assert in the code
without thinking how to phrase the argument.
2021-08-03 10:05:10 +02:00
Lennart Poettering
e5a8b4b593 bootctl: tweak "bootctl update" to be a NOP when boot loader is already current and --graceful is given
Previously, the "bootctl update" logic would refrain from downrgading a
boot loader, but if the boot loader that is installed already matched
the version we could install we'd install it anyway, under the
assumption this was effectively without effect. This behaviour was handy
while developing boot loaders, since installing a modified boot loader
didn't require a version bump.

However, outside of the systems of boot loader developers I don't think
this behaviour makes much sense: we should always emphasize doing
minimal changes to the ESP, hence when an update is supposedly not
necessary, then don't do it. Only update if it really makes sense, to
minimize writes to the ESP. Updating the boot loader is a good thing
after all, but doing so redundantly is not.

Also, downgrade the message about this to LOG_NOTICE, given this
shouldn't be a reason to log.

Finally, exit cleanly in this cases (or if another boot loader is
detected)
2021-07-30 16:48:24 +02:00
Zbigniew Jędrzejewski-Szmek
fce9abb227 meson: use a/b instead of join_paths(a,b)
It is nicer and shorter.
2021-07-27 19:32:35 +02:00
James Hilliard
d6d1fd995f Disable non-explicit sbatvars autodetection for cross builds.
Since autodetection is unlikely to work reliably for cross builds
disable it unless explicitly enabled.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2021-07-10 23:46:26 +01:00
nl6720
250db1bf02 docs: improve wording when mentioning the acronym "ESP"
"ESP" is "EFI system partition", so "ESP partition" is redundant.
2021-07-09 13:41:00 +02:00
Zbigniew Jędrzejewski-Szmek
ad2d6880ea bootctl: print SystemdOptions from efivarfs if newer than our cache
The logic is that if the options are updated after boot, we *don't* use
the new value. But we still want to print out the changed contents in
bootctl as to not confuse people.

Fixes #19597.
Also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=988450.

$ build/bootctl systemd-efi-options
quiet
Note: SystemdOptions EFI variable has been modified since boot. New value: debug

The hint is printed to stderr, so scripts should not be confused.
2021-06-15 22:01:42 +02:00
Zbigniew Jędrzejewski-Szmek
c67bd42b71 Inline some inerator variables 2021-06-15 22:01:42 +02:00
Zbigniew Jędrzejewski-Szmek
e6f055cbc4 basic/efivars: replace dynanamic creation of efivar names with static strings
Creating those string dynamically at runtime is slow and unnecessary.
Let's use static strings with a bit of macro magic and the let the compiler
coalesce as much as possible.

$ size build/src/shared/libsystemd-shared-248.so{.old,}
   text	   data	    bss	    dec	    hex	filename
2813453	  94572	   4584	2912609	 2c7161	build/src/shared/libsystemd-shared-248.so.old
2812309	  94564	   4584	2911457	 2c6ce1	build/src/shared/libsystemd-shared-248.so

A nice side-effect is that the same form is used everywhere, so it's easier to
figure out all variables that are used, and where each specific variable is
used.

C.f. 2b0445262a.

Note: 'const char *foo = alloca(…);' seems OK. Our coding style document and
alloca(3) only warn against using alloca() in function invocations. Declaring
both stack variable and alloca at the same time should be fine: no matter in
which order they happen, i.e. if the pointer variable is above the contents,
or the contents are above the pointer, or even if the pointer is elided by the
compiler, everything should be fine.
2021-06-15 22:01:42 +02:00
Yu Watanabe
16e09d51a7 meson: do not share compiler flags except for emitting warnings
Follow-up for 6526736397.

Prompted by https://github.com/systemd/systemd/issues/19191#issuecomment-856312107.
2021-06-08 10:44:34 +02:00
Yu Watanabe
ffc36c276c efi: drop glibc header and use pre-defined macros
This reverts 72dc626b3d and replace glibc
specific macros with compiler's pre-defined macros.
2021-06-03 13:49:33 +09:00
Yu Watanabe
6526736397 meson: enable more warnings when building efi binary 2021-06-02 15:49:44 +09:00
Yu Watanabe
ca474d5114 efi: constify several arguments of functions which handle loader entries 2021-06-02 15:45:47 +09:00
Yu Watanabe
cfb7fa289d efi: drop const qualifiers from arguments in uefi_call_wrapper() 2021-06-02 15:43:21 +09:00
Yu Watanabe
edad24c61e efi: add const qualifier to EFI variable handling functions 2021-06-02 15:41:39 +09:00
Yu Watanabe
ef53d52b01 efi: add const qualifier to string utils 2021-06-02 15:40:56 +09:00
Yu Watanabe
72dc626b3d efi: include endian.h to handle endian correctly
The macro __BYTE_ORDER__ is defined in endian.h.
2021-06-02 15:38:32 +09:00
Yu Watanabe
959ab90bbc efi: do not use _STRING_ARCH_unaligned macro
It is already removed from glibc. See,
https://sourceware.org/git/?p=glibc.git;a=commit;h=16396c41deab45f715ffd813280d9d685b3b281e
https://sourceware.org/git/?p=glibc.git;a=commit;h=09a596cc2cf4e0f9f8e9f3bba4b1a97efcb13bcb
2021-06-02 15:36:29 +09:00
Zbigniew Jędrzejewski-Szmek
8f127e161e efi: use meson object directly instead of going through 'substs' 2021-05-19 10:25:26 +09:00
Zbigniew Jędrzejewski-Szmek
835cf75aef meson: use jinja2 for rpm templates
The naming of variables is very inconsistent. I tried to use more
modern style naming (UNDERSCORED_TITLE_CASE), but I didn't change existing
names too much. Only SYSTEM_DATA_UNIT_PATH is renamed to SYSTEM_DATA_UNIT_DIR
to match SYSTEM_CONFIG_UNIT_DIR.
2021-05-19 10:25:26 +09:00
Zbigniew Jędrzejewski-Szmek
f86887af6e meson: print autodetected sbat fields
...
Message: sbat-distro (from ID): fedora
Message: sbat-distro-summary (from NAME): Fedora
Message: sbat-distro-url (from BUG_REPORT_URL): https://bugzilla.redhat.com/
...
2021-05-14 14:37:14 +02:00
Zbigniew Jędrzejewski-Szmek
0f4c4f3824 meson: call find_program() once and reuse the variable everywhere
Meson 0.58 has gotten quite bad with emitting a message every time
a quoted command is used:
Program /home/zbyszek/src/systemd-work/tools/meson-make-symlink.sh found: YES (/home/zbyszek/src/systemd-work/tools/meson-make-symlink.sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program sh found: YES (/usr/bin/sh)
Program xsltproc found: YES (/usr/bin/xsltproc)
Configuring custom-entities.ent using configuration
Message: Skipping bootctl.1 because ENABLE_EFI is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Message: Skipping journal-remote.conf.5 because HAVE_MICROHTTPD is false
Message: Skipping journal-upload.conf.5 because HAVE_MICROHTTPD is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Message: Skipping loader.conf.5 because ENABLE_EFI is false
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
Program ln found: YES (/usr/bin/ln)
...

Let's suffer one message only for each command. Hopefully we can silence
even this when https://github.com/mesonbuild/meson/issues/8642 is
resolved.
2021-05-14 14:21:27 +02:00
Zbigniew Jędrzejewski-Szmek
01d0123f04
Merge pull request #19506 from xnox/ship-stub-elf
boot/efi: install ELF linux.elf.stub in addition to PE linux.efi.stub
2021-05-12 09:45:36 +02:00
zsien
5c2e595767 bootctl: same entry path check case-insensitive
Some motherboards convert the path to uppercase under certain circumstances
(e.g. after booting into the Boot Menu in the ASUS ROG STRIX B350-F GAMING).
2021-05-11 14:27:44 +02:00
Zbigniew Jędrzejewski-Szmek
4f3dca78bb meson: rework test-efi-disk.img creation to not require variables
The primary goal is to make the name of the custom_target() rule match
the output file again. Having them different is confusing.
2021-05-10 20:28:24 +02:00
Dimitri John Ledkov
36c5f589fb
boot/efi: add --build-id=sha1 to ELF efi objects
As it is not nice to ship ELF binary without a note.gnu.build-id set.
2021-05-10 09:36:04 +01:00
Dimitri John Ledkov
7840d7af22
boot/efi: install ELF linux.elf.stub in addition to PE linux.efi.stub
Binutils for non-x86 architectures currently does not support PE binaries. Thus
linux.efi.stub is useless on those, as one cannot use any tooling to add
linux/cmdline/splash sections to it. In addition to PE linux.efi.stub also
install ELF linux.elf.stub, such that one can use objcopy ELF target to copy in
linux/cmdline/splash sections and then convert the result to a PE binary.
2021-05-10 09:35:59 +01:00
Dimitri John Ledkov
9137c03c04
boot: add optional EFI SBAT support
Add SBAT support, when -Dsbat-distro value is specified. One can use
-Dsbat-distro=auto for autodetection of all sbat options. Many meson configure
options added to customize SBAT CSV values, but sensible defaults are auto
detected by default. SBAT support is required if shim v15+ is used to load
systemd-boot binary or kernel.efi (Type II BootLoaderSpec).

Fixes #19247
2021-05-07 14:38:48 +01:00
Dimitri John Ledkov
e706aaa7a3 boot/efi: add ARM (THUMB) and RISCV64 machine types
Also drop defines from shared/pe-header.h, appear to be unused.
2021-05-06 15:16:29 +02:00
Yu Watanabe
f0373df1a7
Merge pull request #19507 from nabijaczleweli/bootctlpsko-lite
bootctl: take --make-machine-id-directory=yes|no|auto and make/remove \$MACHINE_ID accordingly
2021-05-06 12:44:21 +09:00
наб
6a3fff75ba
bootctl: take --make-machine-id-directory=yes|no|auto and make/remove \$MACHINE_ID accordingly
auto resolves to yes if /etc/machine-id resides on non-tmpfs

This effectively reverts commit 31e57550b5
2021-05-05 14:35:00 +02:00
Zbigniew Jędrzejewski-Szmek
7e92ab4eb8 meson: make one check shorter 2021-05-04 14:22:58 +02:00
Emil Renner Berthing
a00ff2e1b5 boot/efi: compile on riscv64
This makes systemd-boot compile against the latest gnu-efi which
just added support for riscv64.
2021-04-22 14:37:25 +02:00
Frantisek Sumsal
437e889b18 src: shellcheck-ify shell scripts 2021-04-20 18:39:36 +02:00
Luca Boccassi
c2b2df604b tree-wide: avoid uninitialized warning on _cleanup_ variables
With some versions of the compiler, the _cleanup_ attr makes it think
the variable might be freed/closed when uninitialized, even though it
cannot happen. The added cost is small enough to be worth the benefit,
and optimized builds will help reduce it even further.
2021-04-14 12:25:06 +01:00
Yu Watanabe
dcb6061e1c meson: fix warning about comparison between different types
Follow-up for e39288193f.
2021-03-22 14:40:46 +01:00
tpgxyz
e39288193f systemd-boot: LLVM/lld does not support PE/COFF relocations. Bail out with an error message 2021-03-19 19:42:47 +00:00
Daan De Meyer
95ba433a5f boot: Move console declarations to missing_efi.h
These were added to eficonex.h in gnu-efi 3.0.13. Let's move them
to missing_efi.h behind an appropriate guard to fix the build with
recent versions of gnu-efi.
2021-03-13 13:13:54 +00:00
Yu Watanabe
4e5cbc4b17 efi: introduce UINT32_MAX and UINT64_MAX 2021-03-05 07:10:13 +09:00
Yu Watanabe
f5fbe71d95 tree-wide: use UINT64_MAX or friends 2021-03-05 07:10:13 +09:00
Lennart Poettering
312dff1760 util: add helpers for generating colored check mark glyphs from bools 2021-03-03 03:08:31 +09:00
Lennart Poettering
685097b9ca efi stub: accept it if our loaded image has no FilePath field set
The firmware spec doesn't really say whether FilePath of the LoadedImage
protocol may be NULL or not. So far we assumed it to be non-NULL, but
apparently the FreeBSD UEFI chainloader sets it to NULL. Handle this
gracefully.

(Noticed and tracked down by Alexander Schreiber)

Fixes: #18733
2021-02-23 15:48:48 +01:00
Lennart Poettering
b2a220492b bootctl: show whether the firmware has TPM2 support 2021-02-11 23:11:56 +01:00
Zbigniew Jędrzejewski-Szmek
2d93c20e5f tree-wide: use -EINVAL for enum invalid values
As suggested in https://github.com/systemd/systemd/pull/11484#issuecomment-775288617.

This does not touch anything exposed in src/systemd. Changing the defines there
would be a compatibility break.

Note that tests are broken after this commit. They will be fixed in the next one.
2021-02-10 14:46:59 +01:00
Yu Watanabe
8087644a13 tree-wide: replace strverscmp() and str_verscmp() with strverscmp_improved() 2021-02-09 14:25:03 +09:00
Yu Watanabe
e5bc5f1f5a fundamental: move several macros and functions into src/fundamental/
sd-boot has a copy of a subset of codes from libbasic. This makes
sd-boot share the code with libbasic, and dedup the code.

Note, startswith_no_case() is dropped from sd-boot, as
- it is not used,
- the previous implementation is not correct,
- gnu-efi does not have StrniCmp() or so.
2021-02-09 14:22:54 +09:00
Daan De Meyer
bcea93326b boot: Replace efivar_set() persistent argument with flags argument
To add secure-boot enrolling support, we need to be able to specify
the EFI_VARIABLE_APPEND_WRITE flag so let's make the efivar_set()
methods more generic so we can set that flag.
2021-02-04 16:38:22 +01:00
Daan De Meyer
cb347d263d boot: Add startswith() and endswith() functions with no_case variants
Adapted from string-util
2021-02-02 22:53:31 +00:00
Daan De Meyer
fffd5e8ee3 boot: Drop unnecessary braces 2021-02-02 21:15:24 +00:00
Daan De Meyer
d47b7c5720 boot: Fix void pointer arithmetic warning 2021-02-02 21:15:24 +00:00
Daan De Meyer
c8af7dab21 boot: Replace raw efivar gets with typed variants 2021-02-02 21:15:21 +00:00
Daan De Meyer
987d0a1250 boot: Add efivar_get/set_uint64_le() functions
These are implemented as bit-shifting functions that allow reading
and writing UEFI variables stored as little endian 64-bit unsigned
values.
2021-02-02 21:03:58 +00:00
Daan De Meyer
a7308a266b boot: Rename efivar_get/set_int() to efivar_get/set_uint_string()
Let's clearly indicate that these are used to set/get uints that
are stored as strings.
2021-02-02 21:03:47 +00:00
Daan De Meyer
258f0970f9 boot: Tighten scope of variables used in loops 2021-02-02 21:03:35 +00:00
Daan De Meyer
2a7c16753b boot: Add efivar_get_boolean_u8() 2021-02-02 21:03:33 +00:00
Daan De Meyer
5e1f0e6fca boot: Make all efivar util functions take the guid as an argument
Let's make these functions a little more generic so we can have
them work on more than one GUID. More specifically, this allows
using them with the global guid which will be used a bit more to
extend the secure boot support.
2021-01-31 21:46:05 +00:00
Daan De Meyer
7d2ebb6f85 boot: Turn all guid constants into C99 compound initializers
Avoids having to use the address operator all the time and
avoids having to cast or do other unintuitive stuff.
2021-01-31 21:46:05 +00:00
Daan De Meyer
5021222842 boot: Enable C99
Instead of using -nostdinc, we use -nostdlib. This is necessary
to allow moving to C99 as efibind.h includes stdint.h when C99
is enabled. It isn't necessarily problematic to use some standard
library headers as long as they don't contain functions defined in
libc or another system library (or in other words, header only
headers are fine to use in sd-boot).
2021-01-31 21:46:05 +00:00
Daan De Meyer
ce0f078f4d boot: Move Secure Boot logic to new file 2021-01-31 21:46:05 +00:00
Daan De Meyer
47381f8f64 sd-boot: Add missing includes
Let's make all headers self-sufficient by including the necessary
EFI headers in the headers themselves.
2021-01-31 10:38:59 +00:00
Daan De Meyer
9a383acadd sd-boot: Make internal functions static 2021-01-31 10:38:59 +00:00
Daan De Meyer
bc556335b1 tree-wide: Drop custom formatting for print() help messages
I think this formatting was originally used because it simplified
adding new options to the help messages. However, these days, most
tools their help message end with "\nSee the %s for details.\n" so
the final line almost never has to be edited which eliminates the
benefit of the custom formatting used for printf() help messages.
Let's make things more consistent and use the same formatting for
printf() help messages that we use everywhere else.

Prompted by https://github.com/systemd/systemd/pull/18355#discussion_r567241580
2021-01-31 13:14:02 +09:00
Zbigniew Jędrzejewski-Szmek
9ee03516df tree-wide: add spdx header on all scripts and helpers
Even though many of those scripts are very simple, it is easier to include
the header than to try to say whether each of those files is trivial enough
not to require one.
2021-01-28 09:55:35 +01:00
Yu Watanabe
ecb3e9fba3 boot: at least one of os_name_pretty or os_name exists in this block
Closes CID#1438933.
2021-01-12 20:43:06 +09:00
Endre Szabo
9e516e4c05
A typo fix in bootctl.c (#18106) 2020-12-30 12:10:24 +09:00
Andrew Balmos
361f41645c efi: Only use arm flags if supported
Support gcc 8 on arm
2020-12-15 12:06:52 +09:00
Yu Watanabe
db9ecf0501 license: LGPL-2.1+ -> LGPL-2.1-or-later 2020-11-09 13:23:58 +09:00
Zbigniew Jędrzejewski-Szmek
c062cd9dde headers: use custom LicenseRef- spdx tag for various "public domain" files
There is no spdx tag defined for those versions of "public domain", but we can
add a custom tag, see
https://spdx.github.io/spdx-spec/6-other-licensing-information-detected/.

crc32.h is updated to match crc32.c.
2020-10-29 11:41:27 +01:00
Zbigniew Jędrzejewski-Szmek
448e7440c2 headers: add spdx tags to imported files with a known license
I added the header in the cases where the license text is present and it is
easy to find the appropriate SPDX header.

For "public domain" stuff: SDPX treats each "public domain" license as unique [1],
but luckily the one in siphash24.c is one of the identified variants. There are
some other cases which specify "public domain" but there doesn't seem to be a
SPDX identifier.

[1] https://wiki.spdx.org/view/Legal_Team/Decisions/Dealing_with_Public_Domain_within_SPDX_Files

gunicode.[ch] are imported from glib, which is licensed as LGPL2.1+,
see https://gitlab.gnome.org/GNOME/glib/-/blob/master/glib/gunicode.h.
2020-10-29 11:32:24 +01:00
Zbigniew Jędrzejewski-Szmek
4368277c74 tree-wide: use the usual SPDX header for our own files 2020-10-29 10:47:20 +01:00
Дамјан Георгиевски
c4b843473a bootctl: add @current/@oneshot/@default targets to set-default/set-oneshot
Using `bootctl set-default @current` will set the default loader entry
to the currently booted entry as read from the `LoaderEntrySelected` EFI
variable.

Also `bootctl set-oneshot @current` will set the oneshot loader entry to
the current booted entry.

Correspondingly `@default` and `@oneshot` can be used to read from the
LoaderEntryDefault and LoaderEntryOneshot EFI variables.
2020-10-20 15:02:58 +02:00
Lennart Poettering
64a7fcc5cd bootctl: separate boot loader specific commands in man and --help
bootctl implements three types of operation: those that work with an EFI
boot loader, those which work with any EFI boot loader that implements
the boot loader spec + interface, and finally those specific to sd-boot.
Previously the --help text and the man page mixed them all up. Let's put
them clearly in three separate sections however, to communicate clearly
what is supposed to work everywhere, and what is specific to
systemd-boot or boot loaders implementing the two specs.

This adjusts wording here and there, but is mostly just about
re-ordering existing docs, and putting them under new sections.
2020-10-14 19:40:39 +02:00
Marco Wang
ee85122987 boot/efi: Explicitly specify void in parameter list
Functions that accept no arguments should be
explicitly declared a void parameter in their parameter list.

Signed-off-by: Marco Wang <m.aesophor@gmail.com>
2020-10-06 22:29:57 +02:00
Lennart Poettering
ad0b610b0c bootctl: handle if LoaderSystemToken is invalid for some reason
This points to some firmware issue, but we should still be able to
correct things if this happens. Hence log about this and fix it.

Fixes: #17041
2020-09-14 21:33:31 +02:00
Lennart Poettering
c1b9708c10 bootctl: don't accidentally propagate errors in "bootctl status"
Fixes: #16989
2020-09-10 12:45:54 +02:00
fangxiuning
c53aafb7b5
tree-wide: drop pointless zero initialization (#16884)
tree-wide: drop pointless zero initialization
2020-08-28 17:45:54 +02:00
Zbigniew Jędrzejewski-Szmek
f9536e6793
Merge pull request #16687 from DaanDeMeyer/bootloader-machine-id
Allow bootctl and kernel-install to be called without /etc/machine-id present
2020-08-18 15:05:26 +02:00
Daan De Meyer
31e57550b5 bootctl: Remove dependency on machine-id.
The machine-id is used to create a few directories and setup a default
loader entry in loader.conf. Having bootctl create the directories
itself is not particularly useful as it does not put anything in them
and bootctl install is not guaranteed to be called before an initramfs
tool like kernel-install so other programs will always need to have
logic to create the directories themselves if they happen to be called
before bootctl install is called.

On top of this, when using unified kernel images, these are installed to
$BOOT/EFI/Linux which removes the need to have the directories created
by bootctl at all. This further indicates that these directories should
be created by the program that puts something in them rather than by
bootctl.

Removing the machine-id dependency allows bootctl install to be called
even when there's no machine-id in the image. This is useful for image
builders such as mkosi which don't have a machine-id when
installing systemd-boot (via bootctl) because it should only be
generated by systemd when the final image is booted.

The default entry in loader.conf based on the machine-id in loader.conf
is also removed which shouldn't be a massive loss in usability overall.

This commit reverts commit 341890d.
2020-08-10 19:55:57 +01:00
Zbigniew Jędrzejewski-Szmek
ddd8e23dc9 bless-boot: add missing verb to --help
There is also "help" verb which duplicates the --help option. I don't
think we should advertise it.
2020-08-05 12:16:03 +02:00