Commit graph

419 commits

Author SHA1 Message Date
Yu Watanabe a8a7e5fcf2 bless-boot: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 18:40:02 +01:00
Yu Watanabe 608f8ec92e bootctl: use static destructor and DEFINE_MAIN_FUNCTION() macro 2018-11-20 16:48:21 +01:00
Lennart Poettering afe44c8ffd generators: introduce a common implementation for the log setup boilerplate 2018-11-20 10:57:50 +01:00
Lennart Poettering 012c2f761b tree-wide: use __ prefixed gcc attributes (#10843)
As suggest here:

https://gcc.gnu.org/onlinedocs/gcc/Attribute-Syntax.html#Attribute-Syntax

    "You may optionally specify attribute names with ‘__’ preceding and
    following the name. This allows you to use them in header files without
    being concerned about a possible macro of the same name. For example,
    you may use the attribute name __noreturn__ instead of noreturn. "
2018-11-20 12:34:08 +09:00
Lennart Poettering 5e332028f2 util-lib: move main() definition macros to its own header file
This way, we can extend the macro a bit with stuff pulled in from other
headers without this affecting everything which pulls in macro.h, which
is one of our most basic headers.

This is just refactoring, no change in behaviour, in prepartion for
later changes.
2018-11-19 21:14:34 +01:00
Lennart Poettering 2a44bf5099
Merge pull request #10811 from keszybz/define-main-through-macro
Define main through macro
2018-11-19 15:28:17 +01:00
Zbigniew Jędrzejewski-Szmek 02434ea263 boot-check-no-failures: define main through macro 2018-11-17 09:13:35 +01:00
Lennart Poettering 1b259a5bf3
Merge pull request #10804 from poettering/sd-boot-updates
various sd-boot/EFI fixes (split out from #10495)
2018-11-16 17:52:37 +01:00
Lennart Poettering 80641a81b6 bootctl: display loader features in a pretty way. 2018-11-16 15:52:22 +01:00
Lennart Poettering c027b67f53 util: force time multiplications to happen in longs 2018-11-16 15:52:22 +01:00
Lennart Poettering 3b42f34910 efi: NUL terminate strings read with efivar_get()
let's be more careful and NUL terminate everything we read from EFI
variables, in case it isn't already.
2018-11-16 15:47:18 +01: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 95a18e91db efi: make sure parse_boolean() does something useful on a NULL parameter 2018-11-16 15:47:18 +01:00
Lennart Poettering 427ee7ec82 efi: add 'const' to various util.h API parameters 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 b49dd00f8c efi: add simple macros for MAX values of EFI's UINTN/INTN types 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
Zbigniew Jędrzejewski-Szmek 0221d68a13 basic/pager: convert the pager options to a flags argument
Pretty much everything uses just the first argument, and this doesn't make this
common pattern more complicated, but makes it simpler to pass multiple options.
2018-11-14 16:25:11 +01:00
Lennart Poettering a2689fa5fc
Merge pull request #9437 from poettering/sd-boot-count
many sd-boot/bootctl fixes, and a new "boot counting" concept, for automatic fallback to older kernels on persistent failures
2018-10-19 23:04:22 +02:00
Lennart Poettering f876f53789 units: add simple boot check unit
This is might be useful in some cases, but it's primarily an example for
a boot check service that can be plugged before boot-complete.target.

It's disabled by default.

All it does is check whether the failed unit count is zero
2018-10-19 22:34:50 +02:00
Lennart Poettering 8d16ed0785 add "systemd-bless-boot-generator"
This generator automatically pulls in "systemd-bless-boot.service" if
a boot with boot counting is detected.
2018-10-19 22:34:50 +02:00
Lennart Poettering 36695e880a add new systemd-bless-boot.service that marks boots as successful
This is the counterpiece to the boot counting implemented in
systemd-boot: if a boot is detected as successful we mark drop the
counter again from the booted snippet or kernel image.
2018-10-19 22:34:50 +02:00
Yu Watanabe 7709ef3a70 bootctl: include error cause in log message 2018-10-20 00:52:45 +09:00
Lennart Poettering 0fef958361 efi: rework OFFSETOF() based on __builtin_offsetof()
Since both LLVM and gcc supported this for a long time, we are not
adding a fallback compat kludge. And even if there's some relevant
compiler that doesn't know this concept, it'll fail with a compiler
error, and we'll fix it then.

As suggested by @keszybz:

https://github.com/systemd/systemd/pull/10174#discussion_r226266540
2018-10-18 19:01:54 +02: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 05907f25a5 sd-boot: remove left-over lgpl blurb 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
Lennart Poettering 2880e665ab efi: explicity check for NULL in FreePoolp()
Firmware implementations are generally pretty bad, hence let's better
add an explicit check for NULL before invokin FreePool(), in particular
is it doesn't appear to be documented whether FreePool() is supposed to
be happy with NULL.
2018-10-16 16:44:34 +02:00
Lennart Poettering 3aaa95e0a0 efi: add cleanup handler for closing file descriptors 2018-10-16 16:44:34 +02:00
Lennart Poettering b73acaed42 efi: add poor man's offsetof() implementation 2018-10-16 16:44:34 +02:00
David Tardon de699c7a06 console: avoid promotion to signed int
coverity message:
sign_extension: Suspicious implicit sign extension: "keydata.Key.ScanCode" with type "UINT16" (16 bits, unsigned) is promoted in "keydata.Key.ScanCode << 16" to type "int" (32 bits, signed), then sign-extended to type "unsigned long" (64 bits, unsigned).  If "keydata.Key.ScanCode << 16" is greater than 0x7FFFFFFF, the upper bits of the result will all be 1.
2018-10-12 12:38:41 +02:00
Lennart Poettering bd2865caf6 bootctl: include boot entries discovered by the boot loader but not in $BOOT in the "list" output
Let's use the new LoaderEntries efi var for this, and show all entries
we couldn't find via the config snippets.
2018-10-08 21:40:44 +02:00
Lennart Poettering d88c96ffe5 bootctl: add new verbs for setting the default boot/oneshot entry
Fixes: #5739 #8574
2018-10-08 21:40:44 +02:00
Lennart Poettering 57db6f18d4 bootctl: add auto-paging 2018-10-08 21:40:44 +02:00
Lennart Poettering ba85725324 bootctl: highlight various title/product fields in output 2018-10-08 21:40:44 +02:00
Lennart Poettering 20a28174c5 bootctl: unify the code which we use to show boot loader entries 2018-10-08 21:40:44 +02:00
Lennart Poettering 48184e4391 bootctl: downgrade to log messages that aren't actually errors 2018-10-08 21:40:44 +02:00
Lennart Poettering 7fd66f3c3d bootctl: reword status/list section headers a bit
This is really confusing, let's try to clean this up a bit, in
particular as there are two very similar concepts:

1. The boot loaders, i.e. the category you find systemd-boot, the
   Windows and Apple boot loaders in. These may typically be listed in the
   firmware's EFI variables.

2. The boot loader entries, as defined by the Boot Loader Spec. In this
   category you find the various Linux kernels that are installed, i.e.
   the stuff systemd-boot shows on screen. To make things confusing, the
   Windows and Apple boot loaders can appear both as boot loaders and as
   boot loader entries.

This tries to establish the following nomenclature: "boot loaders" and
"boot loader entries" for these two concepts.
2018-10-08 21:40:44 +02:00
Lennart Poettering a099e0352c bootctl: show 'Default Boot Entry' header only when we found something 2018-10-08 21:40:44 +02:00
Lennart Poettering 21f7a622d5 bootspec: remove redundant logging
boot_loader_read_conf(), boot_entries_find(), boot_entries_load_config()
all log their errors internally, hence no need to log a second or third
time about the same error when they return.
2018-10-08 21:40:44 +02:00
Lennart Poettering a36b411ea2 bootctl: tiny shortification 2018-10-08 21:40:44 +02:00
Lennart Poettering e0e8d177c8 bootctl: let's be paranoid and synchronize the ESP in full after all changes
We already synchronize all files we write individually, as well as the
directories they are stored in. Let's also synchronize the ESP as a
whole after our work, just in case.
2018-10-08 21:40:44 +02:00
Lennart Poettering 1634ebb54a
Merge pull request #10262 from keszybz/hibres-disable
Switches to disable hibernation and/or resuming
2018-10-08 21:39:54 +02:00
Zbigniew Jędrzejewski-Szmek cac4d95ec8 boot: change multiplication order
LGTM was complaining:
> Multiplication result may overflow 'unsigned int' before it is converted to 'unsigned long'.
2018-10-02 12:54:00 +02:00
Mike Gilbert 5f723125ae meson: avoid calling the shell to resolve efi_libdir 2018-09-30 16:22:07 -04:00
Mike Gilbert 595343fb4c meson: use an array option for efi-cc
Fixes: https://github.com/systemd/systemd/issues/10211
2018-09-30 15:43:39 -04:00
Helmut Grohne df7cacae69 meson: use the host architecture compiler/linker for src/boot/efi
cross building systemd to arm64 presently fails, because the build
system uses plain gcc and plain ld (build architecture compiler and
linker respectively) for building src/boot/efi. These values come from
the efi-cc and efi-ld options respectively. It rather should be using
host tools here.

Fixes: b710072da4 ("add support for building efi modules")
2018-09-28 14:42:56 +02:00
Lennart Poettering 12580bc3ed bootspec: rename "filename" field to "id"
This follows the renaming done a few commits earlier too systemd-boot
itself.

Also, let's show the ID, since it's useful.
2018-09-27 17:31:37 +02:00
Zbigniew Jędrzejewski-Szmek 938be08926 meson: disable _all_ tests when -Dtests=false
Back in 08318a2c5a, value "false" was enabled for
'-Dtests=', but various tests were not conditionalized properly. So even with
-Dtests=false -Dslow-tests=false we'd run 120 tests. Let's make this consistent.
2018-09-13 12:07:34 +02:00
Harald Hoyer 15720d0340 boot/efi/stub.c: fix Dell LoadOptions
On Dell machines LoadOptions is filled with:
01 00 00 00 <name of BIOS Boot Loader Entry> ... <unknown bytes>

So, in case of meaningfull LoadOptions, better check if the first char
is a printable character.
2018-09-03 14:10:38 +02:00
Yu Watanabe 7a3c343cb8 tree-wide: use '#pragma once' for header guard
Follow-up for a2b635eb39 (#9959).
2018-08-30 06:10:43 +03:00
Yu Watanabe a2b635eb39 sd-boot: fix header guard
Follow-up for a42d7cf165.
2018-08-29 23:05:15 +09:00
Lennart Poettering 37ec0fdd34 tree-wide: add clickable man page link to all --help texts
This is a bit like the info link in most of GNU's --help texts, but we
don't do info but man pages, and we make them properly clickable on
terminal supporting that, because awesome.

I think it's generally advisable to link up our (brief) --help texts and
our (more comprehensive) man pages a bit, so this should be an easy and
straight-forward way to do it.
2018-08-20 11:33:04 +02:00
Zbigniew Jędrzejewski-Szmek 5a8b164092 meson: drop parens when appending to list
Meson does not care either way, so let's use the simpler syntax. And files()
already gives a list, so nesting this in a list wouldn't be necessary even
if meson did not flatten everything.
2018-07-31 21:02:01 +09:00
Yu Watanabe a0cb8078b1 meson: drop redundant messages
The equivalent messages are shown in the last summary.
2018-07-23 14:03:05 +02:00
Yu Watanabe f330408d62 tree-wide: drop empty lines in comments 2018-07-23 08:44:24 +02:00
Lennart Poettering 2919425bab
Merge pull request #9398 from yuwata/lgtm-fixes
fixes error handlings and several cleanups suggested by LGTM
2018-06-25 13:12:44 +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
Yu Watanabe 33987ba0c2 bootctl: drop dead code 2018-06-25 13:40:36 +09: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
Zbigniew Jędrzejewski-Szmek 50d1760d26 Drop more license boilerplate
$ git grep -e 'This program is free software' -l |grep -v LICENSE | \
  xargs perl -i -0pe 's/ \* This program.*?for more details.\s*\*\n( \* You should have.*licenses.>.\n)?//gms'

For some reason they were missed previously. All those files seem to
have proper SDPX tags.
2018-06-14 13:05:41 +02:00
Zbigniew Jędrzejewski-Szmek 0cd41d4dff Drop my copyright headers
perl -i -0pe 's/\s*Copyright © .... Zbigniew Jędrzejewski.*?\n/\n/gms' man/*xml
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/(#\n)?# +Copyright © [0-9, -]+ Zbigniew Jędrzejewski.*?\n//gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s*\/\*\*\*\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*?\s*\*\*\*\/\s*/\n\n/gms'
git grep -e 'Copyright.*Jędrzejewski' -l | xargs perl -i -0pe 's/\s+Copyright © [0-9, -]+ Zbigniew Jędrzejewski[^\n]*//gms'
2018-06-14 13:03:20 +02:00
Lennart Poettering 96b2fb93c5 tree-wide: beautify remaining copyright statements
Let's unify an beautify our remaining copyright statements, with a
unicode ©. This means our copyright statements are now always formatted
the same way. Yay.
2018-06-14 10:20:21 +02:00
Lennart Poettering 0c69794138 tree-wide: remove Lennart's copyright lines
These lines are generally out-of-date, incomplete and unnecessary. With
SPDX and git repository much more accurate and fine grained information
about licensing and authorship is available, hence let's drop the
per-file copyright notice. Of course, removing copyright lines of others
is problematic, hence this commit only removes my own lines and leaves
all others untouched. It might be nicer if sooner or later those could
go away too, making git the only and accurate source of authorship
information.
2018-06-14 10:20:20 +02:00
Lennart Poettering 810adae9e9 tree-wide: use proper unicode © instead of (C) where we can
Let's use a proper unicode copyright symbol where we can, it's prettier.

This important patch is very important.
2018-06-14 10:20:20 +02:00
Lennart Poettering 818bf54632 tree-wide: drop 'This file is part of systemd' blurb
This part of the copyright blurb stems from the GPL use recommendations:

https://www.gnu.org/licenses/gpl-howto.en.html

The concept appears to originate in times where version control was per
file, instead of per tree, and was a way to glue the files together.
Ultimately, we nowadays don't live in that world anymore, and this
information is entirely useless anyway, as people are very welcome to
copy these files into any projects they like, and they shouldn't have to
change bits that are part of our copyright header for that.

hence, let's just get rid of this old cruft, and shorten our codebase a
bit.
2018-06-14 10:20:20 +02:00
Lennart Poettering 33de6b57a8 efi: explicitly cast physical address to UINTN when converting to/from pointers
UINTN is the integer type equalling the native ptr size. Let's fix the
casting warnings described in #7788 by casting the the pointers and
values to this type first. That way we cast integers to the right size
first before turning them into pointers, and pointers are first
covnerted to integers of the right size before converting them into
integers.

Not tested, since I lack i386 EFI systems, but I think this is simple
enough to be correct event without testing.

Fixes: #7788
2018-05-31 16:10:46 +02:00
Yu Watanabe 4b4ee0f781 meson: also try to search gnu-efi based on EFI_MACHINE_TYPE_NAME (#8900)
On Fedora rawhide, since gnu-efi-3.0.8-3.fc29, many file paths are
changed to use `EFI_MACHINE_TYPE_NAME` instead of `gnu_efi_arch`.

Fixes #8896.
2018-05-04 17:49:57 +02:00
Zbigniew Jędrzejewski-Szmek b1c05b98bf tree-wide: avoid assignment of r just to use in a comparison
This changes
  r = ...;
  if (r < 0)
to
  if (... < 0)
when r will not be used again.
2018-04-24 14:10:27 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Zbigniew Jędrzejewski-Szmek 11a1589223 tree-wide: drop license boilerplate
Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.
2018-04-06 18:58:55 +02:00
Zbigniew Jędrzejewski-Szmek 46af0be929 boot: also use _cleanup_freepool_ in util.c
efivar_get() was leaking memory on success, afaict.
2018-03-13 11:42:02 +01:00
Zbigniew Jędrzejewski-Szmek a42d7cf165 sd-boot: introduce _cleanup_freepool_ 2018-03-13 11:41:32 +01:00
Zbigniew Jędrzejewski-Szmek 48af1eb6ee Merge pull request #8086 from hdante/sdboot-setmode-v2 2018-03-07 10:41:44 +01:00
Zbigniew Jędrzejewski-Szmek 595ced4d81
Merge pull request #7817 from medhefgo/systemd-boot
systemd-boot improvements
2018-03-07 10:14:41 +01:00
Zbigniew Jędrzejewski-Szmek 70756b3b4d systemd-boot: fix off-by-one buffer overrun
We'd allocate a buffer of some size and then write zero to the byte one after.
2018-03-07 09:03:23 +01:00
Zbigniew Jędrzejewski-Szmek 12643e7c43 systemd-boot: reduce indentation in config_entry_add_linux()
No functional change.
2018-03-07 09:03:18 +01:00
Jan Janssen 4c8c9f9f8a systemd-boot: Try harder not to add ourselves to the list
We don't need to check if we are adding ourselves to the list
if we know that it's the windows or EFI shell loaders.

If we are adding the EFI default loader, additionally try to
see if we can find the systemd-boot magic string and skip
this entry if we do.
2018-03-07 09:03:18 +01:00
antizealot1337 6719ca7211 Add missing double quote from log message (#8257) 2018-02-23 00:18:29 +01:00
Lennart Poettering 8ac2f74fb6 tree-wide: make use of fsync_directory_of_file() all over the place
Let's make use this at various places we call fsync(), to make things
fully reliable, as the kernel devs suggest to first fsync() files and
then fsync() the directories they are located in.
2018-02-20 15:39:31 +01:00
Henrique Dante de Almeida d37b0737e1 bootctl: synchronize bootctl code with sd-boot code
This patch adds a line with "#console-mode keep" as a documentation for
the console mode feature and duplicates console-mode parsing to bootctl.
2018-02-03 17:37:21 -02:00
Henrique Dante de Almeida 26e51d87f7 boot/efi: improve automatic mode handling
This patch improves the automatic console mode switching by avoiding
changing the mode if it can verify that the text is readable in the
default mode. The implementation avoids changing mode if we're using a
low resolution device (fixed to be smaller than 1920x1080) because we
assume the text is readable, so the initial mode should be a good one.
Also, the mode is not changed when in high resolution mode if the text
viewport area is larger than 10% of the screen. The conclusion is that
only if the text viewport is calculated to occupy less than 10% of the
screen area it is assumed to be hard to read and a new mode is selected.

With this patch the auto mode will typically avoid changing mode
hopefully in most of the cases, only changing it if completely
necessary.
2018-02-03 17:37:16 -02:00
Henrique Dante de Almeida 68d4b8ac9b boot/efi: add console-mode boot option to change resolution
The new boot option allows changing the display console mode to some new
display resolution.

Usage: in systemd-boot configuration file loader/loader.conf add one of:

	console-mode <number>
	console-mode auto
	console-mode max
	console-mode keep

Where number can be:

	1) 0: UEFI standard 80x25 mode
	2) 1: 80x50 mode, if supported by device
	3) 2 or greater: some non-standard device mode, if supported

When using the auto mode, systemd-boot will try to find a reasonable
mode automatically using some heuristic. Current implementation tries to
switch console mode to mode 2 if it exists, mode 1 if it exists, else
mode 0. Mode 2 is the first non standard mode provided by the firmware
developer and it's assumed to be a reasonable mode.

The max mode adds support for switching to the highest numbered console
mode, whatever mode that would be in the system. The maximum mode being
the last one implemented by the firmware provider should be a reasonable
mode.

The keep mode is the default and is only included for completeness. With
this parameter, the user explicitly states and can be assured that
systemd-boot will not change console mode.

Note: patch includes a workaround for mode 1, that may not exist in
EDK2 OVFM and results in a buggy text mode when requested.
2018-02-03 17:32:04 -02:00
Jan Janssen c1d4e298bc systemd-boot: Make automatic entries configurable
Hiding automatic entries allows for giving custom entry names like
"Windows 10" instead of "Windows Boot Manager" by creating an appropriate
loader file in the loader/entries folder.
Note that it is already doable by renaming bootmgfw.efi (or the other auto-detected
boot loaders) and then using the renamed file for a custom entry. But windows will
automatically recreate the boot loader on updates, including the default EFI
bootloader entry if that one is missing.

Make hiding EFI reboot a separate option because there is no simple way to create
it with a custom loader entry and people may still want that around while still
hiding the other auto entries.

Also, turn no_editor into a positive boolean name while we're touching this code.
2018-01-28 17:20:41 +01:00
Jan Janssen 33d4ba32c9 systemd-boot: Return EFI_STATUS instead of INTN for file_read()
file_read() wants to return both a EFI_STATUS (INTN) and a file
length (UINTN). This seems rather fishy for either large files or
when returning errors (which are defined as positive numbers).
Let's just be more clear and return EFI_STATUS and let the file
length be a pointer.
2018-01-28 17:20:41 +01:00
Raphael Vogelgsang 16c73c765d boot/efi: TPM V2 fix for GetEventLog EFI function 2018-01-25 15:03:55 +01:00
Дамјан Георгиевски 81375b9bf7 bootctl: report StubInfo if present
Current Loader:
      Product: n/a
         Stub: systemd-stub 236
          ESP: /dev/disk/by-partuuid/b0a0807d-0592-40e9-adac-3bb724e9e305
         File: └─/EFI/Secure/secure-boot-4.14.13+.efi
2018-01-15 18:21:14 +01:00
Дамјан Георгиевски 34412f79e6 EFI stub: add StubInfo if non-existant
currently if a stub image is directly booted, bootctl reports:
```
Current Loader:
      Product: n/a
          ESP: /dev/disk/by-partuuid/b0a0807d-0592-40e9-adac-3bb724e9e305
         File: └─/EFI/Secure/secure-boot-4.14.8+.efi
```

Let's add a StubInfo which will be displayed by bootctl too (in a later
patch).
2018-01-15 18:08:11 +01:00
Дамјан Георгиевски 1aa15defbf EFI stub: add LoaderFirmwareInfo, LoaderFirmwareType if non-existant
bootctl previously:
```
System:
     Firmware: n/a (n/a)
```

after:
```
System:
     Firmware: UEFI 2.50 (Lenovo 0.4704)
```
2018-01-15 18:05:39 +01:00
Дамјан Георгиевски 19e0e60a57 EFI stub: add LoaderImageIdentifier if non-existant
when an image with the stub is booted directly from UEFI, bootctl status
shows this:
```
Current Loader:
      Product: n/a
          ESP: /dev/disk/by-partuuid/b0a0807d-0592-40e9-adac-3bb724e9e305
         File: └─n/a
```

After this change, the stub reports the image itself:
```
Current Loader:
      Product: n/a
          ESP: /dev/disk/by-partuuid/b0a0807d-0592-40e9-adac-3bb724e9e305
         File: └─/EFI/Secure/secure-boot-4.14.8+.efi
```
2018-01-15 17:59:33 +01:00
Zbigniew Jędrzejewski-Szmek 67ddb52432
Merge pull request #7855 from poettering/log-h-includes
log.h #include cleanups
2018-01-15 13:43:09 +04:00
winnerman-pythian cce5b4f106 bootctl: add newline after printf (#7856)
Upon error condition, a newline is not printed, leading to the shell prompt jamming against this line.
2018-01-11 18:01:57 +01:00
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
bleep_blop 7629744a3d separate flags from shebang 2017-12-25 19:48:49 +01:00
Yu Watanabe 977f65f01d sd-boot, udev: trivial condition simplifications
Reported and proposed by @dcb314.

Fixes #7656 and #7657.
2017-12-25 19:45:40 +01:00
Zbigniew Jędrzejewski-Szmek 5364c68690 bootctl: silence warning about signed/unsigned comparison 2017-12-19 15:20:37 +01:00
Lennart Poettering b794712a1c
Merge pull request #7631 from cgwalters/systemctl-offline
systemctl,verbs: Introduce SYSTEMCTL_OFFLINE environment variable
2017-12-15 10:29:21 +01:00
Colin Walters c56d1e2c1b verbs: Rename VERB_OFFLINE to VERB_ONLINE_ONLY, expand MUSTBEROOT
Followup to previous commit. Suggested by @poettering.
Reindented the `verbs[]` tables to match the apparent previous
whitespace rules (indent to one flag, allow multiple flags to overflow?).
2017-12-14 16:12:14 -05:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Zbigniew Jędrzejewski-Szmek 4432ac91ee
Merge pull request #7611 from poettering/bootspec-fixes
minor fixes to bootctl.c/bootspec.c to make sure the tool works cleanly on my system
2017-12-12 22:16:34 +01:00
Lennart Poettering 0c63eb7138 verbs: add a new VERB_MUSTBEROOT flag
Given that we regularly have verbs that require privileges, let's just
make this a flag of the verb.
2017-12-11 23:19:46 +01:00
Lennart Poettering fba868fa71 tree-wide: unify logging of "Must be root" message
Let's unify this in one call, generalizing must_be_root() from
bootctl.c.
2017-12-11 23:19:45 +01:00
Lennart Poettering ecec2a5d7a bootctl: don't trip up in "bootctl status" when we can't find the ESP because of lack of privilges
On my system the boot and EFI partitions are protected, hence "bootctl
status" can't find the ESP, and then the tool continues with arg_path ==
NULL, which it really should not. Handle these cases, and simply
suppress all output that needs arg_path.
2017-12-11 23:18:56 +01:00
Lennart Poettering 5caa3167ff efi: rework find_esp() error propagation/logging a bit
This renames find_esp() to find_esp_and_warn() and tries to normalize its
behaviour:

1. Change the error that is returned when we can't find the ESP to
   ENOKEY (from ENOENT). This way the error code can only mean one
   thing: that our search loop didn't find a good candidate.
2. Really log about all errors, except for ENOKEY and EACCES, and
   document the letter cases.
3. Normalize parameters to the call: separate out the path parameter in
   two: an input path and an output path. That way the memory management
   is clear: we will access the input parameter only for reading, and
   only write out the output parameter, using malloc() memory.
   Before the calling convention were quire surprising for internal API
   code, as the path parameter had to be malloc() memory and might and
   might not have changed.
4. Rename bootctl's find_esp_warn() to acquire_esp(), and make it a
   simple wrapper around find_esp_warn(), that basically just adds the
   friendly logging for the ENOKEY case. This rework removes double
   logging in a number of error cases, as we no longer log here in
   anything but ENOKEY, and leave that entirely to find_esp_warn().
5. find_esp_and_warn() now takes a bool flag parameter
   "unprivileged_mode", which disables logging in the EACCES case, and
   skips privileged validation of the path. This makes the function less
   magic, and doesn't hide this internal silencing automatism from the
   caller anymore.

With all that in place "bootctl list" and "bootctl status" work properly
(or as good as they can) when I invoke the tools whithout privileges on
my system where /boot is not world-readable
2017-12-11 23:18:56 +01:00
Lennart Poettering 234519ae6d tree-wide: drop a few == NULL and != NULL comparison
Our CODING_STYLE suggests not comparing with NULL, but relying on C's
downgrade-to-bool feature for that. Fix up some code to match these
guidelines. (This is not comprehensive, the coccinelle output for this
is unfortunately kinda borked)
2017-12-11 16:05:40 +01:00
Harald Hoyer bfdf8c3bb8 boot/efi: fixup TPM V2 measuring and logging (#7568)
Honor the log format and use packed event structures.

Fixes https://github.com/systemd/systemd/issues/7118
2017-12-07 21:07:53 +01:00
Max Resch b4f9f2a62f Set secure_boot flag in Kernel Zero-Page (#7482)
Setting the secure_boot flag, avoids getting the printout
"EFI stub: UEFI Secure Boot is enabled." when booting
a Linux kernel with linuxx64.efi.stub and EFI SecureBoot enabled.

This is mainly a cosmetic fixup, as the "quiet" kernel parameter does
not silence pr_efi printouts in the linux kernel (this only works using
the efi stub from the linux source tree)
2017-12-06 15:29:52 +01:00
Zbigniew Jędrzejewski-Szmek 8d44f5a637 shim: fix logically dead code
The alternate verification path could never be taken.

Found by coverity.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek 10a6e01eaa boot/shim: fix char ** vs char * mismatch
This code cannot have ever worked ;(

Found by coverity, obvious when the type is not obfuscated to void*.
2017-11-28 09:25:38 +01:00
Zbigniew Jędrzejewski-Szmek bceda88b52 boot/efi: fix NULL dereference
The comment above makes the intent of the code pretty clear:
"use security2_protocol == NULL as indicator".
So revert the condition in the check and fix the logic in the comment while
at it.

The question is how this could have ever worked: if BS->LocateProtocol
(which is supposedly optional) ever failed, we'd crash here. Strange.

Found by coverity.
2017-11-28 09:25:38 +01:00
Lennart Poettering 4ff183d419
Merge pull request #7154 from keszybz/bootspec
List bootspec entries in bootctl and use the default for kexec
2017-11-20 13:06:33 +01:00
Zbigniew Jędrzejewski-Szmek 3a726fcd08 Add license headers and SPDX identifiers to meson.build files
So far I avoided adding license headers to meson files, but they are pretty
big and important and should carry license headers like everything else.
I added my own copyright, even though other people modified those files too.
But this is mostly symbolic, so I hope that's OK.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Zbigniew Jędrzejewski-Szmek 30b5047762 bootctl: add a convenient way to print the path to EFI 2017-11-19 12:36:20 +01:00
Zbigniew Jędrzejewski-Szmek 46fb255b0d bootctl: rename r2 and r to r and k
r2 was assigned first despite the name. This scheme is different than
what is used elsewhere in the code. Rename to make it easier to read.
2017-11-19 12:35:50 +01:00
Zbigniew Jędrzejewski-Szmek af91818202 bootctl: move find_esp() to shared
In preparation for use in systemctl.

The original function that prints hints is renamed to find_esp_and_warn()
to make its purpose clearer.
2017-11-07 15:14:40 +01:00
Zbigniew Jędrzejewski-Szmek 64f05708cf bootctl: show unique titles 2017-11-07 15:14:23 +01:00
Zbigniew Jędrzejewski-Szmek 7e87c7d914 bootctl: add listing of loader entries 2017-11-07 15:14:21 +01:00
Zbigniew Jędrzejewski-Szmek a2fa605a65 sd-boot: simplify the implementation of entry uniquification
There's a slight change in implementation: we first try to append the
version, then look for any non-unique pairs again. Before, we would only
mark as possibly unique those entries we changed. But if there are two
entries that e.g. have the same title and version, but only one has the
machine-id specified, we would treat one of them as still non-unique after
appending the machine-id to the other one. So the new algorithm is simpler
but more robust (not that it matters).
2017-10-23 13:40:54 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Alan Jenkins 0675e94ab5 "Don't fear the fsync()"
For files which are vital to boot

1. Avoid opening any window where power loss will zero them out or worse.
   I know app developers all coded to the ext3 implementation, but
   the only formal documentation we have says we're broken if we actually
   rely on it.  E.g.

   * `man mount`, search for `auto_da_alloc`.
   * http://www.linux-mtd.infradead.org/faq/ubifs.html#L_atomic_change
   * https://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/

2. If we tell the kernel we're interested in writing them to disk, it will
   tell us if that fails.  So at minimum, this means we play our part in
   notifying the user about errors.

I refactored error-handling in `udevadm-hwdb` a little.  It turns out I did
exactly the same as had already been done in the `systemd-hwdb` version,
i.e. commit d702dcd.
2017-08-17 20:26:36 +01:00
Harald Hoyer 522aa9f5f8 boot/efi: don't hard fail on error for tpm measure (#6473)
Display the error for a small amount of time, but don't fail hard.

In case of a faulty BIOS, a TPM error should not prevent the boot.
If something cares about the PCM measurement, it will be noticed
anyway later on.

Especially important now, that TPM measurement is the default now on
some distribution builds.

https://bugzilla.redhat.com/show_bug.cgi?id=1411156
2017-07-28 03:46:05 -04:00
Zbigniew Jędrzejewski-Szmek 18b9ad1f61 build-sys: rename SD_BOOT_LOG_TPM to ENABLE_TPM
This makes it more like other configure defines.

Also, it fixes meson status output which was looking for HAVE_ and ENABLE_
prefixes only (the define under meson was OK, just the summary message was
wrong.)
2017-07-18 10:05:06 -04:00
Zbigniew Jędrzejewski-Szmek e5f752082e build-sys: drop gitignore patterns for in-tree builds
... and other autotools-generated files.
2017-07-18 10:05:06 -04:00
Zbigniew Jędrzejewski-Szmek 72cdb3e783 build-sys: drop automake support
v2:
- also mention m4
2017-07-18 10:04:44 -04:00
Yu Watanabe cd2d4c7f68 bootctl: allow non-root user to run bootctl status (#5964) 2017-07-11 11:30:29 -04:00
Matthew Garrett d4cbada2a9 sd-boot: stub: Obtain PE section offsets from RAM, not disk (#6250)
In a Secure Boot scenario the stub loader will have been validated
before execution. A malicious drive could then change the data returned
in future reads, resulting in the loader obtaining incorrect section
offsets and (for instance) allowing the command line to be modified.
Pull that information out of the in-RAM representation of the loader
instead in order to avoid this.

Fixes: #6230

(Lennart did some minor coding style fixes, and renamed pefile.c → pe.c,
as suggested by Kay, given that the file now contains a function whose
name doesn't match the filename as prefix anymore.)
2017-07-03 18:14:09 +02:00
Zbigniew Jędrzejewski-Szmek afc5fc1ffa tree-wide: drop assert.h includes
We provide an independent reimplementation in macro.h, and that's the one
we want to use. Including the system header is unnecessary and confusing.
2017-05-13 15:44:30 -04:00
Max Resch b2bb40ce9a sd-boot: added shim signature/MOK validation (#5702)
Adds support for booting in a SecureBoot environment with shim as a
preloader. Install an appropriate UEFI security policy to check PE
signature of a chained kernel or UEFI application (using LoadImage())
against the MOK database maintained by shim, using shim's installed
BootServices.

Implementation details for installing the security policy are based on
code from the LinuxFoundation's SecureBoot PreLoader, part of efitools
licensed under LGPL 2.1

Current signed (by Microsoft) versions of shim (Versions 0.8 & 0.9)
so not install a security policy by themselves, future Versions of
shim might (a compile time switch exists in rectent git versions),
so in the future this PR might become unnecessary.
2017-05-09 20:57:40 +02:00
Michael Biebl 8251ee109c Merge pull request #5842 from keszybz/meson-status-and-conditionals
Meson status and conditional simplification
2017-05-03 16:45:31 +02:00
Zbigniew Jędrzejewski-Szmek 2c201c2140 meson: use booleans for conf.set and drop unecessary conditionals
Using conf.set() with a boolean argument does the right thing:
either #ifdef or #undef. This means that conf.set can be used unconditionally.

Previously I used '1' as the placeholder value, and that needs to be changed to
'true' for consistency (under meson 1 cannot be used in boolean context). All
checks need to be adjusted.
2017-05-02 16:29:11 -04:00
Max Resch a0693fc951 sd-boot: remove compiler warning (#5860)
This small fixup removes a compiler warning when passing tcg (a const
arg type) to the uefi call wapper, which does not define it as const.

All other source files in sd-boot do this cast except measure.c, so
let's fix that.
2017-04-29 22:11:34 -04:00
Max Resch 1f8476b197 sd-boot: remove unnecessary defines (#5848)
As discussed in #5829 `#define` is not necessary, meson and autotools
set the correct compiler flags and the default value is provided by them.
2017-04-29 12:24:25 +02:00
Max Resch 489e15a8b3 meson: add compiler flags for "--tpm" in EFI apps (#5829)
Readds boot log tpm feature that was missing in meson by readding a
defines in efi_conf.h
2017-04-27 20:59:37 -04:00
Zbigniew Jędrzejewski-Szmek b884196cc1 meson: also indent scripts with 8 spaces 2017-04-25 08:49:16 -04:00
Zbigniew Jędrzejewski-Szmek 6800fe7f06 meson: define gnu_efi_arch for the arch efi name, fix ldsdir detection
This fixes ldsdir detection under Debian.

v2:
- define gnu_efi_arch for the arch efi include directory name

  In the autotools naming convention, efi_arch and this directory always had
  the same name. But meson.cpu_family() uses a slightly different convention,
  so those two don't always match.
2017-04-24 19:24:36 -04:00
Zbigniew Jędrzejewski-Szmek 86b3ca7a66 meson: use "sh -eu" and make .sh +x, .py -x
Shell scripts should be executable so that meson reports their
invocation succinctly (does not print 'sh' '-e').
Python scripts should not be executable so that meson does the
detection of the right python binary itself.

Add -u everywhere to catch potential errors.
2017-04-23 21:47:29 -04:00
Zbigniew Jędrzejewski-Szmek 37efbbd821 meson: reindent all files with 8 spaces
The indentation for emacs'es meson-mode is added .dir-locals.

All files are reindented automatically, using the lasest meson-mode from git.
Indentation should now be fairly consistent.
2017-04-23 21:47:29 -04:00
Zbigniew Jędrzejewski-Szmek 0a76b0e8a2 meson: use efi-includedir to look for header
This change mirrors cba49f2dea.
2017-04-23 21:47:29 -04:00
Zbigniew Jędrzejewski-Szmek d83f4f506d test-efi-create-disk.sh: allow running from separate build dir, hook up to meson
This allow test-efi-disk.img to be created under meson.
The invocation of qemu is not converted yet, in particular because the
command-line used in Makefile.am is outdated.
2017-04-23 21:47:29 -04:00
Zbigniew Jędrzejewski-Szmek 4390be305b meson: replace yes/no/auto with true/false/auto
This doesn't feel as natural, but is more consistent with the boolean options
which require true/false, and allows setting of options without knowing of
which type the option is.
2017-04-23 21:47:28 -04:00
Michael Biebl e17e5ba9bf meson: use join_paths consistently
With -Dsplit-usr=true, we set rootprefix to /. This leads to //lib/systemd or
//lib/udev for various dir variables. Using join_paths() avoids this.
2017-04-23 21:47:28 -04:00
Zbigniew Jędrzejewski-Szmek b710072da4 meson: add support for building efi modules
This is a very straightforward conversion of the rules in Makefile.am.
Generated objects (on arm64) are identical.
The only difference in executed commands is that automake uses ld -m
elf_x86_64, without us specifying the -m option anywhere. I suspect that
using the default for the given linker should be OK, so it's fine to just
skip it.
2017-04-23 21:47:28 -04:00
Lennart Poettering 948a3241de Merge pull request #5708 from vcatechnology/arm-cross-compile
ARM32 cross-compile fixes
2017-04-17 15:49:06 +02:00
Matt Clarkson 6b5cf3ea62 build-sys: correct blkid.h includes
When using pkg-config to determine the include flags for blkid the
flags are returned as:

    $ pkg-config blkid --cflags
    -I/usr/include/blkid -I/usr/include/uuid

We use the <blkid/blkid.h> include which would be correct when using
the default compiler /usr/include header search path. However, when
cross-compiling the blkid.h will not be installed at /usr/include and
highly likely in a temporary system root. It is futher compounded if
the cross-compile packages are split up and the blkid package is not
available in the same sysroot as the compiler.

Regardless of the compilation setup, the correct include path should be
<blkid.h> if using the pkg-config returned CFLAGS.
2017-04-06 14:33:02 +01:00
Zbigniew Jędrzejewski-Szmek 948aaa7c52 tree-wide: standardize on $(PACKAGE_VERSION) for the version string
We defined both $(VERSION) and $(PACKAGE_VERSION) with the same contents.
$(PACKAGE_VERSION) is slightly more descriptive, so settle on that, and
drop the other define.
2017-04-04 20:36:09 -04:00
Mikko Ylinen 293b167349 sd-boot: stub: check LoadOptions contains data (#5467)
With some UEFI shells LoadOptionsSize is reported being > 0
but the corresponding LoadOptions does not contain any data
(the first element has value 0).

When that happens, the stub feature that allows .cmdline to be
replaced by what's in LoadOptions ends up copying nothing/random
data to the kernel cmdline resulting in different kinds of boot
problems.

To fix this, add a check to see if LoadOptions contains data
before replacing the .cmdline.

Signed-off-by: Mikko Ylinen <mikko.ylinen@linux.intel.com>
2017-02-27 20:03:07 +01:00
Martin Pitt 4059584718 Merge pull request #5449 from keszybz/blkd-error-handling
blkid error handling
2017-02-25 12:25:27 +01:00
AsciiWolf 13e785f7a0 Fix missing space in comments (#5439) 2017-02-24 18:14:02 +01:00
Zbigniew Jędrzejewski-Szmek b382db9f3b tree-wide: simplify handling of blkid errors 2017-02-21 16:41:33 -05:00
Lennart Poettering f5b84de2ab bootctl: create loader.conf only if it doesn't exist yet
If the snippet aleady exists, don't do anything, as the file was already
installed then.

(This also reworks the code to create the file atomically)

Fixes: #5396
2017-02-21 21:55:43 +01:00
Lennart Poettering 175d308cad bootctl: rework file copy routines to reuse copy_bytes() from copy.c
Also, make sure to reuse temporary file handling used elsewhere.
2017-02-21 21:55:43 +01:00
Zbigniew Jędrzejewski-Szmek 7db5706eec boot: fix two typos 2017-01-31 00:49:53 -05:00
Lucas Werkmeister d6ccb4f942 bootctl: fix typo (#4897) 2016-12-16 15:41:31 +01:00
Yassine Imounachen b3f76b0d61 Update boot.c (#4780) 2016-12-01 15:58:58 +01:00
Evgeny Vereshchagin 88a00ac517 bootctl: don't try to remove esp_path (#4407)
This is a follow-up for 9ee051b9c7
2016-10-19 21:15:20 +02:00
Yu Watanabe 9ee051b9c7 boot: fix bootctl install segfault (#4404) 2016-10-19 14:50:47 +03:00
Lans Zhang 59991e3fe3 sd-boot: trigger to record further logs to tcg 2.0 final event log area (#4302)
According to TCG EFI Protocol Specification for TPM 2.0 family,
all events generated after the invocation of EFI_TCG2_GET_EVENT_LOG
shall be stored in an instance of an EFI_CONFIGURATION_TABLE aka
EFI TCG 2.0 final events table. Hence, it is necessary to trigger the
internal switch through calling get_event_log() in order to allow
to retrieve the logs from OS runtime.

msekletar:
> I've looked at EDK2 and indeed log entry is added to FinalEventsTable only after 
> EFI_TCG2_PROTOCOL.GetEventLog was called[1][2]. Also, same patch was currently
> merged to shim by Peter Jones [3].

[1] https://github.com/tianocore/edk2/blob/master/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c#L698
[2] https://github.com/tianocore/edk2/blob/master/SecurityPkg/Tcg/Tcg2Dxe/Tcg2Dxe.c#L824
[3] rhinstaller/shim#64
2016-10-09 18:59:54 -04:00
Mantas Mikulėnas a908cf0a12 bootctl: properly skip duplicate entries (#4048)
'continue' is a fancy no-op here – it only skips through the inner loop,
not the outer one, so entries already in BootOrder get printed twice.

This partially reverts f939cff715 "bootctl: various coding style
updates".
2016-08-30 16:50:19 +02:00
Zbigniew Jędrzejewski-Szmek 2d37cd5356 Add enable_disable() helper
In this patch "enabled" and "disabled" is used exclusively, but "enable" and
"disable" forms are need for the following patch.
2016-07-31 22:48:22 -04:00
Zbigniew Jędrzejewski-Szmek e28973ee18 Merge pull request #3757 from poettering/efi-search 2016-07-25 16:34:18 -04:00
Lennart Poettering 3bbaff3e08 tree-wide: use sd_id128_is_null() instead of sd_id128_equal where appropriate
It's a bit easier to read because shorter. Also, most likely a tiny bit faster.
2016-07-22 12:38:08 +02:00
Lennart Poettering d5ff6d6d34 bootctl: modernize install_loader_config()
let's the proper APIs to read the machine ID, and properly check for all
errors.
2016-07-21 11:37:59 +02:00
Lennart Poettering f939cff715 bootctl: various coding style updates 2016-07-21 11:37:58 +02:00
Lennart Poettering db6d9faeb0 bootctl: clean up get_file_version()
Make sure that we always initialize the return parameter on success, and that
all errors result in an error message, not just some.
2016-07-21 11:37:58 +02:00
Lennart Poettering 5fa6c13c7b bootctl: use F_TYPE_EQUAL() to compare statfs' .f_type field
After all, the field is kinda borked.
2016-07-21 11:37:58 +02:00
Lennart Poettering 846b8fc30d bootctl: move toupper() implementation to string-util.h
We already have tolower() calls there, hence let's unify this at one place.
Also, update the code to only use ASCII operations, so that we don't end up
being locale dependant.
2016-07-21 11:37:58 +02:00
Lennart Poettering 181ccb43ea bootctl: make use of STRV_FOREACH() where we can 2016-07-21 11:37:58 +02:00
Lennart Poettering 2f2c539cd4 bootctl: rework to use common verbs parsing, and add searching of ESP path
This rearranges bootctl a bit, so that it uses the usual verbs parsing
routines, and automatically searches the ESP in /boot, /efi or /boot/efi, thus
increasing compatibility with mainstream distros that insist on /boot/efi.

This also adds minimal support for running bootctl in a container environment:
when run inside a container verification of the ESP via raw block device
access, trusting the container manager to mount the ESP correctly. Moreover,
EFI variables are not accessed when running in the container.
2016-07-21 11:37:58 +02:00
Lennart Poettering c18532e031 bootctl: fix error message check 2016-07-21 11:10:35 +02:00
Lennart Poettering 25579a43ef bootctl: minor coding style improvements 2016-07-21 11:10:35 +02:00
Alexander Kurtz 00f69504a2 bootctl: Always use upper case for "/EFI/BOOT" and "/EFI/BOOT/BOOT*.EFI".
If the ESP is not mounted with "iocharset=ascii", but with "iocharset=utf8"
(which is for example the default in Debian), the file system becomes case
sensitive. This means that a file created as "FooBarBaz" cannot be accessed as
"foobarbaz" since those are then considered different files.

Moreover, a file created as "FooBar" can then also not be accessed as "foobar",
and it also prevents such a file from being created, as both would use the same
8.3 short name "FOOBAR".

Even though the UEFI specification [0] does give the canonical spelling for
the files mentioned above, not all implementations completely conform to that,
so it's possible that those files would already exist, but with a different
spelling, causing subtle bugs when scanning or modifying the ESP.

While the proper fix would of course be that everybody conformed to the
standard, we can work around this problem by just referencing the files by
their 8.3 short names, i.e. using upper case.

Fixes: #3740

[0] <http://www.uefi.org/specifications>, version 2.6, section 3.5.1.1
2016-07-21 03:02:15 +02:00
Alexander Kurtz b7536c45ef bootctl: Use lower case string constants in case-insensitive comparisons. 2016-07-21 02:20:12 +02:00
Jan Janssen 03e749af53 sd-boot: Fix waiting for keyboard input (#3735)
WaitForKeyEx may never return on some UEFI systems depending
on firmware, hardware configuration and the phase of the moon.
Use ConIn->WaitForKey unconditionally instead.

Fixes #3632
2016-07-18 15:19:32 -04:00
Michael Biebl 595bfe7df2 Various fixes for typos found by lintian (#3705) 2016-07-12 12:52:11 +02:00
Zbigniew Jędrzejewski-Szmek 323b7dc903 tree-wide: rename draw_special_char to special_glyph
That function doesn't draw anything on it's own, just returns a string, which
sometimes is more than one character. Also remove "DRAW_" prefix from character
names, TREE_* and ARROW and BLACK_CIRCLE are unambigous on their own, don't
draw anything, and are always used as an argument to special_glyph().

Rename "DASH" to "MDASH", as there's more than one type of dash.
2016-05-09 15:17:57 -04:00
Vito Caputo 9ed794a32d tree-wide: minor formatting inconsistency cleanups 2016-02-23 14:20:34 -08:00
Harald Hoyer 92ed3bb49e sd-boot: put hashed kernel command line in a PCR of the TPM
The UEFI BIOS already hashes the contents of the loaded image, so the
initrd and the command line of the binary are recorded.

Because manually added LoadOptions are not taken into account, these
should be recorded also.

This patch logs and extends a TPM PCR register with the LoadOptions.

This feature can be enabled with configure --enable-tpm

The PCR register index can be specified with
configure --with-tpm-pcrindex=<NUM>
2016-02-11 17:48:09 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Michal Sekletar e41256dcec bootctl: replace readdir() loops with FOREACH_DIRENT 2016-01-31 09:44:53 +01:00
Daniel Mack bc9d55c865 bootctl: use DRAW_TREE_RIGHT rather than hard-coded UTF-8 character
Fixes #2384
2016-01-20 13:14:14 +01:00
Thomas Hindoe Paaboel Andersen cf0fbc49e6 tree-wide: sort includes
Sort the includes accoding to the new coding style.
2015-11-16 22:09:36 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 8752c5752f util-lib: move more locale-related calls to locale-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00