]> git.ipfire.org Git - thirdparty/grub.git/log
thirdparty/grub.git
6 years agogeneric/blocklist: Fix implicit declaration of function grub_file_filter_disable_comp...
Lee Jones [Tue, 20 Nov 2018 12:37:01 +0000 (12:37 +0000)] 
generic/blocklist: Fix implicit declaration of function grub_file_filter_disable_compression()

grub_file_filter_disable_compression() no longer exists.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64/xen: Fix too few arguments to function grub_create_loader_cmdline()
Lee Jones [Tue, 20 Nov 2018 10:45:04 +0000 (10:45 +0000)] 
arm64/xen: Fix too few arguments to function grub_create_loader_cmdline()

Without this fix, building xen_boot.c omits:

loader/arm64/xen_boot.c: In function ‘xen_boot_binary_load’:
loader/arm64/xen_boot.c:370:7: error: too few arguments to function ‘grub_create_loader_cmdline’
       grub_create_loader_cmdline (argc - 1, argv + 1, binary->cmdline,
       ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from loader/arm64/xen_boot.c:36:0:
../include/grub/lib/cmdline.h:29:12: note: declared here
 grub_err_t grub_create_loader_cmdline (int argc, char *argv[], char *buf,

Signed-off-by: Lee Jones <lee.jones@linaro.org>
Reviewed-by: Julien Grall <julien.grall@arm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm-uboot, ia64, sparc64: Fix up grub_file_open() calls
Leif Lindholm [Wed, 14 Nov 2018 19:29:19 +0000 (19:29 +0000)] 
arm-uboot, ia64, sparc64: Fix up grub_file_open() calls

The verifiers framework changed the grub_file_open() interface, breaking all
non-x86 linux loaders. Add file types to the grub_file_open() calls to make
them build again.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoarm64/efi: Fix breakage caused by verifiers
Leif Lindholm [Wed, 14 Nov 2018 19:29:18 +0000 (19:29 +0000)] 
arm64/efi: Fix breakage caused by verifiers

  - add variable "err" (used but not defined),
  - add GRUB_FILE_TYPE_LINUX_KERNEL to grub_file_open() call.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-core/loader/efi/fdt.c: Fixup grub_file_open() call
Leif Lindholm [Wed, 14 Nov 2018 19:29:17 +0000 (19:29 +0000)] 
grub-core/loader/efi/fdt.c: Fixup grub_file_open() call

The verifiers framework changed the API of grub_file_open(), but did not
fix up all users. Add the file type GRUB_FILE_TYPE_DEVICE_TREE_IMAGE
to the "devicetree" command handler call.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoinclude/grub/file.h: Add device tree file type
Leif Lindholm [Wed, 14 Nov 2018 19:29:16 +0000 (19:29 +0000)] 
include/grub/file.h: Add device tree file type

The API change of grub_file_open() for adding verifiers did not include
a type for device tree blobs. Add GRUB_FILE_TYPE_DEVICE_TREE_IMAGE to
the grub_file_type enum.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoinclude/grub/verify.h: Add include guard
Leif Lindholm [Wed, 14 Nov 2018 19:29:15 +0000 (19:29 +0000)] 
include/grub/verify.h: Add include guard

verify.h was added without include guards. This means compiling anything
including both include/grub/verify.h and include/grub/lib/cmdline.h fails
(at least grub-core/loader/arm64/linux.c.

Add the necessary include guard.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomkimage: Pad DTBs to target-specific pointer size
Matthew Daley [Tue, 6 Nov 2018 22:44:08 +0000 (11:44 +1300)] 
mkimage: Pad DTBs to target-specific pointer size

Device tree (DTB) lengths are being padded to a multiple of 4 bytes
rather than the target-specific pointer size. This causes objects
following OBJ_TYPE_DTB objects to be incorrectly parsed during GRUB
execution on arm64.

Fix by using ALIGN_ADDR(), not ALIGN_UP().

Signed-by-off: Matthew Daley <mattd@bugfuzz.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoCope with / being on a ZFS root dataset
Colin Watson [Mon, 29 Oct 2018 12:33:37 +0000 (12:33 +0000)] 
Cope with / being on a ZFS root dataset

If / is on the root dataset in a ZFS pool, then ${bootfs} will be set to
"/" (whereas if it is on a non-root dataset, there will be no trailing
slash).  Passing "root=ZFS=${rpool}/" will fail to boot, but
"root=ZFS=${rpool}" works fine, so strip the trailing slash.

Fixes: https://savannah.gnu.org/bugs/?52746
Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Tested-by: Fejes József <jozsef.fejes@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agounix/platform: Initialize variable to fix grub-install on UEFI system
Paul Menzel [Tue, 23 Oct 2018 13:00:13 +0000 (15:00 +0200)] 
unix/platform: Initialize variable to fix grub-install on UEFI system

On a UEFI system, were no boot entry *grub* is present, currently,
`grub-install` fails with an error.

    $ efibootmgr
    BootCurrent: 0000
    Timeout: 0 seconds
    BootOrder: 0001,0006,0003,0004,0005
    Boot0001  Diskette Drive
    Boot0003* USB Storage Device
    Boot0004* CD/DVD/CD-RW Drive
    Boot0005  Onboard NIC
    Boot0006* WDC WD2500AAKX-75U6AA0
    $ sudo grub-install /dev/sda
    Installing for x86_64-efi platform.
    grub-install: error: efibootmgr failed to register the boot entry: Unknown error 22020.

The error code is always different, and the error message (incorrectly)
points to efibootmgr.

But, the error is in GRUB’s function
`grub_install_remove_efi_entries_by_distributor()`, where the variable
`rc` for the return value, is uninitialized and never set, when no boot
entry for the distributor is found.

The content of that uninitialized variable is then returned as the error
code of efibootmgr.

Set the variable to 0, so that success is returned, when no entry needs
to be deleted.

Tested on Dell OptiPlex 7010 with firmware A28.

    $ sudo ./grub-install /dev/sda
    Installing for x86_64-efi platform.
    Installation finished. No error reported.

[1]: https://github.com/rhboot/efibootmgr/issues/100

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoefi: Add EFI shim lock verifier
Daniel Kiper [Fri, 3 Aug 2018 11:25:44 +0000 (13:25 +0200)] 
efi: Add EFI shim lock verifier

This module provides shim lock verification for various kernels
if UEFI secure boot is enabled on a machine.

It is recommended to put this module into GRUB2 standalone image
(avoid putting iorw and memrw modules into it; they are disallowed
if UEFI secure boot is enabled). However, it is also possible to use
it as a normal module. Though such configurations are more fragile
and less secure due to various limitations.

If the module is loaded and UEFI secure boot is enabled then:
  - module itself cannot be unloaded (persistent module),
  - the iorw and memrw modules cannot be loaded,
  - if the iorw and memrw modules are loaded then
    machine boot is disabled,
  - GRUB2 defers modules and ACPI tables verification to
    other verifiers.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agodl: Add support for persistent modules
Daniel Kiper [Tue, 2 Oct 2018 16:49:26 +0000 (18:49 +0200)] 
dl: Add support for persistent modules

This type of modules cannot be unloaded. This is useful if a given
functionality, e.g. UEFI secure boot shim signature verification, should
not be disabled if it was enabled at some point in time. Somebody may
say that we can use standalone GRUB2 here. That is true. However, the
code is not so big nor complicated hence it make sense to support
modularized configs too.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: Add the documentation
Vladimir Serbinenko [Tue, 9 May 2017 14:39:38 +0000 (16:39 +0200)] 
verifiers: Add the documentation

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: Rename verify module to pgp module
Daniel Kiper [Tue, 2 Oct 2018 20:36:43 +0000 (22:36 +0200)] 
verifiers: Rename verify module to pgp module

Just for clarity. No functional change.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: Add possibility to defer verification to other verifiers
Daniel Kiper [Wed, 26 Sep 2018 11:17:52 +0000 (13:17 +0200)] 
verifiers: Add possibility to defer verification to other verifiers

This way if a verifier requires verification of a given file it can defer task
to another verifier (another authority) if it is not able to do it itself. E.g.
shim_lock verifier, posted as a subsequent patch, is able to verify only PE
files. This means that it is not able to verify any of GRUB2 modules which have
to be trusted on UEFI systems with secure boot enabled. So, it can defer
verification to other verifier, e.g. PGP one.

I silently assume that other verifiers are trusted and will do good job for us.
Or at least they will not do any harm.

Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: Add possibility to verify kernel and modules command lines
Vladimir Serbinenko [Tue, 7 Feb 2017 01:10:14 +0000 (02:10 +0100)] 
verifiers: Add possibility to verify kernel and modules command lines

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: Framework core
Vladimir Serbinenko [Sun, 5 Feb 2017 13:25:47 +0000 (14:25 +0100)] 
verifiers: Framework core

Verifiers framework provides core file verification functionality which
can be used by various security mechanisms, e.g., UEFI secure boot, TPM,
PGP signature verification, etc.

The patch contains PGP code changes and probably they should be extracted
to separate patch for the sake of clarity.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agoverifiers: File type for fine-grained signature-verification controlling
Vladimir Serbinenko [Wed, 20 Nov 2013 01:28:29 +0000 (02:28 +0100)] 
verifiers: File type for fine-grained signature-verification controlling

Let's provide file type info to the I/O layer. This way verifiers
framework and its users will be able to differentiate files and verify
only required ones.

This is preparatory patch.

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agobufio: Use grub_size_t instead of plain int for size
Daniel Kiper [Mon, 29 Oct 2018 12:25:25 +0000 (13:25 +0100)] 
bufio: Use grub_size_t instead of plain int for size

Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
6 years agobtrfs: Add RAID 6 recovery for a btrfs filesystem
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:39 +0000 (19:29 +0200)] 
btrfs: Add RAID 6 recovery for a btrfs filesystem

Add the RAID 6 recovery, in order to use a RAID 6 filesystem even if some
disks (up to two) are missing. This code use the md RAID 6 code already
present in grub.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Make more generic the code for RAID 6 rebuilding
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:38 +0000 (19:29 +0200)] 
btrfs: Make more generic the code for RAID 6 rebuilding

The original code which handles the recovery of a RAID 6 disks array
assumes that all reads are multiple of 1 << GRUB_DISK_SECTOR_BITS and it
assumes that all the I/O is done via the struct grub_diskfilter_segment.
This is not true for the btrfs code. In order to reuse the native
grub_raid6_recover() code, it is modified to not call
grub_diskfilter_read_node() directly, but to call an handler passed
as an argument.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Add support for recovery for a RAID 5 btrfs profiles
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:37 +0000 (19:29 +0200)] 
btrfs: Add support for recovery for a RAID 5 btrfs profiles

