Commit graph

421 commits

Author SHA1 Message Date
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
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Lennart Poettering 1f6b411372 tree-wide: update empty-if coccinelle script to cover empty-while and more
Let's also clean up single-line while and for blocks.
2015-09-09 14:59:51 +02:00
Lennart Poettering 52efd56a63 tree-wide: we place the opening bracket on the same line as the function name
Let's do this everywhere the same way.
2015-08-27 17:48:24 +02:00
Karel Zak a592ab6ae8 bootctl: fix path in log message 2015-08-06 13:59:38 +02:00
Kay Sievers 540536ffd1 systemd-boot: sort /EFI/Linux/*.efi files 2015-07-30 18:28:02 +02:00
Daniel Mack 65c85ef511 Merge pull request #779 from poettering/fflush-and-check
tree-wide: port everything over to fflush_and_check()
2015-07-29 20:43:54 +02:00
Lennart Poettering dacd6cee76 tree-wide: port everything over to fflush_and_check()
Some places invoked fflush() directly with their own manual error
checking, let's unify all that by using fflush_and_check().

This also unifies the general error paths of fflush()+rename() file
writers.
2015-07-29 20:31:07 +02:00
Kay Sievers 8110e144ff sd-boot: stub - export LoaderDevicePartUUID 2015-07-29 19:36:17 +02:00
Kay Sievers fc7bdb583f systemd-boot: fix whitespace 2015-07-26 00:38:01 +02:00
Kay Sievers 2da6d7b91d Merge pull request #634 from icarlosvenegas/sd-boot-show-efi-cmdline_v2
sd-boot: Show stub cmdline when edit (v2)
2015-07-26 00:35:23 +02:00
Kay Sievers c11ae0bace bootctl: add missing newline 2015-07-25 03:26:32 +02:00
Jose Carlos Venegas Munoz b1da143f2a sd-boot:Show stub cmdline when edit
If Linux efi stub is used, embedded cmdline in efi stub is
not shown. As a result, it is required to rewrite all the
line, if is only required to modify it. This behavior only
happen using Linux efi stub.

This patch allows boot loader to show embedded cmdline when
'e' key is pressed to edit boot loader options.
2015-07-20 14:56:02 -05:00
David Herrmann ab822b624b sd-boot: ignore missing /etc/machine-id
If /etc/machine-id is missing (eg., gold images), we should not fail
installing sd-boot. This is a perfectly fine use-case and we should simply
skip installing the default loader config in that case.
2015-07-15 12:04:31 +02:00
David Herrmann 59658d1958 boot: use BUILD_ID if VERSION_ID is not present
According to os-release(5), VERSION_ID is not mandatory and BUILD_ID only
needs to be unique underneath VERSION_ID. Therefore, assuming a missing
VERSION_ID field means 'empty', we can rely on BUILD_ID to be unique.

Use BUILD_ID if VERSION_ID is not present. This way, rolling-release
distros can still provide a proper os-release entry without crafting
random VERSION_ID strings.

This fixes #186.
2015-07-09 13:07:27 +02:00
David Herrmann d8c64b7f90 boot: fix memleaks in os-release parser
There is no guarantee that the os-release section contains each key only
once, nor any guarantee that all keys are present. Make sure we properly
free memory in both cases.

Not that it matters much, as we're short-living, anyway. But correct code
is always nicer to read..
2015-07-09 13:02:54 +02:00
Miguel Bernal Marin 68cc17f131 bootctl: fix sdboot to systemd-boot
sdboot was renamed to systemd-boot

Fixes: e7dd673d1e ("gummiboot/sd-boot/systemd-boot: rename galore")

Signed-off-by: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com>
2015-07-04 17:03:50 -05:00
Thomas Hindoe Paaboel Andersen dd114e116b bootctl: fix an error check 2015-05-23 13:03:30 +02:00
Thomas Hindoe Paaboel Andersen 717442507b bootctl: ferror must be called before FILE is closed
Otherwise it will not show any error stored
2015-05-22 23:46:36 +02:00
Zbigniew Jędrzejewski-Szmek 551710cf2e bootctl: try to catch all errors
Do not print garbage on non-EFI installations.
2015-05-19 23:41:38 -04:00
Zbigniew Jędrzejewski-Szmek d3226d7796 bootctl: modernization
Use strjoina to avoid error handling, and openat to simplify things.

Some fixes on the way:
- ferror does not set errno, so the return value was wrong in some cases
- errors are propagated in more cases
- EFI/systemd was created, but EFI/systemd-boot was deleted
- something is always printed on error
- when checking the version, comparison was done against "systemd-bo" for some reason
- return value was converted from negative to EXIT_SUCCESS/EXIT_FAILURE twice,
  resulting in EXIT_SUCCESS all the time
2015-05-19 23:41:38 -04:00
Kay Sievers b40c3dfa32 boot: function parameters are separated by comma 2015-05-12 17:58:59 +02:00
Koen Kooi 0d8d368907 boot/util: add ticks_read() stub 2015-04-11 11:54:45 +02:00
Koen Kooi 8403daa284 boot/util: use x86 ASM only on x86 platforms. 2015-04-11 11:48:39 +02:00
Ronny Chevalier 39505e3c3b remove duplicated includes 2015-04-08 02:42:50 +02:00
Lennart Poettering c687863750 util: rework rm_rf() logic
- Move to its own file rm-rf.c

- Change parameters into a single flags parameter

- Remove "honour sticky" logic, it's unused these days
2015-04-06 10:57:53 +02:00
David Herrmann e0d065d405 bootctl: drop redundant parse_argv()
We already call parse_argv() from main(), don't call it here again.
2015-03-19 14:11:54 +01:00
Zbigniew Jędrzejewski-Szmek 7c5925a448 efi: widen operand to avoid overflow
CID #1287141.
2015-03-13 23:42:16 -04:00
Kay Sievers 4db7e6d781 boot: efi - add config option to disable the command line editor 2015-03-11 23:33:53 +01:00
Zbigniew Jędrzejewski-Szmek 56c70b32af boot/efi: do not assign variable twice
If the highlighted line did not move outside of the visible
region, it should not be necessary to update idx_last.

CID #1287137, #1287138.
2015-03-09 16:45:27 -04:00
Kay Sievers 9d3dec15ae boot: efi - ignore .conf snippets starting with "auto-" 2015-03-01 13:16:10 +01:00
Kay Sievers ea1851b60c boot: efi - remove a couple of Loader* variables 2015-03-01 13:16:10 +01:00
Zbigniew Jędrzejewski-Szmek 1a1db450e5 bootctl: avoid NULL pointer dereference 2015-02-27 17:31:43 -05:00
Marcel Holtmann 2bdbf32183 boot: efi - fix missing include
src/boot/efi/splash.c:312:9: warning: implicit declaration of function ‘graphics_mode’ [-Wimplicit-function-declaration]
         err = graphics_mode(TRUE);
         ^
2015-02-27 03:43:31 +01:00
Kay Sievers 7361099e42 boot: efi - remove custom splash support 2015-02-26 19:51:08 +01:00
Kay Sievers 2f8d336478 boot: efi - split graphics and splash handling 2015-02-26 19:45:08 +01:00
Kay Sievers 37fa369066 boot: efi - support embedded splash image 2015-02-26 18:58:30 +01:00
Kay Sievers 20b1538df6 boot: efi - print generic error message if we fail to execute an image 2015-02-26 01:15:18 +01:00
Kay Sievers a19b0678be boot: efi - remove default boot splash handling 2015-02-26 01:03:29 +01:00
Thomas Hindoe Paaboel Andersen 3a4efbff2e bootctl: check that partition uuid is valid
It probably is but check anyway to make coverity happy.

CID#1271354
2015-02-25 23:32:50 +01:00
Thomas Hindoe Paaboel Andersen 7cb0f263ad bootctl: fix mem leaks
CID#1271347/1271348
2015-02-25 00:00:32 +01:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Kay Sievers 11d63aea3a build-sys: update gitignore 2015-02-20 15:42:32 +01:00
Thomas Hindoe Paaboel Andersen 04155c6713 systemd-boot: fix alignment of version in table 2015-02-18 22:19:17 +01:00
Tom Gundersen e7dd673d1e gummiboot/sd-boot/systemd-boot: rename galore
What used to be gummiboot, was renamed sd-boot when it was merged into
systemd. Let's try to be a bit more consistent with the rest of systemd
and rename it again as follows:

The EFI bootloader is now called 'systemd-bootx64.efi', and its sources are in
'src/boot/efi/'. The drop-in directory where bootctl will find EFI loaders
is now /usr/lib/systemd/boot/efi/.
2015-02-18 15:23:23 +01:00
Kay Sievers 0974a682d1 bootctl: add sd-boot support 2015-02-17 14:36:59 +01:00
Thomas Hindoe Paaboel Andersen c1ff5570f4 Add missing includes in header files
This fixes various issues found by globally reordering the include
sections of all .c files.
2015-02-12 20:44:32 +01:00
Zbigniew Jędrzejewski-Szmek 601185b43d Unify parse_argv style
getopt is usually good at printing out a nice error message when
commandline options are invalid. It distinguishes between an unknown
option and a known option with a missing arg. It is better to let it
do its job and not use opterr=0 unless we actually want to suppress
messages. So remove opterr=0 in the few places where it wasn't really
useful.

When an error in options is encountered, we should not print a lengthy
help() and overwhelm the user, when we know precisely what is wrong
with the commandline. In addition, since help() prints to stdout, it
should not be used except when requested with -h or --help.

Also, simplify things here and there.
2014-08-03 21:46:07 -04:00
Lennart Poettering 39883f622f make gcc shut up
If -flto is used then gcc will generate a lot more warnings than before,
among them a number of use-without-initialization warnings. Most of them
without are false positives, but let's make them go away, because it
doesn't really matter.
2014-02-19 17:53:50 +01:00
Greg KH 29804cc1e0 use memzero(foo, length); for all memset(foo, 0, length); calls
In trying to track down a stupid linker bug, I noticed a bunch of
memset() calls that should be using memzero() to make it more "obvious"
that the options are correct (i.e. 0 is not the length, but the data to
set).  So fix up all current calls to memset(foo, 0, length) to
memzero(foo, length).
2014-01-31 11:55:01 +01:00
Stefan Beller b8265d4f8e boot-efi: Remove superfluous assignment
2 lines after the changed line we assign err to efi_get_variable(...)
unconditionally, so it makes no sense to initialize it to some value.
2013-12-31 17:53:30 +01:00
Thomas Hindoe Paaboel Andersen b226deba78 bootctl: remove unused options from getopt_long 2013-11-09 14:11:56 +01:00
Lennart Poettering eb9da376d7 clients: unify how we invoke getopt_long()
Among other things this makes sure we always expose a --version command
and show it in the help texts.
2013-11-06 18:28:39 +01:00
Thomas Hindoe Paaboel Andersen 82de16f92c bootctl: typo fix in help message 2013-11-06 00:29:49 +01:00
Kay Sievers c51d84dc09 support acpi firmware performance data (FPDT)
Prefer firmware-provided performance data over loader-exported ones; if
ACPI data is available, always use it, otherwise try to read the loader
data.

The firmware-provided variables start at the time the first EFI image
is executed and end when the operating system exits the boot services;
the (loader) time calculated in systemd-analyze increases.
2013-09-24 15:43:41 +02:00
Koen Kooi 8b3227c90d bootctl: fix help text
It currently says 'time settings', change that to 'boot settings'.
2013-03-29 15:47:43 +01:00
Kay Sievers 0014c5221e bootctl: ESP --> Partition 2013-03-28 11:42:32 +01:00
Kay Sievers 33696ef458 bootctl: Binary: --> File: 2013-03-28 03:43:29 +01:00
Kay Sievers 3483fab948 bootctl: rename status output header 2013-03-27 13:55:09 +01:00
Kay Sievers 0876dc1c26 bootctl: print Options only when found 2013-03-10 23:18:50 +01:00
Kay Sievers bc6f2e7c62 bootctl: print secure boot flags 2013-03-10 22:48:27 +01:00
Kay Sievers 71bf4f6f6c bootctl: show "n/a" for empty boot option labels 2013-02-17 22:28:21 +01:00
Thomas Hindoe Paaboel Andersen 090be86534 use streq instead of strcmp 2013-02-13 18:14:20 +01:00
Kay Sievers b05105f0a8 bootctl: always show slashes not backslashes 2013-02-13 17:49:48 +01:00
Kay Sievers 4d34c4951a efi: unify BootXXXX reading 2013-02-13 17:35:20 +01:00
Lennart Poettering 2a2473d89e boot: add stub Makefile symlink 2013-02-13 02:19:03 +01:00
Lennart Poettering 9cde64ff26 efi: various cleanups 2013-02-13 00:12:58 +01:00
Kay Sievers abb381b3b3 bootctl: print partition uuids as /dev/disk/by-partuuid/... 2013-02-11 23:20:02 +01:00
Kay Sievers 7b4d7cc082 bootctl: add boot loader and firmware interface tool 2013-02-11 19:35:52 +01:00