Commit graph

94 commits

Author SHA1 Message Date
Daniel Fullmer e6190e2882 sd-boot: fix menu ordering with boot counting
systemd-boot selects the last valid entry by default, not the first.

Fixes: #15256
2020-05-26 19:27:59 +02:00
Frantisek Sumsal 86b52a3958 tree-wide: fix spelling errors
Based on a report from Fossies.org using Codespell.

Followup to #15436
2020-04-21 23:21:08 +02:00
Jan Janssen 904ebcb200 sd-boot: Add → as alternative to boot selected entry
This is sometimes slightly more convenient to use
and is also what GRUB supports.
2020-04-15 21:29:41 +01:00
Yu Watanabe efda8aebcb sd-boot: fix -Wpointer-sign warning 2020-01-31 19:59:34 +09:00
Yu Watanabe a14c18ba7b sd-boot: fix typo
Fixes #14657.
2020-01-26 13:20:21 +09:00
Lennart Poettering 4353974d75 boot: fix osrel parser
let's check VERSION instead of VERSION_ID where appropriate.

Fixes: #14493
2020-01-07 19:32:14 +00:00
Zbigniew Jędrzejewski-Szmek 41ab3b7a85
Merge pull request #13953 from SpencerMichaels/systemd-boot-efistub-id-fix
boot: Fix default/oneshot selection for EFISTUB entries
2019-12-04 13:30:52 +01:00
Leonid Bloch 26601a2a17 sd-boot: Add a 0.1 second delay before key-probing for showing menu
If there is no boot menu timeout, pressing a key during boot should get
the boot menu displayed. However, on some systems the keyboard is not
initialized right away, which causes the menu to be inaccessible if no
timeout is specified.

To resolve this, if the error is "not ready" after the initial attempt of
detection, wait for 0.1 second and retry. This solves the problem
described above on all the tested systems.

The reason for just a single retry, and not retrying while "not ready",
is that some firmwares continue to return the "not ready" error on
every probe attempt if no key is pressed.

Signed-off-by: Leonid Bloch <lb.workbox@gmail.com>
2019-12-04 10:52:28 +01:00
Spencer Michaels 10d0024a07 boot: Improve EFISTUB name and version detection.
Make two minor cosmetic changes to how config_entry_add_linux() extracts
OS information from the embedded /etc/os-release in EFISTUB binaries.
This increases the detail of information available to the user for
EFISTUB entries.

* entry->version, which was previously always null, is now set to the
value of VERSION, or VERSION_ID, or BUILD_ID (preferred in that order).
* entry->title, which was previously set to the value of PRETTY_NAME, can
now fall back to NAME or ID if PRETTY_NAME is not present. In that case,
NAME is preferred over ID.
2019-11-18 22:59:51 -08:00
Spencer Michaels 6cd12ebcfe boot: Retain ".conf" suffix for loader config IDs.
Change config_entry_add_from_file() so that it does not remove the
`.conf` ending from the filename that it uses for entry->id. This is
necessary because otherwise an EFISTUB binary and a loader config entry
might end up with the same ID, as the loader config IDs previously
didn't include the config filename's .conf extension (see boot.c:1435).
Consider, for instance, an EFISTUB /EFI/Linux/linux.efi and a loader
config /loader/entries/linux.efi.conf; both would have the ID linux.efi.

In addition, update a comment that previously stated that IDs are
non-unique (which is no longer the case, as of this commit).
2019-11-18 22:59:51 -08:00
Spencer Michaels 65901c0fd1 boot: Ignore EFISTUB binaries starting with "auto-".
To further increase similarity with loader configs and provide global
uniqueness, ignore filenames starting with auto- (see boot.c:1512).
2019-11-18 22:59:51 -08:00
Spencer Michaels 7fa23ab646 boot: Make EFISTUB IDs use binaries' filenames.
Change config_entry_add_linux() so that Linux EFISTUB entries' ids are
simply the binaries' filenames, as is already the case with loader
configs. This guarantees that EFISTUB binaries' IDs are mutually unique.
2019-11-18 22:59:44 -08:00
Jan Janssen f9f1d01cbd sd-boot: Skip adding boot entries when the loader does not exist 2019-11-04 13:39:20 +01:00
Jan Janssen d9690d8fe9 sd-boot: Silence compiler warning when building with -O2 2019-10-30 17:47:55 +01:00
Lennart Poettering e4dcf7aa52 sd-boot: read random seed from ESP and pass it to OS 2019-07-25 18:16:46 +02:00
Lennart Poettering 7c122dfef8 bootctl: shortcut configuration file parsing 2019-07-25 17:10:51 +02:00
Lennart Poettering 67633c078c efi: remove trailing whitespace in string 2019-07-24 08:56:10 +09:00
Zbigniew Jędrzejewski-Szmek 3a76fbe01c bootctl,sd-boot: define EFI_LOADER_FEATURE_XBOOTLDR
It was added back in fa2a3bbdd8, but we
forgot to add the feature define.
2019-07-10 15:02:33 +02:00
Zbigniew Jędrzejewski-Szmek 91b08bb00f boot,shared: share the definitions of EFI_LOADER_FEATURE macros
This means the the code needs to be kept compatible in the shared header,
but I think that still nicer than having two places to declare the same
things.