Add support for recovery for a RAID 5 btrfs profile. In addition
it is added some code as preparatory work for RAID 6 recovery code.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Refactor the code that read from disk
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:36 +0000 (19:29 +0200)] 
btrfs: Refactor the code that read from disk

Move the code in charge to read the data from disk into a separate
function. This helps to separate the error handling logic (which
depends on the different raid profiles) from the read from disk
logic. Refactoring this code increases the general readability too.

This is a preparatory patch, to help the adding of the RAID 5/6 recovery code.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Move logging code in grub_btrfs_read_logical()
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:35 +0000 (19:29 +0200)] 
btrfs: Move logging code in grub_btrfs_read_logical()

A portion of the logging code is moved outside of internal for(;;). The part
that is left inside is the one which depends on the internal for(;;) index.

This is a preparatory patch. The next one will refactor the code inside
the for(;;) into an another function.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Avoid a rescan for a device which was already not found
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:34 +0000 (19:29 +0200)] 
btrfs: Avoid a rescan for a device which was already not found

Currently read from missing device triggers rescan. However, it is never
recorded that the device is missing. So, each read of a missing device
triggers rescan again and again. This behavior causes a lot of unneeded
rescans leading to huge slowdowns.

This patch fixes above mentioned issue. Information about missing devices
is stored in the data->devices_attached[] array as NULL value in dev
member. Rescan is triggered only if no information is found for a given
device. This means that only first time read triggers rescan.

The patch drops premature return. This way data->devices_attached[] is
filled even when a given device is missing.

Signed-off-by: Goffredo Baroncelli <kreikack@inwind.it>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Move the error logging from find_device() to its caller
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:33 +0000 (19:29 +0200)] 
btrfs: Move the error logging from find_device() to its caller

The caller knows better if this error is fatal or not, i.e. another disk is
available or not.

This is a preparatory patch.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Add helper to check the btrfs header
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:32 +0000 (19:29 +0200)] 
btrfs: Add helper to check the btrfs header

This helper is used in a few places to help the debugging. As
conservative approach the error is only logged.
This does not impact the error handling.

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobtrfs: Add support for reading a filesystem with a RAID 5 or RAID 6 profile
Goffredo Baroncelli [Mon, 22 Oct 2018 17:29:31 +0000 (19:29 +0200)] 
btrfs: Add support for reading a filesystem with a RAID 5 or RAID 6 profile

Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agomsdos: Fix overflow in converting partition start and length into 512B blocks
Michael Chang [Thu, 13 Sep 2018 08:08:20 +0000 (16:08 +0800)] 
msdos: Fix overflow in converting partition start and length into 512B blocks

When booting from NVME SSD with 4k sector size, it fails with the message.

error: attempt to read or write outside of partition.

This patch fixes the problem by fixing overflow in converting partition start
and length into 512B blocks.

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoosdep/linux: Convert partition start to disk sector length
Mihai Moldovan [Thu, 6 Sep 2018 14:16:39 +0000 (16:16 +0200)] 
osdep/linux: Convert partition start to disk sector length

When reading data off a disk, sector values are based on the disk sector
length.

