Commit Graph
608 Commits
Author SHA1 Message Date
Lennart Poettering 7c248223eb tree-wide: use new RET_NERRNO() helper at various places 2021-11-16 08:04:09 +01:00
Jan Janssen 4cf8a6092e meson: Use fs module
Turns out that meson provides a fs module since 0.53.0, making it unnecessary
to call out to test.
2021-11-14 13:54:27 +09:00
Lennart Poettering 81d9db6805 boot: line-break magic[] array to match osrel[] line breaks 2021-11-11 17:23:04 +01:00
Lennart Poettering df33178416 boot: when we can't boot use the right boot loader entry display title in log message 2021-11-11 17:22:55 +01:00
Lennart Poettering 18fde343a8 boot: clean up unified boot loader entry name/version extraction
Let's make sure IMAGE_ID/IMAGE_VERSION are properly honoured, and
explain in a long comment why.

Let's also use ID= field again, which was lost by accident.

(While we are at it do some minimal OOM checks wherever we touch
something)
2021-11-11 17:22:31 +01:00
Lennart Poettering 1ce915a91c boot: const arguments should be const
Unfortunately they forgot the "const" decoration on the MetaiMatch()
prototype, but let that omission not leak into our code, let's hide it
away in the innermost use.
2021-11-11 17:22:23 +01:00
Lennart Poettering b78a282181 boot: ternary op is your friend 2021-11-11 17:22:18 +01:00
Lennart Poettering 08cd8c4307 boot: add comments what closely related ConfigEntry fields are about 2021-11-11 17:21:37 +01:00
Jan Janssen 9cf75222f2 meson: Rework gnu-efi detection
Moving all of the gnu-efi detection into src/boot/efi/meson.build makes
more sense than having it partially split.

And thanks to subdir_done() we can simplify the code a lot.

Fixes: #21258
2021-11-10 18:25:19 +00:00
Jan Janssen ad102dd09a sd-boot: Add .osrel section
This allows starting systemd-boot from \EFI\Linux for easier testing
and bisection without risking an unbootable system as the user does not
need to replace their working loader.
2021-11-05 22:11:43 +01:00
Luca Boccassi 8389fd19d2 Merge pull request #20138 from keszybz/coding-style-variable-decls
A coding style tweak and checking of sd_notify() calls and voidification of pager_open()
2021-11-05 13:57:30 +00:00
Jan Janssen d1da890004 sd-boot: Fix efi_arch checks
efi_arch is set to whatever meson returns from host_machine.cpu_family() and
gnu_efi_arch is then set accordingly.

On x86, efi_arch == x86 and gnu_efi_arch == ia32. Surprisingly, compilation
worked (without disabling some instruction sets) and nobody ever complained
about systemd-bootia32.efi not working.
2021-11-04 18:54:31 +01:00
Jan Janssen 1840dfc327 sd-boot: Detect supported compile args
This brings the final list of compiler arguments more in line with
how meson does things. In particular, --buildtype=plain will not
add any optimizations on its own (and would have to be provided
through CFLAGS=).
2021-11-04 18:54:31 +01:00
Jan Janssen f8a738bbc0 sd-boot: Add some link flags
These flags are used by gnu-efi. Adding --no-undefined even allows
us to drop the no-undefined-symbols.sh test in favor of immediate
compile time errors.
2021-11-04 18:54:31 +01:00
Jan Janssen 1f6f233f87 sd-stub: Fix possible memory leak 2021-11-04 18:54:31 +01:00
Jan Janssen 65ff3d2626 sd-boot: Check for existence of required pe sections 2021-11-04 18:48:53 +01:00
Jan Janssen ff9d65f6ff sd-boot: Move optional header verification into verify_pe 2021-11-04 18:37:07 +01:00
Jan Janssen 785b5fcf5f sd-boot: Use FLAGS_SET 2021-11-04 18:37:07 +01:00
Jan Janssen 1224d57ba5 sd-boot: Always compile with -ffreestanding and -fshort-wchar
This is not a hosted environment and we should not pretend otherwise
if -ffreestanding is not supported.

With EFI strings being in UCS2, it is not supported to build without
-fshort-wchar as gcc/clang default to a w_char_t size of 4 bytes.

This also makes the charset for wide chars explicit on gcc. This way
we get a nice error message if anyone ever tries to add 💩 to strings.
2021-11-04 18:37:07 +01:00
Jan Janssen 3c86dcc39c sd-boot: Save and restore console attributes
This also only writes the message on a new line if we aren't at the
beginning of one already.
2021-11-04 18:37:07 +01:00
Zbigniew Jędrzejewski-Szmek 384c2c3239 Make pager_open() return void 2021-11-03 15:24:56 +01:00
Jan Janssen ee4fd9cbd4 sd-boot: Add support to boot last selected entry
Fixes: #18994
2021-10-29 13:57:24 +02:00
Jan Janssen 0c674ce5f2 sd-boot: Allow glob patterns for default and oneshot EFI vars too 2021-10-29 13:57:24 +02:00
Jan Janssen bbe51db664 sd-boot: Keep all EFI var loading together
This also delays the last remaining EFI var write in menu_run.
2021-10-29 13:57:24 +02:00
Lennart Poettering 6663b509d8 bootctl: refuse parsing unknown special '@' entry ids
Let's make sure '@' is never written as entry ID into any EFI variable,
as we want the ability to add new ids like this later on, with them
resulting in a clear error on older implementations.
2021-10-27 22:12:07 +09:00
Jan Janssen e6cab77eca sd-boot: Add keys to reboot into firmware interface
This is useful if the auto-firmware setting has been disabled. The
keys used here are based on what the majority of firmware employ in
the wild.
This also ensures there's a chance for the user to discover this in
case they were too slow during POST or simply used the wrong ones.
2021-10-22 19:12:55 +02:00
Jan Janssen c496451216 sd-boot: Be more precise about secure boot modes
Fixes: #11559
2021-10-22 10:08:38 +02:00
Zbigniew Jędrzejewski-Szmek 97c373c7de Merge pull request #21065 from keszybz/efi-warnings
Clean up unused variables in efi code
2021-10-21 08:33:08 +02:00
Dimitri Papadopoulos ba669952b2 Typos found by codespell 2021-10-20 22:20:18 +09:00
Zbigniew Jędrzejewski-Szmek 2fffe2ed19 efi: check input parameter
clang complained about an unused variable. We cast the buffer to
struct boot_params, so let's check that it's at least this long.
2021-10-20 14:20:44 +02:00
Zbigniew Jędrzejewski-Szmek f3611cfb0b efi: drop two unused variables
It seems the code was added in 2553a5482c and
those two were never used for anything.
2021-10-20 13:58:03 +02:00
Jan Janssen a36a0d1540 macro: Move ALIGN_TO to macro-fundamental.h and introduce CONST_ALIGN_TO 2021-10-17 11:56:05 +02:00
Jan Janssen 53f69d671c sd-boot: Require gnu-efi 3.0.5
This version is from 2017 and should be stale enough to not cause
an outrage. All the relevant distros have it or a newer version.

