Commit Graph
793 Commits
Author SHA1 Message Date
Yu Watanabe 8f7a0fcbec meson: fix typo 2021-12-23 17:01:55 +09:00
Jan Janssen 2ef28d054d boot: Use -fvisibility=hidden instead of -fwhole-program
It's functionally the same for sd-boot, but using visibilty
is generally preferred over whole-program.
2021-12-23 00:26:25 +09:00
Jan Janssen e67e6691e5 boot: Fix armhf build failure
Fixes: #21842
2021-12-21 16:34:51 +00:00
Zbigniew Jędrzejewski-Szmek 1ff493d5c1 bootctl: deprecate --make-machine-id-directory=auto
Now that kernel-install creates the machine-id directory, we don't need to do
this is 'bootctl install', and in fact it's better not to do this since it
might never be necessary. So let's change the default behaviour to 'no'.

I kept support for 'auto' to maintain backwards compatibility, even though the
default was changed. Previous behaviour can be requested by specifying
--make-machine-id-directory=auto.
2021-12-17 18:48:08 +01:00
Zbigniew Jędrzejewski-Szmek 47fb161e3a bootctl: write KERNEL_INSTALL_LAYOUT=bls and KERNEL_INSTALL_MACHINE_ID=…
This is a natural extension of d6bce6e224: if we are installing sd-boot, we
want to use the sd-boot layout, so let's write the appropriate
KERNEL_INSTALL_LAYOUT setting. Effectively, if we do 'booctl install',
kernel-install will not autodetect the layout anymore.

And 357376d0bb added support for KERNEL_INSTALL_MACHINE_ID. We need to support
it here too. We both read it, so that we create the right directories, and also
write it if it wasn't written yet and we created some directories using it, so
that kernel-install that is executed later knows the machine-id that matches
the directories we crated.

The code is changed in some places to fail if we can't figure out the current
status. When installing the boot loader it's probably better not to guess.
2021-12-17 18:47:53 +01:00
Yu Watanabe 616f51c16d boot: fix typo 2021-12-17 04:11:41 +09:00
Zbigniew Jędrzejewski-Szmek af3b864d76 Define FOREACH_DIRENT through FOREACH_DIRENT_ALL
As in the previous commit, 'de' is used as the iterator variable name.
2021-12-15 22:50:00 +01:00
Jan Janssen db7f5ab68f test: Add BCD unit test 2021-12-11 21:32:29 +01:00
Jan Janssen 986fd3ebc2 boot: Remove unused memmem_safe 2021-12-11 21:32:29 +01:00
Jan Janssen f7bc0fb35b boot: Add BCD store parser
This replaces the memmem-based approach of finding a suitable title
for the windows boot manager with one that actually parses the BCD
store. It's probably faster but more importantly, it's more correct.

The memmem approach may detect stale title strings that are still
in the file but unused due to the way registry hives are updated.
This approach also allows us to detect if the BCD store is multi-boot
so that we can fall back on the generic one instead.
2021-12-11 21:32:23 +01:00
Jan Janssen 7700e9ba15 boot: Make OFFSETOF lowercase
This is more in line with the userspace offsetof.
2021-12-11 20:50:03 +01:00
Jan Janssen 245e9d55ae boot: Add strncasecmpa helper function 2021-12-11 20:50:03 +01:00
Jan Janssen 3af5a8c613 meson: Fix gnu-efi detection for clang
The gnu-efi headers emit some warnings in clang when not compiled with
-ffreestanding. This is normally not an issue for has_header_symbol()
unless meson is run with CFLAGS="-Werror". Note that this differs
from the --werror option, which does not get passed to clang.

Work around this by adding some compile args to the has_header_symbol()
invocation.
2021-12-12 04:31:41 +09:00
Zbigniew Jędrzejewski-Szmek 881ab17ef7 Merge pull request #21570 from AdrianVovk/stub-global-creds
stub: Load credentials from \loader\credentials\*.cred
2021-12-11 15:59:10 +01:00
Jan Janssen 1ad2c76d5d meson: Auto detect efi-ld 2021-12-11 11:29:30 +01:00
Adrian Vovk f3b6f33387 stub: Load credentials from \loader\credentials\*.cred
Some types of credentials that a user would want to pass
into the initrd do not depend on the specific kernel/initrd
version. For instance, this can include SSH keys, rootfs
encryption keys, dm-integrity keys, and so on. This
introduces a directory where such credentials can be placed
so that any kernel image will load them
2021-12-10 15:56:33 -05:00
Дамјан Георгиевски 12caf72716 bootctl: optionally install .signed efi file
if /usr/lib/systemd/boot/efi/systemd-bootx64.efi.signed exists
install that instead of /usr/lib/systemd/boot/efi/systemd-bootx64.efi