Within grub_util_fd_open_device(), the start of the partition was taken
directly from grub's partition information structure, which uses the
internal sector length (currently 512b), but never transformed to the
disk's sector length.

Subsequent calculations were all wrong for devices that have a diverging
sector length and the functions eventually skipped to the wrong stream
location, reading invalid data.

Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agopython: Use AM_PATH_PYTHON to determine interpreter for gentpl.py
Adam Williamson [Wed, 4 Jul 2018 16:55:52 +0000 (09:55 -0700)] 
python: Use AM_PATH_PYTHON to determine interpreter for gentpl.py

gentpl.py is python2/3-agnostic, but there's no way to cause it
to be run with any interpreter other than 'python', it's just
hard-coded into Makefile.common that way. Adjust that to use
AM_PATH_PYTHON (provided by automake) to find an interpreter
and run gentpl.py with that instead. This makes grub buildable
when `python` does not exist (but rather `python3` or `python2`
or `python2.7`, etc.) Minimum version is set to 2.6 as this is
the first version with `__future__.print_function` available.

Note, AM_PATH_PYTHON respects the PYTHON environment variable
and will treat its value as the *only* candidate for a valid
interpreter if it is set - when PYTHON is set, AM_PATH_PYTHON
will not try to find any alternative interpreter, it will only
check whether the interpreter set as the value of PYTHON meets
the requirements and use it if so or fail if not. This means
that when using grub's `autogen.sh`, as it too uses the value
of the PYTHON environment variable (and if it is not set, just
sets it to 'python') you cannot rely on AM_PATH_PYTHON
interpreter discovery. If your desired Python interpreter is
not just 'python', you must set the PYTHON environment variable,
e.g. 'PYTHON=/usr/local/bin/python3 ./autogen.sh'. The specified
interpreter will then be used both by autogen.sh itself and by
the autotools-driven build scripts.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobuild: Use pkg-config to find FreeType
Colin Watson [Tue, 30 Jan 2018 21:59:09 +0000 (21:59 +0000)] 
build: Use pkg-config to find FreeType

pkg-config is apparently preferred over freetype-config these days (see
the BUGS section of freetype-config(1)).  pkg-config support was added
to FreeType in version 2.1.5, which was released in 2003, so it should
comfortably be available everywhere by now.

We no longer need to explicitly substitute FREETYPE_CFLAGS and
FREETYPE_LIBS, since PKG_CHECK_MODULES does that automatically.

Fixes Debian bug #887721.

Reported-by: Hugh McMaster <hugh.mcmaster@outlook.com>
Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agobuild: Capitalise *freetype_* variables
Colin Watson [Tue, 30 Jan 2018 21:58:53 +0000 (21:58 +0000)] 
build: Capitalise *freetype_* variables

Using FREETYPE_CFLAGS and FREETYPE_LIBS is more in line with the naming
scheme used by pkg-config macros.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoofnet: Initialize structs in bootpath parser
Julian Andres Klode [Mon, 3 Sep 2018 08:09:15 +0000 (10:09 +0200)] 
ofnet: Initialize structs in bootpath parser

Code later on checks if variables inside the struct are
0 to see if they have been set, like if there were addresses
in the bootpath.

The variables were not initialized however, so the check
might succeed with uninitialized data, and a new interface
with random addresses and the same name is added. This causes
$net_default_mac to point to the random one, so, for example,
using that variable to load per-mac config files fails.

Bug-Ubuntu: https://bugs.launchpad.net/bugs/1785859

Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-reboot: Warn when "for the next boot only" promise cannot be kept
dann frazier [Fri, 17 Aug 2018 23:33:44 +0000 (17:33 -0600)] 
grub-reboot: Warn when "for the next boot only" promise cannot be kept

The "for the next boot only" property of grub-reboot is dependent upon
GRUB being able to clear the next_entry variable in the environment
block. However, GRUB cannot write to devices using the diskfilter
and lvm abstractions.

Ref: https://lists.gnu.org/archive/html/grub-devel/2009-12/msg00276.html
Ref: https://bugs.launchpad.net/bugs/788298

Signed-off-by: dann frazier <dann.frazier@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agorelocator16: Comments update
Cao jin [Tue, 14 Aug 2018 07:03:25 +0000 (15:03 +0800)] 
relocator16: Comments update

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoahci: Increase time-out from 10 s to 32 s
Paul Menzel [Thu, 9 Aug 2018 16:10:51 +0000 (18:10 +0200)] 
ahci: Increase time-out from 10 s to 32 s

This is a cryptographically signed message in MIME format.

Date: Thu, 9 Aug 2018 07:27:35 +0200

Currently, the GRUB payload for coreboot does not detect the Western
Digital hard disk WDC WD20EARS-60M AB51 connected to the ASRock E350M1,
as that takes over ten seconds to spin up.

```
disk/ahci.c:533: port 0, err: 0
disk/ahci.c:539: port 0, err: 0
disk/ahci.c:543: port 0, err: 0
disk/ahci.c:549: port 0, offset: 120, tfd:80, CMD: 6016
disk/ahci.c:552: port 0, err: 0
disk/ahci.c:563: port 0, offset: 120, tfd:80, CMD: 6016
disk/ahci.c:566: port: 0, err: 0
disk/ahci.c:593: port 0 is busy
disk/ahci.c:621: cleaning up failed devs
```

GRUB detects the drive, when either unloading the module *ahci*, and
then loading it again, or when doing a warm reset.

As the ten second time-out is too short, increase it to 32 seconds,
used by SeaBIOS. which detects the drive successfully.

The AHCI driver in libpayload uses 30 seconds, and that time-out was
added in commit 354066e1 (libpayload: ahci: Increase timeout for
signature reading) with the description below.

> We can't read the drives signature before it's ready, i.e. spun up.
> So set the timeout to the standard 30s. Also put a notice on the
> console, so the user knows why the signature reading failed.

Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agolinux16: Code cleanup
Cao jin [Tue, 7 Aug 2018 06:57:53 +0000 (14:57 +0800)] 
linux16: Code cleanup

1. move relocator related code more close to each other
2. use variable "len" since it has correct assignment, and keep coding
style with upper code

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agotests: Fix qemu options for UHCI test
Colin Watson [Mon, 30 Jul 2018 11:37:42 +0000 (12:37 +0100)] 
tests: Fix qemu options for UHCI test

qemu 2.12 removed the -usbdevice option.  Use a more modern spelling
instead, in line with other USB-related tests.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agotests: Disable sercon in SeaBIOS
Colin Watson [Mon, 30 Jul 2018 11:37:22 +0000 (12:37 +0100)] 
tests: Disable sercon in SeaBIOS

SeaBIOS 1.11.0 added support for VGA emulation over a serial port, which
interferes with grub-shell.  Turn it off.

Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agogrub-module-verifier: Report the filename or modname in errors
Peter Jones [Wed, 1 Aug 2018 16:23:03 +0000 (12:23 -0400)] 
grub-module-verifier: Report the filename or modname in errors