I added src/boot to -I, so that efi/foo.h needs to be used. This reduces
the potential for accidentally including the wrong header.
2019-07-10 14:59:48 +02:00
Lennart Poettering c1db999eb8 boot: use TAKE_PTR() where appropriate 2019-04-02 14:54:42 +02:00
Zbigniew Jędrzejewski-Szmek 7a2cb0228c boot: avoid 32-bit calculation for a 64-bit lvalue
Coverity CID#1399116:
> Potentially overflowing expression
> gpt_header_buffer.gpt_header.SizeOfPartitionEntry * gpt_header_buffer.gpt_header.NumberOfPartitionEntries
> with type unsigned int (32 bits, unsigned) is evaluated using 32-bit
> arithmetic, and then used in a context that expects an expression of type
> UINTN (64 bits, unsigned).

Let's import the ALIGN_TO macro to sd-boot and use it to avoid the issue.
2019-03-12 13:32:45 +01:00
Zbigniew Jędrzejewski-Szmek ff19ad888d efi: wrap some long lines 2019-03-08 11:04:16 +01:00
Lennart Poettering 5d87589732 sd-boot: don't print error string where there's no error code known 2019-03-01 12:41:32 +01:00
Lennart Poettering fa2a3bbdd8 sd-boot: also look for boot loader entries in the XBOOTLDR partition
The specification always said so, let's actually implement this.

Unfortunately UEFI's own APIs don't allow us to search for partition
type GUID, hence we have to implement a minimal GPT parser ourselves.
2019-03-01 12:41:32 +01:00
Lennart Poettering 17ad0f0f4b sd-boot: don't dereference NULL ptr if loaded_image_path is NULL
In a follow-up commit we'd like to invoke config_entry_add_from_file()
on partitions that are not the ESP, let's prepare fpr that and allow
loaded_image_path to be passed as NULL.
2019-03-01 12:41:32 +01:00
Lennart Poettering c8ad5996b0 sd-boot: pass device handle to config_entry_add_linux()
This makes the code a bit simpler (after all the call is not interested
in the loaded image, just where it is found), and more like
config_load_entries() which takes the same arguments.