the idea is that SecureBoot tooling can create the efi.signed file
whenever /usr/lib/systemd/boot/efi/systemd-bootx64.efi from the package
is updated.
2021-12-08 22:21:34 +01:00
Adrian Vovk bf3f4d16d6 stub: Properly null-terminate filenames in pack_cpio_one
Previously, mangle_filename would write the null terminator, but
then wouldn't increment the pointer. Thus, the pad4 call that comes
immediately after mangle_filename would trample over the null
terminator that mangle_filename wrote. Since the padding is all
0s, this happened to work for the filenames it was tested for

However, in some cases, this would cause the pointer to be a different
position than predicted. Basically, the predicted size would be one
byte bigger than the actual size (the missing null terminator). Usually,
this disappeared into the alignment padding at the end of the buffer,
but if the buffer was already unexpectedly aligned (b/c it was a byte
shorter than expected), this would cause assertion failures.

Also, the c_namesize field in the cpio header was incorrect. It
didn't include the null terminator, as required by the spec.
2021-12-08 13:57:01 -05:00
Zbigniew Jędrzejewski-Szmek 3944ef20f5 Merge pull request #21264 from medhefgo/boot-lto
sd-boot: LTO support
2021-12-07 12:58:59 +01:00
Zbigniew Jędrzejewski-Szmek ed0e6f0f71 Merge pull request #21307 from medhefgo/boot-alloc
sd-boot: Non-failing allocators
2021-12-07 08:20:07 +01:00
Yu Watanabe a783421498 tree-wide: fix typo 2021-12-02 00:51:02 +09:00
Yu Watanabe a6f44d610c tree-wide: fix typo 2021-11-30 12:30:07 +00:00
Jan Janssen 0289441e09 sd-boot: Fix assert failure in random-seed.c
Fixes: #21556
2021-11-30 03:10:03 +09:00
Jan Janssen 0a15a824d2 sd-boot: Use non-failing allocators everywhere else 2021-11-29 16:20:45 +01:00
Jan Janssen ccfbdbdcab sd-boot: Simplify path creation 2021-11-29 16:20:45 +01:00
Jan Janssen 4f94341504 sd-boot: Make stra_to_path/stra_to_str non-failing 2021-11-29 16:20:45 +01:00
Jan Janssen da76f890aa sd-boot: Use non-failing allocators in boot.c 2021-11-29 16:20:45 +01:00
Jan Janssen 484ddd2926 sd-boot: Add non-failing allocators 2021-11-29 16:20:32 +01:00
Jan Janssen fd86250c1e sd-boot: Always add TextInputEx to wait queue if available 2021-11-29 14:42:18 +01:00
Jan Janssen b848b7e166 sd-boot: Add LTO support 2021-11-29 14:41:46 +01:00
Jan Janssen 0e3bcb02d2 sd-boot: Let compiler figure out libgcc location
Since we now let the compiler call the linker for us, we can just
rely on it to find the right (static) libgcc to use.
2021-11-29 14:33:26 +01:00
Jan Janssen fe330f02df sd-boot: Let the compiler invoke the linker for us
For LTO to work, the linker has to be called with some magic sauce arguments.
And the easiest way to get those is to just let the compiler to the job for us.
2021-11-29 14:24:56 +01:00
Jan Janssen 52ccce6ac5 meson: Rename compile_args to efi_cfalgs
compile_args sounds like it could be used for other targets besides
efi binaries. This also keeps the name in line with efi_ldflags.
2021-11-28 16:22:15 +01:00
Jan Janssen 252b6b1bfd meson: Default to sbat-distro=auto
Any recent shim will refuse starting an image that does not have an sbat section
and will do so with a generic "Security Violation" message. And it is very easy
to forget passing -Dsbat-distro=auto to meson when creating a fresh build dir.

Adding sbat info when shim is not used or secure boot is disabled does not hurt
anyone, so default to auto. This still ensures to not add auto-detected info in
case we are cross building.
2021-11-28 16:20:54 +01:00
Lennart Poettering ae54abe7fe bootctl: use new red/green check/cross mark helpers at two places 2021-11-23 22:40:15 +01:00
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