Make it so that when grub-module-verifier complains of an issue, it tells you
which module the issue was with.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoconfigure: Fix an 8 year old typo
Peter Jones [Wed, 1 Aug 2018 16:28:43 +0000 (12:28 -0400)] 
configure: Fix an 8 year old typo

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoloader/multiboot_mbi2: Use central copy of grub_efi_find_mmap_size()
Leif Lindholm [Fri, 13 Jul 2018 16:34:45 +0000 (17:34 +0100)] 
loader/multiboot_mbi2: Use central copy of grub_efi_find_mmap_size()

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoloader/ia64/linux: Use central copy of grub_efi_find_mmap_size()
Leif Lindholm [Fri, 13 Jul 2018 16:34:44 +0000 (17:34 +0100)] 
loader/ia64/linux: Use central copy of grub_efi_find_mmap_size()

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
6 years agoloader/i386/linux: Use central copy of grub_efi_find_mmap_size()
Leif Lindholm [Fri, 13 Jul 2018 16:34:43 +0000 (17:34 +0100)] 
loader/i386/linux: Use central copy of grub_efi_find_mmap_size()

Delete local copy of function to determine required buffer size for the
UEFI memory map, use helper in kern/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoi386: Don't include lib/i386/reset.c in EFI builds
Leif Lindholm [Mon, 9 Jul 2018 18:49:06 +0000 (19:49 +0100)] 
i386: Don't include lib/i386/reset.c in EFI builds

Commit 0ba90a7f0178 ("efi: Move grub_reboot() into kernel") broke
the build on i386-efi - genmoddep.awk bails out with message
  grub_reboot in reboot is duplicated in kernel
This is because both lib/i386/reset.c and kern/efi/efi.c now provide
this function.

Rather than explicitly list each i386 platform variant in
Makefile.core.def, include the contents of lib/i386/reset.c only when
GRUB_MACHINE_EFI is not set.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi: Restrict arm/arm64 linux loader initrd placement
Leif Lindholm [Mon, 9 Jul 2018 17:33:05 +0000 (18:33 +0100)] 
efi: Restrict arm/arm64 linux loader initrd placement

The 32-bit arm Linux kernel is built as a zImage, which self-decompresses
down to near start of RAM. In order for an initrd/initramfs to be
accessible, it needs to be placed within the first ~768MB of RAM.
The initrd loader built into the kernel EFI stub restricts this down to
512MB for simplicity - so enable the same restriction in grub.

For arm64, the requirement is within a 1GB aligned 32GB window also
covering the (runtime) kernel image. Since the EFI stub loader itself
will attempt to relocate to near start of RAM, force initrd to be loaded
completely within the first 32GB of RAM.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoarm: Delete unused efi support from loader/arm
Leif Lindholm [Mon, 9 Jul 2018 17:33:04 +0000 (18:33 +0100)] 
arm: Delete unused efi support from loader/arm

The 32-bit arm efi port now shares the 64-bit linux loader, so delete
the now unused bits from the 32-bit linux loader.

This in turn leaves the grub-core/kern/arm/efi/misc.c unused, so
delete that too.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoarm/efi: Switch to arm64 linux loader
Leif Lindholm [Mon, 9 Jul 2018 17:33:03 +0000 (18:33 +0100)] 
arm/efi: Switch to arm64 linux loader

The arm64 and arm linux kernel EFI-stub support presents pretty much
identical interfaces, so the same linux loader source can be used for
both architectures.

Switch 32-bit ARM UEFI platforms over to the existing EFI-stub aware
loader initially developed for arm64.

This *WILL* stop non-efistub Linux kernels from booting on arm-efi.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoarm64/linux/loader: Rename functions and macros and move to common headers
Leif Lindholm [Mon, 9 Jul 2018 17:33:02 +0000 (18:33 +0100)] 
arm64/linux/loader: Rename functions and macros and move to common headers

In preparation for using the linux loader for 32-bit and 64-bit platforms,
rename grub_arm64*/GRUB_ARM64* to grub_armxx*/GRUB_ARMXX*.

Move prototypes for now-common functions to efi/efi.h.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi: Add grub_efi_get_ram_base() function for arm64
Leif Lindholm [Mon, 9 Jul 2018 17:33:01 +0000 (18:33 +0100)] 
efi: Add grub_efi_get_ram_base() function for arm64

Since ARM platforms do not have a common memory map, add a helper
function that finds the lowest address region with the EFI_MEMORY_WB
attribute set in the UEFI memory map.

Required for the arm64 efi linux loader to restrict the initrd
location to where it will be accessible by the kernel at runtime.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi: Add central copy of grub_efi_find_mmap_size
Leif Lindholm [Mon, 9 Jul 2018 17:33:00 +0000 (18:33 +0100)] 
efi: Add central copy of grub_efi_find_mmap_size

There are several implementations of this function in the tree.
Add a central version in grub-core/efi/mm.c.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoi386/linux: Add support for ext_lfb_base
Arindam Nath [Thu, 12 Jul 2018 13:32:49 +0000 (19:02 +0530)] 
i386/linux: Add support for ext_lfb_base

The EFI Graphics Output Protocol can return a 64-bit
linear frame buffer address in some firmware/BIOS
implementations. We currently only store the lower
32-bits in the lfb_base. This will eventually be
passed to Linux kernel and the efifb driver will
incorrectly interpret the framebuffer address as
32-bit address.

The Linux kernel has already added support to handle
64-bit linear framebuffer address in the efifb driver
since quite some time now.

This patch adds the support for 64-bit linear frame
buffer address in GRUB to address the above mentioned
scenario.

Signed-off-by: Arindam Nath <arindam.nath@amd.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agocommands/file: Use definitions from arm64/linux.h
Leif Lindholm [Mon, 25 Jun 2018 17:01:29 +0000 (18:01 +0100)] 
commands/file: Use definitions from arm64/linux.h

Clean up code for matching IS_ARM64 slightly by making use of struct
linux_arm64_kernel_header and GRUB_LINUX_ARM64_MAGIC_SIGNATURE.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agocommands/file: Use definitions from arm/linux.h
Leif Lindholm [Mon, 25 Jun 2018 17:01:28 +0000 (18:01 +0100)] 
commands/file: Use definitions from arm/linux.h

Clean up code for matching IS_ARM slightly by making use of struct
linux_arm_kernel_header and GRUB_LINUX_ARM_MAGIC_SIGNATURE.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi/console: Fix the "enter" key not working on x86 tablets
Hans de Goede [Tue, 26 Jun 2018 18:15:01 +0000 (20:15 +0200)] 
efi/console: Fix the "enter" key not working on x86 tablets

Most 8" or 7" x86 Windows 10 tablets come with volume up/down buttons and
a power-button. In their UEFI these are almost always mapped to arrow
up/down and enter.