We also already depend on some symbols defined in 3.0.5 anyway,
so let's take the opportunity to reduce our missing_efi.h
baggage.
2021-10-17 11:56:05 +02:00
Jan Janssen 12f32748aa sd-boot: Get rid of uefi_call_wrapper
The uefi_call_wrapper exists to convert to the right calling convention
and presumably predates compilers that can do so natively. The only
architecture where this is even needed is x86_64.
But because we are building with GNU_EFI_USE_MS_ABI defined, the
EFIAPI macro tells the compiler to use the right calling convention
for EFI functions. Our shim callback (which is called by EFI itself)
already relies on this.

This also adds a safety check to make se we are compiling with
GNU_EFI_USE_MS_ABI defined and also adds it to the compiler args
unconditionally. It is only used with x86_64 anyways, so it should
be fine to do so. EFI_FUNCTION_WRAPPER is unused in gnu-efi, so
it is dropped.
2021-10-17 11:55:57 +02:00
Jan Janssen 70cd15e97b sd-boot: Convert VOID -> void
We are already using void in several places and having a screaming
typedef for void feels pointless. There are also CONST, IN, OUT
and OPTIONAL which we aren't using either.

This leaves missing_efi.h to keep it in line with how they are
defined in gnu-efi and/or the specs.
2021-10-17 11:54:17 +02:00
Jan Janssen f69434002c sd-boot: Rework print_status()
A little helper function and some unusual formatting makes this
whole thing a lot easier on the eyes. Also, right-aligning the
properties for better readability at runtime.
2021-10-17 11:52:36 +02:00
Jan Janssen 6ae9a5a0bb sd-boot: Rearm the watchdog in console_key_read
Let's not disable the watchdog at all and instead rearm it inside
of console_key_read(). This way, we are covered by the watchdog everywhere.
2021-10-17 11:52:36 +02:00
Jan Janssen 9f04812331 sd-boot: Check for OOM in some places 2021-10-17 11:52:36 +02:00
Max Resch 33bc9b756e [sd-stub] add support for embedding devicetree 2021-10-15 21:47:42 +02:00
Lennart Poettering 0a51337df1 Merge pull request #20983 from mxre/feature/aarch64
[sd-stub] Add support for aarch64 booting via pe-entry point
2021-10-15 10:26:10 +02:00
Lennart Poettering 2f82562bad alloc-util: add strdupa_safe() + strndupa_safe() and use it everywhere
Let's define two helpers strdupa_safe() + strndupa_safe() which do the
same as their non-safe counterparts, except that they abort if called
with allocations larger than ALLOCA_MAX.

This should ensure that all our alloca() based allocations are subject
to this limit.

afaics glibc offers three alloca() based APIs: alloca() itself,
strndupa() + strdupa(). With this we have now replacements for all of
them, that take the limit into account.
2021-10-14 15:57:52 +02:00
Max Resch dc46792831 [sd-stub] Add support for aarch64 booting via pe-entry point 2021-10-13 18:20:32 +02:00
Jan Janssen a69702c5ea sd-boot: Move security and console control protocol to missing_efi.h
This also fixes a broken #ifdefs in the header itself.
2021-10-12 09:56:54 +02:00
Jan Janssen 4ec9d873f3 sd-boot: Use _cleanup_ in more places 2021-10-12 09:56:23 +02:00
Jan Janssen 19dd3995aa sd-boot: Remove unnecessary TPM conditionalization
This is already done in measure.h.
2021-10-12 09:56:02 +02:00
Jan Janssen d09065f894 sd-boot: Use backup LBA location from first GPT header
If a disk were dd'd to a lager block device, the last block on it
is not necessarily the backup header.
2021-10-12 09:55:49 +02:00
Jan Janssen 393955fd21 sd-boot: Split up xbootldr_open() 2021-10-12 09:55:21 +02:00
Jan Janssen 423523e063 sd-boot: Fix xbootldr detection
The broken crc32 calculation was a copy pasta error introduced in
87167331c9 and luckily has never been
shipped yet.
2021-10-12 09:54:04 +02:00
Jan Janssen bcbc3e81d3 sd-boot: Move xbootldr code into its own file 2021-10-12 09:53:48 +02:00
Jan Janssen 6e7bb7d3ee sd-boot: Invert if in disk_get_part_uuid() 2021-10-12 09:53:16 +02:00