This also makes things easier for us later on, when we add support for
discovering images in $XBOOTLDR partitions.
2019-03-01 12:41:32 +01:00
Louis Taylor e768a4f032 tree-wide: use '"' instead of '\"'
The escape used previously was redundant and made things more confusing.
2019-01-17 16:46:29 +00:00
Zbigniew Jędrzejewski-Szmek 681bd2c524 meson: generate version tag from git
$ build/systemctl --version
systemd 239-3555-g6178cbb5b5
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid
$ git tag v240 -m 'v240'
$ ninja -C build
ninja: Entering directory `build'
[76/76] Linking target fuzz-unit-file.
$ build/systemctl --version
systemd 240
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid

This is very useful during development, because a precise version string is
embedded in the build product and displayed during boot, so we don't have to
guess answers for questions like "did I just boot the latest version or the one
from before?".

This change creates an overhead for "noop" builds. On my laptop, 'ninja -C
build' that does nothing goes from 0.1 to 0.5 s. It would be nice to avoid
this, but I think that <1 s is still acceptable.

Fixes #7183.

PACKAGE_VERSION is renamed to GIT_VERSION, to make it obvious that this is the
more dynamically changing version string.

Why save to a file? It would be easy to generate the version tag using
run_command(), but we want to go through a file so that stuff gets rebuilt when
this file changes. If we just defined an variable in meson, ninja wouldn't know
it needs to rebuild things.
2018-12-21 13:43:20 +01:00
Yu Watanabe d949c467b8 sd-boot: fix trailing whitespace trimming
Fixes #10922.
2018-11-26 06:43:36 +09:00
Lennart Poettering 996daf2fa9 sd-boot: make sure special menu items also work if menu is skipped
While it doesn't really make much sense to set "auto-reboot-to-firmware"
as oneshot boot item, let's still support it properly, by also
dispatching such a menu item if selected.
2018-11-16 15:47:18 +01:00
Lennart Poettering aec1443aec sd-boot: use structured initialization 2018-11-16 15:47:18 +01:00
Lennart Poettering b58c7351c0 sd-boot: change name of automatic entry for rebooting into firmware
Let's stick to one nomenclature. In userspace we usually call this
"reboot to firmware setup", hence use the same name in sd-boot too.

This name was previously only relevant internally, but since the
addition of the LoaderEntries EFI var is exposed to userspace, hence
let's get this right with the first release adding this.
2018-11-16 15:47:18 +01:00
Lennart Poettering 5dd5f7cfa8 sd-boot: add new EFI variable exposing feature set of boot loader
We keep adding new features, let's advertise to the host OS what these
are in a new variable LoaderFeatures.

It works a bit like OsIndicationsSupported, but is about Loader
features.
2018-11-16 15:47:18 +01:00
Lennart Poettering fe2579dd9c sd-boot: introduce a one-time override for the boot menu timeout
This is useful to allow userspace to request a "boot into boot menu"
feature.
2018-11-16 15:47:18 +01:00
Lennart Poettering 2366d92345 sd-boot: when converting menu timeout for UINTN to INTN saturate
Let's be a bit more careful and handle overly long timeouts in a
slightly more sensible way.
2018-11-16 15:47:18 +01:00
Lennart Poettering 8ac694710f sd-boot: timeout_sec is unsigned hence show it with %u 2018-11-16 15:47:18 +01:00
Lennart Poettering 535610b561 sd-boot: factor out searching for loader entry 2018-10-16 16:44:34 +02:00
Lennart Poettering 7f1ef12526 sd-boot: also set an ID for the reboot-into-firmware entry 2018-10-16 16:44:34 +02:00
Lennart Poettering 0e2bc73274 sd-boot: write the IDs of all discovered entries to an EFI variable
This is primarily useful for debugging, but can be useful for other
purposes too. For example userspace could check whether "auto-windows"
is included in the list, before triggering a boot-into-windows
operation.
2018-10-16 16:44:34 +02:00
Lennart Poettering f82ecab0a9 efi: make efivar_set_raw() buffer argument VOID*
No need to define a type if it is just some arbitrary buffer for us
anyway.
2018-10-16 16:44:34 +02:00
Lennart Poettering f538cc6548 sd-boot: add boot counting mechanism 2018-10-16 16:44:34 +02:00
Lennart Poettering 64e7e27cd4 sd-boot: coding style fix, don't rely on C's downgrade-to-bool feature for numerical values 2018-10-16 16:44:34 +02:00
Lennart Poettering 2214cfbf50 sd-boot: simplify memory management in processing of unified kernel image a bit 2018-10-16 16:44:34 +02:00
Lennart Poettering 42cf81c26f sd-boot: properly free all config entry fields 2018-10-16 16:44:34 +02:00
Lennart Poettering 081cc95fec sd-boot: rename ConfigEntry field 'file' to 'id'
The field derives from a file name only in very specific cases, for
many cases it's a fixed string (for example, all "auto-" items are like
this). Also, even when it derives from a file name, it is processed a
bit, as suffixes are removed and the string is converted to lower case.

hence, let's name this field "id" instead, because that's what it is
used for: as general identification token.
2018-10-16 16:44:34 +02:00
Lennart Poettering 580fe4df59 sd-boot: break overly long function argument lists following our usual coding style 2018-10-16 16:44:34 +02:00
Lennart Poettering 1336bb9864 sd-boot: drop initialization of 'line' which we override in the next line anyway 2018-10-16 16:44:34 +02:00
Zbigniew Jędrzejewski-Szmek d3a27ed402 boot: do not assume the last character in cmdline is a newline
Fixes #9401.
2018-06-25 11:17:53 +02:00
Zbigniew Jędrzejewski-Szmek 25612ecba4 tree-wide: drop copyright lines for more authors
Acks in https://github.com/systemd/systemd/issues/9320.
2018-06-22 16:39:45 +02:00
Zbigniew Jędrzejewski-Szmek d9b02e1697 tree-wide: drop copyright headers from frequent contributors
Fixes #9320.

for p in Shapovalov Chevalier Rozhkov Sievers Mack Herrmann Schmidt Rudenberg Sahani Landden Andersen Watanabe; do
  git grep -e 'Copyright.*'$p -l|xargs perl -i -0pe 's|/([*][*])?[*]\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\s*[*]([*][*])?/\n*|\n|gms; s|\s+([*#]\s+)?Copyright[^\n]*'$p'[^\n]*\n*|\n|gms'
done
2018-06-20 11:58:53 +02:00