Pressing the volume buttons (sometimes by accident) will stop the
menu countdown, but the power-button / "enter" key was not being recognized
as enter, so the user would be stuck at the grub menu.

The problem is that these tablets send scan_code 13 or 0x0d for the
power-button, which officialy maps to the F3 key. They also set
unicode_char to 0x0d.

This commit recognizes the special case of both scan_code and unicode_char
being set to 0x0d and treats this as an enter key press.

This fixes things getting stuck at the grub-menu and allows the user
to choice a grub-menu entry using the buttons on the tablet.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-setup: Debug message cleanup
Cao jin [Tue, 3 Jul 2018 10:51:13 +0000 (18:51 +0800)] 
grub-setup: Debug message cleanup

Variable "root" is initialized after root device probing and is null in
current place, so, drop it.

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomultiboot_elfxx.c: Fix compilation by fixing undeclared variable
Denis 'GNUtoo' Carikli [Fri, 29 Jun 2018 12:15:11 +0000 (14:15 +0200)] 
multiboot_elfxx.c: Fix compilation by fixing undeclared variable

Without that fix we have:
  In file included from ../../include/grub/command.h:25:0,
                   from ../../grub-core/loader/multiboot.c:30:
  ../../grub-core/loader/multiboot_elfxx.c: In function 'grub_multiboot_load_elf64':
  ../../grub-core/loader/multiboot_elfxx.c:130:28: error: 'relocatable' undeclared (first use in this function)
     "load_base_addr=0x%x\n", relocatable,

This happens due to mistake in the commit 14ec665
(mbi: Use per segment a separate relocator chunk).

So, let's fix it.

Signed-off-by: Ignat Korchagin <ignat@cloudflare.com>
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi/fdt: Set address/size cells to 2 for empty tree
Leif Lindholm [Mon, 11 Jun 2018 16:24:59 +0000 (17:24 +0100)] 
efi/fdt: Set address/size cells to 2 for empty tree

When booting an arm* system on UEFI with an empty device tree (currently
only when hardware description comes from ACPI), we don't currently set
default to 1 cell (32 bits).

Set both of these properties, to 2 cells (64 bits), to resolve issues
with kexec on some platforms.

This change corresponds with linux kernel commit ae8a442dfdc4
("efi/libstub/arm*: Set default address and size cells values for an empty dtb")
and ensures booting through grub does not behave differently from booting
the stub loader directly.

See also https://patchwork.kernel.org/patch/9561201/

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agofdt: Move prop_entry_size to fdt.h
Leif Lindholm [Mon, 11 Jun 2018 16:24:58 +0000 (17:24 +0100)] 
fdt: Move prop_entry_size to fdt.h

To be able to resuse the prop_entry_size macro, move it to
<grub/fdt.h> and rename it grub_fdt_prop_entry_size.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-fs-tester: Fix losetup race
Will Thompson [Fri, 15 Jun 2018 17:34:04 +0000 (18:34 +0100)] 
grub-fs-tester: Fix losetup race

If something else on the system is using loopback devices, then the
device that's free at the call to `losetup -f` may not be free in the
following call to try to use it. Instead, find and use the first free
loopback device in a single call to losetup.

Signed-off-by: Will Thompson <wjt@endlessm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agombi: Use per segment a separate relocator chunk
Alexander Boettcher [Tue, 12 Jun 2018 18:04:09 +0000 (20:04 +0200)] 
mbi: Use per segment a separate relocator chunk

Instead of setting up a all comprising relocator chunk for all segments,
use per segment a separate relocator chunk.

Currently, if the ELF is non-relocatable, a single relocator chunk will
comprise memory (between the segments) which gets overridden by the relst()
invocation of the movers code in grub_relocator16/32/64_boot().

The overridden memory may contain reserved ranges like VGA memory or ACPI
tables, which may lead to crashes or at least to strange boot behaviour.

Signed-off-by: Alexander Boettcher <alexander.boettcher@genode-labs.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agotemplates: Add missing "]"
Daniel Kiper [Tue, 5 Jun 2018 11:04:04 +0000 (13:04 +0200)] 
templates: Add missing "]"

Commit 51be337 (templates: Update grub script template files)
lacked one "]", so, add it.

Reported-by: Philip <philm@manjaro.org>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoxfs: Accept filesystem with sparse inodes
Daniel Kiper [Tue, 29 May 2018 14:16:02 +0000 (16:16 +0200)] 
xfs: Accept filesystem with sparse inodes

The sparse inode metadata format became a mkfs.xfs default in
xfsprogs-4.16.0, and such filesystems are now rejected by grub as
containing an incompatible feature.

In essence, this feature allows xfs to allocate inodes into fragmented
freespace.  (Without this feature, if xfs could not allocate contiguous
space for 64 new inodes, inode creation would fail.)

In practice, the disk format change is restricted to the inode btree,
which as far as I can tell is not used by grub.  If all you're doing
today is parsing a directory, reading an inode number, and converting
that inode number to a disk location, then ignoring this feature
should be fine, so I've added it to XFS_SB_FEAT_INCOMPAT_SUPPORTED

I did some brief testing of this patch by hacking up the regression
tests to completely fragment freespace on the test xfs filesystem, and
then write a large-ish number of inodes to consume any existing
contiguous 64-inode chunk.  This way any files the grub tests add and
traverse would be in such a fragmented inode allocation.  Tests passed,
but I'm not sure how to cleanly integrate that into the test harness.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Tested-by: Chris Murphy <lists@colorremedies.com>
7 years agogrub-probe: Don't skip /dev/mapper/dm-* devices
Oleg Solovyov [Fri, 11 May 2018 10:55:46 +0000 (13:55 +0300)] 
grub-probe: Don't skip /dev/mapper/dm-* devices

This patch ensures that grub-probe will find the root device placed in
/dev/mapper/dm-[0-9]+-.* e.g. device named /dev/mapper/dm-0-luks will be
found and grub.cfg will be updated properly, enabling the system to boot.

Signed-off-by: Oleg Solovyov <mcpain@altlinux.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agobufio: Round up block size to power of 2
Michael Chang [Tue, 24 Apr 2018 06:13:04 +0000 (14:13 +0800)] 
bufio: Round up block size to power of 2

Rounding up the bufio->block_size to meet power of 2 to facilitate next_buf
calculation in grub_bufio_read().

Signed-off-by: Michael Chang <mchang@suse.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agotemplates: Update grub script template files
Nicholas Vinson [Tue, 17 Apr 2018 05:36:26 +0000 (22:36 -0700)] 
templates: Update grub script template files

Update grub-mkconfig.in and 10_linux.in to support grub-probe's new
partuuid target.  Update grub.texi documentation.  The following table
shows how GRUB_DISABLE_LINUX_UUID, GRUB_DISABLE_LINUX_PARTUUID, and
initramfs detection interact:

Initramfs  GRUB_DISABLE_LINUX_PARTUUID  GRUB_DISABLE_LINUX_UUID  Linux Root
detected   Set                          Set                      ID Method

false      false                        false                    part UUID
false      false                        true                     part UUID
false      true                         false                    dev name
false      true                         true                     dev name
true       false                        false                    fs UUID
true       false                        true                     part UUID
true       true                         false                    fs UUID
true       true                         true                     dev name

Note: GRUB_DISABLE_LINUX_PARTUUID and GRUB_DISABLE_LINUX_UUID equate to
      'false' when unset or set to any value other than 'true'.
      GRUB_DISABLE_LINUX_PARTUUID defaults to 'true'.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-probe: Add PARTUUID detection support
Nicholas Vinson [Tue, 17 Apr 2018 05:36:25 +0000 (22:36 -0700)] 
grub-probe: Add PARTUUID detection support

Add PARTUUID detection support grub-probe for MBR and GPT partition schemes.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agodisk: Update grub_gpt_partentry
Nicholas Vinson [Tue, 17 Apr 2018 05:36:24 +0000 (22:36 -0700)] 
disk: Update grub_gpt_partentry

Rename grub_gpt_part_type to grub_gpt_part_guid and update grub_gpt_partentry
to use this type for both the partition type GUID string and the partition GUID
string entries.  This change ensures that the two GUID fields are handled more
consistently and helps to simplify the changes needed to add Linux partition
GUID support.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-probe: Centralize GUID prints
Nicholas Vinson [Tue, 17 Apr 2018 05:36:23 +0000 (22:36 -0700)] 
grub-probe: Centralize GUID prints

Define print_gpt_guid(), so there is a central function for printing
GUID strings.  This change is a precursor for later patches which rely
on this logic.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-install: Locale depends on nls
Olaf Hering [Fri, 13 Apr 2018 21:36:49 +0000 (23:36 +0200)] 
grub-install: Locale depends on nls

With --disable-nls no locales exist.

Avoid runtime error by moving code that copies locales into its own
function. Return early in case nls was disabled. That way the compiler
will throw away unreachable code, no need to put preprocessor
conditionals everywhere to avoid warnings about unused code.

Fix memleak by freeing srcf and dstf.
Convert tabs to spaces in moved code.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agodiskboot: Trivial correction on stale comments
Cao jin [Wed, 11 Apr 2018 03:23:10 +0000 (11:23 +0800)] 
diskboot: Trivial correction on stale comments

diskboot.img now is loaded at 0x8000 and is jumped to with 0:0x8000.

Signed-off-by: Cao jin <caoj.fnst@cn.fujitsu.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agofs: Add F2FS support
Jaegeuk Kim [Thu, 29 Mar 2018 15:37:39 +0000 (16:37 +0100)] 
fs: Add F2FS support

"F2FS (Flash-Friendly File System) is flash-friendly file system which was merged
into Linux kernel v3.8 in 2013.

The motive for F2FS was to build a file system that from the start, takes into
account the characteristics of NAND flash memory-based storage devices (such as
solid-state disks, eMMC, and SD cards).

F2FS was designed on a basis of a log-structured file system approach, which
remedies some known issues of the older log structured file systems, such as
the snowball effect of wandering trees and high cleaning overhead. In addition,
since a NAND-based storage device shows different characteristics according to
its internal geometry or flash memory management scheme (such as the Flash
Translation Layer or FTL), it supports various parameters not only for
configuring on-disk layout, but also for selecting allocation and cleaning
algorithm.", quote by https://en.wikipedia.org/wiki/F2FS.

The source codes for F2FS are available from:

http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs.git
http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.git

This patch has been integrated in OpenMandriva Lx 3.
  https://www.openmandriva.org/

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Pete Batard <pete@akeo.ie>
Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoFix packed-not-aligned error on GCC 8
Michael Chang [Mon, 26 Mar 2018 08:52:34 +0000 (16:52 +0800)] 
Fix packed-not-aligned error on GCC 8

When building with GCC 8, there are several errors regarding packed-not-aligned.

./include/grub/gpt_partition.h:79:1: error: alignment 1 of ‘struct grub_gpt_partentry’ is less than 8 [-Werror=packed-not-aligned]

This patch fixes the build error by cleaning up the ambiguity of placing
aligned structure in a packed one. In "struct grub_btrfs_time" and "struct
grub_gpt_part_type", the aligned attribute seems to be superfluous, and also
has to be packed, to ensure the structure is bit-to-bit mapped to the format
laid on disk. I think we could blame to copy and paste error here for the
mistake. In "struct efi_variable", we have to use grub_efi_packed_guid_t, as
the name suggests. :)

Signed-off-by: Michael Chang <mchang@suse.com>
Tested-by: Michael Chang <mchang@suse.com>
Tested-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoefi/uga: Fix PCIe LER when GRUB2 accesses non-enabled MMIO data from VGA
mike.travis@hpe.com [Wed, 28 Mar 2018 16:42:18 +0000 (11:42 -0500)] 
efi/uga: Fix PCIe LER when GRUB2 accesses non-enabled MMIO data from VGA

A GPU inserted into a PCIe I/O slot disappears during system startup.
The problem centers around GRUB and a specific VGA init function in
efi_uga.c. This causes an LER (Link Error Recorvery) because the MMIO
memory has not been enabled before attempting access.

The fix is to add the same coding used in other VGA drivers, specifically
to add a check to insure that it is indeed a VGA controller. And then
enable the MMIO address space with the specific bits.

Signed-off-by: Mike Travis <mike.travis@hpe.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: NULL pointer dereference in grub_machine_get_bootlocation()
Eric Snowberg [Wed, 14 Mar 2018 15:51:17 +0000 (08:51 -0700)] 
ieee1275: NULL pointer dereference in grub_machine_get_bootlocation()

Read from NULL pointer canon in function grub_machine_get_bootlocation().
Function grub_ieee1275_canonicalise_devname() may return NULL.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: split up grub_machine_get_bootlocation
Eric Snowberg [Fri, 9 Mar 2018 04:42:22 +0000 (20:42 -0800)] 
ieee1275: split up grub_machine_get_bootlocation

Split up some of the functionality in grub_machine_get_bootlocation into
grub_ieee1275_get_boot_dev.  This will allow for code reuse in a follow on
patch.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agochainloader: patch in BPB's sectors_per_track and num_heads
C. Masloch [Thu, 1 Feb 2018 14:51:55 +0000 (15:51 +0100)] 
chainloader: patch in BPB's sectors_per_track and num_heads

These fields must reflect the ROM-BIOS's geometry for CHS-based
loaders to correctly load their next stage. Most loaders do not
query the ROM-BIOS (Int13.08), relying on the BPB fields to hold
the correct values already.

Tested with lDebug booted in qemu via grub2's
FreeDOS direct loading support, refer to
https://bitbucket.org/ecm/ldosboot + https://bitbucket.org/ecm/ldebug
(For this test, lDebug's iniload.asm must be assembled with
-D_QUERY_GEOMETRY=0 to leave the BPB values provided by grub.)

Signed-off-by: C. Masloch <pushbx@38.de>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agogrub-mkconfig/10_linux: Support multiple early initrd images
Matthew S. Turnbull [Sat, 24 Feb 2018 22:44:58 +0000 (17:44 -0500)] 
grub-mkconfig/10_linux: Support multiple early initrd images

Add support for multiple, shared, early initrd images. These early
images will be loaded in the order declared, and all will be loaded
before the initrd image.

While many classes of data can be provided by early images, the
immediate use case would be for distributions to provide CPU
microcode to mitigate the Meltdown and Spectre vulnerabilities.

There are two environment variables provided for declaring the early
images.

* GRUB_EARLY_INITRD_LINUX_STOCK is for the distribution declare
  images that are provided by the distribution or installed packages.
  If undeclared, this will default to a set of common microcode image
  names.

* GRUB_EARLY_INITRD_LINUX_CUSTOM is for user created images. User
  images will be loaded after the stock images.

These separate configurations allow the distribution and user to
declare different image sets without clobbering each other.

This also makes a minor update to ensure that UUID partition labels
stay disabled when no initrd image is found, even if early images are
present.

This is a continuation of a previous patch published by Christian
Hesse in 2016:
http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00025.html

Down stream Gentoo bug:
https://bugs.gentoo.org/645088

Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Signed-off-by: Matthew S. Turnbull <sparky@bluefang-logic.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: fix build regression in grub_mkimage_load_image
Eric Snowberg [Tue, 6 Mar 2018 21:38:58 +0000 (13:38 -0800)] 
mkimage: fix build regression in grub_mkimage_load_image

The grub_mkimage_load_image function (commit 7542af6, mkimage: refactor a bunch
of section data into a struct.) introduces a build regression on SPARC:

  cc1: warnings being treated as errors
  In file included from util/grub-mkimage32.c:23:
  util/grub-mkimagexx.c: In function 'grub_mkimage_load_image32':
  util/grub-mkimagexx.c:1968: error: missing initializer
  util/grub-mkimagexx.c:1968: error: (near initialization for 'smd.sections')
  make[2]: *** [util/grub_mkimage-grub-mkimage32.o] Error 1

Initialize the entire section_metadata structure.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoRevert "Keep the native terminal active when enabling gfxterm"
dann frazier [Fri, 2 Mar 2018 17:02:19 +0000 (10:02 -0700)] 
Revert "Keep the native terminal active when enabling gfxterm"

This can cause an issue where GRUB is trying to display both a text and
graphical menu on the display at the same time, resulting in a flickering
effect when e.g. scrolling quickly through a menu (LP: #1752767).

Revert for now while we look for a better solution for the original issue.

This reverts commit 52ef7b23f528ce844716661d586497a177e80d5b.

Signed-off-by: dann frazier <dann.frazier@canonical.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agosparc64: #blocks64 disk node method
Eric Snowberg [Tue, 27 Feb 2018 01:34:20 +0000 (17:34 -0800)] 
sparc64: #blocks64 disk node method

Return the 64bit number of blocks of storage associated with the device or
instance. Where a "block" is a unit of storage consisting of the number of
bytes returned by the package's "block-size" method. If the size cannot be
determined, or if the number of blocks exceeds the range return -1.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agosparc64: #blocks disk node method
Eric Snowberg [Tue, 27 Feb 2018 01:34:19 +0000 (17:34 -0800)] 
sparc64: #blocks disk node method

Return the number of blocks of storage associated with the device or
instance. Where a "block" is a unit of storage consisting of the number
of bytes returned by the package's "block-size" method. If the size cannot
be determined, the #blocks method returns the maximum unsigned integer
(which, because of Open Firmware's assumption of two's complement arithmetic,
is equivalent to the signed number -1). If the number of blocks exceeds
the range of an unsigned number, return 0 to alert the caller to try
the #blocks64 command.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: block-size deblocker support method
Eric Snowberg [Tue, 27 Feb 2018 01:34:18 +0000 (17:34 -0800)] 
ieee1275: block-size deblocker support method

IEEE Std 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices

3.8.3 deblocker support package

Any package that uses the "deblocker" support package must define
the following method, which the deblocker uses as a low-level
interface to the device

block-size ( -- block-len ) Return "granularity" for accesses to this
device.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: no-data-command bus specific method
Daniel Kiper [Mon, 5 Mar 2018 14:11:18 +0000 (15:11 +0100)] 
ieee1275: no-data-command bus specific method

IEEE 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices

E.3.2.2 Bus-specific methods for bus nodes

A package implementing the scsi-2 device type shall implement the
following bus-specific method:

no-data-command ( cmd-addr -- error? )
Executes a simple SCSI command, automatically retrying under
certain conditions.  cmd-addr is the address of a 6-byte command buffer
containing an SCSI command that does not have a data transfer phase.
Executes the command, retrying indefinitely with the same retry criteria
as retry-command.

error? is nonzero if an error occurred, zero otherwise.
NOTE no-data-command is a convenience function. It provides
no capabilities that are not present in retry-command, but for
those commands that meet its restrictions, it is easier to use.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: set-address bus specific method
Eric Snowberg [Tue, 27 Feb 2018 01:34:16 +0000 (17:34 -0800)] 
ieee1275: set-address bus specific method

IEEE 1275-1994 Standard for Boot (Initialization Configuration)
Firmware: Core Requirements and Practices
E.3.2.2 Bus-specific methods for bus nodes

A package implementing the scsi-2 device type shall implement the
following bus-specific method:

 set-address ( unit# target# -- )
   Sets the SCSI target number (0x0..0xf) and unit number (0..7) to which
   subsequent commands apply.

This function is for devices with #address-cells == 2

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: encode-unit command for 4 addr cell devs
Eric Snowberg [Tue, 27 Feb 2018 01:34:15 +0000 (17:34 -0800)] 
ieee1275: encode-unit command for 4 addr cell devs

Convert physical address to text unit-string.

Convert phys.lo ... phys-high, the numerical representation, to unit-string,
the text string representation of a physical address within the address
space defined by this device node. The number of cells in the list
phys.lo ... phys.hi is determined by the value of the #address-cells property
of this node.

This function is for devices with #address-cells == 4

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: decode-unit command for 4 addr cell devs
Eric Snowberg [Tue, 27 Feb 2018 01:34:14 +0000 (17:34 -0800)] 
ieee1275: decode-unit command for 4 addr cell devs

decode-unit ( addr len -- phys.lo ... phys.hi )

Convert text unit-string to physical address.

Convert unit-string, the text string representation, to phys.lo ... phys.hi,
the numerical representation of a physical address within the address space
defined by this device node. The number of cells in the list
phys.lo ... phys.hi is determined by the value of the #address-cells
property of this node.

This function is for devices with #address-cells == 4

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agosparc64: Limit nvme of_path_of_nvme to just SPARC
Eric Snowberg [Fri, 2 Mar 2018 03:25:09 +0000 (19:25 -0800)] 
sparc64: Limit nvme of_path_of_nvme to just SPARC

Limit NVMe of_path_of_nvme to just SPARC hardware for now.  It has been
found that non-Open Firmware hardware platforms can some how access
this function.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: Fix crash in of_path_of_nvme when of_path is empty
John Paul Adrian Glaubitz [Thu, 1 Mar 2018 22:34:53 +0000 (23:34 +0100)] 
ieee1275: Fix crash in of_path_of_nvme when of_path is empty

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme
support within ofpath) introduced a functional regression:

On systems which are not based on Open Firmware but have at
least one NVME device, find_obppath will return NULL and thus
trying to append the disk name to of_path will result in a
crash.

The proper behavior of of_path_of_nvme is, however, to just
return NULL in such cases, like other users of find_obppath,
such as of_path_of_scsi.

Signed-off-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Reviewed-by: Eric Snowberg <eric.snowberg@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years ago.mod files: Strip annobin annotations and .eh_frame, and their relocations
Peter Jones [Wed, 21 Feb 2018 20:20:29 +0000 (15:20 -0500)] 
.mod files: Strip annobin annotations and .eh_frame, and their relocations

This way debuginfo built from the .module will still include this
information, but the final result won't have the data we don't actually
need in the modules, either on-disk, loaded at runtime, or in prebuilt
images.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: avoid copying relocations for sections that won't be copied.
Peter Jones [Wed, 21 Feb 2018 20:20:28 +0000 (15:20 -0500)] 
mkimage: avoid copying relocations for sections that won't be copied.

Some versions of gcc include a plugin called "annobin", and in some
build systems this is enabled by default.  This plugin creates special
ELF note sections to track which ABI-breaking features are used by a
binary, as well as a series of relocations to annotate where.

If grub is compiled with this feature, then when grub-mkimage translates
the binary to another file format which does not strongly associate
relocation data with sections (i.e. when platform is *-efi), these
relocations appear to be against the .text section rather than the
original note section.  When the binary is loaded by the PE runtime
loader, hilarity ensues.

This issue is not necessarily limited to the annobin, but could arise
any time there are relocations in sections that are not represented in
grub-mkimage's output.

This patch seeks to avoid this issue by only including relocations that
refer to sections which will be included in the final binary.

As an aside, this should also obviate the need to avoid -funwind-tables,
-fasynchronous-unwind-tables, and any sections similar to .eh_frame in
the future.  I've tested it on x86-64-efi with the following gcc command
line options (as recorded by -grecord-gcc-flags), but I still need to
test the result on some other platforms that have been problematic in
the past (especially ARM Aarch64) before I feel comfortable making
changes to the configure.ac bits:

GNU C11 7.2.1 20180116 (Red Hat 7.2.1-7) -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-3dnow -msoft-float -mno-stack-arg-probe -mcmodel=large -mno-red-zone -m64 -mtune=generic -march=x86-64 -g3 -Os -freg-struct-return -fno-stack-protector -ffreestanding -funwind-tables -fasynchronous-unwind-tables -fno-strict-aliasing -fstack-clash-protection -fno-ident -fplugin=annobin

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: refactor a bunch of section data into a struct.
Peter Jones [Wed, 21 Feb 2018 20:20:27 +0000 (15:20 -0500)] 
mkimage: refactor a bunch of section data into a struct.

This basically moves a bunch of the section information we pass around a
lot into a struct, and passes a pointer to a single one of those
instead.

This shouldn't change the binary file output or the "grub-mkimage -v"
output in any way.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: make locate_sections() set up vaddresses as well.
Peter Jones [Wed, 21 Feb 2018 20:20:26 +0000 (15:20 -0500)] 
mkimage: make locate_sections() set up vaddresses as well.

This puts both kinds of address initialization at the same place, and also lets
us iterate through the section list one time fewer.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: rename a couple of things to be less confusing later.
Peter Jones [Wed, 21 Feb 2018 20:20:25 +0000 (15:20 -0500)] 
mkimage: rename a couple of things to be less confusing later.

This renames some things:

- the "strtab" and "strtab_section" in relocate_symbols are changed to "symtab"
  instead, so as to be less confusing when "strtab" is moved to a struct in a
  later patch.

- The places where we pass section_vaddresses to functions are changed to also
  be called section_vaddresses"inside those functions, so I get less confused
  when I put addresses and vaddresses in a struct in a later patch.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agomkimage: make it easier to run syntax checkers on grub-mkimagexx.c
Peter Jones [Wed, 21 Feb 2018 20:20:24 +0000 (15:20 -0500)] 
mkimage: make it easier to run syntax checkers on grub-mkimagexx.c

This makes it so you can treat grub-mkimagexx.c as a file you can build
directly, so syntax checkers like vim's "syntastic" plugin, which uses
"gcc -x c -fsyntax-only" to build it, will work.

One still has to do whatever setup is required to make it pick the right
include dirs, which -W options we use, etc., but this makes it so you
can do the checking on the file you're editing, rather than on a
different file.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoaout.h: Fix missing include.
Peter Jones [Wed, 21 Feb 2018 20:20:23 +0000 (15:20 -0500)] 
aout.h: Fix missing include.

grub_aout_load() has a grub_file_t parameter, and depending on what order
includes land in, it's sometimes not defined.  This patch explicitly adds
file.h to aout.h so that it will always be defined.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoieee1275: fix build regression in of_path_of_nvme
Joakim Bech [Mon, 26 Feb 2018 08:57:34 +0000 (09:57 +0100)] 
ieee1275: fix build regression in of_path_of_nvme

The of_path_of_nvme function (commit 2391d57, ieee1275: add nvme
support within ofpath) introduced a build regression:
    grub-core/osdep/linux/ofpath.c:365:21: error: comparison between pointer
    and zero character constant [-Werror=pointer-compare]
       if ((digit_string != '\0') && (*part_end == 'p'))

Update digit_string to compare against the char instead of the pointer.

Signed-off-by: Joakim Bech <joakim.bech@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoarm: make linux.h safe to include for non-native builds
Leif Lindholm [Thu, 1 Feb 2018 18:18:56 +0000 (18:18 +0000)] 
arm: make linux.h safe to include for non-native builds

<grub/machine/loader.h> (for machine arm/efi) and
<grub/machine/kernel.h> (for machine arm/coreboot) will not always
resolve (and will likely not be valid to) if pulled in when building
non-native commands, such as host tools or the "file" command.
So explicitly include them with their expanded pathnames.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
7 years agoarm: switch linux loader to linux_arm_kernel_header struct
Leif Lindholm [Thu, 1 Feb 2018 18:18:55 +0000 (18:18 +0000)] 
arm: switch linux loader to linux_arm_kernel_header struct

Use kernel header struct and magic definition to align (and coexist) with
i386/arm64 ports.

Signed-off-by: Leif Lindholm <leif.lindholm@linaro.org>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>